-
Notifications
You must be signed in to change notification settings - Fork 23
polygon builder tests and docs #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| # polygon | ||
|
|
||
| <tldr> | ||
| <p><format style="bold" color="GoldenRod">polygon</format> <format style="italic">{ this: PolygonBuilder -></format></p> | ||
| <list type="none"> | ||
| <li> | ||
| <a href="#x"><format style="bold" color="CadetBlue">x</format></a> <format style="superscript">Positional</format> | ||
| <include from="properties.topic" element-id="signature-of-positional"></include> | ||
| </li> | ||
| <li> | ||
| <a href="#y"><format style="bold" color="CadetBlue">y</format></a> <format style="superscript">Positional</format> | ||
| <include from="properties.topic" element-id="signature-of-positional"></include> | ||
| </li> | ||
| <li> | ||
| <a href="#fillcolor"><format style="bold" color="DarkGray">fillColor</format></a>: Color | ||
| </li> | ||
| <li> | ||
| <a href="#alpha"><format style="bold" color="DarkGray">alpha</format></a>: | ||
| <include from = "properties.topic" element-id="signature-of-nonpos-alpha-setting"></include> | ||
| </li> | ||
| <li> | ||
| <include from="properties.topic" element-id="signature-of-borderLine"/> | ||
| </li> | ||
| </list> | ||
| <format style="italic">}</format> | ||
| </tldr> | ||
|
|
||
| ## Properties | ||
|
|
||
| ### x | ||
|
|
||
| <include from="properties.topic" element-id="x-property"/> | ||
|
|
||
| ### y | ||
|
|
||
| <include from="properties.topic" element-id="y-property"/> | ||
|
|
||
| ### alpha | ||
|
|
||
| <include from="properties.topic" element-id="alpha-property"/> | ||
|
|
||
| ### fillColor | ||
|
|
||
| <include from="properties.topic" element-id="fillColor-property"/> | ||
|
|
||
| ### borderLine | ||
|
|
||
| <include from="properties.topic" element-id="borderLine-property"/> | ||
|
|
175 changes: 175 additions & 0 deletions
175
...lets-plot/src/test/kotlin/org/jetbrains/kotlinx/kandy/letsplot/layers/builders/polygon.kt
This file contains hidden or 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,175 @@ | ||
| @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") | ||
| package org.jetbrains.kotlinx.kandy.letsplot.layers.builders | ||
|
|
||
| import org.jetbrains.kotlinx.dataframe.api.dataFrameOf | ||
| import org.jetbrains.kotlinx.dataframe.api.toColumn | ||
| import org.jetbrains.kotlinx.kandy.dsl.categorical | ||
| import org.jetbrains.kotlinx.kandy.dsl.continuous | ||
| import org.jetbrains.kotlinx.kandy.dsl.internal.dataframe.DataFramePlotBuilder | ||
| import org.jetbrains.kotlinx.kandy.ir.bindings.NonPositionalMapping | ||
| import org.jetbrains.kotlinx.kandy.ir.bindings.NonPositionalSetting | ||
| import org.jetbrains.kotlinx.kandy.ir.bindings.PositionalSetting | ||
| import org.jetbrains.kotlinx.kandy.ir.scale.PositionalCategoricalScale | ||
| import org.jetbrains.kotlinx.kandy.ir.scale.PositionalContinuousScale | ||
| import org.jetbrains.kotlinx.kandy.letsplot.internal.* | ||
| import org.jetbrains.kotlinx.kandy.letsplot.layers.geom.POLYGON | ||
| import org.jetbrains.kotlinx.kandy.util.color.Color | ||
| import org.jetbrains.kotlinx.kandy.util.context.invoke | ||
| import kotlin.test.BeforeTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class PolygonTests { | ||
| private val xAxis = listOf(0.0, 1.0, 2.0).toColumn("xAxis") | ||
| private val yAxis = listOf("A", "B", "C").toColumn("yAxis") | ||
| private val fillColor = listOf("green", "blue", "red").toColumn("fillColor") | ||
| private val alpha = listOf(0.3, 0.7, 0.5).toColumn("alpha") | ||
| private val borderColor = listOf("black", "gray", "white").toColumn("borderColor") | ||
| private val borderSize = listOf(1.0, 2.0, 1.5).toColumn("borderSize") | ||
|
|
||
| private val df = dataFrameOf(xAxis, yAxis, fillColor, alpha, borderColor, borderSize) | ||
|
|
||
| private val parentBuilder = DataFramePlotBuilder(df) | ||
| private lateinit var builder: PolygonBuilder | ||
|
|
||
| @BeforeTest | ||
| fun setUp() { | ||
| builder = PolygonBuilder(parentBuilder) | ||
| } | ||
|
|
||
| @Test | ||
| fun `geom is POLYGON`() { | ||
| assertEquals(POLYGON, builder.geom) | ||
| } | ||
|
|
||
| @Test | ||
| fun `requiredAes contains X and Y`() { | ||
| assertTrue(builder.requiredAes.contains(X)) | ||
| assertTrue(builder.requiredAes.contains(Y)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `fillColor const for polygons`() { | ||
| builder.fillColor = Color.GREEN | ||
| assertEquals(Color.GREEN, (builder.bindingCollector.settings[FILL] as NonPositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `fillColor str mapping for polygons`() { | ||
| builder.fillColor("fillColor") | ||
| assertEquals("fillColor", (builder.bindingCollector.mappings[FILL] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `fillColor dataColumn mapping for polygons`() { | ||
| builder.fillColor(fillColor) | ||
| assertEquals("fillColor", (builder.bindingCollector.mappings[FILL] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `fillColor iterable mapping for polygons`() { | ||
| builder.fillColor(listOf("red", "blue", "green")) | ||
| assertEquals("fill", (builder.bindingCollector.mappings[FILL] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `alpha const for polygons`() { | ||
| builder.alpha = 0.5 | ||
| assertEquals(0.5, (builder.bindingCollector.settings[ALPHA] as NonPositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `alpha str mapping for polygons`() { | ||
| builder.alpha("alpha") | ||
| assertEquals("alpha", (builder.bindingCollector.mappings[ALPHA] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `alpha dataColumn mapping for polygons`() { | ||
| builder.alpha(alpha) | ||
| assertEquals("alpha", (builder.bindingCollector.mappings[ALPHA] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderColor const for polygons`() { | ||
| builder.borderLine.color = Color.BLACK | ||
| assertEquals(Color.BLACK, (builder.bindingCollector.settings[COLOR] as NonPositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderColor str mapping for polygons`() { | ||
| builder.borderLine.color("borderColor") | ||
| assertEquals("borderColor", (builder.bindingCollector.mappings[COLOR] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderColor dataColumn mapping for polygons`() { | ||
| builder.borderLine.color(borderColor) | ||
| assertEquals("borderColor", (builder.bindingCollector.mappings[COLOR] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderSize const for polygons`() { | ||
| builder.borderLine.width = 2.0 | ||
| assertEquals(2.0, (builder.bindingCollector.settings[SIZE] as NonPositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderSize str mapping for polygons`() { | ||
| builder.borderLine.width("borderSize") | ||
| assertEquals("borderSize", (builder.bindingCollector.mappings[SIZE] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `borderSize dataColumn mapping for polygons`() { | ||
| builder.borderLine.width(borderSize) | ||
| assertEquals("borderSize", (builder.bindingCollector.mappings[SIZE] as NonPositionalMapping<*, *>).columnID) | ||
| } | ||
|
|
||
| @Test | ||
| fun `x const for polygons`() { | ||
| builder.x.constant(0.5) | ||
| assertEquals(X, (builder.bindingCollector.settings[X] as PositionalSetting<*>).aes) | ||
| assertEquals(0.5, (builder.bindingCollector.settings[X] as PositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `y const for polygons`() { | ||
| builder.y.constant("B") | ||
| assertEquals(Y, (builder.bindingCollector.settings[Y] as PositionalSetting<*>).aes) | ||
| assertEquals("B", (builder.bindingCollector.settings[Y] as PositionalSetting<*>).value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `x for polygons`() { | ||
| builder.x(xAxis) { | ||
| axis { | ||
| name = "Polygon X Axis" | ||
| } | ||
| scale = continuous(0.0..2.0) | ||
| } | ||
|
|
||
| assertEquals(X, builder.bindingCollector.mappings[X]?.aes) | ||
| assertEquals("xAxis", builder.bindingCollector.mappings[X]?.columnID) | ||
| assertEquals(0.0, (builder.bindingCollector.mappings[X]?.parameters?.scale as PositionalContinuousScale<*>).min) | ||
| assertEquals(2.0, (builder.bindingCollector.mappings[X]?.parameters?.scale as PositionalContinuousScale<*>).max) | ||
| } | ||
|
|
||
| @Test | ||
| fun `y for polygons`() { | ||
| builder.y(yAxis) { | ||
| axis { | ||
| name = "Polygon Y Axis" | ||
| } | ||
| scale = categorical(listOf("A", "B", "C")) | ||
| } | ||
|
|
||
| assertEquals(Y, builder.bindingCollector.mappings[Y]?.aes) | ||
| assertEquals("yAxis", builder.bindingCollector.mappings[Y]?.columnID) | ||
| assertEquals( | ||
| listOf("A", "B", "C"), | ||
| (builder.bindingCollector.mappings[Y]?.parameters?.scale as PositionalCategoricalScale<*>).categories | ||
| ) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X, Y, FILL - from what namespace they were imported?