Skip to content

Commit

Permalink
release of v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
juliansteenbakker committed May 15, 2024
1 parent 706bc8b commit b72135f
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 110 deletions.
2 changes: 1 addition & 1 deletion community_charts_common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.0.3
# 1.0.4
* Add a PointLabelDecorator to render a label for a point
* Enhance LinePointHighlighter to support callbacking the highlight points's info like position, datum and its corresponding seriers id
* Update intl package
Expand Down
3 changes: 2 additions & 1 deletion community_charts_common/lib/community_charts_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ export 'src/chart/scatter_plot/point_renderer_config.dart'
show PointRendererConfig;
export 'src/chart/scatter_plot/point_renderer_decorator.dart'
show PointRendererDecorator;
export 'src/chart/scatter_plot/point_label_decorator.dart';
export 'src/chart/scatter_plot/point_label_decorator.dart'
show PointLabelDecorator, PointLabelSpec;
export 'src/chart/scatter_plot/scatter_plot_chart.dart' show ScatterPlotChart;
export 'src/chart/scatter_plot/symbol_annotation_renderer.dart'
show SymbolAnnotationRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class LinePointHighlighter<D> implements ChartBehavior<D> {

// callback the caller with the selected point
//
final void Function(List<DatumDetails<D>>? selectedDetails)? onHighLightDatumUpdated;
final void Function(List<DatumDetails<D>>? selectedDetails)?
onHighLightDatumUpdated;

LinePointHighlighter(
{SelectionModelType? selectionModelType,
Expand Down Expand Up @@ -193,9 +194,10 @@ class LinePointHighlighter<D> implements ChartBehavior<D> {
void _updateViewData() {
_currentKeys.clear();

final allSelectedDatumDetails = _chart.getSelectedDatumDetails(selectionModelType);
final selectedDatumDetails = allSelectedDatumDetails
.where((element) => _seriesIds == null || _seriesIds!.contains(element.series?.id));
final allSelectedDatumDetails =
_chart.getSelectedDatumDetails(selectionModelType);
final selectedDatumDetails = allSelectedDatumDetails.where((element) =>
_seriesIds == null || _seriesIds!.contains(element.series?.id));

// Create a new map each time to ensure that we have it sorted in the
// selection model order. This preserves the "nearestDetail" ordering, so
Expand Down Expand Up @@ -285,7 +287,7 @@ class LinePointHighlighter<D> implements ChartBehavior<D> {

_seriesPointMap = newSeriesMap;
_view.seriesPointMap = _seriesPointMap;

onHighLightDatumUpdated?.call(allSelectedDatumDetails);
}

Expand Down
8 changes: 6 additions & 2 deletions community_charts_common/lib/src/chart/line/line_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ class LineRenderer<D> extends BaseCartesianRenderer<D> {

LineRenderer._internal({required String rendererId, required this.config})
: _pointRenderer = PointRenderer<D>(
config: PointRendererConfig<D>(radiusPx: config.radiusPx, symbolRenderer: config.symbolRenderer, pointRendererDecorators: config.pointRendererDecorators,)),
config: PointRendererConfig<D>(
radiusPx: config.radiusPx,
symbolRenderer: config.symbolRenderer,
pointRendererDecorators: config.pointRendererDecorators,
)),
super(
rendererId: rendererId,
layoutPaintOrder: config.layoutPaintOrder,
Expand Down Expand Up @@ -927,7 +931,7 @@ class LineRenderer<D> extends BaseCartesianRenderer<D> {
// creation time, since chart onInit is called after the chart is created.
_chart = chart;
}

@override
void set graphicsFactory(GraphicsFactory? graphicsFactory) {
super.graphicsFactory = graphicsFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import '../common/chart_canvas.dart';
import 'point_renderer.dart';
import 'point_renderer_decorator.dart';


class PointLabelSpec {
final String label;
final bool selected;
PointLabelSpec({required this.label, this.selected = false,});
PointLabelSpec({
required this.label,
this.selected = false,
});
}

typedef LabelCallback = PointLabelSpec Function(Object? datum);
Expand All @@ -42,14 +44,12 @@ class PointLabelDecorator<D> extends PointRendererDecorator<D> {
TextStyle? _labelStyle;
TextStyle? _selectedLabelStyle;


PointLabelDecorator({
this.labelStyleSpec,
this.selectedLabelStyleSpec,
required this.labelCallback,
this.horizontalPadding = 0,
this.verticalPadding = 0
});
PointLabelDecorator(
{this.labelStyleSpec,
this.selectedLabelStyleSpec,
required this.labelCallback,
this.horizontalPadding = 0,
this.verticalPadding = 0});

@override
bool get renderAbove => true;
Expand All @@ -58,14 +58,13 @@ class PointLabelDecorator<D> extends PointRendererDecorator<D> {
void decorate(PointRendererElement<D> pointElement, ChartCanvas canvas,
GraphicsFactory graphicsFactory,
{required Rectangle drawBounds,
required double animationPercent,
bool rtl = false}) {
required double animationPercent,
bool rtl = false}) {
// Only decorate the bars when animation is at 100%.
if (animationPercent != 1.0) {
return;
}


if (_labelStyle == null) {
_initLabelStyle(graphicsFactory);
}
Expand All @@ -80,21 +79,21 @@ class PointLabelDecorator<D> extends PointRendererDecorator<D> {
final labelY = point.y!.toInt() - verticalPadding;

canvas.drawText(labelElement, labelX, labelY);

}

void _initLabelStyle(GraphicsFactory graphicsFactory) {
_labelStyle = _textStyleFromSpec(graphicsFactory, labelStyleSpec);
_selectedLabelStyle =
selectedLabelStyleSpec != null ? _textStyleFromSpec(graphicsFactory, selectedLabelStyleSpec) : _labelStyle;
_selectedLabelStyle = selectedLabelStyleSpec != null
? _textStyleFromSpec(graphicsFactory, selectedLabelStyleSpec)
: _labelStyle;
}

TextStyle? _textStyleFromSpec(GraphicsFactory graphicsFactory, TextStyleSpec? spec) {
TextStyle? _textStyleFromSpec(
GraphicsFactory graphicsFactory, TextStyleSpec? spec) {
return graphicsFactory.createTextPaint()
..color = spec?.color ?? const Color(r: 0, g: 0, b: 0)
..fontFamily = spec?.fontFamily
..fontSize = spec?.fontSize ?? 12
..fontWeight = spec?.fontWeight ?? '400';
}

}
2 changes: 1 addition & 1 deletion community_charts_common/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: community_charts_common
version: 1.0.3
version: 1.0.4
description: A common library for charting packages. Forked from google/charts.
repository: https://github.com/juliansteenbakker/community_charts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class FakeCartesianRenderer extends BaseCartesianRenderer {
@override
DatumDetails addPositionToDetailsForSeriesDatum(
DatumDetails details, SeriesDatum seriesDatum) {
assert(details != null);
return details;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ void main() {
}

void _setupChart({Point<double> forPoint, bool isWithinRenderer}) {
if (isWithinRenderer != null) {
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
}
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
}

setUp(() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,10 @@ void main() {
bool isWithinRenderer,
List<DatumDetails<String>> respondWithDetails,
List<MutableSeries<String>> seriesList}) {
if (isWithinRenderer != null) {
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
}
if (respondWithDetails != null) {
when(_chart.getNearestDatumDetailPerSeries(forPoint, true))
.thenReturn(respondWithDetails);
}
if (seriesList != null) {
when(_chart.currentSeriesList).thenReturn(seriesList);
}
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
when(_chart.getNearestDatumDetailPerSeries(forPoint, true))
.thenReturn(respondWithDetails);
when(_chart.currentSeriesList).thenReturn(seriesList);
}

setUp(() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ void main() {
final seriesList = [series1, series2];
final selectionType = SelectionModelType.info;
final measureFormatter =
(num value) => 'measure ${value?.toStringAsFixed(0)}';
(num value) => 'measure ${value.toStringAsFixed(0)}';
final secondaryMeasureFormatter =
(num value) => 'secondary ${value?.toStringAsFixed(0)}';
(num value) => 'secondary ${value.toStringAsFixed(0)}';
final legend = SeriesLegend<String>(
selectionModelType: selectionType,
measureFormatter: measureFormatter,
Expand Down Expand Up @@ -391,7 +391,7 @@ void main() {
test('series legend - show measure sum when there is no selection', () {
final seriesList = [series1, series2];
final selectionType = SelectionModelType.info;
final measureFormatter = (num value) => '${value?.toStringAsFixed(0)}';
final measureFormatter = (num value) => '${value.toStringAsFixed(0)}';
final legend = SeriesLegend<String>(
selectionModelType: selectionType,
legendDefaultMeasure: LegendDefaultMeasure.sum,
Expand Down Expand Up @@ -424,7 +424,7 @@ void main() {
test('series legend - show measure average when there is no selection', () {
final seriesList = [series1, series2];
final selectionType = SelectionModelType.info;
final measureFormatter = (num value) => '${value?.toStringAsFixed(0)}';
final measureFormatter = (num value) => '${value.toStringAsFixed(0)}';
final legend = SeriesLegend<String>(
selectionModelType: selectionType,
legendDefaultMeasure: LegendDefaultMeasure.average,
Expand Down Expand Up @@ -457,7 +457,7 @@ void main() {
test('series legend - show first measure when there is no selection', () {
final seriesList = [series1, series2];
final selectionType = SelectionModelType.info;
final measureFormatter = (num value) => '${value?.toStringAsFixed(0)}';
final measureFormatter = (num value) => '${value.toStringAsFixed(0)}';
final legend = SeriesLegend<String>(
selectionModelType: selectionType,
legendDefaultMeasure: LegendDefaultMeasure.firstValue,
Expand Down Expand Up @@ -490,7 +490,7 @@ void main() {
test('series legend - show last measure when there is no selection', () {
final seriesList = [series1, series2];
final selectionType = SelectionModelType.info;
final measureFormatter = (num value) => '${value?.toStringAsFixed(0)}';
final measureFormatter = (num value) => '${value.toStringAsFixed(0)}';
final legend = SeriesLegend<String>(
selectionModelType: selectionType,
legendDefaultMeasure: LegendDefaultMeasure.lastValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,9 @@ void main() {
when(_chart.domainAxis).thenReturn(_domainAxis);
when(_chart.getMeasureAxis()).thenReturn(_measureAxis);

if (isWithinRenderer != null) {
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
}
if (respondWithDetails != null) {
when(_chart.getNearestDatumDetailPerSeries(forPoint, true))
.thenReturn(respondWithDetails);
}
when(_chart.pointWithinRenderer(forPoint)).thenReturn(isWithinRenderer);
when(_chart.getNearestDatumDetailPerSeries(forPoint, true))
.thenReturn(respondWithDetails);
}

setUp(() {
Expand Down
2 changes: 1 addition & 1 deletion community_charts_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.0.3
# 1.0.4
* Added UserManagedState variable to be passed down into the super constructor on NumericComboChart and OrdinalComboChart
* Add FontWeight support

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ import 'package:flutter/material.dart';
class ScatterPlotComboLineChart extends StatelessWidget {
final List<charts.Series<dynamic, num>> seriesList;
final bool animate;
List<LinearSales> selectedDomains = [];
late charts.PointRendererDecorator<num> pointCustomDecorator;

ScatterPlotComboLineChart(this.seriesList, {this.animate = false}): pointCustomDecorator = charts.PointLabelDecorator(
horizontalPadding: 6,
verticalPadding: 20,
selectedLabelStyleSpec: charts.TextStyleSpec(
color: charts.Color.fromHex(code: '#FF9560'),
fontWeight: '500',
fontSize: 14,
),
labelCallback: (domain) {
if (domain is LinearSales?) {
// final selected = selectedDomains.contains(domain);
return charts.PointLabelSpec(
label: domain?.sales.toString() ?? '',
selected: false,
);
}
return charts.PointLabelSpec(
label: '',
selected: false,
);
});

final List<LinearSales> selectedDomains = [];
late final charts.PointRendererDecorator<num> pointCustomDecorator;

ScatterPlotComboLineChart(this.seriesList, {this.animate = false})
: pointCustomDecorator = charts.PointLabelDecorator(
horizontalPadding: 6,
verticalPadding: 20,
selectedLabelStyleSpec: charts.TextStyleSpec(
color: charts.Color.fromHex(code: '#FF9560'),
fontWeight: '500',
fontSize: 14,
),
labelCallback: (domain) {
if (domain is LinearSales?) {
// final selected = selectedDomains.contains(domain);
return charts.PointLabelSpec(
label: domain?.sales.toString() ?? '',
selected: false,
);
}
return charts.PointLabelSpec(
label: '',
selected: false,
);
});

/// Creates a [ScatterPlotChart] with sample data and no transition.
factory ScatterPlotComboLineChart.withSampleData() {
Expand Down Expand Up @@ -131,8 +131,6 @@ class ScatterPlotComboLineChart extends StatelessWidget {
}
// EXCLUDE_FROM_GALLERY_DOCS_END



@override
Widget build(BuildContext context) {
return new charts.ScatterPlotChart(seriesList,
Expand All @@ -142,11 +140,10 @@ class ScatterPlotComboLineChart extends StatelessWidget {
//
// This is the default configuration, but is shown here for
// illustration.
defaultRenderer: new charts.PointRendererConfig(
pointRendererDecorators: [
pointCustomDecorator,
]
),
defaultRenderer:
new charts.PointRendererConfig(pointRendererDecorators: [
pointCustomDecorator,
]),
// Custom renderer configuration for the line series.
customSeriesRenderers: [
new charts.LineRendererConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class HighlighterPointInfo<T> {
final T? datum;
final String seriesId;

HighlighterPointInfo({this.point, this.datum, required this.seriesId,});
HighlighterPointInfo({
this.point,
this.datum,
required this.seriesId,
});
}

/// Chart behavior that monitors the specified [SelectionModel] and darkens the
Expand Down Expand Up @@ -81,7 +85,8 @@ class LinePointHighlighter<D, T extends Object> extends ChartBehavior<D> {
final common.SymbolRenderer? symbolRenderer;

final List<String>? seriesIds;
final void Function(List<HighlighterPointInfo<T>>? selectedDetails)? onHighLightDatumUpdated;
final void Function(List<HighlighterPointInfo<T>>? selectedDetails)?
onHighLightDatumUpdated;

LinePointHighlighter(
{this.selectionModelType,
Expand All @@ -107,7 +112,14 @@ class LinePointHighlighter<D, T extends Object> extends ChartBehavior<D> {
drawFollowLinesAcrossChart: drawFollowLinesAcrossChart,
symbolRenderer: symbolRenderer,
seriesIds: seriesIds,
onHighLightDatumUpdated: (selectedDetails) => onHighLightDatumUpdated?.call(selectedDetails?.map((e) => HighlighterPointInfo<T>(seriesId: e.series?.id ?? '', point: e.chartPosition, datum: e.datum,)).toList()),
onHighLightDatumUpdated: (selectedDetails) =>
onHighLightDatumUpdated?.call(selectedDetails
?.map((e) => HighlighterPointInfo<T>(
seriesId: e.series?.id ?? '',
point: e.chartPosition,
datum: e.datum,
))
.toList()),
);

@override
Expand Down
Loading

0 comments on commit b72135f

Please sign in to comment.