Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Showing dash pattern in legend. #282

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LegendEntry<D> {
final int datumIndex;
final D domain;
final Color color;
final List<int> dashPattern;
final TextStyleSpec textStyle;
double value;
String formattedValue;
Expand Down Expand Up @@ -68,6 +69,7 @@ class LegendEntry<D> {
this.domain,
this.value,
this.color,
this.dashPattern,
this.textStyle,
this.isSelected = false,
this.rowNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PerDatumLegendEntryGenerator<D> implements LegendEntryGenerator<D> {
legendEntries.add(new LegendEntry<D>(
series, series.domainFn(i).toString(),
color: series.colorFn(i),
dashPattern: series.dashPatternFn != null ? series.dashPatternFn(i) : null,
datum: series.data[i],
datumIndex: i,
textStyle: entryTextStyle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class PerSeriesLegendEntryGenerator<D> implements LegendEntryGenerator<D> {
List<LegendEntry<D>> getLegendEntries(List<MutableSeries<D>> seriesList) {
final legendEntries = seriesList
.map((series) => new LegendEntry<D>(series, series.displayName,
color: series.colorFn(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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SimpleLegendEntryLayout implements LegendEntryLayout {
context,
size: materialSymbolSize,
color: color,
dashPattern: legendEntry.dashPattern,
enabled: !isHidden,
),
onTapUp: makeTapUpCallback(context, legendEntry, legend));
Expand Down
13 changes: 7 additions & 6 deletions charts_flutter/lib/src/symbol_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SymbolRendererCanvas implements SymbolRendererBuilder {

@override
Widget build(BuildContext context,
{Color color, Size size, bool enabled = true}) {
{Color color, List<int> dashPattern, Size size, bool enabled = true}) {
if (!enabled) {
color = color.withOpacity(0.26);
}
Expand All @@ -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)));
}
}

Expand All @@ -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<int> dashPattern, Size size, bool enabled});

@override
void paint(common.ChartCanvas canvas, Rectangle<num> bounds,
Expand All @@ -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<int> dashPattern, Size size, bool enabled});
}

/// The Widget which fulfills the guts of [SymbolRendererCanvas] actually
Expand All @@ -83,8 +83,9 @@ class _SymbolCustomPaint extends CustomPainter {
final BuildContext context;
final common.SymbolRenderer symbolRenderer;
final Color color;
final List<int> dashPattern;

_SymbolCustomPaint(this.context, this.symbolRenderer, this.color);
_SymbolCustomPaint(this.context, this.symbolRenderer, this.color, this.dashPattern);

@override
void paint(Canvas canvas, Size size) {
Expand All @@ -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
Expand Down