Showing
12 changed files
with
327 additions
and
81 deletions
| @@ -96,11 +96,11 @@ Future<Uint8List> generateReport( | @@ -96,11 +96,11 @@ Future<Uint8List> generateReport( | ||
| 96 | width: 15, | 96 | width: 15, |
| 97 | offset: -10, | 97 | offset: -10, |
| 98 | borderColor: baseColor, | 98 | borderColor: baseColor, |
| 99 | - data: List<pw.LineChartValue>.generate( | 99 | + data: List<pw.PointChartValue>.generate( |
| 100 | dataTable.length, | 100 | dataTable.length, |
| 101 | (i) { | 101 | (i) { |
| 102 | final v = dataTable[i][2] as num; | 102 | final v = dataTable[i][2] as num; |
| 103 | - return pw.LineChartValue(i.toDouble(), v.toDouble()); | 103 | + return pw.PointChartValue(i.toDouble(), v.toDouble()); |
| 104 | }, | 104 | }, |
| 105 | ), | 105 | ), |
| 106 | ), | 106 | ), |
| @@ -110,11 +110,11 @@ Future<Uint8List> generateReport( | @@ -110,11 +110,11 @@ Future<Uint8List> generateReport( | ||
| 110 | width: 15, | 110 | width: 15, |
| 111 | offset: 10, | 111 | offset: 10, |
| 112 | borderColor: PdfColors.amber, | 112 | borderColor: PdfColors.amber, |
| 113 | - data: List<pw.LineChartValue>.generate( | 113 | + data: List<pw.PointChartValue>.generate( |
| 114 | dataTable.length, | 114 | dataTable.length, |
| 115 | (i) { | 115 | (i) { |
| 116 | final v = dataTable[i][1] as num; | 116 | final v = dataTable[i][1] as num; |
| 117 | - return pw.LineChartValue(i.toDouble(), v.toDouble()); | 117 | + return pw.PointChartValue(i.toDouble(), v.toDouble()); |
| 118 | }, | 118 | }, |
| 119 | ), | 119 | ), |
| 120 | ), | 120 | ), |
| @@ -138,11 +138,11 @@ Future<Uint8List> generateReport( | @@ -138,11 +138,11 @@ Future<Uint8List> generateReport( | ||
| 138 | isCurved: true, | 138 | isCurved: true, |
| 139 | drawPoints: false, | 139 | drawPoints: false, |
| 140 | color: baseColor, | 140 | color: baseColor, |
| 141 | - data: List<pw.LineChartValue>.generate( | 141 | + data: List<pw.PointChartValue>.generate( |
| 142 | dataTable.length, | 142 | dataTable.length, |
| 143 | (i) { | 143 | (i) { |
| 144 | final v = dataTable[i][2] as num; | 144 | final v = dataTable[i][2] as num; |
| 145 | - return pw.LineChartValue(i.toDouble(), v.toDouble()); | 145 | + return pw.PointChartValue(i.toDouble(), v.toDouble()); |
| 146 | }, | 146 | }, |
| 147 | ), | 147 | ), |
| 148 | ), | 148 | ), |
| @@ -642,6 +642,11 @@ class SizedBox extends StatelessWidget { | @@ -642,6 +642,11 @@ class SizedBox extends StatelessWidget { | ||
| 642 | : width = size?.x, | 642 | : width = size?.x, |
| 643 | height = size?.y; | 643 | height = size?.y; |
| 644 | 644 | ||
| 645 | + /// Creates a box whose width and height are equal. | ||
| 646 | + SizedBox.square({this.child, double? dimension}) | ||
| 647 | + : width = dimension, | ||
| 648 | + height = dimension; | ||
| 649 | + | ||
| 645 | /// If non-null, requires the child to have exactly this width. | 650 | /// If non-null, requires the child to have exactly this width. |
| 646 | final double? width; | 651 | final double? width; |
| 647 | 652 |
| @@ -17,14 +17,15 @@ | @@ -17,14 +17,15 @@ | ||
| 17 | import '../../../pdf.dart'; | 17 | import '../../../pdf.dart'; |
| 18 | import '../flex.dart'; | 18 | import '../flex.dart'; |
| 19 | import '../geometry.dart'; | 19 | import '../geometry.dart'; |
| 20 | +import '../page.dart'; | ||
| 20 | import '../widget.dart'; | 21 | import '../widget.dart'; |
| 21 | import 'chart.dart'; | 22 | import 'chart.dart'; |
| 22 | import 'grid_cartesian.dart'; | 23 | import 'grid_cartesian.dart'; |
| 23 | -import 'line_chart.dart'; | 24 | +import 'point_chart.dart'; |
| 24 | 25 | ||
| 25 | -class BarDataSet extends Dataset { | 26 | +class BarDataSet<T extends PointChartValue> extends PointDataSet<T> { |
| 26 | BarDataSet({ | 27 | BarDataSet({ |
| 27 | - required this.data, | 28 | + required List<T> data, |
| 28 | String? legend, | 29 | String? legend, |
| 29 | this.borderColor, | 30 | this.borderColor, |
| 30 | this.borderWidth = 1.5, | 31 | this.borderWidth = 1.5, |
| @@ -35,16 +36,26 @@ class BarDataSet extends Dataset { | @@ -35,16 +36,26 @@ class BarDataSet extends Dataset { | ||
| 35 | this.width = 10, | 36 | this.width = 10, |
| 36 | this.offset = 0, | 37 | this.offset = 0, |
| 37 | this.axis = Axis.horizontal, | 38 | this.axis = Axis.horizontal, |
| 39 | + PdfColor? pointColor, | ||
| 40 | + double pointSize = 3, | ||
| 41 | + bool drawPoints = false, | ||
| 42 | + BuildCallback? shape, | ||
| 43 | + Widget Function(Context context, T value)? buildValue, | ||
| 44 | + ValuePosition valuePosition = ValuePosition.auto, | ||
| 38 | }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, | 45 | }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, |
| 39 | assert((drawBorder ?? borderColor != null && color != borderColor) || | 46 | assert((drawBorder ?? borderColor != null && color != borderColor) || |
| 40 | drawSurface), | 47 | drawSurface), |
| 41 | super( | 48 | super( |
| 42 | legend: legend, | 49 | legend: legend, |
| 43 | - color: color, | 50 | + color: pointColor ?? color, |
| 51 | + data: data, | ||
| 52 | + buildValue: buildValue, | ||
| 53 | + drawPoints: drawPoints, | ||
| 54 | + pointSize: pointSize, | ||
| 55 | + shape: shape, | ||
| 56 | + valuePosition: valuePosition, | ||
| 44 | ); | 57 | ); |
| 45 | 58 | ||
| 46 | - final List<LineChartValue> data; | ||
| 47 | - | ||
| 48 | final bool drawBorder; | 59 | final bool drawBorder; |
| 49 | final PdfColor? borderColor; | 60 | final PdfColor? borderColor; |
| 50 | final double borderWidth; | 61 | final double borderWidth; |
| @@ -58,7 +69,7 @@ class BarDataSet extends Dataset { | @@ -58,7 +69,7 @@ class BarDataSet extends Dataset { | ||
| 58 | 69 | ||
| 59 | final Axis axis; | 70 | final Axis axis; |
| 60 | 71 | ||
| 61 | - void _drawSurface(Context context, ChartGrid grid, LineChartValue value) { | 72 | + void _drawSurface(Context context, ChartGrid grid, T value) { |
| 62 | switch (axis) { | 73 | switch (axis) { |
| 63 | case Axis.horizontal: | 74 | case Axis.horizontal: |
| 64 | final y = (grid is CartesianGrid) ? grid.xAxisOffset : 0.0; | 75 | final y = (grid is CartesianGrid) ? grid.xAxisOffset : 0.0; |
| @@ -128,4 +139,19 @@ class BarDataSet extends Dataset { | @@ -128,4 +139,19 @@ class BarDataSet extends Dataset { | ||
| 128 | ..strokePath(); | 139 | ..strokePath(); |
| 129 | } | 140 | } |
| 130 | } | 141 | } |
| 142 | + | ||
| 143 | + @override | ||
| 144 | + ValuePosition automaticValuePosition( | ||
| 145 | + PdfPoint point, | ||
| 146 | + PdfPoint size, | ||
| 147 | + PdfPoint? previous, | ||
| 148 | + PdfPoint? next, | ||
| 149 | + ) { | ||
| 150 | + final pos = super.automaticValuePosition(point, size, previous, next); | ||
| 151 | + if (pos == ValuePosition.right || pos == ValuePosition.left) { | ||
| 152 | + return ValuePosition.top; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + return pos; | ||
| 156 | + } | ||
| 131 | } | 157 | } |
| @@ -160,7 +160,9 @@ abstract class Dataset extends Widget { | @@ -160,7 +160,9 @@ abstract class Dataset extends Widget { | ||
| 160 | 160 | ||
| 161 | void paintBackground(Context context) {} | 161 | void paintBackground(Context context) {} |
| 162 | 162 | ||
| 163 | - Widget legendShape() { | 163 | + void paintForeground(Context context) {} |
| 164 | + | ||
| 165 | + Widget legendShape(Context context) { | ||
| 164 | return Container( | 166 | return Container( |
| 165 | decoration: BoxDecoration( | 167 | decoration: BoxDecoration( |
| 166 | color: color, | 168 | color: color, |
| @@ -116,5 +116,9 @@ class CartesianGrid extends ChartGrid { | @@ -116,5 +116,9 @@ class CartesianGrid extends ChartGrid { | ||
| 116 | context.canvas.restoreContext(); | 116 | context.canvas.restoreContext(); |
| 117 | _xAxis.paint(context); | 117 | _xAxis.paint(context); |
| 118 | _yAxis.paint(context); | 118 | _yAxis.paint(context); |
| 119 | + | ||
| 120 | + for (final dataSet in datasets) { | ||
| 121 | + dataSet.paintForeground(context); | ||
| 122 | + } | ||
| 119 | } | 123 | } |
| 120 | } | 124 | } |
| @@ -56,7 +56,7 @@ class ChartLegend extends StatelessWidget { | @@ -56,7 +56,7 @@ class ChartLegend extends StatelessWidget { | ||
| 56 | width: style.fontSize, | 56 | width: style.fontSize, |
| 57 | height: style.fontSize, | 57 | height: style.fontSize, |
| 58 | margin: const EdgeInsets.only(right: 5), | 58 | margin: const EdgeInsets.only(right: 5), |
| 59 | - child: dataset.legendShape(), | 59 | + child: dataset.legendShape(context), |
| 60 | ), | 60 | ), |
| 61 | Text( | 61 | Text( |
| 62 | dataset.legend!, | 62 | dataset.legend!, |
| @@ -16,28 +16,31 @@ | @@ -16,28 +16,31 @@ | ||
| 16 | 16 | ||
| 17 | import '../../../pdf.dart'; | 17 | import '../../../pdf.dart'; |
| 18 | import '../geometry.dart'; | 18 | import '../geometry.dart'; |
| 19 | +import '../page.dart'; | ||
| 19 | import '../widget.dart'; | 20 | import '../widget.dart'; |
| 20 | import 'chart.dart'; | 21 | import 'chart.dart'; |
| 21 | import 'grid_cartesian.dart'; | 22 | import 'grid_cartesian.dart'; |
| 23 | +import 'point_chart.dart'; | ||
| 22 | 24 | ||
| 23 | -class LineChartValue extends ChartValue { | ||
| 24 | - const LineChartValue(this.x, this.y); | ||
| 25 | - final double x; | ||
| 26 | - final double y; | ||
| 27 | - | ||
| 28 | - PdfPoint get point => PdfPoint(x, y); | 25 | +@Deprecated('Use PointChartValue') |
| 26 | +class LineChartValue extends PointChartValue { | ||
| 27 | + const LineChartValue(double x, double y) : super(x, y); | ||
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | -class LineDataSet extends Dataset { | 30 | +class LineDataSet<T extends PointChartValue> extends PointDataSet<T> { |
| 32 | LineDataSet({ | 31 | LineDataSet({ |
| 33 | - required this.data, | 32 | + required List<T> data, |
| 34 | String? legend, | 33 | String? legend, |
| 35 | - this.pointColor, | ||
| 36 | - this.pointSize = 3, | 34 | + PdfColor? pointColor, |
| 35 | + double pointSize = 3, | ||
| 37 | PdfColor color = PdfColors.blue, | 36 | PdfColor color = PdfColors.blue, |
| 38 | this.lineWidth = 2, | 37 | this.lineWidth = 2, |
| 39 | this.drawLine = true, | 38 | this.drawLine = true, |
| 40 | - this.drawPoints = true, | 39 | + this.lineColor, |
| 40 | + bool drawPoints = true, | ||
| 41 | + BuildCallback? shape, | ||
| 42 | + Widget Function(Context context, T value)? buildValue, | ||
| 43 | + ValuePosition valuePosition = ValuePosition.auto, | ||
| 41 | this.drawSurface = false, | 44 | this.drawSurface = false, |
| 42 | this.surfaceOpacity = .2, | 45 | this.surfaceOpacity = .2, |
| 43 | this.surfaceColor, | 46 | this.surfaceColor, |
| @@ -46,19 +49,19 @@ class LineDataSet extends Dataset { | @@ -46,19 +49,19 @@ class LineDataSet extends Dataset { | ||
| 46 | }) : assert(drawLine || drawPoints || drawSurface), | 49 | }) : assert(drawLine || drawPoints || drawSurface), |
| 47 | super( | 50 | super( |
| 48 | legend: legend, | 51 | legend: legend, |
| 49 | - color: color, | 52 | + color: pointColor ?? color, |
| 53 | + data: data, | ||
| 54 | + drawPoints: drawPoints, | ||
| 55 | + pointSize: pointSize, | ||
| 56 | + buildValue: buildValue, | ||
| 57 | + shape: shape, | ||
| 58 | + valuePosition: valuePosition, | ||
| 50 | ); | 59 | ); |
| 51 | 60 | ||
| 52 | - final List<LineChartValue> data; | ||
| 53 | - | ||
| 54 | final bool drawLine; | 61 | final bool drawLine; |
| 55 | - | 62 | + final PdfColor? lineColor; |
| 56 | final double lineWidth; | 63 | final double lineWidth; |
| 57 | 64 | ||
| 58 | - final bool drawPoints; | ||
| 59 | - final PdfColor? pointColor; | ||
| 60 | - final double pointSize; | ||
| 61 | - | ||
| 62 | final bool drawSurface; | 65 | final bool drawSurface; |
| 63 | final PdfColor? surfaceColor; | 66 | final PdfColor? surfaceColor; |
| 64 | final double surfaceOpacity; | 67 | final double surfaceOpacity; |
| @@ -122,13 +125,6 @@ class LineDataSet extends Dataset { | @@ -122,13 +125,6 @@ class LineDataSet extends Dataset { | ||
| 122 | context.canvas.lineTo(pf.x, y); | 125 | context.canvas.lineTo(pf.x, y); |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | - void _drawPoints(Context context, ChartGrid grid) { | ||
| 126 | - for (final value in data) { | ||
| 127 | - final p = grid.toChart(value.point); | ||
| 128 | - context.canvas.drawEllipse(p.x, p.y, pointSize, pointSize); | ||
| 129 | - } | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | @override | 128 | @override |
| 133 | void paintBackground(Context context) { | 129 | void paintBackground(Context context) { |
| 134 | if (data.isEmpty) { | 130 | if (data.isEmpty) { |
| @@ -172,19 +168,46 @@ class LineDataSet extends Dataset { | @@ -172,19 +168,46 @@ class LineDataSet extends Dataset { | ||
| 172 | _drawLine(context, grid, true); | 168 | _drawLine(context, grid, true); |
| 173 | 169 | ||
| 174 | context.canvas | 170 | context.canvas |
| 175 | - ..setStrokeColor(color) | 171 | + ..setStrokeColor(lineColor ?? color) |
| 176 | ..setLineWidth(lineWidth) | 172 | ..setLineWidth(lineWidth) |
| 177 | ..setLineCap(PdfLineCap.round) | 173 | ..setLineCap(PdfLineCap.round) |
| 178 | ..setLineJoin(PdfLineJoin.round) | 174 | ..setLineJoin(PdfLineJoin.round) |
| 179 | ..strokePath(); | 175 | ..strokePath(); |
| 180 | } | 176 | } |
| 177 | + } | ||
| 181 | 178 | ||
| 182 | - if (drawPoints) { | ||
| 183 | - _drawPoints(context, grid); | 179 | + @override |
| 180 | + ValuePosition automaticValuePosition( | ||
| 181 | + PdfPoint point, | ||
| 182 | + PdfPoint size, | ||
| 183 | + PdfPoint? previous, | ||
| 184 | + PdfPoint? next, | ||
| 185 | + ) { | ||
| 186 | + if (point.y - size.y - delta < box!.bottom) { | ||
| 187 | + return ValuePosition.top; | ||
| 188 | + } | ||
| 184 | 189 | ||
| 185 | - context.canvas | ||
| 186 | - ..setColor(pointColor ?? color) | ||
| 187 | - ..fillPath(); | 190 | + if (previous != null && |
| 191 | + previous.y > point.y && | ||
| 192 | + next != null && | ||
| 193 | + next.y > point.y) { | ||
| 194 | + return ValuePosition.bottom; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + if (previous != null && | ||
| 198 | + previous.y < point.y && | ||
| 199 | + next != null && | ||
| 200 | + next.y > point.y) { | ||
| 201 | + return ValuePosition.left; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + if (previous != null && | ||
| 205 | + previous.y > point.y && | ||
| 206 | + next != null && | ||
| 207 | + next.y < point.y) { | ||
| 208 | + return ValuePosition.right; | ||
| 188 | } | 209 | } |
| 210 | + | ||
| 211 | + return super.automaticValuePosition(point, size, previous, next); | ||
| 189 | } | 212 | } |
| 190 | } | 213 | } |
pdf/lib/src/widgets/chart/point_chart.dart
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +import '../../../pdf.dart'; | ||
| 18 | +import '../basic.dart'; | ||
| 19 | +import '../geometry.dart'; | ||
| 20 | +import '../page.dart'; | ||
| 21 | +import '../widget.dart'; | ||
| 22 | +import 'chart.dart'; | ||
| 23 | + | ||
| 24 | +enum ValuePosition { left, top, right, bottom, auto } | ||
| 25 | + | ||
| 26 | +class PointChartValue extends ChartValue { | ||
| 27 | + const PointChartValue(this.x, this.y); | ||
| 28 | + final double x; | ||
| 29 | + final double y; | ||
| 30 | + | ||
| 31 | + PdfPoint get point => PdfPoint(x, y); | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +class PointDataSet<T extends PointChartValue> extends Dataset { | ||
| 35 | + PointDataSet({ | ||
| 36 | + required this.data, | ||
| 37 | + String? legend, | ||
| 38 | + this.pointSize = 3, | ||
| 39 | + PdfColor color = PdfColors.blue, | ||
| 40 | + this.drawPoints = true, | ||
| 41 | + this.shape, | ||
| 42 | + this.buildValue, | ||
| 43 | + this.valuePosition = ValuePosition.auto, | ||
| 44 | + }) : super( | ||
| 45 | + legend: legend, | ||
| 46 | + color: color, | ||
| 47 | + ); | ||
| 48 | + | ||
| 49 | + final List<T> data; | ||
| 50 | + | ||
| 51 | + final bool drawPoints; | ||
| 52 | + | ||
| 53 | + final double pointSize; | ||
| 54 | + | ||
| 55 | + final BuildCallback? shape; | ||
| 56 | + | ||
| 57 | + final Widget Function(Context context, T value)? buildValue; | ||
| 58 | + | ||
| 59 | + final ValuePosition valuePosition; | ||
| 60 | + | ||
| 61 | + double get delta => pointSize * .5; | ||
| 62 | + | ||
| 63 | + @override | ||
| 64 | + void layout(Context context, BoxConstraints constraints, | ||
| 65 | + {bool parentUsesSize = false}) { | ||
| 66 | + box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + ValuePosition automaticValuePosition( | ||
| 70 | + PdfPoint point, | ||
| 71 | + PdfPoint size, | ||
| 72 | + PdfPoint? previous, | ||
| 73 | + PdfPoint? next, | ||
| 74 | + ) { | ||
| 75 | + // Usually on top, except on the edges | ||
| 76 | + | ||
| 77 | + if (point.x - size.x / 2 < box!.left) { | ||
| 78 | + return ValuePosition.right; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + if (point.x + size.x / 2 > box!.right) { | ||
| 82 | + return ValuePosition.left; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + if (point.y + size.y + delta > box!.top) { | ||
| 86 | + return ValuePosition.bottom; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + return ValuePosition.top; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @override | ||
| 93 | + void paintForeground(Context context) { | ||
| 94 | + super.paintForeground(context); | ||
| 95 | + | ||
| 96 | + if (data.isEmpty) { | ||
| 97 | + return; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + final grid = Chart.of(context).grid; | ||
| 101 | + | ||
| 102 | + if (drawPoints) { | ||
| 103 | + if (shape == null) { | ||
| 104 | + for (final value in data) { | ||
| 105 | + final p = grid.toChart(value.point); | ||
| 106 | + context.canvas.drawEllipse(p.x, p.y, pointSize, pointSize); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + context.canvas | ||
| 110 | + ..setColor(color) | ||
| 111 | + ..fillPath(); | ||
| 112 | + } else { | ||
| 113 | + for (final value in data) { | ||
| 114 | + final p = grid.toChart(value.point); | ||
| 115 | + | ||
| 116 | + Widget.draw( | ||
| 117 | + SizedBox.square( | ||
| 118 | + dimension: pointSize * 2, | ||
| 119 | + child: shape!(context), | ||
| 120 | + ), | ||
| 121 | + offset: p, | ||
| 122 | + alignment: Alignment.center, | ||
| 123 | + context: context, | ||
| 124 | + ); | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + if (buildValue != null) { | ||
| 130 | + PdfPoint? previous; | ||
| 131 | + var index = 1; | ||
| 132 | + | ||
| 133 | + for (final value in data) { | ||
| 134 | + final p = grid.toChart(value.point); | ||
| 135 | + | ||
| 136 | + final size = Widget.measure( | ||
| 137 | + buildValue!(context, value), | ||
| 138 | + context: context, | ||
| 139 | + ); | ||
| 140 | + | ||
| 141 | + final PdfPoint offset; | ||
| 142 | + var pos = valuePosition; | ||
| 143 | + if (pos == ValuePosition.auto) { | ||
| 144 | + final next = | ||
| 145 | + index < data.length ? grid.toChart(data[index++].point) : null; | ||
| 146 | + pos = automaticValuePosition(p, size, previous, next); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + switch (pos) { | ||
| 150 | + case ValuePosition.left: | ||
| 151 | + offset = PdfPoint(p.x - size.x / 2 - pointSize - delta, p.y); | ||
| 152 | + break; | ||
| 153 | + case ValuePosition.top: | ||
| 154 | + offset = PdfPoint(p.x, p.y + size.y / 2 + pointSize + delta); | ||
| 155 | + break; | ||
| 156 | + case ValuePosition.right: | ||
| 157 | + offset = PdfPoint(p.x + size.x / 2 + pointSize + delta, p.y); | ||
| 158 | + break; | ||
| 159 | + case ValuePosition.bottom: | ||
| 160 | + offset = PdfPoint(p.x, p.y - size.y / 2 - pointSize - delta); | ||
| 161 | + break; | ||
| 162 | + case ValuePosition.auto: | ||
| 163 | + assert(false, 'We have an issue here'); | ||
| 164 | + offset = p; | ||
| 165 | + break; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + Widget.draw( | ||
| 169 | + buildValue!(context, value), | ||
| 170 | + offset: offset, | ||
| 171 | + alignment: Alignment.center, | ||
| 172 | + context: context, | ||
| 173 | + ); | ||
| 174 | + | ||
| 175 | + previous = p; | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + @override | ||
| 181 | + Widget legendShape(Context context) { | ||
| 182 | + return shape == null ? super.legendShape(context) : shape!(context); | ||
| 183 | + } | ||
| 184 | +} |
| @@ -29,6 +29,7 @@ export 'src/widgets/chart/grid_radial.dart'; | @@ -29,6 +29,7 @@ export 'src/widgets/chart/grid_radial.dart'; | ||
| 29 | export 'src/widgets/chart/legend.dart'; | 29 | export 'src/widgets/chart/legend.dart'; |
| 30 | export 'src/widgets/chart/line_chart.dart'; | 30 | export 'src/widgets/chart/line_chart.dart'; |
| 31 | export 'src/widgets/chart/pie_chart.dart'; | 31 | export 'src/widgets/chart/pie_chart.dart'; |
| 32 | +export 'src/widgets/chart/point_chart.dart'; | ||
| 32 | export 'src/widgets/clip.dart'; | 33 | export 'src/widgets/clip.dart'; |
| 33 | export 'src/widgets/container.dart'; | 34 | export 'src/widgets/container.dart'; |
| 34 | export 'src/widgets/content.dart'; | 35 | export 'src/widgets/content.dart'; |
| @@ -3,7 +3,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -3,7 +3,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
| 3 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 3 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
| 4 | repository: https://github.com/DavBfr/dart_pdf | 4 | repository: https://github.com/DavBfr/dart_pdf |
| 5 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 5 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 6 | -version: 3.7.5 | 6 | +version: 3.8.0 |
| 7 | 7 | ||
| 8 | environment: | 8 | environment: |
| 9 | sdk: ">=2.12.0 <3.0.0" | 9 | sdk: ">=2.12.0 <3.0.0" |
| @@ -39,10 +39,10 @@ void main() { | @@ -39,10 +39,10 @@ void main() { | ||
| 39 | ), | 39 | ), |
| 40 | datasets: <Dataset>[ | 40 | datasets: <Dataset>[ |
| 41 | LineDataSet( | 41 | LineDataSet( |
| 42 | - data: const <LineChartValue>[ | ||
| 43 | - LineChartValue(1, 1), | ||
| 44 | - LineChartValue(2, 3), | ||
| 45 | - LineChartValue(3, 7), | 42 | + data: const <PointChartValue>[ |
| 43 | + PointChartValue(1, 1), | ||
| 44 | + PointChartValue(2, 3), | ||
| 45 | + PointChartValue(3, 7), | ||
| 46 | ], | 46 | ], |
| 47 | ), | 47 | ), |
| 48 | ], | 48 | ], |
| @@ -60,10 +60,10 @@ void main() { | @@ -60,10 +60,10 @@ void main() { | ||
| 60 | ), | 60 | ), |
| 61 | datasets: <Dataset>[ | 61 | datasets: <Dataset>[ |
| 62 | LineDataSet( | 62 | LineDataSet( |
| 63 | - data: const <LineChartValue>[ | ||
| 64 | - LineChartValue(1, 1), | ||
| 65 | - LineChartValue(2, 3), | ||
| 66 | - LineChartValue(3, 7), | 63 | + data: const <PointChartValue>[ |
| 64 | + PointChartValue(1, 1), | ||
| 65 | + PointChartValue(2, 3), | ||
| 66 | + PointChartValue(3, 7), | ||
| 67 | ], | 67 | ], |
| 68 | drawLine: false, | 68 | drawLine: false, |
| 69 | ), | 69 | ), |
| @@ -81,10 +81,10 @@ void main() { | @@ -81,10 +81,10 @@ void main() { | ||
| 81 | ), | 81 | ), |
| 82 | datasets: <Dataset>[ | 82 | datasets: <Dataset>[ |
| 83 | LineDataSet( | 83 | LineDataSet( |
| 84 | - data: const <LineChartValue>[ | ||
| 85 | - LineChartValue(1, 1), | ||
| 86 | - LineChartValue(2, 3), | ||
| 87 | - LineChartValue(3, 7), | 84 | + data: const <PointChartValue>[ |
| 85 | + PointChartValue(1, 1), | ||
| 86 | + PointChartValue(2, 3), | ||
| 87 | + PointChartValue(3, 7), | ||
| 88 | ], | 88 | ], |
| 89 | drawPoints: false, | 89 | drawPoints: false, |
| 90 | ), | 90 | ), |
| @@ -103,10 +103,10 @@ void main() { | @@ -103,10 +103,10 @@ void main() { | ||
| 103 | ), | 103 | ), |
| 104 | datasets: <Dataset>[ | 104 | datasets: <Dataset>[ |
| 105 | LineDataSet( | 105 | LineDataSet( |
| 106 | - data: const <LineChartValue>[ | ||
| 107 | - LineChartValue(1, 1), | ||
| 108 | - LineChartValue(2, 3), | ||
| 109 | - LineChartValue(3, 7), | 106 | + data: const <PointChartValue>[ |
| 107 | + PointChartValue(1, 1), | ||
| 108 | + PointChartValue(2, 3), | ||
| 109 | + PointChartValue(3, 7), | ||
| 110 | ], | 110 | ], |
| 111 | drawLine: false, | 111 | drawLine: false, |
| 112 | pointColor: PdfColors.red, | 112 | pointColor: PdfColors.red, |
| @@ -132,10 +132,10 @@ void main() { | @@ -132,10 +132,10 @@ void main() { | ||
| 132 | ), | 132 | ), |
| 133 | datasets: <Dataset>[ | 133 | datasets: <Dataset>[ |
| 134 | LineDataSet( | 134 | LineDataSet( |
| 135 | - data: const <LineChartValue>[ | ||
| 136 | - LineChartValue(1, 1), | ||
| 137 | - LineChartValue(2, 3), | ||
| 138 | - LineChartValue(3, 7), | 135 | + data: const <PointChartValue>[ |
| 136 | + PointChartValue(1, 1), | ||
| 137 | + PointChartValue(2, 3), | ||
| 138 | + PointChartValue(3, 7), | ||
| 139 | ], | 139 | ], |
| 140 | ), | 140 | ), |
| 141 | ], | 141 | ], |
| @@ -156,10 +156,10 @@ void main() { | @@ -156,10 +156,10 @@ void main() { | ||
| 156 | LineDataSet( | 156 | LineDataSet( |
| 157 | drawPoints: false, | 157 | drawPoints: false, |
| 158 | isCurved: true, | 158 | isCurved: true, |
| 159 | - data: const <LineChartValue>[ | ||
| 160 | - LineChartValue(1, 1), | ||
| 161 | - LineChartValue(3, 7), | ||
| 162 | - LineChartValue(5, 3), | 159 | + data: const <PointChartValue>[ |
| 160 | + PointChartValue(1, 1), | ||
| 161 | + PointChartValue(3, 7), | ||
| 162 | + PointChartValue(5, 3), | ||
| 163 | ], | 163 | ], |
| 164 | ), | 164 | ), |
| 165 | ], | 165 | ], |
| @@ -179,10 +179,10 @@ void main() { | @@ -179,10 +179,10 @@ void main() { | ||
| 179 | ), | 179 | ), |
| 180 | datasets: <Dataset>[ | 180 | datasets: <Dataset>[ |
| 181 | BarDataSet( | 181 | BarDataSet( |
| 182 | - data: const <LineChartValue>[ | ||
| 183 | - LineChartValue(1, 1), | ||
| 184 | - LineChartValue(2, 3), | ||
| 185 | - LineChartValue(3, 7), | 182 | + data: const <PointChartValue>[ |
| 183 | + PointChartValue(1, 1), | ||
| 184 | + PointChartValue(2, 3), | ||
| 185 | + PointChartValue(3, 7), | ||
| 186 | ], | 186 | ], |
| 187 | ), | 187 | ), |
| 188 | ], | 188 | ], |
| @@ -201,10 +201,10 @@ void main() { | @@ -201,10 +201,10 @@ void main() { | ||
| 201 | datasets: <Dataset>[ | 201 | datasets: <Dataset>[ |
| 202 | BarDataSet( | 202 | BarDataSet( |
| 203 | axis: Axis.vertical, | 203 | axis: Axis.vertical, |
| 204 | - data: const <LineChartValue>[ | ||
| 205 | - LineChartValue(1, 1), | ||
| 206 | - LineChartValue(2, 3), | ||
| 207 | - LineChartValue(3, 7), | 204 | + data: const <PointChartValue>[ |
| 205 | + PointChartValue(1, 1), | ||
| 206 | + PointChartValue(2, 3), | ||
| 207 | + PointChartValue(3, 7), | ||
| 208 | ], | 208 | ], |
| 209 | ), | 209 | ), |
| 210 | ], | 210 | ], |
-
Please register or login to post a comment