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
sym_x and sym_y in geom_livemap for pie/bar, x and y for positions
  • Loading branch information
IKupriyanov-HORIS committed Jun 9, 2020
commit 0345d83cf69490f6353ac35c63aaa348dba2bfcd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package jetbrains.datalore.plot.livemap

import jetbrains.datalore.base.typedGeometry.explicitVec
import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.base.Aesthetics
import jetbrains.datalore.plot.base.DataPointAesthetics
import jetbrains.datalore.plot.base.aes.AesInitValue
import jetbrains.datalore.plot.base.livemap.LiveMapOptions
import jetbrains.datalore.plot.base.livemap.LivemapConstants
import jetbrains.datalore.plot.livemap.LiveMapUtil.createLayersConfigurator
import jetbrains.datalore.plot.livemap.MapLayerKind.POINT
import jetbrains.datalore.plot.livemap.MultiDataPointHelper.SortingMode
import jetbrains.livemap.api.LayersBuilder

Expand All @@ -34,7 +34,7 @@ internal class LiveMapDataPointAestheticsProcessor(
private fun getLayerKind(displayMode: LivemapConstants.DisplayMode): MapLayerKind {
return when (displayMode) {
LivemapConstants.DisplayMode.POLYGON -> MapLayerKind.POLYGON
LivemapConstants.DisplayMode.POINT -> POINT
LivemapConstants.DisplayMode.POINT -> MapLayerKind.POINT
LivemapConstants.DisplayMode.PIE -> MapLayerKind.PIE
LivemapConstants.DisplayMode.HEATMAP -> MapLayerKind.HEATMAP
LivemapConstants.DisplayMode.BAR -> MapLayerKind.BAR
Expand All @@ -55,23 +55,28 @@ internal class LiveMapDataPointAestheticsProcessor(

private fun processDataPoints(): List<MapEntityBuilder> {
return myAesthetics.dataPoints()
.map { MapEntityBuilder(it, myLayerKind).apply { setIfNeeded() } }
.map { MapEntityBuilder(it, myLayerKind).apply { setIfNeeded(it) } }
}

private fun processMultiDataPoints(): List<MapEntityBuilder> {
return MultiDataPointHelper
.getPoints(myAesthetics, getSortingMode(myLayerKind))
.map { MapEntityBuilder(it, myLayerKind).apply { setIfNeeded() } }
.map { MapEntityBuilder(it, myLayerKind).apply { setIfNeeded(it.aes) } }
}

private fun useMultiDataPoint(): Boolean {
return myLayerKind === MapLayerKind.PIE || myLayerKind === MapLayerKind.BAR
}

private fun MapEntityBuilder.setIfNeeded() {
private fun MapEntityBuilder.setIfNeeded(p: DataPointAesthetics) {
setGeometryPointIfNeeded(p, this)
setGeodesicIfNeeded(this)
}

private fun setGeometryPointIfNeeded(p: DataPointAesthetics, mapEntityBuilder: MapEntityBuilder) {
mapEntityBuilder.setGeometryPoint(explicitVec(p.x()!!, p.y()!!))
}

private fun setGeodesicIfNeeded(mapEntityBuilder: MapEntityBuilder) {
if (myLayerKind == MapLayerKind.PATH) {
mapEntityBuilder.geodesic = myGeodesic
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.render.svg.TextLabel.HorizontalAnchor.*
import jetbrains.datalore.plot.base.render.svg.TextLabel.VerticalAnchor.*
import jetbrains.datalore.plot.builder.scale.DefaultNaValue
import jetbrains.livemap.api.*
import jetbrains.datalore.plot.livemap.MapLayerKind.*
import jetbrains.livemap.api.*
import kotlin.math.ceil

internal class MapEntityBuilder {
Expand Down Expand Up @@ -109,7 +109,7 @@ internal class MapEntityBuilder {
}

private fun allZeroes(values: List<Double>): Boolean {
return values.all { value -> value == 0.0 }
return values.all(0.0::equals)
}

private fun createNaColorList(size: Int): List<Color> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package jetbrains.datalore.plot.livemap

import jetbrains.datalore.base.spatial.LonLat
import jetbrains.datalore.base.typedGeometry.Vec
import jetbrains.datalore.base.typedGeometry.explicitVec
import jetbrains.datalore.base.values.Color
import jetbrains.datalore.plot.base.Aesthetics
import jetbrains.datalore.plot.base.DataPointAesthetics
Expand All @@ -14,10 +17,12 @@ internal class MultiDataPointHelper private constructor(

companion object {
fun getPoints(aesthetics: Aesthetics, sortingMode: SortingMode): List<MultiDataPoint> {
val builders = HashMap<Any, MultiDataPointBuilder>()
val builders = HashMap<Vec<LonLat>, MultiDataPointBuilder>()

fun fetchBuilder(p: DataPointAesthetics): MultiDataPointBuilder =
builders.getOrPut(p.group()!!, { MultiDataPointBuilder(p, sortingMode) })
fun fetchBuilder(p: DataPointAesthetics): MultiDataPointBuilder {
val coord = explicitVec<LonLat>(p.x()!!, p.y()!!)
return builders.getOrPut(coord, { MultiDataPointBuilder(p, sortingMode) })
}

aesthetics.dataPoints().forEach { fetchBuilder(it).add(it) }
return builders.values.map { it.build() }
Expand Down

This file was deleted.

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

package jetbrains.datalore.plot.livemap

import jetbrains.datalore.base.spatial.LonLat
import jetbrains.datalore.base.typedGeometry.Vec
import jetbrains.datalore.base.typedGeometry.explicitVec
import jetbrains.datalore.plot.base.Aesthetics
import jetbrains.datalore.plot.base.aes.AestheticsBuilder
import jetbrains.datalore.plot.base.aes.AestheticsBuilder.Companion.collection
Expand Down Expand Up @@ -102,7 +105,7 @@ class MultiDataPointHelperTest {
) {
val points = myMultiDataBuilder
.sortingMode(sortingMode)
.multiData("TX", dataPointBuilders)
.multiData(explicitVec(0.0, 0.0), dataPointBuilders)
.points

assertPointsOrder(
Expand All @@ -126,13 +129,13 @@ class MultiDataPointHelperTest {
for (pointBuilder in myPoints) {
values.add(pointBuilder.myValue)
order.add(pointBuilder.myOrder)
mapId.add(pointBuilder.myMapId)
mapId.add(pointBuilder.myCoord)
}

myBuilder
//.mapId(collection(mapId)) // TODO: Fix MAP_ID
.x(collection(order))
.y(collection(values))
.symX(collection(order))
.symY(collection(values))
.dataPointCount(order.size)

return myBuilder.build()
Expand All @@ -143,9 +146,9 @@ class MultiDataPointHelperTest {
return this
}

fun multiData(mapId: Any, v: List<DataPointBuilder>): MultiDataBuilder {
fun multiData(coord: Vec<LonLat>, v: List<DataPointBuilder>): MultiDataBuilder {
for (point in v) {
point.mapId(mapId)
point.coord(coord)
myPoints.add(point)
}
return this
Expand All @@ -154,7 +157,7 @@ class MultiDataPointHelperTest {
internal class DataPointBuilder {
var myValue: Double = 0.0
var myOrder: Double = 0.0
lateinit var myMapId: Any
lateinit var myCoord: Vec<LonLat>

fun value(v: Double): DataPointBuilder {
myValue = v
Expand All @@ -166,8 +169,8 @@ class MultiDataPointHelperTest {
return this
}

fun mapId(v: Any): DataPointBuilder {
myMapId = v
fun coord(v: Vec<LonLat>): DataPointBuilder {
myCoord = v
return this
}
}
Expand Down