Skip to content

Commit

Permalink
Remove CustomPainter and use RenderObjects for our drawing engine in …
Browse files Browse the repository at this point in the history
…line_chart.

Also removed touch_input, we will use Flutter's PointerEvent.
  • Loading branch information
imaNNeo committed Mar 17, 2021
1 parent 1779d70 commit 876093a
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 337 deletions.
5 changes: 3 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample3.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';

class LineChartSample3 extends StatefulWidget {
final weekDays = ['Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
Expand Down Expand Up @@ -97,8 +98,8 @@ class _LineChartSample3State extends State<LineChartSample3> {
}),
touchCallback: (LineTouchResponse lineTouch) {
if (lineTouch.lineBarSpots.length == 1 &&
lineTouch.touchInput is! FlLongPressEnd &&
lineTouch.touchInput is! FlPanEnd) {
lineTouch.touchInput is! PointerExitEvent &&
lineTouch.touchInput is! PointerUpEvent) {
final value = lineTouch.lineBarSpots[0].x;

if (value == 0 || value == 6) {
Expand Down
1 change: 0 additions & 1 deletion lib/fl_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export 'src/chart/bar_chart/bar_chart.dart';
export 'src/chart/bar_chart/bar_chart_data.dart';
export 'src/chart/base/axis_chart/axis_chart_data.dart';
export 'src/chart/base/base_chart/base_chart_data.dart';
export 'src/chart/base/base_chart/touch_input.dart';
export 'src/chart/line_chart/line_chart.dart';
export 'src/chart/line_chart/line_chart_data.dart';
export 'src/chart/pie_chart/pie_chart.dart';
Expand Down
5 changes: 2 additions & 3 deletions lib/src/chart/base/base_chart/base_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:fl_chart/src/utils/utils.dart';
import 'package:flutter/material.dart';

import 'base_chart_painter.dart';
import 'touch_input.dart';

/// This class holds all data needed for [BaseChartPainter].
///
Expand Down Expand Up @@ -150,9 +149,9 @@ TextStyle defaultGetTitleTextStyle(double value) {
///
/// Specific touch details should be hold on the concrete child classes.
class BaseTouchResponse with EquatableMixin {
final FlTouchInput touchInput;
final PointerEvent touchInput;

BaseTouchResponse(FlTouchInput touchInput) : touchInput = touchInput;
BaseTouchResponse(PointerEvent touchInput) : touchInput = touchInput;

/// Used for equality check, see [EquatableMixin].
@override
Expand Down
12 changes: 2 additions & 10 deletions lib/src/chart/base/base_chart/base_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:fl_chart/src/utils/canvas_wrapper.dart';
import 'package:flutter/material.dart';
import 'package:fl_chart/src/extensions/paint_extension.dart';
import 'base_chart_data.dart';
import 'touch_input.dart';
import 'chart_painter.dart';

/// Base class of our painters.
///
/// It is responsible to do basic jobs, like drawing borders of charts.
abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
abstract class BaseChartPainter<D extends BaseChartData> extends ChartPainter {
final D data;
final D targetData;
late Paint _borderPaint;
Expand Down Expand Up @@ -106,11 +106,3 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
/// and the height space we can use to draw chart is[getChartUsableDrawSize.height]
double getTopOffsetDrawSize() => 0;
}

mixin TouchHandler<T extends BaseTouchResponse> {
T handleTouch(
FlTouchInput touchInput,
Size size,
) =>
throw UnsupportedError('not implemented');
}
8 changes: 8 additions & 0 deletions lib/src/chart/base/base_chart/chart_painter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dart:ui';

/// Abstract class for our painters
///
/// This class contains [paint] method, that takes a [canvas], and [size] for drawing the content.
abstract class ChartPainter {
void paint(Canvas canvas, Size size);
}
160 changes: 0 additions & 160 deletions lib/src/chart/base/base_chart/touch_input.dart

This file was deleted.

Loading

0 comments on commit 876093a

Please sign in to comment.