I have this x axis:
private fun createxAxis(builder: SciChartBuilder, firstDay: Date?): DateAxis {
val weekAgo = Calendar.getInstance().let {
it.time = Date()
it.add(Calendar.DATE, -6)
it.time
}
val today = Calendar.getInstance().let {
it.time = Date()
it.add(Calendar.DATE, 1)
it.time
}
val historicalFirst = if (firstDay != null) {
Calendar.getInstance().let {
it.time = firstDay
it.add(Calendar.DAY_OF_MONTH, -1)
it.time
}
} else {
weekAgo
}
return builder.newDateAxis().apply {
withDrawLabels(true)
withDrawMajorBands(false)
withDrawMajorTicks(false)
withDrawMinorTicks(false)
withTextFormatting("E")
withTickLabelStyle(
FontStyle(
ResourcesCompat.getFont(context, R.font.proxima_nova_400),
context.resources.getDimension(R.dimen._9sdp),
resources.getColor(R.color.white, null),
true
)
)
withAutoFitMarginalLabels(false)
withDrawMajorGridLines(true)
withDrawMinorGridLines(false)
isEnabled = true
withVisibleRange(weekAgo, today)
withVisibleRangeLimit(historicalFirst, today)
}.build()
}
and this pan modifier:
private class CustomXAxisDragModifier(
val gestureCallback: WeakReference
) : XAxisDragModifier() {
override fun performPan(xDelta: Float, yDelta: Float, isSecondHalf: Boolean, axis: IAxis) {
super.performPan(xDelta, yDelta, isSecondHalf, axis)
when (axis) {
is DateAxis -> {
gestureCallback.get()
?.onVisibleRangeUpdated(axis.visibleRange.min, axis.visibleRange.max)
}
}
}
}
val panModifier = CustomXAxisDragModifier(WeakReference(callback)).apply {
dragMode = AxisDragModifierBase.AxisDragMode.Pan
minTouchArea = 1000.0f
clipModeX = ClipMode.ClipAtExtents
clipModeTargetX = ClipModeTarget.VisibleRangeLimit
}
surface.chartModifiers.add(panModifier)
When I load this chart with data, it looks correct (see first screenshot). But the moment I try to drag it, the chart clips to the most recent data point (see second screenshot) instead of what I’m setting as the visible range limit. The most recent data point is a few days before today. How can I get the panning to clip at the visible range limit?
- Marcela Guerra asked 2 weeks ago
- last edited 2 weeks ago
-
Would appreciate some help with this still. I can’t find a workaround. Let me know if more details are needed. There doesn’t appear to be any reason why the visible range keeps jumping to only where the data is and can’t go beyond where the data is
-
One other piece of information: when i set the clip mode to “None” or “Stretch” the problem goes away, but then there’s the problem of the xaxis stretching when i try panning to the edge. Also, I’ve tried setting `clipModeTargetX` to all the other values and it’s still the same result. It always behaves as if `clipModeTargetX` is set to `DataRange`
-
Also, when i try printing out the visible range limit of the axis as I’m panning the values never change, but the chart always clips to DataRange instead
-
i found a workaround by using the ZoomPanModifier class instead. It doesn’t appear to have the same issue and will clip to visible range limits instead of only data range
- You must login to post comments
Please login first to submit.