Skip to content

Commit 45a1f78

Browse files
feat!: cards, labels and the toolbar take a BorderRadius
The last of the double corner radii: ChartStyle.labelCornerRadius, DrawingStyle.labelCornerRadius, DrawingStyle.toolbarBorderRadius, DrawingStyle.popoverBorderRadius and SeriesTooltip.borderRadius. The toolbar and popover already built a BorderRadius from theirs, so those two now pass the value straight through. The axis pills and legend chips go through roundedBox as well, so every rounded rectangle the package draws reads its corners the same way. Radii that describe a circle — dots, pie and gauge arcs, drawing handles, event marks, the rounded ends of the depth ratio bar — stay doubles, since a BorderRadius would say nothing there.
1 parent bd5b151 commit 45a1f78

10 files changed

Lines changed: 63 additions & 53 deletions

‎doc/migrating-from-fl_chart.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ patterns.
5656
| `fromY: 0` | `baseline: 0` |
5757
| `color` / per-rod colour | `color` + `negativeColor`, or `colorBuilder` |
5858
| `width` | `width`, or `widthFactor` with `minWidth` / `maxWidth` |
59-
| `borderRadius` rounded away from zero | `radius` — always on the end away from the baseline |
59+
| `borderRadius` rounded away from zero | `radius` — a `BorderRadius`, read as the corners are drawn |
6060
| `backDrawRodData` | `trackColor` |
6161
| `gradient` | `gradient` |
6262
| `fromY` per rod, for a floating bar | `SeriesPoint(x, y, low: ...)` |
@@ -150,7 +150,7 @@ SizedBox(
150150
tooltip: SeriesTooltip(
151151
placement: SeriesTooltipPlacement.above,
152152
backgroundColor: context.backgroundPaper,
153-
borderRadius: 10,
153+
borderRadius: const BorderRadius.all(Radius.circular(10)),
154154
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
155155
builder: (context, d) => BalanceTooltip(
156156
value: formatUsd(d.values.first.value),

‎example/lib/src/chart_theme.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ChartTheme {
8888
thicknessOptions: [1, 2, 3, 5],
8989
swatchesPerRow: 3,
9090
toolbarAxis: Axis.vertical,
91-
toolbarBorderRadius: 18,
91+
toolbarBorderRadius: BorderRadius.all(Radius.circular(18)),
9292
toolbarInitialOffset: Offset(12, 28),
9393
accentColor: Color(0xFF4DABF7),
9494
iconSize: 18,

‎lib/src/chart_style.dart‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import 'package:material_ui/material_ui.dart' show Alignment, Color;
1+
import 'package:material_ui/material_ui.dart'
2+
show Alignment, BorderRadius, Color, Radius;
23

34
import 'trading.dart';
45

@@ -478,7 +479,7 @@ class ChartStyle {
478479
this.axisLabelPadding = 4.0,
479480
this.priceAxisWidth = 0.0,
480481
this.secondaryPriceAxisWidth = 56.0,
481-
this.labelCornerRadius = 3.0,
482+
this.labelCornerRadius = const BorderRadius.all(Radius.circular(3)),
482483
this.legendPadding = 4.0,
483484
this.legendSpacing = 2.0,
484485
this.watermarkAlignment = Alignment.center,
@@ -644,7 +645,7 @@ class ChartStyle {
644645
final double secondaryPriceAxisWidth;
645646

646647
/// Corner radius of the axis label and legend pills.
647-
final double labelCornerRadius;
648+
final BorderRadius labelCornerRadius;
648649

649650
/// Space between an indicator legend's pill and its text.
650651
final double legendPadding;
@@ -701,7 +702,7 @@ class ChartStyle {
701702
double? axisLabelPadding,
702703
double? priceAxisWidth,
703704
double? secondaryPriceAxisWidth,
704-
double? labelCornerRadius,
705+
BorderRadius? labelCornerRadius,
705706
double? legendPadding,
706707
double? legendSpacing,
707708
Alignment? watermarkAlignment,

‎lib/src/drawing/drawing_style.dart‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class DrawingStyle {
7272
this.toolbarBackgroundColor,
7373
this.toolbarBorderColor,
7474
this.toolbarBorderWidth = 1.0,
75-
this.toolbarBorderRadius = 26.0,
75+
this.toolbarBorderRadius = const BorderRadius.all(Radius.circular(26)),
7676
this.toolbarPadding = const EdgeInsets.symmetric(
7777
horizontal: 6,
7878
vertical: 2,
@@ -87,7 +87,7 @@ class DrawingStyle {
8787
this.deleteColor = const Color(0xFFFF5252),
8888
this.doneColor = const Color(0xFF00E676),
8989
this.popoverBackgroundColor,
90-
this.popoverBorderRadius = 14.0,
90+
this.popoverBorderRadius = const BorderRadius.all(Radius.circular(14)),
9191
this.swatchSize = 26.0,
9292
this.swatchesPerRow = 5,
9393
this.handleRadius = 6.0,
@@ -111,7 +111,7 @@ class DrawingStyle {
111111
this.labelBackgroundColor,
112112
this.labelBackgroundAlpha = 220,
113113
this.labelBorderWidth = 1.4,
114-
this.labelCornerRadius = 5.0,
114+
this.labelCornerRadius = const BorderRadius.all(Radius.circular(5)),
115115
this.labelPadding = const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
116116
});
117117

@@ -189,7 +189,7 @@ class DrawingStyle {
189189
final double toolbarBorderWidth;
190190

191191
/// Corner radius of the toolbar.
192-
final double toolbarBorderRadius;
192+
final BorderRadius toolbarBorderRadius;
193193

194194
/// Space between the toolbar's outline and its buttons.
195195
final EdgeInsets toolbarPadding;
@@ -225,7 +225,7 @@ class DrawingStyle {
225225
final Color? popoverBackgroundColor;
226226

227227
/// Corner radius of the popovers.
228-
final double popoverBorderRadius;
228+
final BorderRadius popoverBorderRadius;
229229

230230
/// Side length of one colour swatch.
231231
final double swatchSize;
@@ -306,7 +306,7 @@ class DrawingStyle {
306306
final double labelBorderWidth;
307307

308308
/// Corner radius of the label.
309-
final double labelCornerRadius;
309+
final BorderRadius labelCornerRadius;
310310

311311
/// Space between a label's outline and its text.
312312
final EdgeInsets labelPadding;
@@ -346,7 +346,7 @@ class DrawingStyle {
346346
Color? toolbarBackgroundColor,
347347
Color? toolbarBorderColor,
348348
double? toolbarBorderWidth,
349-
double? toolbarBorderRadius,
349+
BorderRadius? toolbarBorderRadius,
350350
EdgeInsets? toolbarPadding,
351351
List<BoxShadow>? toolbarShadows,
352352
Offset? toolbarInitialOffset,
@@ -358,7 +358,7 @@ class DrawingStyle {
358358
Color? deleteColor,
359359
Color? doneColor,
360360
Color? popoverBackgroundColor,
361-
double? popoverBorderRadius,
361+
BorderRadius? popoverBorderRadius,
362362
double? swatchSize,
363363
int? swatchesPerRow,
364364
double? handleRadius,
@@ -382,7 +382,7 @@ class DrawingStyle {
382382
Color? labelBackgroundColor,
383383
int? labelBackgroundAlpha,
384384
double? labelBorderWidth,
385-
double? labelCornerRadius,
385+
BorderRadius? labelCornerRadius,
386386
EdgeInsets? labelPadding,
387387
}) {
388388
return DrawingStyle(

‎lib/src/drawing/drawing_toolbar.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class DrawingToolbar extends StatelessWidget {
138138
padding: style.toolbarPadding,
139139
decoration: BoxDecoration(
140140
color: _background,
141-
borderRadius: BorderRadius.circular(style.toolbarBorderRadius),
141+
borderRadius: style.toolbarBorderRadius,
142142
border: style.toolbarBorderWidth <= 0
143143
? null
144144
: Border.all(
@@ -462,7 +462,7 @@ class _PopoverState extends State<_Popover> {
462462
@override
463463
Widget build(BuildContext context) {
464464
final touchSize = widget.style.iconSize + 16;
465-
final radius = BorderRadius.circular(widget.style.popoverBorderRadius);
465+
final radius = widget.style.popoverBorderRadius;
466466

467467
return MenuAnchor(
468468
controller: _controller,

‎lib/src/renderer/base_chart_renderer.dart‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:material_ui/material_ui.dart';
22

3+
import '../corner_radius.dart';
4+
35
export '../chart_style.dart';
46

57
abstract class BaseChartRenderer<T> {
@@ -14,7 +16,7 @@ abstract class BaseChartRenderer<T> {
1416
Color? gridColumnColor,
1517
double gridStrokeWidth = 0.5,
1618
double separatorWidth = 1.0,
17-
this.labelCornerRadius = 3.0,
19+
this.labelCornerRadius = const BorderRadius.all(Radius.circular(3)),
1820
this.legendPadding = 4.0,
1921
this.legendBgColor,
2022
this.priceAxisGutter = 0.0,
@@ -37,7 +39,7 @@ abstract class BaseChartRenderer<T> {
3739
}
3840

3941
/// Corner radius of the legend pill.
40-
final double labelCornerRadius;
42+
final BorderRadius labelCornerRadius;
4143

4244
/// Space between the legend pill and its text.
4345
final double legendPadding;
@@ -200,12 +202,14 @@ abstract class BaseChartRenderer<T> {
200202
final background = legendBgColor;
201203
if (background != null && background.a > 0) {
202204
canvas.drawRRect(
203-
RRect.fromLTRBR(
204-
offset.dx - legendPadding,
205-
offset.dy - legendPadding / 2,
206-
offset.dx + tp.width + legendPadding,
207-
offset.dy + tp.height + legendPadding / 2,
208-
Radius.circular(labelCornerRadius),
205+
roundedBox(
206+
Rect.fromLTRB(
207+
offset.dx - legendPadding,
208+
offset.dy - legendPadding / 2,
209+
offset.dx + tp.width + legendPadding,
210+
offset.dy + tp.height + legendPadding / 2,
211+
),
212+
labelCornerRadius,
209213
),
210214
Paint()..color = background,
211215
);

‎lib/src/renderer/chart_painter.dart‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:math' as math;
22

33
import 'package:material_ui/material_ui.dart';
44

5+
import '../corner_radius.dart';
56
import '../drawing/line_painting.dart';
67
import '../drawing/shape_geometry.dart';
78
import '../entity/horizontal_line.dart';
@@ -2279,12 +2280,14 @@ class ChartPainter extends BaseChartPainter {
22792280
callout.color,
22802281
);
22812282
final padding = drawingStyle.labelPadding;
2282-
final rect = RRect.fromLTRBR(
2283-
box.dx - padding.left,
2284-
box.dy - tp.height / 2 - padding.top,
2285-
box.dx + tp.width + padding.right,
2286-
box.dy + tp.height / 2 + padding.bottom,
2287-
Radius.circular(drawingStyle.labelCornerRadius),
2283+
final rect = roundedBox(
2284+
Rect.fromLTRB(
2285+
box.dx - padding.left,
2286+
box.dy - tp.height / 2 - padding.top,
2287+
box.dx + tp.width + padding.right,
2288+
box.dy + tp.height / 2 + padding.bottom,
2289+
),
2290+
drawingStyle.labelCornerRadius,
22882291
);
22892292

22902293
canvas.drawRRect(
@@ -2589,12 +2592,14 @@ class ChartPainter extends BaseChartPainter {
25892592
Color borderColor,
25902593
) {
25912594
final padding = drawingStyle.labelPadding;
2592-
final rect = RRect.fromLTRBR(
2593-
textOffset.dx - padding.left,
2594-
textOffset.dy - padding.top,
2595-
textOffset.dx + tp.width + padding.right,
2596-
textOffset.dy + tp.height + padding.bottom,
2597-
Radius.circular(drawingStyle.labelCornerRadius),
2595+
final rect = roundedBox(
2596+
Rect.fromLTRB(
2597+
textOffset.dx - padding.left,
2598+
textOffset.dy - padding.top,
2599+
textOffset.dx + tp.width + padding.right,
2600+
textOffset.dy + tp.height + padding.bottom,
2601+
),
2602+
drawingStyle.labelCornerRadius,
25982603
);
25992604

26002605
canvas.drawRRect(
@@ -3082,12 +3087,9 @@ class ChartPainter extends BaseChartPainter {
30823087
final top = y - tp.height / 2 - padding / 2;
30833088

30843089
canvas.drawRRect(
3085-
RRect.fromLTRBR(
3086-
left,
3087-
top,
3088-
left + tagWidth,
3089-
top + tp.height + padding,
3090-
Radius.circular(chartStyle.labelCornerRadius),
3090+
roundedBox(
3091+
Rect.fromLTRB(left, top, left + tagWidth, top + tp.height + padding),
3092+
chartStyle.labelCornerRadius,
30913093
),
30923094
Paint()
30933095
..color = color

‎lib/src/renderer/main_renderer.dart‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:math' as math;
33
import 'package:material_ui/material_ui.dart';
44

55
import '../chart_type.dart';
6+
import '../corner_radius.dart';
67
import '../comparison.dart';
78
import '../drawing/line_painting.dart';
89
import '../entity/candle_entity.dart';
@@ -1078,12 +1079,14 @@ class MainRenderer extends BaseChartRenderer<CandleEntity> {
10781079

10791080
if (chartStyle.axisLabelBackground) {
10801081
canvas.drawRRect(
1081-
RRect.fromLTRBR(
1082-
offsetX - padding / 2,
1083-
offsetY,
1084-
offsetX + tp.width + padding / 2,
1085-
offsetY + tp.height,
1086-
Radius.circular(chartStyle.labelCornerRadius),
1082+
roundedBox(
1083+
Rect.fromLTRB(
1084+
offsetX - padding / 2,
1085+
offsetY,
1086+
offsetX + tp.width + padding / 2,
1087+
offsetY + tp.height,
1088+
),
1089+
chartStyle.labelCornerRadius,
10871090
),
10881091
Paint()..color = chartColors.effectiveAxisLabelBgColor,
10891092
);

‎lib/src/series/series_chart.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class _SeriesChartState extends State<SeriesChart>
763763
return DecoratedBox(
764764
decoration: BoxDecoration(
765765
color: tooltip.backgroundColor,
766-
borderRadius: BorderRadius.circular(tooltip.borderRadius),
766+
borderRadius: tooltip.borderRadius,
767767
border: tooltip.borderColor == null
768768
? null
769769
: Border.all(color: tooltip.borderColor!),

‎lib/src/series/series_touch.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SeriesTooltip {
8585
this.margin = 8,
8686
this.backgroundColor = const Color(0xF2202329),
8787
this.borderColor,
88-
this.borderRadius = 8,
88+
this.borderRadius = const BorderRadius.all(Radius.circular(8)),
8989
this.padding = const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
9090
this.titleStyle,
9191
this.valueStyle,
@@ -117,7 +117,7 @@ class SeriesTooltip {
117117
final Color? borderColor;
118118

119119
/// Card corner radius.
120-
final double borderRadius;
120+
final BorderRadius borderRadius;
121121

122122
/// Space inside the card.
123123
final EdgeInsets padding;

0 commit comments

Comments
 (0)