Skip to content

Commit bd5b151

Browse files
feat!: cell and tile charts take a BorderRadius
CalendarChart.cellRadius, WaffleChart.cellRadius, TreemapChart.radius, HeatmapChart.radius and SeasonalityChart.radius are each a BorderRadius rather than a double, so a caller can round the corners of a cell one at a time — the outer corners of a grid, say — instead of all four together. Each default draws the shape it drew before, and the hover outline follows the cell it traces.
1 parent 600fcfa commit bd5b151

13 files changed

Lines changed: 42 additions & 40 deletions

‎doc/calendar-chart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CalendarChart(
6464
| `firstWeekday` | The day a week begins on (default `DateTime.monday`) |
6565
| `monthsPerRow` | Month panels per row; `null` fits as many as it can |
6666
| `minPanelWidth` | The narrowest a panel may be when fitting a row |
67-
| `cellSpacing`, `cellRadius` | Gap between and rounding of day squares |
67+
| `cellSpacing`, `cellRadius` | Gap between day squares, and their rounding as a `BorderRadius` |
6868
| `headerHeight`, `monthSpacing` | Room for a month's name, and between panels |
6969
| `padding` | Space around the chart |
7070

‎doc/heatmap-chart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ HeatmapChart.matrix(
1313
xAxis: const HeatmapAxis(labels: dayNames),
1414
yAxis: const HeatmapAxis(labels: hourNames, size: 34),
1515
spacing: 3,
16-
radius: 3,
16+
radius: const BorderRadius.all(Radius.circular(3)),
1717
);
1818
```
1919

‎doc/seasonality-chart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ and `columnSummary` — for use in a table of your own.
7171
| `limit` | The value painted at full strength either way; `null` takes the largest square |
7272
| `showValues`, `valueFormatter`, `labelStyle` | Values in the squares; returns default to `+1.2%` |
7373
| `axisLabelStyle`, `rowAxisWidth`, `columnAxisHeight` | Row and column names |
74-
| `spacing`, `radius` | Square gaps and corners |
74+
| `spacing`, `radius` | Square gaps, and their corner rounding as a `BorderRadius` |
7575
| `padding`, `backgroundColor` | Around and behind the chart |
7676

7777
Setting `limit` keeps one extreme month from washing out the rest.

‎doc/treemap-chart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ proportions allow so small items remain readable.
5757
| --- | --- |
5858
| `sort` | Place the largest items first for the squarest layout (default); `false` keeps the given order |
5959
| `spacing` | Gap between tiles |
60-
| `radius` | Tile corner radius |
60+
| `radius` | Tile corner rounding, as a `BorderRadius` |
6161
| `groupHeaderHeight` | Height reserved at the top of a group for its label; omitted for groups too short to fit it. `0` disables headers |
6262
| `groupColor`, `groupLabelStyle` | Group background and label style |
6363
| `padding` | Space around the chart |

‎doc/waffle-chart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ many cells it holds; `tooltipBuilder` replaces the card and
6868

6969
| Field | Default |
7070
| --- | --- |
71-
| `cellGap`, `cellRadius` | 3 and 2 |
71+
| `cellGap`, `cellRadius` | 3, and a `BorderRadius` of 2 |
7272
| `emptyColor` | A faint grey for cells no slice reached |
7373
| `padding`, `backgroundColor` | None |
7474
| `animationDuration`, `animationCurve`, `animateOnMount` | The fill-in |

‎example/lib/src/gallery/gallery_entries.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ List<GalleryEntry> _results() => [
595595
colors: [galleryRed, Color(0xFF1B222B), galleryGreen],
596596
),
597597
cellSpacing: 3,
598-
cellRadius: 3,
598+
cellRadius: const BorderRadius.all(Radius.circular(3)),
599599
showDayNumbers: true,
600600
showWeekdayHeader: true,
601601
headerStyle: _smallAxisStyle,
@@ -699,7 +699,7 @@ List<GalleryEntry> _dashboard() => [
699699
height: 1.3,
700700
),
701701
spacing: 3,
702-
radius: 3,
702+
radius: const BorderRadius.all(Radius.circular(3)),
703703
),
704704
),
705705
GalleryVariant(
@@ -720,7 +720,7 @@ List<GalleryEntry> _dashboard() => [
720720
height: 1.3,
721721
),
722722
spacing: 3,
723-
radius: 3,
723+
radius: const BorderRadius.all(Radius.circular(3)),
724724
),
725725
),
726726
],
@@ -1439,7 +1439,7 @@ List<GalleryEntry> _dashboard() => [
14391439
WaffleSlice(label: 'Cash', value: 20, color: galleryGreen),
14401440
],
14411441
cellGap: 4,
1442-
cellRadius: 3,
1442+
cellRadius: BorderRadius.all(Radius.circular(3)),
14431443
),
14441444
),
14451445
GalleryVariant(
@@ -1451,7 +1451,7 @@ List<GalleryEntry> _dashboard() => [
14511451
],
14521452
total: 100,
14531453
cellGap: 4,
1454-
cellRadius: 3,
1454+
cellRadius: BorderRadius.all(Radius.circular(3)),
14551455
emptyColor: Color(0x22FA5252),
14561456
),
14571457
),

‎example/lib/src/series_page.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class _SeriesPageState extends State<SeriesPage> {
463463
'${(index + 9).toString().padLeft(2, '0')}:00',
464464
),
465465
spacing: 3,
466-
radius: 3,
466+
radius: const BorderRadius.all(Radius.circular(3)),
467467
onTouch: (d) => setState(() => _square = d),
468468
animationDuration: const Duration(milliseconds: 500),
469469
),

‎example/tool/screenshots.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ Widget heatmapScene() {
24192419
labels: ['Mon', '', 'Wed', '', 'Fri', '', 'Sun'],
24202420
),
24212421
spacing: 3,
2422-
radius: 2,
2422+
radius: const BorderRadius.all(Radius.circular(2)),
24232423
// A contribution graph wants squares, not columns.
24242424
squareCells: true,
24252425
),
@@ -2461,7 +2461,7 @@ Widget heatmapScene() {
24612461
'${(index + 9).toString().padLeft(2, '0')}:00',
24622462
),
24632463
spacing: 3,
2464-
radius: 3,
2464+
radius: const BorderRadius.all(Radius.circular(3)),
24652465
labelBuilder: (cell) => cell.value!.round().toString(),
24662466
),
24672467
),

‎lib/src/calendar/calendar_chart.dart‎

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

33
import 'package:flutter/widgets.dart';
44

5+
import '../corner_radius.dart';
56
import '../heatmap/heatmap_data.dart';
67
import '../renderer/text_painter_cache.dart';
78
import '../series/series_axis.dart';
@@ -377,7 +378,7 @@ class CalendarChart extends StatefulWidget {
377378
this.firstWeekday = DateTime.monday,
378379
this.monthsPerRow,
379380
this.cellSpacing = 2,
380-
this.cellRadius = 2,
381+
this.cellRadius = const BorderRadius.all(Radius.circular(2)),
381382
this.headerHeight = 16,
382383
this.monthSpacing = 12,
383384
this.minPanelWidth = 130,
@@ -435,7 +436,7 @@ class CalendarChart extends StatefulWidget {
435436
final double cellSpacing;
436437

437438
/// How rounded a day square is.
438-
final double cellRadius;
439+
final BorderRadius cellRadius;
439440

440441
/// How much room a month's name takes above its panel.
441442
final double headerHeight;
@@ -733,7 +734,6 @@ class CalendarChartPainter extends CustomPainter {
733734
if (layout.isEmpty) return;
734735

735736
final t = animation.clamp(0.0, 1.0);
736-
final radius = Radius.circular(math.max(0, chart.cellRadius));
737737
final fill = Paint()..isAntiAlias = true;
738738

739739
for (final cell in layout.cells) {
@@ -744,7 +744,7 @@ class CalendarChartPainter extends CustomPainter {
744744
? chart.scale.emptyColor
745745
: chart.scale.colorAt(value, min, max));
746746
fill.color = t >= 1 ? color : color.withValues(alpha: color.a * t);
747-
canvas.drawRRect(RRect.fromRectAndRadius(cell.rect, radius), fill);
747+
canvas.drawRRect(roundedBox(cell.rect, chart.cellRadius), fill);
748748
if (chart.showDayNumbers) _paintDayNumber(canvas, cell, color);
749749
}
750750

@@ -761,7 +761,7 @@ class CalendarChartPainter extends CustomPainter {
761761
for (final cell in layout.cells) {
762762
if (cell.date != at) continue;
763763
canvas.drawRRect(
764-
RRect.fromRectAndRadius(cell.rect.inflate(hover.width / 2), radius),
764+
roundedBox(cell.rect.inflate(hover.width / 2), chart.cellRadius),
765765
Paint()
766766
..style = PaintingStyle.stroke
767767
..strokeWidth = hover.width

‎lib/src/heatmap/heatmap_chart.dart‎

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

33
import 'package:flutter/widgets.dart';
44

5+
import '../corner_radius.dart';
56
import '../renderer/text_painter_cache.dart';
67
import '../series/series_axis.dart';
78
import 'heatmap_data.dart';
@@ -163,7 +164,7 @@ class HeatmapTouchDetails {
163164
/// xAxis: const HeatmapAxis(labels: dayNames),
164165
/// yAxis: const HeatmapAxis(labels: hourNames, size: 34),
165166
/// spacing: 3,
166-
/// radius: 3,
167+
/// radius: const BorderRadius.all(Radius.circular(3)),
167168
/// );
168169
/// ```
169170
///
@@ -184,7 +185,7 @@ class HeatmapChart extends StatefulWidget {
184185
this.xAxis = const HeatmapAxis(),
185186
this.yAxis = const HeatmapAxis(size: 30),
186187
this.spacing = 2,
187-
this.radius = 2,
188+
this.radius = const BorderRadius.all(Radius.circular(2)),
188189
this.squareCells = false,
189190
this.border,
190191
this.labelBuilder,
@@ -216,7 +217,7 @@ class HeatmapChart extends StatefulWidget {
216217
this.xAxis = const HeatmapAxis(),
217218
this.yAxis = const HeatmapAxis(size: 30),
218219
this.spacing = 2,
219-
this.radius = 2,
220+
this.radius = const BorderRadius.all(Radius.circular(2)),
220221
this.squareCells = false,
221222
this.border,
222223
this.labelBuilder,
@@ -261,8 +262,8 @@ class HeatmapChart extends StatefulWidget {
261262
/// The gap left between two squares.
262263
final double spacing;
263264

264-
/// The corner radius of a square.
265-
final double radius;
265+
/// The rounding of each square's corners, as drawn on the screen.
266+
final BorderRadius radius;
266267

267268
/// Whether the squares are kept square, which leaves the grid smaller than
268269
/// the box when the two do not have the same shape.
@@ -594,7 +595,6 @@ class HeatmapChartPainter extends CustomPainter {
594595
}
595596

596597
void _paintCells(Canvas canvas) {
597-
final radius = Radius.circular(chart.radius);
598598
final side = chart.border;
599599
final outline =
600600
side != null && side.style != BorderStyle.none && side.width > 0
@@ -612,7 +612,7 @@ class HeatmapChartPainter extends CustomPainter {
612612
for (var x = 0; x < layout.columns; x++) {
613613
final rect = layout.cellRect(x, y);
614614
if (rect.width <= 0 || rect.height <= 0) continue;
615-
final shape = RRect.fromRectAndRadius(rect, radius);
615+
final shape = roundedBox(rect, chart.radius);
616616
final color = _colorOf(cells[(x, y)]);
617617
byColor.putIfAbsent(color, Path.new).addRRect(shape);
618618
if (outline != null) canvas.drawRRect(shape, outline);
@@ -634,9 +634,9 @@ class HeatmapChartPainter extends CustomPainter {
634634
hover.style != BorderStyle.none &&
635635
hover.width > 0) {
636636
canvas.drawRRect(
637-
RRect.fromRectAndRadius(
637+
roundedBox(
638638
layout.cellRect(at.$1, at.$2).deflate(hover.width / 2),
639-
radius,
639+
chart.radius,
640640
),
641641
Paint()
642642
..style = PaintingStyle.stroke

0 commit comments

Comments
 (0)