renderMarker method
void
renderMarker(
- CartesianSeriesRenderer seriesRenderer,
- CartesianChartPoint point,
- Animation<
double> ? animationController, - Canvas canvas,
- int markerIndex, [
- int? outlierIndex,
To paint the marker here
Implementation
void renderMarker(
CartesianSeriesRenderer seriesRenderer,
CartesianChartPoint<dynamic> point,
Animation<double>? animationController,
Canvas canvas,
int markerIndex,
[int? outlierIndex]) {
final bool isDataPointVisible = _isLabelWithinRange(
seriesRenderer, seriesRenderer._dataPoints[markerIndex]);
Paint strokePaint, fillPaint;
final XyDataSeries<dynamic, dynamic> series =
seriesRenderer._series as XyDataSeries<dynamic, dynamic>;
final Size size =
Size(series.markerSettings.width, series.markerSettings.height);
final DataMarkerType markerType = series.markerSettings.shape;
CartesianChartPoint<dynamic> point;
final bool hasPointColor = series.pointColorMapper != null;
final bool isBoxSeries =
seriesRenderer._seriesType.contains('boxandwhisker');
final double opacity = (animationController != null &&
(seriesRenderer._chartState!._initialRender! ||
seriesRenderer._needAnimateSeriesElements))
? animationController.value
: 1;
point = seriesRenderer._dataPoints[markerIndex];
Color? seriesColor = seriesRenderer._seriesColor;
if (seriesRenderer._seriesType == 'waterfall') {
seriesColor = _getWaterfallSeriesColor(
seriesRenderer._series as WaterfallSeries<dynamic, dynamic>,
point,
seriesColor);
}
_borderColor = series.markerSettings.borderColor ?? seriesColor;
_color = series.markerSettings.color;
_borderWidth = series.markerSettings.borderWidth;
if (!isBoxSeries) {
seriesRenderer._markerShapes.add(isDataPointVisible
? _getMarkerShapesPath(
markerType,
Offset(point.markerPoint!.x, point.markerPoint!.y),
size,
seriesRenderer,
markerIndex,
null,
animationController)
: null);
} else {
seriesRenderer._markerShapes.add(isDataPointVisible
? _getMarkerShapesPath(
markerType,
Offset(point.outliersPoint[outlierIndex!].x,
point.outliersPoint[outlierIndex].y),
size,
seriesRenderer,
markerIndex,
null,
animationController)
: null);
}
if (seriesRenderer._seriesType.contains('range') ||
seriesRenderer._seriesType == 'hilo') {
seriesRenderer._markerShapes2.add(isDataPointVisible
? _getMarkerShapesPath(
markerType,
Offset(point.markerPoint2!.x, point.markerPoint2!.y),
size,
seriesRenderer,
markerIndex,
null,
animationController)
: null);
}
strokePaint = Paint()
..color = point.isEmpty == true
? (series.emptyPointSettings.borderWidth == 0
? Colors.transparent
: series.emptyPointSettings.borderColor.withOpacity(opacity))
: (series.markerSettings.borderWidth == 0
? Colors.transparent
: ((hasPointColor && point.pointColorMapper != null)
? point.pointColorMapper!.withOpacity(opacity)
: _borderColor!.withOpacity(opacity)))
..style = PaintingStyle.stroke
..strokeWidth = point.isEmpty == true
? series.emptyPointSettings.borderWidth
: _borderWidth;
if (series.gradient != null && series.markerSettings.borderColor == null) {
strokePaint = _getLinearGradientPaint(
series.gradient!,
_getMarkerShapesPath(
markerType,
Offset(
isBoxSeries
? point.outliersPoint[outlierIndex!].x
: point.markerPoint!.x,
isBoxSeries
? point.outliersPoint[outlierIndex!].y
: point.markerPoint!.y),
size,
seriesRenderer,
null,
null,
animationController)
.getBounds(),
seriesRenderer._chartState!._requireInvertedAxis);
strokePaint.style = PaintingStyle.stroke;
strokePaint.strokeWidth = point.isEmpty == true
? series.emptyPointSettings.borderWidth
: series.markerSettings.borderWidth;
}
fillPaint = Paint()
..color = point.isEmpty == true
? series.emptyPointSettings.color
: _color != Colors.transparent
? (_color ??
(seriesRenderer._chartState!._chartTheme.brightness ==
Brightness.light
? Colors.white
: Colors.black))
.withOpacity(opacity)
: _color!
..style = PaintingStyle.fill;
final bool isScatter = seriesRenderer._seriesType == 'scatter';
final Rect axisClipRect =
seriesRenderer._chartState!._chartAxis._axisClipRect;
/// Render marker points
if ((series.markerSettings.isVisible || isScatter || isBoxSeries) &&
point.isVisible &&
_withInRect(seriesRenderer, point.markerPoint, axisClipRect) &&
(point.markerPoint != null ||
// ignore: unnecessary_null_comparison
point.outliersPoint[outlierIndex!] != null) &&
point.isGap != true &&
(!isScatter || series.markerSettings.shape == DataMarkerType.image) &&
seriesRenderer
._markerShapes[isBoxSeries ? outlierIndex! : markerIndex] !=
null) {
seriesRenderer.drawDataMarker(
isBoxSeries ? outlierIndex! : markerIndex,
canvas,
fillPaint,
strokePaint,
isBoxSeries
? point.outliersPoint[outlierIndex!].x
: point.markerPoint!.x,
isBoxSeries
? point.outliersPoint[outlierIndex!].y
: point.markerPoint!.y,
seriesRenderer);
if (series.markerSettings.shape == DataMarkerType.image) {
_drawImageMarker(
seriesRenderer,
canvas,
isBoxSeries
? point.outliersPoint[outlierIndex!].x
: point.markerPoint!.x,
isBoxSeries
? point.outliersPoint[outlierIndex!].y
: point.markerPoint!.y);
if (seriesRenderer._seriesType.contains('range') ||
seriesRenderer._seriesType == 'hilo') {
_drawImageMarker(seriesRenderer, canvas, point.markerPoint2!.x,
point.markerPoint2!.y);
}
}
}
}