diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/crosshair.dart b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/crosshair.dart new file mode 100644 index 000000000..d2a1d5155 --- /dev/null +++ b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/crosshair.dart @@ -0,0 +1,1100 @@ +import 'dart:async'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart' hide Image; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:intl/intl.dart' hide TextDirection; +import 'package:syncfusion_flutter_core/core.dart'; +import 'package:syncfusion_flutter_core/theme.dart'; + +import '../axis/axis.dart'; +import '../axis/category_axis.dart'; +import '../axis/datetime_axis.dart'; +import '../axis/datetime_category_axis.dart'; +import '../axis/logarithmic_axis.dart'; +import '../axis/numeric_axis.dart'; +import '../base.dart'; +import '../common/callbacks.dart'; +import '../common/interactive_tooltip.dart'; +import '../interactions/behavior.dart'; +import '../series/chart_series.dart'; +import '../utils/constants.dart'; +import '../utils/enum.dart'; +import '../utils/helper.dart'; + +/// This class has the properties of the crosshair behavior. +/// +/// Crosshair behavior has the activation mode and line type property to set +/// the behavior of the crosshair. It also has the property to customize +/// the appearance. +/// +/// Provide options for activation mode, line type, line color, line width, +/// hide delay for customizing the behavior of the crosshair. +class CrosshairBehavior extends ChartBehavior { + /// Creating an argument constructor of [CrosshairBehavior] class. + CrosshairBehavior({ + this.activationMode = ActivationMode.longPress, + this.lineType = CrosshairLineType.both, + this.lineDashArray, + this.enable = false, + this.lineColor, + this.lineWidth = 1, + this.shouldAlwaysShow = false, + this.hideDelay = 0, + }); + + /// Toggles the visibility of the crosshair. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior(enable: true); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final bool enable; + + /// Width of the crosshair line. + /// + /// Defaults to `1`. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// lineWidth: 5 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final double lineWidth; + + /// Color of the crosshair line. + /// + /// Color will be applied based on the brightness + /// property of the app. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true,lineColor: Colors.red + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final Color? lineColor; + + /// Dashes of the crosshair line. + /// + /// Any number of values can be provided in the list. + /// Odd value is considered as rendering size and even value is + /// considered as gap. + /// + /// Defaults to `[0,0]`. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// lineDashArray: [10,10] + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final List? lineDashArray; + + /// Gesture for activating the crosshair. + /// + /// Crosshair can be activated in tap, double tap + /// and long press. + /// + /// Defaults to `ActivationMode.longPress`. + /// + /// Also refer [ActivationMode]. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// activationMode: ActivationMode.doubleTap + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final ActivationMode activationMode; + + /// Type of crosshair line. + /// + /// By default, both vertical and horizontal lines will be + /// displayed. You can change this by specifying values to this property. + /// + /// Defaults to `CrosshairLineType.both`. + /// + /// Also refer [CrosshairLineType]. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// lineType: CrosshairLineType.horizontal + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final CrosshairLineType lineType; + + /// Enables or disables the crosshair. + /// + /// By default, the crosshair will be hidden on touch. + /// To avoid this, set this property to true. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// shouldAlwaysShow: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final bool shouldAlwaysShow; + + /// Time delay for hiding the crosshair. + /// + /// Defaults to `0`. + /// + /// ```dart + /// late CrosshairBehavior _crosshairBehavior; + /// + /// void initState() { + /// _crosshairBehavior = CrosshairBehavior( + /// enable: true, + /// hideDelay: 3000 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// crosshairBehavior: _crosshairBehavior + /// ); + /// } + /// ``` + final double hideDelay; + + /// Hold crosshair target position. + Offset? _position; + Timer? _crosshairHideTimer; + + final List _verticalPaths = []; + final List _horizontalPaths = []; + final List _verticalLabels = []; + final List _horizontalLabels = []; + final List _verticalLabelPositions = []; + final List _horizontalLabelPositions = []; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + + return other is CrosshairBehavior && + other.activationMode == activationMode && + other.lineType == lineType && + other.lineDashArray == lineDashArray && + other.enable == enable && + other.lineColor == lineColor && + other.lineWidth == lineWidth && + other.shouldAlwaysShow == shouldAlwaysShow && + other.hideDelay == hideDelay; + } + + @override + int get hashCode { + final List values = [ + activationMode, + lineType, + lineDashArray, + enable, + lineColor, + lineWidth, + shouldAlwaysShow, + hideDelay + ]; + return Object.hashAll(values); + } + + /// Displays the crosshair at the specified x and y-positions. + /// + /// x & y - x and y values/pixel where the crosshair needs to be shown. + /// + /// coordinateUnit - specify the type of x and y values given. `pixel` or + /// `point` for logical pixel and chart data point respectively. + /// + /// Defaults to `point`. + void show(dynamic x, double y, [String coordinateUnit = 'point']) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + assert(x != null); + assert(!y.isNaN); + if (coordinateUnit == 'point') { + _position = rawValueToPixelPoint( + x, y, parent.xAxis, parent.yAxis, parent.isTransposed); + } else if (coordinateUnit == 'pixel') { + if (x is num) { + _position = Offset(x.toDouble(), y); + } else { + _position = Offset( + rawValueToPixelPoint( + x, y, parent.xAxis, parent.yAxis, parent.isTransposed) + .dx, + y); + } + } + + _show(); + } + + /// Displays the crosshair at the specified point index. + /// + /// pointIndex - index of point at which the crosshair needs to be shown. + void showByIndex(int pointIndex) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && parent.plotArea != null) { + final XyDataSeriesRenderer? seriesRenderer = + parent.plotArea!.firstChild as XyDataSeriesRenderer?; + if (seriesRenderer != null) { + final List visibleIndexes = seriesRenderer.visibleIndexes; + if (visibleIndexes.first <= pointIndex && + pointIndex <= visibleIndexes.last) { + show(seriesRenderer.xRawValues[pointIndex], + seriesRenderer.yValues[pointIndex].toDouble()); + } + } + } + } + + /// Hides the crosshair if it is displayed. + void hide() { + _position = null; + _resetCrosshairHolders(); + (parentBox as RenderBehaviorArea?)?.invalidate(); + } + + /// To customize the necessary pointer events in behaviors. + /// (e.g., CrosshairBehavior, TrackballBehavior, ZoomingBehavior). + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (event is PointerMoveEvent) { + _handlePointerMove(event); + } else if (event is PointerHoverEvent) { + _handlePointerHover(event); + } else if (event is PointerCancelEvent || event is PointerUpEvent) { + _hideCrosshair(immediately: true); + } + } + + void _handlePointerMove(PointerMoveEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showCrosshair(parentBox!.globalToLocal(details.position)); + } + } + + void _handlePointerHover(PointerHoverEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showCrosshair(parentBox!.globalToLocal(details.position)); + } + } + + /// Called when a pointer or mouse enter on the screen. + @override + void handlePointerEnter(PointerEnterEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showCrosshair(parentBox!.globalToLocal(details.position)); + } + } + + /// Called when a pointer or mouse exit on the screen. + @override + void handlePointerExit(PointerExitEvent details) { + _hideCrosshair(immediately: true); + } + + /// Called when a long press gesture by a primary button has been + /// recognized in behavior. + @override + void handleLongPressStart(LongPressStartDetails details) { + if (activationMode == ActivationMode.longPress) { + _showCrosshair(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when moving after the long press gesture by a primary button is + /// recognized in behavior. + @override + void handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + if (activationMode == ActivationMode.longPress) { + _showCrosshair(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when the pointer stops contacting the screen after a long-press + /// by a primary button in behavior. + @override + void handleLongPressEnd(LongPressEndDetails details) { + _hideCrosshair(); + } + + /// Called when the pointer tap has contacted the screen in behavior. + @override + void handleTapDown(TapDownDetails details) { + if (activationMode == ActivationMode.singleTap) { + _showCrosshair(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when pointer has stopped contacting screen in behavior. + @override + void handleTapUp(TapUpDetails details) { + _hideCrosshair(); + } + + /// Called when pointer tap has contacted the screen double time in behavior. + @override + void handleDoubleTap(Offset position) { + if (activationMode == ActivationMode.doubleTap) { + _showCrosshair(parentBox!.globalToLocal(position)); + _hideCrosshair(doubleTapHideDelay: 200); + } + } + + void _showCrosshair(Offset localPosition) { + if (enable) { + show(localPosition.dx, localPosition.dy, 'pixel'); + } + } + + void _hideCrosshair({int doubleTapHideDelay = 0, bool immediately = false}) { + if (immediately) { + hide(); + } else if (!shouldAlwaysShow) { + final int hideDelayDuration = + hideDelay > 0 ? hideDelay.toInt() : doubleTapHideDelay; + _crosshairHideTimer?.cancel(); + _crosshairHideTimer = + Timer(Duration(milliseconds: hideDelayDuration), () { + _crosshairHideTimer = null; + hide(); + }); + } + } + + void _resetCrosshairHolders() { + _verticalPaths.clear(); + _horizontalPaths.clear(); + _verticalLabels.clear(); + _horizontalLabels.clear(); + _verticalLabelPositions.clear(); + _horizontalLabelPositions.clear(); + } + + void _show() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (_position == null || parent == null) { + return; + } + + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + + _calculateTooltipLabelAndPositions(parent, cartesianAxes); + parent.invalidate(); + } + + void _calculateTooltipLabelAndPositions( + RenderBehaviorArea parent, RenderCartesianAxes cartesianAxes) { + final Rect plotAreaBounds = parent.paintBounds; + if (plotAreaBounds.contains(_position!)) { + _resetCrosshairHolders(); + + final Offset plotAreaOffset = + (parent.parentData! as BoxParentData).offset; + RenderChartAxis? child = cartesianAxes.firstChild; + while (child != null) { + final InteractiveTooltip interactiveTooltip = child.interactiveTooltip; + if (child.isVisible && + interactiveTooltip.enable && + child.visibleLabels.isNotEmpty) { + final TextStyle textStyle = child.chartThemeData!.crosshairTextStyle! + .merge(interactiveTooltip.textStyle); + + final Offset parentDataOffset = + (child.parentData! as BoxParentData).offset; + final Offset axisOffset = parentDataOffset.translate( + -plotAreaOffset.dx, -plotAreaOffset.dy); + final Rect axisBounds = axisOffset & child.size; + + if (child.isVertical) { + _computeVerticalAxisTooltips( + child, + _position!, + textStyle, + axisBounds, + plotAreaBounds, + interactiveTooltip.arrowLength, + interactiveTooltip.arrowWidth, + interactiveTooltip.borderRadius, + ); + } else { + _computeHorizontalAxisTooltips( + child, + _position!, + textStyle, + axisBounds, + plotAreaBounds, + interactiveTooltip.arrowLength, + interactiveTooltip.arrowWidth, + interactiveTooltip.borderRadius, + ); + } + } + + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + } + } + + void _computeHorizontalAxisTooltips( + RenderChartAxis axis, + Offset position, + TextStyle textStyle, + Rect axisBounds, + Rect plotAreaBounds, + double arrowLength, + double arrowWidth, + double borderRadius, + ) { + final num actualXValue = _actualXValue(axis, position, plotAreaBounds); + String label = _resultantString(axis, actualXValue); + label = _triggerCrosshairCallback(axis, label, actualXValue); + final Size labelSize = measureText(label, textStyle); + + final String tooltipPosition = axis.opposedPosition ? 'Top' : 'Bottom'; + final Rect tooltipRect = _calculateTooltipRect( + tooltipPosition, position, labelSize, axisBounds, arrowLength); + + final Rect validatedRect = _validateRectBounds(tooltipRect, axisBounds); + _validateRectXPosition(validatedRect, plotAreaBounds); + + final RRect tooltipRRect = + RRect.fromRectAndRadius(validatedRect, Radius.circular(borderRadius)); + + final Path tooltipAndArrowPath = Path() + ..addRRect(tooltipRRect) + ..addPath( + _tooltipArrowHeadPath( + tooltipPosition, tooltipRRect, position, arrowLength, arrowWidth), + Offset.zero); + + _horizontalPaths.add(tooltipAndArrowPath); + _horizontalLabels.add(label); + _horizontalLabelPositions.add(_textPosition(tooltipRRect, labelSize)); + } + + void _computeVerticalAxisTooltips( + RenderChartAxis axis, + Offset position, + TextStyle textStyle, + Rect axisBounds, + Rect plotAreaBounds, + double arrowLength, + double arrowWidth, + double borderRadius, + ) { + final num actualYValue = _actualYValue(axis, position); + String label = _resultantString(axis, actualYValue); + label = _triggerCrosshairCallback(axis, label, actualYValue); + final Size labelSize = measureText(label, textStyle); + + final String tooltipPosition = axis.opposedPosition ? 'Right' : 'Left'; + final Rect tooltipRect = _calculateTooltipRect( + tooltipPosition, position, labelSize, axisBounds, arrowLength); + + final Rect validatedRect = _validateRectBounds(tooltipRect, axisBounds); + _validateRectYPosition(validatedRect, plotAreaBounds); + + final RRect tooltipRRect = + RRect.fromRectAndRadius(validatedRect, Radius.circular(borderRadius)); + + final Path tooltipAndArrowPath = Path() + ..addRRect(tooltipRRect) + ..addPath( + _tooltipArrowHeadPath( + tooltipPosition, tooltipRRect, position, arrowLength, arrowWidth), + Offset.zero); + + _verticalPaths.add(tooltipAndArrowPath); + _verticalLabels.add(label); + _verticalLabelPositions.add(_textPosition(tooltipRRect, labelSize)); + } + + num _actualXValue( + RenderChartAxis axis, Offset position, Rect plotAreaBounds) { + return axis.pixelToPoint(axis.paintBounds, + position.dx - plotAreaBounds.left, position.dy - plotAreaBounds.top); + } + + num _actualYValue(RenderChartAxis axis, Offset position) { + return axis.pixelToPoint(axis.paintBounds, position.dx, position.dy); + } + + String _triggerCrosshairCallback( + RenderChartAxis axis, String label, num value) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && + parent.onCrosshairPositionChanging != null && + parent.chartThemeData != null) { + final CrosshairRenderArgs crosshairEventArgs = CrosshairRenderArgs( + axis.widget, + _rawValue(axis, value), + axis.name, + axis.isVertical ? AxisOrientation.vertical : AxisOrientation.horizontal, + ); + crosshairEventArgs.text = label; + parent.onCrosshairPositionChanging!(crosshairEventArgs); + return crosshairEventArgs.text; + } + return label; + } + + Rect _validateRectBounds(Rect tooltipRect, Rect axisBounds) { + const double padding = 0.5; // Padding between the corners. + Rect validatedRect = tooltipRect; + double difference = 0; + + if (tooltipRect.left < axisBounds.left) { + difference = (axisBounds.left - tooltipRect.left) + padding; + validatedRect = validatedRect.translate(difference, 0); + } + if (tooltipRect.right > axisBounds.right) { + difference = (tooltipRect.right - axisBounds.right) + padding; + validatedRect = validatedRect.translate(-difference, 0); + } + if (tooltipRect.top < axisBounds.top) { + difference = (axisBounds.top - tooltipRect.top) + padding; + validatedRect = validatedRect.translate(0, difference); + } + + if (tooltipRect.bottom > axisBounds.bottom) { + difference = (tooltipRect.bottom - axisBounds.bottom) + padding; + validatedRect = validatedRect.translate(0, -difference); + } + return validatedRect; + } + + Rect _validateRectXPosition(Rect labelRect, Rect axisClipRect) { + if (labelRect.right >= axisClipRect.right) { + return Rect.fromLTRB( + labelRect.left - (labelRect.right - axisClipRect.right), + labelRect.top, + axisClipRect.right, + labelRect.bottom); + } else if (labelRect.left <= axisClipRect.left) { + return Rect.fromLTRB( + axisClipRect.left, + labelRect.top, + labelRect.right + (axisClipRect.left - labelRect.left), + labelRect.bottom); + } + return labelRect; + } + + Rect _validateRectYPosition(Rect labelRect, Rect axisClipRect) { + if (labelRect.bottom >= axisClipRect.bottom) { + return Rect.fromLTRB( + labelRect.left, + labelRect.top - (labelRect.bottom - axisClipRect.bottom), + labelRect.right, + axisClipRect.bottom); + } else if (labelRect.top <= axisClipRect.top) { + return Rect.fromLTRB(labelRect.left, axisClipRect.top, labelRect.right, + labelRect.bottom + (axisClipRect.top - labelRect.top)); + } + return labelRect; + } + + Rect _calculateTooltipRect(String axis, Offset position, Size labelSize, + Rect axisBounds, double arrowLength) { + final double labelWidthWithPadding = labelSize.width + crosshairPadding; + final double labelHeightWithPadding = labelSize.height + crosshairPadding; + switch (axis) { + case 'Left': + return Rect.fromLTWH( + axisBounds.right - labelWidthWithPadding - arrowLength, + position.dy - (labelHeightWithPadding / 2), + labelWidthWithPadding, + labelHeightWithPadding); + + case 'Right': + return Rect.fromLTWH( + axisBounds.left + arrowLength, + position.dy - (labelHeightWithPadding / 2), + labelSize.width + crosshairPadding, + labelHeightWithPadding); + + case 'Top': + return Rect.fromLTWH( + position.dx - (labelWidthWithPadding / 2), + axisBounds.bottom - labelHeightWithPadding - arrowLength, + labelWidthWithPadding, + labelHeightWithPadding); + + case 'Bottom': + return Rect.fromLTWH( + position.dx - (labelWidthWithPadding / 2), + axisBounds.top + arrowLength, + labelWidthWithPadding, + labelSize.height + crosshairPadding); + } + return Rect.zero; + } + + Path _tooltipArrowHeadPath(String axis, RRect tooltipRect, Offset position, + double arrowLength, double arrowWidth) { + final Path arrowPath = Path(); + final double tooltipLeft = tooltipRect.left; + final double tooltipRight = tooltipRect.right; + final double tooltipTop = tooltipRect.top; + final double tooltipBottom = tooltipRect.bottom; + final double rectHalfWidth = tooltipRect.width / 2; + final double rectHalfHeight = tooltipRect.height / 2; + switch (axis) { + case 'Left': + arrowPath.moveTo( + tooltipRight, tooltipTop + rectHalfHeight - arrowWidth); + arrowPath.lineTo( + tooltipRight, tooltipBottom - rectHalfHeight + arrowWidth); + arrowPath.lineTo(tooltipRight + arrowLength, position.dy); + arrowPath.close(); + return arrowPath; + + case 'Right': + arrowPath.moveTo(tooltipLeft, tooltipTop + rectHalfHeight - arrowWidth); + arrowPath.lineTo( + tooltipLeft, tooltipBottom - rectHalfHeight + arrowWidth); + arrowPath.lineTo(tooltipLeft - arrowLength, position.dy); + arrowPath.close(); + return arrowPath; + + case 'Top': + arrowPath.moveTo(position.dx, tooltipBottom + arrowLength); + arrowPath.lineTo( + (tooltipRight - rectHalfWidth) + arrowWidth, tooltipBottom); + arrowPath.lineTo( + (tooltipLeft + rectHalfWidth) - arrowWidth, tooltipBottom); + arrowPath.close(); + return arrowPath; + + case 'Bottom': + arrowPath.moveTo(position.dx, tooltipTop - arrowLength); + arrowPath.lineTo( + (tooltipRight - rectHalfWidth) + arrowWidth, tooltipTop); + arrowPath.lineTo( + (tooltipLeft + rectHalfWidth) - arrowWidth, tooltipTop); + arrowPath.close(); + return arrowPath; + } + return arrowPath; + } + + Offset _textPosition(RRect tooltipRect, Size labelSize) { + return Offset( + (tooltipRect.left + tooltipRect.width / 2) - labelSize.width / 2, + (tooltipRect.top + tooltipRect.height / 2) - labelSize.height / 2); + } + + String _resultantString(RenderChartAxis axis, num actualValue) { + final String resultantString = + _interactiveTooltipLabel(actualValue, axis).toString(); + if (axis.interactiveTooltip.format != null) { + return axis.interactiveTooltip.format! + .replaceAll('{value}', resultantString); + } else { + return resultantString; + } + } + + /// To get interactive tooltip label. + String _interactiveTooltipLabel(num value, RenderChartAxis axis) { + if (axis is RenderCategoryAxis) { + final num index = value < 0 ? 0 : value; + final List labels = axis.labels; + final int labelsLength = labels.length; + return labels[(index.round() >= labelsLength + ? (index.round() > labelsLength + ? labelsLength - 1 + : index - 1) + : index) + .round()] + .toString(); + } else if (axis is RenderDateTimeCategoryAxis) { + final num index = value < 0 ? 0 : value; + final List labels = axis.labels; + final int labelsLength = labels.length; + final int milliseconds = labels[(index.round() >= labelsLength + ? (index.round() > labelsLength ? labelsLength - 1 : index - 1) + : index) + .round()]; + final num interval = axis.visibleRange!.minimum.ceil(); + final num previousInterval = + labels.isNotEmpty ? labels[labelsLength - 1] : interval; + final DateFormat dateFormat = axis.dateFormat ?? + dateTimeCategoryAxisLabelFormat( + axis, interval.toInt(), previousInterval.toInt()); + return dateFormat + .format(DateTime.fromMillisecondsSinceEpoch(milliseconds.toInt())); + } else if (axis is RenderDateTimeAxis) { + final num interval = axis.visibleRange!.minimum.ceil(); + final List visibleLabels = axis.visibleLabels; + final num previousInterval = visibleLabels.isNotEmpty + ? visibleLabels[visibleLabels.length - 1].value + : interval; + final DateFormat dateFormat = axis.dateFormat ?? + dateTimeAxisLabelFormat( + axis, interval.toInt(), previousInterval.toInt()); + return dateFormat + .format(DateTime.fromMillisecondsSinceEpoch(value.toInt())); + } else if (axis is RenderLogarithmicAxis) { + return logAxisLabel( + axis, axis.toPow(value), axis.interactiveTooltip.decimalPlaces); + } else if (axis is RenderNumericAxis) { + return numericAxisLabel( + axis, value, axis.interactiveTooltip.decimalPlaces); + } else { + return ''; + } + } + + // It specifies for callback value field. + dynamic _rawValue(RenderChartAxis axis, num value) { + if (axis is RenderCategoryAxis) { + final num index = value < 0 ? 0 : value; + final int labelsLength = axis.labels.length; + final String? label = axis.labels[(index.round() >= labelsLength + ? (index.round() > labelsLength ? labelsLength - 1 : index - 1) + : index) + .round()]; + return axis.labels.indexOf(label); + } else if (axis is RenderDateTimeCategoryAxis) { + final num index = value < 0 ? 0 : value; + final int labelsLength = axis.labels.length; + return axis.labels[(index.round() >= labelsLength + ? (index.round() > labelsLength ? labelsLength - 1 : index - 1) + : index) + .round()]; + } else { + return value; + } + } + + /// Override this method to customize the crosshair tooltips & line rendering. + @override + void onPaint(PaintingContext context, Offset offset, + SfChartThemeData chartThemeData, ThemeData themeData) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (_position == null || parent == null) { + return; + } + + if (parent.paintBounds.contains(_position!)) { + _drawCrosshairLines(context, _position!, parent, chartThemeData); + _drawCrosshairTooltip(context, parent); + } + } + + void _drawCrosshairLines(PaintingContext context, Offset offset, + RenderBehaviorArea parent, SfChartThemeData chartThemeData) { + Color crosshairLineColor = + (lineColor ?? chartThemeData.crosshairLineColor)!; + if (parent.onCrosshairPositionChanging != null && + parent.chartThemeData != null) { + final CrosshairRenderArgs crosshairEventArgs = CrosshairRenderArgs(); + crosshairEventArgs.text = ''; + crosshairEventArgs.lineColor = crosshairLineColor; + parent.onCrosshairPositionChanging!(crosshairEventArgs); + crosshairLineColor = crosshairEventArgs.lineColor; + } + + final Paint paint = Paint() + ..isAntiAlias = true + ..color = crosshairLineColor + ..strokeWidth = lineWidth + ..style = PaintingStyle.stroke; + + switch (lineType) { + case CrosshairLineType.both: + drawHorizontalAxisLine(context, offset, lineDashArray, paint); + drawVerticalAxisLine(context, offset, lineDashArray, paint); + break; + + case CrosshairLineType.horizontal: + drawHorizontalAxisLine(context, offset, lineDashArray, paint); + break; + + case CrosshairLineType.vertical: + drawVerticalAxisLine(context, offset, lineDashArray, paint); + break; + + case CrosshairLineType.none: + break; + } + } + + /// Override this method to customize the horizontal line drawing and styling. + @protected + void drawHorizontalAxisLine(PaintingContext context, Offset offset, + List? dashArray, Paint paint) { + if (parentBox == null) { + return; + } + + final Rect plotAreaBounds = parentBox!.paintBounds; + final Offset start = Offset(plotAreaBounds.left, offset.dy); + final Offset end = Offset(plotAreaBounds.right, offset.dy); + drawDashes(context.canvas, dashArray, paint, start: start, end: end); + } + + /// Override this method to customize the vertical line drawing and styling. + @protected + void drawVerticalAxisLine(PaintingContext context, Offset offset, + List? dashArray, Paint paint) { + if (parentBox == null) { + return; + } + + final Rect plotAreaBounds = parentBox!.paintBounds; + final Offset start = Offset(offset.dx, plotAreaBounds.top); + final Offset end = Offset(offset.dx, plotAreaBounds.bottom); + drawDashes(context.canvas, dashArray, paint, start: start, end: end); + } + + void _drawCrosshairTooltip( + PaintingContext context, RenderBehaviorArea parent) { + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + + final Color themeBackgroundColor = + parent.chartThemeData!.crosshairBackgroundColor!; + _drawHorizontalAxisTooltip(context, cartesianAxes, themeBackgroundColor); + _drawVerticalAxisTooltip(context, cartesianAxes, themeBackgroundColor); + } + + void _drawHorizontalAxisTooltip(PaintingContext context, + RenderCartesianAxes cartesianAxes, Color themeBackgroundColor) { + if (_horizontalPaths.isNotEmpty && + _horizontalLabels.isNotEmpty && + _horizontalLabelPositions.isNotEmpty) { + final Paint fillPaint = Paint() + ..isAntiAlias = true + ..style = PaintingStyle.fill; + final Paint strokePaint = Paint() + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + + RenderChartAxis? child = cartesianAxes.firstChild; + int index = 0; + while (child != null) { + final InteractiveTooltip interactiveTooltip = child.interactiveTooltip; + if (!child.isVertical && + child.isVisible && + interactiveTooltip.enable && + child.visibleLabels.isNotEmpty) { + final TextStyle textStyle = child.chartThemeData!.crosshairTextStyle! + .merge(interactiveTooltip.textStyle); + fillPaint.color = interactiveTooltip.color ?? themeBackgroundColor; + strokePaint + ..color = interactiveTooltip.borderColor ?? themeBackgroundColor + ..strokeWidth = interactiveTooltip.borderWidth; + + drawHorizontalAxisTooltip( + context, + _horizontalLabelPositions[index], + _horizontalLabels[index], + textStyle, + _horizontalPaths[index], + fillPaint, + strokePaint); + + index++; + } + + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + } + } + + void _drawVerticalAxisTooltip(PaintingContext context, + RenderCartesianAxes cartesianAxes, Color themeBackgroundColor) { + if (_verticalPaths.isNotEmpty && + _verticalLabels.isNotEmpty && + _verticalLabelPositions.isNotEmpty) { + final Paint fillPaint = Paint() + ..isAntiAlias = true + ..style = PaintingStyle.fill; + final Paint strokePaint = Paint() + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + + RenderChartAxis? child = cartesianAxes.firstChild; + int index = 0; + while (child != null) { + final InteractiveTooltip interactiveTooltip = child.interactiveTooltip; + if (child.isVertical && + child.isVisible && + interactiveTooltip.enable && + child.visibleLabels.isNotEmpty) { + final TextStyle textStyle = child.chartThemeData!.crosshairTextStyle! + .merge(interactiveTooltip.textStyle); + fillPaint.color = interactiveTooltip.color ?? themeBackgroundColor; + strokePaint + ..color = interactiveTooltip.borderColor ?? themeBackgroundColor + ..strokeWidth = interactiveTooltip.borderWidth; + + drawVerticalAxisTooltip( + context, + _verticalLabelPositions[index], + _verticalLabels[index], + textStyle, + _verticalPaths[index], + fillPaint, + strokePaint); + + index++; + } + + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + } + } + + /// Override this method to customize the horizontal axis tooltip with styling + /// and it's position. + @protected + void drawHorizontalAxisTooltip( + PaintingContext context, Offset position, String text, TextStyle style, + [Path? path, Paint? fillPaint, Paint? strokePaint]) { + _drawTooltipAndLabel( + context, position, text, style, path, fillPaint, strokePaint); + } + + /// Override this method to customize the vertical axis tooltip with styling + /// and it's position. + @protected + void drawVerticalAxisTooltip( + PaintingContext context, Offset position, String text, TextStyle style, + [Path? path, Paint? fillPaint, Paint? strokePaint]) { + _drawTooltipAndLabel( + context, position, text, style, path, fillPaint, strokePaint); + } + + void _drawTooltipAndLabel( + PaintingContext context, Offset position, String text, TextStyle style, + [Path? path, Paint? fillPaint, Paint? strokePaint]) { + if (text.isEmpty) { + return; + } + + // Draw tooltip rectangle. + if (path != null && fillPaint != null && strokePaint != null) { + context.canvas.drawPath(path, strokePaint); + context.canvas.drawPath(path, fillPaint); + } + + // Draw label. + final TextPainter textPainter = TextPainter( + text: TextSpan(text: text, style: style), + textAlign: TextAlign.center, + maxLines: getMaxLinesContent(text), + textDirection: TextDirection.rtl); + textPainter + ..layout() + ..paint(context.canvas, position); + } +} diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/trackball.dart b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/trackball.dart new file mode 100644 index 000000000..ec140b9a1 --- /dev/null +++ b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/trackball.dart @@ -0,0 +1,3162 @@ +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart' hide Image; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:syncfusion_flutter_core/core.dart'; +import 'package:syncfusion_flutter_core/theme.dart'; + +import '../axis/axis.dart'; +import '../axis/category_axis.dart'; +import '../axis/datetime_category_axis.dart'; +import '../base.dart'; +import '../common/callbacks.dart'; +import '../common/chart_point.dart'; +import '../common/interactive_tooltip.dart'; +import '../common/marker.dart'; +import '../indicators/technical_indicator.dart'; +import '../interactions/behavior.dart'; +import '../series/bar_series.dart'; +import '../series/chart_series.dart'; +import '../utils/constants.dart'; +import '../utils/enum.dart'; +import '../utils/helper.dart'; +import '../utils/typedef.dart'; + +/// Customizes the trackball. +/// +/// Trackball feature displays the tooltip for the data points that are closer +/// to the point where you touch on the chart area. +/// This feature can be enabled using enable property of [TrackballBehavior]. +/// +/// Provides options to customize the [activationMode], [tooltipDisplayMode], +/// [lineType] and [tooltipSettings]. +class TrackballBehavior extends ChartBehavior { + /// Creating an argument constructor of TrackballBehavior class. + TrackballBehavior({ + this.activationMode = ActivationMode.longPress, + this.lineType = TrackballLineType.vertical, + this.tooltipDisplayMode = TrackballDisplayMode.floatAllPoints, + this.tooltipAlignment = ChartAlignment.center, + this.tooltipSettings = const InteractiveTooltip(), + this.markerSettings, + this.lineDashArray, + this.enable = false, + this.lineColor, + this.lineWidth = 1, + this.shouldAlwaysShow = false, + this.builder, + this.hideDelay = 0, + }) { + _fetchImage(); + } + + /// Toggles the visibility of the trackball. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior(enable: true); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final bool enable; + + /// Width of the track line. + /// + /// Defaults to `1`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// lineWidth: 5 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final double lineWidth; + + /// Color of the track line. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// lineColor: Colors.red + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final Color? lineColor; + + /// Dashes of the track line. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// lineDashArray: [10,10] + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final List? lineDashArray; + + /// Gesture for activating the trackball. + /// + /// Trackball can be activated in tap, double tap and long press. + /// + /// Defaults to `ActivationMode.longPress`. + /// + /// Also refer [ActivationMode]. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// activationMode: ActivationMode.doubleTap + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final ActivationMode activationMode; + + /// Alignment of the trackball tooltip. + /// + /// The trackball tooltip can be aligned at the top, bottom, and center + /// position of the chart. + /// + /// _Note:_ This is applicable only when the `tooltipDisplayMode` property + /// is set to `TrackballDisplayMode.groupAllPoints`. + /// + /// Defaults to `ChartAlignment.center` + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// tooltipDisplayMode: TrackballDisplayMode.groupAllPoints, + /// tooltipAlignment: ChartAlignment.far + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final ChartAlignment tooltipAlignment; + + /// Type of trackball line. By default, vertical line will be displayed. + /// + /// You can change this by specifying values to this property. + /// + /// Defaults to `TrackballLineType.vertical`. + /// + /// Also refer [TrackballLineType] + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// lineType: TrackballLineType.vertical + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final TrackballLineType lineType; + + /// Display mode of tooltip. + /// + /// By default, tooltip of all the series under the current point index value + /// will be shown. + /// + /// Defaults to `TrackballDisplayMode.floatAllPoints`. + /// + /// Also refer [TrackballDisplayMode]. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// tooltipDisplayMode: TrackballDisplayMode.groupAllPoints + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final TrackballDisplayMode tooltipDisplayMode; + + /// Shows or hides the trackball. + /// + /// By default, the trackball will be hidden on touch. To avoid this, + /// set this property to true. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// shouldAlwaysShow: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final bool shouldAlwaysShow; + + /// Customizes the trackball tooltip. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// canShowMarker: false + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final InteractiveTooltip tooltipSettings; + + /// Giving disappear delay for trackball. + /// + /// Defaults to `0`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// hideDelay: 2000 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior, + /// ); + /// } + /// ``` + final double hideDelay; + + /// Builder of the trackball tooltip. + /// + /// Add any custom widget as the trackball template. + /// + /// If the trackball display mode is `groupAllPoints` or `nearestPoint` + /// it will called once and if it is + /// `floatAllPoints`, it will be called for each point. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// builder: (BuildContext context, TrackballDetails trackballDetails) { + /// return Container( + /// width: 70, + /// decoration: + /// const BoxDecoration(color: Color.fromRGBO(66, 244, 164, 1)), + /// child: Text('${trackballDetails.point?.cumulative}') + /// ); + /// } + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + /// ``` + final ChartTrackballBuilder? builder; + + /// Hold trackball target position. + Offset? _position; + Offset? _dividerStartOffset; + Offset? _dividerEndOffset; + Timer? _trackballHideTimer; + SfChartThemeData? _chartThemeData; + ThemeData? _themeData; + Rect _plotAreaBounds = Rect.zero; + Image? _trackballImage; + bool _isTransposed = false; + bool _isLeft = false; + bool _isRight = false; + bool _isTop = false; + + List chartPointInfo = []; + final List _visiblePoints = []; + final List<_TooltipLabels> _tooltipLabels = <_TooltipLabels>[]; + final List _lineMarkers = []; + final List _tooltipMarkers = []; + final List _tooltipPaths = []; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + + return other is TrackballBehavior && + other.activationMode == activationMode && + other.lineType == lineType && + other.tooltipDisplayMode == tooltipDisplayMode && + other.tooltipAlignment == tooltipAlignment && + other.tooltipSettings == tooltipSettings && + other.lineDashArray == lineDashArray && + other.markerSettings == markerSettings && + other.enable == enable && + other.lineColor == lineColor && + other.lineWidth == lineWidth && + other.shouldAlwaysShow == shouldAlwaysShow && + other.builder == builder && + other.hideDelay == hideDelay; + } + + @override + int get hashCode { + final List values = [ + activationMode, + lineType, + tooltipDisplayMode, + tooltipAlignment, + tooltipSettings, + markerSettings, + lineDashArray, + enable, + lineColor, + lineWidth, + shouldAlwaysShow, + builder, + hideDelay + ]; + return Object.hashAll(values); + } + + /// Options to customize the markers that are displayed when trackball is + /// enabled. + /// + /// Trackball markers are used to provide information about the exact point + /// location, when the trackball is visible. You can add a shape to adorn each + /// data point. Trackball markers can be enabled by using the + /// `markerVisibility` property in [TrackballMarkerSettings]. + /// + /// Provides the options like color, border width, border color and shape of + /// the marker to customize the appearance. + final TrackballMarkerSettings? markerSettings; + + /// Displays the trackball at the specified x and y-positions. + /// + /// *x and y - x & y pixels/values at which the trackball needs to be shown. + /// + /// coordinateUnit - specify the type of x and y values given. + /// + /// `pixel` or `point` for logical pixel and chart data point respectively. + /// + /// Defaults to `point`. + void show(dynamic x, double y, [String coordinateUnit = 'point']) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + assert(x != null); + assert(!y.isNaN); + if (coordinateUnit == 'point') { + _position = rawValueToPixelPoint( + x, y, parent.xAxis, parent.yAxis, parent.isTransposed); + } else if (coordinateUnit == 'pixel') { + if (x is num) { + _position = Offset(x.toDouble(), y); + } else { + _position = Offset( + rawValueToPixelPoint( + x, y, parent.xAxis, parent.yAxis, parent.isTransposed) + .dx, + y); + } + } + + _show(); + } + + /// Displays the trackball at the specified point index. + /// + /// * pointIndex - index of the point for which the trackball must be shown + void showByIndex(int pointIndex) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && parent.plotArea != null) { + final CartesianSeriesRenderer? series = + parent.plotArea!.firstChild! as CartesianSeriesRenderer?; + if (series != null) { + final List visibleIndexes = series.visibleIndexes; + if (visibleIndexes.first <= pointIndex && + pointIndex <= visibleIndexes.last) { + show(series.xRawValues[pointIndex], 0); + } + } + } + } + + /// Hides the trackball if it is displayed. + void hide() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + _position = null; + if (builder != null) { + parent?.trackballBuilder!([]); + } + _resetDataHolders(); + parent?.invalidate(); + } + + /// To customize the necessary pointer events in behaviors. + /// (e.g., CrosshairBehavior, TrackballBehavior, ZoomingBehavior). + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (event is PointerMoveEvent) { + _handlePointerMove(event); + } else if (event is PointerHoverEvent) { + _handlePointerHover(event); + } else if (event is PointerCancelEvent || event is PointerUpEvent) { + _hideTrackball(immediately: true); + } + } + + void _handlePointerMove(PointerMoveEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showTrackball(parentBox!.globalToLocal(details.position)); + } + } + + void _handlePointerHover(PointerHoverEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showTrackball(parentBox!.globalToLocal(details.position)); + } + } + + /// Called when a pointer or mouse enter on the screen. + @override + void handlePointerEnter(PointerEnterEvent details) { + if (activationMode == ActivationMode.singleTap) { + _showTrackball(parentBox!.globalToLocal(details.position)); + } + } + + /// Called when a pointer or mouse exit on the screen. + @override + void handlePointerExit(PointerExitEvent details) { + _hideTrackball(immediately: true); + } + + /// Called when a long press gesture by a primary button has been + /// recognized in behavior. + @override + void handleLongPressStart(LongPressStartDetails details) { + if (activationMode == ActivationMode.longPress) { + _showTrackball(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when moving after the long press gesture by a primary button is + /// recognized in behavior. + @override + void handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + if (activationMode == ActivationMode.longPress) { + _showTrackball(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when the pointer stops contacting the screen after a long-press + /// by a primary button in behavior. + @override + void handleLongPressEnd(LongPressEndDetails details) { + _hideTrackball(); + } + + /// Called when the pointer tap has contacted the screen in behavior. + @override + void handleTapDown(TapDownDetails details) { + if (activationMode == ActivationMode.singleTap) { + _showTrackball(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when pointer has stopped contacting screen in behavior. + @override + void handleTapUp(TapUpDetails details) { + _hideTrackball(); + } + + /// Called when pointer tap has contacted the screen double time in behavior. + @override + void handleDoubleTap(Offset position) { + if (activationMode == ActivationMode.doubleTap) { + _showTrackball(parentBox!.globalToLocal(position)); + _hideTrackball(doubleTapHideDelay: 200); + } + } + + void _showTrackball(Offset localPosition) { + if (enable) { + show(localPosition.dx, localPosition.dy, 'pixel'); + } + } + + void _hideTrackball({int doubleTapHideDelay = 0, bool immediately = false}) { + if (immediately) { + hide(); + } else if (!shouldAlwaysShow) { + final int hideDelayDuration = + hideDelay > 0 ? hideDelay.toInt() : doubleTapHideDelay; + _trackballHideTimer?.cancel(); + _trackballHideTimer = + Timer(Duration(milliseconds: hideDelayDuration), () { + _trackballHideTimer = null; + hide(); + }); + } + } + + void _fetchImage() { + if (markerSettings != null && + markerSettings!.markerVisibility == TrackballVisibilityMode.visible && + markerSettings!.shape == DataMarkerType.image && + markerSettings!.image != null) { + fetchImage(markerSettings!.image).then((Image? value) { + _trackballImage = value; + (parentBox as RenderBehaviorArea?)?.invalidate(); + }); + } else { + _trackballImage = null; + } + } + + void _show() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (_position == null || parent == null) { + return; + } + + _generateAllPoints(parent, _position!); + parent.invalidate(); + if (builder != null) { + final List details = []; + final List chartPoints = []; + final List currentPointIndices = []; + final List visibleSeriesIndices = []; + final List visibleSeriesList = []; + final int length = chartPointInfo.length; + if (tooltipDisplayMode == TrackballDisplayMode.groupAllPoints) { + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + chartPoints.add(pointInfo.chartPoint!); + currentPointIndices.add(pointInfo.dataPointIndex!); + visibleSeriesIndices.add(pointInfo.seriesIndex!); + visibleSeriesList.add(pointInfo.series!); + } + + final TrackballGroupingModeInfo groupingModeInfo = + TrackballGroupingModeInfo(chartPoints, currentPointIndices, + visibleSeriesIndices, visibleSeriesList); + details.add(TrackballDetails(null, null, null, null, groupingModeInfo)); + } else { + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + details.add(TrackballDetails(pointInfo.chartPoint, pointInfo.series!, + pointInfo.dataPointIndex, pointInfo.seriesIndex)); + } + } + parent.trackballBuilder!(details); + chartPoints.clear(); + currentPointIndices.clear(); + visibleSeriesIndices.clear(); + visibleSeriesList.clear(); + } + } + + void _resetDataHolders() { + chartPointInfo.clear(); + _visiblePoints.clear(); + _tooltipLabels.clear(); + _lineMarkers.clear(); + _tooltipMarkers.clear(); + _tooltipPaths.clear(); + _dividerStartOffset = null; + _dividerEndOffset = null; + _isTransposed = false; + _isLeft = false; + _isRight = false; + _isTop = false; + } + + void _generateAllPoints(RenderBehaviorArea parent, Offset position) { + final RenderChartPlotArea? chartPlotArea = parent.plotArea; + if (chartPlotArea == null) { + return; + } + + _resetDataHolders(); + double leastX = 0.0; + final bool isRtl = parent.textDirection == TextDirection.rtl; + final bool isGroupMode = + tooltipDisplayMode == TrackballDisplayMode.groupAllPoints; + _chartThemeData = parent.chartThemeData!; + _themeData = parent.themeData; + _plotAreaBounds = parent.paintBounds; + _isTransposed = parent.isTransposed; + + chartPlotArea.visitChildren((RenderObject child) { + if (child is CartesianSeriesRenderer && + child.controller.isVisible && + child.dataSource != null && + child.dataSource!.isNotEmpty && + child.animationController != null && + !child.animationController!.isAnimating) { + final List nearestPointIndexes = + _findNearestChartPointIndexes(child, position); + for (final int nearestPointIndex in nearestPointIndexes) { + final ChartSegment segment = child.segmentAt(nearestPointIndex); + final TrackballInfo? trackballInfo = + segment.trackballInfo(position, nearestPointIndex); + + if (trackballInfo != null) { + final ChartTrackballInfo trackInfo = + trackballInfo as ChartTrackballInfo; + if (trackInfo.pointIndex >= 0) { + final Offset trackPosition = trackInfo.position!; + double xPos = trackPosition.dx; + double yPos = trackPosition.dy; + final double touchXPos = position.dx; + if (trackInfo.seriesIndex == 0 || + ((leastX - touchXPos).abs() > (xPos - touchXPos).abs())) { + leastX = xPos; + } + + final Rect rect = _plotAreaBounds + .intersect(Rect.fromLTWH(xPos - 1, yPos - 1, 2, 2)); + if (_plotAreaBounds.contains(trackPosition) || + _plotAreaBounds.overlaps(rect)) { + final double touchXPos = position.dx; + if (trackInfo.seriesIndex == 0 || + ((leastX - touchXPos).abs() > (xPos - touchXPos).abs())) { + leastX = xPos; + } + + _visiblePoints.add(Offset(xPos, yPos)); + _addChartPointInfo(trackInfo, xPos, yPos); + if (isGroupMode && leastX >= _plotAreaBounds.left) { + if (_isTransposed) { + yPos = leastX; + } else { + xPos = leastX; + } + } + } + _updateLeastX(leastX, child.dataCount); + if (child is BarSeriesRenderer ? _isTransposed : _isTransposed) { + yPos = leastX; + } else { + xPos = leastX; + } + } + } + } + } + }); + + if (parent.indicatorArea != null) { + parent.indicatorArea!.visitChildren((RenderObject child) { + if (child is IndicatorRenderer && child.effectiveIsVisible) { + final List? trackballInfo = + child.trackballInfo(position); + if (trackballInfo != null && + trackballInfo.isNotEmpty && + child.animationFactor == 1) { + for (final TrackballInfo trackInfo in trackballInfo) { + final ChartTrackballInfo info = trackInfo as ChartTrackballInfo; + final CartesianChartPoint chartPoint = info.point; + final bool pointIsNaN = + (chartPoint.xValue != null && chartPoint.xValue!.isNaN) || + (chartPoint.y != null && chartPoint.y!.isNaN); + if (trackInfo.pointIndex >= 0 && !pointIsNaN) { + final Offset indicatorPosition = info.position!; + double xPos = indicatorPosition.dx; + double yPos = indicatorPosition.dy; + final double touchXPos = position.dx; + if ((leastX - touchXPos).abs() > (xPos - touchXPos).abs()) { + leastX = xPos; + } + + if (_isTransposed && + (leastX - touchXPos).abs() > (yPos - touchXPos).abs()) { + leastX = yPos; + } + + _visiblePoints.add(Offset(xPos, yPos)); + _addChartPointInfo(info, xPos, yPos); + if (isGroupMode && leastX >= _plotAreaBounds.left) { + if (_isTransposed) { + yPos = leastX; + } else { + xPos = leastX; + } + } + } + } + } + _updateLeastX(leastX, child.dataCount); + } + }); + } + + _validateLeastPointInfoWithLeastX(leastX); + _sortTrackballPoints(_isTransposed); + _triggerTrackballRenderCallback(parent); + _applyTooltipDisplayMode(_chartThemeData!, _themeData!, + _chartThemeData!.trackballTextStyle!, leastX, position, isRtl); + } + + void _sortTrackballPoints(bool isTranposed) { + if (_visiblePoints.isNotEmpty) { + isTranposed + ? _visiblePoints.sort((Offset a, Offset b) => a.dx.compareTo(b.dx)) + : _visiblePoints.sort((Offset a, Offset b) => a.dy.compareTo(b.dy)); + } + if (chartPointInfo.isNotEmpty) { + if (tooltipDisplayMode != TrackballDisplayMode.groupAllPoints) { + isTranposed + ? chartPointInfo.sort((ChartPointInfo a, ChartPointInfo b) => + a.xPosition!.compareTo(b.xPosition!)) + : tooltipDisplayMode == TrackballDisplayMode.floatAllPoints + ? chartPointInfo.sort((ChartPointInfo a, ChartPointInfo b) => + a.yPosition!.compareTo(b.yPosition!)) + : chartPointInfo.sort((ChartPointInfo a, ChartPointInfo b) => + b.yPosition!.compareTo(a.yPosition!)); + } + } + } + + void _triggerTrackballRenderCallback(RenderBehaviorArea parent) { + if (parent.onTrackballPositionChanging != null) { + final int length = chartPointInfo.length - 1; + for (int i = length; i >= 0; i--) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + final TrackballArgs trackballArgs = TrackballArgs(); + trackballArgs.chartPointInfo = pointInfo; + parent.onTrackballPositionChanging!(trackballArgs); + chartPointInfo[i].label = trackballArgs.chartPointInfo.label; + chartPointInfo[i].header = trackballArgs.chartPointInfo.header; + if (builder == null && pointInfo.label == null || + pointInfo.label == '') { + chartPointInfo.removeAt(i); + _visiblePoints.removeAt(i); + } + } + } + } + + List _findNearestChartPointIndexes( + CartesianSeriesRenderer series, Offset position) { + final List indexes = []; + final int dataCount = series.dataCount; + final RenderChartAxis xAxis = series.xAxis!; + final RenderChartAxis yAxis = series.yAxis!; + final Rect bounds = series.paintBounds; + final num xValue = xAxis.pixelToPoint(bounds, position.dx, position.dy); + final num yValue = yAxis.pixelToPoint(bounds, position.dx, position.dy); + + if (xAxis is RenderCategoryAxis || xAxis is RenderDateTimeCategoryAxis) { + final DoubleRange range = xAxis.visibleRange!; + int index = xValue.round(); + if (xAxis is RenderCategoryAxis && !xAxis.arrangeByIndex) { + index = series.xValues.indexOf(index); + } + if (index <= range.maximum && + index >= range.minimum && + index < dataCount && + index >= 0) { + indexes.add(index); + } + return indexes; + } else { + if (series.canFindLinearVisibleIndexes) { + final int binaryIndex = + _binarySearch(series.xValues, xValue.toDouble(), 0, dataCount - 1); + if (binaryIndex >= 0) { + indexes.add(binaryIndex); + } + } else { + double delta = 0; + num nearPointX = series.xValues[0]; + num nearPointY = series.yAxis!.visibleRange!.minimum; + for (int i = 0; i < dataCount; i++) { + final num touchXValue = xValue; + final num touchYValue = yValue; + final double curX = series.xValues[i].toDouble(); + final double curY = series.trackballYValue(i).toDouble(); + if (delta == touchXValue - curX) { + if ((touchYValue - curY).abs() > (touchYValue - nearPointY).abs()) { + indexes.clear(); + } + indexes.add(i); + } else if ((touchXValue - curX).abs() <= + (touchXValue - nearPointX).abs()) { + nearPointX = curX; + nearPointY = curY; + delta = touchXValue - curX; + indexes.clear(); + indexes.add(i); + } + } + } + return indexes; + } + } + + int _binarySearch(List xValues, double touchValue, int min, int max) { + var closerIndex = 0; + double closerDelta = double.maxFinite; + while (min <= max) { + final int mid = (min + max) ~/ 2; + final double xValue = xValues[mid].toDouble(); + final double delta = (touchValue - xValue).abs(); + if (delta < closerDelta) { + closerDelta = delta; + closerIndex = mid; + } + + if (touchValue == xValue) { + return mid; + } else if (touchValue < xValue) { + max = mid - 1; + } else { + min = mid + 1; + } + } + return closerIndex; + } + + void _addChartPointInfo( + ChartTrackballInfo trackballInfo, double xPos, double yPos) { + final ChartPointInfo pointInfo = ChartPointInfo( + label: trackballInfo.text, + header: trackballInfo.header, + color: trackballInfo.color, + series: trackballInfo.series, + seriesName: trackballInfo.name, + seriesIndex: trackballInfo.seriesIndex, + chartPoint: trackballInfo.point, + dataPointIndex: trackballInfo.pointIndex, + xPosition: xPos, + yPosition: yPos, + markerXPos: xPos, + markerYPos: yPos, + lowYPosition: trackballInfo.lowYPos, + highXPosition: trackballInfo.highXPos, + highYPosition: trackballInfo.highYPos, + openXPosition: trackballInfo.openXPos, + openYPosition: trackballInfo.openYPos, + closeXPosition: trackballInfo.closeXPos, + closeYPosition: trackballInfo.closeYPos, + minYPosition: trackballInfo.minYPos, + maxYPosition: trackballInfo.maxYPos, + maxXPosition: trackballInfo.maxXPos, + lowerXPosition: trackballInfo.lowerXPos, + lowerYPosition: trackballInfo.lowerYPos, + upperXPosition: trackballInfo.upperXPos, + upperYPosition: trackballInfo.upperYPos, + ); + chartPointInfo.add(pointInfo); + } + + void _updateLeastX(double leastX, int dataCount) { + if (chartPointInfo.isNotEmpty && + chartPointInfo[0].dataPointIndex! < dataCount) { + leastX = chartPointInfo[0].xPosition!; + } + } + + void _validateLeastPointInfoWithLeastX(double leastX) { + final int length = chartPointInfo.length; + if (length > 1) { + final ChartPointInfo firstPoint = chartPointInfo[0]; + final bool isFloatAllPoints = + tooltipDisplayMode == TrackballDisplayMode.floatAllPoints; + for (int i = 0; i < length; i++) { + final ChartPointInfo currentPoint = chartPointInfo[i]; + if (firstPoint.chartPoint!.xValue! != + currentPoint.chartPoint!.xValue!) { + final List leastPointInfo = []; + for (final ChartPointInfo pointInfo in chartPointInfo) { + final double xPos = pointInfo.xPosition!; + if (xPos == leastX) { + leastPointInfo.add(pointInfo); + final int leastLength = leastPointInfo.length; + if (!(isFloatAllPoints && + leastLength > 1 && + (pointInfo.series is IndicatorRenderer || + pointInfo.seriesIndex != + leastPointInfo[leastLength - 2].seriesIndex))) { + _visiblePoints.clear(); + } + + _visiblePoints.add(Offset(xPos, pointInfo.yPosition!)); + } + } + chartPointInfo.clear(); + chartPointInfo = leastPointInfo; + break; + } + } + } + } + + void _validateNearestChartPointInfo(double leastX, Offset position) { + final double touchXPos = position.dx; + final double touchYPos = position.dy; + int length = chartPointInfo.length; + if (length > 1) { + ChartPointInfo? pointInfo; + final ChartPointInfo firstPoint = chartPointInfo[0]; + final double firstX = firstPoint.xPosition!; + if (leastX != firstX && !_isTransposed) { + chartPointInfo.remove(firstPoint); + } + pointInfo = firstPoint; + length = chartPointInfo.length; + for (int i = 1; i < length; i++) { + final ChartPointInfo nextPoint = chartPointInfo[i]; + final double nextX = nextPoint.xPosition!; + final double nextY = nextPoint.yPosition!; + final bool isXYPositioned = !_isTransposed + ? (((pointInfo!.yPosition! - touchYPos).abs() > + (nextY - touchYPos).abs()) && + pointInfo.xPosition! == nextX) + : (((pointInfo!.xPosition! - touchXPos).abs() > + (nextX - touchXPos).abs()) && + pointInfo.yPosition! == nextY); + if (isXYPositioned) { + pointInfo = chartPointInfo[i]; + } + } + + if (pointInfo != null) { + chartPointInfo + ..clear() + ..add(pointInfo); + } + } + } + + void _applyTooltipDisplayMode( + SfChartThemeData chartThemeData, + ThemeData themeData, + TextStyle labelStyle, + double leastX, + Offset position, + bool isRtl, + ) { + if (chartPointInfo.isEmpty) { + return; + } + + // It applicable for template tooltip. + if (tooltipDisplayMode == TrackballDisplayMode.nearestPoint) { + _validateNearestChartPointInfo(leastX, position); + } + + if (tooltipSettings.enable && builder == null) { + if (tooltipSettings.textStyle != null) { + labelStyle = + _createLabelStyle(FontWeight.normal, tooltipSettings.textStyle!); + } + const double padding = 5; + final bool markerIsVisible = markerSettings != null && + markerSettings!.markerVisibility == TrackballVisibilityMode.visible; + final bool markerAutoVisibility = markerSettings != null && + markerSettings!.markerVisibility == TrackballVisibilityMode.auto; + + switch (tooltipDisplayMode) { + case TrackballDisplayMode.nearestPoint: + _applyNearestPointDisplayMode(padding, labelStyle, markerIsVisible, + markerAutoVisibility, isRtl); + break; + + case TrackballDisplayMode.floatAllPoints: + _applyFloatAllPointsDisplayMode(padding, labelStyle, markerIsVisible, + markerAutoVisibility, isRtl); + break; + + case TrackballDisplayMode.groupAllPoints: + _applyGroupAllPointDisplayMode(padding, labelStyle, markerIsVisible, + markerAutoVisibility, isRtl); + break; + + case TrackballDisplayMode.none: + break; + } + + if (markerIsVisible) { + _computeLineMarkers(themeData, _lineMarkers); + } + } + } + + void _applyNearestPointDisplayMode( + double defaultPadding, + TextStyle labelStyle, + bool markerIsVisible, + bool markerAutoVisibility, + bool isRtl, + ) { + final double arrowLength = tooltipSettings.arrowLength; + final double arrowWidth = tooltipSettings.arrowWidth; + double borderRadius = tooltipSettings.borderRadius; + for (final ChartPointInfo pointInfo in chartPointInfo) { + final Size labelSize = _labelSize(pointInfo.label!, labelStyle); + final dynamic series = pointInfo.series; + double width = labelSize.width; + if (width < 10) { + width = 10; + borderRadius = borderRadius > 5 ? 5 : borderRadius; + } + borderRadius = borderRadius > 15 ? 15 : borderRadius; + final double padding = (markerAutoVisibility + ? series is IndicatorRenderer || + (series != null && series.markerSettings.isVisible) + : markerIsVisible) + ? (markerSettings!.width / 2) + defaultPadding + : defaultPadding; + + _computeNearestTooltip(pointInfo, labelStyle, width, labelSize.height, + padding, arrowWidth, arrowLength, borderRadius, isRtl); + } + } + + void _computeNearestTooltip( + ChartPointInfo pointInfo, + TextStyle labelStyle, + double width, + double height, + double padding, + double arrowWidth, + double arrowLength, + double borderRadius, + bool isRtl, + ) { + final double xPosition = pointInfo.xPosition!; + final double yPosition = pointInfo.yPosition!; + final Rect tooltipRect = _tooltipRect(xPosition, yPosition, width, height); + final double labelRectWidth = tooltipRect.width; + final double labelRectHeight = tooltipRect.height; + final Offset alignPosition = _alignPosition( + xPosition, + yPosition, + labelRectWidth, + labelRectHeight, + arrowLength, + arrowWidth, + padding, + isRtl); + final RRect tooltipRRect = RRect.fromRectAndRadius( + Rect.fromLTWH( + alignPosition.dx, alignPosition.dy, labelRectWidth, labelRectHeight), + Radius.circular(borderRadius), + ); + + final Path nosePath = _nosePath(_tooltipDirection(), tooltipRRect, + Offset(xPosition, yPosition), arrowLength, arrowWidth); + final Path nearestTooltipPath = Path() + ..addRRect(tooltipRRect) + ..addPath(nosePath, Offset.zero); + _tooltipPaths.add(nearestTooltipPath); + + const double markerPadding = 5; + if (tooltipSettings.canShowMarker) { + final Offset markerPosition = + _markerPosition(tooltipRRect, width, height, markerPadding, isRtl); + _computeTooltipMarkers(pointInfo, markerPosition); + } + + if (pointInfo.label != null) { + _computeTooltipLabels(pointInfo.label!, width, height, labelStyle, + tooltipRRect, markerPadding); + } + } + + void _applyFloatAllPointsDisplayMode( + double defaultPadding, + TextStyle labelStyle, + bool markerIsVisible, + bool markerAutoVisibility, + bool isRtl, + ) { + final double arrowLength = tooltipSettings.arrowLength; + final double arrowWidth = tooltipSettings.arrowWidth; + double borderRadius = tooltipSettings.borderRadius; + final _TooltipPositions floatTooltipPosition = + _computeTooltipPositionForFloatAllPoints(labelStyle, borderRadius); + + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + final dynamic series = pointInfo.series; + final Size labelSize = _labelSize(pointInfo.label!, labelStyle); + double width = labelSize.width; + if (width < 10) { + width = 10; + borderRadius = borderRadius > 5 ? 5 : borderRadius; + } + borderRadius = borderRadius > 15 ? 15 : borderRadius; + final double padding = (markerAutoVisibility + ? series is IndicatorRenderer || + (series != null && series.markerSettings.isVisible) + : markerIsVisible) + ? (markerSettings!.width / 2) + defaultPadding + : defaultPadding; + + if (floatTooltipPosition != null) { + final num tooltipTop = floatTooltipPosition.tooltipTop[i]; + final num tooltipBottom = floatTooltipPosition.tooltipBottom[i]; + if (_isTransposed + ? tooltipTop >= _plotAreaBounds.left && + tooltipBottom <= _plotAreaBounds.right + : tooltipTop >= _plotAreaBounds.top && + tooltipBottom <= _plotAreaBounds.bottom) { + _computeFloatAllPointTooltip( + i, + pointInfo, + width, + labelSize.height, + padding, + arrowWidth, + arrowLength, + borderRadius, + labelStyle, + floatTooltipPosition, + isRtl); + } + } + } + } + + void _computeFloatAllPointTooltip( + int index, + ChartPointInfo pointInfo, + double width, + double height, + double padding, + double arrowWidth, + double arrowLength, + double borderRadius, + TextStyle labelStyle, + _TooltipPositions tooltipPosition, + bool isRtl, + ) { + final double xPosition = pointInfo.xPosition!; + final double yPosition = pointInfo.yPosition!; + final Rect tooltipRect = _tooltipRect(xPosition, yPosition, width, height); + final double labelRectWidth = tooltipRect.width; + final double labelRectHeight = tooltipRect.height; + final Offset alignPosition = _alignPosition( + xPosition, + yPosition, + labelRectWidth, + labelRectHeight, + arrowLength, + arrowWidth, + padding, + isRtl); + + final double topValue = tooltipPosition.tooltipTop[index].toDouble(); + final RRect tooltipRRect = RRect.fromRectAndRadius( + Rect.fromLTWH( + _isTransposed ? topValue : alignPosition.dx, + _isTransposed ? alignPosition.dy : topValue, + labelRectWidth, + labelRectHeight), + Radius.circular(borderRadius)); + + final Path nosePath = _nosePath(_tooltipDirection(), tooltipRRect, + Offset(xPosition, yPosition), arrowLength, arrowWidth); + final Path nearestTooltipPath = Path() + ..addRRect(tooltipRRect) + ..addPath(nosePath, Offset.zero); + _tooltipPaths.add(nearestTooltipPath); + + const double markerPadding = 5; + if (tooltipSettings.canShowMarker) { + final Offset markerPosition = + _markerPosition(tooltipRRect, width, height, markerPadding, isRtl); + _computeTooltipMarkers(pointInfo, markerPosition); + } + + if (pointInfo.label != null) { + _computeTooltipLabels(pointInfo.label!, width, height, labelStyle, + tooltipRRect, markerPadding); + } + } + + _TooltipPositions _computeTooltipPositionForFloatAllPoints( + TextStyle labelStyle, double borderRadius) { + final List tooltipTop = []; + final List tooltipBottom = []; + final List xAxesInfo = []; + final List yAxesInfo = []; + final num tooltipPaddingForFloatPoint = _isTransposed ? 8 : 5; + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + final dynamic series = pointInfo.series; + final String label = pointInfo.label!; + final Size labelSize = _labelSize(label, labelStyle); + final double height = labelSize.height; + double width = labelSize.width; + if (width < 10) { + width = 10; + } + + if (label != '' && _visiblePoints.isNotEmpty) { + final Offset visiblePoint = _visiblePoints[i]; + final double closeX = visiblePoint.dx; + final double closeY = visiblePoint.dy; + tooltipTop.add(_isTransposed + ? closeX - tooltipPaddingForFloatPoint - (width / 2) + : closeY - tooltipPaddingForFloatPoint - height / 2); + tooltipBottom.add(_isTransposed + ? (closeX + tooltipPaddingForFloatPoint + (width / 2)) + + (tooltipSettings.canShowMarker ? 20 : 0) + : closeY + tooltipPaddingForFloatPoint + height / 2); + if (series != null && series.xAxis != null) { + xAxesInfo.add(series.xAxis!); + } + if (series != null && series.yAxis != null) { + yAxesInfo.add(series.yAxis!); + } + } + } + + if (tooltipTop.isNotEmpty && tooltipBottom.isNotEmpty) { + return _smartTooltipPositions(tooltipTop, tooltipBottom, xAxesInfo, + yAxesInfo, chartPointInfo, tooltipPaddingForFloatPoint); + } + return _TooltipPositions(tooltipTop, tooltipBottom); + } + + /// Method to place the collided tooltips properly + _TooltipPositions _smartTooltipPositions( + List tooltipTop, + List tooltipBottom, + List xAxesInfo, + List yAxesInfo, + List chartPointInfo, + [num tooltipPaddingForFloatPoint = 0]) { + final List visibleLocation = []; + num totalHeight = 0; + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + _isTransposed + ? visibleLocation.add(pointInfo.xPosition!) + : visibleLocation.add(pointInfo.yPosition!); + totalHeight += + tooltipBottom[i] - tooltipTop[i] + tooltipPaddingForFloatPoint; + } + + _TooltipPositions smartTooltipPosition = _continuousOverlappingPoints( + tooltipTop, + tooltipBottom, + visibleLocation, + tooltipPaddingForFloatPoint); + if (!_isTransposed + ? totalHeight < (_plotAreaBounds.bottom - _plotAreaBounds.top) + : totalHeight < (_plotAreaBounds.right - _plotAreaBounds.left)) { + smartTooltipPosition = _verticalArrangements(smartTooltipPosition, + xAxesInfo, yAxesInfo, tooltipPaddingForFloatPoint); + } + return smartTooltipPosition; + } + + _TooltipPositions _verticalArrangements( + _TooltipPositions tooltipPosition, + List xAxesInfo, + List yAxesInfo, + num tooltipPaddingForFloatPoint, + ) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return tooltipPosition; + } + num? startPos; + num? chartHeight; + num secWidth; + num width; + final int tooltipTopLength = tooltipPosition.tooltipTop.length; + RenderChartAxis yAxis; + for (int i = tooltipTopLength - 1; i >= 0; i--) { + yAxis = yAxesInfo[i]; + RenderChartAxis? child = parent.cartesianAxes!.firstChild; + while (child != null) { + if (yAxis == child) { + if (_isTransposed) { + chartHeight = _plotAreaBounds.right; + startPos = _plotAreaBounds.left; + } else { + chartHeight = _plotAreaBounds.bottom - _plotAreaBounds.top; + startPos = _plotAreaBounds.top; + } + } + + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + + width = tooltipPosition.tooltipBottom[i] - tooltipPosition.tooltipTop[i]; + if (chartHeight != null && + chartHeight < tooltipPosition.tooltipBottom[i]) { + tooltipPosition.tooltipBottom[i] = chartHeight - 2; + tooltipPosition.tooltipTop[i] = + tooltipPosition.tooltipBottom[i] - width; + for (int j = i - 1; j >= 0; j--) { + secWidth = + tooltipPosition.tooltipBottom[j] - tooltipPosition.tooltipTop[j]; + if (tooltipPosition.tooltipBottom[j] > + tooltipPosition.tooltipTop[j + 1] && + (tooltipPosition.tooltipTop[j + 1] > startPos! && + tooltipPosition.tooltipBottom[j + 1] < chartHeight)) { + tooltipPosition.tooltipBottom[j] = + tooltipPosition.tooltipTop[j + 1] - tooltipPaddingForFloatPoint; + tooltipPosition.tooltipTop[j] = + tooltipPosition.tooltipBottom[j] - secWidth; + } + } + } + } + + for (int i = 0; i < tooltipTopLength; i++) { + yAxis = yAxesInfo[i]; + RenderChartAxis? child = parent.cartesianAxes!.firstChild; + while (child != null) { + if (yAxis == child) { + if (_isTransposed) { + chartHeight = _plotAreaBounds.right; + startPos = _plotAreaBounds.left; + } else { + chartHeight = _plotAreaBounds.bottom - _plotAreaBounds.top; + startPos = _plotAreaBounds.top; + } + } + + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + + width = tooltipPosition.tooltipBottom[i] - tooltipPosition.tooltipTop[i]; + if (startPos != null && tooltipPosition.tooltipTop[i] < startPos) { + tooltipPosition.tooltipTop[i] = startPos + 1; + tooltipPosition.tooltipBottom[i] = + tooltipPosition.tooltipTop[i] + width; + for (int j = i + 1; j <= (tooltipTopLength - 1); j++) { + secWidth = + tooltipPosition.tooltipBottom[j] - tooltipPosition.tooltipTop[j]; + if (tooltipPosition.tooltipTop[j] < + tooltipPosition.tooltipBottom[j - 1] && + (tooltipPosition.tooltipTop[j - 1] > startPos && + tooltipPosition.tooltipBottom[j - 1] < chartHeight!)) { + tooltipPosition.tooltipTop[j] = + tooltipPosition.tooltipBottom[j - 1] + + tooltipPaddingForFloatPoint; + tooltipPosition.tooltipBottom[j] = + tooltipPosition.tooltipTop[j] + secWidth; + } + } + } + } + return tooltipPosition; + } + + // Method to identify the colliding trackball tooltips and + // return the new tooltip positions + _TooltipPositions _continuousOverlappingPoints(List tooltipTop, + List tooltipBottom, List visibleLocation, num tooltipPadding) { + num temp; + num count = 0; + num start = 0; + num halfHeight; + num midPos; + num tempTooltipHeight; + num temp1TooltipHeight; + int startPoint = 0, i, j, k; + final num endPoint = tooltipBottom.length - 1; + final num firstTop = tooltipTop[0]; + num tooltipHeight = (tooltipBottom[0] - firstTop) + tooltipPadding; + temp = firstTop + tooltipHeight; + start = firstTop; + for (i = 0; i < endPoint; i++) { + // To identify that tooltip collides or not. + if (temp >= tooltipTop[i + 1]) { + tooltipHeight = + tooltipBottom[i + 1] - tooltipTop[i + 1] + tooltipPadding; + temp += tooltipHeight; + count++; + // This condition executes when the tooltip count is half of the total + // number of tooltips. + if (count - 1 == endPoint - 1 || i == endPoint - 1) { + halfHeight = (temp - start) / 2; + midPos = (visibleLocation[startPoint] + visibleLocation[i + 1]) / 2; + tempTooltipHeight = + tooltipBottom[startPoint] - tooltipTop[startPoint]; + tooltipTop[startPoint] = midPos - halfHeight; + tooltipBottom[startPoint] = + tooltipTop[startPoint] + tempTooltipHeight; + for (k = startPoint; k > 0; k--) { + if (tooltipTop[k] <= tooltipBottom[k - 1] + tooltipPadding) { + temp1TooltipHeight = tooltipBottom[k - 1] - tooltipTop[k - 1]; + tooltipTop[k - 1] = + tooltipTop[k] - temp1TooltipHeight - tooltipPadding; + tooltipBottom[k - 1] = tooltipTop[k - 1] + temp1TooltipHeight; + } else { + break; + } + } + // To set tool tip positions based on the half height and + // other tooltip height. + for (j = startPoint + 1; j <= startPoint + count; j++) { + tempTooltipHeight = tooltipBottom[j] - tooltipTop[j]; + tooltipTop[j] = tooltipBottom[j - 1] + tooltipPadding; + tooltipBottom[j] = tooltipTop[j] + tempTooltipHeight; + } + } + } else { + count = i > 0 ? count : 0; + // This executes when any of the middle tooltip collides. + if (count > 0) { + halfHeight = (temp - start) / 2; + midPos = (visibleLocation[startPoint] + visibleLocation[i]) / 2; + tempTooltipHeight = + tooltipBottom[startPoint] - tooltipTop[startPoint]; + tooltipTop[startPoint] = midPos - halfHeight; + tooltipBottom[startPoint] = + tooltipTop[startPoint] + tempTooltipHeight; + for (k = startPoint; k > 0; k--) { + if (tooltipTop[k] <= tooltipBottom[k - 1] + tooltipPadding) { + temp1TooltipHeight = tooltipBottom[k - 1] - tooltipTop[k - 1]; + tooltipTop[k - 1] = + tooltipTop[k] - temp1TooltipHeight - tooltipPadding; + tooltipBottom[k - 1] = tooltipTop[k - 1] + temp1TooltipHeight; + } else { + break; + } + } + + // To set tool tip positions based on the half height and + // other tooltip height. + for (j = startPoint + 1; j <= startPoint + count; j++) { + tempTooltipHeight = tooltipBottom[j] - tooltipTop[j]; + tooltipTop[j] = tooltipBottom[j - 1] + tooltipPadding; + tooltipBottom[j] = tooltipTop[j] + tempTooltipHeight; + } + count = 0; + } + tooltipHeight = + (tooltipBottom[i + 1] - tooltipTop[i + 1]) + tooltipPadding; + temp = tooltipTop[i + 1] + tooltipHeight; + start = tooltipTop[i + 1]; + startPoint = i + 1; + } + } + return _TooltipPositions(tooltipTop, tooltipBottom); + } + + void _applyGroupAllPointDisplayMode(double padding, TextStyle labelStyle, + bool markerIsVisible, bool markerAutoVisibility, bool isRtl) { + double borderRadius = tooltipSettings.borderRadius; + final ChartPointInfo pointInfo = chartPointInfo[0]; + final double xPosition = pointInfo.xPosition!; + final double yPosition = pointInfo.yPosition!; + final dynamic series = pointInfo.series; + final Size totalLabelSize = _labelSizeForGroupAllPoints(labelStyle); + final double height = totalLabelSize.height; + double width = totalLabelSize.width; + if (width < 10) { + width = 10; + borderRadius = borderRadius > 5 ? 5 : borderRadius; + } + borderRadius = borderRadius > 15 ? 15 : borderRadius; + padding = (markerAutoVisibility + ? series is IndicatorRenderer || + (series != null && series.markerSettings.isVisible) + : markerIsVisible) + ? (markerSettings!.width / 2) + padding + : padding; + + final Rect tooltipRect = _tooltipRect(xPosition, yPosition, width, height); + final double labelRectWidth = tooltipRect.width; + final double labelRectHeight = tooltipRect.height; + final Offset defaultPosition = _defaultGroupPosition(xPosition, yPosition); + final Offset alignPosition = _alignPosition( + defaultPosition.dx, + defaultPosition.dy, + labelRectWidth, + labelRectHeight, + tooltipSettings.arrowLength, + tooltipSettings.arrowWidth, + padding, + isRtl, + true, + ); + + final RRect tooltipRRect = _validateRect( + Rect.fromLTWH( + alignPosition.dx, alignPosition.dy, labelRectWidth, labelRectHeight), + _plotAreaBounds, + borderRadius, + ); + + if (tooltipRRect != RRect.zero) { + _tooltipPaths.add(Path()..addRRect(tooltipRRect)); + _computeGroupTooltipLabels( + alignPosition, tooltipRRect, totalLabelSize, labelStyle); + } + } + + void _computeGroupTooltipLabels(Offset alignPosition, RRect tooltipRRect, + Size totalLabelSize, TextStyle labelStyle) { + bool hasIndicator = false; + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && parent.indicatorArea != null) { + hasIndicator = true; + } + const double markerPadding = 5; + final double markerSize = tooltipSettings.canShowMarker ? 20 : 0; + // It specifies for marker position calculation. + double totalLabelHeight = tooltipRRect.top + markerPadding; + // It specifies for label position calculation with label style. + double eachTextHeight = 0; + + final String? header = chartPointInfo[0].header; + if (header != null && header != '') { + const double headerPadding = 10; + final TextStyle boldStyle = + labelStyle.copyWith(fontWeight: FontWeight.bold); + final Size headerSize = measureText(header, boldStyle); + final double headerHeight = headerSize.height; + totalLabelHeight += headerHeight; + eachTextHeight += headerHeight; + + _tooltipLabels.add(_TooltipLabels( + header, + boldStyle, + Offset(tooltipRRect.left + tooltipRRect.width / 2, + tooltipRRect.top + headerHeight / 2 + headerPadding / 2) + .translate(-headerSize.width / 2, -headerSize.height / 2), + )); + + // Divider offset calculation. + _dividerStartOffset = Offset(tooltipRRect.left + headerPadding, + tooltipRRect.top + headerHeight + headerPadding); + _dividerEndOffset = Offset(tooltipRRect.right - headerPadding, + tooltipRRect.top + headerHeight + headerPadding); + } + + // Empty text size consideration between the header and series text. + final Size emptyTextSize = measureText('', labelStyle); + final double emptyTextHeight = emptyTextSize.height; + totalLabelHeight += emptyTextHeight; + eachTextHeight += emptyTextHeight; + + final bool canShowMarker = tooltipSettings.canShowMarker; + final bool hasFormat = tooltipSettings.format != null; + final double rectLeftWithPadding = tooltipRRect.left + markerPadding; + final double x = rectLeftWithPadding + markerSize; + final double y = tooltipRRect.top + markerPadding; + final double markerX = rectLeftWithPadding + (markerSize / 2); + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + final String text = pointInfo.label!; + final Size actualLabelSize = measureText(text, labelStyle); + final double actualLabelHeight = actualLabelSize.height; + totalLabelHeight += actualLabelHeight; + if (!hasFormat) { + // Apply gap between xYDataSeries and other series types. + if (text.contains('\n')) { + totalLabelHeight += markerPadding; + } + } + + // Marker position calculation. + if (canShowMarker) { + Offset markerPosition; + if (text.contains('\n') && hasIndicator) { + markerPosition = Offset( + markerX, totalLabelHeight - actualLabelHeight + markerPadding); + } else { + markerPosition = + Offset(markerX, totalLabelHeight - actualLabelHeight / 2); + } + + _computeTooltipMarkers(pointInfo, markerPosition); + } + + // Label style and position calculation. + final double dy = y + eachTextHeight; + if (hasFormat) { + final double dx = canShowMarker ? x : x + markerPadding; + _computeFormatTooltipLabels(dx, dy, text, labelStyle); + } else { + _computeDefaultTooltipLabels(x, dy, text, labelStyle); + // Apply gap between xYDataSeries and other series types. + if (text.contains('\n')) { + eachTextHeight += markerPadding; + } + } + eachTextHeight += actualLabelHeight; + } + } + + Size _labelSize(String text, TextStyle textStyle) { + if (text != '') { + if (text.contains('') && text.contains('')) { + text = text.replaceAll('', '').replaceAll('', ''); + return measureText( + text, textStyle.copyWith(fontWeight: FontWeight.bold)); + } + } + return measureText(text, textStyle); + } + + Size _labelSizeForGroupAllPoints(TextStyle labelStyle) { + if (chartPointInfo.isEmpty) { + return Size.zero; + } + + double width = 0; + double height = 0; + // Header text size. + final String? header = chartPointInfo[0].header; + if (header != null) { + final Size headerSize = _labelSize(header, labelStyle); + if (headerSize.width > width) { + width = headerSize.width; + } + height += headerSize.height; + } + + // Empty text size consideration. + final Size emptyTextSize = measureText('', labelStyle); + if (emptyTextSize.width > width) { + width = emptyTextSize.width; + } + height += emptyTextSize.height; + + final bool hasFormat = tooltipSettings.format != null; + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final String? label = chartPointInfo[i].label; + if (label != null) { + final Size labelSize = _labelSize(label, labelStyle); + if (labelSize.width > width) { + width = labelSize.width; + } + height += labelSize.height; + // Apply gap between xYDataSeries and other series types. + if (!hasFormat) { + if (label.contains('\n')) { + height += 5; + } + } + } + } + return Size(width, height); + } + + Offset _defaultGroupPosition(double xPosition, double yPosition) { + double xPos = xPosition; + double yPos = yPosition; + if (_isTransposed) { + switch (tooltipAlignment) { + case ChartAlignment.near: + xPos = _plotAreaBounds.top; + break; + + case ChartAlignment.center: + xPos = _plotAreaBounds.center.dx; + break; + + case ChartAlignment.far: + xPos = _plotAreaBounds.bottom; + break; + } + } else { + switch (tooltipAlignment) { + case ChartAlignment.near: + yPos = _plotAreaBounds.top; + break; + + case ChartAlignment.center: + yPos = _plotAreaBounds.center.dy; + break; + + case ChartAlignment.far: + yPos = _plotAreaBounds.bottom; + break; + } + } + return Offset(xPos, yPos); + } + + Offset _markerPosition(RRect tooltipRRect, double labelWidth, + double labelHeight, double markerPadding, bool isRtl) { + return Offset( + (tooltipRRect.left + tooltipRRect.width / 2) + + (isRtl + ? labelWidth / 2 - markerPadding + : -labelWidth / 2 - markerPadding), + tooltipRRect.top + tooltipRRect.height / 2, + ); + } + + Rect _tooltipRect(double x, double y, double width, double height) { + if (tooltipSettings.canShowMarker) { + const double padding = 20 + 17; // markerSize + widthPadding. + return Rect.fromLTWH(x, y, width + padding, height + 10); + } else { + return Rect.fromLTWH(x, y, width + 15, height + 10); + } + } + + Offset _alignPosition( + double xPosition, + double yPosition, + double rectWidth, + double rectHeight, + double arrowLength, + double arrowWidth, + double padding, + bool isRtl, + [bool isGroupMode = false]) { + double xPos = xPosition; + double yPos = yPosition; + if (yPosition > arrowLength + rectHeight) { + _isTop = true; + _isRight = false; + if (_isTransposed) { + final double totalWidth = _plotAreaBounds.left + _plotAreaBounds.width; + final double halfRectWidth = rectWidth / 2; + xPos = xPosition - halfRectWidth; + if (xPos < _plotAreaBounds.left) { + xPos = _plotAreaBounds.left; + } else if ((xPosition + halfRectWidth) > totalWidth) { + xPos = totalWidth - rectWidth; + } + + yPos = (yPosition - rectHeight) - padding; + yPos = yPos - arrowLength; + if (yPos + rectHeight >= _plotAreaBounds.bottom) { + yPos = _plotAreaBounds.bottom - rectHeight; + } + } else { + yPos = yPosition - rectHeight / 2; + if (!isRtl) { + if (xPos + rectWidth + padding + arrowLength > + _plotAreaBounds.right) { + xPos = isGroupMode + ? xPos - rectWidth - groupAllPadding + : xPos - rectWidth - padding - arrowLength; + _isLeft = true; + } else { + xPos = isGroupMode + ? xPosition + groupAllPadding + : xPosition + padding + arrowLength; + _isLeft = false; + _isRight = true; + } + } else { + xPos = isGroupMode + ? xPos - rectWidth - groupAllPadding + : xPos - rectWidth - padding - arrowLength; + if (xPos < _plotAreaBounds.left) { + xPos = isGroupMode + ? xPosition + groupAllPadding + : xPosition + padding + arrowLength; + _isRight = true; + } else { + _isLeft = true; + } + } + if (yPos + rectHeight >= _plotAreaBounds.bottom) { + yPos = _plotAreaBounds.bottom - rectHeight; + } + } + } else { + _isTop = false; + if (_isTransposed) { + final double totalWidth = _plotAreaBounds.left + _plotAreaBounds.width; + final double halfRectWidth = rectWidth / 2; + xPos = xPosition - halfRectWidth; + if (xPos < _plotAreaBounds.left) { + xPos = _plotAreaBounds.left; + } else if ((xPosition + halfRectWidth) > totalWidth) { + xPos = totalWidth - rectWidth; + } + + yPos = (yPosition + arrowLength) + padding; + } else { + if (isGroupMode) { + xPos = xPosition - rectWidth / 2; + yPos = yPosition - rectHeight / 2; + } else { + yPos = (yPosition + arrowLength / 2) + padding; + } + + if (!isRtl) { + if ((isGroupMode + ? (xPos + (rectWidth / 2) + groupAllPadding) + : xPos + rectWidth + padding + arrowLength) > + _plotAreaBounds.right) { + xPos = isGroupMode + ? (xPos - (rectWidth / 2) - groupAllPadding) + : xPos - rectWidth - padding - arrowLength; + _isLeft = true; + } else { + xPos = isGroupMode + ? xPosition + groupAllPadding + : xPosition + padding + arrowLength; + _isRight = true; + } + } else { + if (xPosition - rectWidth - padding - arrowLength > + _plotAreaBounds.left) { + xPos = isGroupMode + ? (xPos - (rectWidth / 2) - groupAllPadding) + : xPos - rectWidth - padding - arrowLength; + _isLeft = true; + } else { + xPos = isGroupMode + ? xPosition + groupAllPadding + : xPosition + padding + arrowLength; + _isRight = true; + } + } + + if (isGroupMode) { + if ((yPos + rectHeight) >= _plotAreaBounds.bottom) { + yPos = _plotAreaBounds.bottom / 2 - rectHeight / 2; + } + + if (yPos <= _plotAreaBounds.top) { + yPos = _plotAreaBounds.top; + } + } + } + } + + return Offset(xPos, yPos); + } + + RRect _validateRect( + Rect tooltipRRect, Rect plotAreaBounds, double borderRadius) { + if (tooltipRRect == Rect.zero || + tooltipRRect.width >= plotAreaBounds.width || + tooltipRRect.height >= plotAreaBounds.height) { + return RRect.zero; + } + + double rectLeft = tooltipRRect.left; + double rectRight = tooltipRRect.right; + if (tooltipRRect.left < plotAreaBounds.left) { + final double left = plotAreaBounds.left - tooltipRRect.left; + rectLeft += left; + rectRight += left; + } else if (tooltipRRect.right > plotAreaBounds.right) { + final double right = tooltipRRect.right - plotAreaBounds.right; + rectLeft -= right; + rectRight -= right; + } + + RRect alignedRect = RRect.fromRectAndRadius( + Rect.fromLTRB(rectLeft, tooltipRRect.top, rectRight, tooltipRRect.bottom), + Radius.circular(borderRadius), + ); + + if (alignedRect.left < plotAreaBounds.left || + alignedRect.right > plotAreaBounds.right) { + alignedRect = RRect.zero; + } + return alignedRect; + } + + Path _nosePath(String tooltipPosition, RRect tooltipRect, Offset position, + double arrowLength, double arrowWidth) { + final Path nosePath = Path(); + final double tooltipLeft = tooltipRect.left; + final double tooltipRight = tooltipRect.right; + final double tooltipTop = tooltipRect.top; + final double tooltipBottom = tooltipRect.bottom; + final double rectHalfWidth = tooltipRect.width / 2; + final double rectHalfHeight = tooltipRect.height / 2; + switch (tooltipPosition) { + case 'Left': + nosePath.moveTo(tooltipRight, tooltipTop + rectHalfHeight - arrowWidth); + nosePath.lineTo( + tooltipRight, tooltipBottom - rectHalfHeight + arrowWidth); + nosePath.lineTo(tooltipRight + arrowLength, position.dy); + nosePath.close(); + return nosePath; + + case 'Right': + nosePath.moveTo(tooltipLeft, tooltipTop + rectHalfHeight - arrowWidth); + nosePath.lineTo( + tooltipLeft, tooltipBottom - rectHalfHeight + arrowWidth); + nosePath.lineTo(tooltipLeft - arrowLength, position.dy); + nosePath.close(); + return nosePath; + + case 'Top': + nosePath.moveTo(position.dx, tooltipBottom + arrowLength); + nosePath.lineTo( + (tooltipRight - rectHalfWidth) + arrowWidth, tooltipBottom); + nosePath.lineTo( + (tooltipLeft + rectHalfWidth) - arrowWidth, tooltipBottom); + nosePath.close(); + return nosePath; + + case 'Bottom': + nosePath.moveTo(position.dx, tooltipTop - arrowLength); + nosePath.lineTo( + (tooltipRight - rectHalfWidth) + arrowWidth, tooltipTop); + nosePath.lineTo((tooltipLeft + rectHalfWidth) - arrowWidth, tooltipTop); + nosePath.close(); + return nosePath; + } + return nosePath; + } + + String _tooltipDirection() { + if (_isRight) { + return 'Right'; + } else if (_isLeft) { + return 'Left'; + } else if (_isTop) { + return 'Top'; + } else { + return 'Bottom'; + } + } + + TextStyle _createLabelStyle(FontWeight fontWeight, TextStyle labelStyle) { + return TextStyle( + fontWeight: fontWeight, + color: labelStyle.color, + fontSize: labelStyle.fontSize, + fontFamily: labelStyle.fontFamily, + fontStyle: labelStyle.fontStyle, + inherit: labelStyle.inherit, + backgroundColor: labelStyle.backgroundColor, + letterSpacing: labelStyle.letterSpacing, + wordSpacing: labelStyle.wordSpacing, + textBaseline: labelStyle.textBaseline, + height: labelStyle.height, + locale: labelStyle.locale, + foreground: labelStyle.foreground, + background: labelStyle.background, + shadows: labelStyle.shadows, + fontFeatures: labelStyle.fontFeatures, + decoration: labelStyle.decoration, + decorationColor: labelStyle.decorationColor, + decorationStyle: labelStyle.decorationStyle, + decorationThickness: labelStyle.decorationThickness, + debugLabel: labelStyle.debugLabel, + fontFamilyFallback: labelStyle.fontFamilyFallback); + } + + void _computeTooltipMarkers(ChartPointInfo pointInfo, Offset markerPosition) { + final Color color = pointInfo.color!; + final ChartMarker marker = ChartMarker() + ..x = markerPosition.dx + ..y = markerPosition.dy + ..index = pointInfo.dataPointIndex! + ..height = tooltipMarkerSize + ..width = tooltipMarkerSize + ..borderColor = color + ..borderWidth = 1 + ..color = color; + if (markerSettings != null) { + marker.merge( + borderColor: markerSettings!.borderColor ?? color, + color: markerSettings!.color ?? color, + image: markerSettings!.image, + type: markerSettings!.shape, + ); + } + marker.position = + Offset(marker.x - marker.width / 2, marker.y - marker.height / 2); + marker.shader = _markerShader( + pointInfo, marker.position & Size(marker.height, marker.width)); + _tooltipMarkers.add(marker); + } + + Shader? _markerShader(ChartPointInfo pointInfo, Rect bounds) { + final dynamic series = pointInfo.series; + if (series is CartesianSeriesRenderer) { + if (series.onCreateShader != null) { + final ShaderDetails details = ShaderDetails(bounds, 'marker'); + return series.onCreateShader!(details); + } else if (series.gradient != null) { + return series.gradient!.createShader(bounds); + } + } + return null; + } + + void _computeLineMarkers(ThemeData themeData, List source) { + final Color themeFillColor = themeData.colorScheme.surface; + final int length = chartPointInfo.length; + for (int i = 0; i < length; i++) { + final ChartPointInfo pointInfo = chartPointInfo[i]; + final Color color = pointInfo.color!; + final ChartMarker marker = ChartMarker() + ..x = pointInfo.markerXPos! + ..y = pointInfo.markerYPos! + ..index = pointInfo.dataPointIndex! + ..borderColor = color + ..color = themeFillColor; + if (markerSettings != null) { + marker.merge( + borderColor: markerSettings!.borderColor ?? color, + borderWidth: markerSettings!.borderWidth, + color: markerSettings!.color ?? themeFillColor, + height: markerSettings!.height, + width: markerSettings!.width, + image: markerSettings!.image, + type: markerSettings!.shape, + ); + } + marker.borderWidth = marker.borderWidth / 2; + marker.position = + Offset(marker.x - marker.width / 2, marker.y - marker.height / 2); + source.add(marker); + } + } + + void _computeTooltipLabels(String text, double width, double height, + TextStyle textStyle, RRect tooltipRRect, double markerPadding) { + final double markerSize = tooltipSettings.canShowMarker ? 20 : 0; + final double x = tooltipRRect.left + markerPadding + markerSize; + final double y = tooltipRRect.top + markerPadding; + if (tooltipSettings.format != null) { + _computeFormatTooltipLabels(x, y, text, textStyle); + } else { + // It specifies for range, financial type series. + if (text.contains('\n') || text.contains(':')) { + _computeDefaultTooltipLabels(x, y, text, textStyle); + } else { + // It specifies for xYDataSeriesRenderer. + final double markerPadding = tooltipSettings.canShowMarker ? 5 : 0; + _tooltipLabels.add(_TooltipLabels( + text, + textStyle.copyWith(fontWeight: FontWeight.bold), + Offset((tooltipRRect.left + tooltipRRect.width / 2) + markerPadding, + tooltipRRect.top + tooltipRRect.height / 2) + .translate(-width / 2, -height / 2), + )); + } + } + } + + void _computeDefaultTooltipLabels( + double x, double y, String text, TextStyle textStyle) { + final TextStyle boldStyle = textStyle.copyWith(fontWeight: FontWeight.bold); + double eachTextHeight = 0; + final List labels = text.split('\n'); + final int labelsLength = labels.length; + for (int i = 0; i < labelsLength; i++) { + final String label = labels[i]; + final double dy = y + eachTextHeight; + if (label.contains(':')) { + final List parts = label.split(':'); + final String leftText = '${parts[0]}:'; + final Size leftSize = measureText(leftText, textStyle); + _tooltipLabels.add(_TooltipLabels(leftText, textStyle, Offset(x, dy))); + if (parts.length > 1) { + final String rightText = parts[1]; + _tooltipLabels.add(_TooltipLabels( + rightText, boldStyle, Offset(x + leftSize.width, dy))); + } + eachTextHeight += leftSize.height; + } else { + _tooltipLabels.add(_TooltipLabels(label, boldStyle, Offset(x, dy))); + eachTextHeight += measureText(label, textStyle).height; + } + } + } + + void _computeFormatTooltipLabels( + double x, double y, String text, TextStyle textStyle) { + if (text.contains('\n')) { + _multiLineLabelFormat(x, y, text, textStyle); + } else { + _singleLineLabelFormat(x, y, text, textStyle); + } + } + + void _singleLineLabelFormat( + double x, double y, String label, TextStyle textStyle) { + final TextStyle boldStyle = textStyle.copyWith(fontWeight: FontWeight.bold); + double dx = x; + if (label.contains('') && label.contains('')) { + final List boldParts = label.split(''); + Size textSize = Size.zero; + for (final String text in boldParts) { + if (text.contains('')) { + final List parts = text.split(''); + if (parts.length == 2) { + final String boldText = parts[0]; + if (boldText != '') { + _tooltipLabels + .add(_TooltipLabels(boldText, boldStyle, Offset(dx, y))); + textSize = measureText(boldText, textStyle); + dx += textSize.width; + } + final String normalText = parts[1]; + if (normalText != '') { + _tooltipLabels + .add(_TooltipLabels(normalText, textStyle, Offset(dx, y))); + textSize = measureText(normalText, textStyle); + dx += textSize.width; + } + } + } else { + _tooltipLabels.add(_TooltipLabels(text, textStyle, Offset(dx, y))); + textSize = measureText(text, textStyle); + dx += textSize.width; + } + } + } else if (label.contains(':')) { + _computeDefaultTooltipLabels(x, y, label, textStyle); + } else { + _tooltipLabels.add(_TooltipLabels(label, textStyle, Offset(x, y))); + } + } + + void _multiLineLabelFormat( + double x, double y, String label, TextStyle textStyle) { + final TextStyle boldStyle = textStyle.copyWith(fontWeight: FontWeight.bold); + double dx = x; + double dy = y; + final List multiLines = label.split('\n'); + for (final String text in multiLines) { + if (text.contains('') && text.contains('')) { + final List boldParts = text.split(''); + Size boldPartSize = Size.zero; + for (final String boldPart in boldParts) { + if (boldPart != '') { + if (boldPart.contains('')) { + final List parts = boldPart.split(''); + if (parts.length == 2) { + final String boldText = parts[0]; + if (boldText != '') { + _tooltipLabels + .add(_TooltipLabels(boldText, boldStyle, Offset(dx, dy))); + boldPartSize = measureText(boldText, textStyle); + dx += boldPartSize.width; + } + final String normalText = parts[1]; + if (normalText != '') { + _tooltipLabels.add( + _TooltipLabels(normalText, textStyle, Offset(dx, dy))); + boldPartSize = measureText(normalText, textStyle); + dx += boldPartSize.width; + } + } + } else { + _tooltipLabels + .add(_TooltipLabels(boldPart, textStyle, Offset(dx, dy))); + boldPartSize = measureText(boldPart, textStyle); + dx += boldPartSize.width; + } + boldPartSize = measureText(boldPart, textStyle); + } + } + dx = x; + dy += boldPartSize.height; + } else { + _tooltipLabels.add(_TooltipLabels(text, textStyle, Offset(dx, dy))); + final Size textSize = measureText(text, textStyle); + dy += textSize.height; + } + } + } + + /// Override this method to customize the trackball tooltip labels + /// and it's positions and line rendering. + @override + void onPaint(PaintingContext context, Offset offset, + SfChartThemeData chartThemeData, ThemeData themeData) { + _drawTrackballLine(context, offset, chartThemeData, themeData); + // Draw line marker. + _drawMarkers(context, chartThemeData, _lineMarkers); + _drawLabel(context, offset, chartThemeData, themeData); + } + + void _drawTrackballLine(PaintingContext context, Offset offset, + SfChartThemeData chartThemeData, ThemeData themeData) { + if (chartPointInfo.isNotEmpty && lineType != TrackballLineType.none) { + final Paint paint = Paint() + ..isAntiAlias = true + ..color = (lineColor ?? chartThemeData.crosshairLineColor)! + ..strokeWidth = lineWidth + ..style = PaintingStyle.stroke; + + _drawLine( + context, offset, chartThemeData, themeData, lineDashArray, paint); + } + } + + void _drawLine( + PaintingContext context, + Offset offset, + SfChartThemeData chartThemeData, + ThemeData themeData, + List? dashArray, + Paint paint, + ) { + if (parentBox == null) { + return; + } + + final Rect plotAreaBounds = parentBox!.paintBounds; + final Path path = Path(); + if (_isTransposed) { + final double y = chartPointInfo[0].yPosition!; + path + ..moveTo(plotAreaBounds.left, y) + ..lineTo(plotAreaBounds.right, y); + } else { + final double x = chartPointInfo[0].xPosition!; + path + ..moveTo(x, plotAreaBounds.top) + ..lineTo(x, plotAreaBounds.bottom); + } + drawDashes(context.canvas, dashArray, paint, path: path); + } + + void _drawLabel(PaintingContext context, Offset offset, + SfChartThemeData chartThemeData, ThemeData themeData) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + final bool isRtl = parent.textDirection == TextDirection.rtl; + if (tooltipDisplayMode != TrackballDisplayMode.none) { + // Draw tooltip rectangle. + if (_tooltipPaths.isNotEmpty) { + final Color themeBackgroundColor = + chartThemeData.crosshairBackgroundColor!; + final Paint fillPaint = Paint() + ..color = tooltipSettings.color ?? themeBackgroundColor + ..isAntiAlias = true + ..style = PaintingStyle.fill; + final Paint strokePaint = Paint() + ..color = tooltipSettings.borderColor ?? themeBackgroundColor + ..strokeWidth = tooltipSettings.borderWidth + ..strokeCap = StrokeCap.butt + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + final int length = _tooltipPaths.length; + for (int i = 0; i < length; i++) { + final Path path = _tooltipPaths[i]; + context.canvas.drawPath(path, strokePaint); + context.canvas.drawPath(path, fillPaint); + } + } + + // Draw tooltip marker. + _drawMarkers(context, chartThemeData, _tooltipMarkers); + + // Draw divider. + if (tooltipDisplayMode == TrackballDisplayMode.groupAllPoints && + _dividerStartOffset != null && + _dividerEndOffset != null) { + context.canvas.drawLine( + _dividerStartOffset!, + _dividerEndOffset!, + Paint() + ..color = chartThemeData.tooltipSeparatorColor! + ..strokeWidth = 1 + ..style = PaintingStyle.stroke + ..isAntiAlias = true, + ); + } + + // Draw tooltip labels. + if (_tooltipLabels.isNotEmpty) { + final int length = _tooltipLabels.length; + for (int i = 0; i < length; i++) { + final _TooltipLabels label = _tooltipLabels[i]; + _drawText( + context.canvas, label.text, label.position, label.style, isRtl); + } + } + } + } + + void _drawMarkers(PaintingContext context, SfChartThemeData chartThemeData, + List markers) { + if (markers.isNotEmpty) { + final Paint fillPaint = Paint()..isAntiAlias = true; + final Paint strokePaint = Paint() + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + for (final ChartMarker marker in markers) { + fillPaint + ..color = marker.color! + ..shader = marker.shader; + strokePaint + ..color = marker.borderColor! + ..strokeWidth = marker.borderWidth; + _drawMarker( + context.canvas, + marker.position, + Size(marker.width, marker.height), + marker.type, + fillPaint, + strokePaint, + ); + } + } + } + + void _drawMarker(Canvas canvas, Offset position, Size size, + DataMarkerType type, Paint fillPaint, Paint strokePaint) { + if (position.isNaN) { + return; + } + + if (type == DataMarkerType.image) { + if (_trackballImage != null) { + paintImage( + canvas: canvas, rect: position & size, image: _trackballImage!); + } + } else if (type != DataMarkerType.none) { + paint( + canvas: canvas, + rect: position & size, + shapeType: toShapeMarkerType(type), + paint: fillPaint, + borderPaint: strokePaint, + ); + } + } + + void _drawText(Canvas canvas, String text, Offset position, TextStyle style, + bool isRtl) { + final TextPainter textPainter = TextPainter( + text: TextSpan(text: text, style: style), + textAlign: isRtl ? TextAlign.right : TextAlign.left, + maxLines: getMaxLinesContent(text), + textDirection: isRtl ? TextDirection.rtl : TextDirection.ltr, + ); + textPainter + ..layout() + ..paint(canvas, position); + } +} + +class TrackballBuilderOpacityWidget extends Opacity { + const TrackballBuilderOpacityWidget({ + super.key, + super.child, + required super.opacity, + }); + + @override + RenderOpacity createRenderObject(BuildContext context) { + return TrackballOpacityRenderBox( + opacity: opacity, + alwaysIncludeSemantics: alwaysIncludeSemantics, + ); + } +} + +class TrackballOpacityRenderBox extends RenderOpacity { + TrackballOpacityRenderBox({ + super.opacity = 1.0, + super.alwaysIncludeSemantics = false, + super.child, + }); +} + +class TrackballBuilderRenderObjectWidget extends SingleChildRenderObjectWidget { + const TrackballBuilderRenderObjectWidget( + {Key? key, + this.index, + required this.xPos, + required this.yPos, + required this.builder, + required this.chartPointInfo, + required this.trackballBehavior, + required Widget child}) + : super(key: key, child: child); + + final int? index; + final double xPos; + final double yPos; + final Widget builder; + final List? chartPointInfo; + final TrackballBehavior trackballBehavior; + + @override + RenderObject createRenderObject(BuildContext context) { + return TrackballBuilderRenderBox( + index, + xPos, + yPos, + builder, + chartPointInfo, + trackballBehavior, + ); + } + + @override + void updateRenderObject( + BuildContext context, covariant TrackballBuilderRenderBox renderObject) { + super.updateRenderObject(context, renderObject); + renderObject + ..index = index + ..xPos = xPos + ..yPos = yPos + ..builder = builder + ..chartPointInfo = chartPointInfo + ..trackballBehavior = trackballBehavior; + } +} + +/// Render the annotation widget in the respective position. +class TrackballBuilderRenderBox extends RenderShiftedBox { + /// Creates an instance of trackball template render box. + TrackballBuilderRenderBox(this.index, this.xPos, this.yPos, this._builder, + this.chartPointInfo, this.trackballBehavior, + [RenderBox? child]) + : super(child); + + /// Holds the value of x and y position. + double xPos, yPos; + + /// Specifies the list of chart point info. + List? chartPointInfo; + + /// Holds the value of index. + int? index; + + /// Holds the value of pointer length and pointer width respectively. + late double pointerLength, pointerWidth; + + /// Holds the value of trackball template rect. + Rect? trackballTemplateRect; + + /// Holds the value of boundary rect. + late Rect plotAreaBounds; + + /// Specifies the value of padding. + num padding = 10; + + /// Specifies the value of trackball behavior. + TrackballBehavior trackballBehavior; + + /// Specifies whether to group all the points. + bool isGroupAllPoints = false; + + /// Specifies whether it is the nearest point. + bool isNearestPoint = false; + + /// Specifies whether tooltip is present at right. + bool isRight = false; + + /// Specifies whether tooltip is present at bottom. + bool isBottom = false; + + /// Specifies whether the template is present inside the bounds. + bool isTemplateInBounds = true; + // Offset arrowOffset; + + /// Holds the tooltip position. + _TooltipPositions? _tooltipPosition; + + /// Holds the value of box parent data. + late BoxParentData childParentData; + + /// Gets and sets the builder widget. + Widget get builder => _builder; + Widget _builder; + set builder(Widget value) { + if (_builder != value) { + _builder = value; + markNeedsLayout(); + } + } + + bool isTransposed = false; + + @override + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { + if (child != null && child!.parentData != null) { + final BoxParentData childParentData = child!.parentData! as BoxParentData; + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + return child!.hitTest(result, position: transformed); + }, + ); + } + return false; + } + + @override + void performLayout() { + size = constraints.biggest; + isTransposed = chartPointInfo != null && + chartPointInfo!.isNotEmpty && + chartPointInfo![0].series!.isTransposed; + final TrackballDisplayMode tooltipDisplayMode = + trackballBehavior.tooltipDisplayMode; + isGroupAllPoints = + tooltipDisplayMode == TrackballDisplayMode.groupAllPoints; + isNearestPoint = tooltipDisplayMode == TrackballDisplayMode.nearestPoint; + + final List? tooltipTop = []; + final List tooltipBottom = []; + final List xAxesInfo = []; + final List yAxesInfo = []; + final bool isTrackballMarkerEnabled = + trackballBehavior.markerSettings != null; + + final List visiblePoints = trackballBehavior._visiblePoints; + pointerLength = trackballBehavior.tooltipSettings.arrowLength; + pointerWidth = trackballBehavior.tooltipSettings.arrowWidth; + plotAreaBounds = trackballBehavior._plotAreaBounds; + final double boundaryLeft = plotAreaBounds.left; + final double boundaryRight = plotAreaBounds.right; + final num totalWidth = boundaryLeft + plotAreaBounds.width; + double left; + double top; + if (child != null) { + child!.layout(constraints, parentUsesSize: true); + if (child!.parentData is BoxParentData) { + childParentData = child!.parentData as BoxParentData; + final double sizeFullWidth = child!.size.width; + final double sizeFullHeight = child!.size.height; + final double sizeHalfWidth = sizeFullWidth / 2; + final double sizeHalfHeight = sizeFullHeight / 2; + + if (isGroupAllPoints) { + final ChartAlignment tooltipAlignment = + trackballBehavior.tooltipAlignment; + if (tooltipAlignment == ChartAlignment.center) { + yPos = plotAreaBounds.center.dy - sizeHalfHeight; + } else if (tooltipAlignment == ChartAlignment.near) { + yPos = plotAreaBounds.top; + } else { + yPos = plotAreaBounds.bottom; + } + + if (yPos + sizeFullHeight > plotAreaBounds.bottom && + tooltipAlignment == ChartAlignment.far) { + yPos = plotAreaBounds.bottom - sizeFullHeight; + } + } + + final double markerHalfWidth = isTrackballMarkerEnabled + ? trackballBehavior.markerSettings!.width / 2 + : 0; + + if (chartPointInfo != null && + chartPointInfo!.isNotEmpty && + !isGroupAllPoints) { + final int length = chartPointInfo!.length; + for (int i = 0; i < length; i++) { + final dynamic series = chartPointInfo![i].series!; + final Offset visiblePoint = visiblePoints[i]; + final double closestPointX = visiblePoint.dx; + final double closestPointY = visiblePoint.dy; + tooltipTop!.add(isTransposed + ? closestPointX - sizeHalfWidth + : closestPointY - sizeHalfHeight); + tooltipBottom.add(isTransposed + ? closestPointX + sizeHalfWidth + : closestPointY + sizeHalfHeight); + xAxesInfo.add(series.xAxis!); + yAxesInfo.add(series.yAxis!); + } + + if (tooltipTop != null && tooltipTop.isNotEmpty) { + _tooltipPosition = trackballBehavior._smartTooltipPositions( + tooltipTop, + tooltipBottom, + xAxesInfo, + yAxesInfo, + chartPointInfo!, + isTransposed ? 8 : 5); + } + + if (isNearestPoint) { + left = isTransposed + ? xPos + sizeHalfWidth + : xPos + padding + markerHalfWidth; + top = isTransposed + ? yPos + padding + markerHalfWidth + : yPos - sizeHalfHeight; + } else { + left = (isTransposed + ? _tooltipPosition!.tooltipTop[index!] + : xPos + padding + markerHalfWidth) + .toDouble(); + top = (isTransposed + ? yPos + pointerLength + markerHalfWidth + : _tooltipPosition!.tooltipTop[index!]) + .toDouble(); + } + + if (!isTransposed) { + if (left + sizeFullWidth > totalWidth) { + isRight = true; + left = xPos - sizeFullWidth - pointerLength - markerHalfWidth; + } else { + isRight = false; + } + } else { + if (top + sizeFullHeight > plotAreaBounds.bottom) { + isBottom = true; + top = yPos - sizeFullHeight - pointerLength - markerHalfWidth; + } else { + isBottom = false; + } + } + + trackballTemplateRect = + Rect.fromLTWH(left, top, sizeFullWidth, sizeFullHeight); + double xPlotOffset = + visiblePoints.first.dx - trackballTemplateRect!.width / 2; + final double rightTemplateEnd = + xPlotOffset + trackballTemplateRect!.width; + final double leftTemplateEnd = xPlotOffset; + + if (_isTemplateWithinBounds(plotAreaBounds, trackballTemplateRect!)) { + isTemplateInBounds = true; + childParentData.offset = Offset(left, top); + } else if (plotAreaBounds.width > trackballTemplateRect!.width && + plotAreaBounds.height > trackballTemplateRect!.height) { + isTemplateInBounds = true; + if (rightTemplateEnd > boundaryRight) { + xPlotOffset = xPlotOffset - (rightTemplateEnd - boundaryRight); + if (xPlotOffset < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - xPlotOffset); + if (xPlotOffset + trackballTemplateRect!.width > + boundaryRight) { + xPlotOffset = xPlotOffset - + (totalWidth + + trackballTemplateRect!.width - + boundaryRight); + } + if (xPlotOffset < boundaryLeft || xPlotOffset > boundaryRight) { + isTemplateInBounds = false; + } + } + } else if (leftTemplateEnd < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - leftTemplateEnd); + if (xPlotOffset + trackballTemplateRect!.width > boundaryRight) { + xPlotOffset = xPlotOffset - + (totalWidth + trackballTemplateRect!.width - boundaryRight); + if (xPlotOffset < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - xPlotOffset); + } + if (xPlotOffset < boundaryLeft || + xPlotOffset + trackballTemplateRect!.width > + boundaryRight) { + isTemplateInBounds = false; + } + } + } + childParentData.offset = Offset(xPlotOffset, yPos); + } else { + child!.layout(constraints.copyWith(maxWidth: 0), + parentUsesSize: true); + isTemplateInBounds = false; + } + } else { + if (visiblePoints.isNotEmpty) { + if (xPos + sizeFullWidth > totalWidth) { + xPos = xPos - sizeFullWidth - 2 * padding - markerHalfWidth; + } + + trackballTemplateRect = + Rect.fromLTWH(xPos, yPos, sizeFullWidth, sizeFullHeight); + double xPlotOffset = + visiblePoints.first.dx - trackballTemplateRect!.width / 2; + final double rightTemplateEnd = + xPlotOffset + trackballTemplateRect!.width; + final double leftTemplateEnd = xPlotOffset; + + if (_isTemplateWithinBounds( + plotAreaBounds, trackballTemplateRect!) && + (boundaryRight > trackballTemplateRect!.right && + boundaryLeft < trackballTemplateRect!.left)) { + isTemplateInBounds = true; + childParentData.offset = Offset( + xPos + + (trackballTemplateRect!.right + padding > boundaryRight + ? trackballTemplateRect!.right + + padding - + boundaryRight + : padding) + + markerHalfWidth, + yPos); + } else if (plotAreaBounds.width > trackballTemplateRect!.width && + plotAreaBounds.height > trackballTemplateRect!.height) { + isTemplateInBounds = true; + if (rightTemplateEnd > boundaryRight) { + xPlotOffset = xPlotOffset - (rightTemplateEnd - boundaryRight); + if (xPlotOffset < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - xPlotOffset); + if (xPlotOffset + trackballTemplateRect!.width > + boundaryRight) { + xPlotOffset = xPlotOffset - + (totalWidth + + trackballTemplateRect!.width - + boundaryRight); + } + if (xPlotOffset < boundaryLeft || + xPlotOffset > boundaryRight) { + isTemplateInBounds = false; + } + } + } else if (leftTemplateEnd < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - leftTemplateEnd); + if (xPlotOffset + trackballTemplateRect!.width > + boundaryRight) { + xPlotOffset = xPlotOffset - + (xPlotOffset + + trackballTemplateRect!.width - + boundaryRight); + if (xPlotOffset < boundaryLeft) { + xPlotOffset = xPlotOffset + (boundaryLeft - xPlotOffset); + } + if (xPlotOffset < boundaryLeft || + xPlotOffset > boundaryRight) { + isTemplateInBounds = false; + } + } + } + childParentData.offset = Offset(xPlotOffset, yPos); + } else { + child!.layout(constraints.copyWith(maxWidth: 0), + parentUsesSize: true); + isTemplateInBounds = false; + } + } + } + } + } + if (!isGroupAllPoints && index == chartPointInfo!.length - 1) { + tooltipTop?.clear(); + tooltipBottom.clear(); + yAxesInfo.clear(); + xAxesInfo.clear(); + } + } + + /// To check template is within bounds. + bool _isTemplateWithinBounds(Rect plotAreaBounds, Rect templateRect) { + final double triplePadding = (3 * padding).toDouble(); + final Rect rect = Rect.fromLTWH( + padding + templateRect.left, + triplePadding + templateRect.top, + templateRect.width, + templateRect.height); + final Rect axisBounds = Rect.fromLTWH( + padding + plotAreaBounds.left, + triplePadding + plotAreaBounds.top, + plotAreaBounds.width, + plotAreaBounds.height); + return rect.left >= axisBounds.left && + rect.left + rect.width <= axisBounds.left + axisBounds.width && + rect.top >= axisBounds.top && + rect.bottom <= axisBounds.top + axisBounds.height; + } + + void _calculateMarkerPositions(PaintingContext context, + SfChartThemeData chartThemeData, ThemeData themeData) { + final TrackballMarkerSettings? markerSettings = + trackballBehavior.markerSettings; + if ((chartPointInfo != null && chartPointInfo!.isEmpty) || + markerSettings == null || + markerSettings.markerVisibility == TrackballVisibilityMode.hidden) { + return; + } + + final List markers = []; + trackballBehavior._computeLineMarkers(themeData, markers); + trackballBehavior._drawMarkers(context, chartThemeData, markers); + } + + @override + void paint(PaintingContext context, Offset offset) { + final SfChartThemeData chartThemeData = trackballBehavior._chartThemeData!; + final ThemeData themeData = trackballBehavior._themeData!; + _calculateMarkerPositions(context, chartThemeData, themeData); + + final bool isTemplateWithInBoundsInTransposedChart = + _isTemplateWithinBounds(plotAreaBounds, trackballTemplateRect!); + if ((!isTransposed && isTemplateInBounds) || + (isTransposed && isTemplateWithInBoundsInTransposedChart)) { + super.paint(context, offset); + } + + if (!isGroupAllPoints) { + final Color chartThemeBackgroundColor = + chartThemeData.crosshairBackgroundColor!; + final ChartPointInfo pointInfo = chartPointInfo![index!]; + final Color color = pointInfo.series is IndicatorRenderer + ? pointInfo.color + : (pointInfo.series!.color) ?? chartThemeBackgroundColor; + final InteractiveTooltip tooltipSettings = + trackballBehavior.tooltipSettings; + final Paint fillPaint = Paint() + ..color = tooltipSettings.color ?? color + ..isAntiAlias = true + ..style = PaintingStyle.fill; + final Paint strokePaint = Paint() + ..color = tooltipSettings.borderColor ?? color + ..strokeWidth = tooltipSettings.borderWidth + ..strokeCap = StrokeCap.butt + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + + if (trackballTemplateRect!.left > plotAreaBounds.left && + trackballTemplateRect!.right < plotAreaBounds.right) { + final RRect templateRRect = RRect.fromRectAndRadius( + Rect.fromLTWH( + offset.dx + trackballTemplateRect!.left, + offset.dy + trackballTemplateRect!.top, + trackballTemplateRect!.width, + trackballTemplateRect!.height), + Radius.zero); + + String nosePosition = ''; + if (!isTransposed) { + if (!isRight) { + nosePosition = 'Right'; + } else { + nosePosition = 'Left'; + } + } else if (isTemplateInBounds && + isTemplateWithInBoundsInTransposedChart) { + if (!isBottom) { + nosePosition = 'Bottom'; + } else { + nosePosition = 'Top'; + } + } + + final Path nosePath = trackballBehavior._nosePath(nosePosition, + templateRRect, Offset(xPos, yPos), pointerLength, pointerWidth); + + if (isTemplateInBounds) { + context.canvas.drawPath(nosePath, fillPaint); + context.canvas.drawPath(nosePath, strokePaint); + } + } + } + } +} + +/// Options to customize the markers that are displayed when +/// trackball is enabled. +/// +/// Trackball markers are used to provide information about the exact +/// point location, when the trackball is visible. You can add a shape to adorn +/// each data point. Trackball markers can be enabled by using the +/// [markerVisibility] property in [TrackballMarkerSettings]. +/// Provides the options like color, border width, border color and shape of the +/// marker to customize the appearance. +class TrackballMarkerSettings extends MarkerSettings { + /// Creating an argument constructor of TrackballMarkerSettings class. + const TrackballMarkerSettings({ + this.markerVisibility = TrackballVisibilityMode.auto, + super.height, + super.width, + super.color, + super.shape, + super.borderWidth, + super.borderColor, + super.image, + }); + + /// Whether marker should be visible or not when trackball is enabled. + /// + /// The below values are applicable for this: + /// * TrackballVisibilityMode.auto - If the [isVisible] property in the series + /// `markerSettings` is set to true, then the trackball marker will also be + /// displayed for that particular series, else it will not be displayed. + /// * TrackballVisibilityMode.visible - Makes the trackball marker visible + /// for all the series, + /// irrespective of considering the [isVisible] property's value in the + /// `markerSettings`. + /// * TrackballVisibilityMode.hidden - Hides the trackball marker for all + /// the series. + /// + /// Defaults to `TrackballVisibilityMode.auto`. + /// + /// Also refer [TrackballVisibilityMode]. + /// + /// ```dart + /// late TrackballBehavior trackballBehavior; + /// + /// void initState() { + /// trackballBehavior = TrackballBehavior( + /// enable: true, + /// markerSettings: TrackballMarkerSettings( + /// markerVisibility: TrackballVisibilityMode.visible, + /// width: 10 + /// ) + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// trackballBehavior: trackballBehavior + /// ); + /// } + ///``` + final TrackballVisibilityMode markerVisibility; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + + return other is TrackballMarkerSettings && + other.markerVisibility == markerVisibility && + other.height == height && + other.width == width && + other.color == color && + other.shape == shape && + other.borderWidth == borderWidth && + other.borderColor == borderColor && + other.image == image; + } + + @override + int get hashCode { + final List values = [ + markerVisibility, + height, + width, + color, + shape, + borderWidth, + borderColor, + image + ]; + return Object.hashAll(values); + } +} + +class TrackballInfo { + TrackballInfo({ + required this.position, + this.name, + this.color, + }); + + /// Local position of the tooltip. + final Offset? position; + + /// Specifies the series name. + final String? name; + + /// Specifies the series color. + final Color? color; +} + +class ChartTrackballInfo extends TrackballInfo { + ChartTrackballInfo({ + required super.position, + required this.point, + required this.series, + required this.seriesIndex, + required this.segmentIndex, + required this.pointIndex, + this.header, + this.text, + this.lowYPos, + this.highXPos, + this.highYPos, + this.openXPos, + this.openYPos, + this.closeXPos, + this.closeYPos, + this.minYPos, + this.maxXPos, + this.maxYPos, + this.lowerXPos, + this.lowerYPos, + this.upperXPos, + this.upperYPos, + super.name, + super.color, + }); + + final CartesianChartPoint point; + final dynamic series; + final int seriesIndex; + final int segmentIndex; + final int pointIndex; + final String? header; + final String? text; + + double? lowYPos; + double? highXPos; + double? highYPos; + double? openXPos; + double? openYPos; + double? closeXPos; + double? closeYPos; + double? minYPos; + double? maxXPos; + double? maxYPos; + double? lowerXPos; + double? lowerYPos; + double? upperXPos; + double? upperYPos; +} + +/// Class to store trackball tooltip start and end positions. +class _TooltipPositions { + /// Creates the parameterized constructor for the class TooltipPositions. + const _TooltipPositions(this.tooltipTop, this.tooltipBottom); + + /// Specifies the tooltip top value. + final List tooltipTop; + + /// Specifies the tooltip bottom value. + final List tooltipBottom; +} + +/// Class to store trackball tooltip label, label style and positions. +class _TooltipLabels { + /// Creates the parameterized constructor for the class _TooltipLabels. + _TooltipLabels(this.text, this.style, this.position); + + /// Specifies the tooltip label value. + final String text; + + /// Specifies the tooltip label style value. + final TextStyle style; + + /// Specifies the tooltip label position value. + final Offset position; +} diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/zooming.dart b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/zooming.dart new file mode 100644 index 000000000..a0933a671 --- /dev/null +++ b/packages/syncfusion_flutter_charts/lib/src/charts/behaviors/zooming.dart @@ -0,0 +1,1825 @@ +import 'dart:math'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:intl/intl.dart'; +import 'package:syncfusion_flutter_core/core.dart'; +import 'package:syncfusion_flutter_core/theme.dart'; + +import '../../sparkline/utils/helper.dart'; +import '../axis/axis.dart'; +import '../axis/category_axis.dart'; +import '../axis/datetime_axis.dart'; +import '../axis/datetime_category_axis.dart'; +import '../axis/logarithmic_axis.dart'; +import '../axis/numeric_axis.dart'; +import '../base.dart'; +import '../common/callbacks.dart'; +import '../common/interactive_tooltip.dart'; +import '../interactions/behavior.dart'; +import '../utils/enum.dart'; +import '../utils/helper.dart'; +import '../utils/typedef.dart'; + +/// Customizes the zooming options. +/// +/// Customize the various zooming actions such as tap zooming, selection +/// zooming, zoom pinch. In selection zooming, you can long-press and drag to +/// select a range on the chart to be zoomed in and also you can customize the +/// selection zooming rectangle using `selectionRectBorderWidth`, +/// `selectionRectBorderColor` and `selectionRectColor` properties. +/// +/// Pinch zooming can be performed by moving two fingers over the chart. +/// Default mode is [ZoomMode.xy]. Zooming will be stopped after reaching +/// `maximumZoomLevel`. +/// +/// _Note:_ This is only applicable for `SfCartesianChart`. +class ZoomPanBehavior extends ChartBehavior { + /// Creating an argument constructor of ZoomPanBehavior class. + ZoomPanBehavior({ + this.enablePinching = false, + this.enableDoubleTapZooming = false, + this.enablePanning = false, + this.enableSelectionZooming = false, + this.enableMouseWheelZooming = false, + this.zoomMode = ZoomMode.xy, + this.maximumZoomLevel = 0.01, + this.selectionRectBorderWidth = 1, + this.selectionRectBorderColor, + this.selectionRectColor, + }); + + /// Enables or disables the pinch zooming. + /// + /// Pinching can be performed by moving two fingers over the chart. + /// You can zoom the chart through pinch gesture in touch enabled devices. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enablePinching: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final bool enablePinching; + + /// Enables or disables the double tap zooming. + /// + /// Zooming will enable when you tap double time in plot area. + /// After reaching the maximum zoom level, zooming will be stopped. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableDoubleTapZooming: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final bool enableDoubleTapZooming; + + /// Enables or disables the panning. + /// + /// Panning can be performed on a zoomed axis. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enablePanning: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final bool enablePanning; + + /// Enables or disables the selection zooming. + /// + /// Selection zooming can be performed by long-press and then dragging. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableSelectionZooming: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final bool enableSelectionZooming; + + /// Enables or disables the mouseWheelZooming. + /// + /// Mouse wheel zooming can be performed by rolling the mouse wheel up or + /// down. The place where the cursor is hovering gets zoomed in or out + /// according to the mouse wheel rolling up or down. + /// + /// Defaults to `false`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableMouseWheelZooming: true + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final bool enableMouseWheelZooming; + + /// By default, both the x and y-axes in the chart can be zoomed. + /// + /// It can be changed by setting value to this property. + /// + /// Defaults to `ZoomMode.xy`. + /// + /// Also refer [ZoomMode]. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// zoomMode: ZoomMode.x + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final ZoomMode zoomMode; + + /// Maximum zoom level. + /// + /// Zooming will be stopped after reached this value and ranges from 0 to 1. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// maximumZoomLevel: 0.8 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final double maximumZoomLevel; + + /// Border width of the selection zooming rectangle. + /// + /// Used to change the stroke width of the selection rectangle. + /// + /// Defaults to `1`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableSelectionZooming: true, + /// selectionRectBorderWidth: 2 + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final double selectionRectBorderWidth; + + /// Border color of the selection zooming rectangle. + /// + /// It used to change the stroke color of the selection rectangle. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableSelectionZooming: true, + /// selectionRectBorderColor: Colors.red + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final Color? selectionRectBorderColor; + + /// Color of the selection zooming rectangle. + /// + /// It used to change the background color of the selection rectangle. + /// + /// Defaults to `null`. + /// + /// ```dart + /// late ZoomPanBehavior zoomPanBehavior; + /// + /// void initState() { + /// zoomPanBehavior = ZoomPanBehavior( + /// enableSelectionZooming: true, + /// selectionRectColor: Colors.yellow + /// ); + /// super.initState(); + /// } + /// + /// Widget build(BuildContext context) { + /// return SfCartesianChart( + /// zoomPanBehavior: zoomPanBehavior + /// ); + /// } + /// ``` + final Color? selectionRectColor; + + late bool _isZoomIn, _isZoomOut; + Path? _rectPath; + + bool? _isPinching = false; + Offset? _previousMovedPosition; + Offset? _zoomStartPosition; + List _touchStartPositions = []; + List _touchMovePositions = []; + List<_ZoomAxisRange> _zoomAxes = <_ZoomAxisRange>[]; + + /// Holds the value of zooming rect. + Rect _zoomingRect = Rect.zero; + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + + return other is ZoomPanBehavior && + other.enablePinching == enablePinching && + other.enableDoubleTapZooming == enableDoubleTapZooming && + other.enablePanning == enablePanning && + other.enableSelectionZooming == enableSelectionZooming && + other.enableMouseWheelZooming == enableMouseWheelZooming && + other.zoomMode == zoomMode && + other.maximumZoomLevel == maximumZoomLevel && + other.selectionRectBorderWidth == selectionRectBorderWidth && + other.selectionRectBorderColor == selectionRectBorderColor && + other.selectionRectColor == selectionRectColor; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode { + final List values = [ + enablePinching, + enableDoubleTapZooming, + enablePanning, + enableSelectionZooming, + enableMouseWheelZooming, + zoomMode, + maximumZoomLevel, + selectionRectBorderWidth, + selectionRectBorderColor, + selectionRectColor + ]; + return Object.hashAll(values); + } + + /// To customize the necessary pointer events in behaviors. + /// (e.g., CrosshairBehavior, TrackballBehavior, ZoomingBehavior). + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (event is PointerScrollEvent || event is PointerPanZoomUpdateEvent) { + _handlePanZoomUpdate(event); + } + if (event is PointerDownEvent) { + _startPinchZooming(event); + } + if (event is PointerMoveEvent) { + _performPinchZoomUpdate(event); + } + if (event is PointerUpEvent) { + _endPinchZooming(event); + } + } + + /// Called when a long press gesture by a primary button has been + /// recognized in behavior. + @override + void handleLongPressStart(LongPressStartDetails details) { + if (enableSelectionZooming) { + _longPressStart(parentBox!.globalToLocal(details.globalPosition)); + } + } + + /// Called when moving after the long press gesture by a primary button is + /// recognized in behavior. + @override + void handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + if (enableSelectionZooming) { + final Offset position = parentBox!.globalToLocal(details.globalPosition); + _doSelectionZooming(position.dx, position.dy); + parentBox!.markNeedsPaint(); + } + } + + /// Called when the pointer stops contacting the screen after a long-press + /// by a primary button in behavior. + @override + void handleLongPressEnd(LongPressEndDetails details) { + if (enableSelectionZooming) { + _longPressEnd(); + parentBox!.markNeedsPaint(); + } + } + + /// Called when pointer tap has contacted the screen double time in behavior. + @override + void handleDoubleTap(Offset position) { + final RenderBehaviorArea parent = parentBox as RenderBehaviorArea; + final Offset localPosition = parentBox!.globalToLocal(position); + if (enableDoubleTapZooming) { + parent.hideInteractiveTooltip(); + _doubleTap(localPosition, parentBox!.paintBounds); + } + } + + /// Called when the pointers in contact with the screen, + /// and initial scale of 1.0. + @override + void handleScaleStart(ScaleStartDetails details) { + _startPanning(); + } + + /// Called when the pointers in contact with the screen have indicated + /// a new scale. + @override + void handleScaleUpdate(ScaleUpdateDetails details) { + _performPanning(details); + } + + /// Called when the pointers are no longer in contact with the screen. + @override + void handleScaleEnd(ScaleEndDetails details) { + _endPanning(); + } + + void _handlePanZoomUpdate(PointerEvent details) { + if (parentBox!.attached && enableMouseWheelZooming) { + final Offset localPosition = parentBox!.globalToLocal(details.position); + final Rect paintBounds = parentBox!.paintBounds; + _performMouseWheelZooming( + details, localPosition.dx, localPosition.dy, paintBounds); + } + } + + void _performPinchZoomUpdate(PointerMoveEvent event) { + final RenderBehaviorArea parent = parentBox as RenderBehaviorArea; + if (parent.performZoomThroughTouch && enablePinching) { + _zoom(event); + } + } + + void _performPanning(ScaleUpdateDetails details) { + if (enablePanning) { + _pan( + parentBox!.globalToLocal(details.focalPoint), parentBox!.paintBounds); + } + } + + void _zoom(PointerMoveEvent event) { + Rect? pinchRect; + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + final RenderCartesianAxes? axes = parent.cartesianAxes; + if (axes == null) { + return; + } + final Rect clipRect = parent.paintBounds; + num selectionMin, selectionMax, rangeMin, rangeMax, value, axisTrans; + double currentFactor, currentPosition, maxZoomFactor, currentZoomFactor; + int count = 0; + if (enablePinching && _touchStartPositions.length == 2) { + _isPinching = true; + final int pointerID = event.pointer; + bool addPointer = true; + for (int i = 0; i < _touchMovePositions.length; i++) { + if (_touchMovePositions[i].pointer == pointerID) { + addPointer = false; + } + } + if (_touchMovePositions.length < 2 && addPointer) { + _touchMovePositions.add(event); + } + if (_touchMovePositions.length == 2) { + if (_touchMovePositions[0].pointer == event.pointer) { + _touchMovePositions[0] = event; + } + if (_touchMovePositions[1].pointer == event.pointer) { + _touchMovePositions[1] = event; + } + Offset touchStart0, touchEnd0, touchStart1, touchEnd1; + _calculateZoomAxesRange(axes); + final Rect containerRect = Offset.zero & clipRect.size; + touchStart0 = _touchStartPositions[0].position - containerRect.topLeft; + touchEnd0 = _touchMovePositions[0].position - containerRect.topLeft; + touchStart1 = _touchStartPositions[1].position - containerRect.topLeft; + touchEnd1 = _touchMovePositions[1].position - containerRect.topLeft; + final double scaleX = (touchEnd0.dx - touchEnd1.dx).abs() / + (touchStart0.dx - touchStart1.dx).abs(); + final double scaleY = (touchEnd0.dy - touchEnd1.dy).abs() / + (touchStart0.dy - touchStart1.dy).abs(); + final double clipX = ((clipRect.left - touchEnd0.dx) / scaleX) + + min(touchStart0.dx, touchStart1.dx); + final double clipY = ((clipRect.top - touchEnd0.dy) / scaleY) + + min(touchStart0.dy, touchStart1.dy); + pinchRect = Rect.fromLTWH( + clipX, clipY, clipRect.width / scaleX, clipRect.height / scaleY); + } + } + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis && pinchRect != null) { + child.zoomingInProgress = true; + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + if (!child.isVertical) { + value = pinchRect.left - clipRect.left; + axisTrans = clipRect.width / _zoomAxes[count].delta!; + rangeMin = value / axisTrans + _zoomAxes[count].min!; + value = pinchRect.left + pinchRect.width - clipRect.left; + rangeMax = value / axisTrans + _zoomAxes[count].min!; + } else { + value = pinchRect.top - clipRect.top; + axisTrans = clipRect.height / _zoomAxes[count].delta!; + rangeMin = (value * -1 + clipRect.height) / axisTrans + + _zoomAxes[count].min!; + value = pinchRect.top + pinchRect.height - clipRect.top; + rangeMax = (value * -1 + clipRect.height) / axisTrans + + _zoomAxes[count].min!; + } + selectionMin = min(rangeMin, rangeMax); + selectionMax = max(rangeMin, rangeMax); + currentPosition = (selectionMin - _zoomAxes[count].actualMin!) / + _zoomAxes[count].actualDelta!; + currentFactor = + (selectionMax - selectionMin) / _zoomAxes[count].actualDelta!; + child.controller.zoomPosition = + currentPosition < 0 ? 0 : currentPosition; + currentZoomFactor = currentFactor > 1 ? 1 : currentFactor; + maxZoomFactor = maximumZoomLevel; + child.controller.zoomFactor = currentZoomFactor < maxZoomFactor + ? maxZoomFactor + : currentZoomFactor; + parent.hideInteractiveTooltip(); + } + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + } + count++; + }); + } + + void _pan(Offset currentPosition, Rect plotAreaBound) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + final RenderCartesianAxes? axes = parent.cartesianAxes; + if (axes == null) { + return; + } + double currentZoomPosition; + num currentScale, value; + if (_previousMovedPosition != null) { + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + child.zoomingInProgress = true; + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + currentZoomPosition = child.controller.zoomPosition; + currentScale = + max(1 / _minMax(child.controller.zoomFactor, 0, 1), 1); + if (child.isVertical) { + value = (_previousMovedPosition!.dy - currentPosition.dy) / + plotAreaBound.height / + currentScale; + currentZoomPosition = _minMax( + child.isInversed + ? child.controller.zoomPosition + value + : child.controller.zoomPosition - value, + 0, + 1 - child.controller.zoomFactor); + if (currentZoomPosition != child.controller.zoomPosition) { + child.controller.zoomPosition = currentZoomPosition; + parent.hideInteractiveTooltip(); + } + } else { + value = (_previousMovedPosition!.dx - currentPosition.dx) / + plotAreaBound.width / + currentScale; + currentZoomPosition = _minMax( + child.isInversed + ? child.controller.zoomPosition - value + : child.controller.zoomPosition + value, + 0, + 1 - child.controller.zoomFactor); + if (currentZoomPosition != child.controller.zoomPosition) { + child.controller.zoomPosition = currentZoomPosition; + parent.hideInteractiveTooltip(); + } + } + } + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + } + }); + } + _previousMovedPosition = currentPosition; + } + + void _doubleTap(Offset position, Rect plotAreaBounds) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + final RenderCartesianAxes? axes = parent.cartesianAxes; + if (axes == null) { + return; + } + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + child.zoomingInProgress = true; + if (parent.onZoomStart != null) { + _bindZoomEvent(child, parent.onZoomStart!); + } + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + double zoomFactor = child.controller.zoomFactor; + final double cumulative = max( + max(1 / _minMax(child.controller.zoomFactor, 0, 1), 1) + (0.25), + 1); + if (cumulative >= 1) { + double origin = child.isVertical + ? 1 - (position.dy / plotAreaBounds.height) + : position.dx / plotAreaBounds.width; + origin = origin > 1 + ? 1 + : origin < 0 + ? 0 + : origin; + zoomFactor = cumulative == 1 ? 1 : _minMax(1 / cumulative, 0, 1); + final double zoomPosition = (cumulative == 1) + ? 0 + : child.controller.zoomPosition + + ((child.controller.zoomFactor - zoomFactor) * origin); + if (child.controller.zoomPosition != zoomPosition || + child.controller.zoomFactor != zoomFactor) { + zoomFactor = (zoomPosition + zoomFactor) > 1 + ? (1 - zoomPosition) + : zoomFactor; + } + + child.controller.zoomPosition = zoomPosition; + child.controller.zoomFactor = zoomFactor; + parent.hideInteractiveTooltip(); + } + final double maxZoomFactor = maximumZoomLevel; + if (zoomFactor < maxZoomFactor) { + child.controller.zoomFactor = maxZoomFactor; + child.controller.zoomPosition = 0.0; + zoomFactor = maxZoomFactor; + } + } + if (parent.onZoomEnd != null) { + _bindZoomEvent(child, parent.onZoomEnd!); + } + } + }); + } + + /// Below method is for mouse wheel Zooming. + void _performMouseWheelZooming( + PointerEvent event, double mouseX, double mouseY, Rect plotAreaBounds) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + final RenderCartesianAxes? axes = parent.cartesianAxes; + if (axes == null) { + return; + } + double direction = 0.0; + if (event is PointerScrollEvent) { + direction = (event.scrollDelta.dy / 120) > 0 ? -1 : 1; + } else if (event is PointerPanZoomUpdateEvent) { + direction = event.panDelta.dy == 0 + ? 0 + : (event.panDelta.dy / 120) > 0 + ? 1 + : -1; + } + double origin = 0.5; + double cumulative, zoomFactor, zoomPosition, maxZoomFactor; + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + child.zoomingInProgress = true; + if (parent.onZoomStart != null) { + _bindZoomEvent(child, parent.onZoomStart!); + } + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + cumulative = max( + max(1 / _minMax(child.controller.zoomFactor, 0, 1), 1) + + (0.25 * direction), + 1); + if (cumulative >= 1) { + origin = child.isVertical + ? 1 - (mouseY / plotAreaBounds.height) + : mouseX / plotAreaBounds.width; + origin = origin > 1 + ? 1 + : origin < 0 + ? 0 + : origin; + zoomFactor = ((cumulative == 1) ? 1 : _minMax(1 / cumulative, 0, 1)) + .toDouble(); + zoomPosition = (cumulative == 1) + ? 0 + : child.controller.zoomPosition + + ((child.controller.zoomFactor - zoomFactor) * origin); + if (child.controller.zoomPosition != zoomPosition || + child.controller.zoomFactor != zoomFactor) { + zoomFactor = (zoomPosition + zoomFactor) > 1 + ? (1 - zoomPosition) + : zoomFactor; + } + child.controller.zoomPosition = zoomPosition < 0 + ? 0 + : zoomPosition > 1 + ? 1 + : zoomPosition; + child.controller.zoomFactor = zoomFactor < 0 + ? 0 + : zoomFactor > 1 + ? 1 + : zoomFactor; + maxZoomFactor = maximumZoomLevel; + if (zoomFactor < maxZoomFactor) { + child.controller.zoomFactor = maxZoomFactor; + zoomFactor = maxZoomFactor; + } + parent.hideInteractiveTooltip(); + if (parent.onZoomEnd != null) { + _bindZoomEvent(child, parent.onZoomEnd!); + } + if (child.controller.zoomFactor.toInt() == 1 && + child.controller.zoomPosition.toInt() == 0 && + parent.onZoomReset != null) { + _bindZoomEvent(child, parent.onZoomReset!); + } + } + } + } + }); + } + + /// Below method for drawing selection rectangle. + void _doSelectionZooming(double currentX, double currentY) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + if (_isPinching != true && _zoomStartPosition != null) { + final Offset start = _zoomStartPosition!; + final Rect clipRect = parent.paintBounds; + final Offset startPosition = Offset( + (start.dx < clipRect.left) ? clipRect.left : start.dx, + (start.dy < clipRect.top) ? clipRect.top : start.dy); + final Offset currentMousePosition = Offset( + (currentX > clipRect.right) + ? clipRect.right + : ((currentX < clipRect.left) ? clipRect.left : currentX), + (currentY > clipRect.bottom) + ? clipRect.bottom + : ((currentY < clipRect.top) ? clipRect.top : currentY)); + _rectPath = Path(); + if (zoomMode == ZoomMode.x) { + _rectPath!.moveTo(startPosition.dx, clipRect.top); + _rectPath!.lineTo(startPosition.dx, clipRect.bottom); + _rectPath!.lineTo(currentMousePosition.dx, clipRect.bottom); + _rectPath!.lineTo(currentMousePosition.dx, clipRect.top); + _rectPath!.close(); + } else if (zoomMode == ZoomMode.y) { + _rectPath!.moveTo(clipRect.left, startPosition.dy); + _rectPath!.lineTo(clipRect.left, currentMousePosition.dy); + _rectPath!.lineTo(clipRect.right, currentMousePosition.dy); + _rectPath!.lineTo(clipRect.right, startPosition.dy); + _rectPath!.close(); + } else { + _rectPath!.moveTo(startPosition.dx, startPosition.dy); + _rectPath!.lineTo(startPosition.dx, currentMousePosition.dy); + _rectPath!.lineTo(currentMousePosition.dx, currentMousePosition.dy); + _rectPath!.lineTo(currentMousePosition.dx, startPosition.dy); + _rectPath!.close(); + } + _zoomingRect = _rectPath!.getBounds(); + } + } + + /// Increases the magnification of the plot area. + void zoomIn() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + _isZoomIn = true; + _isZoomOut = false; + // TODO(YuvarajG): Need to have variable to notify zooming inprogress + // _stateProperties.zoomProgress = true; + bool? needZoom; + RenderChartAxis? child = cartesianAxes.firstChild; + while (child != null) { + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + if (child.controller.zoomFactor <= 1.0 && + child.controller.zoomFactor > 0.0) { + if (child.controller.zoomFactor - 0.1 < 0) { + needZoom = false; + break; + } else { + _updateZoomFactorAndZoomPosition(child); + needZoom = true; + } + } + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + } + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + if (needZoom ?? false) { + (parentBox as RenderBehaviorArea?)?.invalidate(); + } + } + + /// Decreases the magnification of the plot area. + void zoomOut() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + _isZoomIn = false; + _isZoomOut = true; + // TODO(YuvarajG): Need to have variable to notify zooming inprogress + // _stateProperties.zoomProgress = true; + RenderChartAxis? child = cartesianAxes.firstChild; + while (child != null) { + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + if (child.controller.zoomFactor < 1.0 && + child.controller.zoomFactor > 0.0) { + _updateZoomFactorAndZoomPosition(child); + child.controller.zoomFactor = child.controller.zoomFactor > 1.0 + ? 1.0 + : (child.controller.zoomFactor < 0.0 + ? 0.0 + : child.controller.zoomFactor); + } + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + } + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + (parentBox as RenderBehaviorArea?)?.invalidate(); + } + + /// Changes the zoom level using zoom factor. + /// + /// Here, you can pass the zoom factor of an axis to magnify the plot + /// area. The value ranges from 0 to 1. + void zoomByFactor(double zoomFactor) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + _isZoomIn = false; + _isZoomOut = true; + // TODO(YuvarajG): Need to have variable to notify zooming inprogress + // _stateProperties.zoomProgress = true; + RenderChartAxis? child = cartesianAxes.firstChild; + if (zoomFactor.clamp(0.0, 1.0) == zoomFactor) { + while (child != null) { + if ((child.isVertical && zoomMode != ZoomMode.x) || + (!child.isVertical && zoomMode != ZoomMode.y)) { + child.controller.zoomFactor = zoomFactor; + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + } + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + (parentBox as RenderBehaviorArea?)?.invalidate(); + } + } + + /// Zooms the chart for a given rectangle value. + /// + /// Here, you can pass the rectangle with the left, right, top, and bottom + /// values, using which the selection zooming will be performed. + void zoomByRect(Rect rect) { + _drawSelectionZoomRect(rect); + } + + /// Change the zoom level of an appropriate axis. + /// + /// Here, you need to pass axis, zoom factor, zoom position of the zoom level + /// that needs to be modified. + void zoomToSingleAxis( + ChartAxis axis, double zoomPosition, double zoomFactor) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderChartAxis? axisDetails = axis.name != null + ? parent.axisFromName(axis.name) + : parent.axisFromObject(axis); + + if (axisDetails != null) { + axisDetails.controller.zoomFactor = zoomFactor; + axisDetails.controller.zoomPosition = zoomPosition; + } + parent.invalidate(); + } + + /// Pans the plot area for given left, right, top, and bottom directions. + /// + /// To perform this action, the plot area needs to be in zoomed state. + void panToDirection(String direction) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + direction = direction.toLowerCase(); + RenderChartAxis? child = cartesianAxes.firstChild; + while (child != null) { + if (child.isVertical) { + if (direction == 'bottom') { + child.controller.zoomPosition = (child.controller.zoomPosition > 0 && + child.controller.zoomPosition <= 1.0) + ? child.controller.zoomPosition - 0.1 + : child.controller.zoomPosition; + child.controller.zoomPosition = child.controller.zoomPosition < 0.0 + ? 0.0 + : child.controller.zoomPosition; + } + if (direction == 'top') { + child.controller.zoomPosition = (child.controller.zoomPosition >= 0 && + child.controller.zoomPosition < 1) + ? child.controller.zoomPosition + 0.1 + : child.controller.zoomPosition; + child.controller.zoomPosition = child.controller.zoomPosition > 1.0 + ? 1.0 + : child.controller.zoomPosition; + } + } else { + if (direction == 'left') { + child.controller.zoomPosition = (child.controller.zoomPosition > 0 && + child.controller.zoomPosition <= 1.0) + ? child.controller.zoomPosition - 0.1 + : child.controller.zoomPosition; + child.controller.zoomPosition = child.controller.zoomPosition < 0.0 + ? 0.0 + : child.controller.zoomPosition; + } + if (direction == 'right') { + child.controller.zoomPosition = (child.controller.zoomPosition >= 0 && + child.controller.zoomPosition < 1) + ? child.controller.zoomPosition + 0.1 + : child.controller.zoomPosition; + child.controller.zoomPosition = child.controller.zoomPosition > 1.0 + ? 1.0 + : child.controller.zoomPosition; + } + } + if (parent.onZooming != null) { + _bindZoomEvent(child, parent.onZooming!); + } + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + parent.invalidate(); + } + + /// Returns the plot area back to its original position after zooming. + void reset() { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + RenderChartAxis? child = cartesianAxes.firstChild; + while (child != null) { + child.controller.zoomFactor = 1.0; + child.controller.zoomPosition = 0.0; + if (parent.onZoomReset != null) { + _bindZoomEvent(child, parent.onZoomReset!); + } + final CartesianAxesParentData childParentData = + child.parentData! as CartesianAxesParentData; + child = childParentData.nextSibling; + } + parent.invalidate(); + } + + ZoomPanArgs _bindZoomEvent( + RenderChartAxis axis, ChartZoomingCallback zoomEventType) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + final ZoomPanArgs zoomPanArgs = ZoomPanArgs( + axis, + axis.controller.previousZoomPosition, + axis.controller.previousZoomFactor); + zoomPanArgs.currentZoomFactor = axis.controller.zoomFactor; + zoomPanArgs.currentZoomPosition = axis.controller.zoomPosition; + if (parent == null) { + return zoomPanArgs; + } + zoomEventType == parent.onZoomStart + ? parent.onZoomStart!(zoomPanArgs) + : zoomEventType == parent.onZoomEnd + ? parent.onZoomEnd!(zoomPanArgs) + : zoomEventType == parent.onZooming + ? parent.onZooming!(zoomPanArgs) + : parent.onZoomReset!(zoomPanArgs); + return zoomPanArgs; + } + + /// Below method for zooming selected portion. + void _drawSelectionZoomRect(Rect zoomRect) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + + parent.hideInteractiveTooltip(); + final RenderCartesianAxes? axes = parent.cartesianAxes; + if (axes == null) { + return; + } + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + child.zoomingInProgress = true; + if (parent.onZoomStart != null) { + _bindZoomEvent(child, parent.onZoomStart!); + } + if (child.isVertical) { + if (zoomMode != ZoomMode.x) { + child.controller.zoomPosition += (1 - + ((zoomRect.height + + (zoomRect.top - child.paintBounds.top)) / + (child.paintBounds.height)) + .abs()) * + child.controller.zoomFactor; + child.controller.zoomFactor *= + zoomRect.height / child.paintBounds.height; + + child.controller.zoomFactor = + child.controller.zoomFactor >= maximumZoomLevel + ? child.controller.zoomFactor + : maximumZoomLevel; + } + } else { + if (zoomMode != ZoomMode.y) { + child.controller.zoomPosition += + ((zoomRect.left - child.paintBounds.left) / + (child.paintBounds.width)) + .abs() * + child.controller.zoomFactor; + child.controller.zoomFactor *= + zoomRect.width / child.paintBounds.width; + child.controller.zoomFactor = + child.controller.zoomFactor >= maximumZoomLevel + ? child.controller.zoomFactor + : maximumZoomLevel; + } + } + if (parent.onZoomEnd != null) { + _bindZoomEvent(child, parent.onZoomEnd!); + } + } + }); + zoomRect = Rect.zero; + _rectPath = Path(); + } + + double _minMax(double value, double min, double max) { + return value > max ? max : (value < min ? min : value); + } + + @override + void onPaint(PaintingContext context, Offset offset, + SfChartThemeData chartThemeData, ThemeData themeData) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent == null) { + return; + } + final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes; + if (cartesianAxes == null) { + return; + } + if (_zoomingRect != Rect.zero && _rectPath != null) { + Color? fillColor = selectionRectColor; + if (fillColor != null && + fillColor != Colors.transparent && + fillColor.opacity == 1) { + fillColor = fillColor.withOpacity(0.3); + } + final Paint fillPaint = Paint() + ..color = + (fillColor ?? cartesianAxes.chartThemeData.selectionRectColor)! + ..style = PaintingStyle.fill; + context.canvas.drawRect(_zoomingRect, fillPaint); + final Paint strokePaint = Paint() + ..isAntiAlias = true + ..color = (selectionRectBorderColor ?? + cartesianAxes.chartThemeData.selectionRectBorderColor)! + ..strokeWidth = selectionRectBorderWidth + ..style = PaintingStyle.stroke; + + if (strokePaint.color != Colors.transparent && + strokePaint.strokeWidth > 0) { + final List dashArray = [5, 5]; + drawDashes(context.canvas, dashArray, strokePaint, path: _rectPath); + } + + final Offset plotAreaOffset = + (parent.parentData! as BoxParentData).offset; + //Selection zooming tooltip rendering + _drawTooltipConnector( + cartesianAxes, + _zoomingRect.topLeft, + _zoomingRect.bottomRight, + context.canvas, + parent.paintBounds, + plotAreaOffset); + } + } + + void _calculateZoomAxesRange(RenderCartesianAxes axes) { + _ZoomAxisRange range; + axes.visitChildren((RenderObject child) { + range = _ZoomAxisRange(); + if (child is RenderChartAxis) { + if (child.actualRange != null) { + range.actualMin = child.actualRange!.minimum.toDouble(); + range.actualDelta = child.actualRange!.delta.toDouble(); + } + range.min = child.visibleRange!.minimum.toDouble(); + range.delta = child.visibleRange!.delta.toDouble(); + _zoomAxes.add(range); + } + }); + } + + /// Returns the tooltip label on zooming. + String _tooltipValue( + Offset position, RenderChartAxis axis, Rect plotAreaBounds) { + final num value = axis.isVertical + ? axis.pixelToPoint(axis.paintBounds, position.dx, position.dy) + : axis.pixelToPoint(axis.paintBounds, position.dx - plotAreaBounds.left, + position.dy - plotAreaBounds.top); + + dynamic result = _interactiveTooltipLabel(value, axis); + if (axis.interactiveTooltip.format != null) { + final String stringValue = + axis.interactiveTooltip.format!.replaceAll('{value}', result); + result = stringValue; + } + return result.toString(); + } + + /// Validate the rect by comparing small and large rect. + Rect _validateRect(Rect largeRect, Rect smallRect, String axisPosition) => + Rect.fromLTRB( + axisPosition == 'left' + ? (smallRect.left - (largeRect.width - smallRect.width)) + : smallRect.left, + smallRect.top, + axisPosition == 'right' + ? (smallRect.right + (largeRect.width - smallRect.width)) + : smallRect.right, + smallRect.bottom); + + /// Calculate the interactive tooltip rect, based on the zoomed axis position. + Rect _calculateRect(RenderChartAxis axis, Offset position, Size labelSize) { + const double paddingForRect = 10; + final Rect axisBound = + (axis.parentData! as BoxParentData).offset & axis.size; + final double arrowLength = axis.interactiveTooltip.arrowLength; + double left, top; + final double width = labelSize.width + paddingForRect; + final double height = labelSize.height + paddingForRect; + + if (axis.isVertical) { + top = position.dy - height / 2; + if (axis.opposedPosition) { + left = axisBound.left + arrowLength; + } else { + left = axisBound.left - width - arrowLength; + } + } else { + left = position.dx - width / 2; + if (axis.opposedPosition) { + top = axisBound.top - height - arrowLength; + } else { + top = axisBound.top + arrowLength; + } + } + return Rect.fromLTWH(left, top, width, height); + } + + /// To draw tooltip connector. + void _drawTooltipConnector( + RenderCartesianAxes axes, + Offset startPosition, + Offset endPosition, + Canvas canvas, + Rect plotAreaBounds, + Offset plotAreaOffset) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + RRect? startTooltipRect, endTooltipRect; + String startValue, endValue; + Size startLabelSize, endLabelSize; + Rect startLabelRect, endLabelRect; + TextStyle textStyle = + parent!.chartThemeData!.selectionZoomingTooltipTextStyle!; + final Paint labelFillPaint = Paint() + ..color = axes.chartThemeData.crosshairBackgroundColor! + ..isAntiAlias = true; + + final Paint labelStrokePaint = Paint() + ..color = axes.chartThemeData.crosshairBackgroundColor! + ..isAntiAlias = true + ..style = PaintingStyle.stroke; + + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + if (child.interactiveTooltip.enable) { + textStyle = textStyle.merge(child.interactiveTooltip.textStyle); + labelFillPaint.color = (child.interactiveTooltip.color ?? + axes.chartThemeData.crosshairBackgroundColor)!; + labelStrokePaint.color = (child.interactiveTooltip.borderColor ?? + axes.chartThemeData.crosshairBackgroundColor)!; + labelStrokePaint.strokeWidth = child.interactiveTooltip.borderWidth; + final Paint connectorLinePaint = Paint() + ..color = (child.interactiveTooltip.connectorLineColor ?? + axes.chartThemeData.selectionTooltipConnectorLineColor)! + ..strokeWidth = child.interactiveTooltip.connectorLineWidth + ..style = PaintingStyle.stroke; + + final Path startLabelPath = Path(); + final Path endLabelPath = Path(); + startValue = _tooltipValue(startPosition, child, plotAreaBounds); + endValue = _tooltipValue(endPosition, child, plotAreaBounds); + + if (startValue.isNotEmpty && endValue.isNotEmpty) { + startLabelSize = measureText(startValue, textStyle); + endLabelSize = measureText(endValue, textStyle); + startLabelRect = + _calculateRect(child, startPosition, startLabelSize); + endLabelRect = _calculateRect(child, endPosition, endLabelSize); + if (child.isVertical && + startLabelRect.width != endLabelRect.width) { + final String axisPosition = + child.opposedPosition ? 'right' : 'left'; + (startLabelRect.width > endLabelRect.width) + ? endLabelRect = + _validateRect(startLabelRect, endLabelRect, axisPosition) + : startLabelRect = + _validateRect(endLabelRect, startLabelRect, axisPosition); + } + startTooltipRect = _drawTooltip( + canvas, + labelFillPaint, + labelStrokePaint, + startLabelPath, + startPosition, + startLabelRect, + startTooltipRect, + startValue, + startLabelSize, + plotAreaBounds, + textStyle, + child, + plotAreaOffset); + endTooltipRect = _drawTooltip( + canvas, + labelFillPaint, + labelStrokePaint, + endLabelPath, + endPosition, + endLabelRect, + endTooltipRect, + endValue, + endLabelSize, + plotAreaBounds, + textStyle, + child, + plotAreaOffset); + _drawConnector(canvas, connectorLinePaint, startTooltipRect!, + endTooltipRect!, startPosition, endPosition, child); + } + } + } + }); + } + + /// To draw connectors. + void _drawConnector( + Canvas canvas, + Paint connectorLinePaint, + RRect startTooltipRect, + RRect endTooltipRect, + Offset startPosition, + Offset endPosition, + RenderChartAxis axis) { + final InteractiveTooltip tooltip = axis.interactiveTooltip; + if (!axis.isVertical && !axis.opposedPosition) { + startPosition = + Offset(startPosition.dx, startTooltipRect.top - tooltip.arrowLength); + endPosition = + Offset(endPosition.dx, endTooltipRect.top - tooltip.arrowLength); + } else if (!axis.isVertical && axis.opposedPosition) { + startPosition = Offset( + startPosition.dx, startTooltipRect.bottom + tooltip.arrowLength); + endPosition = + Offset(endPosition.dx, endTooltipRect.bottom + tooltip.arrowLength); + } else if (axis.isVertical && !axis.opposedPosition) { + startPosition = Offset( + startTooltipRect.right + tooltip.arrowLength, startPosition.dy); + endPosition = + Offset(endTooltipRect.right + tooltip.arrowLength, endPosition.dy); + } else { + startPosition = + Offset(startTooltipRect.left - tooltip.arrowLength, startPosition.dy); + endPosition = + Offset(endTooltipRect.left - tooltip.arrowLength, endPosition.dy); + } + drawDashedPath(canvas, connectorLinePaint, startPosition, endPosition, + tooltip.connectorLineDashArray); + } + + /// To draw tooltip. + RRect _drawTooltip( + Canvas canvas, + Paint fillPaint, + Paint strokePaint, + Path path, + Offset position, + Rect labelRect, + RRect? rect, + String value, + Size labelSize, + Rect plotAreaBound, + TextStyle textStyle, + RenderChartAxis axis, + Offset plotAreaOffset) { + final Offset parentDataOffset = (axis.parentData! as BoxParentData).offset; + final Offset axisOffset = + parentDataOffset.translate(-plotAreaOffset.dx, -plotAreaOffset.dy); + final Rect axisRect = axisOffset & axis.size; + labelRect = _validateRectBounds(labelRect, axisRect); + labelRect = axis.isVertical + ? _validateRectYPosition(labelRect, plotAreaBound) + : _validateRectXPosition(labelRect, plotAreaBound); + path.reset(); + rect = RRect.fromRectAndRadius( + labelRect, Radius.circular(axis.interactiveTooltip.borderRadius)); + path.addRRect(rect); + _calculateNeckPositions( + canvas, fillPaint, strokePaint, path, position, rect, axis); + drawText( + canvas, + value, + Offset((rect.left + rect.width / 2) - labelSize.width / 2, + (rect.top + rect.height / 2) - labelSize.height / 2), + textStyle, + ); + return rect; + } + + /// To calculate tooltip neck positions. + void _calculateNeckPositions( + Canvas canvas, + Paint fillPaint, + Paint strokePaint, + Path path, + Offset position, + RRect rect, + RenderChartAxis axis) { + final InteractiveTooltip tooltip = axis.interactiveTooltip; + double x1, x2, x3, x4, y1, y2, y3, y4; + if (!axis.isVertical && !axis.opposedPosition) { + x1 = position.dx; + y1 = rect.top - tooltip.arrowLength; + x2 = (rect.right - rect.width / 2) + tooltip.arrowWidth; + y2 = rect.top; + x3 = (rect.left + rect.width / 2) - tooltip.arrowWidth; + y3 = rect.top; + x4 = position.dx; + y4 = rect.top - tooltip.arrowLength; + } else if (!axis.isVertical && axis.opposedPosition) { + x1 = position.dx; + y1 = rect.bottom + tooltip.arrowLength; + x2 = (rect.right - rect.width / 2) + tooltip.arrowWidth; + y2 = rect.bottom; + x3 = (rect.left + rect.width / 2) - tooltip.arrowWidth; + y3 = rect.bottom; + x4 = position.dx; + y4 = rect.bottom + tooltip.arrowLength; + } else if (axis.isVertical && !axis.opposedPosition) { + x1 = rect.right; + y1 = rect.top + rect.height / 2 - tooltip.arrowWidth; + x2 = rect.right; + y2 = rect.bottom - rect.height / 2 + tooltip.arrowWidth; + x3 = rect.right + tooltip.arrowLength; + y3 = position.dy; + x4 = rect.right + tooltip.arrowLength; + y4 = position.dy; + } else { + x1 = rect.left; + y1 = rect.top + rect.height / 2 - tooltip.arrowWidth; + x2 = rect.left; + y2 = rect.bottom - rect.height / 2 + tooltip.arrowWidth; + x3 = rect.left - tooltip.arrowLength; + y3 = position.dy; + x4 = rect.left - tooltip.arrowLength; + y4 = position.dy; + } + _drawTooltipArrowhead( + canvas, path, fillPaint, strokePaint, x1, y1, x2, y2, x3, y3, x4, y4); + } + + /// Below method is for zoomIn and zoomOut public methods. + void _updateZoomFactorAndZoomPosition(RenderChartAxis axis) { + final Rect axisClipRect = axis.paintBounds; + double? zoomFactor, zoomPosition; + final num direction = _isZoomIn + ? 1 + : _isZoomOut + ? -1 + : 1; + final num cumulative = max( + max(1 / _minMax(axis.controller.zoomFactor, 0, 1), 1) + + (0.1 * direction), + 1); + if (cumulative >= 1) { + num origin = axis.isVertical + ? 1 - + ((axisClipRect.top + axisClipRect.height / 2) / + axisClipRect.height) + : (axisClipRect.left + axisClipRect.width / 2) / axisClipRect.width; + origin = origin > 1 + ? 1 + : origin < 0 + ? 0 + : origin; + zoomFactor = + ((cumulative == 1) ? 1 : _minMax(1 / cumulative, 0, 1)).toDouble(); + zoomPosition = (cumulative == 1) + ? 0 + : axis.controller.zoomPosition + + ((axis.controller.zoomFactor - zoomFactor) * origin); + if (axis.controller.zoomPosition != zoomPosition || + axis.controller.zoomFactor != zoomFactor) { + zoomFactor = + (zoomPosition + zoomFactor) > 1 ? (1 - zoomPosition) : zoomFactor; + } + + axis.controller.zoomPosition = zoomPosition; + axis.controller.zoomFactor = zoomFactor; + } + } + + void _startPinchZooming(PointerEvent event) { + if (_touchStartPositions.length < 2) { + _touchStartPositions.add(event); + } + + if (_touchStartPositions.length == 2) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && + parent.onZoomStart != null && + parent.cartesianAxes != null) { + parent.hideInteractiveTooltip(); + final RenderCartesianAxes axes = parent.cartesianAxes!; + + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + _bindZoomEvent(child, parent.onZoomStart!); + } + }); + } + } + } + + // ignore: unused_element + void _endPinchZooming(PointerUpEvent event) { + if (_touchStartPositions.length == 2 && _touchMovePositions.length == 2) { + final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?; + if (parent != null && parent.cartesianAxes != null) { + final RenderCartesianAxes axes = parent.cartesianAxes!; + + axes.visitChildren((RenderObject child) { + if (child is RenderChartAxis) { + if (parent.onZoomEnd != null) { + _bindZoomEvent(child, parent.onZoomEnd!); + } + } + }); + } + } + + _zoomAxes = <_ZoomAxisRange>[]; + _touchMovePositions = []; + _touchStartPositions = []; + _isPinching = false; + } + + void _startPanning() { + _previousMovedPosition = null; + } + + void _endPanning() { + _previousMovedPosition = null; + } + + void _longPressStart(Offset position) { + if (_zoomStartPosition != position) { + _zoomStartPosition = position; + } + } + + void _longPressEnd() { + if (_zoomStartPosition != null && _zoomingRect.width != 0) { + _drawSelectionZoomRect(_zoomingRect); + } + _zoomStartPosition = null; + _zoomingRect = Rect.zero; + } +} + +/// This method will validate whether the tooltip exceeds the screen or not. +Rect _validateRectBounds(Rect tooltipRect, Rect boundary) { + Rect validatedRect = tooltipRect; + double difference = 0; + + /// Padding between the corners. + const double padding = 0.5; + + // Move the tooltip if it's outside of the boundary. + if (tooltipRect.left < boundary.left) { + difference = (boundary.left - tooltipRect.left) + padding; + validatedRect = validatedRect.translate(difference, 0); + } + if (tooltipRect.right > boundary.right) { + difference = (tooltipRect.right - boundary.right) + padding; + validatedRect = validatedRect.translate(-difference, 0); + } + if (tooltipRect.top < boundary.top) { + difference = (boundary.top - tooltipRect.top) + padding; + validatedRect = validatedRect.translate(0, difference); + } + + if (tooltipRect.bottom > boundary.bottom) { + difference = (tooltipRect.bottom - boundary.bottom) + padding; + validatedRect = validatedRect.translate(0, -difference); + } + return validatedRect; +} + +/// Gets the x position of validated rect. +Rect _validateRectYPosition(Rect labelRect, Rect axisClipRect) { + Rect validatedRect = labelRect; + if (labelRect.bottom >= axisClipRect.bottom) { + validatedRect = Rect.fromLTRB( + labelRect.left, + labelRect.top - (labelRect.bottom - axisClipRect.bottom), + labelRect.right, + axisClipRect.bottom); + } else if (labelRect.top <= axisClipRect.top) { + validatedRect = Rect.fromLTRB(labelRect.left, axisClipRect.top, + labelRect.right, labelRect.bottom + (axisClipRect.top - labelRect.top)); + } + return validatedRect; +} + +/// Gets the x position of validated rect. +Rect _validateRectXPosition(Rect labelRect, Rect axisClipRect) { + Rect validatedRect = labelRect; + if (labelRect.right >= axisClipRect.right) { + validatedRect = Rect.fromLTRB( + labelRect.left - (labelRect.right - axisClipRect.right), + labelRect.top, + axisClipRect.right, + labelRect.bottom); + } else if (labelRect.left <= axisClipRect.left) { + validatedRect = Rect.fromLTRB( + axisClipRect.left, + labelRect.top, + labelRect.right + (axisClipRect.left - labelRect.left), + labelRect.bottom); + } + return validatedRect; +} + +/// Draw tooltip arrow head. +void _drawTooltipArrowhead( + Canvas canvas, + Path backgroundPath, + Paint fillPaint, + Paint strokePaint, + double x1, + double y1, + double x2, + double y2, + double x3, + double y3, + double x4, + double y4) { + backgroundPath.moveTo(x1, y1); + backgroundPath.lineTo(x2, y2); + backgroundPath.lineTo(x3, y3); + backgroundPath.lineTo(x4, y4); + backgroundPath.lineTo(x1, y1); + fillPaint.isAntiAlias = true; + canvas.drawPath(backgroundPath, strokePaint); + canvas.drawPath(backgroundPath, fillPaint); +} + +/// To get interactive tooltip label. +dynamic _interactiveTooltipLabel(dynamic value, RenderChartAxis axis) { + if (axis.visibleLabels.isEmpty) { + return ''; + } + + final int labelsLength = axis.visibleLabels.length; + if (axis is RenderCategoryAxis) { + value = value < 0 ? 0 : value; + value = axis.labels[(value.round() >= axis.labels.length + ? (value.round() > axis.labels.length + ? axis.labels.length - 1 + : value - 1) + : value.round()) + .round()]; + } else if (axis is RenderDateTimeCategoryAxis) { + value = value < 0 ? 0 : value; + value = axis.labels[(value.round() >= axis.labels.length + ? (value.round() > axis.labels.length + ? axis.labels.length - 1 + : value - 1) + : value.round()) + .round()]; + } else if (axis is RenderDateTimeAxis) { + final num interval = axis.visibleRange!.minimum.ceil(); + final num previousInterval = (axis.visibleLabels.isNotEmpty) + ? axis.visibleLabels[labelsLength - 1].value + : interval; + final DateFormat dateFormat = axis.dateFormat ?? + _dateTimeLabelFormat(axis, interval.toInt(), previousInterval.toInt()); + value = + dateFormat.format(DateTime.fromMillisecondsSinceEpoch(value.toInt())); + } else { + value = axis is RenderLogarithmicAxis ? pow(10, value) : value; + value = _labelValue(value, axis, axis.interactiveTooltip.decimalPlaces); + } + return value; +} + +/// To get the label format of the date-time axis. +DateFormat _dateTimeLabelFormat(RenderChartAxis axis, + [int? interval, int? prevInterval]) { + DateFormat? format; + final bool notDoubleInterval = + (axis.interval != null && axis.interval! % 1 == 0) || + axis.interval == null; + DateTimeIntervalType? actualIntervalType; + num? minimum; + if (axis is RenderDateTimeAxis) { + actualIntervalType = axis.visibleIntervalType; + minimum = axis.visibleRange!.minimum; + } else if (axis is RenderDateTimeCategoryAxis) { + minimum = axis.visibleRange!.minimum; + actualIntervalType = axis.visibleIntervalType; + } + switch (actualIntervalType) { + case DateTimeIntervalType.years: + format = notDoubleInterval ? DateFormat.y() : DateFormat.MMMd(); + break; + case DateTimeIntervalType.months: + format = (minimum == interval || interval == prevInterval) + ? _firstLabelFormat(actualIntervalType) + : _dateTimeFormat(actualIntervalType, interval, prevInterval); + + break; + case DateTimeIntervalType.days: + format = (minimum == interval || interval == prevInterval) + ? _firstLabelFormat(actualIntervalType) + : _dateTimeFormat(actualIntervalType, interval, prevInterval); + break; + case DateTimeIntervalType.hours: + format = DateFormat.j(); + break; + case DateTimeIntervalType.minutes: + format = DateFormat.Hm(); + break; + case DateTimeIntervalType.seconds: + format = DateFormat.ms(); + break; + case DateTimeIntervalType.milliseconds: + final DateFormat dateFormat = DateFormat('ss.SSS'); + format = dateFormat; + break; + case DateTimeIntervalType.auto: + break; + // ignore: no_default_cases + default: + break; + } + return format!; +} + +/// Gets the the actual label value for tooltip and data label etc. +String _labelValue(dynamic value, dynamic axis, [int? showDigits]) { + if (value.toString().split('.').length > 1) { + final String str = value.toString(); + final List list = str.split('.'); + value = double.parse(value.toStringAsFixed(showDigits ?? 3)); + value = (list[1] == '0' || + list[1] == '00' || + list[1] == '000' || + list[1] == '0000' || + list[1] == '00000' || + list[1] == '000000' || + list[1] == '0000000') + ? value.round() + : value; + } + final dynamic text = axis is NumericAxis && axis.numberFormat != null + ? axis.numberFormat!.format(value) + : value; + return ((axis.labelFormat != null && axis.labelFormat != '') + ? axis.labelFormat.replaceAll(RegExp('{value}'), text.toString()) + : text.toString()) as String; +} + +/// Calculate the dateTime format. +DateFormat? _dateTimeFormat(DateTimeIntervalType? actualIntervalType, + int? interval, int? prevInterval) { + final DateTime minimum = DateTime.fromMillisecondsSinceEpoch(interval!); + final DateTime maximum = DateTime.fromMillisecondsSinceEpoch(prevInterval!); + DateFormat? format; + final bool isIntervalDecimal = interval % 1 == 0; + if (actualIntervalType == DateTimeIntervalType.months) { + format = minimum.year == maximum.year + ? (isIntervalDecimal ? DateFormat.MMM() : DateFormat.MMMd()) + : DateFormat('yyy MMM'); + } else if (actualIntervalType == DateTimeIntervalType.days) { + format = minimum.month != maximum.month + ? (isIntervalDecimal ? DateFormat.MMMd() : DateFormat.MEd()) + : DateFormat.d(); + } + + return format; +} + +/// Returns the first label format for date time values. +DateFormat? _firstLabelFormat(DateTimeIntervalType? actualIntervalType) { + DateFormat? format; + + if (actualIntervalType == DateTimeIntervalType.months) { + format = DateFormat('yyy MMM'); + } else if (actualIntervalType == DateTimeIntervalType.days) { + format = DateFormat.MMMd(); + } else if (actualIntervalType == DateTimeIntervalType.minutes) { + format = DateFormat.Hm(); + } + + return format; +} + +/// Represents the zoom axis range class. +class _ZoomAxisRange { + /// Holds the value of actual minimum, actual delta, minimum and delta value. + double? actualMin, actualDelta, min, delta; +} diff --git a/packages/syncfusion_flutter_charts/lib/src/sparkline/theme.dart b/packages/syncfusion_flutter_charts/lib/src/sparkline/theme.dart new file mode 100644 index 000000000..075144e58 --- /dev/null +++ b/packages/syncfusion_flutter_charts/lib/src/sparkline/theme.dart @@ -0,0 +1,82 @@ +import 'package:flutter/material.dart'; +import 'package:syncfusion_flutter_core/theme.dart'; + +/// Holds the value of [SfSparkChartThemeData] color properties for +/// material 2 theme based on the brightness. +class SfSparkChartThemeDataM2 extends SfSparkChartThemeData { + /// Creating an argument constructor of SfChartThemeDataM2 class. + SfSparkChartThemeDataM2(this.context); + + /// Specifies the build context of the chart widgets. + final BuildContext context; + + /// Specifies the material app color scheme based on the brightness. + late final ColorScheme colorScheme = Theme.of(context).colorScheme; + + @override + Color? get color => Colors.blue; + + @override + Color? get axisLineColor => Colors.black; + + @override + Color? get markerFillColor => colorScheme.surface; + + @override + Color? get dataLabelBackgroundColor => colorScheme.surface; + + @override + Color? get tooltipColor => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(79, 79, 79, 1) + : const Color.fromRGBO(255, 255, 255, 1); + + @override + Color? get trackballLineColor => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(79, 79, 79, 1) + : const Color.fromRGBO(255, 255, 255, 1); + + @override + Color? get tooltipLabelColor => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(229, 229, 229, 1) + : const Color.fromRGBO(0, 0, 0, 1); +} + +/// Holds the value of [SfSparkChartThemeData] color properties for +/// material 3 theme based on the brightness. +class SfSparkChartThemeDataM3 extends SfSparkChartThemeData { + /// Creating an argument constructor of SfChartThemeDataM3 class. + SfSparkChartThemeDataM3(this.context); + + /// Specifies the build context of the chart widgets. + final BuildContext context; + + /// Specifies the material app color scheme based on the brightness. + late final ColorScheme colorScheme = Theme.of(context).colorScheme; + + @override + Color? get color => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(150, 60, 112, 1) + : const Color.fromRGBO(77, 170, 255, 1); + + @override + Color? get axisLineColor => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(73, 69, 79, 1) + : const Color.fromRGBO(202, 196, 208, 1); + + @override + Color? get markerFillColor => colorScheme.surface; + + @override + Color? get dataLabelBackgroundColor => colorScheme.surface; + + @override + Color? get tooltipColor => colorScheme.inverseSurface; + + @override + Color? get trackballLineColor => colorScheme.brightness == Brightness.light + ? const Color.fromRGBO(73, 69, 79, 1) + : const Color.fromRGBO(202, 196, 208, 1); + + @override + Color? get tooltipLabelColor => colorScheme.onInverseSurface; +} diff --git a/packages/syncfusion_pdfviewer_platform_interface/CHANGELOG.md b/packages/syncfusion_flutter_pdfviewer_platform_interface/CHANGELOG.md similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/CHANGELOG.md rename to packages/syncfusion_flutter_pdfviewer_platform_interface/CHANGELOG.md diff --git a/packages/syncfusion_pdfviewer_platform_interface/LICENSE b/packages/syncfusion_flutter_pdfviewer_platform_interface/LICENSE similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/LICENSE rename to packages/syncfusion_flutter_pdfviewer_platform_interface/LICENSE diff --git a/packages/syncfusion_pdfviewer_platform_interface/README.md b/packages/syncfusion_flutter_pdfviewer_platform_interface/README.md similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/README.md rename to packages/syncfusion_flutter_pdfviewer_platform_interface/README.md diff --git a/packages/syncfusion_pdfviewer_platform_interface/analysis_options.yaml b/packages/syncfusion_flutter_pdfviewer_platform_interface/analysis_options.yaml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/analysis_options.yaml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/analysis_options.yaml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/README.md b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/README.md similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/README.md rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/README.md diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/analysis_options.yaml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/analysis_options.yaml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/analysis_options.yaml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/analysis_options.yaml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/build.gradle b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/build.gradle similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/build.gradle rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/build.gradle diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/debug/AndroidManifest.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/debug/AndroidManifest.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/debug/AndroidManifest.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/AndroidManifest.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/AndroidManifest.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/AndroidManifest.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/AndroidManifest.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/drawable-v21/launch_background.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/drawable/launch_background.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/drawable/launch_background.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/drawable/launch_background.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/values-night/styles.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/values-night/styles.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/values-night/styles.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/values/styles.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/values/styles.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/main/res/values/styles.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/main/res/values/styles.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/profile/AndroidManifest.xml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/app/src/profile/AndroidManifest.xml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/app/src/profile/AndroidManifest.xml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/build.gradle b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/build.gradle similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/build.gradle rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/build.gradle diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/gradle.properties b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/gradle.properties similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/gradle.properties rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/gradle.properties diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/gradle/wrapper/gradle-wrapper.properties rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/gradle/wrapper/gradle-wrapper.properties diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/android/settings.gradle b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/settings.gradle similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/android/settings.gradle rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/android/settings.gradle diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/.gitignore b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/.gitignore similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/.gitignore rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/.gitignore diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/AppFrameworkInfo.plist b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/AppFrameworkInfo.plist rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/AppFrameworkInfo.plist diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/Debug.xcconfig b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/Debug.xcconfig similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/Debug.xcconfig rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/Debug.xcconfig diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/Release.xcconfig b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/Release.xcconfig similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Flutter/Release.xcconfig rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Flutter/Release.xcconfig diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.pbxproj b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.pbxproj similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.pbxproj rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.pbxproj diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/AppDelegate.swift b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/AppDelegate.swift similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/AppDelegate.swift rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/AppDelegate.swift diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/Main.storyboard b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/Main.storyboard rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Base.lproj/Main.storyboard diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Info.plist b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Info.plist similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Info.plist rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Info.plist diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Runner-Bridging-Header.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/ios/Runner/Runner-Bridging-Header.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/ios/Runner/Runner-Bridging-Header.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/pubspec.yaml b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/pubspec.yaml similarity index 91% rename from packages/syncfusion_pdfviewer_platform_interface/example/pubspec.yaml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/pubspec.yaml index 7e9260272..267f4b839 100644 --- a/packages/syncfusion_pdfviewer_platform_interface/example/pubspec.yaml +++ b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/pubspec.yaml @@ -18,12 +18,8 @@ dependencies: flutter: sdk: flutter - syncfusion_flutter_pdfviewer: - git: - url: https://SyncfusionBuild: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@github.com/essential-studio/flutter-pdfviewer - path: flutter_pdfviewer/syncfusion_flutter_pdfviewer - branch: release/25.1.1 - ref: release/25.1.1 + syncfusion_flutter_pdfviewer: ^25.1.35 + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/web/favicon.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/favicon.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/web/favicon.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/favicon.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/web/icons/Icon-192.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/icons/Icon-192.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/web/icons/Icon-192.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/icons/Icon-192.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/web/icons/Icon-512.png b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/icons/Icon-512.png similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/web/icons/Icon-512.png rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/icons/Icon-512.png diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/web/index.html b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/index.html similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/web/index.html rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/index.html diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/web/manifest.json b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/manifest.json similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/web/manifest.json rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/web/manifest.json diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/.gitignore b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/.gitignore similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/.gitignore rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/.gitignore diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/CMakeLists.txt b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/CMakeLists.txt similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/CMakeLists.txt rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/CMakeLists.txt diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/CMakeLists.txt b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/CMakeLists.txt similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/CMakeLists.txt rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/CMakeLists.txt diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.cc b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.cc similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.cc rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.cc diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugin_registrant.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugins.cmake b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugins.cmake similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/generated_plugins.cmake rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/flutter/generated_plugins.cmake diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/CMakeLists.txt b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/CMakeLists.txt similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/CMakeLists.txt rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/CMakeLists.txt diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/Runner.rc b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/Runner.rc similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/Runner.rc rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/Runner.rc diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/flutter_window.cpp b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/flutter_window.cpp similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/flutter_window.cpp rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/flutter_window.cpp diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/flutter_window.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/flutter_window.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/flutter_window.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/flutter_window.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/main.cpp b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/main.cpp similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/main.cpp rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/main.cpp diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/resource.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/resource.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/resource.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/resource.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/resources/app_icon.ico b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/resources/app_icon.ico similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/resources/app_icon.ico rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/resources/app_icon.ico diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/runner.exe.manifest b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/runner.exe.manifest similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/runner.exe.manifest rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/runner.exe.manifest diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/utils.cpp b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/utils.cpp similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/utils.cpp rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/utils.cpp diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/utils.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/utils.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/utils.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/utils.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/win32_window.cpp b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/win32_window.cpp similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/win32_window.cpp rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/win32_window.cpp diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/win32_window.h b/packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/win32_window.h similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/example/windows/runner/win32_window.h rename to packages/syncfusion_flutter_pdfviewer_platform_interface/example/windows/runner/win32_window.h diff --git a/packages/syncfusion_pdfviewer_platform_interface/pubspec.yaml b/packages/syncfusion_flutter_pdfviewer_platform_interface/pubspec.yaml similarity index 100% rename from packages/syncfusion_pdfviewer_platform_interface/pubspec.yaml rename to packages/syncfusion_flutter_pdfviewer_platform_interface/pubspec.yaml diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/lib/main.dart b/packages/syncfusion_pdfviewer_platform_interface/example/lib/main.dart deleted file mode 100644 index c476c0306..000000000 --- a/packages/syncfusion_pdfviewer_platform_interface/example/lib/main.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; - -void main() { - runApp(MaterialApp( - title: 'Syncfusion PDF Viewer Demo for Web', - theme: ThemeData( - useMaterial3: false, - ), - home: const HomePage(), - )); -} - -/// Represents Homepage for Navigation -class HomePage extends StatefulWidget { - const HomePage({Key? key}) : super(key: key); - - @override - _HomePage createState() => _HomePage(); -} - -class _HomePage extends State { - final GlobalKey _pdfViewerKey = GlobalKey(); - - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Syncfusion Flutter PDF Viewer'), - actions: [ - IconButton( - icon: const Icon( - Icons.bookmark, - color: Colors.white, - ), - onPressed: () { - _pdfViewerKey.currentState?.openBookmarkView(); - }, - ), - ], - ), - body: SfPdfViewer.network( - 'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf', - key: _pdfViewerKey, - ), - ); - } -} diff --git a/packages/syncfusion_pdfviewer_platform_interface/lib/pdfviewer_platform_interface.dart b/packages/syncfusion_pdfviewer_platform_interface/lib/pdfviewer_platform_interface.dart deleted file mode 100644 index 81a29938d..000000000 --- a/packages/syncfusion_pdfviewer_platform_interface/lib/pdfviewer_platform_interface.dart +++ /dev/null @@ -1 +0,0 @@ -export 'src/pdfviewer_platform_interface.dart'; diff --git a/packages/syncfusion_pdfviewer_platform_interface/lib/src/method_channel_pdfviewer.dart b/packages/syncfusion_pdfviewer_platform_interface/lib/src/method_channel_pdfviewer.dart deleted file mode 100644 index bd71c47ee..000000000 --- a/packages/syncfusion_pdfviewer_platform_interface/lib/src/method_channel_pdfviewer.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'dart:async'; -import 'package:flutter/services.dart'; -import 'package:syncfusion_pdfviewer_platform_interface/pdfviewer_platform_interface.dart'; - -class MethodChannelPdfViewer extends PdfViewerPlatform { - final MethodChannel _channel = MethodChannel('syncfusion_flutter_pdfviewer'); - - /// Initializes the PDF renderer instance in respective platform by loading the PDF from the provided byte information. - /// If success, returns page count else returns error message from respective platform - @override - Future initializePdfRenderer( - Uint8List documentBytes, String documentID) async { - return _channel.invokeMethod('initializePdfRenderer', { - 'documentBytes': documentBytes, - 'documentID': documentID - }); - } - - /// Gets the height of all pages in the document. - @override - Future getPagesHeight(String documentID) async { - return _channel.invokeMethod('getPagesHeight', documentID); - } - - /// Gets the width of all pages in the document. - @override - Future getPagesWidth(String documentID) async { - return _channel.invokeMethod('getPagesWidth', documentID); - } - - /// Gets the image's bytes information of the specified page. - @override - Future getImage( - int pageNumber, double currentScale, String documentID) async { - return _channel.invokeMethod('getImage', { - 'index': pageNumber, - 'scale': currentScale, - 'documentID': documentID - }); - } - - /// Gets the image's bytes information of the specified portion of the page - @override - Future getTileImage(int pageNumber, double currentScale, double x, - double y, double width, double height, String documentID) async { - return _channel.invokeMethod('getTileImage', { - 'pageNumber': pageNumber, - 'scale': currentScale, - 'x': x, - 'y': y, - 'width': width, - 'height': height, - 'documentID': documentID - }); - } - - /// Closes the PDF document. - @override - Future closeDocument(String documentID) async { - return _channel.invokeMethod('closeDocument', documentID); - } -} diff --git a/packages/syncfusion_pdfviewer_platform_interface/lib/src/pdfviewer_platform_interface.dart b/packages/syncfusion_pdfviewer_platform_interface/lib/src/pdfviewer_platform_interface.dart deleted file mode 100644 index 04a285611..000000000 --- a/packages/syncfusion_pdfviewer_platform_interface/lib/src/pdfviewer_platform_interface.dart +++ /dev/null @@ -1,69 +0,0 @@ -library syncfusion_pdfviewer_platform_interface; - -import 'dart:async'; -import 'dart:typed_data'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:syncfusion_pdfviewer_platform_interface/src/method_channel_pdfviewer.dart'; - -/// The interface that implementations of syncfusion_flutter_pdfviewer must implement. -/// -/// Platform implementations should extend this class rather than implement it as `syncfusion_flutter_pdfviewer` -/// does not consider newly added methods to be breaking changes. Extending this class -/// (using `extends`) ensures that the subclass will get the default implementation, while -/// platform implementations that `implements` this interface will be broken by newly added -/// [PdfViewerPlatform] methods -abstract class PdfViewerPlatform extends PlatformInterface { - /// Constructs a PdfViewerPlatform. - PdfViewerPlatform() : super(token: _token); - static PdfViewerPlatform _instance = MethodChannelPdfViewer(); - - static final Object _token = Object(); - - /// The default instance of [PdfViewerPlatform] to use. - /// - /// Defaults to [MethodChannelPdfViewer] - static PdfViewerPlatform get instance => _instance; - - /// Platform-specific plugins should set this with their own platform-specific - /// class that extends [PdfViewerPlatform] when they register themselves. - static set instance(PdfViewerPlatform instance) { - PlatformInterface.verifyToken(instance, _token); - _instance = instance; - } - - /// Initializes the PDF renderer instance in respective platform by loading the PDF from the specified path. - /// - /// If success, returns page count else returns error message from respective platform - Future initializePdfRenderer( - Uint8List documentBytes, String documentID) async { - throw UnimplementedError( - 'initializePdfRenderer() has not been implemented.'); - } - - /// Gets the height of all pages in the document. - Future getPagesHeight(String documentID) async { - throw UnimplementedError('getPagesHeight() has not been implemented.'); - } - - /// Gets the width of all pages in the document. - Future getPagesWidth(String documentID) async { - throw UnimplementedError('getPagesWidth() has not been implemented.'); - } - - /// Gets the image's bytes information of the specified page. - Future getImage( - int pageNumber, double scale, String documentID) async { - throw UnimplementedError('getImage() has not been implemented.'); - } - - /// Gets the image's bytes information of the specified portion of the page. - Future getTileImage(int pageNumber, double scale, double x, - double y, double width, double height, String documentID) async { - throw UnimplementedError('getTileImage() has not been implemented.'); - } - - /// Closes the PDF document. - Future closeDocument(String documentID) async { - throw UnimplementedError('closeDocument() has not been implemented.'); - } -}