-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,513 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.juul.krayon.sample | ||
|
||
internal data class Point( | ||
data class Point( | ||
val x: Float, | ||
val y: Float, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import com.juul.krayon.element.view.ElementViewAdapter | ||
import com.juul.krayon.element.view.attachAdapter | ||
import com.juul.krayon.sample.interactiveTreeChart | ||
import org.w3c.dom.HTMLCanvasElement | ||
|
||
@JsExport | ||
fun setupInteractiveChart(element: HTMLCanvasElement) { | ||
val (flow, update) = interactiveTreeChart() | ||
element.attachAdapter(ElementViewAdapter(flow, update)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.juul.krayon.element.view.ElementViewAdapter | ||
import com.juul.krayon.element.view.attachAdapter | ||
import com.juul.krayon.sample.data.movingSineWave | ||
import com.juul.krayon.sample.updaters.lineChart | ||
import org.w3c.dom.HTMLCanvasElement | ||
|
||
@JsExport | ||
fun setupMovingSineWave(element: HTMLCanvasElement) { | ||
element.attachAdapter( | ||
ElementViewAdapter( | ||
dataSource = movingSineWave(), | ||
updater = ::lineChart, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package tutorial | ||
|
||
import com.juul.krayon.color.blue | ||
import com.juul.krayon.element.LineElement | ||
import com.juul.krayon.element.RootElement | ||
import com.juul.krayon.kanvas.HtmlKanvas | ||
import com.juul.krayon.kanvas.Paint | ||
import com.juul.krayon.scale.domain | ||
import com.juul.krayon.scale.range | ||
import com.juul.krayon.scale.scale | ||
import com.juul.krayon.selection.asSelection | ||
import com.juul.krayon.selection.data | ||
import com.juul.krayon.selection.each | ||
import com.juul.krayon.selection.join | ||
import com.juul.krayon.selection.selectAll | ||
import org.w3c.dom.HTMLCanvasElement | ||
|
||
@JsExport | ||
fun setupBarChart(element: HTMLCanvasElement) { | ||
val (width, height) = element.size // 1 | ||
val data = (1..10).toList() // 2 | ||
|
||
val x = scale() // 3 | ||
.domain(0, data.count() - 1) // 3 | ||
.range(0f, width) // 3 | ||
|
||
val y = scale() // 4 | ||
.domain(0, data.max()) // 4 | ||
.range(height, 0f) // 4 | ||
|
||
val barPaint = Paint.Stroke( // 5 | ||
color = blue, // 5 | ||
width = x.scale(1), // 5 | ||
) | ||
|
||
val root = RootElement() // 6 | ||
root.asSelection() // 7 | ||
.selectAll(LineElement) // 8 | ||
.data(data) // 9 | ||
.join(LineElement) // 10 | ||
.each { (data, index) -> // 11 | ||
startX = x.scale(index) // 12 | ||
startY = y.scale(0) // 12 | ||
endX = x.scale(index) // 12 | ||
endY = y.scale(data) // 12 | ||
paint = barPaint // 13 | ||
} | ||
root.draw(HtmlKanvas(element)) // 14 | ||
} | ||
|
||
private val HTMLCanvasElement.size | ||
get() = width.toFloat() to height.toFloat() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tutorial | ||
|
||
import com.juul.krayon.element.LineElement | ||
import com.juul.krayon.element.RootElement | ||
import com.juul.krayon.kanvas.HtmlKanvas | ||
import com.juul.krayon.selection.append | ||
import com.juul.krayon.selection.asSelection | ||
import com.juul.krayon.selection.each | ||
import org.w3c.dom.HTMLCanvasElement | ||
|
||
@JsExport | ||
fun setupLine1(element: HTMLCanvasElement) { | ||
val root = RootElement() // 1 | ||
root.asSelection() // 2 | ||
.append(LineElement) // 3 | ||
.each { | ||
startX = 10f // 4 | ||
startY = 10f // 4 | ||
endX = 90f // 4 | ||
endY = 90f // 4 | ||
} | ||
root.draw(HtmlKanvas(element)) // 5 | ||
} |
Oops, something went wrong.