Skip to content

Conversation

darkerthan-black
Copy link

Separated CandleStick Chart commit and implemented relative coordinates for mouse tracking.

Copy link
Member

@gsteckman gsteckman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a flaw in the approach of handling pointer move events here, in that the modifier is on the HoverableElementArea instead of directly on the chart area where it is desired to capture the mouse events. Additionally it updates a value in the scope class, which won't necessarily cause any action to be executed in client code. Instead, put the pointer input event handler modifier directly on the component needed so the mouse coordinates do not need to be adjusted for other elements, and then callback an optional user function to handle the updated pointer position.

@Composable
public fun <X, Y : Comparable<Y>> XYGraphScope<X, Y>.CandleStickPlot(
defaultCandle: @Composable BarScope.(entry: CandleStickPlotEntry<X, Y>) -> Unit = { _ -> },
modifier: Modifier = Modifier,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifier should be the 1st optional parameter to the function

)
}

internal class CandleStickPlotScopeImpl<X, Y>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class should implement equals() and hashCode()

@ExperimentalKoalaPlotApi
@Composable
public fun <X, Y : Comparable<Y>> XYGraphScope<X, Y>.CandleStickPlot(
defaultCandle: @Composable BarScope.(entry: CandleStickPlotEntry<X, Y>) -> Unit = { _ -> },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a @composable for the hover element. In that case, this variable name is not clear as it looks like its for the candle shape itself.


@ExperimentalKoalaPlotApi
@Composable
public fun <X, Y : Comparable<Y>> XYGraphScope<X, Y>.CandleStickPlot(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments documenting all parameters.

)?
) {
data.add(entry)
if (candleContent != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics of candleContent is not obvious here. If item is called more than once with a different candleContent, the subsequent values are going to override the previous values. Either this should allow overriding the default value individually for each data point, or this should be removed and only the value provided to CandlestickPlot should be used.

@@ -1,16 +1,12 @@
@file:Suppress("TooManyFunctions") // expected

package io.github.koalaplot.core.xygraph
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of changes in this file and its hard for me to track all of them and what the purpose is when so many are making things that were not nullable, now nullable, or format changes. Nullable values should be avoided. To extract the mouse coordinates, can't that be done in the existing Modifier.onGestureInput, or by adding a Modifier.pointerInput, that is wrapping the chart content? Also, I think there should be a callback function to pass the mouse coordinates back to the user rather than putting them into the XYGraphScope, because I don't think that will cause a recomposition which might be required depending on what the user is doing.

//
// Based on the measurement results, calculate mouse coordinates and create Scope
//
val mouseAbsoluteOffset = getCurrentPointer() // Absolute screen coordinates (FractionalOffset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a lot of changes had to be made to the layout, etc. because of this approach of getting the mouse pointer position via the HoverableElementArea (which is wrapping axes and labels in addition to the chart area). Instead, add a pointerInput Modifier on the original subcompose("chart"), adjacent to where the panZoomModifier is, e.g., append it to the modifier chain where the panZoomModifier is applied modifier = Modifier.clip(RectangleShape).then(panZoomModifier) . Then add a parameter to XYGraph that is a callback for mouse events in the axes coordinate space, e.g., pointerPosition: (x: X, y: Y) -> Unit. Then all you have to do on pointer position events is transform the coordinate through the axes models, and call the user provided pointerPosition callback function.


return copy(yAxisLabelAreaWidth = yAxisLabelAreas.maxOfOrNull { it.width } ?: 0)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add the pointerInput modifier to the Box wrapping the chartScope.content(), then I think none of this is needed.

blendMode = blendMode
)
}
private fun DrawScope.drawGridLine(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If multiple parameters on a single line doesn't violate the line length rules check, please don't split onto multiple lines.

}
}

override fun getCurrentPointer(): Offset {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the mouse is moved the currentPosition is updated, but how will client code know it needs to call getCurrentPosition to update whatever it wants to do with an updated mouse position?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants