Skip to content
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

Remove map_id, add sym_x and sym_y #148

Merged
merged 11 commits into from
Jun 15, 2020
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
IKupriyanov-HORIS committed Jun 9, 2020
commit e79089b218351cd7c8c0b8df1559ff7b68fa8212
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ class LiveMap : PlotConfigDemoBase() {
{
"geom":"livemap",
"mapping":{
"map_id":"lonlat",
"x":"x",
"y":"y",
"color":"label"
},
"display_mode":"point",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Aes<T> private constructor(val name: String, val isNumeric: Boolean = true
aes == ANGLE ||
aes == FAMILY ||
aes == FONTFACE ||
aes == SYM_X ||
aes == SYM_Y ||
isPositional(aes)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package jetbrains.datalore.plot.base.geom

import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.base.values.SomeFig
import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.plot.base.*
import jetbrains.datalore.plot.base.geom.legend.GenericLegendKeyElementFactory
Expand Down Expand Up @@ -49,7 +47,6 @@ class LiveMapGeom(private val myDisplayMode: DisplayMode) : Geom {

// ToDo: not static, depends on 'display mode'
// val RENDERS = listOf(
// Aes.MAP_ID,
// Aes.ALPHA,
// Aes.COLOR,
// Aes.FILL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class MapGeom : PolygonGeom() {
// Aes.COLOR,
// Aes.FILL,
// Aes.ALPHA,
//
// Aes.MAP_ID
// )

const val HANDLES_GROUPS = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class RectGeom : GeomBase() {
// Aes.COLOR,
// Aes.FILL,
// Aes.ALPHA,
// Aes.MAP_ID
// )
//rectangle groups are used in geom_livemap
const val HANDLES_GROUPS = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,12 @@ object Option {
object GeoDataFrame {
const val GDF = "geodataframe"
const val GEOMETRY = "geometry"

// Column with geometries extracted from GeoDataFrame. Can be used either in DATA and MAP
const val GEOMETRIES = "__geometry__"
}

object GeoDict {
const val TAG = "geodict"
}

object MapJoin {
// column in map used for join with data
const val MAP_ID = "__map_id__"
}

object MappingAnnotation {
const val TAG = "mapping_annotations"
const val AES = "aes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import jetbrains.datalore.plot.builder.interact.GeomInteractionBuilder.Companion
import jetbrains.datalore.plot.builder.theme.Theme
import jetbrains.datalore.plot.builder.tooltip.CompositeValue
import jetbrains.datalore.plot.builder.tooltip.TooltipLineSpecification
import jetbrains.datalore.plot.config.Option.Meta.MapJoin

object PlotConfigClientSideUtil {
internal fun createGuideOptionsMap(scaleConfigs: List<ScaleConfig<*>>): Map<Aes<*>, GuideOptions> {
Expand Down Expand Up @@ -255,7 +254,8 @@ object PlotConfigClientSideUtil {
}

// remove auto generated mappings
aesListForTooltip.removeAll { layerConfig.getScaleForAes(it)?.name == MapJoin.MAP_ID }
val autoGenerated = listOf<String>()
aesListForTooltip.removeAll { layerConfig.getScaleForAes(it)?.name in autoGenerated }

return aesListForTooltip
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
package plot.config

import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.config.LayerConfig
import jetbrains.datalore.plot.config.Option
import jetbrains.datalore.plot.config.*
import jetbrains.datalore.plot.config.Option.GeomName.POINT
import jetbrains.datalore.plot.config.Option.Layer.GEOM
import jetbrains.datalore.plot.config.Option.Meta.DATA_META
import jetbrains.datalore.plot.config.Option.Meta.GeoDataFrame
import jetbrains.datalore.plot.config.Option.Meta.KIND
import jetbrains.datalore.plot.config.Option.Meta.Kind.PLOT
import jetbrains.datalore.plot.config.Option.Plot.LAYERS
import jetbrains.datalore.plot.config.Option.PlotBase.DATA
import jetbrains.datalore.plot.config.Option.PlotBase.MAPPING
import jetbrains.datalore.plot.config.PlotConfigClientSideUtil
import jetbrains.datalore.plot.server.config.PlotConfigServerSide
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -29,9 +35,9 @@ class GeomInteractionBuilderCreationTest {
)
val plotOpts = mutableMapOf(
MAPPING to mappedData,
Option.Plot.LAYERS to listOf(
LAYERS to listOf(
mapOf(
Option.Layer.GEOM to Option.GeomName.HISTOGRAM
GEOM to Option.GeomName.HISTOGRAM
)
)
)
Expand All @@ -50,72 +56,6 @@ class GeomInteractionBuilderCreationTest {
assertAesListCount(expectedAesListCount, builder.aesListForTooltip)
}

/* TODO: Fix MAP_ID
@Test
fun shouldSkipMapIdMapping() {
val mappedData = data + mapOf(
Aes.MAP_ID.name to listOf('a')
)
val plotOpts = mutableMapOf(
MAPPING to mappedData,
Option.Plot.LAYERS to listOf(
mapOf(
Option.Layer.GEOM to Option.GeomName.POINT
)
)
)
val layerConfig = createLayerConfig(plotOpts)

val builder = PlotConfigClientSideUtil.createGeomInteractionBuilder(
layerConfig,
emptyList(),
false
)

assertFalse { builder.aesListForTooltip.contains(Aes.MAP_ID) }

val expectedAxisList = listOf(Aes.X, Aes.Y)
// without Aes.MAP_ID:
val expectedAesListCount = (layerConfig.geomProto.renders() - expectedAxisList).size - 1

assertAesListCount(expectedAxisList.size, builder.axisAesListForTooltip)
assertAesListCount(expectedAesListCount, builder.aesListForTooltip)
}

@Test
fun shouldSkipMapIdMappingAndAxisVisibilityIsFalse() {
val mappedData = data + mapOf(
Aes.MAP_ID.name to listOf('a')
)

val plotOpts = mutableMapOf(
MAPPING to mappedData,
Option.Plot.LAYERS to listOf(
mapOf(
Option.Layer.GEOM to Option.GeomName.POLYGON
)
)
)
val layerConfig = createLayerConfig(plotOpts)

val builder = PlotConfigClientSideUtil.createGeomInteractionBuilder(
layerConfig,
emptyList(),
false
)

assertFalse { builder.aesListForTooltip.contains(Aes.MAP_ID) }

// builder's axis tooltip visibility is false:
val expectedAxisCount = 0
// without Aes.MAP_ID:
val expectedAesListCount = (layerConfig.geomProto.renders() - listOf(Aes.X, Aes.Y)).size - 1

assertAesListCount(expectedAxisCount, builder.axisAesListForTooltip)
assertAesListCount(expectedAesListCount, builder.aesListForTooltip)

}*/

@Test
fun shouldNotDuplicateVarToAxisAndGenericTooltip() {
val mappedData = mapOf(
Expand All @@ -125,9 +65,9 @@ class GeomInteractionBuilderCreationTest {

val plotOpts = mutableMapOf(
MAPPING to mappedData,
Option.Plot.LAYERS to listOf(
LAYERS to listOf(
mapOf(
Option.Layer.GEOM to Option.GeomName.HISTOGRAM
GEOM to Option.GeomName.HISTOGRAM
)
)
)
Expand All @@ -149,56 +89,59 @@ class GeomInteractionBuilderCreationTest {
assertAesListCount(expectedAesListCount, builder.aesListForTooltip)
}

/* TODO: Fix MAP_ID
@Test
fun shouldSkipAutoGeneratedMappings() {

val GEOMETRIES = listOf(
"{\"type: \"Point\", \"coordinates\":[-10, -20]}",
"{\"type: \"Point\", \"coordinates\":[-30, -40]}",
"{\"type: \"Point\", \"coordinates\":[-50, -60]}"
"{\"type\": \"Point\", \"coordinates\":[-10, -20]}",
"{\"type\": \"Point\", \"coordinates\":[-30, -40]}",
"{\"type\": \"Point\", \"coordinates\":[-50, -60]}"
)
val geomData = mapOf(
"name" to listOf("a", "b", "c"),
"value" to listOf("1", "2", "3"),
"coord" to GEOMETRIES
)
val GEO_DATA_FRAME_META = mapOf(
Option.Meta.GeoDataFrame.TAG to mapOf(
Option.Meta.GeoDataFrame.GEOMETRY_COLUMN_NAME to "coord"
GeoDataFrame.GDF to mapOf(
GeoDataFrame.GEOMETRY to "coord"
)
)
val plotOpts = mutableMapOf(
Option.Meta.KIND to Option.Meta.Kind.PLOT,
Option.Plot.LAYERS to listOf(
KIND to PLOT,
LAYERS to listOf(
mutableMapOf(
Option.Layer.GEOM to Option.GeomName.POLYGON,
GEOM to POINT,
DATA to geomData,
Option.Meta.DATA_META to GEO_DATA_FRAME_META,
DATA_META to GEO_DATA_FRAME_META,
MAPPING to mapOf(Aes.FILL.name to "name")
)
)
)
val layerConfig = createLayerConfig(plotOpts)

val binding = layerConfig.varBindings.find { it.variable.name == MapJoin.ID }
assertNotNull(binding)

val opts = PlotConfigServerSide.processTransform(plotOpts)
val layerConfig = PlotConfigClientSide.create(opts).layerConfigs.first()

val pointX = layerConfig.varBindings.find { it.variable.name == POINT_X }
val pointY = layerConfig.varBindings.find { it.variable.name == POINT_Y }

val builder = PlotConfigClientSideUtil.createGeomInteractionBuilder(
layerConfig,
emptyList(),
false
)

assertFalse { builder.aesListForTooltip.contains(binding.aes) }
}*/
assertFalse { builder.aesListForTooltip.contains(pointX!!.aes) }
assertFalse { builder.aesListForTooltip.contains(pointY!!.aes) }
}

private fun createLayerConfig(plotOpts: MutableMap<String, Any>): LayerConfig {
val plotSpec = PlotConfigServerSide.processTransform(plotOpts)
return PlotConfigServerSide(plotSpec).layerConfigs.first()
}

internal fun assertAesListCount(expectedCount: Int, aesList: List<Aes<*>>) {
private fun assertAesListCount(expectedCount: Int, aesList: List<Aes<*>>) {
assertEquals(expectedCount, aesList.size)
}
}
9 changes: 4 additions & 5 deletions plot-config/src/jvmTest/kotlin/plot/config/ConfigUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package jetbrains.datalore.plot.config

import jetbrains.datalore.plot.base.DataFrame
import jetbrains.datalore.plot.base.DataFrame.Variable
import jetbrains.datalore.plot.config.Option.Meta.MapJoin.MAP_ID
import org.assertj.core.api.Assertions.assertThat
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -21,20 +20,20 @@ class ConfigUtilTest {
val dataValues = listOf("a", "b", "c", "d")

val data = DataFrame.Builder()
.put(Variable(MAP_ID), idList)
.put(Variable("id"), idList)
.put(Variable("foo"), dataValues)
.build()

val map = DataFrame.Builder()
.put(Variable(MAP_ID), idList)
.put(Variable("id"), idList)
.put(Variable("lon"), listOf(13.0, 24.0, -65.0, 117.0))
.put(Variable("lat"), listOf(42.0, 21.0, -12.0, 77.0))
.build()

val joinedDf = ConfigUtil.rightJoin(data, MAP_ID, map, MAP_ID)
val joinedDf = ConfigUtil.rightJoin(data, "id", map, "id")

assertThat(joinedDf.variables().map { it.toString() })
.containsExactlyInAnyOrder(MAP_ID, "foo", "lon", "lat")
.containsExactlyInAnyOrder("id", "foo", "lon", "lat")

var dataVar: Variable? = null
for (variable in joinedDf.variables()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import jetbrains.datalore.plot.builder.tooltip.MappedAes
import jetbrains.datalore.plot.builder.tooltip.VariableValue
import jetbrains.datalore.plot.config.LayerConfig
import jetbrains.datalore.plot.config.Option.Geom.Choropleth.GEO_POSITIONS
import jetbrains.datalore.plot.config.Option.Meta.GeoDataFrame.GEOMETRIES
import jetbrains.datalore.plot.config.Option.Meta.MapJoin.MAP_ID
import org.assertj.core.api.AbstractAssert
import org.assertj.core.api.Assertions
import kotlin.test.assertEquals
Expand Down Expand Up @@ -76,14 +74,6 @@ class SingleLayerAssert private constructor(layers: List<LayerConfig>) :
return this
}

internal fun haveMapIds(expectedIds: List<*>): SingleLayerAssert {
return haveMapValues(MAP_ID, expectedIds)
}

internal fun haveMapGeometries(expectedGeometries: List<*>): SingleLayerAssert {
return haveMapValues(GEOMETRIES, expectedGeometries)
}

private fun haveMapValues(key: String, expectedMapValues: List<*>): SingleLayerAssert {
val geoPositions = myLayer[GEO_POSITIONS] as Map<*, *>?
assertTrue(geoPositions!!.containsKey(key))
Expand Down
Loading