Skip to content

Commit

Permalink
Markers shape rotation of points on livemap (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
RYangazov committed May 29, 2024
1 parent 72ec10f commit 89daf2c
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 4 deletions.
178 changes: 178 additions & 0 deletions docs/dev/notebooks/LP-736-livemap.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PointEntityBuilder(
var animation: Int = 0
var label: String = ""
var shape: Int = 1
var angle: Double = 0.0

fun build(nonInteractive: Boolean = false): EcsEntity {
val d = radius * 2.0
Expand All @@ -80,7 +81,7 @@ class PointEntityBuilder(
+IndexComponent(layerIndex!!, index!!)
}
+ RenderableComponent().apply {
renderer = PointRenderer(shape)
renderer = PointRenderer(shape, angle)
}
+ChartElementComponent().apply {
sizeScalingRange = this@PointEntityBuilder.sizeScalingRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.jetbrains.letsPlot.livemap.chart.point

import org.jetbrains.letsPlot.commons.intern.math.toRadians
import org.jetbrains.letsPlot.core.canvas.Context2d
import org.jetbrains.letsPlot.livemap.chart.ChartElementComponent
import org.jetbrains.letsPlot.livemap.chart.PointComponent
Expand All @@ -17,8 +18,10 @@ import kotlin.math.PI
import kotlin.math.sqrt

class PointRenderer(
private val shape: Int
private val shape: Int,
degreeAngle: Double
) : Renderer {
private val angle = toRadians(degreeAngle)

override fun render(entity: EcsEntity, ctx: Context2d, renderHelper: RenderHelper) {
val chartElement = entity.get<ChartElementComponent>()
Expand All @@ -31,7 +34,8 @@ class PointRenderer(
ctx = ctx,
radius = pointData.scaledRadius(chartElement.scalingSizeFactor),
stroke = chartElement.scaledStrokeWidth(),
shape = shape
shape = shape,
angle = angle
)
if (chartElement.fillColor != null) {
ctx.setFillStyle(chartElement.scaledFillColor())
Expand All @@ -43,7 +47,12 @@ class PointRenderer(
ctx.stroke()
}
}
private fun drawMarker(ctx: Context2d, radius: Double, stroke: Double, shape: Int) {
private fun drawMarker(ctx: Context2d, radius: Double, stroke: Double, shape: Int, angle: Double) {
val needToRotate = shape !in listOf(1, 10, 16, 19, 20, 21) && angle != 0.0
if (needToRotate) {
ctx.rotate(angle)
}

when (shape) {
0 -> square(ctx, radius)
1 -> circle(ctx, radius)
Expand Down Expand Up @@ -94,6 +103,10 @@ class PointRenderer(
25 -> triangle(ctx, radius, stroke, pointingUp = false)
else -> throw IllegalStateException("Unknown point shape")
}

if (needToRotate) {
ctx.rotate(-angle)
}
}

private fun circle(ctx: Context2d, r: Double) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ object LayerConverter {
label = it.label
animation = it.animation
shape = it.shape
angle = it.angle
radius = it.radius
fillColor = it.fillColor
strokeColor = it.strokeColor
Expand Down

0 comments on commit 89daf2c

Please sign in to comment.