From b017c4a683870540083776d61cec7b5c77c1baad Mon Sep 17 00:00:00 2001 From: Gazihan Alankus Date: Tue, 25 Jun 2019 19:00:32 +0300 Subject: [PATCH 1/2] Showing dash pattern in legend. --- .../chart/common/behavior/legend/legend_entry.dart | 2 ++ .../legend/per_datum_legend_entry_generator.dart | 1 + .../legend/per_series_legend_entry_generator.dart | 2 +- .../src/behaviors/legend/legend_entry_layout.dart | 1 + charts_flutter/lib/src/symbol_renderer.dart | 13 +++++++------ 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/charts_common/lib/src/chart/common/behavior/legend/legend_entry.dart b/charts_common/lib/src/chart/common/behavior/legend/legend_entry.dart index b3824bfd6..1fb066e33 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/legend_entry.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/legend_entry.dart @@ -30,6 +30,7 @@ class LegendEntry { final int datumIndex; final D domain; final Color color; + final List dashPattern; final TextStyleSpec textStyle; double value; String formattedValue; @@ -68,6 +69,7 @@ class LegendEntry { this.domain, this.value, this.color, + this.dashPattern, this.textStyle, this.isSelected = false, this.rowNumber, diff --git a/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart b/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart index 08b9cf5f5..2c5f25bfa 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart @@ -42,6 +42,7 @@ class PerDatumLegendEntryGenerator implements LegendEntryGenerator { legendEntries.add(new LegendEntry( series, series.domainFn(i).toString(), color: series.colorFn(i), + dashPattern: series.dashPatternFn(i), datum: series.data[i], datumIndex: i, textStyle: entryTextStyle)); diff --git a/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart b/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart index 43994c155..cf7a21643 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart @@ -39,7 +39,7 @@ class PerSeriesLegendEntryGenerator implements LegendEntryGenerator { List> getLegendEntries(List> seriesList) { final legendEntries = seriesList .map((series) => new LegendEntry(series, series.displayName, - color: series.colorFn(0), textStyle: entryTextStyle)) + color: series.colorFn(0), dashPattern: series.dashPatternFn(0), textStyle: entryTextStyle)) .toList(); // Update with measures only if showing measure on no selection. diff --git a/charts_flutter/lib/src/behaviors/legend/legend_entry_layout.dart b/charts_flutter/lib/src/behaviors/legend/legend_entry_layout.dart index aeaa9d11a..57bbd42e3 100644 --- a/charts_flutter/lib/src/behaviors/legend/legend_entry_layout.dart +++ b/charts_flutter/lib/src/behaviors/legend/legend_entry_layout.dart @@ -56,6 +56,7 @@ class SimpleLegendEntryLayout implements LegendEntryLayout { context, size: materialSymbolSize, color: color, + dashPattern: legendEntry.dashPattern, enabled: !isHidden, ), onTapUp: makeTapUpCallback(context, legendEntry, legend)); diff --git a/charts_flutter/lib/src/symbol_renderer.dart b/charts_flutter/lib/src/symbol_renderer.dart index d4405149e..ac6d3e658 100644 --- a/charts_flutter/lib/src/symbol_renderer.dart +++ b/charts_flutter/lib/src/symbol_renderer.dart @@ -31,7 +31,7 @@ class SymbolRendererCanvas implements SymbolRendererBuilder { @override Widget build(BuildContext context, - {Color color, Size size, bool enabled = true}) { + {Color color, List dashPattern, Size size, bool enabled = true}) { if (!enabled) { color = color.withOpacity(0.26); } @@ -40,7 +40,7 @@ class SymbolRendererCanvas implements SymbolRendererBuilder { size: size, child: new CustomPaint( painter: - new _SymbolCustomPaint(context, commonSymbolRenderer, color))); + new _SymbolCustomPaint(context, commonSymbolRenderer, color, dashPattern))); } } @@ -54,7 +54,7 @@ abstract class CustomSymbolRenderer extends common.SymbolRenderer /// Must override this method to build the custom Widget with the given color /// as @override - Widget build(BuildContext context, {Color color, Size size, bool enabled}); + Widget build(BuildContext context, {Color color, List dashPattern, Size size, bool enabled}); @override void paint(common.ChartCanvas canvas, Rectangle bounds, @@ -74,7 +74,7 @@ abstract class CustomSymbolRenderer extends common.SymbolRenderer /// Common interface for [CustomSymbolRenderer] & [SymbolRendererCanvas] for /// convenience for [LegendEntryLayout]. abstract class SymbolRendererBuilder { - Widget build(BuildContext context, {Color color, Size size, bool enabled}); + Widget build(BuildContext context, {Color color, List dashPattern, Size size, bool enabled}); } /// The Widget which fulfills the guts of [SymbolRendererCanvas] actually @@ -83,8 +83,9 @@ class _SymbolCustomPaint extends CustomPainter { final BuildContext context; final common.SymbolRenderer symbolRenderer; final Color color; + final List dashPattern; - _SymbolCustomPaint(this.context, this.symbolRenderer, this.color); + _SymbolCustomPaint(this.context, this.symbolRenderer, this.color, this.dashPattern); @override void paint(Canvas canvas, Size size) { @@ -94,7 +95,7 @@ class _SymbolCustomPaint extends CustomPainter { r: color.red, g: color.green, b: color.blue, a: color.alpha); symbolRenderer.paint( new ChartCanvas(canvas, GraphicsFactory(context)), bounds, - fillColor: commonColor, strokeColor: commonColor); + fillColor: commonColor, strokeColor: commonColor, dashPattern: dashPattern); } @override From 34048ea005b79532c13706d27b04024b808a5bcd Mon Sep 17 00:00:00 2001 From: Gazihan Alankus Date: Wed, 26 Jun 2019 14:42:37 +0300 Subject: [PATCH 2/2] Handle cases in which dash pattern function is null. --- .../behavior/legend/per_datum_legend_entry_generator.dart | 2 +- .../behavior/legend/per_series_legend_entry_generator.dart | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart b/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart index 2c5f25bfa..fbe796219 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/per_datum_legend_entry_generator.dart @@ -42,7 +42,7 @@ class PerDatumLegendEntryGenerator implements LegendEntryGenerator { legendEntries.add(new LegendEntry( series, series.domainFn(i).toString(), color: series.colorFn(i), - dashPattern: series.dashPatternFn(i), + dashPattern: series.dashPatternFn != null ? series.dashPatternFn(i) : null, datum: series.data[i], datumIndex: i, textStyle: entryTextStyle)); diff --git a/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart b/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart index cf7a21643..cc3eeae28 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart @@ -39,7 +39,10 @@ class PerSeriesLegendEntryGenerator implements LegendEntryGenerator { List> getLegendEntries(List> seriesList) { final legendEntries = seriesList .map((series) => new LegendEntry(series, series.displayName, - color: series.colorFn(0), dashPattern: series.dashPatternFn(0), textStyle: entryTextStyle)) + color: series.colorFn(0), + dashPattern: + series.dashPatternFn != null ? series.dashPatternFn(0) : null, + textStyle: entryTextStyle)) .toList(); // Update with measures only if showing measure on no selection.