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

Markers shape rotation of points on livemap #1108

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = [email protected]
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