From 9977517bbea3c988a7362c0b383ee472e470b228 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Wed, 18 Sep 2024 05:35:09 +1000 Subject: [PATCH 1/9] dart fix apply --- charts_flutter/example/analysis_options.yaml | 31 +-- .../example/lib/a11y/a11y_gallery.dart | 14 +- .../a11y/domain_a11y_explore_bar_chart.dart | 120 ++++----- charts_flutter/example/lib/app_config.dart | 12 +- .../example/lib/axes/axes_gallery.dart | 137 +++++----- .../example/lib/axes/bar_secondary_axis.dart | 121 ++++----- .../lib/axes/bar_secondary_axis_only.dart | 74 +++-- .../lib/axes/custom_axis_tick_formatters.dart | 143 +++++----- .../lib/axes/custom_font_size_and_color.dart | 137 +++++----- .../lib/axes/custom_measure_tick_count.dart | 107 ++++---- .../lib/axes/flipped_vertical_axis.dart | 73 +++-- .../lib/axes/gridline_dash_pattern.dart | 111 ++++---- .../axes/hidden_ticks_and_labels_axis.dart | 91 +++---- .../axes/horizontal_bar_secondary_axis.dart | 126 +++++---- .../lib/axes/integer_only_measure_axis.dart | 97 ++++--- .../example/lib/axes/line_disjoint_axis.dart | 189 +++++++------ .../axes/measure_axis_label_alignment.dart | 62 ++--- .../lib/axes/nonzero_bound_measure_axis.dart | 95 ++++--- .../lib/axes/numeric_initial_viewport.dart | 101 ++++--- .../lib/axes/ordinal_initial_viewport.dart | 125 +++++---- .../lib/axes/short_tick_length_axis.dart | 62 ++--- .../lib/axes/statically_provided_ticks.dart | 82 +++--- .../example/lib/bar_chart/bar_gallery.dart | 172 ++++++------ .../lib/bar_chart/custom_rounded_bars.dart | 69 +++-- .../example/lib/bar_chart/grouped.dart | 112 ++++---- .../lib/bar_chart/grouped_fill_color.dart | 116 ++++---- .../bar_chart/grouped_single_target_line.dart | 163 ++++++----- .../lib/bar_chart/grouped_stacked.dart | 196 +++++++------- .../grouped_stacked_weight_pattern.dart | 198 +++++++------- .../lib/bar_chart/grouped_target_line.dart | 203 +++++++------- .../example/lib/bar_chart/horizontal.dart | 63 +++-- .../lib/bar_chart/horizontal_bar_label.dart | 73 +++-- .../horizontal_bar_label_custom.dart | 95 ++++--- .../horizontal_pattern_forward_hatch.dart | 118 ++++---- .../lib/bar_chart/pattern_forward_hatch.dart | 116 ++++---- .../example/lib/bar_chart/simple.dart | 65 +++-- .../example/lib/bar_chart/spark_bar.dart | 100 ++++--- .../example/lib/bar_chart/stacked.dart | 114 ++++---- .../lib/bar_chart/stacked_fill_color.dart | 116 ++++---- .../lib/bar_chart/stacked_horizontal.dart | 112 ++++---- .../lib/bar_chart/stacked_target_line.dart | 204 +++++++------- .../lib/bar_chart/vertical_bar_label.dart | 73 +++-- .../lib/behaviors/behaviors_gallery.dart | 119 ++++---- .../example/lib/behaviors/chart_title.dart | 81 +++--- .../lib/behaviors/initial_hint_animation.dart | 131 +++++---- .../lib/behaviors/initial_selection.dart | 71 +++-- .../lib/behaviors/percent_of_domain.dart | 120 ++++----- .../percent_of_domain_by_category.dart | 202 +++++++------- .../lib/behaviors/percent_of_series.dart | 80 +++--- .../behaviors/selection_bar_highlight.dart | 62 ++--- .../behaviors/selection_callback_example.dart | 144 +++++----- .../behaviors/selection_line_highlight.dart | 69 +++-- ...selection_line_highlight_custom_shape.dart | 69 +++-- .../selection_scatter_plot_highlight.dart | 169 ++++++------ .../lib/behaviors/selection_user_managed.dart | 92 +++---- .../example/lib/behaviors/slider.dart | 102 ++++--- .../sliding_viewport_on_selection.dart | 125 +++++---- .../lib/combo_chart/combo_gallery.dart | 46 ++-- .../lib/combo_chart/date_time_line_point.dart | 127 +++++---- .../lib/combo_chart/numeric_line_bar.dart | 129 +++++---- .../lib/combo_chart/numeric_line_point.dart | 129 +++++---- .../lib/combo_chart/ordinal_bar_line.dart | 134 +++++---- .../lib/combo_chart/scatter_plot_line.dart | 145 +++++----- .../example/lib/gallery_scaffold.dart | 44 ++- charts_flutter/example/lib/home.dart | 69 ++--- .../example/lib/i18n/i18n_gallery.dart | 38 ++- .../example/lib/i18n/rtl_bar_chart.dart | 68 +++-- .../example/lib/i18n/rtl_line_chart.dart | 68 +++-- .../example/lib/i18n/rtl_line_segments.dart | 194 +++++++------ .../example/lib/i18n/rtl_series_legend.dart | 152 ++++++----- .../lib/legends/datum_legend_options.dart | 68 +++-- .../legends/datum_legend_with_measures.dart | 72 +++-- .../legends/default_hidden_series_legend.dart | 146 +++++----- .../lib/legends/legend_custom_symbol.dart | 159 ++++++----- .../example/lib/legends/legends_gallery.dart | 56 ++-- .../lib/legends/series_legend_options.dart | 148 +++++----- .../legends/series_legend_with_measures.dart | 156 +++++------ .../lib/legends/simple_datum_legend.dart | 62 ++--- .../lib/legends/simple_series_legend.dart | 142 +++++----- .../lib/line_chart/animation_zoom.dart | 63 ++--- .../example/lib/line_chart/area_and_line.dart | 99 ++++--- .../example/lib/line_chart/dash_pattern.dart | 129 +++++---- .../lib/line_chart/line_annotation.dart | 85 +++--- .../example/lib/line_chart/line_gallery.dart | 110 ++++---- .../example/lib/line_chart/points.dart | 67 +++-- .../lib/line_chart/range_annotation.dart | 85 +++--- .../line_chart/range_annotation_margin.dart | 93 +++---- .../example/lib/line_chart/segments.dart | 193 +++++++------ .../example/lib/line_chart/simple.dart | 65 +++-- .../example/lib/line_chart/simple_nulls.dart | 157 ++++++----- .../example/lib/line_chart/stacked_area.dart | 129 +++++---- .../line_chart/stacked_area_custom_color.dart | 129 +++++---- .../lib/line_chart/stacked_area_nulls.dart | 161 ++++++----- charts_flutter/example/lib/main.dart | 16 +- .../example/lib/pie_chart/auto_label.dart | 73 +++-- .../example/lib/pie_chart/donut.dart | 67 +++-- .../example/lib/pie_chart/gauge.dart | 69 +++-- .../example/lib/pie_chart/outside_label.dart | 77 +++--- .../example/lib/pie_chart/partial_pie.dart | 31 ++- .../example/lib/pie_chart/pie_gallery.dart | 28 +- .../example/lib/pie_chart/simple.dart | 65 +++-- .../scatter_plot_chart/animation_zoom.dart | 93 +++---- .../scatter_plot_chart/bucketing_axis.dart | 255 +++++++++--------- .../scatter_plot_chart/comparison_points.dart | 105 ++++---- .../scatter_plot_gallery.dart | 42 ++- .../lib/scatter_plot_chart/shapes.dart | 162 ++++++----- .../lib/scatter_plot_chart/simple.dart | 111 ++++---- .../confidence_interval.dart | 73 +++-- .../time_series_chart/end_points_axis.dart | 67 +++-- .../time_series_chart/line_annotation.dart | 81 +++--- .../time_series_chart/range_annotation.dart | 73 +++-- .../range_annotation_margin.dart | 97 ++++--- .../example/lib/time_series_chart/simple.dart | 65 +++-- .../time_series_chart/symbol_annotation.dart | 201 +++++++------- .../time_series_gallery.dart | 71 +++-- .../time_series_chart/with_bar_renderer.dart | 137 +++++----- charts_flutter/example/pubspec.yaml | 2 + 117 files changed, 5835 insertions(+), 6367 deletions(-) diff --git a/charts_flutter/example/analysis_options.yaml b/charts_flutter/example/analysis_options.yaml index 0d2902135..bc7a72fda 100644 --- a/charts_flutter/example/analysis_options.yaml +++ b/charts_flutter/example/analysis_options.yaml @@ -1,28 +1,7 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml +include: package:austerity/analysis_options.yaml -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at https://dart.dev/lints. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +analyzer: + errors: + comment_references: warning + \ No newline at end of file diff --git a/charts_flutter/example/lib/a11y/a11y_gallery.dart b/charts_flutter/example/lib/a11y/a11y_gallery.dart index c5d4b5f71..51f8408e7 100644 --- a/charts_flutter/example/lib/a11y/a11y_gallery.dart +++ b/charts_flutter/example/lib/a11y/a11y_gallery.dart @@ -12,18 +12,16 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/a11y/domain_a11y_explore_bar_chart.dart'; +import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'domain_a11y_explore_bar_chart.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.accessibility), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.accessibility), title: 'Screen reader enabled bar chart', subtitle: 'Requires TalkBack or Voiceover turned on to work. ' 'Bar chart with domain selection explore mode behavior.', - childBuilder: () => new DomainA11yExploreBarChart.withRandomData(), + childBuilder: DomainA11yExploreBarChart.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart index c1af8a5d6..62f3e36c5 100644 --- a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart +++ b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart @@ -22,8 +22,8 @@ /// OS screen reader is enabled, the node that is being read out loud will be /// surrounded by a rectangle. /// -/// When [DomainA11yExploreBehavior] is added to the chart, the chart will -/// listen for the gesture that triggers "explore mode". +/// When [charts.DomainA11yExploreBehavior] is added to the chart, the chart +/// will listen for the gesture that triggers "explore mode". /// "Explore mode" creates semantic nodes for each domain value in the chart /// with a description (customizable, defaults to domain value) and a bounding /// box that surrounds the domain. @@ -31,74 +31,76 @@ /// These semantic node descriptions are read out loud by the OS screen reader /// when the user taps within the bounding box, or when the user cycles through /// the screen's elements (such as swiping left and right). +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class DomainA11yExploreBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - - DomainA11yExploreBarChart(this.seriesList, {this.animate = false}); - - /// Creates a [BarChart] with sample data and no transition. - factory DomainA11yExploreBarChart.withSampleData() { - return new DomainA11yExploreBarChart( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + const DomainA11yExploreBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); + + /// Creates a [charts.BarChart] with sample data and no transition. + factory DomainA11yExploreBarChart.withSampleData() => + DomainA11yExploreBarChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DomainA11yExploreBarChart.withRandomData() { - return new DomainA11yExploreBarChart(_createRandomData()); - } + factory DomainA11yExploreBarChart.withRandomData() => + DomainA11yExploreBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final mobileData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tabletData = [ // Purposely missing data to show that only measures that are available // are vocalized. - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Mobile Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileData, ), - new charts.Series( + charts.Series( id: 'Tablet Sales', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletData, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END /// An example of how to generate a customized vocalization for - /// [DomainA11yExploreBehavior] from a list of [SeriesDatum]s. + /// [charts.DomainA11yExploreBehavior] from a list of [charts.SeriesDatum]s. /// /// The list of series datums is for one domain. /// @@ -106,13 +108,13 @@ class DomainA11yExploreBarChart extends StatelessWidget { /// domain, it vocalizes the series display name and the measure and a /// description of that measure. String vocalizeDomainAndMeasures(List seriesDatums) { - final buffer = new StringBuffer(); + final buffer = StringBuffer().. // The datum's type in this case is [OrdinalSales]. // So we can access year and sales information here. - buffer.write(seriesDatums.first.datum.year); + write(seriesDatums.first.datum.year); - for (charts.SeriesDatum seriesDatum in seriesDatums) { + for (final seriesDatum in seriesDatums) { final series = seriesDatum.series; final datum = seriesDatum.datum; @@ -124,14 +126,13 @@ class DomainA11yExploreBarChart extends StatelessWidget { } @override - Widget build(BuildContext context) { - return new Semantics( + Widget build(BuildContext context) => Semantics( // Describe your chart label: 'Yearly sales bar chart', // Optionally provide a hint for the user to know how to trigger // explore mode. hint: 'Press and hold to enable explore', - child: new charts.BarChart( + child: charts.BarChart( seriesList, animate: animate, // To prevent conflict with the select nearest behavior that uses the @@ -140,7 +141,7 @@ class DomainA11yExploreBarChart extends StatelessWidget { // with the application. defaultInteractions: !MediaQuery.of(context).accessibleNavigation, behaviors: [ - new charts.DomainA11yExploreBehavior( + charts.DomainA11yExploreBehavior( // Callback for generating the message that is vocalized. // An example of how to use is in [vocalizeDomainAndMeasures]. // If none is set, the default only vocalizes the domain value. @@ -160,56 +161,55 @@ class DomainA11yExploreBarChart extends StatelessWidget { // minimum width of the screen reader bounding box. The bounding // box width is calculated based on the domain axis step size. // Minimum width will be used if the step size is smaller. - minimumWidth: 1.0, + minimumWidth: 1, ), // Optionally include domain highlighter as a behavior. // This behavior is included in this example to show that when an // a11y node has focus, the chart's internal selection model is // also updated. - new charts.DomainHighlighter(charts.SelectionModelType.info), + charts.DomainHighlighter(), ], - )); - } + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { final mobileData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletData = [ // Purposely missing data to show that only measures that are available // are vocalized. - new OrdinalSales('2016', 25), - new OrdinalSales('2017', 50), + OrdinalSales('2016', 25), + OrdinalSales('2017', 50), ]; return [ - new charts.Series( + charts.Series( id: 'Mobile Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileData, ), - new charts.Series( + charts.Series( id: 'Tablet Sales', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletData, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/app_config.dart b/charts_flutter/example/lib/app_config.dart index 730c36477..0eee0d66f 100644 --- a/charts_flutter/example/lib/app_config.dart +++ b/charts_flutter/example/lib/app_config.dart @@ -17,25 +17,23 @@ import 'package:flutter/material.dart'; /// A particular configuration of the app. class AppConfig { - final String appName; - final String appLink; - final ThemeData theme; AppConfig({ required this.appName, required this.appLink, required this.theme, }); + final String appName; + final String appLink; + final ThemeData theme; } /// The default configuration of the app. -AppConfig get defaultConfig { - return new AppConfig( +AppConfig get defaultConfig => AppConfig( appName: 'Charts Gallery', appLink: '', - theme: new ThemeData( + theme: ThemeData( brightness: Brightness.light, primarySwatch: Colors.lightBlue, ), ); -} diff --git a/charts_flutter/example/lib/axes/axes_gallery.dart b/charts_flutter/example/lib/axes/axes_gallery.dart index f192e2c7e..4797046ee 100644 --- a/charts_flutter/example/lib/axes/axes_gallery.dart +++ b/charts_flutter/example/lib/axes/axes_gallery.dart @@ -13,125 +13,122 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/axes/bar_secondary_axis.dart'; +import 'package:example/axes/bar_secondary_axis_only.dart'; +import 'package:example/axes/custom_axis_tick_formatters.dart'; +import 'package:example/axes/custom_font_size_and_color.dart'; +import 'package:example/axes/custom_measure_tick_count.dart'; +import 'package:example/axes/gridline_dash_pattern.dart'; +import 'package:example/axes/hidden_ticks_and_labels_axis.dart'; +import 'package:example/axes/horizontal_bar_secondary_axis.dart'; +import 'package:example/axes/integer_only_measure_axis.dart'; +import 'package:example/axes/line_disjoint_axis.dart'; +import 'package:example/axes/measure_axis_label_alignment.dart'; +import 'package:example/axes/nonzero_bound_measure_axis.dart'; +import 'package:example/axes/numeric_initial_viewport.dart'; +import 'package:example/axes/ordinal_initial_viewport.dart'; +import 'package:example/axes/short_tick_length_axis.dart'; +import 'package:example/axes/statically_provided_ticks.dart'; +import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'bar_secondary_axis.dart'; -import 'bar_secondary_axis_only.dart'; -import 'custom_axis_tick_formatters.dart'; -import 'custom_font_size_and_color.dart'; -import 'custom_measure_tick_count.dart'; -import 'gridline_dash_pattern.dart'; -import 'hidden_ticks_and_labels_axis.dart'; -import 'horizontal_bar_secondary_axis.dart'; -import 'integer_only_measure_axis.dart'; -import 'line_disjoint_axis.dart'; -import 'measure_axis_label_alignment.dart'; -import 'numeric_initial_viewport.dart'; -import 'nonzero_bound_measure_axis.dart'; -import 'ordinal_initial_viewport.dart'; -import 'short_tick_length_axis.dart'; -import 'statically_provided_ticks.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Bar chart with Secondary Measure Axis', subtitle: 'Bar chart with a series using a secondary measure axis', - childBuilder: () => new BarChartWithSecondaryAxis.withRandomData(), + childBuilder: BarChartWithSecondaryAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Bar chart with Secondary Measure Axis only', subtitle: 'Bar chart with both series using secondary measure axis', - childBuilder: () => new BarChartWithSecondaryAxisOnly.withRandomData(), + childBuilder: BarChartWithSecondaryAxisOnly.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Horizontal bar chart with Secondary Measure Axis', subtitle: 'Horizontal Bar chart with a series using secondary measure axis', - childBuilder: () => - new HorizontalBarChartWithSecondaryAxis.withRandomData(), + childBuilder: HorizontalBarChartWithSecondaryAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Short Ticks Axis', subtitle: 'Bar chart with the primary measure axis having short ticks', - childBuilder: () => new ShortTickLengthAxis.withRandomData(), + childBuilder: ShortTickLengthAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Custom Axis Fonts', subtitle: 'Bar chart with custom axis font size and color', - childBuilder: () => new CustomFontSizeAndColor.withRandomData(), + childBuilder: CustomFontSizeAndColor.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Label Alignment Axis', subtitle: 'Bar chart with custom measure axis label alignments', - childBuilder: () => new MeasureAxisLabelAlignment.withRandomData(), + childBuilder: MeasureAxisLabelAlignment.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'No Axis', subtitle: 'Bar chart with only the axis line drawn', - childBuilder: () => new HiddenTicksAndLabelsAxis.withRandomData(), + childBuilder: HiddenTicksAndLabelsAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Statically Provided Ticks', subtitle: 'Bar chart with statically provided ticks', - childBuilder: () => new StaticallyProvidedTicks.withRandomData(), + childBuilder: StaticallyProvidedTicks.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Custom Formatter', subtitle: 'Timeseries with custom domain and measure tick formatters', - childBuilder: () => new CustomAxisTickFormatters.withRandomData(), + childBuilder: CustomAxisTickFormatters.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Custom Tick Count', subtitle: 'Timeseries with custom measure axis tick count', - childBuilder: () => new CustomMeasureTickCount.withRandomData(), + childBuilder: CustomMeasureTickCount.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Integer Measure Ticks', subtitle: 'Timeseries with only whole number measure axis ticks', - childBuilder: () => new IntegerOnlyMeasureAxis.withRandomData(), + childBuilder: IntegerOnlyMeasureAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Non-zero bound Axis', subtitle: 'Timeseries with measure axis that does not include zero', - childBuilder: () => new NonzeroBoundMeasureAxis.withRandomData(), + childBuilder: NonzeroBoundMeasureAxis.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Ordinal axis with initial viewport', subtitle: 'Single series with initial viewport', - childBuilder: () => new OrdinalInitialViewport.withRandomData(), + childBuilder: OrdinalInitialViewport.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Numeric axis with initial viewport', subtitle: 'Initial viewport is set to a subset of the data', - childBuilder: () => new NumericInitialViewport.withRandomData(), + childBuilder: NumericInitialViewport.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Gridline dash pattern', subtitle: 'Timeseries with measure gridlines that have a dash pattern', - childBuilder: () => new GridlineDashPattern.withRandomData(), + childBuilder: GridlineDashPattern.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Disjoint Measure Axes', subtitle: 'Line chart with disjoint measure axes', - childBuilder: () => new DisjointMeasureAxisLineChart.withRandomData(), + childBuilder: DisjointMeasureAxisLineChart.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/axes/bar_secondary_axis.dart b/charts_flutter/example/lib/axes/bar_secondary_axis.dart index bf99cfe2e..9bb057dd0 100644 --- a/charts_flutter/example/lib/axes/bar_secondary_axis.dart +++ b/charts_flutter/example/lib/axes/bar_secondary_axis.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -35,59 +37,55 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: primary and secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class BarChartWithSecondaryAxis extends StatelessWidget { - static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; - final List> seriesList; - final bool animate; + const BarChartWithSecondaryAxis(this.seriesList, + {super.key, this.animate = false}); - BarChartWithSecondaryAxis(this.seriesList, {this.animate = false}); - - factory BarChartWithSecondaryAxis.withSampleData() { - return new BarChartWithSecondaryAxis( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory BarChartWithSecondaryAxis.withSampleData() => + BarChartWithSecondaryAxis( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory BarChartWithSecondaryAxis.withRandomData() { - return new BarChartWithSecondaryAxis(_createRandomData()); - } + factory BarChartWithSecondaryAxis.withRandomData() => + BarChartWithSecondaryAxis(_createRandomData()); + static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; final losAngelesSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), - new charts.Series( + charts.Series( id: 'Los Angeles Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: losAngelesSalesData, - )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId) + )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId), // Set the 'Los Angeles Revenue' series to use the secondary measure axis. // All series that have this set will use the secondary measure axis. // All other series will use the primary measure axis. @@ -96,52 +94,52 @@ class BarChartWithSecondaryAxis extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // It is important when using both primary and secondary axes to choose - // the same number of ticks for both sides to get the gridlines to line - // up. - primaryMeasureAxis: new charts.NumericAxisSpec( + Widget build(BuildContext context) => charts.BarChart( + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // It is important when using both primary and secondary axes to choose + // the same number of ticks for both sides to get the gridlines to line + // up. + primaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: - new charts.BasicNumericTickProviderSpec(desiredTickCount: 3)), - secondaryMeasureAxis: new charts.NumericAxisSpec( + charts.BasicNumericTickProviderSpec(desiredTickCount: 3), + ), + secondaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: - new charts.BasicNumericTickProviderSpec(desiredTickCount: 3)), - ); - } + charts.BasicNumericTickProviderSpec(desiredTickCount: 3), + ), + ); /// Create series list with multiple series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; final losAngelesSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), - new charts.Series( + charts.Series( id: 'Los Angeles Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: losAngelesSalesData, - )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId) + )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId), // Set the 'Los Angeles Revenue' series to use the secondary measure axis. // All series that have this set will use the secondary measure axis. // All other series will use the primary measure axis. @@ -151,8 +149,7 @@ class BarChartWithSecondaryAxis extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/axes/bar_secondary_axis_only.dart b/charts_flutter/example/lib/axes/bar_secondary_axis_only.dart index 04f277830..de17aa4aa 100644 --- a/charts_flutter/example/lib/axes/bar_secondary_axis_only.dart +++ b/charts_flutter/example/lib/axes/bar_secondary_axis_only.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -29,44 +31,43 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class BarChartWithSecondaryAxisOnly extends StatelessWidget { - static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; - final List> seriesList; - final bool animate; + const BarChartWithSecondaryAxisOnly( + this.seriesList, { + super.key, + this.animate = false, + }); - BarChartWithSecondaryAxisOnly(this.seriesList, {this.animate = false}); - - factory BarChartWithSecondaryAxisOnly.withSampleData() { - return new BarChartWithSecondaryAxisOnly( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory BarChartWithSecondaryAxisOnly.withSampleData() => + BarChartWithSecondaryAxisOnly( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory BarChartWithSecondaryAxisOnly.withRandomData() { - return new BarChartWithSecondaryAxisOnly(_createRandomData()); - } + factory BarChartWithSecondaryAxisOnly.withRandomData() => + BarChartWithSecondaryAxisOnly(_createRandomData()); + static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ) // Set series to use the secondary measure axis. @@ -76,27 +77,25 @@ class BarChartWithSecondaryAxisOnly extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( - seriesList, - animate: animate, - ); - } + Widget build(BuildContext context) => charts.BarChart( + seriesList, + animate: animate, + ); /// Create series list with multiple series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 500), - new OrdinalSales('2015', 2500), - new OrdinalSales('2016', 1000), - new OrdinalSales('2017', 7500), + OrdinalSales('2014', 500), + OrdinalSales('2015', 2500), + OrdinalSales('2016', 1000), + OrdinalSales('2017', 7500), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ) // Set series to use the secondary measure axis. @@ -107,8 +106,7 @@ class BarChartWithSecondaryAxisOnly extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/axes/custom_axis_tick_formatters.dart b/charts_flutter/example/lib/axes/custom_axis_tick_formatters.dart index 2e76e9220..be1189892 100644 --- a/charts_flutter/example/lib/axes/custom_axis_tick_formatters.dart +++ b/charts_flutter/example/lib/axes/custom_axis_tick_formatters.dart @@ -14,61 +14,62 @@ // limitations under the License. /// Example of timeseries chart with custom measure and domain formatters. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; -// EXCLUDE_FROM_GALLERY_DOCS_END -import 'package:nimble_charts/flutter.dart' as charts; + import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; +// EXCLUDE_FROM_GALLERY_DOCS_END +import 'package:nimble_charts/flutter.dart' as charts; class CustomAxisTickFormatters extends StatelessWidget { - final List> seriesList; - final bool animate; + const CustomAxisTickFormatters( + this.seriesList, { + super.key, + this.animate = false, + }); - CustomAxisTickFormatters(this.seriesList, {this.animate = false}); - - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory CustomAxisTickFormatters.withSampleData() { - return new CustomAxisTickFormatters( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory CustomAxisTickFormatters.withSampleData() => CustomAxisTickFormatters( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory CustomAxisTickFormatters.withRandomData() { - return new CustomAxisTickFormatters(_createRandomData()); - } + factory CustomAxisTickFormatters.withRandomData() => + CustomAxisTickFormatters(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new MyRow(new DateTime(2017, 9, 25), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 26), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 27), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 28), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 29), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 30), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 01), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 02), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 03), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 04), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 05), random.nextInt(100)), + MyRow(DateTime(2017, 9, 25), random.nextInt(100)), + MyRow(DateTime(2017, 9, 26), random.nextInt(100)), + MyRow(DateTime(2017, 9, 27), random.nextInt(100)), + MyRow(DateTime(2017, 9, 28), random.nextInt(100)), + MyRow(DateTime(2017, 9, 29), random.nextInt(100)), + MyRow(DateTime(2017, 9, 30), random.nextInt(100)), + MyRow(DateTime(2017, 10), random.nextInt(100)), + MyRow(DateTime(2017, 10, 02), random.nextInt(100)), + MyRow(DateTime(2017, 10, 03), random.nextInt(100)), + MyRow(DateTime(2017, 10, 04), random.nextInt(100)), + MyRow(DateTime(2017, 10, 05), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -79,8 +80,9 @@ class CustomAxisTickFormatters extends StatelessWidget { /// /// This is what is used in the [NumericAxisSpec] below. final simpleCurrencyFormatter = - new charts.BasicNumericTickFormatterSpec.fromNumberFormat( - new NumberFormat.compactSimpleCurrency()); + charts.BasicNumericTickFormatterSpec.fromNumberFormat( + NumberFormat.compactSimpleCurrency(), + ); /// Formatter for numeric ticks that uses the callback provided. /// @@ -91,54 +93,61 @@ class CustomAxisTickFormatters extends StatelessWidget { // final customTickFormatter = // charts.BasicNumericTickFormatterSpec((num value) => 'MyValue: $value'); - return new charts.TimeSeriesChart(seriesList, - animate: animate, - // Sets up a currency formatter for the measure axis. - primaryMeasureAxis: new charts.NumericAxisSpec( - tickFormatterSpec: simpleCurrencyFormatter), - - /// Customizes the date tick formatter. It will print the day of month - /// as the default format, but include the month and year if it - /// transitions to a new month. - /// - /// minute, hour, day, month, and year are all provided by default and - /// you can override them following this pattern. - domainAxis: new charts.DateTimeAxisSpec( - tickFormatterSpec: new charts.AutoDateTimeTickFormatterSpec( - day: new charts.TimeFormatterSpec( - format: 'd', transitionFormat: 'MM/dd/yyyy')))); + return charts.TimeSeriesChart( + seriesList, + animate: animate, + // Sets up a currency formatter for the measure axis. + primaryMeasureAxis: charts.NumericAxisSpec( + tickFormatterSpec: simpleCurrencyFormatter, + ), + + /// Customizes the date tick formatter. It will print the day of month + /// as the default format, but include the month and year if it + /// transitions to a new month. + /// + /// minute, hour, day, month, and year are all provided by default and + /// you can override them following this pattern. + domainAxis: const charts.DateTimeAxisSpec( + tickFormatterSpec: charts.AutoDateTimeTickFormatterSpec( + day: charts.TimeFormatterSpec( + format: 'd', + transitionFormat: 'MM/dd/yyyy', + ), + ), + ), + ); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new MyRow(new DateTime(2017, 9, 25), 6), - new MyRow(new DateTime(2017, 9, 26), 8), - new MyRow(new DateTime(2017, 9, 27), 6), - new MyRow(new DateTime(2017, 9, 28), 9), - new MyRow(new DateTime(2017, 9, 29), 11), - new MyRow(new DateTime(2017, 9, 30), 15), - new MyRow(new DateTime(2017, 10, 01), 25), - new MyRow(new DateTime(2017, 10, 02), 33), - new MyRow(new DateTime(2017, 10, 03), 27), - new MyRow(new DateTime(2017, 10, 04), 31), - new MyRow(new DateTime(2017, 10, 05), 23), + MyRow(DateTime(2017, 9, 25), 6), + MyRow(DateTime(2017, 9, 26), 8), + MyRow(DateTime(2017, 9, 27), 6), + MyRow(DateTime(2017, 9, 28), 9), + MyRow(DateTime(2017, 9, 29), 11), + MyRow(DateTime(2017, 9, 30), 15), + MyRow(DateTime(2017, 10), 25), + MyRow(DateTime(2017, 10, 02), 33), + MyRow(DateTime(2017, 10, 03), 27), + MyRow(DateTime(2017, 10, 04), 31), + MyRow(DateTime(2017, 10, 05), 23), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } } /// Sample time series data type. class MyRow { + MyRow(this.timeStamp, this.cost); final DateTime timeStamp; final int cost; - MyRow(this.timeStamp, this.cost); } diff --git a/charts_flutter/example/lib/axes/custom_font_size_and_color.dart b/charts_flutter/example/lib/axes/custom_font_size_and_color.dart index bf18b8104..49180ad66 100644 --- a/charts_flutter/example/lib/axes/custom_font_size_and_color.dart +++ b/charts_flutter/example/lib/axes/custom_font_size_and_color.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Custom Font Style Example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -26,43 +28,41 @@ import 'package:nimble_charts/flutter.dart' as charts; /// There are many axis styling options in the SmallTickRenderer allowing you /// to customize the font, tick lengths, and offsets. class CustomFontSizeAndColor extends StatelessWidget { - final List> seriesList; - final bool animate; + const CustomFontSizeAndColor( + this.seriesList, { + super.key, + this.animate = false, + }); - CustomFontSizeAndColor(this.seriesList, {this.animate = false}); - - factory CustomFontSizeAndColor.withSampleData() { - return new CustomFontSizeAndColor( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory CustomFontSizeAndColor.withSampleData() => CustomFontSizeAndColor( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory CustomFontSizeAndColor.withRandomData() { - return new CustomFontSizeAndColor(_createRandomData()); - } + factory CustomFontSizeAndColor.withRandomData() => + CustomFontSizeAndColor(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -70,57 +70,61 @@ class CustomFontSizeAndColor extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( - seriesList, - animate: animate, - - /// Assign a custom style for the domain axis. - /// - /// This is an OrdinalAxisSpec to match up with BarChart's default - /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for - /// other charts). - domainAxis: new charts.OrdinalAxisSpec( - renderSpec: new charts.SmallTickRendererSpec( - - // Tick and Label styling here. - labelStyle: new charts.TextStyleSpec( - fontSize: 18, // size in Pts. - color: charts.MaterialPalette.black), - - // Change the line colors to match text color. - lineStyle: new charts.LineStyleSpec( - color: charts.MaterialPalette.black))), - - /// Assign a custom style for the measure axis. - primaryMeasureAxis: new charts.NumericAxisSpec( - renderSpec: new charts.GridlineRendererSpec( - - // Tick and Label styling here. - labelStyle: new charts.TextStyleSpec( - fontSize: 18, // size in Pts. - color: charts.MaterialPalette.black), - - // Change the line colors to match text color. - lineStyle: new charts.LineStyleSpec( - color: charts.MaterialPalette.black))), - ); - } + Widget build(BuildContext context) => charts.BarChart( + seriesList, + animate: animate, + + /// Assign a custom style for the domain axis. + /// + /// This is an OrdinalAxisSpec to match up with BarChart's default + /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for + /// other charts). + domainAxis: const charts.OrdinalAxisSpec( + renderSpec: charts.SmallTickRendererSpec( + // Tick and Label styling here. + labelStyle: charts.TextStyleSpec( + fontSize: 18, // size in Pts. + color: charts.MaterialPalette.black, + ), + + // Change the line colors to match text color. + lineStyle: charts.LineStyleSpec( + color: charts.MaterialPalette.black, + ), + ), + ), + + /// Assign a custom style for the measure axis. + primaryMeasureAxis: const charts.NumericAxisSpec( + renderSpec: charts.GridlineRendererSpec( + // Tick and Label styling here. + labelStyle: charts.TextStyleSpec( + fontSize: 18, // size in Pts. + color: charts.MaterialPalette.black, + ), + + // Change the line colors to match text color. + lineStyle: charts.LineStyleSpec( + color: charts.MaterialPalette.black, + ), + ), + ), + ); /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -129,8 +133,7 @@ class CustomFontSizeAndColor extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/axes/custom_measure_tick_count.dart b/charts_flutter/example/lib/axes/custom_measure_tick_count.dart index 2c5739f4e..d2d6a925f 100644 --- a/charts_flutter/example/lib/axes/custom_measure_tick_count.dart +++ b/charts_flutter/example/lib/axes/custom_measure_tick_count.dart @@ -18,105 +18,104 @@ /// The tick count can be set by setting the [desiredMinTickCount] and /// [desiredMaxTickCount] for automatically adjusted tick counts (based on /// how 'nice' the ticks are) or [desiredTickCount] for a fixed tick count. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class CustomMeasureTickCount extends StatelessWidget { - final List> seriesList; - final bool animate; - - CustomMeasureTickCount(this.seriesList, {this.animate = false}); + const CustomMeasureTickCount(this.seriesList, + {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory CustomMeasureTickCount.withSampleData() { - return new CustomMeasureTickCount( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory CustomMeasureTickCount.withSampleData() => CustomMeasureTickCount( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory CustomMeasureTickCount.withRandomData() { - return new CustomMeasureTickCount(_createRandomData()); - } + factory CustomMeasureTickCount.withRandomData() => + CustomMeasureTickCount(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new MyRow(new DateTime(2017, 9, 25), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 26), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 27), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 28), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 29), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 30), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 01), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 02), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 03), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 04), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 05), random.nextInt(100)), + MyRow(DateTime(2017, 9, 25), random.nextInt(100)), + MyRow(DateTime(2017, 9, 26), random.nextInt(100)), + MyRow(DateTime(2017, 9, 27), random.nextInt(100)), + MyRow(DateTime(2017, 9, 28), random.nextInt(100)), + MyRow(DateTime(2017, 9, 29), random.nextInt(100)), + MyRow(DateTime(2017, 9, 30), random.nextInt(100)), + MyRow(DateTime(2017, 10), random.nextInt(100)), + MyRow(DateTime(2017, 10, 02), random.nextInt(100)), + MyRow(DateTime(2017, 10, 03), random.nextInt(100)), + MyRow(DateTime(2017, 10, 04), random.nextInt(100)), + MyRow(DateTime(2017, 10, 05), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, animate: animate, /// Customize the measure axis to have 2 ticks, - primaryMeasureAxis: new charts.NumericAxisSpec( - tickProviderSpec: - new charts.BasicNumericTickProviderSpec(desiredTickCount: 2))); - } + primaryMeasureAxis: const charts.NumericAxisSpec( + tickProviderSpec: + charts.BasicNumericTickProviderSpec(desiredTickCount: 2), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new MyRow(new DateTime(2017, 9, 25), 6), - new MyRow(new DateTime(2017, 9, 26), 8), - new MyRow(new DateTime(2017, 9, 27), 6), - new MyRow(new DateTime(2017, 9, 28), 9), - new MyRow(new DateTime(2017, 9, 29), 11), - new MyRow(new DateTime(2017, 9, 30), 15), - new MyRow(new DateTime(2017, 10, 01), 25), - new MyRow(new DateTime(2017, 10, 02), 33), - new MyRow(new DateTime(2017, 10, 03), 27), - new MyRow(new DateTime(2017, 10, 04), 31), - new MyRow(new DateTime(2017, 10, 05), 23), + MyRow(DateTime(2017, 9, 25), 6), + MyRow(DateTime(2017, 9, 26), 8), + MyRow(DateTime(2017, 9, 27), 6), + MyRow(DateTime(2017, 9, 28), 9), + MyRow(DateTime(2017, 9, 29), 11), + MyRow(DateTime(2017, 9, 30), 15), + MyRow(DateTime(2017, 10), 25), + MyRow(DateTime(2017, 10, 02), 33), + MyRow(DateTime(2017, 10, 03), 27), + MyRow(DateTime(2017, 10, 04), 31), + MyRow(DateTime(2017, 10, 05), 23), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } } /// Sample time series data type. class MyRow { + MyRow(this.timeStamp, this.cost); final DateTime timeStamp; final int cost; - MyRow(this.timeStamp, this.cost); } diff --git a/charts_flutter/example/lib/axes/flipped_vertical_axis.dart b/charts_flutter/example/lib/axes/flipped_vertical_axis.dart index 28fbd58a9..2ddc04d82 100644 --- a/charts_flutter/example/lib/axes/flipped_vertical_axis.dart +++ b/charts_flutter/example/lib/axes/flipped_vertical_axis.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -29,46 +31,40 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: primary and secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class FlippedVerticalAxis extends StatelessWidget { - final List> seriesList; - final bool animate; + const FlippedVerticalAxis(this.seriesList, {super.key, this.animate = false}); - FlippedVerticalAxis(this.seriesList, {this.animate = false}); - - factory FlippedVerticalAxis.withSampleData() { - return new FlippedVerticalAxis( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory FlippedVerticalAxis.withSampleData() => FlippedVerticalAxis( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory FlippedVerticalAxis.withRandomData() { - return new FlippedVerticalAxis(_createRandomData()); - } + factory FlippedVerticalAxis.withRandomData() => + FlippedVerticalAxis(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); const runners = ['Smith', 'Jones', 'Brown', 'Doe']; // Randomly assign runners, but leave the order of the places. final raceData = [ - new RunnerRank(runners.removeAt(random.nextInt(runners.length)), 1), - new RunnerRank(runners.removeAt(random.nextInt(runners.length)), 2), - new RunnerRank(runners.removeAt(random.nextInt(runners.length)), 3), - new RunnerRank(runners.removeAt(random.nextInt(runners.length)), 4), + RunnerRank(runners.removeAt(random.nextInt(runners.length)), 1), + RunnerRank(runners.removeAt(random.nextInt(runners.length)), 2), + RunnerRank(runners.removeAt(random.nextInt(runners.length)), 3), + RunnerRank(runners.removeAt(random.nextInt(runners.length)), 4), ]; return [ - new charts.Series( + charts.Series( id: 'Race Results', - domainFn: (RunnerRank row, _) => row.name, - measureFn: (RunnerRank row, _) => row.place, + domainFn: (row, _) => row.name, + measureFn: (row, _) => row.place, data: raceData, ), ]; @@ -79,36 +75,35 @@ class FlippedVerticalAxis extends StatelessWidget { // time so the result is an empty chart. // TODO: Remove this comment @override - Widget build(BuildContext context) { - return new charts.BarChart( - seriesList, - animate: animate, - flipVerticalAxis: true, - ); - } + Widget build(BuildContext context) => charts.BarChart( + seriesList, + animate: animate, + flipVerticalAxis: true, + ); /// Create series list with multiple series static List> _createSampleData() { final raceData = [ - new RunnerRank('Smith', 1), - new RunnerRank('Jones', 2), - new RunnerRank('Brown', 3), - new RunnerRank('Doe', 4), + RunnerRank('Smith', 1), + RunnerRank('Jones', 2), + RunnerRank('Brown', 3), + RunnerRank('Doe', 4), ]; return [ - new charts.Series( - id: 'Race Results', - domainFn: (RunnerRank row, _) => row.name, - measureFn: (RunnerRank row, _) => row.place, - data: raceData), + charts.Series( + id: 'Race Results', + domainFn: (row, _) => row.name, + measureFn: (row, _) => row.place, + data: raceData, + ), ]; } } /// Datum/Row for the chart. class RunnerRank { + RunnerRank(this.name, this.place); final String name; final int place; - RunnerRank(this.name, this.place); } diff --git a/charts_flutter/example/lib/axes/gridline_dash_pattern.dart b/charts_flutter/example/lib/axes/gridline_dash_pattern.dart index 862c4bc50..66c87a190 100644 --- a/charts_flutter/example/lib/axes/gridline_dash_pattern.dart +++ b/charts_flutter/example/lib/axes/gridline_dash_pattern.dart @@ -14,107 +14,106 @@ // limitations under the License. /// Example of timeseries chart with gridlines that have a dash pattern. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class GridlineDashPattern extends StatelessWidget { - final List> seriesList; - final bool animate; - - GridlineDashPattern(this.seriesList, {this.animate = false}); + const GridlineDashPattern(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory GridlineDashPattern.withSampleData() { - return new GridlineDashPattern( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory GridlineDashPattern.withSampleData() => GridlineDashPattern( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GridlineDashPattern.withRandomData() { - return new GridlineDashPattern(_createRandomData()); - } + factory GridlineDashPattern.withRandomData() => + GridlineDashPattern(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new MyRow(new DateTime(2017, 9, 25), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 26), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 27), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 28), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 29), random.nextInt(100)), - new MyRow(new DateTime(2017, 9, 30), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 01), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 02), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 03), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 04), random.nextInt(100)), - new MyRow(new DateTime(2017, 10, 05), random.nextInt(100)), + MyRow(DateTime(2017, 9, 25), random.nextInt(100)), + MyRow(DateTime(2017, 9, 26), random.nextInt(100)), + MyRow(DateTime(2017, 9, 27), random.nextInt(100)), + MyRow(DateTime(2017, 9, 28), random.nextInt(100)), + MyRow(DateTime(2017, 9, 29), random.nextInt(100)), + MyRow(DateTime(2017, 9, 30), random.nextInt(100)), + MyRow(DateTime(2017, 10), random.nextInt(100)), + MyRow(DateTime(2017, 10, 02), random.nextInt(100)), + MyRow(DateTime(2017, 10, 03), random.nextInt(100)), + MyRow(DateTime(2017, 10, 04), random.nextInt(100)), + MyRow(DateTime(2017, 10, 05), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, animate: animate, /// Customize the gridlines to use a dash pattern. - primaryMeasureAxis: new charts.NumericAxisSpec( - renderSpec: charts.GridlineRendererSpec( - lineStyle: charts.LineStyleSpec( - dashPattern: [4, 4], - )))); - } + primaryMeasureAxis: const charts.NumericAxisSpec( + renderSpec: charts.GridlineRendererSpec( + lineStyle: charts.LineStyleSpec( + dashPattern: [4, 4], + ), + ), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new MyRow(new DateTime(2017, 9, 25), 6), - new MyRow(new DateTime(2017, 9, 26), 8), - new MyRow(new DateTime(2017, 9, 27), 6), - new MyRow(new DateTime(2017, 9, 28), 9), - new MyRow(new DateTime(2017, 9, 29), 11), - new MyRow(new DateTime(2017, 9, 30), 15), - new MyRow(new DateTime(2017, 10, 01), 25), - new MyRow(new DateTime(2017, 10, 02), 33), - new MyRow(new DateTime(2017, 10, 03), 27), - new MyRow(new DateTime(2017, 10, 04), 31), - new MyRow(new DateTime(2017, 10, 05), 23), + MyRow(DateTime(2017, 9, 25), 6), + MyRow(DateTime(2017, 9, 26), 8), + MyRow(DateTime(2017, 9, 27), 6), + MyRow(DateTime(2017, 9, 28), 9), + MyRow(DateTime(2017, 9, 29), 11), + MyRow(DateTime(2017, 9, 30), 15), + MyRow(DateTime(2017, 10), 25), + MyRow(DateTime(2017, 10, 02), 33), + MyRow(DateTime(2017, 10, 03), 27), + MyRow(DateTime(2017, 10, 04), 31), + MyRow(DateTime(2017, 10, 05), 23), ]; return [ - new charts.Series( + charts.Series( id: 'Cost', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.cost, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.cost, data: data, - ) + ), ]; } } /// Sample time series data type. class MyRow { + MyRow(this.timeStamp, this.cost); final DateTime timeStamp; final int cost; - MyRow(this.timeStamp, this.cost); } diff --git a/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart b/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart index c4e2a9907..036d036da 100644 --- a/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart +++ b/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart @@ -14,6 +14,8 @@ // limitations under the License. /// No Axis Example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -22,43 +24,38 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of hiding both axis. class HiddenTicksAndLabelsAxis extends StatelessWidget { - final List> seriesList; - final bool animate; + const HiddenTicksAndLabelsAxis(this.seriesList, + {super.key, this.animate = false}); - HiddenTicksAndLabelsAxis(this.seriesList, {this.animate = false}); - - factory HiddenTicksAndLabelsAxis.withSampleData() { - return new HiddenTicksAndLabelsAxis( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory HiddenTicksAndLabelsAxis.withSampleData() => HiddenTicksAndLabelsAxis( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HiddenTicksAndLabelsAxis.withRandomData() { - return new HiddenTicksAndLabelsAxis(_createRandomData()); - } + factory HiddenTicksAndLabelsAxis.withRandomData() => + HiddenTicksAndLabelsAxis(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -66,43 +63,42 @@ class HiddenTicksAndLabelsAxis extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( - seriesList, - animate: animate, + Widget build(BuildContext context) => charts.BarChart( + seriesList, + animate: animate, - /// Assign a custom style for the measure axis. - /// - /// The NoneRenderSpec can still draw an axis line with - /// showAxisLine=true. - primaryMeasureAxis: - new charts.NumericAxisSpec(renderSpec: new charts.NoneRenderSpec()), + /// Assign a custom style for the measure axis. + /// + /// The NoneRenderSpec can still draw an axis line with + /// showAxisLine=true. + primaryMeasureAxis: + const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()), - /// This is an OrdinalAxisSpec to match up with BarChart's default - /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for - /// other charts). - domainAxis: new charts.OrdinalAxisSpec( + /// This is an OrdinalAxisSpec to match up with BarChart's default + /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for + /// other charts). + domainAxis: const charts.OrdinalAxisSpec( // Make sure that we draw the domain axis line. showAxisLine: true, // But don't draw anything else. - renderSpec: new charts.NoneRenderSpec()), - ); - } + renderSpec: charts.NoneRenderSpec(), + ), + ); /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -111,8 +107,7 @@ class HiddenTicksAndLabelsAxis extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart b/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart index ef945b45e..97cdc9c86 100644 --- a/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart +++ b/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -35,59 +37,55 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: primary and secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class HorizontalBarChartWithSecondaryAxis extends StatelessWidget { - static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; - final List> seriesList; - final bool animate; + const HorizontalBarChartWithSecondaryAxis(this.seriesList, + {super.key, this.animate = false}); - HorizontalBarChartWithSecondaryAxis(this.seriesList, {this.animate = false}); - - factory HorizontalBarChartWithSecondaryAxis.withSampleData() { - return new HorizontalBarChartWithSecondaryAxis( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + factory HorizontalBarChartWithSecondaryAxis.withSampleData() => + HorizontalBarChartWithSecondaryAxis( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarChartWithSecondaryAxis.withRandomData() { - return new HorizontalBarChartWithSecondaryAxis(_createRandomData()); - } + factory HorizontalBarChartWithSecondaryAxis.withRandomData() => + HorizontalBarChartWithSecondaryAxis(_createRandomData()); + static const secondaryMeasureAxisId = 'secondaryMeasureAxisId'; + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; final losAngelesSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), - new charts.Series( + charts.Series( id: 'Los Angeles Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: losAngelesSalesData, - )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId) + )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId), // Set the 'Los Angeles Revenue' series to use the secondary measure axis. // All series that have this set will use the secondary measure axis. // All other series will use the primary measure axis. @@ -96,54 +94,55 @@ class HorizontalBarChartWithSecondaryAxis extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // For horizontal bar charts, set the [vertical] flag to false. - return new charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - vertical: false, - // It is important when using both primary and secondary axes to choose - // the same number of ticks for both sides to get the gridlines to line - // up. - primaryMeasureAxis: new charts.NumericAxisSpec( + Widget build(BuildContext context) => + // For horizontal bar charts, set the [vertical] flag to false. + charts.BarChart( + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + vertical: false, + // It is important when using both primary and secondary axes to choose + // the same number of ticks for both sides to get the gridlines to line + // up. + primaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: - new charts.BasicNumericTickProviderSpec(desiredTickCount: 3)), - secondaryMeasureAxis: new charts.NumericAxisSpec( + charts.BasicNumericTickProviderSpec(desiredTickCount: 3), + ), + secondaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: - new charts.BasicNumericTickProviderSpec(desiredTickCount: 3)), - ); - } + charts.BasicNumericTickProviderSpec(desiredTickCount: 3), + ), + ); /// Create series list with multiple series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; final losAngelesSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), - new charts.Series( + charts.Series( id: 'Los Angeles Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: losAngelesSalesData, - )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId) + )..setAttribute(charts.measureAxisIdKey, secondaryMeasureAxisId), // Set the 'Los Angeles Revenue' series to use the secondary measure axis. // All series that have this set will use the secondary measure axis. // All other series will use the primary measure axis. @@ -153,8 +152,7 @@ class HorizontalBarChartWithSecondaryAxis extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { + OrdinalSales(this.year, this.sales); final String year; final int sales; - - OrdinalSales(this.year, this.sales); } diff --git a/charts_flutter/example/lib/axes/integer_only_measure_axis.dart b/charts_flutter/example/lib/axes/integer_only_measure_axis.dart index a8296e616..da5a62f16 100644 --- a/charts_flutter/example/lib/axes/integer_only_measure_axis.dart +++ b/charts_flutter/example/lib/axes/integer_only_measure_axis.dart @@ -19,111 +19,106 @@ /// /// This is done by customizing the measure axis and setting /// [dataIsInWholeNumbers] on the tick provider. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class IntegerOnlyMeasureAxis extends StatelessWidget { - final List> seriesList; - final bool animate; - IntegerOnlyMeasureAxis(this.seriesList, {this.animate = false}); + const IntegerOnlyMeasureAxis(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory IntegerOnlyMeasureAxis.withSampleData() { - return new IntegerOnlyMeasureAxis( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory IntegerOnlyMeasureAxis.withSampleData() => IntegerOnlyMeasureAxis( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory IntegerOnlyMeasureAxis.withRandomData() { - return new IntegerOnlyMeasureAxis(_createRandomData()); - } + factory IntegerOnlyMeasureAxis.withRandomData() => IntegerOnlyMeasureAxis(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new MyRow(new DateTime(2017, 9, 25), random.nextDouble().round()), - new MyRow(new DateTime(2017, 9, 26), random.nextDouble().round()), - new MyRow(new DateTime(2017, 9, 27), random.nextDouble().round()), - new MyRow(new DateTime(2017, 9, 28), random.nextDouble().round()), - new MyRow(new DateTime(2017, 9, 29), random.nextDouble().round()), - new MyRow(new DateTime(2017, 9, 30), random.nextDouble().round()), - new MyRow(new DateTime(2017, 10, 01), random.nextDouble().round()), - new MyRow(new DateTime(2017, 10, 02), random.nextDouble().round()), - new MyRow(new DateTime(2017, 10, 03), random.nextDouble().round()), - new MyRow(new DateTime(2017, 10, 04), random.nextDouble().round()), - new MyRow(new DateTime(2017, 10, 05), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 25), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 26), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 27), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 28), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 29), random.nextDouble().round()), + MyRow(DateTime(2017, 9, 30), random.nextDouble().round()), + MyRow(DateTime(2017, 10), random.nextDouble().round()), + MyRow(DateTime(2017, 10, 02), random.nextDouble().round()), + MyRow(DateTime(2017, 10, 03), random.nextDouble().round()), + MyRow(DateTime(2017, 10, 04), random.nextDouble().round()), + MyRow(DateTime(2017, 10, 05), random.nextDouble().round()), ]; return [ - new charts.Series( + charts.Series( id: 'Headcount', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.headcount, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.headcount, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Provides a custom axis ensuring that the ticks are in whole numbers. - primaryMeasureAxis: new charts.NumericAxisSpec( - tickProviderSpec: new charts.BasicNumericTickProviderSpec( + primaryMeasureAxis: const charts.NumericAxisSpec( + tickProviderSpec: charts.BasicNumericTickProviderSpec( // Make sure we don't have values less than 1 as ticks // (ie: counts). dataIsInWholeNumbers: true, // Fixed tick count to highlight the integer only behavior // generating ticks [0, 1, 2, 3, 4]. - desiredTickCount: 5)), + desiredTickCount: 5,),), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new MyRow(new DateTime(2017, 9, 25), 0), - new MyRow(new DateTime(2017, 9, 26), 0), - new MyRow(new DateTime(2017, 9, 27), 0), - new MyRow(new DateTime(2017, 9, 28), 0), - new MyRow(new DateTime(2017, 9, 29), 0), - new MyRow(new DateTime(2017, 9, 30), 0), - new MyRow(new DateTime(2017, 10, 01), 1), - new MyRow(new DateTime(2017, 10, 02), 1), - new MyRow(new DateTime(2017, 10, 03), 1), - new MyRow(new DateTime(2017, 10, 04), 1), - new MyRow(new DateTime(2017, 10, 05), 1), + MyRow(DateTime(2017, 9, 25), 0), + MyRow(DateTime(2017, 9, 26), 0), + MyRow(DateTime(2017, 9, 27), 0), + MyRow(DateTime(2017, 9, 28), 0), + MyRow(DateTime(2017, 9, 29), 0), + MyRow(DateTime(2017, 9, 30), 0), + MyRow(DateTime(2017, 10), 1), + MyRow(DateTime(2017, 10, 02), 1), + MyRow(DateTime(2017, 10, 03), 1), + MyRow(DateTime(2017, 10, 04), 1), + MyRow(DateTime(2017, 10, 05), 1), ]; return [ - new charts.Series( + charts.Series( id: 'Headcount', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.headcount, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.headcount, data: data, - ) + ), ]; } } /// Sample time series data type. class MyRow { + MyRow(this.timeStamp, this.headcount); final DateTime timeStamp; final int headcount; - MyRow(this.timeStamp, this.headcount); } diff --git a/charts_flutter/example/lib/axes/line_disjoint_axis.dart b/charts_flutter/example/lib/axes/line_disjoint_axis.dart index 766177461..1103efae7 100644 --- a/charts_flutter/example/lib/axes/line_disjoint_axis.dart +++ b/charts_flutter/example/lib/axes/line_disjoint_axis.dart @@ -20,116 +20,113 @@ /// /// Disjoint measure axes will be used to scale the series associated with them, /// but they will not render any tick elements on either side of the chart. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:collection' show LinkedHashMap; import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class DisjointMeasureAxisLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - DisjointMeasureAxisLineChart(this.seriesList, {this.animate = false}); + const DisjointMeasureAxisLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory DisjointMeasureAxisLineChart.withSampleData() { - return new DisjointMeasureAxisLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory DisjointMeasureAxisLineChart.withSampleData() => DisjointMeasureAxisLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DisjointMeasureAxisLineChart.withRandomData() { - return new DisjointMeasureAxisLineChart(_createRandomData()); - } + factory DisjointMeasureAxisLineChart.withRandomData() => DisjointMeasureAxisLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); // The first three series contain similar data with different magnitudes. // This demonstrates the ability to graph the trends in each series relative // to each other, without the largest magnitude series compressing the // smallest. final myFakeDesktopData = [ - new LinearClicks(0, clickCount: random.nextInt(100)), - new LinearClicks(1, clickCount: random.nextInt(100)), - new LinearClicks(2, clickCount: random.nextInt(100)), - new LinearClicks(3, clickCount: random.nextInt(100)), + LinearClicks(0, clickCount: random.nextInt(100)), + LinearClicks(1, clickCount: random.nextInt(100)), + LinearClicks(2, clickCount: random.nextInt(100)), + LinearClicks(3, clickCount: random.nextInt(100)), ]; final myFakeTabletData = [ - new LinearClicks(0, clickCount: random.nextInt(100) * 100), - new LinearClicks(1, clickCount: random.nextInt(100) * 100), - new LinearClicks(2, clickCount: random.nextInt(100) * 100), - new LinearClicks(3, clickCount: random.nextInt(100) * 100), + LinearClicks(0, clickCount: random.nextInt(100) * 100), + LinearClicks(1, clickCount: random.nextInt(100) * 100), + LinearClicks(2, clickCount: random.nextInt(100) * 100), + LinearClicks(3, clickCount: random.nextInt(100) * 100), ]; final myFakeMobileData = [ - new LinearClicks(0, clickCount: random.nextInt(100) * 1000), - new LinearClicks(1, clickCount: random.nextInt(100) * 1000), - new LinearClicks(2, clickCount: random.nextInt(100) * 1000), - new LinearClicks(3, clickCount: random.nextInt(100) * 1000), + LinearClicks(0, clickCount: random.nextInt(100) * 1000), + LinearClicks(1, clickCount: random.nextInt(100) * 1000), + LinearClicks(2, clickCount: random.nextInt(100) * 1000), + LinearClicks(3, clickCount: random.nextInt(100) * 1000), ]; // The fourth series renders with decimal values, representing a very // different sort ratio-based data. If this was on the same axis as any of // the other series, it would be squashed near zero. final myFakeClickRateData = [ - new LinearClicks(0, clickRate: .25), - new LinearClicks(1, clickRate: .65), - new LinearClicks(2, clickRate: .50), - new LinearClicks(3, clickRate: .30), + LinearClicks(0, clickRate: .25), + LinearClicks(1, clickRate: .65), + LinearClicks(2, clickRate: .50), + LinearClicks(3, clickRate: .30), ]; return [ // We render an empty series on the primary measure axis to ensure that // the axis itself gets rendered. This helps us draw the gridlines on the // chart. - new charts.Series( + charts.Series( id: 'Fake Series', - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, - data: []), - new charts.Series( + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, + data: [],), + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeDesktopData, ) // Set the 'Desktop' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 1'), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeTabletData, ) // Set the 'Tablet' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 2'), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeMobileData, ) // Set the 'Mobile' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 3'), - new charts.Series( + charts.Series( id: 'Click Rate', colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeClickRateData, ) // Set the 'Click Rate' series to use a disjoint axis. @@ -139,8 +136,7 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, // Configure a primary measure axis that will render gridlines across // the chart. This axis uses fake ticks with no labels to ensure that we @@ -148,29 +144,28 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // // We do this because disjoint measure axes do not draw any tick // elements on the chart. - primaryMeasureAxis: new charts.NumericAxisSpec( - tickProviderSpec: new charts.StaticNumericTickProviderSpec( + primaryMeasureAxis: const charts.NumericAxisSpec( + tickProviderSpec: charts.StaticNumericTickProviderSpec( // Create the ticks to be used the domain axis. >[ - new charts.TickSpec(0, label: ''), - new charts.TickSpec(1, label: ''), - new charts.TickSpec(2, label: ''), - new charts.TickSpec(3, label: ''), - new charts.TickSpec(4, label: ''), + charts.TickSpec(0, label: ''), + charts.TickSpec(1, label: ''), + charts.TickSpec(2, label: ''), + charts.TickSpec(3, label: ''), + charts.TickSpec(4, label: ''), ], - )), + ),), // Create one disjoint measure axis per series on the chart. // // Disjoint measure axes will be used to scale the rendered data, // without drawing any tick elements on either side of the chart. disjointMeasureAxes: - new LinkedHashMap.from({ - 'axis 1': new charts.NumericAxisSpec(), - 'axis 2': new charts.NumericAxisSpec(), - 'axis 3': new charts.NumericAxisSpec(), - 'axis 4': new charts.NumericAxisSpec(), - })); - } + LinkedHashMap.from({ + 'axis 1': const charts.NumericAxisSpec(), + 'axis 2': const charts.NumericAxisSpec(), + 'axis 3': const charts.NumericAxisSpec(), + 'axis 4': const charts.NumericAxisSpec(), + }),); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -179,77 +174,77 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // to each other, without the largest magnitude series compressing the // smallest. final myFakeDesktopData = [ - new LinearClicks(0, clickCount: 25), - new LinearClicks(1, clickCount: 125), - new LinearClicks(2, clickCount: 920), - new LinearClicks(3, clickCount: 375), + LinearClicks(0, clickCount: 25), + LinearClicks(1, clickCount: 125), + LinearClicks(2, clickCount: 920), + LinearClicks(3, clickCount: 375), ]; final myFakeTabletData = [ - new LinearClicks(0, clickCount: 375), - new LinearClicks(1, clickCount: 1850), - new LinearClicks(2, clickCount: 9700), - new LinearClicks(3, clickCount: 5000), + LinearClicks(0, clickCount: 375), + LinearClicks(1, clickCount: 1850), + LinearClicks(2, clickCount: 9700), + LinearClicks(3, clickCount: 5000), ]; final myFakeMobileData = [ - new LinearClicks(0, clickCount: 5000), - new LinearClicks(1, clickCount: 25000), - new LinearClicks(2, clickCount: 100000), - new LinearClicks(3, clickCount: 75000), + LinearClicks(0, clickCount: 5000), + LinearClicks(1, clickCount: 25000), + LinearClicks(2, clickCount: 100000), + LinearClicks(3, clickCount: 75000), ]; // The fourth series renders with decimal values, representing a very // different sort ratio-based data. If this was on the same axis as any of // the other series, it would be squashed near zero. final myFakeClickRateData = [ - new LinearClicks(0, clickRate: .25), - new LinearClicks(1, clickRate: .65), - new LinearClicks(2, clickRate: .50), - new LinearClicks(3, clickRate: .30), + LinearClicks(0, clickRate: .25), + LinearClicks(1, clickRate: .65), + LinearClicks(2, clickRate: .50), + LinearClicks(3, clickRate: .30), ]; return [ // We render an empty series on the primary measure axis to ensure that // the axis itself gets rendered. This helps us draw the gridlines on the // chart. - new charts.Series( + charts.Series( id: 'Fake Series', - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, - data: []), - new charts.Series( + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, + data: [],), + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeDesktopData, ) // Set the 'Desktop' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 1'), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeTabletData, ) // Set the 'Tablet' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 2'), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickCount, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, data: myFakeMobileData, ) // Set the 'Mobile' series to use a disjoint axis. ..setAttribute(charts.measureAxisIdKey, 'axis 3'), - new charts.Series( + charts.Series( id: 'Click Rate', colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearClicks clickCount, _) => clickCount.year, - measureFn: (LinearClicks clickCount, _) => clickCount.clickRate, + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickRate, data: myFakeClickRateData, ) // Set the 'Click Rate' series to use a disjoint axis. @@ -260,9 +255,9 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { /// Sample linear data type. class LinearClicks { + + LinearClicks(this.year, {this.clickCount, this.clickRate}); final int year; final int? clickCount; final double? clickRate; - - LinearClicks(this.year, {this.clickCount, this.clickRate}); } diff --git a/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart b/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart index 9baa6b740..45f1e272f 100644 --- a/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart +++ b/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Custom Tick Label Alignment Example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -23,43 +25,37 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of using a custom primary measure replacing the renderSpec with one /// that aligns the text under the tick and left justifies. class MeasureAxisLabelAlignment extends StatelessWidget { - final List> seriesList; - final bool animate; - MeasureAxisLabelAlignment(this.seriesList, {this.animate = false}); + const MeasureAxisLabelAlignment(this.seriesList, {super.key, this.animate = false}); - factory MeasureAxisLabelAlignment.withSampleData() { - return new MeasureAxisLabelAlignment( + factory MeasureAxisLabelAlignment.withSampleData() => MeasureAxisLabelAlignment( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory MeasureAxisLabelAlignment.withRandomData() { - return new MeasureAxisLabelAlignment(_createRandomData()); - } + factory MeasureAxisLabelAlignment.withRandomData() => MeasureAxisLabelAlignment(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -67,16 +63,15 @@ class MeasureAxisLabelAlignment extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, /// Customize the primary measure axis using a small tick renderer. /// Use String instead of num for ordinal domain axis /// (typically bar charts). - primaryMeasureAxis: new charts.NumericAxisSpec( - renderSpec: new charts.GridlineRendererSpec( + primaryMeasureAxis: const charts.NumericAxisSpec( + renderSpec: charts.GridlineRendererSpec( // Display the measure axis labels below the gridline. // // 'Before' & 'after' follow the axis value direction. @@ -89,24 +84,23 @@ class MeasureAxisLabelAlignment extends StatelessWidget { // Note: outside means that the secondary measure axis would right // justify. labelJustification: charts.TickLabelJustification.outside, - )), + ),), ); - } /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -115,8 +109,8 @@ class MeasureAxisLabelAlignment extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart b/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart index 77fd02ff5..38841dd8e 100644 --- a/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart +++ b/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart @@ -15,105 +15,100 @@ /// Example of timeseries chart that has a measure axis that does NOT include /// zero. It starts at 100 and goes to 140. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class NonzeroBoundMeasureAxis extends StatelessWidget { - final List> seriesList; - final bool animate; - NonzeroBoundMeasureAxis(this.seriesList, {this.animate = false}); + const NonzeroBoundMeasureAxis(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory NonzeroBoundMeasureAxis.withSampleData() { - return new NonzeroBoundMeasureAxis( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory NonzeroBoundMeasureAxis.withSampleData() => NonzeroBoundMeasureAxis( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NonzeroBoundMeasureAxis.withRandomData() { - return new NonzeroBoundMeasureAxis(_createRandomData()); - } + factory NonzeroBoundMeasureAxis.withRandomData() => NonzeroBoundMeasureAxis(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new MyRow(new DateTime(2017, 9, 25), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 9, 26), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 9, 27), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 9, 28), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 9, 29), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 9, 30), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 10, 01), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 10, 02), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 10, 03), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 10, 04), random.nextInt(100) + 100), - new MyRow(new DateTime(2017, 10, 05), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 25), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 26), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 27), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 28), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 29), random.nextInt(100) + 100), + MyRow(DateTime(2017, 9, 30), random.nextInt(100) + 100), + MyRow(DateTime(2017, 10), random.nextInt(100) + 100), + MyRow(DateTime(2017, 10, 02), random.nextInt(100) + 100), + MyRow(DateTime(2017, 10, 03), random.nextInt(100) + 100), + MyRow(DateTime(2017, 10, 04), random.nextInt(100) + 100), + MyRow(DateTime(2017, 10, 05), random.nextInt(100) + 100), ]; return [ - new charts.Series( + charts.Series( id: 'Headcount', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.headcount, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.headcount, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, // Provide a tickProviderSpec which does NOT require that zero is // included. - primaryMeasureAxis: new charts.NumericAxisSpec( + primaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: - new charts.BasicNumericTickProviderSpec(zeroBound: false))); - } + charts.BasicNumericTickProviderSpec(zeroBound: false),),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new MyRow(new DateTime(2017, 9, 25), 106), - new MyRow(new DateTime(2017, 9, 26), 108), - new MyRow(new DateTime(2017, 9, 27), 106), - new MyRow(new DateTime(2017, 9, 28), 109), - new MyRow(new DateTime(2017, 9, 29), 111), - new MyRow(new DateTime(2017, 9, 30), 115), - new MyRow(new DateTime(2017, 10, 01), 125), - new MyRow(new DateTime(2017, 10, 02), 133), - new MyRow(new DateTime(2017, 10, 03), 127), - new MyRow(new DateTime(2017, 10, 04), 131), - new MyRow(new DateTime(2017, 10, 05), 123), + MyRow(DateTime(2017, 9, 25), 106), + MyRow(DateTime(2017, 9, 26), 108), + MyRow(DateTime(2017, 9, 27), 106), + MyRow(DateTime(2017, 9, 28), 109), + MyRow(DateTime(2017, 9, 29), 111), + MyRow(DateTime(2017, 9, 30), 115), + MyRow(DateTime(2017, 10), 125), + MyRow(DateTime(2017, 10, 02), 133), + MyRow(DateTime(2017, 10, 03), 127), + MyRow(DateTime(2017, 10, 04), 131), + MyRow(DateTime(2017, 10, 05), 123), ]; return [ - new charts.Series( + charts.Series( id: 'Headcount', - domainFn: (MyRow row, _) => row.timeStamp, - measureFn: (MyRow row, _) => row.headcount, + domainFn: (row, _) => row.timeStamp, + measureFn: (row, _) => row.headcount, data: data, - ) + ), ]; } } /// Sample time series data type. class MyRow { + MyRow(this.timeStamp, this.headcount); final DateTime timeStamp; final int headcount; - MyRow(this.timeStamp, this.headcount); } diff --git a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart index d26f1eea7..724b5a6be 100644 --- a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart +++ b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart @@ -20,114 +20,109 @@ /// /// In this example, the series list has numeric data from 0 to 10, but we /// want to show from 3 to 7. -/// We can do this by specifying an [NumericExtents] in [NumericAxisSpec]. +/// We can do this by specifying an [charts.NumericExtents] in [charts.NumericAxisSpec]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class NumericInitialViewport extends StatelessWidget { - final List> seriesList; - final bool animate; - NumericInitialViewport(this.seriesList, {this.animate = false}); + const NumericInitialViewport(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory NumericInitialViewport.withSampleData() { - return new NumericInitialViewport( + /// Creates a [charts.LineChart] with sample data and no transition. + factory NumericInitialViewport.withSampleData() => NumericInitialViewport( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericInitialViewport.withRandomData() { - return new NumericInitialViewport(_createRandomData()); - } + factory NumericInitialViewport.withRandomData() => NumericInitialViewport(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, random.nextInt(100)), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), - new LinearSales(7, random.nextInt(100)), - new LinearSales(8, random.nextInt(100)), - new LinearSales(9, random.nextInt(100)), - new LinearSales(10, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), + LinearSales(4, random.nextInt(100)), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), + LinearSales(7, random.nextInt(100)), + LinearSales(8, random.nextInt(100)), + LinearSales(9, random.nextInt(100)), + LinearSales(10, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart( + Widget build(BuildContext context) => charts.LineChart( seriesList, animate: animate, - domainAxis: new charts.NumericAxisSpec( + domainAxis: const charts.NumericAxisSpec( // Set the initial viewport by providing a new AxisSpec with the // desired viewport, in NumericExtents. - viewport: new charts.NumericExtents(3.0, 7.0)), + viewport: charts.NumericExtents(3.0, 7.0),), // Optionally add a pan or pan and zoom behavior. // If pan/zoom is not added, the viewport specified remains the viewport. - behaviors: [new charts.PanAndZoomBehavior()], + behaviors: [charts.PanAndZoomBehavior()], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), - new LinearSales(4, 55), - new LinearSales(5, 66), - new LinearSales(6, 110), - new LinearSales(7, 70), - new LinearSales(8, 20), - new LinearSales(9, 25), - new LinearSales(10, 45), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), + LinearSales(4, 55), + LinearSales(5, 66), + LinearSales(6, 110), + LinearSales(7, 70), + LinearSales(8, 20), + LinearSales(9, 25), + LinearSales(10, 45), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart b/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart index c05033899..73ded3326 100644 --- a/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart +++ b/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart @@ -20,126 +20,121 @@ /// /// In this example, the series list has ordinal data from year 2014 to 2030, /// but we want to show starting at 2018 and we only want to show 4 values. -/// We can do this by specifying an [OrdinalViewport] in [OrdinalAxisSpec]. +/// We can do this by specifying an [charts.OrdinalViewport] in [charts.OrdinalAxisSpec]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class OrdinalInitialViewport extends StatelessWidget { - final List> seriesList; - final bool animate; - OrdinalInitialViewport(this.seriesList, {this.animate = false}); + const OrdinalInitialViewport(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory OrdinalInitialViewport.withSampleData() { - return new OrdinalInitialViewport( + /// Creates a [charts.BarChart] with sample data and no transition. + factory OrdinalInitialViewport.withSampleData() => OrdinalInitialViewport( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory OrdinalInitialViewport.withRandomData() { - return new OrdinalInitialViewport(_createRandomData()); - } + factory OrdinalInitialViewport.withRandomData() => OrdinalInitialViewport(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), - new OrdinalSales('2018', random.nextInt(100)), - new OrdinalSales('2019', random.nextInt(100)), - new OrdinalSales('2020', random.nextInt(100)), - new OrdinalSales('2021', random.nextInt(100)), - new OrdinalSales('2022', random.nextInt(100)), - new OrdinalSales('2023', random.nextInt(100)), - new OrdinalSales('2024', random.nextInt(100)), - new OrdinalSales('2025', random.nextInt(100)), - new OrdinalSales('2026', random.nextInt(100)), - new OrdinalSales('2027', random.nextInt(100)), - new OrdinalSales('2028', random.nextInt(100)), - new OrdinalSales('2029', random.nextInt(100)), - new OrdinalSales('2030', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2018', random.nextInt(100)), + OrdinalSales('2019', random.nextInt(100)), + OrdinalSales('2020', random.nextInt(100)), + OrdinalSales('2021', random.nextInt(100)), + OrdinalSales('2022', random.nextInt(100)), + OrdinalSales('2023', random.nextInt(100)), + OrdinalSales('2024', random.nextInt(100)), + OrdinalSales('2025', random.nextInt(100)), + OrdinalSales('2026', random.nextInt(100)), + OrdinalSales('2027', random.nextInt(100)), + OrdinalSales('2028', random.nextInt(100)), + OrdinalSales('2029', random.nextInt(100)), + OrdinalSales('2030', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Set the initial viewport by providing a new AxisSpec with the // desired viewport: a starting domain and the data size. - domainAxis: new charts.OrdinalAxisSpec( - viewport: new charts.OrdinalViewport('2018', 4)), + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4),), // Optionally add a pan or pan and zoom behavior. // If pan/zoom is not added, the viewport specified remains the viewport. - behaviors: [new charts.PanAndZoomBehavior()], + behaviors: [charts.PanAndZoomBehavior()], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), - new OrdinalSales('2018', 33), - new OrdinalSales('2019', 80), - new OrdinalSales('2020', 21), - new OrdinalSales('2021', 77), - new OrdinalSales('2022', 8), - new OrdinalSales('2023', 12), - new OrdinalSales('2024', 42), - new OrdinalSales('2025', 70), - new OrdinalSales('2026', 77), - new OrdinalSales('2027', 55), - new OrdinalSales('2028', 19), - new OrdinalSales('2029', 66), - new OrdinalSales('2030', 27), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), + OrdinalSales('2018', 33), + OrdinalSales('2019', 80), + OrdinalSales('2020', 21), + OrdinalSales('2021', 77), + OrdinalSales('2022', 8), + OrdinalSales('2023', 12), + OrdinalSales('2024', 42), + OrdinalSales('2025', 70), + OrdinalSales('2026', 77), + OrdinalSales('2027', 55), + OrdinalSales('2028', 19), + OrdinalSales('2029', 66), + OrdinalSales('2030', 27), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/axes/short_tick_length_axis.dart b/charts_flutter/example/lib/axes/short_tick_length_axis.dart index ba16cb315..bdf50fb09 100644 --- a/charts_flutter/example/lib/axes/short_tick_length_axis.dart +++ b/charts_flutter/example/lib/axes/short_tick_length_axis.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Custom Tick Style Example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -27,43 +29,37 @@ import 'package:nimble_charts/flutter.dart' as charts; /// There are many axis styling options in the SmallTickRenderer allowing you /// to customize the font, tick lengths, and offsets. class ShortTickLengthAxis extends StatelessWidget { - final List> seriesList; - final bool animate; - ShortTickLengthAxis(this.seriesList, {this.animate = false}); + const ShortTickLengthAxis(this.seriesList, {super.key, this.animate = false}); - factory ShortTickLengthAxis.withSampleData() { - return new ShortTickLengthAxis( + factory ShortTickLengthAxis.withSampleData() => ShortTickLengthAxis( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ShortTickLengthAxis.withRandomData() { - return new ShortTickLengthAxis(_createRandomData()); - } + factory ShortTickLengthAxis.withRandomData() => ShortTickLengthAxis(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -71,35 +67,33 @@ class ShortTickLengthAxis extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, /// Customize the primary measure axis using a small tick renderer. /// Note: use String instead of num for ordinal domain axis /// (typically bar charts). - primaryMeasureAxis: new charts.NumericAxisSpec( - renderSpec: new charts.SmallTickRendererSpec( + primaryMeasureAxis: const charts.NumericAxisSpec( + renderSpec: charts.SmallTickRendererSpec( // Tick and Label styling here. - )), + ),), ); - } /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -108,8 +102,8 @@ class ShortTickLengthAxis extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/axes/statically_provided_ticks.dart b/charts_flutter/example/lib/axes/statically_provided_ticks.dart index ff62df867..00b2e3c2a 100644 --- a/charts_flutter/example/lib/axes/statically_provided_ticks.dart +++ b/charts_flutter/example/lib/axes/statically_provided_ticks.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Example of axis using statically provided ticks. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,52 +27,46 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Specifying custom set of ticks allows specifying exactly what ticks are /// used in the axis. Each tick is also allowed to have a different style set. /// -/// For an ordinal axis, the [StaticOrdinalTickProviderSpec] is shown in this -/// example defining ticks to be used with [TickSpec] of String. +/// For an ordinal axis, the [charts.StaticOrdinalTickProviderSpec] is shown in this +/// example defining ticks to be used with [charts.TickSpec] of String. /// -/// For numeric axis, the [StaticNumericTickProviderSpec] can be used by passing -/// in a list of ticks defined with [TickSpec] of num. +/// For numeric axis, the [charts.StaticNumericTickProviderSpec] can be used by passing +/// in a list of ticks defined with [charts.TickSpec] of num. /// -/// For datetime axis, the [StaticDateTimeTickProviderSpec] can be used by -/// passing in a list of ticks defined with [TickSpec] of datetime. +/// For datetime axis, the [charts.StaticDateTimeTickProviderSpec] can be used by +/// passing in a list of ticks defined with [charts.TickSpec] of datetime. class StaticallyProvidedTicks extends StatelessWidget { - final List> seriesList; - final bool animate; - StaticallyProvidedTicks(this.seriesList, {this.animate = false}); + const StaticallyProvidedTicks(this.seriesList, {super.key, this.animate = false}); - factory StaticallyProvidedTicks.withSampleData() { - return new StaticallyProvidedTicks( + factory StaticallyProvidedTicks.withSampleData() => StaticallyProvidedTicks( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StaticallyProvidedTicks.withRandomData() { - return new StaticallyProvidedTicks(_createRandomData()); - } + factory StaticallyProvidedTicks.withRandomData() => StaticallyProvidedTicks(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2014', random.nextInt(100) * 100), - new OrdinalSales('2015', random.nextInt(100) * 100), - new OrdinalSales('2016', random.nextInt(100) * 100), - new OrdinalSales('2017', random.nextInt(100) * 100), + OrdinalSales('2014', random.nextInt(100) * 100), + OrdinalSales('2015', random.nextInt(100) * 100), + OrdinalSales('2016', random.nextInt(100) * 100), + OrdinalSales('2017', random.nextInt(100) * 100), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -81,44 +77,44 @@ class StaticallyProvidedTicks extends StatelessWidget { Widget build(BuildContext context) { // Create the ticks to be used the domain axis. final staticTicks = >[ - new charts.TickSpec( + const charts.TickSpec( // Value must match the domain value. '2014', // Optional label for this tick, defaults to domain value if not set. label: 'Year 2014', // The styling for this tick. - style: new charts.TextStyleSpec( - color: new charts.Color(r: 0x4C, g: 0xAF, b: 0x50))), + style: charts.TextStyleSpec( + color: charts.Color(r: 0x4C, g: 0xAF, b: 0x50),),), // If no text style is specified - the style from renderSpec will be used // if one is specified. - new charts.TickSpec('2015'), - new charts.TickSpec('2016'), - new charts.TickSpec('2017'), + const charts.TickSpec('2015'), + const charts.TickSpec('2016'), + const charts.TickSpec('2017'), ]; - return new charts.BarChart( + return charts.BarChart( seriesList, animate: animate, - domainAxis: new charts.OrdinalAxisSpec( + domainAxis: charts.OrdinalAxisSpec( tickProviderSpec: - new charts.StaticOrdinalTickProviderSpec(staticTicks)), + charts.StaticOrdinalTickProviderSpec(staticTicks),), ); } /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 25000), - new OrdinalSales('2016', 100000), - new OrdinalSales('2017', 750000), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 25000), + OrdinalSales('2016', 100000), + OrdinalSales('2017', 750000), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -127,8 +123,8 @@ class StaticallyProvidedTicks extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/bar_gallery.dart b/charts_flutter/example/lib/bar_chart/bar_gallery.dart index ca656c44d..cc0eb2a40 100644 --- a/charts_flutter/example/lib/bar_chart/bar_gallery.dart +++ b/charts_flutter/example/lib/bar_chart/bar_gallery.dart @@ -13,152 +13,148 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/bar_chart/custom_rounded_bars.dart'; +import 'package:example/bar_chart/grouped.dart'; +import 'package:example/bar_chart/grouped_fill_color.dart'; +import 'package:example/bar_chart/grouped_single_target_line.dart'; +import 'package:example/bar_chart/grouped_stacked.dart'; +import 'package:example/bar_chart/grouped_stacked_weight_pattern.dart'; +import 'package:example/bar_chart/grouped_target_line.dart'; +import 'package:example/bar_chart/horizontal.dart'; +import 'package:example/bar_chart/horizontal_bar_label.dart'; +import 'package:example/bar_chart/horizontal_bar_label_custom.dart'; +import 'package:example/bar_chart/horizontal_pattern_forward_hatch.dart'; +import 'package:example/bar_chart/pattern_forward_hatch.dart'; +import 'package:example/bar_chart/simple.dart'; +import 'package:example/bar_chart/spark_bar.dart'; +import 'package:example/bar_chart/stacked.dart'; +import 'package:example/bar_chart/stacked_fill_color.dart'; +import 'package:example/bar_chart/stacked_horizontal.dart'; +import 'package:example/bar_chart/stacked_target_line.dart'; +import 'package:example/bar_chart/vertical_bar_label.dart'; +import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'custom_rounded_bars.dart'; -import 'grouped.dart'; -import 'grouped_fill_color.dart'; -import 'grouped_single_target_line.dart'; -import 'grouped_stacked.dart'; -import 'grouped_stacked_weight_pattern.dart'; -import 'grouped_target_line.dart'; -import 'horizontal.dart'; -import 'horizontal_bar_label.dart'; -import 'horizontal_bar_label_custom.dart'; -import 'horizontal_pattern_forward_hatch.dart'; -import 'pattern_forward_hatch.dart'; -import 'simple.dart'; -import 'stacked.dart'; -import 'stacked_fill_color.dart'; -import 'stacked_horizontal.dart'; -import 'stacked_target_line.dart'; -import 'spark_bar.dart'; -import 'vertical_bar_label.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Simple Bar Chart', subtitle: 'Simple bar chart with a single series', - childBuilder: () => new SimpleBarChart.withRandomData(), + childBuilder: SimpleBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Stacked Bar Chart', subtitle: 'Stacked bar chart with multiple series', - childBuilder: () => new StackedBarChart.withRandomData(), + childBuilder: StackedBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Bar Chart', subtitle: 'Grouped bar chart with multiple series', - childBuilder: () => new GroupedBarChart.withRandomData(), + childBuilder: GroupedBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Stacked Bar Chart', subtitle: 'Grouped and stacked bar chart with multiple series', - childBuilder: () => new GroupedStackedBarChart.withRandomData(), + childBuilder: GroupedStackedBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Bar Target Line Chart', subtitle: 'Grouped bar target line chart with multiple series', - childBuilder: () => new GroupedBarTargetLineChart.withRandomData(), + childBuilder: GroupedBarTargetLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Bar Single Target Line Chart', subtitle: 'Grouped bar target line chart with multiple series and a single target', - childBuilder: () => new GroupedBarSingleTargetLineChart.withRandomData(), + childBuilder: GroupedBarSingleTargetLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Stacked Bar Target Line Chart', subtitle: 'Stacked bar target line chart with multiple series', - childBuilder: () => new StackedBarTargetLineChart.withRandomData(), + childBuilder: StackedBarTargetLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Horizontal Bar Chart', subtitle: 'Horizontal bar chart with a single series', - childBuilder: () => new HorizontalBarChart.withRandomData(), + childBuilder: HorizontalBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Stacked Horizontal Bar Chart', subtitle: 'Stacked horizontal bar chart with multiple series', - childBuilder: () => new StackedHorizontalBarChart.withRandomData(), + childBuilder: StackedHorizontalBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Horizontal Bar Chart with Bar Labels', subtitle: 'Horizontal bar chart with a single series and bar labels', - childBuilder: () => new HorizontalBarLabelChart.withRandomData(), + childBuilder: HorizontalBarLabelChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Horizontal Bar Chart with Custom Bar Labels', subtitle: 'Bar labels with customized styling', - childBuilder: () => new HorizontalBarLabelCustomChart.withRandomData(), + childBuilder: HorizontalBarLabelCustomChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Vertical Bar Chart with Bar Labels', subtitle: 'Vertical bar chart with a single series and bar labels', - childBuilder: () => new VerticalBarLabelChart.withRandomData(), + childBuilder: VerticalBarLabelChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Spark Bar Chart', subtitle: 'Spark Bar Chart', - childBuilder: () => new SparkBar.withRandomData(), + childBuilder: SparkBar.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Fill Color Bar Chart', subtitle: 'Grouped bar chart with fill colors', - childBuilder: () => new GroupedFillColorBarChart.withRandomData(), + childBuilder: GroupedFillColorBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Stacked Fill Color Bar Chart', subtitle: 'Stacked bar chart with fill colors', - childBuilder: () => new StackedFillColorBarChart.withRandomData(), + childBuilder: StackedFillColorBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Pattern Forward Hatch Bar Chart', subtitle: 'Pattern Forward Hatch Bar Chart', - childBuilder: () => new PatternForwardHatchBarChart.withRandomData(), + childBuilder: PatternForwardHatchBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, child: const Icon(Icons.insert_chart),), title: 'Horizontal Pattern Forward Hatch Bar Chart', subtitle: 'Horizontal Pattern Forward Hatch Bar Chart', - childBuilder: () => - new HorizontalPatternForwardHatchBarChart.withRandomData(), + childBuilder: HorizontalPatternForwardHatchBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Weight Pattern Bar Chart', subtitle: 'Grouped and stacked bar chart with a weight pattern', - childBuilder: () => - new GroupedStackedWeightPatternBarChart.withRandomData(), + childBuilder: GroupedStackedWeightPatternBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Bar Chart with custom bar radius', subtitle: 'Custom rounded bar corners', - childBuilder: () => new CustomRoundedBars.withRandomData(), + childBuilder: CustomRoundedBars.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart b/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart index 019bb7a61..402a8c510 100644 --- a/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart +++ b/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart @@ -14,97 +14,92 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class CustomRoundedBars extends StatelessWidget { - final List> seriesList; - final bool animate; - CustomRoundedBars(this.seriesList, {this.animate = false}); + const CustomRoundedBars(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with custom rounded bars. - factory CustomRoundedBars.withSampleData() { - return new CustomRoundedBars( + /// Creates a [charts.BarChart] with custom rounded bars. + factory CustomRoundedBars.withSampleData() => CustomRoundedBars( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory CustomRoundedBars.withRandomData() { - return new CustomRoundedBars(_createRandomData()); - } + factory CustomRoundedBars.withRandomData() => CustomRoundedBars(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, - defaultRenderer: new charts.BarRendererConfig( + defaultRenderer: charts.BarRendererConfig( // By default, bar renderer will draw rounded bars with a constant // radius of 30. // To not have any rounded corners, use [NoCornerStrategy] // To change the radius of the bars, use [ConstCornerStrategy] - cornerStrategy: const charts.ConstCornerStrategy(30)), + cornerStrategy: const charts.ConstCornerStrategy(30),), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped.dart b/charts_flutter/example/lib/bar_chart/grouped.dart index ca96e14c5..69539936d 100644 --- a/charts_flutter/example/lib/bar_chart/grouped.dart +++ b/charts_flutter/example/lib/bar_chart/grouped.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,69 +23,63 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedBarChart(this.seriesList, {this.animate = false}); + const GroupedBarChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedBarChart.withSampleData() { - return new GroupedBarChart( + factory GroupedBarChart.withSampleData() => GroupedBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarChart.withRandomData() { - return new GroupedBarChart(_createRandomData()); - } + factory GroupedBarChart.withRandomData() => GroupedBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -91,54 +87,52 @@ class GroupedBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -147,8 +141,8 @@ class GroupedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart b/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart index aaf97d36c..cfacf2c51 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -23,58 +25,52 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a grouped bar chart with three series, each rendered with /// different fill colors. class GroupedFillColorBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedFillColorBarChart(this.seriesList, {this.animate = false}); + const GroupedFillColorBarChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedFillColorBarChart.withSampleData() { - return new GroupedFillColorBarChart( + factory GroupedFillColorBarChart.withSampleData() => GroupedFillColorBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedFillColorBarChart.withRandomData() { - return new GroupedFillColorBarChart(_createRandomData()); - } + factory GroupedFillColorBarChart.withRandomData() => GroupedFillColorBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ // Blue bars with a lighter center color. - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, fillColorFn: (_, __) => @@ -82,18 +78,18 @@ class GroupedFillColorBarChart extends StatelessWidget { ), // Solid red bars. Fill color will default to the series color if no // fillColorFn is configured. - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, ), // Hollow green bars. - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, fillColorFn: (_, __) => charts.MaterialPalette.transparent, @@ -103,45 +99,43 @@ class GroupedFillColorBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Configure a stroke width to enable borders on the bars. - defaultRenderer: new charts.BarRendererConfig( - groupingType: charts.BarGroupingType.grouped, strokeWidthPx: 2.0), + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.grouped, strokeWidthPx: 2,), ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 50), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ // Blue bars with a lighter center color. - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, fillColorFn: (_, __) => @@ -149,18 +143,18 @@ class GroupedFillColorBarChart extends StatelessWidget { ), // Solid red bars. Fill color will default to the series color if no // fillColorFn is configured. - new charts.Series( + charts.Series( id: 'Tablet', - measureFn: (OrdinalSales sales, _) => sales.sales, + measureFn: (sales, _) => sales.sales, data: tableSalesData, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, + domainFn: (sales, _) => sales.year, ), // Hollow green bars. - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, fillColorFn: (_, __) => charts.MaterialPalette.transparent, @@ -171,8 +165,8 @@ class GroupedFillColorBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart b/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart index 7b44010dc..2bc8b88d1 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,80 +23,74 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarSingleTargetLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedBarSingleTargetLineChart(this.seriesList, {this.animate = false}); + const GroupedBarSingleTargetLineChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedBarSingleTargetLineChart.withSampleData() { - return new GroupedBarSingleTargetLineChart( + factory GroupedBarSingleTargetLineChart.withSampleData() => GroupedBarSingleTargetLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarSingleTargetLineChart.withRandomData() { - return new GroupedBarSingleTargetLineChart(_createRandomData()); - } + factory GroupedBarSingleTargetLineChart.withRandomData() => GroupedBarSingleTargetLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final targetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: desktopSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData,), + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: tableSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData,), + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: mobileSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,), + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: targetLineData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: targetLineData,) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), ]; @@ -102,69 +98,66 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart(seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, customSeriesRenderers: [ - new charts.BarTargetLineRendererConfig( + charts.BarTargetLineRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customTargetLine', - groupingType: charts.BarGroupingType.grouped) - ]); - } + customRendererId: 'customTargetLine',), + ],); /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final targetLineData = [ - new OrdinalSales('2014', 30), - new OrdinalSales('2015', 55), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 25), + OrdinalSales('2014', 30), + OrdinalSales('2015', 55), + OrdinalSales('2016', 15), + OrdinalSales('2017', 25), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: desktopSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData,), + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: tableSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData,), + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: mobileSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,), + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: targetLineData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: targetLineData,) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), ]; @@ -173,8 +166,8 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked.dart index eac7278d0..fd861e972 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Example of a bar chart with grouped, stacked series oriented vertically. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,114 +23,108 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedStackedBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedStackedBarChart(this.seriesList, {this.animate = false}); + const GroupedStackedBarChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedStackedBarChart.withSampleData() { - return new GroupedStackedBarChart( + factory GroupedStackedBarChart.withSampleData() => GroupedStackedBarChart( createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedStackedBarChart.withRandomData() { - return new GroupedStackedBarChart(_createRandomData()); - } + factory GroupedStackedBarChart.withRandomData() => GroupedStackedBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -136,99 +132,97 @@ class GroupedStackedBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.groupedStacked, ); - } /// Create series list with multiple series static List> createSampleData() { final desktopSalesDataA = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataA = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataB = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -237,8 +231,8 @@ class GroupedStackedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart index c26ab906b..a373ef374 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart @@ -18,6 +18,8 @@ /// /// This is a pattern of weights used to calculate the width of bars within a /// bar group. If not specified, each bar in the group will have an equal width. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,114 +27,108 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedStackedWeightPatternBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedStackedWeightPatternBarChart(this.seriesList, {this.animate = false}); + const GroupedStackedWeightPatternBarChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedStackedWeightPatternBarChart.withSampleData() { - return new GroupedStackedWeightPatternBarChart( + factory GroupedStackedWeightPatternBarChart.withSampleData() => GroupedStackedWeightPatternBarChart( createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedStackedWeightPatternBarChart.withRandomData() { - return new GroupedStackedWeightPatternBarChart(_createRandomData()); - } + factory GroupedStackedWeightPatternBarChart.withRandomData() => GroupedStackedWeightPatternBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -140,8 +136,7 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Configure the bar renderer in grouped stacked rendering mode with a @@ -149,98 +144,97 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { // // The first stack of bars in each group is configured to be twice as wide // as the second stack of bars in each group. - defaultRenderer: new charts.BarRendererConfig( + defaultRenderer: charts.BarRendererConfig( groupingType: charts.BarGroupingType.groupedStacked, weightPattern: [2, 1], ), ); - } /// Create series list with multiple series static List> createSampleData() { final desktopSalesDataA = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataA = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataB = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -249,8 +243,8 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/grouped_target_line.dart b/charts_flutter/example/lib/bar_chart/grouped_target_line.dart index 9ab9fa675..ef88f0412 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_target_line.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,112 +23,106 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarTargetLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GroupedBarTargetLineChart(this.seriesList, {this.animate = false}); + const GroupedBarTargetLineChart(this.seriesList, {super.key, this.animate = false}); - factory GroupedBarTargetLineChart.withSampleData() { - return new GroupedBarTargetLineChart( + factory GroupedBarTargetLineChart.withSampleData() => GroupedBarTargetLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarTargetLineChart.withRandomData() { - return new GroupedBarTargetLineChart(_createRandomData()); - } + factory GroupedBarTargetLineChart.withRandomData() => GroupedBarTargetLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final desktopTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Tablet Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Mobile Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileTargetLineData, ) // Configure our custom bar target renderer for this series. @@ -136,101 +132,98 @@ class GroupedBarTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart(seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, customSeriesRenderers: [ - new charts.BarTargetLineRendererConfig( + charts.BarTargetLineRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customTargetLine', - groupingType: charts.BarGroupingType.grouped) - ]); - } + customRendererId: 'customTargetLine',), + ],); /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final desktopTargetLineData = [ - new OrdinalSales('2014', 4), - new OrdinalSales('2015', 20), - new OrdinalSales('2016', 80), - new OrdinalSales('2017', 65), + OrdinalSales('2014', 4), + OrdinalSales('2015', 20), + OrdinalSales('2016', 80), + OrdinalSales('2017', 65), ]; final tableTargetLineData = [ - new OrdinalSales('2014', 30), - new OrdinalSales('2015', 55), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 25), + OrdinalSales('2014', 30), + OrdinalSales('2015', 55), + OrdinalSales('2016', 15), + OrdinalSales('2017', 25), ]; final mobileTargetLineData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 5), - new OrdinalSales('2016', 45), - new OrdinalSales('2017', 35), + OrdinalSales('2014', 10), + OrdinalSales('2015', 5), + OrdinalSales('2016', 45), + OrdinalSales('2017', 35), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Tablet Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Mobile Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileTargetLineData, ) // Configure our custom bar target renderer for this series. @@ -241,8 +234,8 @@ class GroupedBarTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/horizontal.dart b/charts_flutter/example/lib/bar_chart/horizontal.dart index a32e4f866..6aa8b02b6 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal.dart @@ -14,53 +14,50 @@ // limitations under the License. /// Horizontal bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class HorizontalBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - HorizontalBarChart(this.seriesList, {this.animate = false}); + const HorizontalBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory HorizontalBarChart.withSampleData() { - return new HorizontalBarChart( + /// Creates a [charts.BarChart] with sample data and no transition. + factory HorizontalBarChart.withSampleData() => HorizontalBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarChart.withRandomData() { - return new HorizontalBarChart(_createRandomData()); - } + factory HorizontalBarChart.withRandomData() => HorizontalBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -68,7 +65,7 @@ class HorizontalBarChart extends StatelessWidget { @override Widget build(BuildContext context) { // For horizontal bar charts, set the [vertical] flag to false. - return new charts.BarChart( + return charts.BarChart( seriesList, animate: animate, vertical: false, @@ -78,27 +75,27 @@ class HorizontalBarChart extends StatelessWidget { /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart b/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart index 1bc2a1c15..b5504b81e 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart @@ -14,55 +14,52 @@ // limitations under the License. /// Horizontal bar chart with bar label renderer example and hidden domain axis. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class HorizontalBarLabelChart extends StatelessWidget { - final List> seriesList; - final bool animate; - HorizontalBarLabelChart(this.seriesList, {this.animate = false}); + const HorizontalBarLabelChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory HorizontalBarLabelChart.withSampleData() { - return new HorizontalBarLabelChart( + /// Creates a [charts.BarChart] with sample data and no transition. + factory HorizontalBarLabelChart.withSampleData() => HorizontalBarLabelChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarLabelChart.withRandomData() { - return new HorizontalBarLabelChart(_createRandomData()); - } + factory HorizontalBarLabelChart.withRandomData() => HorizontalBarLabelChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '${sales.year}: \$${sales.sales.toString()}') + labelAccessorFn: (sales, _) => + '${sales.year}: \$${sales.sales}',), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -75,8 +72,7 @@ class HorizontalBarLabelChart extends StatelessWidget { // Text style for inside / outside can be controlled independently by setting // [insideLabelStyleSpec] and [outsideLabelStyleSpec]. @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, vertical: false, @@ -85,39 +81,38 @@ class HorizontalBarLabelChart extends StatelessWidget { // barRendererDecorator: new charts.BarLabelDecorator( // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - barRendererDecorator: new charts.BarLabelDecorator(), + barRendererDecorator: charts.BarLabelDecorator(), // Hide domain axis. domainAxis: - new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec()), + const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '${sales.year}: \$${sales.sales.toString()}') + labelAccessorFn: (sales, _) => + '${sales.year}: \$${sales.sales}',), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart b/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart index 5201c76bf..3e1390393 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart @@ -14,66 +14,63 @@ // limitations under the License. /// Horizontal bar chart with custom style for each datum in the bar label. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class HorizontalBarLabelCustomChart extends StatelessWidget { - final List> seriesList; - final bool animate; - HorizontalBarLabelCustomChart(this.seriesList, {this.animate = false}); - - /// Creates a [BarChart] with sample data and no transition. - static HorizontalBarLabelCustomChart createWithSampleData() { - return new HorizontalBarLabelCustomChart( - _createSampleData(), - // Disable animations for image tests. - animate: false, - ); - } + const HorizontalBarLabelCustomChart(this.seriesList, {super.key, this.animate = false}); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarLabelCustomChart.withRandomData() { - return new HorizontalBarLabelCustomChart(_createRandomData()); - } + factory HorizontalBarLabelCustomChart.withRandomData() => HorizontalBarLabelCustomChart(_createRandomData()); + final List> seriesList; + final bool animate; + + /// Creates a [charts.BarChart] with sample data and no transition. + static HorizontalBarLabelCustomChart createWithSampleData() => HorizontalBarLabelCustomChart( + _createSampleData(), + ); /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '${sales.year}: \$${sales.sales.toString()}', - insideLabelStyleAccessorFn: (OrdinalSales sales, _) { + labelAccessorFn: (sales, _) => + '${sales.year}: \$${sales.sales}', + insideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault : charts.MaterialPalette.yellow.shadeDefault.darker; - return new charts.TextStyleSpec(color: color); + return charts.TextStyleSpec(color: color); }, - outsideLabelStyleAccessorFn: (OrdinalSales sales, _) { + outsideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault : charts.MaterialPalette.yellow.shadeDefault.darker; - return new charts.TextStyleSpec(color: color); + return charts.TextStyleSpec(color: color); }, ), ]; @@ -84,47 +81,45 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { // for inside the bar and outside the bar. To be able to control each datum's // style, set the style accessor functions on the series. @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, vertical: false, - barRendererDecorator: new charts.BarLabelDecorator(), + barRendererDecorator: charts.BarLabelDecorator(), // Hide domain axis. domainAxis: - new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec()), + const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '${sales.year}: \$${sales.sales.toString()}', - insideLabelStyleAccessorFn: (OrdinalSales sales, _) { + labelAccessorFn: (sales, _) => + '${sales.year}: \$${sales.sales}', + insideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault : charts.MaterialPalette.yellow.shadeDefault.darker; - return new charts.TextStyleSpec(color: color); + return charts.TextStyleSpec(color: color); }, - outsideLabelStyleAccessorFn: (OrdinalSales sales, _) { + outsideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault : charts.MaterialPalette.yellow.shadeDefault.darker; - return new charts.TextStyleSpec(color: color); + return charts.TextStyleSpec(color: color); }, ), ]; @@ -133,8 +128,8 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart b/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart index 32be61b2e..16d8c6e42 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Forward pattern hatch bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,72 +27,66 @@ import 'package:nimble_charts/flutter.dart' as charts; /// The second series of bars is rendered with a pattern by defining a /// fillPatternFn mapping function. class HorizontalPatternForwardHatchBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - HorizontalPatternForwardHatchBarChart(this.seriesList, - {this.animate = false}); + const HorizontalPatternForwardHatchBarChart(this.seriesList, + {super.key, this.animate = false,}); - factory HorizontalPatternForwardHatchBarChart.withSampleData() { - return new HorizontalPatternForwardHatchBarChart( + factory HorizontalPatternForwardHatchBarChart.withSampleData() => HorizontalPatternForwardHatchBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalPatternForwardHatchBarChart.withRandomData() { - return new HorizontalPatternForwardHatchBarChart(_createRandomData()); - } + factory HorizontalPatternForwardHatchBarChart.withRandomData() => HorizontalPatternForwardHatchBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (OrdinalSales sales, _) => + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -98,57 +94,55 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, vertical: false, ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (OrdinalSales sales, _) => + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -157,8 +151,8 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart b/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart index 27f5aaa9e..bdabdf9ea 100644 --- a/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart +++ b/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart @@ -17,6 +17,8 @@ /// /// The second series of bars is rendered with a pattern by defining a /// fillPatternFn mapping function. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -24,71 +26,65 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PatternForwardHatchBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PatternForwardHatchBarChart(this.seriesList, {this.animate = false}); + const PatternForwardHatchBarChart(this.seriesList, {super.key, this.animate = false}); - factory PatternForwardHatchBarChart.withSampleData() { - return new PatternForwardHatchBarChart( + factory PatternForwardHatchBarChart.withSampleData() => PatternForwardHatchBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PatternForwardHatchBarChart.withRandomData() { - return new PatternForwardHatchBarChart(_createRandomData()); - } + factory PatternForwardHatchBarChart.withRandomData() => PatternForwardHatchBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (OrdinalSales sales, _) => + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -96,56 +92,54 @@ class PatternForwardHatchBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (OrdinalSales sales, _) => + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -154,8 +148,8 @@ class PatternForwardHatchBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/simple.dart b/charts_flutter/example/lib/bar_chart/simple.dart index 898f30632..90d3601d9 100644 --- a/charts_flutter/example/lib/bar_chart/simple.dart +++ b/charts_flutter/example/lib/bar_chart/simple.dart @@ -14,91 +14,86 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimpleBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleBarChart(this.seriesList, {this.animate = false}); + const SimpleBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory SimpleBarChart.withSampleData() { - return new SimpleBarChart( + /// Creates a [charts.BarChart] with sample data and no transition. + factory SimpleBarChart.withSampleData() => SimpleBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleBarChart.withRandomData() { - return new SimpleBarChart(_createRandomData()); - } + factory SimpleBarChart.withRandomData() => SimpleBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/spark_bar.dart b/charts_flutter/example/lib/bar_chart/spark_bar.dart index 435e665b0..a2e5c494d 100644 --- a/charts_flutter/example/lib/bar_chart/spark_bar.dart +++ b/charts_flutter/example/lib/bar_chart/spark_bar.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Spark Bar Example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -22,50 +24,44 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a Spark Bar by hiding both axis, reducing the chart margins. class SparkBar extends StatelessWidget { - final List> seriesList; - final bool animate; - SparkBar(this.seriesList, {this.animate = false}); + const SparkBar(this.seriesList, {super.key, this.animate = false}); - factory SparkBar.withSampleData() { - return new SparkBar( + factory SparkBar.withSampleData() => SparkBar( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SparkBar.withRandomData() { - return new SparkBar(_createRandomData()); - } + factory SparkBar.withRandomData() => SparkBar(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final globalSalesData = [ - new OrdinalSales('2007', random.nextInt(100)), - new OrdinalSales('2008', random.nextInt(100)), - new OrdinalSales('2009', random.nextInt(100)), - new OrdinalSales('2010', random.nextInt(100)), - new OrdinalSales('2011', random.nextInt(100)), - new OrdinalSales('2012', random.nextInt(100)), - new OrdinalSales('2013', random.nextInt(100)), - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2007', random.nextInt(100)), + OrdinalSales('2008', random.nextInt(100)), + OrdinalSales('2009', random.nextInt(100)), + OrdinalSales('2010', random.nextInt(100)), + OrdinalSales('2011', random.nextInt(100)), + OrdinalSales('2012', random.nextInt(100)), + OrdinalSales('2013', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -73,8 +69,7 @@ class SparkBar extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, @@ -83,48 +78,47 @@ class SparkBar extends StatelessWidget { /// The NoneRenderSpec only draws an axis line (and even that can be hidden /// with showAxisLine=false). primaryMeasureAxis: - new charts.NumericAxisSpec(renderSpec: new charts.NoneRenderSpec()), + const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()), /// This is an OrdinalAxisSpec to match up with BarChart's default /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for /// other charts). - domainAxis: new charts.OrdinalAxisSpec( + domainAxis: const charts.OrdinalAxisSpec( // Make sure that we draw the domain axis line. showAxisLine: true, // But don't draw anything else. - renderSpec: new charts.NoneRenderSpec()), + renderSpec: charts.NoneRenderSpec(),), // With a spark chart we likely don't want large chart margins. // 1px is the smallest we can make each margin. - layoutConfig: new charts.LayoutConfig( - leftMarginSpec: new charts.MarginSpec.fixedPixel(0), - topMarginSpec: new charts.MarginSpec.fixedPixel(0), - rightMarginSpec: new charts.MarginSpec.fixedPixel(0), - bottomMarginSpec: new charts.MarginSpec.fixedPixel(0)), + layoutConfig: charts.LayoutConfig( + leftMarginSpec: charts.MarginSpec.fixedPixel(0), + topMarginSpec: charts.MarginSpec.fixedPixel(0), + rightMarginSpec: charts.MarginSpec.fixedPixel(0), + bottomMarginSpec: charts.MarginSpec.fixedPixel(0),), ); - } /// Create series list with single series static List> _createSampleData() { final globalSalesData = [ - new OrdinalSales('2007', 3100), - new OrdinalSales('2008', 3500), - new OrdinalSales('2009', 5000), - new OrdinalSales('2010', 2500), - new OrdinalSales('2011', 3200), - new OrdinalSales('2012', 4500), - new OrdinalSales('2013', 4400), - new OrdinalSales('2014', 5000), - new OrdinalSales('2015', 5000), - new OrdinalSales('2016', 4500), - new OrdinalSales('2017', 4300), + OrdinalSales('2007', 3100), + OrdinalSales('2008', 3500), + OrdinalSales('2009', 5000), + OrdinalSales('2010', 2500), + OrdinalSales('2011', 3200), + OrdinalSales('2012', 4500), + OrdinalSales('2013', 4400), + OrdinalSales('2014', 5000), + OrdinalSales('2015', 5000), + OrdinalSales('2016', 4500), + OrdinalSales('2017', 4300), ]; return [ - new charts.Series( + charts.Series( id: 'Global Revenue', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: globalSalesData, ), ]; @@ -133,8 +127,8 @@ class SparkBar extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/stacked.dart b/charts_flutter/example/lib/bar_chart/stacked.dart index 1d26c2687..a02fa355e 100644 --- a/charts_flutter/example/lib/bar_chart/stacked.dart +++ b/charts_flutter/example/lib/bar_chart/stacked.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,70 +23,64 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedBarChart(this.seriesList, {this.animate = false}); + const StackedBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a stacked [BarChart] with sample data and no transition. - factory StackedBarChart.withSampleData() { - return new StackedBarChart( + /// Creates a stacked [charts.BarChart] with sample data and no transition. + factory StackedBarChart.withSampleData() => StackedBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedBarChart.withRandomData() { - return new StackedBarChart(_createRandomData()); - } + factory StackedBarChart.withRandomData() => StackedBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -92,54 +88,52 @@ class StackedBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.stacked, ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -148,8 +142,8 @@ class StackedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart b/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart index 2eb2c5545..bb0f1deb9 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -23,58 +25,52 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a stacked bar chart with three series, each rendered with /// different fill colors. class StackedFillColorBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedFillColorBarChart(this.seriesList, {this.animate = false}); + const StackedFillColorBarChart(this.seriesList, {super.key, this.animate = false}); - factory StackedFillColorBarChart.withSampleData() { - return new StackedFillColorBarChart( + factory StackedFillColorBarChart.withSampleData() => StackedFillColorBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedFillColorBarChart.withRandomData() { - return new StackedFillColorBarChart(_createRandomData()); - } + factory StackedFillColorBarChart.withRandomData() => StackedFillColorBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ // Blue bars with a lighter center color. - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, fillColorFn: (_, __) => @@ -82,18 +78,18 @@ class StackedFillColorBarChart extends StatelessWidget { ), // Solid red bars. Fill color will default to the series color if no // fillColorFn is configured. - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, ), // Hollow green bars. - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, fillColorFn: (_, __) => charts.MaterialPalette.transparent, @@ -103,45 +99,43 @@ class StackedFillColorBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Configure a stroke width to enable borders on the bars. - defaultRenderer: new charts.BarRendererConfig( - groupingType: charts.BarGroupingType.stacked, strokeWidthPx: 2.0), + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.stacked, strokeWidthPx: 2,), ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 50), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ // Blue bars with a lighter center color. - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, fillColorFn: (_, __) => @@ -149,18 +143,18 @@ class StackedFillColorBarChart extends StatelessWidget { ), // Solid red bars. Fill color will default to the series color if no // fillColorFn is configured. - new charts.Series( + charts.Series( id: 'Tablet', - measureFn: (OrdinalSales sales, _) => sales.sales, + measureFn: (sales, _) => sales.sales, data: tableSalesData, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, + domainFn: (sales, _) => sales.year, ), // Hollow green bars. - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, fillColorFn: (_, __) => charts.MaterialPalette.transparent, @@ -171,8 +165,8 @@ class StackedFillColorBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart b/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart index 4659bed6b..a32738380 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,70 +23,64 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedHorizontalBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedHorizontalBarChart(this.seriesList, {this.animate = false}); + const StackedHorizontalBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a stacked [BarChart] with sample data and no transition. - factory StackedHorizontalBarChart.withSampleData() { - return new StackedHorizontalBarChart( + /// Creates a stacked [charts.BarChart] with sample data and no transition. + factory StackedHorizontalBarChart.withSampleData() => StackedHorizontalBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedHorizontalBarChart.withRandomData() { - return new StackedHorizontalBarChart(_createRandomData()); - } + factory StackedHorizontalBarChart.withRandomData() => StackedHorizontalBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -94,7 +90,7 @@ class StackedHorizontalBarChart extends StatelessWidget { @override Widget build(BuildContext context) { // For horizontal bar charts, set the [vertical] flag to false. - return new charts.BarChart( + return charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.stacked, @@ -105,43 +101,43 @@ class StackedHorizontalBarChart extends StatelessWidget { /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -150,8 +146,8 @@ class StackedHorizontalBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/stacked_target_line.dart b/charts_flutter/example/lib/bar_chart/stacked_target_line.dart index b1873dd52..061e822d3 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_target_line.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,113 +23,107 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedBarTargetLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedBarTargetLineChart(this.seriesList, {this.animate = false}); + const StackedBarTargetLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a stacked [BarChart] with sample data and no transition. - factory StackedBarTargetLineChart.withSampleData() { - return new StackedBarTargetLineChart( + /// Creates a stacked [charts.BarChart] with sample data and no transition. + factory StackedBarTargetLineChart.withSampleData() => StackedBarTargetLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedBarTargetLineChart.withRandomData() { - return new StackedBarTargetLineChart(_createRandomData()); - } + factory StackedBarTargetLineChart.withRandomData() => StackedBarTargetLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final desktopTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileTargetLineData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Tablet Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Mobile Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileTargetLineData, ) // Configure our custom bar target renderer for this series. @@ -137,101 +133,99 @@ class StackedBarTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart(seriesList, animate: animate, barGroupingType: charts.BarGroupingType.stacked, customSeriesRenderers: [ - new charts.BarTargetLineRendererConfig( + charts.BarTargetLineRendererConfig( // ID used to link series to this renderer. customRendererId: 'customTargetLine', - groupingType: charts.BarGroupingType.stacked) - ]); - } + groupingType: charts.BarGroupingType.stacked,), + ],); /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final desktopTargetLineData = [ - new OrdinalSales('2014', 4), - new OrdinalSales('2015', 20), - new OrdinalSales('2016', 80), - new OrdinalSales('2017', 65), + OrdinalSales('2014', 4), + OrdinalSales('2015', 20), + OrdinalSales('2016', 80), + OrdinalSales('2017', 65), ]; final tableTargetLineData = [ - new OrdinalSales('2014', 30), - new OrdinalSales('2015', 55), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 25), + OrdinalSales('2014', 30), + OrdinalSales('2015', 55), + OrdinalSales('2016', 15), + OrdinalSales('2017', 25), ]; final mobileTargetLineData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 5), - new OrdinalSales('2016', 45), - new OrdinalSales('2017', 35), + OrdinalSales('2014', 10), + OrdinalSales('2015', 5), + OrdinalSales('2016', 45), + OrdinalSales('2017', 35), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Desktop Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Tablet Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableTargetLineData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), - new charts.Series( + charts.Series( id: 'Mobile Target Line', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileTargetLineData, ) // Configure our custom bar target renderer for this series. @@ -242,8 +236,8 @@ class StackedBarTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart index 387300879..d368bb933 100644 --- a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart +++ b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart @@ -14,55 +14,52 @@ // limitations under the License. /// Vertical bar chart with bar label renderer example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class VerticalBarLabelChart extends StatelessWidget { - final List> seriesList; - final bool animate; - VerticalBarLabelChart(this.seriesList, {this.animate = false}); + const VerticalBarLabelChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory VerticalBarLabelChart.withSampleData() { - return new VerticalBarLabelChart( + /// Creates a [charts.BarChart] with sample data and no transition. + factory VerticalBarLabelChart.withSampleData() => VerticalBarLabelChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory VerticalBarLabelChart.withRandomData() { - return new VerticalBarLabelChart(_createRandomData()); - } + factory VerticalBarLabelChart.withRandomData() => VerticalBarLabelChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '${sales.sales.toString()}') + labelAccessorFn: (sales, _) => + sales.sales,), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -75,8 +72,7 @@ class VerticalBarLabelChart extends StatelessWidget { // Text style for inside / outside can be controlled independently by setting // [insideLabelStyleSpec] and [outsideLabelStyleSpec]. @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Set a bar label decorator. @@ -84,37 +80,36 @@ class VerticalBarLabelChart extends StatelessWidget { // barRendererDecorator: new charts.BarLabelDecorator( // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - barRendererDecorator: new charts.BarLabelDecorator(), - domainAxis: new charts.OrdinalAxisSpec(), + barRendererDecorator: charts.BarLabelDecorator(), + domainAxis: const charts.OrdinalAxisSpec(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (OrdinalSales sales, _) => - '\$${sales.sales.toString()}') + labelAccessorFn: (sales, _) => + '\$${sales.sales}',), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart index c4103d6ec..bde5163db 100644 --- a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart +++ b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart @@ -13,43 +13,40 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/behaviors/chart_title.dart'; +import 'package:example/behaviors/initial_hint_animation.dart'; +import 'package:example/behaviors/initial_selection.dart'; +import 'package:example/behaviors/percent_of_domain.dart'; +import 'package:example/behaviors/percent_of_domain_by_category.dart'; +import 'package:example/behaviors/percent_of_series.dart'; +import 'package:example/behaviors/selection_bar_highlight.dart'; +import 'package:example/behaviors/selection_callback_example.dart'; +import 'package:example/behaviors/selection_line_highlight.dart'; +import 'package:example/behaviors/selection_line_highlight_custom_shape.dart'; +import 'package:example/behaviors/selection_user_managed.dart'; +import 'package:example/behaviors/slider.dart'; +import 'package:example/behaviors/sliding_viewport_on_selection.dart'; +import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'chart_title.dart'; -import 'initial_hint_animation.dart'; -import 'initial_selection.dart'; -import 'percent_of_domain.dart'; -import 'percent_of_domain_by_category.dart'; -import 'percent_of_series.dart'; -import 'selection_bar_highlight.dart'; -import 'selection_line_highlight.dart'; -import 'selection_line_highlight_custom_shape.dart'; -import 'selection_callback_example.dart'; -import 'selection_scatter_plot_highlight.dart'; -import 'selection_user_managed.dart'; -import 'slider.dart'; -import 'sliding_viewport_on_selection.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Selection Bar Highlight', subtitle: 'Simple bar chart with tap activation', - childBuilder: () => new SelectionBarHighlight.withRandomData(), + childBuilder: SelectionBarHighlight.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Selection Line Highlight', subtitle: 'Line chart with tap and drag activation', - childBuilder: () => new SelectionLineHighlight.withRandomData(), + childBuilder: SelectionLineHighlight.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Selection Line Highlight Custom Shape', subtitle: 'Line chart with tap and drag activation and a custom shape', - childBuilder: () => - new SelectionLineHighlightCustomShape.withRandomData(), + childBuilder: SelectionLineHighlightCustomShape.withRandomData, ), //TODO // new GalleryScaffold( @@ -58,70 +55,66 @@ List buildGallery() { // subtitle: 'Scatter plot chart with tap and drag activation', // childBuilder: () => new SelectionScatterPlotHighlight.withRandomData(), // ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Selection Callback Example', subtitle: 'Timeseries that updates external components on selection', - childBuilder: () => new SelectionCallbackExample.withRandomData(), + childBuilder: SelectionCallbackExample.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'User managed selection', subtitle: 'Example where selection can be set and cleared programmatically', - childBuilder: () => new SelectionUserManaged.withRandomData(), + childBuilder: SelectionUserManaged.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Bar Chart with initial selection', subtitle: 'Single series with initial selection', - childBuilder: () => new InitialSelection.withRandomData(), + childBuilder: InitialSelection.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Line Chart with Chart Titles', subtitle: 'Line chart with four chart titles', - childBuilder: () => new ChartTitleLine.withRandomData(), + childBuilder: ChartTitleLine.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'Line Chart with Slider', subtitle: 'Line chart with a slider behavior', - childBuilder: () => new SliderLine.withRandomData(), + childBuilder: SliderLine.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Percent of Domain', - subtitle: 'Stacked bar chart with measures calculated as percent of ' + - 'domain', - childBuilder: () => new PercentOfDomainBarChart.withRandomData(), + subtitle: 'Stacked bar chart with measures calculated as percent of ' 'domain', + childBuilder: PercentOfDomainBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Percent of Domain by Category', subtitle: 'Grouped stacked bar chart with measures calculated as ' 'percent of domain and series category', - childBuilder: () => - new PercentOfDomainByCategoryBarChart.withRandomData(), + childBuilder: PercentOfDomainByCategoryBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Percent of Series', - subtitle: 'Grouped bar chart with measures calculated as percent of ' + - 'series', - childBuilder: () => new PercentOfSeriesBarChart.withRandomData(), + subtitle: 'Grouped bar chart with measures calculated as percent of ' 'series', + childBuilder: PercentOfSeriesBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Sliding viewport on domain selection', subtitle: 'Center viewport on selected domain', - childBuilder: () => new SlidingViewportOnSelection.withRandomData(), + childBuilder: SlidingViewportOnSelection.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Initial hint animation ', subtitle: 'Animate into final viewport', - childBuilder: () => new InitialHintAnimation.withRandomData(), + childBuilder: InitialHintAnimation.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/behaviors/chart_title.dart b/charts_flutter/example/lib/behaviors/chart_title.dart index 5eafc966a..765ae450e 100644 --- a/charts_flutter/example/lib/behaviors/chart_title.dart +++ b/charts_flutter/example/lib/behaviors/chart_title.dart @@ -14,62 +14,56 @@ // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; /// This is a line chart with a title text in every margin. /// -/// A series of [ChartTitle] behaviors are used to render titles, one per +/// A series of [charts.ChartTitle] behaviors are used to render titles, one per /// margin. class ChartTitleLine extends StatelessWidget { - final List> seriesList; - final bool animate; - ChartTitleLine(this.seriesList, {this.animate = false}); + const ChartTitleLine(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory ChartTitleLine.withSampleData() { - return new ChartTitleLine( + /// Creates a [charts.LineChart] with sample data and no transition. + factory ChartTitleLine.withSampleData() => ChartTitleLine( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ChartTitleLine.withRandomData() { - return new ChartTitleLine(_createRandomData()); - } + factory ChartTitleLine.withRandomData() => ChartTitleLine(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart( + Widget build(BuildContext context) => charts.LineChart( seriesList, animate: animate, // Configures four [ChartTitle] behaviors to render titles in each chart @@ -77,7 +71,7 @@ class ChartTitleLine extends StatelessWidget { // of the chart. The other titles are aligned with the middle of the draw // area. behaviors: [ - new charts.ChartTitle('Top title text', + charts.ChartTitle('Top title text', subTitle: 'Top sub-title text', behaviorPosition: charts.BehaviorPosition.top, titleOutsideJustification: charts.OutsideJustification.start, @@ -85,47 +79,46 @@ class ChartTitleLine extends StatelessWidget { // rendering the text too close to the top measure axis tick label. // The top tick label may extend upwards into the top margin region // if it is located at the top of the draw area. - innerPadding: 18), - new charts.ChartTitle('Bottom title text', + innerPadding: 18,), + charts.ChartTitle('Bottom title text', behaviorPosition: charts.BehaviorPosition.bottom, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea), - new charts.ChartTitle('Start title', + charts.OutsideJustification.middleDrawArea,), + charts.ChartTitle('Start title', behaviorPosition: charts.BehaviorPosition.start, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea), - new charts.ChartTitle('End title', + charts.OutsideJustification.middleDrawArea,), + charts.ChartTitle('End title', behaviorPosition: charts.BehaviorPosition.end, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea), + charts.OutsideJustification.middleDrawArea,), ], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart index 1cc4aa311..a0b8a8866 100644 --- a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart +++ b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart @@ -19,7 +19,7 @@ /// "Initial hint animation". /// /// This behavior is intended to be used with charts that also have pan/zoom -/// behaviors added and/or the initial viewport set in [AxisSpec]. +/// behaviors added and/or the initial viewport set in [charts.AxisSpec]. /// /// Adding this behavior will cause the chart to animate from a scale and/or /// offset of the desired final viewport. If the user taps the widget prior @@ -35,80 +35,76 @@ /// /// In this example, the series list has ordinal data from year 2014 to 2030, /// and we have the initial viewport set to start at 2018 that shows 4 values by -/// specifying an [OrdinalViewport] in [OrdinalAxisSpec]. We can add the hint -/// animation by adding behavior [InitialHintBehavior] with [maxHintTranslate] +/// specifying an [charts.OrdinalViewport] in [charts.OrdinalAxisSpec]. We can add the hint +/// animation by adding behavior [charts.InitialHintBehavior] with [maxHintTranslate] /// of 4. When the chart is drawn for the first time, the viewport will show /// 2022 as the first value and the viewport will animate by panning values to /// the right until 2018 is the first value in the viewport. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class InitialHintAnimation extends StatelessWidget { - final List> seriesList; - final bool animate; - InitialHintAnimation(this.seriesList, {this.animate = false}); + const InitialHintAnimation(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory InitialHintAnimation.withSampleData() { - return new InitialHintAnimation( + /// Creates a [charts.BarChart] with sample data and no transition. + factory InitialHintAnimation.withSampleData() => InitialHintAnimation( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory InitialHintAnimation.withRandomData() { - return new InitialHintAnimation(_createRandomData()); - } + factory InitialHintAnimation.withRandomData() => InitialHintAnimation(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), - new OrdinalSales('2018', random.nextInt(100)), - new OrdinalSales('2019', random.nextInt(100)), - new OrdinalSales('2020', random.nextInt(100)), - new OrdinalSales('2021', random.nextInt(100)), - new OrdinalSales('2022', random.nextInt(100)), - new OrdinalSales('2023', random.nextInt(100)), - new OrdinalSales('2024', random.nextInt(100)), - new OrdinalSales('2025', random.nextInt(100)), - new OrdinalSales('2026', random.nextInt(100)), - new OrdinalSales('2027', random.nextInt(100)), - new OrdinalSales('2028', random.nextInt(100)), - new OrdinalSales('2029', random.nextInt(100)), - new OrdinalSales('2030', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2018', random.nextInt(100)), + OrdinalSales('2019', random.nextInt(100)), + OrdinalSales('2020', random.nextInt(100)), + OrdinalSales('2021', random.nextInt(100)), + OrdinalSales('2022', random.nextInt(100)), + OrdinalSales('2023', random.nextInt(100)), + OrdinalSales('2024', random.nextInt(100)), + OrdinalSales('2025', random.nextInt(100)), + OrdinalSales('2026', random.nextInt(100)), + OrdinalSales('2027', random.nextInt(100)), + OrdinalSales('2028', random.nextInt(100)), + OrdinalSales('2029', random.nextInt(100)), + OrdinalSales('2030', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, // Optionally turn off the animation that animates values up from the @@ -117,59 +113,58 @@ class InitialHintAnimation extends StatelessWidget { animationDuration: Duration.zero, // Set the initial viewport by providing a new AxisSpec with the // desired viewport: a starting domain and the data size. - domainAxis: new charts.OrdinalAxisSpec( - viewport: new charts.OrdinalViewport('2018', 4)), + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4),), behaviors: [ // Add this behavior to show initial hint animation that will pan to the // final desired viewport. // The duration of the animation can be adjusted by pass in // [hintDuration]. By default this is 3000ms. - new charts.InitialHintBehavior(maxHintTranslate: 4.0), + charts.InitialHintBehavior(maxHintTranslate: 4), // Optionally add a pan or pan and zoom behavior. // If pan/zoom is not added, the viewport specified remains the viewport - new charts.PanAndZoomBehavior(), + charts.PanAndZoomBehavior(), ], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), - new OrdinalSales('2018', 33), - new OrdinalSales('2019', 80), - new OrdinalSales('2020', 21), - new OrdinalSales('2021', 77), - new OrdinalSales('2022', 8), - new OrdinalSales('2023', 12), - new OrdinalSales('2024', 42), - new OrdinalSales('2025', 70), - new OrdinalSales('2026', 77), - new OrdinalSales('2027', 55), - new OrdinalSales('2028', 19), - new OrdinalSales('2029', 66), - new OrdinalSales('2030', 27), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), + OrdinalSales('2018', 33), + OrdinalSales('2019', 80), + OrdinalSales('2020', 21), + OrdinalSales('2021', 77), + OrdinalSales('2022', 8), + OrdinalSales('2023', 12), + OrdinalSales('2024', 42), + OrdinalSales('2025', 70), + OrdinalSales('2026', 77), + OrdinalSales('2027', 55), + OrdinalSales('2028', 19), + OrdinalSales('2029', 66), + OrdinalSales('2030', 27), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/initial_selection.dart b/charts_flutter/example/lib/behaviors/initial_selection.dart index 924913da5..61a2a424d 100644 --- a/charts_flutter/example/lib/behaviors/initial_selection.dart +++ b/charts_flutter/example/lib/behaviors/initial_selection.dart @@ -23,62 +23,58 @@ /// /// The selection will remain on the chart unless another behavior is added /// that updates the selection. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class InitialSelection extends StatelessWidget { - final List> seriesList; - final bool animate; - InitialSelection(this.seriesList, {this.animate = false}); + const InitialSelection(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with initial selection behavior. - factory InitialSelection.withSampleData() { - return new InitialSelection( + /// Creates a [charts.BarChart] with initial selection behavior. + factory InitialSelection.withSampleData() => InitialSelection( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory InitialSelection.withRandomData() { - return new InitialSelection(_createRandomData()); - } + factory InitialSelection.withRandomData() => InitialSelection(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, behaviors: [ @@ -92,38 +88,37 @@ class InitialSelection extends StatelessWidget { // [BarChart] by default includes behaviors [SelectNearest] and // [DomainHighlighter]. So this behavior shows the initial selection // highlighted and when another datum is tapped, the selection changes. - new charts.InitialSelection(selectedDataConfig: [ - new charts.SeriesDatumConfig('Sales', '2016') - ]) + charts.InitialSelection(selectedDataConfig: [ + charts.SeriesDatumConfig('Sales', '2016'), + ],), ], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/percent_of_domain.dart b/charts_flutter/example/lib/behaviors/percent_of_domain.dart index 866c2fddc..3768cfd73 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_domain.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_domain.dart @@ -17,6 +17,8 @@ /// /// Each bar stack shows the percentage of each measure out of the total measure /// value of the stack. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -24,70 +26,64 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfDomainBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PercentOfDomainBarChart(this.seriesList, {this.animate = false}); + const PercentOfDomainBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a stacked [BarChart] with sample data and no transition. - factory PercentOfDomainBarChart.withSampleData() { - return new PercentOfDomainBarChart( + /// Creates a stacked [charts.BarChart] with sample data and no transition. + factory PercentOfDomainBarChart.withSampleData() => PercentOfDomainBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfDomainBarChart.withRandomData() { - return new PercentOfDomainBarChart(_createRandomData()); - } + factory PercentOfDomainBarChart.withRandomData() => PercentOfDomainBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -95,8 +91,7 @@ class PercentOfDomainBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.stacked, @@ -104,54 +99,53 @@ class PercentOfDomainBarChart extends StatelessWidget { // values as the percentage of the total of all data that shares a // domain value. behaviors: [ - new charts.PercentInjector( - totalType: charts.PercentInjectorTotalType.domain) + charts.PercentInjector( + ,), ], // Configure the axis spec to show percentage values. - primaryMeasureAxis: new charts.PercentAxisSpec(), + primaryMeasureAxis: charts.PercentAxisSpec(), ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), ]; @@ -160,8 +154,8 @@ class PercentOfDomainBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart index ce2471e5f..6001e4e16 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart @@ -18,6 +18,8 @@ /// /// Each bar stack shows the percentage of each measure out of the total measure /// value of the stack. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,114 +27,108 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfDomainByCategoryBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PercentOfDomainByCategoryBarChart(this.seriesList, {this.animate = false}); + const PercentOfDomainByCategoryBarChart(this.seriesList, {super.key, this.animate = false}); - factory PercentOfDomainByCategoryBarChart.withSampleData() { - return new PercentOfDomainByCategoryBarChart( + factory PercentOfDomainByCategoryBarChart.withSampleData() => PercentOfDomainByCategoryBarChart( createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfDomainByCategoryBarChart.withRandomData() { - return new PercentOfDomainByCategoryBarChart(_createRandomData()); - } + factory PercentOfDomainByCategoryBarChart.withRandomData() => PercentOfDomainByCategoryBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -140,8 +136,7 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.groupedStacked, @@ -153,99 +148,98 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget { // total value for each bar stack is 100%. A stacked bar chart that does // not group by series category would use the "domain" option. behaviors: [ - new charts.PercentInjector( - totalType: charts.PercentInjectorTotalType.domainBySeriesCategory) + charts.PercentInjector( + totalType: charts.PercentInjectorTotalType.domainBySeriesCategory,), ], // Configure the axis spec to show percentage values. - primaryMeasureAxis: new charts.PercentAxisSpec(), + primaryMeasureAxis: charts.PercentAxisSpec(), ); - } /// Create series list with multiple series static List> createSampleData() { final desktopSalesDataA = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataA = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataA = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final desktopSalesDataB = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesDataB = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesDataB = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataA, ), - new charts.Series( + charts.Series( id: 'Tablet A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataA, ), - new charts.Series( + charts.Series( id: 'Mobile A', seriesCategory: 'A', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataA, ), - new charts.Series( + charts.Series( id: 'Desktop B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesDataB, ), - new charts.Series( + charts.Series( id: 'Tablet B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesDataB, ), - new charts.Series( + charts.Series( id: 'Mobile B', seriesCategory: 'B', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesDataB, ), ]; @@ -254,8 +248,8 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/percent_of_series.dart b/charts_flutter/example/lib/behaviors/percent_of_series.dart index 25846f62d..01b4f981b 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_series.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_series.dart @@ -15,6 +15,8 @@ /// Example of a percentage bar chart which shows each bar as the percentage of /// the total series measure value. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -22,48 +24,42 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfSeriesBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PercentOfSeriesBarChart(this.seriesList, {this.animate = false}); + const PercentOfSeriesBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a stacked [BarChart] with sample data and no transition. - factory PercentOfSeriesBarChart.withSampleData() { - return new PercentOfSeriesBarChart( + /// Creates a stacked [charts.BarChart] with sample data and no transition. + factory PercentOfSeriesBarChart.withSampleData() => PercentOfSeriesBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfSeriesBarChart.withRandomData() { - return new PercentOfSeriesBarChart(_createRandomData()); - } + factory PercentOfSeriesBarChart.withRandomData() => PercentOfSeriesBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), ]; @@ -71,40 +67,38 @@ class PercentOfSeriesBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, // Configures a [PercentInjector] behavior that will calculate measure // values as the percentage of the total of all data in its series. behaviors: [ - new charts.PercentInjector( - totalType: charts.PercentInjectorTotalType.series) + charts.PercentInjector( + totalType: charts.PercentInjectorTotalType.series,), ], // Configure the axis spec to show percentage values. - primaryMeasureAxis: new charts.PercentAxisSpec(), + primaryMeasureAxis: charts.PercentAxisSpec(), ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2011', 5), - new OrdinalSales('2012', 25), - new OrdinalSales('2013', 50), - new OrdinalSales('2014', 75), - new OrdinalSales('2015', 100), - new OrdinalSales('2016', 125), - new OrdinalSales('2017', 200), - new OrdinalSales('2018', 150), + OrdinalSales('2011', 5), + OrdinalSales('2012', 25), + OrdinalSales('2013', 50), + OrdinalSales('2014', 75), + OrdinalSales('2015', 100), + OrdinalSales('2016', 125), + OrdinalSales('2017', 200), + OrdinalSales('2018', 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), ]; @@ -113,8 +107,8 @@ class PercentOfSeriesBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart index d4e7f6731..9b0edfc9c 100644 --- a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart @@ -14,51 +14,46 @@ // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionBarHighlight extends StatelessWidget { - final List> seriesList; - final bool animate; - SelectionBarHighlight(this.seriesList, {this.animate = false}); + const SelectionBarHighlight(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory SelectionBarHighlight.withSampleData() { - return new SelectionBarHighlight( + /// Creates a [charts.BarChart] with sample data and no transition. + factory SelectionBarHighlight.withSampleData() => SelectionBarHighlight( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionBarHighlight.withRandomData() { - return new SelectionBarHighlight(_createRandomData()); - } + factory SelectionBarHighlight.withRandomData() => SelectionBarHighlight(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -74,37 +69,36 @@ class SelectionBarHighlight extends StatelessWidget { // // [defaultInteractions] can be set to false to avoid the default // interactions. - return new charts.BarChart( + return charts.BarChart( seriesList, animate: animate, - defaultInteractions: true, ); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/selection_callback_example.dart b/charts_flutter/example/lib/behaviors/selection_callback_example.dart index 457c806c6..4ff7ba850 100644 --- a/charts_flutter/example/lib/behaviors/selection_callback_example.dart +++ b/charts_flutter/example/lib/behaviors/selection_callback_example.dart @@ -16,76 +16,73 @@ /// Timeseries chart with example of updating external state based on selection. /// /// A SelectionModelConfig can be provided for each of the different -/// [SelectionModel] (currently info and action). +/// [charts.SelectionModel] (currently info and action). /// -/// [SelectionModelType.info] is the default selection chart exploration type +/// [charts.SelectionModelType.info] is the default selection chart exploration type /// initiated by some tap event. This is a different model from -/// [SelectionModelType.action] which is typically used to select some value as +/// [charts.SelectionModelType.action] which is typically used to select some value as /// an input to some other UI component. This allows dual state of exploring /// and selecting data via different touch events. /// -/// See [SelectNearest] behavior on setting the different ways of triggering -/// [SelectionModel] updates from hover & click events. +/// See [charts.SelectNearest] behavior on setting the different ways of triggering +/// [charts.SelectionModel] updates from hover & click events. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionCallbackExample extends StatefulWidget { - final List> seriesList; - final bool animate; - SelectionCallbackExample(this.seriesList, {this.animate = false}); + const SelectionCallbackExample(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory SelectionCallbackExample.withSampleData() { - return new SelectionCallbackExample( + factory SelectionCallbackExample.withSampleData() => SelectionCallbackExample( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionCallbackExample.withRandomData() { - return new SelectionCallbackExample(_createRandomData()); - } + factory SelectionCallbackExample.withRandomData() => SelectionCallbackExample(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final us_data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + final usData = [ + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; - final uk_data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + final ukData = [ + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'US Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: us_data, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: usData, ), - new charts.Series( + charts.Series( id: 'UK Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: uk_data, - ) + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: ukData, + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -93,37 +90,37 @@ class SelectionCallbackExample extends StatefulWidget { // We need a Stateful widget to build the selection details with the current // selection as the state. @override - State createState() => new _SelectionCallbackState(); + State createState() => _SelectionCallbackState(); /// Create one series with sample hard coded data. static List> _createSampleData() { - final us_data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 78), - new TimeSeriesSales(new DateTime(2017, 10, 10), 54), + final usData = [ + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 78), + TimeSeriesSales(DateTime(2017, 10, 10), 54), ]; - final uk_data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 15), - new TimeSeriesSales(new DateTime(2017, 9, 26), 33), - new TimeSeriesSales(new DateTime(2017, 10, 3), 68), - new TimeSeriesSales(new DateTime(2017, 10, 10), 48), + final ukData = [ + TimeSeriesSales(DateTime(2017, 9, 19), 15), + TimeSeriesSales(DateTime(2017, 9, 26), 33), + TimeSeriesSales(DateTime(2017, 10, 3), 68), + TimeSeriesSales(DateTime(2017, 10, 10), 48), ]; return [ - new charts.Series( + charts.Series( id: 'US Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: us_data, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: usData, ), - new charts.Series( + charts.Series( id: 'UK Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: uk_data, - ) + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: ukData, + ), ]; } } @@ -148,9 +145,9 @@ class _SelectionCallbackState extends State { // series name for each selection point. if (selectedDatum.isNotEmpty) { time = selectedDatum.first.datum.time; - selectedDatum.forEach((charts.SeriesDatum datumPair) { + for (final datumPair in selectedDatum) { measures[datumPair.series.displayName!] = datumPair.datum.sales; - }); + } } // Request a build. @@ -164,38 +161,37 @@ class _SelectionCallbackState extends State { Widget build(BuildContext context) { // The children consist of a Chart and Text widgets below to hold the info. final children = [ - new SizedBox( - height: 150.0, - child: new charts.TimeSeriesChart( + SizedBox( + height: 150, + child: charts.TimeSeriesChart( widget.seriesList, animate: widget.animate, selectionModels: [ - new charts.SelectionModelConfig( - type: charts.SelectionModelType.info, + charts.SelectionModelConfig( changedListener: _onSelectionChanged, - ) + ), ], - )), + ),), ]; // If there is a selection, then include the details. if (_time != null) { - children.add(new Padding( - padding: new EdgeInsets.only(top: 5.0), - child: new Text(_time.toString()))); + children.add(Padding( + padding: const EdgeInsets.only(top: 5), + child: Text(_time.toString()),),); } - _measures.forEach((String series, num value) { - children.add(new Text('${series}: ${value}')); + _measures.forEach((series, value) { + children.add(Text('$series: $value')); }); - return new Column(children: children); + return Column(children: children); } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart index 99b998810..3ff2c0b9f 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart @@ -14,51 +14,46 @@ // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionLineHighlight extends StatelessWidget { - final List> seriesList; - final bool animate; - SelectionLineHighlight(this.seriesList, {this.animate = false}); + const SelectionLineHighlight(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SelectionLineHighlight.withSampleData() { - return new SelectionLineHighlight( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SelectionLineHighlight.withSampleData() => SelectionLineHighlight( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionLineHighlight.withRandomData() { - return new SelectionLineHighlight(_createRandomData()); - } + factory SelectionLineHighlight.withRandomData() => SelectionLineHighlight(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -75,7 +70,7 @@ class SelectionLineHighlight extends StatelessWidget { // // As an alternative, [defaultInteractions] can be set to true to include // the default chart interactions, including a LinePointHighlighter. - return new charts.LineChart(seriesList, animate: animate, behaviors: [ + return charts.LineChart(seriesList, animate: animate, behaviors: [ // Optional - Configures a [LinePointHighlighter] behavior with a // vertical follow line. A vertical follow line is included by // default, but is shown here as an example configuration. @@ -84,44 +79,44 @@ class SelectionLineHighlight extends StatelessWidget { // set by providing a [dashPattern] or it can be turned off by passing in // an empty list. An empty list is necessary because passing in a null // value will be treated the same as not passing in a value at all. - new charts.LinePointHighlighter( + charts.LinePointHighlighter( showHorizontalFollowLine: charts.LinePointHighlighterFollowLineType.none, showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest), + charts.LinePointHighlighterFollowLineType.nearest,), // Optional - By default, select nearest is configured to trigger // with tap so that a user can have pan/zoom behavior and line point // highlighter. Changing the trigger to tap and drag allows the // highlighter to follow the dragging gesture but it is not // recommended to be used when pan/zoom behavior is enabled. - new charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag) - ]); + charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), + ],); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart index e030bcebe..3740682d6 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart @@ -14,51 +14,46 @@ // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionLineHighlightCustomShape extends StatelessWidget { - final List> seriesList; - final bool animate; - SelectionLineHighlightCustomShape(this.seriesList, {this.animate = false}); + const SelectionLineHighlightCustomShape(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SelectionLineHighlightCustomShape.withSampleData() { - return new SelectionLineHighlightCustomShape( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SelectionLineHighlightCustomShape.withSampleData() => SelectionLineHighlightCustomShape( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionLineHighlightCustomShape.withRandomData() { - return new SelectionLineHighlightCustomShape(_createRandomData()); - } + factory SelectionLineHighlightCustomShape.withRandomData() => SelectionLineHighlightCustomShape(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -74,7 +69,7 @@ class SelectionLineHighlightCustomShape extends StatelessWidget { // // As an alternative, [defaultInteractions] can be set to true to include // the default chart interactions, including a LinePointHighlighter. - return new charts.LineChart(seriesList, animate: animate, behaviors: [ + return charts.LineChart(seriesList, animate: animate, behaviors: [ // Optional - Configures a [LinePointHighlighter] behavior with a // vertical follow line. A vertical follow line is included by // default, but is shown here as an example configuration. @@ -86,45 +81,45 @@ class SelectionLineHighlightCustomShape extends StatelessWidget { // // The symbol renderer is configured to render a hollow shape, for // demonstration. - new charts.LinePointHighlighter( + charts.LinePointHighlighter( showHorizontalFollowLine: charts.LinePointHighlighterFollowLineType.none, showVerticalFollowLine: charts.LinePointHighlighterFollowLineType.nearest, - symbolRenderer: new charts.RectSymbolRenderer(isSolid: false)), + symbolRenderer: charts.RectSymbolRenderer(isSolid: false),), // Optional - By default, select nearest is configured to trigger // with tap so that a user can have pan/zoom behavior and line point // highlighter. Changing the trigger to tap and drag allows the // highlighter to follow the dragging gesture but it is not // recommended to be used when pan/zoom behavior is enabled. - new charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag) - ]); + charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), + ],); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart index 410c3b3bd..46c13369f 100644 --- a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart @@ -31,77 +31,74 @@ /// defined. Configuring a separate fillColor will cause the center of the shape /// to be filled in, with white in these examples. The border of the shape will /// be color with the color of the data. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionScatterPlotHighlight extends StatelessWidget { - final List> seriesList; - final bool animate; - SelectionScatterPlotHighlight(this.seriesList, {this.animate = false}); + const SelectionScatterPlotHighlight(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory SelectionScatterPlotHighlight.withSampleData() { - return new SelectionScatterPlotHighlight( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory SelectionScatterPlotHighlight.withSampleData() => SelectionScatterPlotHighlight( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionScatterPlotHighlight.withRandomData() { - return new SelectionScatterPlotHighlight(_createRandomData()); - } + factory SelectionScatterPlotHighlight.withRandomData() => SelectionScatterPlotHighlight(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final data = [ - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + 'circle', null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow circle, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + 'circle', null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow circle, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow square, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, null, charts.MaterialPalette.white, 2.0), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, null, charts.MaterialPalette.white, 2,), ]; - final maxMeasure = 100; + const maxMeasure = 100; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -113,25 +110,24 @@ class SelectionScatterPlotHighlight extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, - fillColorFn: (LinearSales row, _) => row.fillColor, - strokeWidthPxFn: (LinearSales row, _) => row.strokeWidth, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, + fillColorFn: (row, _) => row.fillColor, + strokeWidthPxFn: (row, _) => row.strokeWidth, data: data, ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (int index) => data[index].shape) + charts.pointSymbolRendererFnKey, (index) => data[index].shape,) // Default symbol renderer ID for data that have no defined shape. - ..setAttribute(charts.pointSymbolRendererIdKey, 'rect') + ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate, behaviors: [ // Optional - Configures a [LinePointHighlighter] behavior with @@ -143,57 +139,56 @@ class SelectionScatterPlotHighlight extends StatelessWidget { // in an empty list. An empty list is necessary because passing in a // null value will be treated the same as not passing in a value at // all. - new charts.LinePointHighlighter( + charts.LinePointHighlighter( showHorizontalFollowLine: charts.LinePointHighlighterFollowLineType.nearest, showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest), + charts.LinePointHighlighterFollowLineType.nearest,), // Optional - By default, select nearest is configured to trigger // with tap so that a user can have pan/zoom behavior and line point // highlighter. Changing the trigger to tap and drag allows the // highlighter to follow the dragging gesture but it is not // recommended to be used when pan/zoom behavior is enabled. - new charts.SelectNearest( - eventTrigger: charts.SelectionTrigger.tapAndDrag), + charts.SelectNearest( + eventTrigger: charts.SelectionTrigger.tapAndDrag,), ], // Configure the point renderer to have a map of custom symbol // renderers. defaultRenderer: - new charts.PointRendererConfig(customSymbolRenderers: { - 'circle': new charts.CircleSymbolRenderer(), - 'rect': new charts.RectSymbolRenderer(), - })); - } + charts.PointRendererConfig(customSymbolRenderers: { + 'circle': charts.CircleSymbolRenderer(), + 'rect': charts.RectSymbolRenderer(), + },),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5, 3.0, 'circle', null, null), - new LinearSales(10, 25, 5.0, null, null, null), - new LinearSales(12, 75, 4.0, null, null, null), + LinearSales(0, 5, 3, 'circle', null, null), + LinearSales(10, 25, 5, null, null, null), + LinearSales(12, 75, 4, null, null, null), // Render a hollow circle, filled in with white. - new LinearSales( - 13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(16, 50, 4.0, null, null, null), - new LinearSales(24, 75, 3.0, null, null, null), - new LinearSales(25, 100, 3.0, 'circle', null, null), - new LinearSales(34, 150, 5.0, null, null, null), - new LinearSales(37, 10, 4.5, null, null, null), + LinearSales( + 13, 225, 5, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(16, 50, 4, null, null, null), + LinearSales(24, 75, 3, null, null, null), + LinearSales(25, 100, 3, 'circle', null, null), + LinearSales(34, 150, 5, null, null, null), + LinearSales(37, 10, 4.5, null, null, null), // Render a hollow circle, filled in with white. - new LinearSales( - 45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(52, 15, 4.0, null, null, null), + LinearSales( + 45, 300, 8, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(52, 15, 4, null, null, null), // Render a hollow square, filled in with white. - new LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0), + LinearSales(56, 200, 7, null, charts.MaterialPalette.white, 2), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -205,31 +200,31 @@ class SelectionScatterPlotHighlight extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, - fillColorFn: (LinearSales row, _) => row.fillColor, - strokeWidthPxFn: (LinearSales row, _) => row.strokeWidth, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, + fillColorFn: (row, _) => row.fillColor, + strokeWidthPxFn: (row, _) => row.strokeWidth, data: data, ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (int index) => data[index].shape) + charts.pointSymbolRendererFnKey, (index) => data[index].shape,) // Default symbol renderer ID for data that have no defined shape. - ..setAttribute(charts.pointSymbolRendererIdKey, 'rect') + ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, + this.strokeWidth,); final int year; final int sales; final double radius; final String? shape; final charts.Color? fillColor; final double? strokeWidth; - - LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, - this.strokeWidth); } diff --git a/charts_flutter/example/lib/behaviors/selection_user_managed.dart b/charts_flutter/example/lib/behaviors/selection_user_managed.dart index 5a84deb96..91a70b3f7 100644 --- a/charts_flutter/example/lib/behaviors/selection_user_managed.dart +++ b/charts_flutter/example/lib/behaviors/selection_user_managed.dart @@ -22,54 +22,51 @@ /// Note that the picture in this example is not interactive, please run the /// gallery app to try out using the button to clear selection. /// +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SelectionUserManaged extends StatefulWidget { - final List> seriesList; - final bool animate; - SelectionUserManaged(this.seriesList, {this.animate = false}); + const SelectionUserManaged(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory SelectionUserManaged.withSampleData() { - return new SelectionUserManaged( + /// Creates a [charts.BarChart] with sample data and no transition. + factory SelectionUserManaged.withSampleData() => SelectionUserManaged( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionUserManaged.withRandomData() { - return new SelectionUserManaged(_createRandomData()); - } + factory SelectionUserManaged.withRandomData() => SelectionUserManaged(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -77,41 +74,38 @@ class SelectionUserManaged extends StatefulWidget { /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } @override - SelectionUserManagedState createState() { - return new SelectionUserManagedState(); - } + SelectionUserManagedState createState() => SelectionUserManagedState(); } class SelectionUserManagedState extends State { - final _myState = new charts.UserManagedState(); + final _myState = charts.UserManagedState(); @override Widget build(BuildContext context) { - final chart = new charts.BarChart( + final chart = charts.BarChart( widget.seriesList, animate: false, //widget.animate, selectionModels: [ - new charts.SelectionModelConfig( - type: charts.SelectionModelType.info, - updatedListener: _infoSelectionModelUpdated) + charts.SelectionModelConfig( + updatedListener: _infoSelectionModelUpdated,), ], // Pass in the state you manage to the chart. This will be used to // override the internal chart state. @@ -119,17 +113,17 @@ class SelectionUserManagedState extends State { // The initial selection can still be optionally added by adding the // initial selection behavior. behaviors: [ - new charts.InitialSelection(selectedDataConfig: [ - new charts.SeriesDatumConfig('Sales', '2016') - ]) + charts.InitialSelection(selectedDataConfig: [ + charts.SeriesDatumConfig('Sales', '2016'), + ],), ], ); - final clearSelection = new MaterialButton( - onPressed: _handleClearSelection, child: new Text('Clear Selection')); + final clearSelection = MaterialButton( + onPressed: _handleClearSelection, child: const Text('Clear Selection'),); - return new Column( - children: [new SizedBox(height: 150.0, child: chart), clearSelection]); + return Column( + children: [SizedBox(height: 150, child: chart), clearSelection],); } void _infoSelectionModelUpdated(charts.SelectionModel model) { @@ -141,7 +135,7 @@ class SelectionUserManagedState extends State { // This also allows you to listen to the selection model update events and // alter the selection. _myState.selectionModels[charts.SelectionModelType.info] = - new charts.UserManagedSelectionModel(model: model); + charts.UserManagedSelectionModel(model: model); } void _handleClearSelection() { @@ -150,15 +144,15 @@ class SelectionUserManagedState extends State { // no selection model to clear all selection when rebuilt. setState(() { _myState.selectionModels[charts.SelectionModelType.info] = - new charts.UserManagedSelectionModel(); + charts.UserManagedSelectionModel(); }); } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/slider.dart b/charts_flutter/example/lib/behaviors/slider.dart index ebc150787..e6a623b63 100644 --- a/charts_flutter/example/lib/behaviors/slider.dart +++ b/charts_flutter/example/lib/behaviors/slider.dart @@ -14,10 +14,12 @@ // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + // EXCLUDE_FROM_GALLERY_DOCS_END -import 'package:nimble_charts/flutter.dart' as charts; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; +import 'package:nimble_charts/flutter.dart' as charts; +import 'package:nimble_charts/flutter.dart'; /// This is just a simple line chart with a behavior that adds slider controls. /// @@ -29,49 +31,43 @@ import 'package:flutter/scheduler.dart'; /// will be fired when the chart is drawn because an initial domain value is /// set. /// -/// [Slider.moveSliderToDomain] can be called to programmatically position the +/// [charts.Slider.moveSliderToDomain] can be called to programmatically position the /// slider. This is useful for synchronizing the slider with external elements. class SliderLine extends StatefulWidget { - final List> seriesList; - final bool animate; - SliderLine(this.seriesList, {this.animate = false}); + const SliderLine(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SliderLine.withSampleData() { - return new SliderLine( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SliderLine.withSampleData() => SliderLine( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SliderLine.withRandomData() { - return new SliderLine(_createRandomData()); - } + factory SliderLine.withRandomData() => SliderLine(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -79,24 +75,24 @@ class SliderLine extends StatefulWidget { // We need a Stateful widget to build the selection details with the current // selection as the state. @override - State createState() => new _SliderCallbackState(); + State createState() => _SliderCallbackState(); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } @@ -107,8 +103,8 @@ class _SliderCallbackState extends State { Point? _sliderPosition; // Handles callbacks when the user drags the slider. - _onSliderChange(Point point, dynamic domain, String roleId, - charts.SliderListenerDragState dragState) { + _onSliderChange(Point point, domain, String roleId, + charts.SliderListenerDragState dragState,) { // Request a build. void rebuild(_) { setState(() { @@ -125,9 +121,9 @@ class _SliderCallbackState extends State { Widget build(BuildContext context) { // The children consist of a Chart and Text widgets below to hold the info. final children = [ - new SizedBox( - height: 150.0, - child: new charts.LineChart( + SizedBox( + height: 150, + child: charts.LineChart( widget.seriesList, animate: widget.animate, // Configures a [Slider] behavior. @@ -158,38 +154,38 @@ class _SliderCallbackState extends State { // [style] takes in a [SliderStyle] configuration object, and // configures the color and sizing of the slider line and handle. behaviors: [ - new charts.Slider( - initialDomainValue: 1.0, onChangeCallback: _onSliderChange), + charts.Slider( + initialDomainValue: 1.0, onChangeCallback: _onSliderChange,), ], - )), + ),), ]; // If there is a slider change event, then include the details. if (_sliderDomainValue != null) { - children.add(new Padding( - padding: new EdgeInsets.only(top: 5.0), - child: new Text('Slider domain value: ${_sliderDomainValue}'))); + children.add(Padding( + padding: const EdgeInsets.only(top: 5), + child: Text('Slider domain value: $_sliderDomainValue'),),); } if (_sliderPosition != null) { - children.add(new Padding( - padding: new EdgeInsets.only(top: 5.0), - child: new Text( - 'Slider position: ${_sliderPosition!.x}, ${_sliderPosition!.y}'))); + children.add(Padding( + padding: const EdgeInsets.only(top: 5), + child: Text( + 'Slider position: ${_sliderPosition!.x}, ${_sliderPosition!.y}',),),); } if (_sliderDragState != null) { - children.add(new Padding( - padding: new EdgeInsets.only(top: 5.0), - child: new Text('Slider drag state: ${_sliderDragState}'))); + children.add(Padding( + padding: const EdgeInsets.only(top: 5), + child: Text('Slider drag state: $_sliderDragState'),),); } - return new Column(children: children); + return Column(children: children); } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart index 33a5bc05e..0441221a2 100644 --- a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart +++ b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart @@ -14,131 +14,126 @@ // limitations under the License. /// Example of the chart behavior that centers the viewport on domain selection. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SlidingViewportOnSelection extends StatelessWidget { - final List> seriesList; - final bool animate; - SlidingViewportOnSelection(this.seriesList, {this.animate = false}); + const SlidingViewportOnSelection(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory SlidingViewportOnSelection.withSampleData() { - return new SlidingViewportOnSelection( + /// Creates a [charts.BarChart] with sample data and no transition. + factory SlidingViewportOnSelection.withSampleData() => SlidingViewportOnSelection( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SlidingViewportOnSelection.withRandomData() { - return new SlidingViewportOnSelection(_createRandomData()); - } + factory SlidingViewportOnSelection.withRandomData() => SlidingViewportOnSelection(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), - new OrdinalSales('2018', random.nextInt(100)), - new OrdinalSales('2019', random.nextInt(100)), - new OrdinalSales('2020', random.nextInt(100)), - new OrdinalSales('2021', random.nextInt(100)), - new OrdinalSales('2022', random.nextInt(100)), - new OrdinalSales('2023', random.nextInt(100)), - new OrdinalSales('2024', random.nextInt(100)), - new OrdinalSales('2025', random.nextInt(100)), - new OrdinalSales('2026', random.nextInt(100)), - new OrdinalSales('2027', random.nextInt(100)), - new OrdinalSales('2028', random.nextInt(100)), - new OrdinalSales('2029', random.nextInt(100)), - new OrdinalSales('2030', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2018', random.nextInt(100)), + OrdinalSales('2019', random.nextInt(100)), + OrdinalSales('2020', random.nextInt(100)), + OrdinalSales('2021', random.nextInt(100)), + OrdinalSales('2022', random.nextInt(100)), + OrdinalSales('2023', random.nextInt(100)), + OrdinalSales('2024', random.nextInt(100)), + OrdinalSales('2025', random.nextInt(100)), + OrdinalSales('2026', random.nextInt(100)), + OrdinalSales('2027', random.nextInt(100)), + OrdinalSales('2028', random.nextInt(100)), + OrdinalSales('2029', random.nextInt(100)), + OrdinalSales('2030', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, behaviors: [ // Add the sliding viewport behavior to have the viewport center on the // domain that is currently selected. - new charts.SlidingViewport(), + charts.SlidingViewport(), // A pan and zoom behavior helps demonstrate the sliding viewport // behavior by allowing the data visible in the viewport to be adjusted // dynamically. - new charts.PanAndZoomBehavior(), + charts.PanAndZoomBehavior(), ], // Set an initial viewport to demonstrate the sliding viewport behavior on // initial chart load. - domainAxis: new charts.OrdinalAxisSpec( - viewport: new charts.OrdinalViewport('2018', 4)), + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4),), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), - new OrdinalSales('2018', 33), - new OrdinalSales('2019', 80), - new OrdinalSales('2020', 21), - new OrdinalSales('2021', 77), - new OrdinalSales('2022', 8), - new OrdinalSales('2023', 12), - new OrdinalSales('2024', 42), - new OrdinalSales('2025', 70), - new OrdinalSales('2026', 77), - new OrdinalSales('2027', 55), - new OrdinalSales('2028', 19), - new OrdinalSales('2029', 66), - new OrdinalSales('2030', 27), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), + OrdinalSales('2018', 33), + OrdinalSales('2019', 80), + OrdinalSales('2020', 21), + OrdinalSales('2021', 77), + OrdinalSales('2022', 8), + OrdinalSales('2023', 12), + OrdinalSales('2024', 42), + OrdinalSales('2025', 70), + OrdinalSales('2026', 77), + OrdinalSales('2027', 55), + OrdinalSales('2028', 19), + OrdinalSales('2029', 66), + OrdinalSales('2030', 27), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/combo_chart/combo_gallery.dart b/charts_flutter/example/lib/combo_chart/combo_gallery.dart index e56655102..3b8613b2d 100644 --- a/charts_flutter/example/lib/combo_chart/combo_gallery.dart +++ b/charts_flutter/example/lib/combo_chart/combo_gallery.dart @@ -13,45 +13,43 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/combo_chart/date_time_line_point.dart'; +import 'package:example/combo_chart/numeric_line_bar.dart'; +import 'package:example/combo_chart/numeric_line_point.dart'; +import 'package:example/combo_chart/ordinal_bar_line.dart'; +import 'package:example/combo_chart/scatter_plot_line.dart'; +import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'date_time_line_point.dart'; -import 'numeric_line_bar.dart'; -import 'numeric_line_point.dart'; -import 'ordinal_bar_line.dart'; -import 'scatter_plot_line.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Ordinal Combo Chart', subtitle: 'Ordinal combo chart with bars and lines', - childBuilder: () => new OrdinalComboBarLineChart.withRandomData(), + childBuilder: OrdinalComboBarLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Numeric Line Bar Combo Chart', subtitle: 'Numeric combo chart with lines and bars', - childBuilder: () => new NumericComboLineBarChart.withRandomData(), + childBuilder: NumericComboLineBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Numeric Line Points Combo Chart', subtitle: 'Numeric combo chart with lines and points', - childBuilder: () => new NumericComboLinePointChart.withRandomData(), + childBuilder: NumericComboLinePointChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Time Series Combo Chart', subtitle: 'Time series combo chart with lines and points', - childBuilder: () => new DateTimeComboLinePointChart.withRandomData(), + childBuilder: DateTimeComboLinePointChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.scatter_plot), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), title: 'Scatter Plot Combo Chart', subtitle: 'Scatter plot combo chart with a line', - childBuilder: () => new ScatterPlotComboLineChart.withRandomData(), + childBuilder: ScatterPlotComboLineChart.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart index 3ec993966..d0fc3f457 100644 --- a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart @@ -20,81 +20,78 @@ /// different color from the main series color. The line renderer supports /// drawing points with the "includePoints" option, but those points will share /// the same color as the line. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class DateTimeComboLinePointChart extends StatelessWidget { - final List> seriesList; - final bool animate; - DateTimeComboLinePointChart(this.seriesList, {this.animate = false}); + const DateTimeComboLinePointChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory DateTimeComboLinePointChart.withSampleData() { - return new DateTimeComboLinePointChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory DateTimeComboLinePointChart.withSampleData() => DateTimeComboLinePointChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DateTimeComboLinePointChart.withRandomData() { - return new DateTimeComboLinePointChart(_createRandomData()); - } + factory DateTimeComboLinePointChart.withRandomData() => DateTimeComboLinePointChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; final tableSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; final mobileSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), tableSalesData[0].sales), - new TimeSeriesSales(new DateTime(2017, 9, 26), tableSalesData[1].sales), - new TimeSeriesSales(new DateTime(2017, 10, 3), tableSalesData[2].sales), - new TimeSeriesSales(new DateTime(2017, 10, 10), tableSalesData[3].sales), + TimeSeriesSales(DateTime(2017, 9, 19), tableSalesData[0].sales), + TimeSeriesSales(DateTime(2017, 9, 26), tableSalesData[1].sales), + TimeSeriesSales(DateTime(2017, 10, 3), tableSalesData[2].sales), + TimeSeriesSales(DateTime(2017, 10, 10), tableSalesData[3].sales), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -102,72 +99,70 @@ class DateTimeComboLinePointChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. // // This is the default configuration, but is shown here for illustration. - defaultRenderer: new charts.LineRendererConfig(), + defaultRenderer: charts.LineRendererConfig(), // Custom renderer configuration for the point series. customSeriesRenderers: [ - new charts.PointRendererConfig( + charts.PointRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customPoint') + customRendererId: 'customPoint',), ], // Optionally pass in a [DateTimeFactory] used by the chart. The factory // should create the same type of [DateTime] as the data provided. If none // specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final desktopSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; final tableSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 10), - new TimeSeriesSales(new DateTime(2017, 9, 26), 50), - new TimeSeriesSales(new DateTime(2017, 10, 3), 200), - new TimeSeriesSales(new DateTime(2017, 10, 10), 150), + TimeSeriesSales(DateTime(2017, 9, 19), 10), + TimeSeriesSales(DateTime(2017, 9, 26), 50), + TimeSeriesSales(DateTime(2017, 10, 3), 200), + TimeSeriesSales(DateTime(2017, 10, 10), 150), ]; final mobileSalesData = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 10), - new TimeSeriesSales(new DateTime(2017, 9, 26), 50), - new TimeSeriesSales(new DateTime(2017, 10, 3), 200), - new TimeSeriesSales(new DateTime(2017, 10, 10), 150), + TimeSeriesSales(DateTime(2017, 9, 19), 10), + TimeSeriesSales(DateTime(2017, 9, 26), 50), + TimeSeriesSales(DateTime(2017, 10, 3), 200), + TimeSeriesSales(DateTime(2017, 10, 10), 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -176,8 +171,8 @@ class DateTimeComboLinePointChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart b/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart index aaadbaf95..bd89d1476 100644 --- a/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart +++ b/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart @@ -15,160 +15,155 @@ /// Example of a numeric combo chart with two series rendered as bars, and a /// third rendered as a line. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class NumericComboLineBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - NumericComboLineBarChart(this.seriesList, {this.animate = false}); + const NumericComboLineBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory NumericComboLineBarChart.withSampleData() { - return new NumericComboLineBarChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory NumericComboLineBarChart.withSampleData() => NumericComboLineBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericComboLineBarChart.withRandomData() { - return new NumericComboLineBarChart(_createRandomData()); - } + factory NumericComboLineBarChart.withRandomData() => NumericComboLineBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; final tableSalesData = [ - new LinearSales(0, desktopSalesData[0].sales), - new LinearSales(1, desktopSalesData[1].sales), - new LinearSales(2, desktopSalesData[2].sales), - new LinearSales(3, desktopSalesData[3].sales), + LinearSales(0, desktopSalesData[0].sales), + LinearSales(1, desktopSalesData[1].sales), + LinearSales(2, desktopSalesData[2].sales), + LinearSales(3, desktopSalesData[3].sales), ]; final mobileSalesData = [ - new LinearSales(0, tableSalesData[0].sales * 2), - new LinearSales(1, tableSalesData[1].sales * 2), - new LinearSales(2, tableSalesData[2].sales * 2), - new LinearSales(3, tableSalesData[3].sales * 2), + LinearSales(0, tableSalesData[0].sales * 2), + LinearSales(1, tableSalesData[1].sales * 2), + LinearSales(2, tableSalesData[2].sales * 2), + LinearSales(3, tableSalesData[3].sales * 2), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ) // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ) // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: mobileSalesData), + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.NumericComboChart(seriesList, + Widget build(BuildContext context) => charts.NumericComboChart(seriesList, animate: animate, // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. - defaultRenderer: new charts.LineRendererConfig(), + defaultRenderer: charts.LineRendererConfig(), // Custom renderer configuration for the bar series. customSeriesRenderers: [ - new charts.BarRendererConfig( + charts.BarRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customBar') - ]); - } + customRendererId: 'customBar',), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final desktopSalesData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; final tableSalesData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; final mobileSalesData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ) // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ) // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: mobileSalesData), + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart index 2821afae9..fc244b830 100644 --- a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart @@ -20,81 +20,78 @@ /// different color from the main series color. The line renderer supports /// drawing points with the "includePoints" option, but those points will share /// the same color as the line. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class NumericComboLinePointChart extends StatelessWidget { - final List> seriesList; - final bool animate; - NumericComboLinePointChart(this.seriesList, {this.animate = false}); + const NumericComboLinePointChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory NumericComboLinePointChart.withSampleData() { - return new NumericComboLinePointChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory NumericComboLinePointChart.withSampleData() => NumericComboLinePointChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericComboLinePointChart.withRandomData() { - return new NumericComboLinePointChart(_createRandomData()); - } + factory NumericComboLinePointChart.withRandomData() => NumericComboLinePointChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; final tableSalesData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; final mobileSalesData = [ - new LinearSales(0, tableSalesData[0].sales), - new LinearSales(1, tableSalesData[1].sales), - new LinearSales(2, tableSalesData[2].sales), - new LinearSales(3, tableSalesData[3].sales), + LinearSales(0, tableSalesData[0].sales), + LinearSales(1, tableSalesData[1].sales), + LinearSales(2, tableSalesData[2].sales), + LinearSales(3, tableSalesData[3].sales), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -102,64 +99,62 @@ class NumericComboLinePointChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.NumericComboChart(seriesList, + Widget build(BuildContext context) => charts.NumericComboChart(seriesList, animate: animate, // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. - defaultRenderer: new charts.LineRendererConfig(), + defaultRenderer: charts.LineRendererConfig(), // Custom renderer configuration for the point series. customSeriesRenderers: [ - new charts.PointRendererConfig( + charts.PointRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customPoint') - ]); - } + customRendererId: 'customPoint',), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final desktopSalesData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; final tableSalesData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; final mobileSalesData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tableSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -168,8 +163,8 @@ class NumericComboLinePointChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart index 804fb3a6a..2dd8e2534 100644 --- a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart +++ b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart @@ -15,6 +15,8 @@ /// Example of an ordinal combo chart with two series rendered as bars, and a /// third rendered as a line. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -22,71 +24,65 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class OrdinalComboBarLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - OrdinalComboBarLineChart(this.seriesList, {this.animate = false}); + const OrdinalComboBarLineChart(this.seriesList, {super.key, this.animate = false}); - factory OrdinalComboBarLineChart.withSampleData() { - return new OrdinalComboBarLineChart( + factory OrdinalComboBarLineChart.withSampleData() => OrdinalComboBarLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory OrdinalComboBarLineChart.withRandomData() { - return new OrdinalComboBarLineChart(_createRandomData()); - } + factory OrdinalComboBarLineChart.withRandomData() => OrdinalComboBarLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tableSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: desktopSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData,), + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: tableSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData,), + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -94,63 +90,61 @@ class OrdinalComboBarLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.OrdinalComboChart(seriesList, + Widget build(BuildContext context) => charts.OrdinalComboChart(seriesList, animate: animate, // Configure the default renderer as a bar renderer. - defaultRenderer: new charts.BarRendererConfig( - groupingType: charts.BarGroupingType.grouped), + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.grouped,), // Custom renderer configuration for the line series. This will be used for // any series that does not define a rendererIdKey. customSeriesRenderers: [ - new charts.LineRendererConfig( + charts.LineRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customLine') - ]); - } + customRendererId: 'customLine',), + ],); /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tableSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 200), - new OrdinalSales('2017', 150), + OrdinalSales('2014', 10), + OrdinalSales('2015', 50), + OrdinalSales('2016', 200), + OrdinalSales('2017', 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: desktopSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData,), + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: tableSalesData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData,), + charts.Series( id: 'Mobile ', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, - data: mobileSalesData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData,) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -159,8 +153,8 @@ class OrdinalComboBarLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart index f55c83e4d..c1c0bf730 100644 --- a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart +++ b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart @@ -15,69 +15,66 @@ /// Example of a combo scatter plot chart with a second series rendered as a /// line. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class ScatterPlotComboLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - ScatterPlotComboLineChart(this.seriesList, {this.animate = false}); + const ScatterPlotComboLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory ScatterPlotComboLineChart.withSampleData() { - return new ScatterPlotComboLineChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory ScatterPlotComboLineChart.withSampleData() => ScatterPlotComboLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ScatterPlotComboLineChart.withRandomData() { - return new ScatterPlotComboLineChart(_createRandomData()); - } + factory ScatterPlotComboLineChart.withRandomData() => ScatterPlotComboLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final desktopSalesData = [ - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), ]; - var myRegressionData = [ - new LinearSales(0, desktopSalesData[0].sales, 3.5), - new LinearSales( - 100, desktopSalesData[desktopSalesData.length - 1].sales, 7.5), + final myRegressionData = [ + LinearSales(0, desktopSalesData[0].sales, 3.5), + LinearSales( + 100, desktopSalesData[desktopSalesData.length - 1].sales, 7.5,), ]; - final maxMeasure = 100; + const maxMeasure = 100; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -89,18 +86,18 @@ class ScatterPlotComboLineChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, // Providing a radius function is optional. - radiusPxFn: (LinearSales sales, _) => sales.radius, + radiusPxFn: (sales, _) => sales.radius, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: myRegressionData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: myRegressionData,) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -108,57 +105,55 @@ class ScatterPlotComboLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate, // Configure the default renderer as a point renderer. This will be used // for any series that does not define a rendererIdKey. // // This is the default configuration, but is shown here for // illustration. - defaultRenderer: new charts.PointRendererConfig(), + defaultRenderer: charts.PointRendererConfig(), // Custom renderer configuration for the line series. customSeriesRenderers: [ - new charts.LineRendererConfig( + charts.LineRendererConfig( // ID used to link series to this renderer. customRendererId: 'customLine', // Configure the regression line to be painted above the points. // // By default, series drawn by the point renderer are painted on // top of those drawn by a line renderer. - layoutPaintOrder: charts.LayoutViewPaintOrder.point + 1) - ]); - } + layoutPaintOrder: charts.LayoutViewPaintOrder.point + 1,), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final desktopSalesData = [ - new LinearSales(0, 5, 3.0), - new LinearSales(10, 25, 5.0), - new LinearSales(12, 75, 4.0), - new LinearSales(13, 225, 5.0), - new LinearSales(16, 50, 4.0), - new LinearSales(24, 75, 3.0), - new LinearSales(25, 100, 3.0), - new LinearSales(34, 150, 5.0), - new LinearSales(37, 10, 4.5), - new LinearSales(45, 300, 8.0), - new LinearSales(52, 15, 4.0), - new LinearSales(56, 200, 7.0), + LinearSales(0, 5, 3), + LinearSales(10, 25, 5), + LinearSales(12, 75, 4), + LinearSales(13, 225, 5), + LinearSales(16, 50, 4), + LinearSales(24, 75, 3), + LinearSales(25, 100, 3), + LinearSales(34, 150, 5), + LinearSales(37, 10, 4.5), + LinearSales(45, 300, 8), + LinearSales(52, 15, 4), + LinearSales(56, 200, 7), ]; - var myRegressionData = [ - new LinearSales(0, 5, 3.5), - new LinearSales(56, 240, 3.5), + final myRegressionData = [ + LinearSales(0, 5, 3.5), + LinearSales(56, 240, 3.5), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -170,18 +165,18 @@ class ScatterPlotComboLineChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, // Providing a radius function is optional. - radiusPxFn: (LinearSales sales, _) => sales.radius, + radiusPxFn: (sales, _) => sales.radius, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - data: myRegressionData) + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: myRegressionData,) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -190,9 +185,9 @@ class ScatterPlotComboLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.radius); final int year; final int sales; final double radius; - - LinearSales(this.year, this.sales, this.radius); } diff --git a/charts_flutter/example/lib/gallery_scaffold.dart b/charts_flutter/example/lib/gallery_scaffold.dart index 2a13c551e..568d3e51f 100644 --- a/charts_flutter/example/lib/gallery_scaffold.dart +++ b/charts_flutter/example/lib/gallery_scaffold.dart @@ -15,34 +15,30 @@ import 'package:flutter/material.dart'; -typedef Widget GalleryWidgetBuilder(); +typedef GalleryWidgetBuilder = Widget Function(); /// Helper to build gallery. class GalleryScaffold extends StatefulWidget { + + const GalleryScaffold({required this.listTileIcon, required this.title, required this.subtitle, required this.childBuilder, super.key, + }); /// The widget used for leading in a [ListTile]. final Widget listTileIcon; final String title; final String subtitle; final GalleryWidgetBuilder childBuilder; - GalleryScaffold({ - required this.listTileIcon, - required this.title, - required this.subtitle, - required this.childBuilder, - }); - /// Gets the gallery - Widget buildGalleryListTile(BuildContext context) => new ListTile( + Widget buildGalleryListTile(BuildContext context) => ListTile( leading: listTileIcon, - title: new Text(title), - subtitle: new Text(subtitle), + title: Text(title), + subtitle: Text(subtitle), onTap: () { - Navigator.push(context, new MaterialPageRoute(builder: (_) => this)); - }); + Navigator.push(context, MaterialPageRoute(builder: (_) => this)); + },); @override - _GalleryScaffoldState createState() => new _GalleryScaffoldState(); + _GalleryScaffoldState createState() => _GalleryScaffoldState(); } class _GalleryScaffoldState extends State { @@ -51,16 +47,14 @@ class _GalleryScaffoldState extends State { } @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar(title: new Text(widget.title)), - body: new Padding( - padding: const EdgeInsets.all(8.0), - child: new Column(children: [ - new SizedBox(height: 250.0, child: widget.childBuilder()), - ])), - floatingActionButton: new FloatingActionButton( - onPressed: _handleButtonPress, child: new Icon(Icons.refresh)), + Widget build(BuildContext context) => Scaffold( + appBar: AppBar(title: Text(widget.title)), + body: Padding( + padding: const EdgeInsets.all(8), + child: Column(children: [ + SizedBox(height: 250, child: widget.childBuilder()), + ],),), + floatingActionButton: FloatingActionButton( + onPressed: _handleButtonPress, child: const Icon(Icons.refresh),), ); - } } diff --git a/charts_flutter/example/lib/home.dart b/charts_flutter/example/lib/home.dart index 05125749d..a9c8f63b2 100644 --- a/charts_flutter/example/lib/home.dart +++ b/charts_flutter/example/lib/home.dart @@ -13,28 +13,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; import 'dart:developer'; -import 'app_config.dart'; -import 'a11y/a11y_gallery.dart' as a11y show buildGallery; -import 'bar_chart/bar_gallery.dart' as bar show buildGallery; -import 'time_series_chart/time_series_gallery.dart' as time_series + +import 'package:example/a11y/a11y_gallery.dart' as a11y show buildGallery; +import 'package:example/app_config.dart'; +import 'package:example/axes/axes_gallery.dart' as axes show buildGallery; +import 'package:example/bar_chart/bar_gallery.dart' as bar show buildGallery; +import 'package:example/behaviors/behaviors_gallery.dart' as behaviors show buildGallery; +import 'package:example/combo_chart/combo_gallery.dart' as combo show buildGallery; +import 'package:example/i18n/i18n_gallery.dart' as i18n show buildGallery; +import 'package:example/legends/legends_gallery.dart' as legends show buildGallery; +import 'package:example/line_chart/line_gallery.dart' as line show buildGallery; +import 'package:example/pie_chart/pie_gallery.dart' as pie show buildGallery; +import 'package:example/scatter_plot_chart/scatter_plot_gallery.dart' as scatter_plot show buildGallery; -import 'line_chart/line_gallery.dart' as line show buildGallery; -import 'scatter_plot_chart/scatter_plot_gallery.dart' as scatter_plot +import 'package:example/time_series_chart/time_series_gallery.dart' as time_series show buildGallery; -import 'combo_chart/combo_gallery.dart' as combo show buildGallery; -import 'pie_chart/pie_gallery.dart' as pie show buildGallery; -import 'axes/axes_gallery.dart' as axes show buildGallery; -import 'behaviors/behaviors_gallery.dart' as behaviors show buildGallery; -import 'i18n/i18n_gallery.dart' as i18n show buildGallery; -import 'legends/legends_gallery.dart' as legends show buildGallery; +import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart' as charts; /// Main entry point of the gallery app. /// /// This renders a list of all available demos. class Home extends StatelessWidget { + + Home({ + super.key, + }); final a11yGalleries = a11y.buildGallery(); final barGalleries = bar.buildGallery(); final timeSeriesGalleries = time_series.buildGallery(); @@ -47,61 +52,57 @@ class Home extends StatelessWidget { final i18nGalleries = i18n.buildGallery(); final legendsGalleries = legends.buildGallery(); - Home({ - Key? key, - }) : super(key: key) {} - @override Widget build(BuildContext context) { - var galleries = []; + final galleries = []; galleries.addAll( - a11yGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + a11yGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); // Add example bar charts. galleries.addAll( - barGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + barGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); // Add example time series charts. galleries.addAll(timeSeriesGalleries - .map((gallery) => gallery.buildGalleryListTile(context))); + .map((gallery) => gallery.buildGalleryListTile(context)),); // Add example line charts. galleries.addAll( - lineGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + lineGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); // Add example scatter plot charts. galleries.addAll(scatterPlotGalleries - .map((gallery) => gallery.buildGalleryListTile(context))); + .map((gallery) => gallery.buildGalleryListTile(context)),); // Add example pie charts. galleries.addAll( - comboGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + comboGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); // Add example pie charts. galleries.addAll( - pieGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + pieGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); // Add example custom axis. galleries.addAll( - axesGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + axesGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); galleries.addAll(behaviorsGalleries - .map((gallery) => gallery.buildGalleryListTile(context))); + .map((gallery) => gallery.buildGalleryListTile(context)),); // Add legends examples galleries.addAll(legendsGalleries - .map((gallery) => gallery.buildGalleryListTile(context))); + .map((gallery) => gallery.buildGalleryListTile(context)),); // Add examples for i18n. galleries.addAll( - i18nGalleries.map((gallery) => gallery.buildGalleryListTile(context))); + i18nGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); _setupPerformance(); - return new Scaffold( - appBar: new AppBar(title: new Text(defaultConfig.appName)), - body: new ListView(padding: kMaterialListPadding, children: galleries), + return Scaffold( + appBar: AppBar(title: Text(defaultConfig.appName)), + body: ListView(padding: kMaterialListPadding, children: galleries), ); } @@ -111,7 +112,7 @@ class Home extends StatelessWidget { // mode and this mode is slow. To build in release mode, specify the flag // blaze-run flag "--define flutter_build_mode=release". // The build target must also be an actual device and not the emulator. - charts.Performance.time = (String tag) => Timeline.startSync(tag); + charts.Performance.time = Timeline.startSync; charts.Performance.timeEnd = (_) => Timeline.finishSync(); } } diff --git a/charts_flutter/example/lib/i18n/i18n_gallery.dart b/charts_flutter/example/lib/i18n/i18n_gallery.dart index cab90664d..dc5b21746 100644 --- a/charts_flutter/example/lib/i18n/i18n_gallery.dart +++ b/charts_flutter/example/lib/i18n/i18n_gallery.dart @@ -13,38 +13,36 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/i18n/rtl_bar_chart.dart'; +import 'package:example/i18n/rtl_line_chart.dart'; +import 'package:example/i18n/rtl_line_segments.dart'; +import 'package:example/i18n/rtl_series_legend.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'rtl_bar_chart.dart'; -import 'rtl_line_chart.dart'; -import 'rtl_line_segments.dart'; -import 'rtl_series_legend.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'RTL Bar Chart', subtitle: 'Simple bar chart in RTL', - childBuilder: () => new RTLBarChart.withRandomData(), + childBuilder: RTLBarChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'RTL Line Chart', subtitle: 'Simple line chart in RTL', - childBuilder: () => new RTLLineChart.withRandomData(), + childBuilder: RTLLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'RTL Line Segments', subtitle: 'Stacked area chart with style segments in RTL', - childBuilder: () => new RTLLineSegments.withRandomData(), + childBuilder: RTLLineSegments.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.flag), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), title: 'RTL Series Legend', subtitle: 'Series legend in RTL', - childBuilder: () => new RTLSeriesLegend.withRandomData(), + childBuilder: RTLSeriesLegend.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart index baf610858..bd913ae3a 100644 --- a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart @@ -14,53 +14,51 @@ // limitations under the License. /// RTL Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart'; class RTLBarChart extends StatelessWidget { - final List> seriesList; - final bool animate; - RTLBarChart(this.seriesList, {this.animate = false}); + const RTLBarChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory RTLBarChart.withSampleData() { - return new RTLBarChart( + /// Creates a [charts.BarChart] with sample data and no transition. + factory RTLBarChart.withSampleData() => RTLBarChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLBarChart.withRandomData() { - return new RTLBarChart(_createRandomData()); - } + factory RTLBarChart.withRandomData() => RTLBarChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -81,39 +79,39 @@ class RTLBarChart extends StatelessWidget { // // Optionally, [RTLSpec] can be passed in when creating the chart to specify // chart display settings in RTL mode. - return new Directionality( + return Directionality( textDirection: TextDirection.rtl, - child: new charts.BarChart( + child: charts.BarChart( seriesList, animate: animate, vertical: false, - )); + ),); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/i18n/rtl_line_chart.dart b/charts_flutter/example/lib/i18n/rtl_line_chart.dart index d49e7600b..aa0ef3c46 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_chart.dart @@ -14,53 +14,51 @@ // limitations under the License. /// RTL Line chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart'; class RTLLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - RTLLineChart(this.seriesList, {this.animate = false}); + const RTLLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory RTLLineChart.withSampleData() { - return new RTLLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory RTLLineChart.withSampleData() => RTLLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLLineChart.withRandomData() { - return new RTLLineChart(_createRandomData()); - } + factory RTLLineChart.withRandomData() => RTLLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -78,38 +76,38 @@ class RTLLineChart extends StatelessWidget { // Measure axis positions are flipped. Primary measure axis is on the right // and the secondary measure axis is on the left (when used). // Domain axis' first domain starts on the right and grows left. - return new Directionality( + return Directionality( textDirection: TextDirection.rtl, - child: new charts.LineChart( + child: charts.LineChart( seriesList, animate: animate, - )); + ),); } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/i18n/rtl_line_segments.dart b/charts_flutter/example/lib/i18n/rtl_line_segments.dart index 2b2034552..70c798732 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_segments.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_segments.dart @@ -25,71 +25,69 @@ /// the [charts.LineRendererConfig]. This could be used, for example, to define /// a default dash pattern for the series, with only a specific datum called out /// with a different pattern. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart'; class RTLLineSegments extends StatelessWidget { - final List> seriesList; - final bool animate; - RTLLineSegments(this.seriesList, {this.animate = false}); + const RTLLineSegments(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory RTLLineSegments.withSampleData() { - return new RTLLineSegments( + /// Creates a [charts.LineChart] with sample data and no transition. + factory RTLLineSegments.withSampleData() => RTLLineSegments( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLLineSegments.withRandomData() { - return new RTLLineSegments(_createRandomData()); - } + factory RTLLineSegments.withRandomData() => RTLLineSegments(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); // Series of data with static dash pattern and stroke width. The colorFn // accessor will colorize each datum (for all three series). final colorChangeData = [ - new LinearSales(0, random.nextInt(100), null, 2.0), - new LinearSales(1, random.nextInt(100), null, 2.0), - new LinearSales(2, random.nextInt(100), null, 2.0), - new LinearSales(3, random.nextInt(100), null, 2.0), - new LinearSales(4, random.nextInt(100), null, 2.0), - new LinearSales(5, random.nextInt(100), null, 2.0), - new LinearSales(6, random.nextInt(100), null, 2.0), + LinearSales(0, random.nextInt(100), null, 2), + LinearSales(1, random.nextInt(100), null, 2), + LinearSales(2, random.nextInt(100), null, 2), + LinearSales(3, random.nextInt(100), null, 2), + LinearSales(4, random.nextInt(100), null, 2), + LinearSales(5, random.nextInt(100), null, 2), + LinearSales(6, random.nextInt(100), null, 2), ]; // Series of data with changing color and dash pattern. final dashPatternChangeData = [ - new LinearSales(0, random.nextInt(100), [2, 2], 2.0), - new LinearSales(1, random.nextInt(100), [2, 2], 2.0), - new LinearSales(2, random.nextInt(100), [4, 4], 2.0), - new LinearSales(3, random.nextInt(100), [4, 4], 2.0), - new LinearSales(4, random.nextInt(100), [4, 4], 2.0), - new LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0), - new LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0), + LinearSales(0, random.nextInt(100), [2, 2], 2), + LinearSales(1, random.nextInt(100), [2, 2], 2), + LinearSales(2, random.nextInt(100), [4, 4], 2), + LinearSales(3, random.nextInt(100), [4, 4], 2), + LinearSales(4, random.nextInt(100), [4, 4], 2), + LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2), + LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2), ]; // Series of data with changing color and stroke width. final strokeWidthChangeData = [ - new LinearSales(0, random.nextInt(100), null, 2.0), - new LinearSales(1, random.nextInt(100), null, 2.0), - new LinearSales(2, random.nextInt(100), null, 4.0), - new LinearSales(3, random.nextInt(100), null, 4.0), - new LinearSales(4, random.nextInt(100), null, 4.0), - new LinearSales(5, random.nextInt(100), null, 6.0), - new LinearSales(6, random.nextInt(100), null, 6.0), + LinearSales(0, random.nextInt(100), null, 2), + LinearSales(1, random.nextInt(100), null, 2), + LinearSales(2, random.nextInt(100), null, 4), + LinearSales(3, random.nextInt(100), null, 4), + LinearSales(4, random.nextInt(100), null, 4), + LinearSales(5, random.nextInt(100), null, 6), + LinearSales(6, random.nextInt(100), null, 6), ]; // Generate 2 shades of each color so that we can style the line segments. @@ -98,37 +96,37 @@ class RTLLineSegments extends StatelessWidget { final green = charts.MaterialPalette.green.makeShades(2); return [ - new charts.Series( + charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? blue[1] : blue[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: colorChangeData, ), - new charts.Series( + charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? red[1] : red[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: dashPatternChangeData, ), - new charts.Series( + charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? green[1] : green[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: strokeWidthChangeData, ), ]; @@ -148,14 +146,14 @@ class RTLLineSegments extends StatelessWidget { // Measure axis positions are flipped. Primary measure axis is on the right // and the secondary measure axis is on the left (when used). // Domain axis' first domain starts on the right and grows left. - return new Directionality( + return Directionality( textDirection: TextDirection.rtl, - child: new charts.LineChart( + child: charts.LineChart( seriesList, defaultRenderer: - new charts.LineRendererConfig(includeArea: true, stacked: true), + charts.LineRendererConfig(includeArea: true, stacked: true), animate: animate, - )); + ),); } /// Create one series with sample hard coded data. @@ -163,35 +161,35 @@ class RTLLineSegments extends StatelessWidget { // Series of data with static dash pattern and stroke width. The colorFn // accessor will colorize each datum (for all three series). final colorChangeData = [ - new LinearSales(0, 5, null, 2.0), - new LinearSales(1, 15, null, 2.0), - new LinearSales(2, 25, null, 2.0), - new LinearSales(3, 75, null, 2.0), - new LinearSales(4, 100, null, 2.0), - new LinearSales(5, 90, null, 2.0), - new LinearSales(6, 75, null, 2.0), + LinearSales(0, 5, null, 2), + LinearSales(1, 15, null, 2), + LinearSales(2, 25, null, 2), + LinearSales(3, 75, null, 2), + LinearSales(4, 100, null, 2), + LinearSales(5, 90, null, 2), + LinearSales(6, 75, null, 2), ]; // Series of data with changing color and dash pattern. final dashPatternChangeData = [ - new LinearSales(0, 5, [2, 2], 2.0), - new LinearSales(1, 15, [2, 2], 2.0), - new LinearSales(2, 25, [4, 4], 2.0), - new LinearSales(3, 75, [4, 4], 2.0), - new LinearSales(4, 100, [4, 4], 2.0), - new LinearSales(5, 90, [8, 3, 2, 3], 2.0), - new LinearSales(6, 75, [8, 3, 2, 3], 2.0), + LinearSales(0, 5, [2, 2], 2), + LinearSales(1, 15, [2, 2], 2), + LinearSales(2, 25, [4, 4], 2), + LinearSales(3, 75, [4, 4], 2), + LinearSales(4, 100, [4, 4], 2), + LinearSales(5, 90, [8, 3, 2, 3], 2), + LinearSales(6, 75, [8, 3, 2, 3], 2), ]; // Series of data with changing color and stroke width. final strokeWidthChangeData = [ - new LinearSales(0, 5, null, 2.0), - new LinearSales(1, 15, null, 2.0), - new LinearSales(2, 25, null, 4.0), - new LinearSales(3, 75, null, 4.0), - new LinearSales(4, 100, null, 4.0), - new LinearSales(5, 90, null, 6.0), - new LinearSales(6, 75, null, 6.0), + LinearSales(0, 5, null, 2), + LinearSales(1, 15, null, 2), + LinearSales(2, 25, null, 4), + LinearSales(3, 75, null, 4), + LinearSales(4, 100, null, 4), + LinearSales(5, 90, null, 6), + LinearSales(6, 75, null, 6), ]; // Generate 2 shades of each color so that we can style the line segments. @@ -200,37 +198,37 @@ class RTLLineSegments extends StatelessWidget { final green = charts.MaterialPalette.green.makeShades(2); return [ - new charts.Series( + charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? blue[1] : blue[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: colorChangeData, ), - new charts.Series( + charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? red[1] : red[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: dashPatternChangeData, ), - new charts.Series( + charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? green[1] : green[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: strokeWidthChangeData, ), ]; @@ -239,10 +237,10 @@ class RTLLineSegments extends StatelessWidget { /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); final int year; final int sales; final List? dashPattern; final double strokeWidthPx; - - LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); } diff --git a/charts_flutter/example/lib/i18n/rtl_series_legend.dart b/charts_flutter/example/lib/i18n/rtl_series_legend.dart index 9ef79dce1..33cf3f439 100644 --- a/charts_flutter/example/lib/i18n/rtl_series_legend.dart +++ b/charts_flutter/example/lib/i18n/rtl_series_legend.dart @@ -14,90 +14,88 @@ // limitations under the License. /// RTL Bar chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart'; class RTLSeriesLegend extends StatelessWidget { - final List> seriesList; - final bool animate; - RTLSeriesLegend(this.seriesList, {this.animate = false}); + const RTLSeriesLegend(this.seriesList, {super.key, this.animate = false}); - /// Creates a [BarChart] with sample data and no transition. - factory RTLSeriesLegend.withSampleData() { - return new RTLSeriesLegend( + /// Creates a [charts.BarChart] with sample data and no transition. + factory RTLSeriesLegend.withSampleData() => RTLSeriesLegend( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLSeriesLegend.withRandomData() { - return new RTLSeriesLegend(_createRandomData()); - } + factory RTLSeriesLegend.withRandomData() => RTLSeriesLegend(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -126,71 +124,71 @@ class RTLSeriesLegend extends StatelessWidget { // The below example changes the position to 'start' and max rows of 2 in // order to show these effects, but are not required for SeriesLegend to // work with the correct directionality. - return new Directionality( + return Directionality( textDirection: TextDirection.rtl, - child: new charts.BarChart( + child: charts.BarChart( seriesList, animate: animate, behaviors: [ - new charts.SeriesLegend( - position: charts.BehaviorPosition.end, desiredMaxRows: 2) + charts.SeriesLegend( + position: charts.BehaviorPosition.end, desiredMaxRows: 2,), ], - )); + ),); } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -199,8 +197,8 @@ class RTLSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/datum_legend_options.dart b/charts_flutter/example/lib/legends/datum_legend_options.dart index 1d104f65e..a61172435 100644 --- a/charts_flutter/example/lib/legends/datum_legend_options.dart +++ b/charts_flutter/example/lib/legends/datum_legend_options.dart @@ -18,6 +18,8 @@ /// an example of how to use the customizations, they do not necessary have to /// be used together in this way. Choosing [end] as the position does not /// require the justification to also be [endDrawArea]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,59 +27,52 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DatumLegendOptions extends StatelessWidget { - final List> seriesList; - final bool animate; - DatumLegendOptions(this.seriesList, {this.animate = false}); + const DatumLegendOptions(this.seriesList, {super.key, this.animate = false}); - factory DatumLegendOptions.withSampleData() { - return new DatumLegendOptions( + factory DatumLegendOptions.withSampleData() => DatumLegendOptions( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DatumLegendOptions.withRandomData() { - return new DatumLegendOptions(_createRandomData()); - } + factory DatumLegendOptions.withRandomData() => DatumLegendOptions(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart( + Widget build(BuildContext context) => charts.PieChart( seriesList, animate: animate, // Add the legend behavior to the chart to turn on legends. // This example shows how to change the position and justification of // the legend, in addition to altering the max rows and padding. behaviors: [ - new charts.DatumLegend( + charts.DatumLegend( // Positions for "start" and "end" will be left and right respectively // for widgets with a build context that has directionality ltr. // For rtl, "start" and "end" will be right and left respectively. @@ -96,41 +91,40 @@ class DatumLegendOptions extends StatelessWidget { // rows before adding a new column. desiredMaxRows: 2, // This defines the padding around each legend entry. - cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0), + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), // Render the legend entry text with custom styles. entryTextStyle: charts.TextStyleSpec( color: charts.MaterialPalette.purple.shadeDefault, fontFamily: 'Georgia', - fontSize: 11), - ) + fontSize: 11,), + ), ], ); - } /// Create series list with one series static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart index 461521058..c3c1aa6d0 100644 --- a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart @@ -18,6 +18,8 @@ /// to use the customizations, they do not necessary have to be used together in /// this way. Choosing [end] as the position does not require the justification /// to also be [endDrawArea]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -28,52 +30,45 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// Also shows the option to provide a custom measure formatter. class DatumLegendWithMeasures extends StatelessWidget { - final List> seriesList; - final bool animate; - DatumLegendWithMeasures(this.seriesList, {this.animate = false}); + const DatumLegendWithMeasures(this.seriesList, {super.key, this.animate = false}); - factory DatumLegendWithMeasures.withSampleData() { - return new DatumLegendWithMeasures( + factory DatumLegendWithMeasures.withSampleData() => DatumLegendWithMeasures( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DatumLegendWithMeasures.withRandomData() { - return new DatumLegendWithMeasures(_createRandomData()); - } + factory DatumLegendWithMeasures.withRandomData() => DatumLegendWithMeasures(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(2014, random.nextInt(100)), - new LinearSales(2015, random.nextInt(100)), - new LinearSales(2016, random.nextInt(100)), - new LinearSales(2017, random.nextInt(100)), + LinearSales(2014, random.nextInt(100)), + LinearSales(2015, random.nextInt(100)), + LinearSales(2016, random.nextInt(100)), + LinearSales(2017, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart( + Widget build(BuildContext context) => charts.PieChart( seriesList, animate: animate, // Add the legend behavior to the chart to turn on legends. @@ -84,13 +79,13 @@ class DatumLegendWithMeasures extends StatelessWidget { // This section is excluded from being copied to the gallery. // This is added in order to generate the image for the gallery to show // an initial selection so that measure values are shown in the gallery. - new charts.InitialSelection( + charts.InitialSelection( selectedDataConfig: [ - new charts.SeriesDatumConfig('Sales', 0), + charts.SeriesDatumConfig('Sales', 0), ], ), // EXCLUDE_FROM_GALLERY_DOCS_END - new charts.DatumLegend( + charts.DatumLegend( // Positions for "start" and "end" will be left and right respectively // for widgets with a build context that has directionality ltr. // For rtl, "start" and "end" will be right and left respectively. @@ -102,45 +97,42 @@ class DatumLegendWithMeasures extends StatelessWidget { // legend entries will grow as new rows first instead of a new column. horizontalFirst: false, // This defines the padding around each legend entry. - cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0), + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), // Set [showMeasures] to true to display measures in series legend. showMeasures: true, // Configure the measure value to be shown by default in the legend. legendDefaultMeasure: charts.LegendDefaultMeasure.firstValue, // Optionally provide a measure formatter to format the measure value. // If none is specified the value is formatted as a decimal. - measureFormatter: (num? value) { - return value == null ? '-' : '${value}k'; - }, + measureFormatter: (value) => value == null ? '-' : '${value}k', ), ], ); - } /// Create series list with one series static List> _createSampleData() { final data = [ - new LinearSales(2014, 100), - new LinearSales(2015, 75), - new LinearSales(2016, 25), - new LinearSales(2017, 5), + LinearSales(2014, 100), + LinearSales(2015, 75), + LinearSales(2016, 25), + LinearSales(2017, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart index e01b84089..78ec15137 100644 --- a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart +++ b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart with default hidden series legend example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,82 +23,76 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DefaultHiddenSeriesLegend extends StatelessWidget { - final List> seriesList; - final bool animate; - DefaultHiddenSeriesLegend(this.seriesList, {this.animate = false}); + const DefaultHiddenSeriesLegend(this.seriesList, {super.key, this.animate = false}); - factory DefaultHiddenSeriesLegend.withSampleData() { - return new DefaultHiddenSeriesLegend( + factory DefaultHiddenSeriesLegend.withSampleData() => DefaultHiddenSeriesLegend( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DefaultHiddenSeriesLegend.withRandomData() { - return new DefaultHiddenSeriesLegend(_createRandomData()); - } + factory DefaultHiddenSeriesLegend.withRandomData() => DefaultHiddenSeriesLegend(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -104,75 +100,73 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, // Add the series legend behavior to the chart to turn on series legends. // By default the legend will display above the chart. behaviors: [ - new charts.SeriesLegend( + charts.SeriesLegend( // Configures the "Other" series to be hidden on first chart draw. - defaultHiddenSeries: ['Other'], - ) + defaultHiddenSeries: const ['Other'], + ), ], ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -181,8 +175,8 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/legend_custom_symbol.dart b/charts_flutter/example/lib/legends/legend_custom_symbol.dart index 3a17c5f9b..88d6da548 100644 --- a/charts_flutter/example/lib/legends/legend_custom_symbol.dart +++ b/charts_flutter/example/lib/legends/legend_custom_symbol.dart @@ -14,21 +14,24 @@ // limitations under the License. /// Bar chart with custom symbol in legend example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts_common/common.dart' as common; import 'package:nimble_charts/src/util/color.dart'; +import 'package:nimble_charts_common/common.dart' as common; /// Example custom renderer that renders [IconData]. /// /// This is used to show that legend symbols can be assigned a custom symbol. class IconRenderer extends charts.CustomSymbolRenderer { - final IconData iconData; IconRenderer(this.iconData); + final IconData iconData; @override Widget build( @@ -43,98 +46,91 @@ class IconRenderer extends charts.CustomSymbolRenderer { color = color.withAlpha(.26); } - return new SizedBox.fromSize( + return SizedBox.fromSize( size: size, - child: new Icon(iconData, color: color?.toDartColor(), size: 12.0)); + child: Icon(iconData, color: color?.toDartColor(), size: 12),); } } class LegendWithCustomSymbol extends StatelessWidget { - final List> seriesList; - final bool animate; - LegendWithCustomSymbol(this.seriesList, {this.animate = false}); + const LegendWithCustomSymbol(this.seriesList, {super.key, this.animate = false}); - factory LegendWithCustomSymbol.withSampleData() { - return new LegendWithCustomSymbol( + factory LegendWithCustomSymbol.withSampleData() => LegendWithCustomSymbol( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LegendWithCustomSymbol.withRandomData() { - return new LegendWithCustomSymbol(_createRandomData()); - } + factory LegendWithCustomSymbol.withRandomData() => LegendWithCustomSymbol(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, @@ -143,75 +139,74 @@ class LegendWithCustomSymbol extends StatelessWidget { // // To change the symbol used in the legend, set the renderer attribute of // symbolRendererKey to a SymbolRenderer. - behaviors: [new charts.SeriesLegend()], - defaultRenderer: new charts.BarRendererConfig( - symbolRenderer: new IconRenderer(Icons.cloud)), + behaviors: [charts.SeriesLegend()], + defaultRenderer: charts.BarRendererConfig( + symbolRenderer: IconRenderer(Icons.cloud),), ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, - ) + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/legends_gallery.dart b/charts_flutter/example/lib/legends/legends_gallery.dart index b5732d5b6..0507293ab 100644 --- a/charts_flutter/example/lib/legends/legends_gallery.dart +++ b/charts_flutter/example/lib/legends/legends_gallery.dart @@ -13,49 +13,46 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/legends/datum_legend_with_measures.dart'; +import 'package:example/legends/default_hidden_series_legend.dart'; +import 'package:example/legends/legend_custom_symbol.dart'; +import 'package:example/legends/series_legend_options.dart'; +import 'package:example/legends/series_legend_with_measures.dart'; +import 'package:example/legends/simple_series_legend.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'datum_legend_options.dart'; -import 'datum_legend_with_measures.dart'; -import 'default_hidden_series_legend.dart'; -import 'legend_custom_symbol.dart'; -import 'series_legend_options.dart'; -import 'series_legend_with_measures.dart'; -import 'simple_datum_legend.dart'; -import 'simple_series_legend.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Series Legend', subtitle: 'A series legend for a bar chart with default settings', - childBuilder: () => new SimpleSeriesLegend.withRandomData(), + childBuilder: SimpleSeriesLegend.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Series Legend Options', subtitle: 'A series legend with custom positioning and spacing for a bar chart', - childBuilder: () => new LegendOptions.withRandomData(), + childBuilder: LegendOptions.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Series Legend Custom Symbol', subtitle: 'A series legend using a custom symbol renderer', - childBuilder: () => new LegendWithCustomSymbol.withRandomData(), + childBuilder: LegendWithCustomSymbol.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Default Hidden Series Legend', subtitle: 'A series legend showing a series hidden by default', - childBuilder: () => new DefaultHiddenSeriesLegend.withRandomData(), + childBuilder: DefaultHiddenSeriesLegend.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), title: 'Series legend with measures', subtitle: 'Series legend with measures and measure formatting', - childBuilder: () => new LegendWithMeasures.withRandomData(), + childBuilder: LegendWithMeasures.withRandomData, ), //TODO: // new GalleryScaffold( @@ -71,11 +68,10 @@ List buildGallery() { // 'A datum legend with custom positioning and spacing for a pie chart', // childBuilder: () => new DatumLegendOptions.withRandomData(), // ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.pie_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), title: 'Datum legend with measures', subtitle: 'Datum legend with measures and measure formatting', - childBuilder: () => new DatumLegendWithMeasures.withRandomData(), + childBuilder: DatumLegendWithMeasures.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/legends/series_legend_options.dart b/charts_flutter/example/lib/legends/series_legend_options.dart index aea381739..6c7b1853e 100644 --- a/charts_flutter/example/lib/legends/series_legend_options.dart +++ b/charts_flutter/example/lib/legends/series_legend_options.dart @@ -18,6 +18,8 @@ /// an example of how to use the customizations, they do not necessary have to /// be used together in this way. Choosing [end] as the position does not /// require the justification to also be [endDrawArea]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -25,82 +27,76 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LegendOptions extends StatelessWidget { - final List> seriesList; - final bool animate; - LegendOptions(this.seriesList, {this.animate = false}); + const LegendOptions(this.seriesList, {super.key, this.animate = false}); - factory LegendOptions.withSampleData() { - return new LegendOptions( + factory LegendOptions.withSampleData() => LegendOptions( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LegendOptions.withRandomData() { - return new LegendOptions(_createRandomData()); - } + factory LegendOptions.withRandomData() => LegendOptions(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -108,8 +104,7 @@ class LegendOptions extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, @@ -117,7 +112,7 @@ class LegendOptions extends StatelessWidget { // This example shows how to change the position and justification of // the legend, in addition to altering the max rows and padding. behaviors: [ - new charts.SeriesLegend( + charts.SeriesLegend( // Positions for "start" and "end" will be left and right respectively // for widgets with a build context that has directionality ltr. // For rtl, "start" and "end" will be right and left respectively. @@ -136,70 +131,69 @@ class LegendOptions extends StatelessWidget { // rows before adding a new column. desiredMaxRows: 2, // This defines the padding around each legend entry. - cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0), + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), // Render the legend entry text with custom styles. entryTextStyle: charts.TextStyleSpec( color: charts.MaterialPalette.purple.shadeDefault, fontFamily: 'Georgia', - fontSize: 11), - ) + fontSize: 11,), + ), ], ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -208,8 +202,8 @@ class LegendOptions extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/series_legend_with_measures.dart b/charts_flutter/example/lib/legends/series_legend_with_measures.dart index cce4c3014..b641b1d69 100644 --- a/charts_flutter/example/lib/legends/series_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/series_legend_with_measures.dart @@ -18,6 +18,8 @@ /// to use the customizations, they do not necessary have to be used together in /// this way. Choosing [end] as the position does not require the justification /// to also be [endDrawArea]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -29,82 +31,76 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// Also shows the option to provide a custom measure formatter. class LegendWithMeasures extends StatelessWidget { - final List> seriesList; - final bool animate; - LegendWithMeasures(this.seriesList, {this.animate = false}); + const LegendWithMeasures(this.seriesList, {super.key, this.animate = false}); - factory LegendWithMeasures.withSampleData() { - return new LegendWithMeasures( + factory LegendWithMeasures.withSampleData() => LegendWithMeasures( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LegendWithMeasures.withRandomData() { - return new LegendWithMeasures(_createRandomData()); - } + factory LegendWithMeasures.withRandomData() => LegendWithMeasures(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -112,8 +108,7 @@ class LegendWithMeasures extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, @@ -125,16 +120,16 @@ class LegendWithMeasures extends StatelessWidget { // This section is excluded from being copied to the gallery. // This is added in order to generate the image for the gallery to show // an initial selection so that measure values are shown in the gallery. - new charts.InitialSelection( + charts.InitialSelection( selectedDataConfig: [ - new charts.SeriesDatumConfig('Desktop', '2016'), - new charts.SeriesDatumConfig('Tablet', '2016'), - new charts.SeriesDatumConfig('Mobile', '2016'), - new charts.SeriesDatumConfig('Other', '2016'), + charts.SeriesDatumConfig('Desktop', '2016'), + charts.SeriesDatumConfig('Tablet', '2016'), + charts.SeriesDatumConfig('Mobile', '2016'), + charts.SeriesDatumConfig('Other', '2016'), ], ), // EXCLUDE_FROM_GALLERY_DOCS_END - new charts.SeriesLegend( + charts.SeriesLegend( // Positions for "start" and "end" will be left and right respectively // for widgets with a build context that has directionality ltr. // For rtl, "start" and "end" will be right and left respectively. @@ -146,73 +141,70 @@ class LegendWithMeasures extends StatelessWidget { // legend entries will grow as new rows first instead of a new column. horizontalFirst: false, // This defines the padding around each legend entry. - cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0), + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), // Set show measures to true to display measures in series legend, // when the datum is selected. showMeasures: true, // Optionally provide a measure formatter to format the measure value. // If none is specified the value is formatted as a decimal. - measureFormatter: (num? value) { - return value == null ? '-' : '${value}k'; - }, + measureFormatter: (value) => value == null ? '-' : '${value}k', ), ], ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), // Purposely have a missing datum for 2016 to show the null measure format - new OrdinalSales('2017', 20), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -221,8 +213,8 @@ class LegendWithMeasures extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/simple_datum_legend.dart b/charts_flutter/example/lib/legends/simple_datum_legend.dart index b53f66a62..fe8d34925 100644 --- a/charts_flutter/example/lib/legends/simple_datum_legend.dart +++ b/charts_flutter/example/lib/legends/simple_datum_legend.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart with series legend example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,84 +23,76 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleDatumLegend extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleDatumLegend(this.seriesList, {this.animate = false}); + const SimpleDatumLegend(this.seriesList, {super.key, this.animate = false}); - factory SimpleDatumLegend.withSampleData() { - return new SimpleDatumLegend( + factory SimpleDatumLegend.withSampleData() => SimpleDatumLegend( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleDatumLegend.withRandomData() { - return new SimpleDatumLegend(_createRandomData()); - } + factory SimpleDatumLegend.withRandomData() => SimpleDatumLegend(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart( + Widget build(BuildContext context) => charts.PieChart( seriesList, animate: animate, // Add the series legend behavior to the chart to turn on series legends. // By default the legend will display above the chart. - behaviors: [new charts.DatumLegend()], + behaviors: [charts.DatumLegend()], ); - } /// Create series list with one series static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/legends/simple_series_legend.dart b/charts_flutter/example/lib/legends/simple_series_legend.dart index 7a1c6330b..34f59446f 100644 --- a/charts_flutter/example/lib/legends/simple_series_legend.dart +++ b/charts_flutter/example/lib/legends/simple_series_legend.dart @@ -14,6 +14,8 @@ // limitations under the License. /// Bar chart with series legend example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END @@ -21,82 +23,76 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleSeriesLegend extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleSeriesLegend(this.seriesList, {this.animate = false}); + const SimpleSeriesLegend(this.seriesList, {super.key, this.animate = false}); - factory SimpleSeriesLegend.withSampleData() { - return new SimpleSeriesLegend( + factory SimpleSeriesLegend.withSampleData() => SimpleSeriesLegend( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleSeriesLegend.withRandomData() { - return new SimpleSeriesLegend(_createRandomData()); - } + factory SimpleSeriesLegend.withRandomData() => SimpleSeriesLegend(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final desktopSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final tabletSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final mobileSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; final otherSalesData = [ - new OrdinalSales('2014', random.nextInt(100)), - new OrdinalSales('2015', random.nextInt(100)), - new OrdinalSales('2016', random.nextInt(100)), - new OrdinalSales('2017', random.nextInt(100)), + OrdinalSales('2014', random.nextInt(100)), + OrdinalSales('2015', random.nextInt(100)), + OrdinalSales('2016', random.nextInt(100)), + OrdinalSales('2017', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -104,70 +100,68 @@ class SimpleSeriesLegend extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.BarChart( + Widget build(BuildContext context) => charts.BarChart( seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, // Add the series legend behavior to the chart to turn on series legends. // By default the legend will display above the chart. - behaviors: [new charts.SeriesLegend()], + behaviors: [charts.SeriesLegend()], ); - } /// Create series list with multiple series static List> _createSampleData() { final desktopSalesData = [ - new OrdinalSales('2014', 5), - new OrdinalSales('2015', 25), - new OrdinalSales('2016', 100), - new OrdinalSales('2017', 75), + OrdinalSales('2014', 5), + OrdinalSales('2015', 25), + OrdinalSales('2016', 100), + OrdinalSales('2017', 75), ]; final tabletSalesData = [ - new OrdinalSales('2014', 25), - new OrdinalSales('2015', 50), - new OrdinalSales('2016', 10), - new OrdinalSales('2017', 20), + OrdinalSales('2014', 25), + OrdinalSales('2015', 50), + OrdinalSales('2016', 10), + OrdinalSales('2017', 20), ]; final mobileSalesData = [ - new OrdinalSales('2014', 10), - new OrdinalSales('2015', 15), - new OrdinalSales('2016', 50), - new OrdinalSales('2017', 45), + OrdinalSales('2014', 10), + OrdinalSales('2015', 15), + OrdinalSales('2016', 50), + OrdinalSales('2017', 45), ]; final otherSalesData = [ - new OrdinalSales('2014', 20), - new OrdinalSales('2015', 35), - new OrdinalSales('2016', 15), - new OrdinalSales('2017', 10), + OrdinalSales('2014', 20), + OrdinalSales('2015', 35), + OrdinalSales('2016', 15), + OrdinalSales('2017', 10), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: desktopSalesData, ), - new charts.Series( + charts.Series( id: 'Tablet', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: tabletSalesData, ), - new charts.Series( + charts.Series( id: 'Mobile', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: mobileSalesData, ), - new charts.Series( + charts.Series( id: 'Other', - domainFn: (OrdinalSales sales, _) => sales.year, - measureFn: (OrdinalSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: otherSalesData, ), ]; @@ -176,8 +170,8 @@ class SimpleSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - final String year; - final int sales; OrdinalSales(this.year, this.sales); + final String year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/animation_zoom.dart b/charts_flutter/example/lib/line_chart/animation_zoom.dart index 86a600a55..6871a6a85 100644 --- a/charts_flutter/example/lib/line_chart/animation_zoom.dart +++ b/charts_flutter/example/lib/line_chart/animation_zoom.dart @@ -15,87 +15,82 @@ /// Example of a line chart with pan and zoom enabled via /// [Charts.PanAndZoomBehavior]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class LineAnimationZoomChart extends StatelessWidget { - final List> seriesList; - final bool animate; - LineAnimationZoomChart(this.seriesList, {this.animate = false}); + const LineAnimationZoomChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory LineAnimationZoomChart.withSampleData() { - return new LineAnimationZoomChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory LineAnimationZoomChart.withSampleData() => LineAnimationZoomChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineAnimationZoomChart.withRandomData() { - return new LineAnimationZoomChart(_createRandomData()); - } + factory LineAnimationZoomChart.withRandomData() => LineAnimationZoomChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = []; for (var i = 0; i < 100; i++) { - data.add(new LinearSales(i, random.nextInt(100))); + data.add(LinearSales(i, random.nextInt(100))); } return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate, behaviors: [ - new charts.PanAndZoomBehavior(), - ]); - } + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ + charts.PanAndZoomBehavior(), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/area_and_line.dart b/charts_flutter/example/lib/line_chart/area_and_line.dart index 8290936d7..8cd315297 100644 --- a/charts_flutter/example/lib/line_chart/area_and_line.dart +++ b/charts_flutter/example/lib/line_chart/area_and_line.dart @@ -14,66 +14,63 @@ // limitations under the License. /// Line chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class AreaAndLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - AreaAndLineChart(this.seriesList, {this.animate = false}); + const AreaAndLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory AreaAndLineChart.withSampleData() { - return new AreaAndLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory AreaAndLineChart.withSampleData() => AreaAndLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory AreaAndLineChart.withRandomData() { - return new AreaAndLineChart(_createRandomData()); - } + factory AreaAndLineChart.withRandomData() => AreaAndLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ) // Configure our custom bar target renderer for this series. @@ -83,49 +80,47 @@ class AreaAndLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, customSeriesRenderers: [ - new charts.LineRendererConfig( + charts.LineRendererConfig( // ID used to link series to this renderer. customRendererId: 'customArea', includeArea: true, - stacked: true), - ]); - } + stacked: true,), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; - var myFakeTabletData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + final myFakeTabletData = [ + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customArea'), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), ]; @@ -134,8 +129,8 @@ class AreaAndLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/dash_pattern.dart b/charts_flutter/example/lib/line_chart/dash_pattern.dart index bab7185c8..45eb89c57 100644 --- a/charts_flutter/example/lib/line_chart/dash_pattern.dart +++ b/charts_flutter/example/lib/line_chart/dash_pattern.dart @@ -14,149 +14,144 @@ // limitations under the License. /// Dash pattern line chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; /// Example of a line chart rendered with dash patterns. class DashPatternLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - DashPatternLineChart(this.seriesList, {this.animate = false}); + const DashPatternLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory DashPatternLineChart.withSampleData() { - return new DashPatternLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory DashPatternLineChart.withSampleData() => DashPatternLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DashPatternLineChart.withRandomData() { - return new DashPatternLineChart(_createRandomData()); - } + factory DashPatternLineChart.withRandomData() => DashPatternLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeMobileData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeMobileData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, dashPatternFn: (_, __) => [2, 2], - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, dashPatternFn: (_, __) => [8, 3, 2, 3], - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate); - } + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); /// Create three series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; - var myFakeTabletData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + final myFakeTabletData = [ + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; - var myFakeMobileData = [ - new LinearSales(0, 15), - new LinearSales(1, 75), - new LinearSales(2, 300), - new LinearSales(3, 225), + final myFakeMobileData = [ + LinearSales(0, 15), + LinearSales(1, 75), + LinearSales(2, 300), + LinearSales(3, 225), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, dashPatternFn: (_, __) => [2, 2], - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, dashPatternFn: (_, __) => [8, 3, 2, 3], - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/line_annotation.dart b/charts_flutter/example/lib/line_chart/line_annotation.dart index f1fb8d1c3..00ce4efb3 100644 --- a/charts_flutter/example/lib/line_chart/line_annotation.dart +++ b/charts_flutter/example/lib/line_chart/line_annotation.dart @@ -14,111 +14,106 @@ // limitations under the License. /// Line chart with line annotations example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class LineLineAnnotationChart extends StatelessWidget { - final List> seriesList; - final bool animate; - LineLineAnnotationChart(this.seriesList, {this.animate = false}); + const LineLineAnnotationChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and line annotations. + /// Creates a [charts.LineChart] with sample data and line annotations. /// /// The second annotation extends beyond the range of the series data, /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. - factory LineLineAnnotationChart.withSampleData() { - return new LineLineAnnotationChart( + factory LineLineAnnotationChart.withSampleData() => LineLineAnnotationChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineLineAnnotationChart.withRandomData() { - return new LineLineAnnotationChart(_createRandomData()); - } + factory LineLineAnnotationChart.withRandomData() => LineLineAnnotationChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), // Fix one of the points to 100 so that the annotations are consistently // placed. - new LinearSales(3, 100), + LinearSales(3, 100), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate, behaviors: [ - new charts.RangeAnnotation([ - new charts.LineAnnotationSegment( + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ + charts.RangeAnnotation([ + charts.LineAnnotationSegment( 1.0, charts.RangeAnnotationAxisType.domain, - startLabel: 'Domain 1'), - new charts.LineAnnotationSegment( + startLabel: 'Domain 1',), + charts.LineAnnotationSegment( 4, charts.RangeAnnotationAxisType.domain, - endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200), - new charts.LineAnnotationSegment( + endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200,), + charts.LineAnnotationSegment( 20, charts.RangeAnnotationAxisType.measure, startLabel: 'Measure 1 Start', endLabel: 'Measure 1 End', - color: charts.MaterialPalette.gray.shade300), - new charts.LineAnnotationSegment( + color: charts.MaterialPalette.gray.shade300,), + charts.LineAnnotationSegment( 65, charts.RangeAnnotationAxisType.measure, startLabel: 'Measure 2 Start', endLabel: 'Measure 2 End', - color: charts.MaterialPalette.gray.shade400), + color: charts.MaterialPalette.gray.shade400,), ]), - ]); - } + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/line_gallery.dart b/charts_flutter/example/lib/line_chart/line_gallery.dart index edd29a411..d743f3fcc 100644 --- a/charts_flutter/example/lib/line_chart/line_gallery.dart +++ b/charts_flutter/example/lib/line_chart/line_gallery.dart @@ -13,101 +13,99 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/line_chart/animation_zoom.dart'; +import 'package:example/line_chart/area_and_line.dart'; +import 'package:example/line_chart/dash_pattern.dart'; +import 'package:example/line_chart/line_annotation.dart'; +import 'package:example/line_chart/points.dart'; +import 'package:example/line_chart/range_annotation.dart'; +import 'package:example/line_chart/range_annotation_margin.dart'; +import 'package:example/line_chart/segments.dart'; +import 'package:example/line_chart/simple.dart'; +import 'package:example/line_chart/simple_nulls.dart'; +import 'package:example/line_chart/stacked_area.dart'; +import 'package:example/line_chart/stacked_area_custom_color.dart'; +import 'package:example/line_chart/stacked_area_nulls.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'animation_zoom.dart'; -import 'area_and_line.dart'; -import 'dash_pattern.dart'; -import 'line_annotation.dart'; -import 'points.dart'; -import 'range_annotation.dart'; -import 'range_annotation_margin.dart'; -import 'segments.dart'; -import 'simple.dart'; -import 'simple_nulls.dart'; -import 'stacked_area.dart'; -import 'stacked_area_custom_color.dart'; -import 'stacked_area_nulls.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Simple Line Chart', subtitle: 'With a single series and default line point highlighter', - childBuilder: () => new SimpleLineChart.withRandomData(), + childBuilder: SimpleLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Stacked Area Chart', subtitle: 'Stacked area chart with three series', - childBuilder: () => new StackedAreaLineChart.withRandomData(), + childBuilder: StackedAreaLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Stacked Area Custom Color Chart', subtitle: 'Stacked area chart with custom area skirt color', - childBuilder: () => new StackedAreaCustomColorLineChart.withRandomData(), + childBuilder: StackedAreaCustomColorLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Area and Line Combo Chart', subtitle: 'Combo chart with one line series and one area series', - childBuilder: () => new AreaAndLineChart.withRandomData(), + childBuilder: AreaAndLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Points Line Chart', subtitle: 'Line chart with points on a single series', - childBuilder: () => new PointsLineChart.withRandomData(), + childBuilder: PointsLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Null Data Line Chart', subtitle: 'With a single series and null measure values', - childBuilder: () => new SimpleNullsLineChart.withRandomData(), + childBuilder: SimpleNullsLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Stacked Area with Nulls Chart', subtitle: 'Stacked area chart with three series and null measure values', - childBuilder: () => new StackedAreaNullsLineChart.withRandomData(), + childBuilder: StackedAreaNullsLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Dash Pattern Line Chart', subtitle: 'Line chart with dash patterns', - childBuilder: () => new DashPatternLineChart.withRandomData(), + childBuilder: DashPatternLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Segments Line Chart', subtitle: 'Line chart with changes of style for each line', - childBuilder: () => new SegmentsLineChart.withRandomData(), + childBuilder: SegmentsLineChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Line Annotation Line Chart', subtitle: 'Line chart with line annotations', - childBuilder: () => new LineLineAnnotationChart.withRandomData(), + childBuilder: LineLineAnnotationChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Range Annotation Line Chart', subtitle: 'Line chart with range annotations', - childBuilder: () => new LineRangeAnnotationChart.withRandomData(), + childBuilder: LineRangeAnnotationChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Range Annotation Margin Labels Line Chart', subtitle: 'Line chart with range annotations with labels in margins', - childBuilder: () => new LineRangeAnnotationMarginChart.withRandomData(), + childBuilder: LineRangeAnnotationMarginChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Pan and Zoom Line Chart', subtitle: 'Simple line chart pan and zoom behaviors enabled', - childBuilder: () => new LineAnimationZoomChart.withRandomData(), + childBuilder: LineAnimationZoomChart.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/line_chart/points.dart b/charts_flutter/example/lib/line_chart/points.dart index cf0fc993e..bd456d00b 100644 --- a/charts_flutter/example/lib/line_chart/points.dart +++ b/charts_flutter/example/lib/line_chart/points.dart @@ -14,90 +14,85 @@ // limitations under the License. /// Line chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class PointsLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PointsLineChart(this.seriesList, {this.animate = false}); + const PointsLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory PointsLineChart.withSampleData() { - return new PointsLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory PointsLineChart.withSampleData() => PointsLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PointsLineChart.withRandomData() { - return new PointsLineChart(_createRandomData()); - } + factory PointsLineChart.withRandomData() => PointsLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, - defaultRenderer: new charts.LineRendererConfig(includePoints: true)); - } + defaultRenderer: charts.LineRendererConfig(includePoints: true),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/range_annotation.dart b/charts_flutter/example/lib/line_chart/range_annotation.dart index cc0a9cb37..264d3d010 100644 --- a/charts_flutter/example/lib/line_chart/range_annotation.dart +++ b/charts_flutter/example/lib/line_chart/range_annotation.dart @@ -14,111 +14,106 @@ // limitations under the License. /// Line chart with range annotations example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class LineRangeAnnotationChart extends StatelessWidget { - final List> seriesList; - final bool animate; - LineRangeAnnotationChart(this.seriesList, {this.animate = false}); + const LineRangeAnnotationChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and range annotations. + /// Creates a [charts.LineChart] with sample data and range annotations. /// /// The second annotation extends beyond the range of the series data, /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. - factory LineRangeAnnotationChart.withSampleData() { - return new LineRangeAnnotationChart( + factory LineRangeAnnotationChart.withSampleData() => LineRangeAnnotationChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineRangeAnnotationChart.withRandomData() { - return new LineRangeAnnotationChart(_createRandomData()); - } + factory LineRangeAnnotationChart.withRandomData() => LineRangeAnnotationChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), // Fix one of the points to 100 so that the annotations are consistently // placed. - new LinearSales(3, 100), + LinearSales(3, 100), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate, behaviors: [ - new charts.RangeAnnotation([ - new charts.RangeAnnotationSegment( + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ + charts.RangeAnnotation([ + charts.RangeAnnotationSegment( 0.5, 1.0, charts.RangeAnnotationAxisType.domain, - startLabel: 'Domain 1'), - new charts.RangeAnnotationSegment( + startLabel: 'Domain 1',), + charts.RangeAnnotationSegment( 2, 4, charts.RangeAnnotationAxisType.domain, - endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200), - new charts.RangeAnnotationSegment( + endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200,), + charts.RangeAnnotationSegment( 15, 20, charts.RangeAnnotationAxisType.measure, startLabel: 'Measure 1 Start', endLabel: 'Measure 1 End', - color: charts.MaterialPalette.gray.shade300), - new charts.RangeAnnotationSegment( + color: charts.MaterialPalette.gray.shade300,), + charts.RangeAnnotationSegment( 35, 65, charts.RangeAnnotationAxisType.measure, startLabel: 'Measure 2 Start', endLabel: 'Measure 2 End', - color: charts.MaterialPalette.gray.shade400), + color: charts.MaterialPalette.gray.shade400,), ]), - ]); - } + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/range_annotation_margin.dart b/charts_flutter/example/lib/line_chart/range_annotation_margin.dart index 40a3864e8..2d5a37630 100644 --- a/charts_flutter/example/lib/line_chart/range_annotation_margin.dart +++ b/charts_flutter/example/lib/line_chart/range_annotation_margin.dart @@ -15,127 +15,122 @@ /// Example of a line chart with range annotations configured to render labels /// in the chart margin area. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class LineRangeAnnotationMarginChart extends StatelessWidget { - final List> seriesList; - final bool animate; - LineRangeAnnotationMarginChart(this.seriesList, {this.animate = false}); + const LineRangeAnnotationMarginChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and range annotations. + /// Creates a [charts.LineChart] with sample data and range annotations. /// /// The second annotation extends beyond the range of the series data, /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. - factory LineRangeAnnotationMarginChart.withSampleData() { - return new LineRangeAnnotationMarginChart( + factory LineRangeAnnotationMarginChart.withSampleData() => LineRangeAnnotationMarginChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineRangeAnnotationMarginChart.withRandomData() { - return new LineRangeAnnotationMarginChart(_createRandomData()); - } + factory LineRangeAnnotationMarginChart.withRandomData() => LineRangeAnnotationMarginChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), // Fix one of the points to 100 so that the annotations are consistently // placed. - new LinearSales(3, 100), + LinearSales(3, 100), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, // Allow enough space in the left and right chart margins for the // annotations. - layoutConfig: new charts.LayoutConfig( - leftMarginSpec: new charts.MarginSpec.fixedPixel(60), - topMarginSpec: new charts.MarginSpec.fixedPixel(20), - rightMarginSpec: new charts.MarginSpec.fixedPixel(60), - bottomMarginSpec: new charts.MarginSpec.fixedPixel(20)), + layoutConfig: charts.LayoutConfig( + leftMarginSpec: charts.MarginSpec.fixedPixel(60), + topMarginSpec: charts.MarginSpec.fixedPixel(20), + rightMarginSpec: charts.MarginSpec.fixedPixel(60), + bottomMarginSpec: charts.MarginSpec.fixedPixel(20),), behaviors: [ // Define one domain and two measure annotations configured to render // labels in the chart margins. - new charts.RangeAnnotation([ - new charts.RangeAnnotationSegment( + charts.RangeAnnotation([ + charts.RangeAnnotationSegment( 0.5, 1.0, charts.RangeAnnotationAxisType.domain, startLabel: 'D1 Start', endLabel: 'D1 End', labelAnchor: charts.AnnotationLabelAnchor.end, color: charts.MaterialPalette.gray.shade200, // Override the default vertical direction for domain labels. - labelDirection: charts.AnnotationLabelDirection.horizontal), - new charts.RangeAnnotationSegment( + labelDirection: charts.AnnotationLabelDirection.horizontal,), + charts.RangeAnnotationSegment( 15, 20, charts.RangeAnnotationAxisType.measure, startLabel: 'M1 Start', endLabel: 'M1 End', labelAnchor: charts.AnnotationLabelAnchor.end, - color: charts.MaterialPalette.gray.shade300), - new charts.RangeAnnotationSegment( + color: charts.MaterialPalette.gray.shade300,), + charts.RangeAnnotationSegment( 35, 65, charts.RangeAnnotationAxisType.measure, startLabel: 'M2 Start', endLabel: 'M2 End', labelAnchor: charts.AnnotationLabelAnchor.start, - color: charts.MaterialPalette.gray.shade400), - ], defaultLabelPosition: charts.AnnotationLabelPosition.margin), - ]); - } + color: charts.MaterialPalette.gray.shade400,), + ], defaultLabelPosition: charts.AnnotationLabelPosition.margin,), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/segments.dart b/charts_flutter/example/lib/line_chart/segments.dart index 52e845341..3ae308cb5 100644 --- a/charts_flutter/example/lib/line_chart/segments.dart +++ b/charts_flutter/example/lib/line_chart/segments.dart @@ -25,71 +25,68 @@ /// the [charts.LineRendererConfig]. This could be used, for example, to define /// a default dash pattern for the series, with only a specific datum called out /// with a different pattern. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SegmentsLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SegmentsLineChart(this.seriesList, {this.animate = false}); + const SegmentsLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SegmentsLineChart.withSampleData() { - return new SegmentsLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SegmentsLineChart.withSampleData() => SegmentsLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SegmentsLineChart.withRandomData() { - return new SegmentsLineChart(_createRandomData()); - } + factory SegmentsLineChart.withRandomData() => SegmentsLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); // Series of data with static dash pattern and stroke width. The colorFn // accessor will colorize each datum (for all three series). final colorChangeData = [ - new LinearSales(0, random.nextInt(100), null, 2.0), - new LinearSales(1, random.nextInt(100), null, 2.0), - new LinearSales(2, random.nextInt(100), null, 2.0), - new LinearSales(3, random.nextInt(100), null, 2.0), - new LinearSales(4, random.nextInt(100), null, 2.0), - new LinearSales(5, random.nextInt(100), null, 2.0), - new LinearSales(6, random.nextInt(100), null, 2.0), + LinearSales(0, random.nextInt(100), null, 2), + LinearSales(1, random.nextInt(100), null, 2), + LinearSales(2, random.nextInt(100), null, 2), + LinearSales(3, random.nextInt(100), null, 2), + LinearSales(4, random.nextInt(100), null, 2), + LinearSales(5, random.nextInt(100), null, 2), + LinearSales(6, random.nextInt(100), null, 2), ]; // Series of data with changing color and dash pattern. final dashPatternChangeData = [ - new LinearSales(0, random.nextInt(100), [2, 2], 2.0), - new LinearSales(1, random.nextInt(100), [2, 2], 2.0), - new LinearSales(2, random.nextInt(100), [4, 4], 2.0), - new LinearSales(3, random.nextInt(100), [4, 4], 2.0), - new LinearSales(4, random.nextInt(100), [4, 4], 2.0), - new LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0), - new LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0), + LinearSales(0, random.nextInt(100), [2, 2], 2), + LinearSales(1, random.nextInt(100), [2, 2], 2), + LinearSales(2, random.nextInt(100), [4, 4], 2), + LinearSales(3, random.nextInt(100), [4, 4], 2), + LinearSales(4, random.nextInt(100), [4, 4], 2), + LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2), + LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2), ]; // Series of data with changing color and stroke width. final strokeWidthChangeData = [ - new LinearSales(0, random.nextInt(100), null, 2.0), - new LinearSales(1, random.nextInt(100), null, 2.0), - new LinearSales(2, random.nextInt(100), null, 4.0), - new LinearSales(3, random.nextInt(100), null, 4.0), - new LinearSales(4, random.nextInt(100), null, 4.0), - new LinearSales(5, random.nextInt(100), null, 6.0), - new LinearSales(6, random.nextInt(100), null, 6.0), + LinearSales(0, random.nextInt(100), null, 2), + LinearSales(1, random.nextInt(100), null, 2), + LinearSales(2, random.nextInt(100), null, 4), + LinearSales(3, random.nextInt(100), null, 4), + LinearSales(4, random.nextInt(100), null, 4), + LinearSales(5, random.nextInt(100), null, 6), + LinearSales(6, random.nextInt(100), null, 6), ]; // Generate 2 shades of each color so that we can style the line segments. @@ -98,37 +95,37 @@ class SegmentsLineChart extends StatelessWidget { final green = charts.MaterialPalette.green.makeShades(2); return [ - new charts.Series( + charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? blue[1] : blue[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: colorChangeData, ), - new charts.Series( + charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? red[1] : red[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: dashPatternChangeData, ), - new charts.Series( + charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? green[1] : green[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: strokeWidthChangeData, ), ]; @@ -136,47 +133,45 @@ class SegmentsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, defaultRenderer: - new charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate); - } + charts.LineRendererConfig(includeArea: true, stacked: true), + animate: animate,); /// Create one series with sample hard coded data. static List> _createSampleData() { // Series of data with static dash pattern and stroke width. The colorFn // accessor will colorize each datum (for all three series). final colorChangeData = [ - new LinearSales(0, 5, null, 2.0), - new LinearSales(1, 15, null, 2.0), - new LinearSales(2, 25, null, 2.0), - new LinearSales(3, 75, null, 2.0), - new LinearSales(4, 100, null, 2.0), - new LinearSales(5, 90, null, 2.0), - new LinearSales(6, 75, null, 2.0), + LinearSales(0, 5, null, 2), + LinearSales(1, 15, null, 2), + LinearSales(2, 25, null, 2), + LinearSales(3, 75, null, 2), + LinearSales(4, 100, null, 2), + LinearSales(5, 90, null, 2), + LinearSales(6, 75, null, 2), ]; // Series of data with changing color and dash pattern. final dashPatternChangeData = [ - new LinearSales(0, 5, [2, 2], 2.0), - new LinearSales(1, 15, [2, 2], 2.0), - new LinearSales(2, 25, [4, 4], 2.0), - new LinearSales(3, 75, [4, 4], 2.0), - new LinearSales(4, 100, [4, 4], 2.0), - new LinearSales(5, 90, [8, 3, 2, 3], 2.0), - new LinearSales(6, 75, [8, 3, 2, 3], 2.0), + LinearSales(0, 5, [2, 2], 2), + LinearSales(1, 15, [2, 2], 2), + LinearSales(2, 25, [4, 4], 2), + LinearSales(3, 75, [4, 4], 2), + LinearSales(4, 100, [4, 4], 2), + LinearSales(5, 90, [8, 3, 2, 3], 2), + LinearSales(6, 75, [8, 3, 2, 3], 2), ]; // Series of data with changing color and stroke width. final strokeWidthChangeData = [ - new LinearSales(0, 5, null, 2.0), - new LinearSales(1, 15, null, 2.0), - new LinearSales(2, 25, null, 4.0), - new LinearSales(3, 75, null, 4.0), - new LinearSales(4, 100, null, 4.0), - new LinearSales(5, 90, null, 6.0), - new LinearSales(6, 75, null, 6.0), + LinearSales(0, 5, null, 2), + LinearSales(1, 15, null, 2), + LinearSales(2, 25, null, 4), + LinearSales(3, 75, null, 4), + LinearSales(4, 100, null, 4), + LinearSales(5, 90, null, 6), + LinearSales(6, 75, null, 6), ]; // Generate 2 shades of each color so that we can style the line segments. @@ -185,37 +180,37 @@ class SegmentsLineChart extends StatelessWidget { final green = charts.MaterialPalette.green.makeShades(2); return [ - new charts.Series( + charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? blue[1] : blue[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: colorChangeData, ), - new charts.Series( + charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? red[1] : red[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: dashPatternChangeData, ), - new charts.Series( + charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => sales.year % 2 == 0 ? green[1] : green[0], - dashPatternFn: (LinearSales sales, _) => sales.dashPattern, - strokeWidthPxFn: (LinearSales sales, _) => sales.strokeWidthPx, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + dashPatternFn: (sales, _) => sales.dashPattern, + strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: strokeWidthChangeData, ), ]; @@ -224,10 +219,10 @@ class SegmentsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); final int year; final int sales; final List? dashPattern; final double strokeWidthPx; - - LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); } diff --git a/charts_flutter/example/lib/line_chart/simple.dart b/charts_flutter/example/lib/line_chart/simple.dart index a7d01dba6..6f818fb58 100644 --- a/charts_flutter/example/lib/line_chart/simple.dart +++ b/charts_flutter/example/lib/line_chart/simple.dart @@ -14,88 +14,83 @@ // limitations under the License. /// Example of a simple line chart. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimpleLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleLineChart(this.seriesList, {this.animate = false}); + const SimpleLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SimpleLineChart.withSampleData() { - return new SimpleLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SimpleLineChart.withSampleData() => SimpleLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleLineChart.withRandomData() { - return new SimpleLineChart(_createRandomData()); - } + factory SimpleLineChart.withRandomData() => SimpleLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate); - } + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/simple_nulls.dart b/charts_flutter/example/lib/line_chart/simple_nulls.dart index cce1a25c6..39877412c 100644 --- a/charts_flutter/example/lib/line_chart/simple_nulls.dart +++ b/charts_flutter/example/lib/line_chart/simple_nulls.dart @@ -18,89 +18,86 @@ /// Null values will be visible as gaps in lines and area skirts. Any data /// points that exist between two nulls in a line will be rendered as an /// isolated point, as seen in the green series. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimpleNullsLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleNullsLineChart(this.seriesList, {this.animate = false}); + const SimpleNullsLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory SimpleNullsLineChart.withSampleData() { - return new SimpleNullsLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory SimpleNullsLineChart.withSampleData() => SimpleNullsLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleNullsLineChart.withRandomData() { - return new SimpleNullsLineChart(_createRandomData()); - } + factory SimpleNullsLineChart.withRandomData() => SimpleNullsLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, null), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, random.nextInt(100)), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, null), + LinearSales(3, random.nextInt(100)), + LinearSales(4, random.nextInt(100)), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, random.nextInt(100)), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), + LinearSales(4, random.nextInt(100)), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; - var myFakeMobileData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, null), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, null), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + final myFakeMobileData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, null), + LinearSales(3, random.nextInt(100)), + LinearSales(4, null), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -108,62 +105,60 @@ class SimpleNullsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, animate: animate); - } + Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 15), - new LinearSales(2, null), - new LinearSales(3, 75), - new LinearSales(4, 100), - new LinearSales(5, 90), - new LinearSales(6, 75), + LinearSales(0, 5), + LinearSales(1, 15), + LinearSales(2, null), + LinearSales(3, 75), + LinearSales(4, 100), + LinearSales(5, 90), + LinearSales(6, 75), ]; final myFakeTabletData = [ - new LinearSales(0, 10), - new LinearSales(1, 30), - new LinearSales(2, 50), - new LinearSales(3, 150), - new LinearSales(4, 200), - new LinearSales(5, 180), - new LinearSales(6, 150), + LinearSales(0, 10), + LinearSales(1, 30), + LinearSales(2, 50), + LinearSales(3, 150), + LinearSales(4, 200), + LinearSales(5, 180), + LinearSales(6, 150), ]; final myFakeMobileData = [ - new LinearSales(0, 15), - new LinearSales(1, 45), - new LinearSales(2, null), - new LinearSales(3, 225), - new LinearSales(4, null), - new LinearSales(5, 270), - new LinearSales(6, 225), + LinearSales(0, 15), + LinearSales(1, 45), + LinearSales(2, null), + LinearSales(3, 225), + LinearSales(4, null), + LinearSales(5, 270), + LinearSales(6, 225), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -172,8 +167,8 @@ class SimpleNullsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int? sales; LinearSales(this.year, this.sales); + final int year; + final int? sales; } diff --git a/charts_flutter/example/lib/line_chart/stacked_area.dart b/charts_flutter/example/lib/line_chart/stacked_area.dart index 3bf088753..dbb14a6e0 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area.dart @@ -14,80 +14,77 @@ // limitations under the License. /// Example of a stacked area chart. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class StackedAreaLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedAreaLineChart(this.seriesList, {this.animate = false}); + const StackedAreaLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory StackedAreaLineChart.withSampleData() { - return new StackedAreaLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory StackedAreaLineChart.withSampleData() => StackedAreaLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaLineChart.withRandomData() { - return new StackedAreaLineChart(_createRandomData()); - } + factory StackedAreaLineChart.withRandomData() => StackedAreaLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeMobileData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeMobileData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -95,56 +92,54 @@ class StackedAreaLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, defaultRenderer: - new charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate); - } + charts.LineRendererConfig(includeArea: true, stacked: true), + animate: animate,); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; - var myFakeTabletData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + final myFakeTabletData = [ + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; - var myFakeMobileData = [ - new LinearSales(0, 15), - new LinearSales(1, 75), - new LinearSales(2, 300), - new LinearSales(3, 225), + final myFakeMobileData = [ + LinearSales(0, 15), + LinearSales(1, 75), + LinearSales(2, 300), + LinearSales(3, 225), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -153,8 +148,8 @@ class StackedAreaLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart b/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart index 2e7d161f0..64db3e9ec 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart @@ -18,80 +18,77 @@ /// By default, the area skirt for a chart will be drawn with the same color as /// the line, but with a 10% opacity assigned to it. An area color function can /// be provided to override this with any custom color. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class StackedAreaCustomColorLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedAreaCustomColorLineChart(this.seriesList, {this.animate = false}); + const StackedAreaCustomColorLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory StackedAreaCustomColorLineChart.withSampleData() { - return new StackedAreaCustomColorLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory StackedAreaCustomColorLineChart.withSampleData() => StackedAreaCustomColorLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaCustomColorLineChart.withRandomData() { - return new StackedAreaCustomColorLineChart(_createRandomData()); - } + factory StackedAreaCustomColorLineChart.withRandomData() => StackedAreaCustomColorLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; - var myFakeMobileData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + final myFakeMobileData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -99,67 +96,65 @@ class StackedAreaCustomColorLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, defaultRenderer: - new charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate); - } + charts.LineRendererConfig(includeArea: true, stacked: true), + animate: animate,); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 25), - new LinearSales(2, 100), - new LinearSales(3, 75), + LinearSales(0, 5), + LinearSales(1, 25), + LinearSales(2, 100), + LinearSales(3, 75), ]; - var myFakeTabletData = [ - new LinearSales(0, 10), - new LinearSales(1, 50), - new LinearSales(2, 200), - new LinearSales(3, 150), + final myFakeTabletData = [ + LinearSales(0, 10), + LinearSales(1, 50), + LinearSales(2, 200), + LinearSales(3, 150), ]; - var myFakeMobileData = [ - new LinearSales(0, 15), - new LinearSales(1, 75), - new LinearSales(2, 300), - new LinearSales(3, 225), + final myFakeMobileData = [ + LinearSales(0, 15), + LinearSales(1, 75), + LinearSales(2, 300), + LinearSales(3, 225), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', // colorFn specifies that the line will be blue. colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, // areaColorFn specifies that the area skirt will be light blue. areaColorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault.lighter, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', // colorFn specifies that the line will be red. colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, // areaColorFn specifies that the area skirt will be light red. areaColorFn: (_, __) => charts.MaterialPalette.red.shadeDefault.lighter, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', // colorFn specifies that the line will be green. colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, // areaColorFn specifies that the area skirt will be light green. areaColorFn: (_, __) => charts.MaterialPalette.green.shadeDefault.lighter, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -168,8 +163,8 @@ class StackedAreaCustomColorLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart index 918d385f9..1b5c5f2d1 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart @@ -27,89 +27,86 @@ /// This will also result in an isolated point being rendered for the domain /// value 3 in the Mobile series, because that series also contains a null at /// domain 4. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class StackedAreaNullsLineChart extends StatelessWidget { - final List> seriesList; - final bool animate; - StackedAreaNullsLineChart(this.seriesList, {this.animate = false}); + const StackedAreaNullsLineChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [LineChart] with sample data and no transition. - factory StackedAreaNullsLineChart.withSampleData() { - return new StackedAreaNullsLineChart( + /// Creates a [charts.LineChart] with sample data and no transition. + factory StackedAreaNullsLineChart.withSampleData() => StackedAreaNullsLineChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaNullsLineChart.withRandomData() { - return new StackedAreaNullsLineChart(_createRandomData()); - } + factory StackedAreaNullsLineChart.withRandomData() => StackedAreaNullsLineChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myFakeDesktopData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, null), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, random.nextInt(100)), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, null), + LinearSales(3, random.nextInt(100)), + LinearSales(4, random.nextInt(100)), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; - var myFakeTabletData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, random.nextInt(100)), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + final myFakeTabletData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), + LinearSales(4, random.nextInt(100)), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; - var myFakeMobileData = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), - new LinearSales(4, null), - new LinearSales(5, random.nextInt(100)), - new LinearSales(6, random.nextInt(100)), + final myFakeMobileData = [ + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), + LinearSales(4, null), + LinearSales(5, random.nextInt(100)), + LinearSales(6, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -117,65 +114,63 @@ class StackedAreaNullsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart(seriesList, defaultRenderer: - new charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate); - } + charts.LineRendererConfig(includeArea: true, stacked: true), + animate: animate,); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(0, 5), - new LinearSales(1, 15), - new LinearSales(2, null), - new LinearSales(3, 75), - new LinearSales(4, 100), - new LinearSales(5, 90), - new LinearSales(6, 75), + LinearSales(0, 5), + LinearSales(1, 15), + LinearSales(2, null), + LinearSales(3, 75), + LinearSales(4, 100), + LinearSales(5, 90), + LinearSales(6, 75), ]; final myFakeTabletData = [ - new LinearSales(0, 5), - new LinearSales(1, 15), - new LinearSales(2, 25), - new LinearSales(3, 75), - new LinearSales(4, 100), - new LinearSales(5, 90), - new LinearSales(6, 75), + LinearSales(0, 5), + LinearSales(1, 15), + LinearSales(2, 25), + LinearSales(3, 75), + LinearSales(4, 100), + LinearSales(5, 90), + LinearSales(6, 75), ]; final myFakeMobileData = [ - new LinearSales(0, 5), - new LinearSales(1, 15), - new LinearSales(2, 25), - new LinearSales(3, 75), - new LinearSales(4, null), - new LinearSales(5, 90), - new LinearSales(6, 75), + LinearSales(0, 5), + LinearSales(1, 15), + LinearSales(2, 25), + LinearSales(3, 75), + LinearSales(4, null), + LinearSales(5, 90), + LinearSales(6, 75), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeTabletData, ), - new charts.Series( + charts.Series( id: 'Mobile', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: myFakeMobileData, ), ]; @@ -184,8 +179,8 @@ class StackedAreaNullsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - final int year; - final int? sales; LinearSales(this.year, this.sales); + final int year; + final int? sales; } diff --git a/charts_flutter/example/lib/main.dart b/charts_flutter/example/lib/main.dart index 8a6484dcc..bb0fcd1dd 100644 --- a/charts_flutter/example/lib/main.dart +++ b/charts_flutter/example/lib/main.dart @@ -13,16 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/app_config.dart'; +import 'package:example/home.dart'; import 'package:flutter/material.dart'; -import 'app_config.dart'; -import 'home.dart'; /// The main gallery app widget. class GalleryApp extends StatefulWidget { - GalleryApp({Key? key}) : super(key: key); + const GalleryApp({super.key}); @override - GalleryAppState createState() => new GalleryAppState(); + GalleryAppState createState() => GalleryAppState(); } /// The main gallery app state. @@ -30,15 +30,13 @@ class GalleryApp extends StatefulWidget { /// Controls performance overlay, and instantiates a [Home] widget. class GalleryAppState extends State { @override - Widget build(BuildContext context) { - return new MaterialApp( + Widget build(BuildContext context) => MaterialApp( debugShowCheckedModeBanner: false, title: defaultConfig.appName, theme: defaultConfig.theme, - home: new Home()); - } + home: Home(),); } void main() { - runApp(new GalleryApp()); + runApp(const GalleryApp()); } diff --git a/charts_flutter/example/lib/pie_chart/auto_label.dart b/charts_flutter/example/lib/pie_chart/auto_label.dart index 09bf24498..bce273dd9 100644 --- a/charts_flutter/example/lib/pie_chart/auto_label.dart +++ b/charts_flutter/example/lib/pie_chart/auto_label.dart @@ -15,62 +15,58 @@ /// Donut chart with labels example. This is a simple pie chart with a hole in /// the middle. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class DonutAutoLabelChart extends StatelessWidget { - final List> seriesList; - final bool animate; - DonutAutoLabelChart(this.seriesList, {this.animate = false}); + const DonutAutoLabelChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [PieChart] with sample data and no transition. - factory DonutAutoLabelChart.withSampleData() { - return new DonutAutoLabelChart( + /// Creates a [charts.PieChart] with sample data and no transition. + factory DonutAutoLabelChart.withSampleData() => DonutAutoLabelChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DonutAutoLabelChart.withRandomData() { - return new DonutAutoLabelChart(_createRandomData()); - } + factory DonutAutoLabelChart.withRandomData() => DonutAutoLabelChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the arc label. - labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}', - ) + labelAccessorFn: (row, _) => '${row.year}: ${row.sales}', + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. @@ -87,37 +83,36 @@ class DonutAutoLabelChart extends StatelessWidget { // new charts.ArcLabelDecorator( // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - defaultRenderer: new charts.ArcRendererConfig( + defaultRenderer: charts.ArcRendererConfig( arcWidth: 60, - arcRendererDecorators: [new charts.ArcLabelDecorator()])); - } + arcRendererDecorators: [charts.ArcLabelDecorator()],),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the arc label. - labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}', - ) + labelAccessorFn: (row, _) => '${row.year}: ${row.sales}', + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/pie_chart/donut.dart b/charts_flutter/example/lib/pie_chart/donut.dart index 58a0f571e..a627c6e82 100644 --- a/charts_flutter/example/lib/pie_chart/donut.dart +++ b/charts_flutter/example/lib/pie_chart/donut.dart @@ -14,90 +14,85 @@ // limitations under the License. /// Donut chart example. This is a simple pie chart with a hole in the middle. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class DonutPieChart extends StatelessWidget { - final List> seriesList; - final bool animate; - DonutPieChart(this.seriesList, {this.animate = false}); + const DonutPieChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [PieChart] with sample data and no transition. - factory DonutPieChart.withSampleData() { - return new DonutPieChart( + /// Creates a [charts.PieChart] with sample data and no transition. + factory DonutPieChart.withSampleData() => DonutPieChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DonutPieChart.withRandomData() { - return new DonutPieChart(_createRandomData()); - } + factory DonutPieChart.withRandomData() => DonutPieChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. - defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60)); - } + defaultRenderer: charts.ArcRendererConfig(arcWidth: 60),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/pie_chart/gauge.dart b/charts_flutter/example/lib/pie_chart/gauge.dart index b5fd7fa89..b0c3e80c1 100644 --- a/charts_flutter/example/lib/pie_chart/gauge.dart +++ b/charts_flutter/example/lib/pie_chart/gauge.dart @@ -15,92 +15,87 @@ /// Gauge chart example, where the data does not cover a full revolution in the /// chart. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class GaugeChart extends StatelessWidget { - final List> seriesList; - final bool animate; - GaugeChart(this.seriesList, {this.animate = false}); + const GaugeChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [PieChart] with sample data and no transition. - factory GaugeChart.withSampleData() { - return new GaugeChart( + /// Creates a [charts.PieChart] with sample data and no transition. + factory GaugeChart.withSampleData() => GaugeChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GaugeChart.withRandomData() { - return new GaugeChart(_createRandomData()); - } + factory GaugeChart.withRandomData() => GaugeChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new GaugeSegment('Low', random.nextInt(100)), - new GaugeSegment('Acceptable', random.nextInt(100)), - new GaugeSegment('High', random.nextInt(100)), - new GaugeSegment('Highly Unusual', random.nextInt(100)), + GaugeSegment('Low', random.nextInt(100)), + GaugeSegment('Acceptable', random.nextInt(100)), + GaugeSegment('High', random.nextInt(100)), + GaugeSegment('Highly Unusual', random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Segments', - domainFn: (GaugeSegment segment, _) => segment.segment, - measureFn: (GaugeSegment segment, _) => segment.size, + domainFn: (segment, _) => segment.segment, + measureFn: (segment, _) => segment.size, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate, // Configure the width of the pie slices to 30px. The remaining space in // the chart will be left as a hole in the center. Adjust the start // angle and the arc length of the pie so it resembles a gauge. - defaultRenderer: new charts.ArcRendererConfig( - arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi)); - } + defaultRenderer: charts.ArcRendererConfig( + arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi,),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new GaugeSegment('Low', 75), - new GaugeSegment('Acceptable', 100), - new GaugeSegment('High', 50), - new GaugeSegment('Highly Unusual', 5), + GaugeSegment('Low', 75), + GaugeSegment('Acceptable', 100), + GaugeSegment('High', 50), + GaugeSegment('Highly Unusual', 5), ]; return [ - new charts.Series( + charts.Series( id: 'Segments', - domainFn: (GaugeSegment segment, _) => segment.segment, - measureFn: (GaugeSegment segment, _) => segment.size, + domainFn: (segment, _) => segment.segment, + measureFn: (segment, _) => segment.size, data: data, - ) + ), ]; } } /// Sample data type. class GaugeSegment { - final String segment; - final int size; GaugeSegment(this.segment, this.size); + final String segment; + final int size; } diff --git a/charts_flutter/example/lib/pie_chart/outside_label.dart b/charts_flutter/example/lib/pie_chart/outside_label.dart index a4c068f60..8b7a44960 100644 --- a/charts_flutter/example/lib/pie_chart/outside_label.dart +++ b/charts_flutter/example/lib/pie_chart/outside_label.dart @@ -14,62 +14,58 @@ // limitations under the License. /// Simple pie chart with outside labels example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class PieOutsideLabelChart extends StatelessWidget { - final List> seriesList; - final bool animate; - PieOutsideLabelChart(this.seriesList, {this.animate = false}); + const PieOutsideLabelChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [PieChart] with sample data and no transition. - factory PieOutsideLabelChart.withSampleData() { - return new PieOutsideLabelChart( + /// Creates a [charts.PieChart] with sample data and no transition. + factory PieOutsideLabelChart.withSampleData() => PieOutsideLabelChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PieOutsideLabelChart.withRandomData() { - return new PieOutsideLabelChart(_createRandomData()); - } + factory PieOutsideLabelChart.withRandomData() => PieOutsideLabelChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the arc label. - labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}', - ) + labelAccessorFn: (row, _) => '${row.year}: ${row.sales}', + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate, // Add an [ArcLabelDecorator] configured to render labels outside of the // arc with a leader line. @@ -81,38 +77,37 @@ class PieOutsideLabelChart extends StatelessWidget { // new charts.ArcLabelDecorator( // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - defaultRenderer: new charts.ArcRendererConfig(arcRendererDecorators: [ - new charts.ArcLabelDecorator( - labelPosition: charts.ArcLabelPosition.outside) - ])); - } + defaultRenderer: charts.ArcRendererConfig(arcRendererDecorators: [ + charts.ArcLabelDecorator( + labelPosition: charts.ArcLabelPosition.outside,), + ],),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the arc label. - labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}', - ) + labelAccessorFn: (row, _) => '${row.year}: ${row.sales}', + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/pie_chart/partial_pie.dart b/charts_flutter/example/lib/pie_chart/partial_pie.dart index 80a98a2e0..4175d15d7 100644 --- a/charts_flutter/example/lib/pie_chart/partial_pie.dart +++ b/charts_flutter/example/lib/pie_chart/partial_pie.dart @@ -15,26 +15,29 @@ /// Partial pie chart example, where the data does not cover a full revolution /// in the chart. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; /// Creates a partial pie chart where the data does not cover a full revolution. class PartialPieChart extends StatelessWidget { - final List> seriesList; - final bool animate; - const PartialPieChart(this.seriesList, {this.animate = false}); + const PartialPieChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [PartialPieChart] with sample data and no transition. factory PartialPieChart.withSampleData() => - PartialPieChart(_createSampleData(), animate: false); + PartialPieChart(_createSampleData()); /// Creates a [PartialPieChart] with random data. factory PartialPieChart.withRandomData() => PartialPieChart(_createRandomData()); + final List> seriesList; + final bool animate; @override Widget build(BuildContext context) => charts.PieChart( @@ -47,15 +50,15 @@ class PartialPieChart extends StatelessWidget { static List> _createSampleData() => [ charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: [ LinearSales(0, 100), LinearSales(1, 75), LinearSales(2, 25), LinearSales(3, 5), ], - ) + ), ]; /// Creates random data. @@ -64,19 +67,19 @@ class PartialPieChart extends StatelessWidget { return [ charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: List.generate( - 4, (index) => LinearSales(index, random.nextInt(100))), - ) + 4, (index) => LinearSales(index, random.nextInt(100)),), + ), ]; } } /// Represents linear sales data. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/pie_chart/pie_gallery.dart b/charts_flutter/example/lib/pie_chart/pie_gallery.dart index 8e24b57b3..ae7d21a61 100644 --- a/charts_flutter/example/lib/pie_chart/pie_gallery.dart +++ b/charts_flutter/example/lib/pie_chart/pie_gallery.dart @@ -13,22 +13,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/pie_chart/partial_pie.dart'; +import 'package:example/pie_chart/simple.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'auto_label.dart'; -import 'donut.dart'; -import 'gauge.dart'; -import 'simple.dart'; -import 'outside_label.dart'; -import 'partial_pie.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.pie_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), title: 'Simple Pie Chart', subtitle: 'With a single series', - childBuilder: () => new SimplePieChart.withRandomData(), + childBuilder: SimplePieChart.withRandomData, ), //TODO: // new GalleryScaffold( @@ -37,11 +32,11 @@ List buildGallery() { // subtitle: 'With a single series and labels outside the arcs', // childBuilder: () => new PieOutsideLabelChart.withRandomData(), // ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.pie_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), title: 'Partial Pie Chart', - subtitle: 'That doesn\'t cover a full revolution', - childBuilder: () => new PartialPieChart.withRandomData(), + subtitle: "That doesn't cover a full revolution", + childBuilder: PartialPieChart.withRandomData, ), //TODO: // new GalleryScaffold( @@ -64,4 +59,3 @@ List buildGallery() { // childBuilder: () => new GaugeChart.withRandomData(), // ), ]; -} diff --git a/charts_flutter/example/lib/pie_chart/simple.dart b/charts_flutter/example/lib/pie_chart/simple.dart index 94a649465..9facbcc59 100644 --- a/charts_flutter/example/lib/pie_chart/simple.dart +++ b/charts_flutter/example/lib/pie_chart/simple.dart @@ -14,86 +14,81 @@ // limitations under the License. /// Simple pie chart example. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimplePieChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimplePieChart(this.seriesList, {this.animate = false}); + const SimplePieChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [PieChart] with sample data and no transition. - factory SimplePieChart.withSampleData() { - return new SimplePieChart( + /// Creates a [charts.PieChart] with sample data and no transition. + factory SimplePieChart.withSampleData() => SimplePieChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimplePieChart.withRandomData() { - return new SimplePieChart(_createRandomData()); - } + factory SimplePieChart.withRandomData() => SimplePieChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new LinearSales(0, random.nextInt(100)), - new LinearSales(1, random.nextInt(100)), - new LinearSales(2, random.nextInt(100)), - new LinearSales(3, random.nextInt(100)), + LinearSales(0, random.nextInt(100)), + LinearSales(1, random.nextInt(100)), + LinearSales(2, random.nextInt(100)), + LinearSales(3, random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.PieChart(seriesList, animate: animate); - } + Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 100), - new LinearSales(1, 75), - new LinearSales(2, 25), - new LinearSales(3, 5), + LinearSales(0, 100), + LinearSales(1, 75), + LinearSales(2, 25), + LinearSales(3, 5), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { - final int year; - final int sales; LinearSales(this.year, this.sales); + final int year; + final int sales; } diff --git a/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart b/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart index c82f480c1..4a30db2dd 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart @@ -15,53 +15,50 @@ /// Example of a line chart with pan and zoom enabled via /// [Charts.PanAndZoomBehavior]. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class ScatterPlotAnimationZoomChart extends StatelessWidget { - final List> seriesList; - final bool animate; - ScatterPlotAnimationZoomChart(this.seriesList, {this.animate = false}); + const ScatterPlotAnimationZoomChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory ScatterPlotAnimationZoomChart.withSampleData() { - return new ScatterPlotAnimationZoomChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory ScatterPlotAnimationZoomChart.withSampleData() => ScatterPlotAnimationZoomChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ScatterPlotAnimationZoomChart.withRandomData() { - return new ScatterPlotAnimationZoomChart(_createRandomData()); - } + factory ScatterPlotAnimationZoomChart.withRandomData() => ScatterPlotAnimationZoomChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = []; - final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); for (var i = 0; i < 100; i++) { - data.add(new LinearSales(i, random.nextInt(100), makeRadius(4))); + data.add(LinearSales(i, random.nextInt(100), makeRadius(4))); } - final maxMeasure = 100; + const maxMeasure = 100; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -73,47 +70,45 @@ class ScatterPlotAnimationZoomChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate, behaviors: [ - new charts.PanAndZoomBehavior(), - ]); - } + charts.PanAndZoomBehavior(), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5, 3.0), - new LinearSales(10, 25, 5.0), - new LinearSales(12, 75, 4.0), - new LinearSales(13, 225, 5.0), - new LinearSales(16, 50, 4.0), - new LinearSales(24, 75, 3.0), - new LinearSales(25, 100, 3.0), - new LinearSales(34, 150, 5.0), - new LinearSales(37, 10, 4.5), - new LinearSales(45, 300, 8.0), - new LinearSales(52, 15, 4.0), - new LinearSales(56, 200, 7.0), + LinearSales(0, 5, 3), + LinearSales(10, 25, 5), + LinearSales(12, 75, 4), + LinearSales(13, 225, 5), + LinearSales(16, 50, 4), + LinearSales(24, 75, 3), + LinearSales(25, 100, 3), + LinearSales(34, 150, 5), + LinearSales(37, 10, 4.5), + LinearSales(45, 300, 8), + LinearSales(52, 15, 4), + LinearSales(56, 200, 7), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -125,20 +120,20 @@ class ScatterPlotAnimationZoomChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.radius); final int year; final int sales; final double radius; - - LinearSales(this.year, this.sales, this.radius); } diff --git a/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart b/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart index e8ddf7b55..d8e29b33f 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart @@ -19,246 +19,241 @@ /// into a reserved space on the axis range. The label for the bucket line will /// be drawn in the middle of the bucket range, rather than aligned with the /// gridline for that value's position on the scale. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class BucketingAxisScatterPlotChart extends StatelessWidget { - final List> seriesList; - final bool animate; - BucketingAxisScatterPlotChart(this.seriesList, {this.animate = false}); + const BucketingAxisScatterPlotChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory BucketingAxisScatterPlotChart.withSampleData() { - return new BucketingAxisScatterPlotChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory BucketingAxisScatterPlotChart.withSampleData() => BucketingAxisScatterPlotChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory BucketingAxisScatterPlotChart.withRandomData() { - return new BucketingAxisScatterPlotChart(_createRandomData()); - } + factory BucketingAxisScatterPlotChart.withRandomData() => BucketingAxisScatterPlotChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final makeRadius = (int value) => (random.nextInt(value) + 6).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 6).toDouble(); // Make sure that the measure values for the first five series are well // above the threshold. This simulates the grouping of the small values into // the "Other" series. final myFakeDesktopData = [ - new LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), ]; final myFakeTabletData = [ - new LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), ]; final myFakeMobileData = [ - new LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), ]; final myFakeChromebookData = [ - new LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), ]; final myFakeHomeData = [ - new LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), ]; // Make sure that the "Other" series values are smaller. final myFakeOtherData = [ - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), - new LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6)), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + LinearSales( + random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeDesktopData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeDesktopData,), + charts.Series( id: 'Tablet', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeTabletData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeTabletData,), + charts.Series( id: 'Mobile', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeMobileData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeMobileData,), + charts.Series( id: 'Chromebook', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeChromebookData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeChromebookData,), + charts.Series( id: 'Home', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.indigo.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeHomeData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeHomeData,), + charts.Series( id: 'Other', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.gray.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeOtherData), + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeOtherData,), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, // Set up a bucketing axis that will place all values below 0.1 (10%) // into a bucket at the bottom of the chart. // // Configure a tick count of 3 so that we get 100%, 50%, and the // threshold. - primaryMeasureAxis: new charts.BucketingAxisSpec( + primaryMeasureAxis: charts.BucketingAxisSpec( threshold: 0.1, - tickProviderSpec: new charts.BucketingNumericTickProviderSpec( - desiredTickCount: 3)), + tickProviderSpec: const charts.BucketingNumericTickProviderSpec( + desiredTickCount: 3,),), // Add a series legend to display the series names. behaviors: [ - new charts.SeriesLegend(position: charts.BehaviorPosition.end), + charts.SeriesLegend(position: charts.BehaviorPosition.end), ], - animate: animate); - } + animate: animate,); /// Create one series with sample hard coded data. static List> _createSampleData() { final myFakeDesktopData = [ - new LinearSales(52, 0.75, 14.0), + LinearSales(52, 0.75, 14), ]; final myFakeTabletData = [ - new LinearSales(45, 0.3, 18.0), + LinearSales(45, 0.3, 18), ]; final myFakeMobileData = [ - new LinearSales(56, 0.8, 17.0), + LinearSales(56, 0.8, 17), ]; final myFakeChromebookData = [ - new LinearSales(25, 0.6, 13.0), + LinearSales(25, 0.6, 13), ]; final myFakeHomeData = [ - new LinearSales(34, 0.5, 15.0), + LinearSales(34, 0.5, 15), ]; final myFakeOtherData = [ - new LinearSales(10, 0.25, 15.0), - new LinearSales(12, 0.075, 14.0), - new LinearSales(13, 0.225, 15.0), - new LinearSales(16, 0.03, 14.0), - new LinearSales(24, 0.04, 13.0), - new LinearSales(37, 0.1, 14.5), + LinearSales(10, 0.25, 15), + LinearSales(12, 0.075, 14), + LinearSales(13, 0.225, 15), + LinearSales(16, 0.03, 14), + LinearSales(24, 0.04, 13), + LinearSales(37, 0.1, 14.5), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeDesktopData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeDesktopData,), + charts.Series( id: 'Tablet', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.red.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeTabletData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeTabletData,), + charts.Series( id: 'Mobile', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.green.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeMobileData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeMobileData,), + charts.Series( id: 'Chromebook', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeChromebookData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeChromebookData,), + charts.Series( id: 'Home', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.indigo.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeHomeData), - new charts.Series( + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeHomeData,), + charts.Series( id: 'Other', - colorFn: (LinearSales sales, _) => + colorFn: (sales, _) => charts.MaterialPalette.gray.shadeDefault, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.revenueShare, - radiusPxFn: (LinearSales sales, _) => sales.radius, - data: myFakeOtherData), + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeOtherData,), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.revenueShare, this.radius); final int year; final double revenueShare; final double radius; - - LinearSales(this.year, this.revenueShare, this.radius); } diff --git a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart index 4349b7d6b..2edcdbd6b 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart @@ -14,40 +14,37 @@ // limitations under the License. /// Line chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class ComparisonPointsScatterPlotChart extends StatelessWidget { - final List> seriesList; - final bool animate; - ComparisonPointsScatterPlotChart(this.seriesList, {this.animate = false}); + const ComparisonPointsScatterPlotChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory ComparisonPointsScatterPlotChart.withSampleData() { - return new ComparisonPointsScatterPlotChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory ComparisonPointsScatterPlotChart.withSampleData() => ComparisonPointsScatterPlotChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ComparisonPointsScatterPlotChart.withRandomData() { - return new ComparisonPointsScatterPlotChart(_createRandomData()); - } + factory ComparisonPointsScatterPlotChart.withRandomData() => ComparisonPointsScatterPlotChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final maxMeasure = 100; + const maxMeasure = 100; final data = [ _makeRandomDatum(maxMeasure, random), @@ -59,9 +56,9 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -73,20 +70,20 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - domainLowerBoundFn: (LinearSales sales, _) => sales.yearLower, - domainUpperBoundFn: (LinearSales sales, _) => sales.yearUpper, - measureFn: (LinearSales sales, _) => sales.sales, - measureLowerBoundFn: (LinearSales sales, _) => sales.salesLower, - measureUpperBoundFn: (LinearSales sales, _) => sales.salesUpper, - radiusPxFn: (LinearSales sales, _) => sales.radius, + domainFn: (sales, _) => sales.year, + domainLowerBoundFn: (sales, _) => sales.yearLower, + domainUpperBoundFn: (sales, _) => sales.yearUpper, + measureFn: (sales, _) => sales.sales, + measureLowerBoundFn: (sales, _) => sales.salesLower, + measureUpperBoundFn: (sales, _) => sales.salesUpper, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } static LinearSales _makeRandomDatum(int max, Random random) { - final makeRadius = (int value) => (random.nextInt(value) + 6).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 6).toDouble(); final year = random.nextInt(max); final yearLower = (year * 0.8).round(); @@ -95,40 +92,38 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { final salesLower = (sales * 0.8).round(); final salesUpper = sales; - return new LinearSales(year, yearLower, yearUpper, sales, salesLower, - salesUpper, makeRadius(4)); + return LinearSales(year, yearLower, yearUpper, sales, salesLower, + salesUpper, makeRadius(4),); } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate, defaultRenderer: - new charts.PointRendererConfig(pointRendererDecorators: [ - new charts.ComparisonPointsDecorator( - symbolRenderer: new charts.CylinderSymbolRenderer()) - ])); - } + charts.PointRendererConfig(pointRendererDecorators: [ + charts.ComparisonPointsDecorator( + symbolRenderer: charts.CylinderSymbolRenderer(),), + ],),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(10, 7, 10, 25, 20, 25, 5.0), - new LinearSales(13, 11, 13, 225, 205, 225, 5.0), - new LinearSales(34, 34, 24, 150, 150, 130, 5.0), - new LinearSales(37, 37, 57, 10, 10, 12, 6.5), - new LinearSales(45, 35, 45, 260, 300, 260, 8.0), - new LinearSales(56, 46, 56, 200, 170, 200, 7.0), + LinearSales(10, 7, 10, 25, 20, 25, 5), + LinearSales(13, 11, 13, 225, 205, 225, 5), + LinearSales(34, 34, 24, 150, 150, 130, 5), + LinearSales(37, 37, 57, 10, 10, 12, 6.5), + LinearSales(45, 35, 45, 260, 300, 260, 8), + LinearSales(56, 46, 56, 200, 170, 200, 7), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -140,22 +135,25 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - domainLowerBoundFn: (LinearSales sales, _) => sales.yearLower, - domainUpperBoundFn: (LinearSales sales, _) => sales.yearUpper, - measureFn: (LinearSales sales, _) => sales.sales, - measureLowerBoundFn: (LinearSales sales, _) => sales.salesLower, - measureUpperBoundFn: (LinearSales sales, _) => sales.salesUpper, + domainFn: (sales, _) => sales.year, + domainLowerBoundFn: (sales, _) => sales.yearLower, + domainUpperBoundFn: (sales, _) => sales.yearUpper, + measureFn: (sales, _) => sales.sales, + measureLowerBoundFn: (sales, _) => sales.salesLower, + measureUpperBoundFn: (sales, _) => sales.salesUpper, // Providing a radius function is optional. - radiusPxFn: (LinearSales sales, _) => sales.radius, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.yearLower, this.yearUpper, this.sales, + this.salesLower, this.salesUpper, this.radius,); final int year; final int yearLower; final int yearUpper; @@ -163,7 +161,4 @@ class LinearSales { final int salesLower; final int salesUpper; final double radius; - - LinearSales(this.year, this.yearLower, this.yearUpper, this.sales, - this.salesLower, this.salesUpper, this.radius); } diff --git a/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart b/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart index 4fd35ce02..f21e7866f 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart @@ -13,21 +13,19 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/scatter_plot_chart/animation_zoom.dart'; +import 'package:example/scatter_plot_chart/bucketing_axis.dart'; +import 'package:example/scatter_plot_chart/comparison_points.dart'; +import 'package:example/scatter_plot_chart/simple.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'animation_zoom.dart'; -import 'bucketing_axis.dart'; -import 'comparison_points.dart'; -import 'shapes.dart'; -import 'simple.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.scatter_plot), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), title: 'Simple Scatter Plot Chart', subtitle: 'With a single series', - childBuilder: () => new SimpleScatterPlotChart.withRandomData(), + childBuilder: SimpleScatterPlotChart.withRandomData, ), //TODO: // new GalleryScaffold( @@ -36,24 +34,22 @@ List buildGallery() { // subtitle: 'With custom shapes', // childBuilder: () => new ShapesScatterPlotChart.withRandomData(), // ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.scatter_plot), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), title: 'Comparison Points Scatter Plot Chart', subtitle: 'Scatter plot chart with comparison points', - childBuilder: () => new ComparisonPointsScatterPlotChart.withRandomData(), + childBuilder: ComparisonPointsScatterPlotChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.scatter_plot), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), title: 'Pan and Zoom Scatter Plot Chart', subtitle: 'Simple scatter plot chart pan and zoom behaviors enabled', - childBuilder: () => new ScatterPlotAnimationZoomChart.withRandomData(), + childBuilder: ScatterPlotAnimationZoomChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.scatter_plot), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), title: 'Bucketing Axis Scatter Plot Chart', - subtitle: 'Scatter plot with a measure axis that buckets values less ' + - 'than 10% into a single region below the draw area', - childBuilder: () => new BucketingAxisScatterPlotChart.withRandomData(), + subtitle: 'Scatter plot with a measure axis that buckets values less ' 'than 10% into a single region below the draw area', + childBuilder: BucketingAxisScatterPlotChart.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart index 05358ccce..503aa83ab 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart @@ -25,77 +25,75 @@ /// defined. Configuring a separate fillColor will cause the center of the shape /// to be filled in, with white in these examples. The border of the shape will /// be color with the color of the data. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; +import 'package:nimble_charts/flutter.dart'; class ShapesScatterPlotChart extends StatelessWidget { - final List> seriesList; - final bool animate; - ShapesScatterPlotChart(this.seriesList, {this.animate = false}); + const ShapesScatterPlotChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory ShapesScatterPlotChart.withSampleData() { - return new ShapesScatterPlotChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory ShapesScatterPlotChart.withSampleData() => ShapesScatterPlotChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ShapesScatterPlotChart.withRandomData() { - return new ShapesScatterPlotChart(_createRandomData()); - } + factory ShapesScatterPlotChart.withRandomData() => ShapesScatterPlotChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final data = [ - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + 'circle', null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow circle, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + 'circle', null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow circle, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), + null, null, null,), // Render a hollow square, filled in with white. - new LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, null, charts.MaterialPalette.white, 2.0), + LinearSales(random.nextInt(100), random.nextInt(100), + makeRadius(4) + 4, null, charts.MaterialPalette.white, 2,), ]; - final maxMeasure = 100; + const maxMeasure = 100; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -107,64 +105,62 @@ class ShapesScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, - fillColorFn: (LinearSales row, _) => row.fillColor, - strokeWidthPxFn: (LinearSales row, _) => row.strokeWidth, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, + fillColorFn: (row, _) => row.fillColor, + strokeWidthPxFn: (row, _) => row.strokeWidth, data: data, ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (int index) => data[index].shape) + charts.pointSymbolRendererFnKey, (index) => data[index].shape,) // Default symbol renderer ID for data that have no defined shape. - ..setAttribute(charts.pointSymbolRendererIdKey, 'rect') + ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate, // Configure the point renderer to have a map of custom symbol // renderers. defaultRenderer: - new charts.PointRendererConfig(customSymbolRenderers: { - 'circle': new charts.CircleSymbolRenderer(), - 'rect': new charts.RectSymbolRenderer(), - })); - } + charts.PointRendererConfig(customSymbolRenderers: { + 'circle': charts.CircleSymbolRenderer(), + 'rect': charts.RectSymbolRenderer(), + },),); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5, 3.0, 'circle', null, null), - new LinearSales(10, 25, 5.0, null, null, null), - new LinearSales(12, 75, 4.0, null, null, null), + LinearSales(0, 5, 3, 'circle', null, null), + LinearSales(10, 25, 5, null, null, null), + LinearSales(12, 75, 4, null, null, null), // Render a hollow circle, filled in with white. - new LinearSales( - 13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(16, 50, 4.0, null, null, null), - new LinearSales(24, 75, 3.0, null, null, null), - new LinearSales(25, 100, 3.0, 'circle', null, null), - new LinearSales(34, 150, 5.0, null, null, null), - new LinearSales(37, 10, 4.5, null, null, null), + LinearSales( + 13, 225, 5, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(16, 50, 4, null, null, null), + LinearSales(24, 75, 3, null, null, null), + LinearSales(25, 100, 3, 'circle', null, null), + LinearSales(34, 150, 5, null, null, null), + LinearSales(37, 10, 4.5, null, null, null), // Render a hollow circle, filled in with white. - new LinearSales( - 45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0), - new LinearSales(52, 15, 4.0, null, null, null), + LinearSales( + 45, 300, 8, 'circle', charts.MaterialPalette.white, 2,), + LinearSales(52, 15, 4, null, null, null), // Render a hollow square, filled in with white. - new LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0), + LinearSales(56, 200, 7, null, charts.MaterialPalette.white, 2), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -176,31 +172,31 @@ class ShapesScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, - fillColorFn: (LinearSales row, _) => row.fillColor, - strokeWidthPxFn: (LinearSales row, _) => row.strokeWidth, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, + fillColorFn: (row, _) => row.fillColor, + strokeWidthPxFn: (row, _) => row.strokeWidth, data: data, ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (int index) => data[index].shape) + charts.pointSymbolRendererFnKey, (index) => data[index].shape,) // Default symbol renderer ID for data that have no defined shape. - ..setAttribute(charts.pointSymbolRendererIdKey, 'rect') + ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, + this.strokeWidth,); final int year; final int sales; final double radius; final String? shape; final charts.Color? fillColor; final double? strokeWidth; - - LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, - this.strokeWidth); } diff --git a/charts_flutter/example/lib/scatter_plot_chart/simple.dart b/charts_flutter/example/lib/scatter_plot_chart/simple.dart index 5c9168b2d..41aa8695c 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/simple.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/simple.dart @@ -14,62 +14,59 @@ // limitations under the License. /// Scatter plot chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimpleScatterPlotChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleScatterPlotChart(this.seriesList, {this.animate = false}); + const SimpleScatterPlotChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [ScatterPlotChart] with sample data and no transition. - factory SimpleScatterPlotChart.withSampleData() { - return new SimpleScatterPlotChart( + /// Creates a [charts.ScatterPlotChart] with sample data and no transition. + factory SimpleScatterPlotChart.withSampleData() => SimpleScatterPlotChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleScatterPlotChart.withRandomData() { - return new SimpleScatterPlotChart(_createRandomData()); - } + factory SimpleScatterPlotChart.withRandomData() => SimpleScatterPlotChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); - final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble(); + double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final data = [ - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), - new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), + LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6)), ]; - final maxMeasure = 100; + const maxMeasure = 100; return [ - new charts.Series( + charts.Series( id: 'Sales', - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Color bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -81,44 +78,42 @@ class SimpleScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, - radiusPxFn: (LinearSales sales, _) => sales.radius, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.ScatterPlotChart(seriesList, animate: animate); - } + Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new LinearSales(0, 5, 3.0), - new LinearSales(10, 25, 5.0), - new LinearSales(12, 75, 4.0), - new LinearSales(13, 225, 5.0), - new LinearSales(16, 50, 4.0), - new LinearSales(24, 75, 3.0), - new LinearSales(25, 100, 3.0), - new LinearSales(34, 150, 5.0), - new LinearSales(37, 10, 4.5), - new LinearSales(45, 300, 8.0), - new LinearSales(52, 15, 4.0), - new LinearSales(56, 200, 7.0), + LinearSales(0, 5, 3), + LinearSales(10, 25, 5), + LinearSales(12, 75, 4), + LinearSales(13, 225, 5), + LinearSales(16, 50, 4), + LinearSales(24, 75, 3), + LinearSales(25, 100, 3), + LinearSales(34, 150, 5), + LinearSales(37, 10, 4.5), + LinearSales(45, 300, 8), + LinearSales(52, 15, 4), + LinearSales(56, 200, 7), ]; - final maxMeasure = 300; + const maxMeasure = 300; return [ - new charts.Series( + charts.Series( id: 'Sales', // Providing a color function is optional. - colorFn: (LinearSales sales, _) { + colorFn: (sales, _) { // Bucket the measure column value into 3 distinct colors. final bucket = sales.sales / maxMeasure; @@ -130,21 +125,21 @@ class SimpleScatterPlotChart extends StatelessWidget { return charts.MaterialPalette.green.shadeDefault; } }, - domainFn: (LinearSales sales, _) => sales.year, - measureFn: (LinearSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, // Providing a radius function is optional. - radiusPxFn: (LinearSales sales, _) => sales.radius, + radiusPxFn: (sales, _) => sales.radius, data: data, - ) + ), ]; } } /// Sample linear data type. class LinearSales { + + LinearSales(this.year, this.sales, this.radius); final int year; final int sales; final double radius; - - LinearSales(this.year, this.sales, this.radius); } diff --git a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart index 6c1fc1f12..02999df32 100644 --- a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart +++ b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart @@ -17,65 +17,61 @@ /// /// Confidence interval is defined by specifying the upper and lower measure /// bounds in the series. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesConfidenceInterval extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesConfidenceInterval(this.seriesList, {this.animate = false}); + const TimeSeriesConfidenceInterval(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesConfidenceInterval.withSampleData() { - return new TimeSeriesConfidenceInterval( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesConfidenceInterval.withSampleData() => TimeSeriesConfidenceInterval( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesConfidenceInterval.withRandomData() { - return new TimeSeriesConfidenceInterval(_createRandomData()); - } + factory TimeSeriesConfidenceInterval.withRandomData() => TimeSeriesConfidenceInterval(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, // When the measureLowerBoundFn and measureUpperBoundFn is defined, // the line renderer will render the area around the bounds. - measureLowerBoundFn: (TimeSeriesSales sales, _) => sales.sales - 5, - measureUpperBoundFn: (TimeSeriesSales sales, _) => sales.sales + 5, + measureLowerBoundFn: (sales, _) => sales.sales - 5, + measureUpperBoundFn: (sales, _) => sales.sales + 5, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory @@ -83,37 +79,36 @@ class TimeSeriesConfidenceInterval extends StatelessWidget { // specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, // When the measureLowerBoundFn and measureUpperBoundFn is defined, // the line renderer will render the area around the bounds. - measureLowerBoundFn: (TimeSeriesSales sales, _) => sales.sales - 5, - measureUpperBoundFn: (TimeSeriesSales sales, _) => sales.sales + 5, + measureLowerBoundFn: (sales, _) => sales.sales - 5, + measureUpperBoundFn: (sales, _) => sales.sales + 5, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart index aefaf5384..caac946e2 100644 --- a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart +++ b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart @@ -16,96 +16,91 @@ /// Example of a time series chart with an end points domain axis. /// /// An end points axis generates two ticks, one at each end of the axis range. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class EndPointsAxisTimeSeriesChart extends StatelessWidget { - final List> seriesList; - final bool animate; - EndPointsAxisTimeSeriesChart(this.seriesList, {this.animate = false}); + const EndPointsAxisTimeSeriesChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory EndPointsAxisTimeSeriesChart.withSampleData() { - return new EndPointsAxisTimeSeriesChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory EndPointsAxisTimeSeriesChart.withSampleData() => EndPointsAxisTimeSeriesChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory EndPointsAxisTimeSeriesChart.withRandomData() { - return new EndPointsAxisTimeSeriesChart(_createRandomData()); - } + factory EndPointsAxisTimeSeriesChart.withRandomData() => EndPointsAxisTimeSeriesChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Configures an axis spec that is configured to render one tick at each // end of the axis range, anchored "inside" the axis. The start tick label // will be left-aligned with its tick mark, and the end tick label will be // right-aligned with its tick mark. - domainAxis: new charts.EndPointsTimeAxisSpec(), + domainAxis: const charts.EndPointsTimeAxisSpec(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/line_annotation.dart b/charts_flutter/example/lib/time_series_chart/line_annotation.dart index bac36aad2..ad59db4a8 100644 --- a/charts_flutter/example/lib/time_series_chart/line_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/line_annotation.dart @@ -21,95 +21,90 @@ /// /// Additional annotations may be added simply by adding additional /// [Charts.RangeAnnotationSegment] items to the list. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesLineAnnotationChart extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesLineAnnotationChart(this.seriesList, {this.animate = false}); + const TimeSeriesLineAnnotationChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesLineAnnotationChart.withSampleData() { - return new TimeSeriesLineAnnotationChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesLineAnnotationChart.withSampleData() => TimeSeriesLineAnnotationChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesLineAnnotationChart.withRandomData() { - return new TimeSeriesLineAnnotationChart(_createRandomData()); - } + factory TimeSeriesLineAnnotationChart.withRandomData() => TimeSeriesLineAnnotationChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ - new charts.RangeAnnotation([ - new charts.LineAnnotationSegment( - new DateTime(2017, 10, 4), charts.RangeAnnotationAxisType.domain, - startLabel: 'Oct 4'), - new charts.LineAnnotationSegment( - new DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain, - endLabel: 'Oct 15'), + Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ + charts.RangeAnnotation([ + charts.LineAnnotationSegment( + DateTime(2017, 10, 4), charts.RangeAnnotationAxisType.domain, + startLabel: 'Oct 4',), + charts.LineAnnotationSegment( + DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain, + endLabel: 'Oct 15',), ]), - ]); - } + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/range_annotation.dart b/charts_flutter/example/lib/time_series_chart/range_annotation.dart index 098e94efc..493cbd23d 100644 --- a/charts_flutter/example/lib/time_series_chart/range_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/range_annotation.dart @@ -21,91 +21,86 @@ /// /// Additional annotations may be added simply by adding additional /// [Charts.RangeAnnotationSegment] items to the list. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesRangeAnnotationChart extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesRangeAnnotationChart(this.seriesList, {this.animate = false}); + const TimeSeriesRangeAnnotationChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesRangeAnnotationChart.withSampleData() { - return new TimeSeriesRangeAnnotationChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesRangeAnnotationChart.withSampleData() => TimeSeriesRangeAnnotationChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesRangeAnnotationChart.withRandomData() { - return new TimeSeriesRangeAnnotationChart(_createRandomData()); - } + factory TimeSeriesRangeAnnotationChart.withRandomData() => TimeSeriesRangeAnnotationChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ - new charts.RangeAnnotation([ - new charts.RangeAnnotationSegment(new DateTime(2017, 10, 4), - new DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain), + Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ + charts.RangeAnnotation([ + charts.RangeAnnotationSegment(DateTime(2017, 10, 4), + DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain,), ]), - ]); - } + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart b/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart index bd5f4b2f4..d24c22ba1 100644 --- a/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart +++ b/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart @@ -15,125 +15,120 @@ /// Example of a time series chart with range annotations configured to render /// labels in the chart margin area. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesRangeAnnotationMarginChart extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesRangeAnnotationMarginChart(this.seriesList, {this.animate = false}); + const TimeSeriesRangeAnnotationMarginChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesRangeAnnotationMarginChart.withSampleData() { - return new TimeSeriesRangeAnnotationMarginChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesRangeAnnotationMarginChart.withSampleData() => TimeSeriesRangeAnnotationMarginChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesRangeAnnotationMarginChart.withRandomData() { - return new TimeSeriesRangeAnnotationMarginChart(_createRandomData()); - } + factory TimeSeriesRangeAnnotationMarginChart.withRandomData() => TimeSeriesRangeAnnotationMarginChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), // Fix one of the points to 100 so that the annotations are consistently // placed. - new TimeSeriesSales(new DateTime(2017, 10, 10), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 100), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, // Allow enough space in the left and right chart margins for the // annotations. - layoutConfig: new charts.LayoutConfig( - leftMarginSpec: new charts.MarginSpec.fixedPixel(60), - topMarginSpec: new charts.MarginSpec.fixedPixel(20), - rightMarginSpec: new charts.MarginSpec.fixedPixel(60), - bottomMarginSpec: new charts.MarginSpec.fixedPixel(20)), + layoutConfig: charts.LayoutConfig( + leftMarginSpec: charts.MarginSpec.fixedPixel(60), + topMarginSpec: charts.MarginSpec.fixedPixel(20), + rightMarginSpec: charts.MarginSpec.fixedPixel(60), + bottomMarginSpec: charts.MarginSpec.fixedPixel(20),), behaviors: [ // Define one domain and two measure annotations configured to render // labels in the chart margins. - new charts.RangeAnnotation([ - new charts.RangeAnnotationSegment( - new DateTime(2017, 10, 4), - new DateTime(2017, 10, 15), + charts.RangeAnnotation([ + charts.RangeAnnotationSegment( + DateTime(2017, 10, 4), + DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain, startLabel: 'D1 Start', endLabel: 'D1 End', labelAnchor: charts.AnnotationLabelAnchor.end, color: charts.MaterialPalette.gray.shade200, // Override the default vertical direction for domain labels. - labelDirection: charts.AnnotationLabelDirection.horizontal), - new charts.RangeAnnotationSegment( + labelDirection: charts.AnnotationLabelDirection.horizontal,), + charts.RangeAnnotationSegment( 15, 20, charts.RangeAnnotationAxisType.measure, startLabel: 'M1 Start', endLabel: 'M1 End', labelAnchor: charts.AnnotationLabelAnchor.end, - color: charts.MaterialPalette.gray.shade300), - new charts.RangeAnnotationSegment( + color: charts.MaterialPalette.gray.shade300,), + charts.RangeAnnotationSegment( 35, 65, charts.RangeAnnotationAxisType.measure, startLabel: 'M2 Start', endLabel: 'M2 End', labelAnchor: charts.AnnotationLabelAnchor.start, - color: charts.MaterialPalette.gray.shade300), - ], defaultLabelPosition: charts.AnnotationLabelPosition.margin), - ]); - } + color: charts.MaterialPalette.gray.shade300,), + ], defaultLabelPosition: charts.AnnotationLabelPosition.margin,), + ],); /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/simple.dart b/charts_flutter/example/lib/time_series_chart/simple.dart index 5b33f3d44..c1894db41 100644 --- a/charts_flutter/example/lib/time_series_chart/simple.dart +++ b/charts_flutter/example/lib/time_series_chart/simple.dart @@ -14,61 +14,57 @@ // limitations under the License. /// Timeseries chart example +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class SimpleTimeSeriesChart extends StatelessWidget { - final List> seriesList; - final bool animate; - SimpleTimeSeriesChart(this.seriesList, {this.animate = false}); + const SimpleTimeSeriesChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory SimpleTimeSeriesChart.withSampleData() { - return new SimpleTimeSeriesChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory SimpleTimeSeriesChart.withSampleData() => SimpleTimeSeriesChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleTimeSeriesChart.withRandomData() { - return new SimpleTimeSeriesChart(_createRandomData()); - } + factory SimpleTimeSeriesChart.withRandomData() => SimpleTimeSeriesChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory @@ -76,33 +72,32 @@ class SimpleTimeSeriesChart extends StatelessWidget { // specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 19), 5), - new TimeSeriesSales(new DateTime(2017, 9, 26), 25), - new TimeSeriesSales(new DateTime(2017, 10, 3), 100), - new TimeSeriesSales(new DateTime(2017, 10, 10), 75), + TimeSeriesSales(DateTime(2017, 9, 19), 5), + TimeSeriesSales(DateTime(2017, 9, 26), 25), + TimeSeriesSales(DateTime(2017, 10, 3), 100), + TimeSeriesSales(DateTime(2017, 10, 10), 75), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart index 13f1cdd16..82d655aa5 100644 --- a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart @@ -25,59 +25,56 @@ /// shape between the domainLowerBound and domainUpperBound positions along the /// chart's domain axis. Point annotations are drawn on top of range /// annotations. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesSymbolAnnotationChart extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesSymbolAnnotationChart(this.seriesList, {this.animate = false}); + const TimeSeriesSymbolAnnotationChart(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesSymbolAnnotationChart.withSampleData() { - return new TimeSeriesSymbolAnnotationChart( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesSymbolAnnotationChart.withSampleData() => TimeSeriesSymbolAnnotationChart( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesSymbolAnnotationChart.withRandomData() { - return new TimeSeriesSymbolAnnotationChart(_createRandomData()); - } + factory TimeSeriesSymbolAnnotationChart.withRandomData() => TimeSeriesSymbolAnnotationChart(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final myDesktopData = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 19), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 26), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 10, 3), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 10, 10), sales: random.nextInt(100)), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 19), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 26), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 10, 3), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 10, 10), sales: random.nextInt(100),), ]; final myTabletData = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 19), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 26), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 10, 3), sales: random.nextInt(100)), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 10, 10), sales: random.nextInt(100)), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 19), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 26), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 10, 3), sales: random.nextInt(100),), + TimeSeriesSales( + timeCurrent: DateTime(2017, 10, 10), sales: random.nextInt(100),), ]; // Example of a series with two range annotations. A regular point shape @@ -87,15 +84,15 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // Note that these series do not contain any measure values. They are // positioned automatically in rows. final myAnnotationDataTop = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 24), - timePrevious: new DateTime(2017, 9, 19), - timeTarget: new DateTime(2017, 9, 24), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 24), + timePrevious: DateTime(2017, 9, 19), + timeTarget: DateTime(2017, 9, 24), ), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 29), - timePrevious: new DateTime(2017, 9, 29), - timeTarget: new DateTime(2017, 10, 4), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 29), + timePrevious: DateTime(2017, 9, 29), + timeTarget: DateTime(2017, 10, 4), ), ]; @@ -103,36 +100,36 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // annotations. Omitting the previous and target domain values causes that // datum to be drawn as a single point. final myAnnotationDataBottom = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 25), - timePrevious: new DateTime(2017, 9, 21), - timeTarget: new DateTime(2017, 9, 25), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 25), + timePrevious: DateTime(2017, 9, 21), + timeTarget: DateTime(2017, 9, 25), ), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 31)), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 5)), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 31)), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 5)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.timeCurrent, + measureFn: (sales, _) => sales.sales, data: myDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.timeCurrent, + measureFn: (sales, _) => sales.sales, data: myTabletData, ), - new charts.Series( + charts.Series( id: 'Annotation Series 1', colorFn: (_, __) => charts.MaterialPalette.gray.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - domainLowerBoundFn: (TimeSeriesSales row, _) => row.timePrevious, - domainUpperBoundFn: (TimeSeriesSales row, _) => row.timeTarget, + domainFn: (sales, _) => sales.timeCurrent, + domainLowerBoundFn: (row, _) => row.timePrevious, + domainUpperBoundFn: (row, _) => row.timeTarget, // No measure values are needed for symbol annotations. measureFn: (_, __) => null, data: myAnnotationDataTop, @@ -142,12 +139,12 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // Optional radius for the annotation shape. If not specified, this will // default to the same radius as the points. ..setAttribute(charts.boundsLineRadiusPxKey, 3.5), - new charts.Series( + charts.Series( id: 'Annotation Series 2', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - domainLowerBoundFn: (TimeSeriesSales row, _) => row.timePrevious, - domainUpperBoundFn: (TimeSeriesSales row, _) => row.timeTarget, + domainFn: (sales, _) => sales.timeCurrent, + domainLowerBoundFn: (row, _) => row.timePrevious, + domainUpperBoundFn: (row, _) => row.timeTarget, // No measure values are needed for symbol annotations. measureFn: (_, __) => null, data: myAnnotationDataBottom, @@ -162,37 +159,35 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Custom renderer configuration for the point series. customSeriesRenderers: [ - new charts.SymbolAnnotationRendererConfig( + charts.SymbolAnnotationRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customSymbolAnnotation') + customRendererId: 'customSymbolAnnotation',), ], // Optionally pass in a [DateTimeFactory] used by the chart. The factory // should create the same type of [DateTime] as the data provided. If none // specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final myDesktopData = [ - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 19), sales: 5), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 26), sales: 25), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 3), sales: 100), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 10), sales: 75), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 19), sales: 5), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 26), sales: 25), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 3), sales: 100), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 10), sales: 75), ]; final myTabletData = [ - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 19), sales: 10), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 26), sales: 50), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 3), sales: 200), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 10), sales: 150), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 19), sales: 10), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 26), sales: 50), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 3), sales: 200), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 10), sales: 150), ]; // Example of a series with two range annotations. A regular point shape @@ -202,15 +197,15 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // Note that these series do not contain any measure values. They are // positioned automatically in rows. final myAnnotationDataTop = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 24), - timePrevious: new DateTime(2017, 9, 19), - timeTarget: new DateTime(2017, 9, 24), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 24), + timePrevious: DateTime(2017, 9, 19), + timeTarget: DateTime(2017, 9, 24), ), - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 29), - timePrevious: new DateTime(2017, 9, 29), - timeTarget: new DateTime(2017, 10, 4), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 29), + timePrevious: DateTime(2017, 9, 29), + timeTarget: DateTime(2017, 10, 4), ), ]; @@ -218,39 +213,39 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // annotations. Omitting the previous and target domain values causes that // datum to be drawn as a single point. final myAnnotationDataBottom = [ - new TimeSeriesSales( - timeCurrent: new DateTime(2017, 9, 25), - timePrevious: new DateTime(2017, 9, 21), - timeTarget: new DateTime(2017, 9, 25), + TimeSeriesSales( + timeCurrent: DateTime(2017, 9, 25), + timePrevious: DateTime(2017, 9, 21), + timeTarget: DateTime(2017, 9, 25), ), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 9, 31)), - new TimeSeriesSales(timeCurrent: new DateTime(2017, 10, 5)), + TimeSeriesSales(timeCurrent: DateTime(2017, 9, 31)), + TimeSeriesSales(timeCurrent: DateTime(2017, 10, 5)), ]; return [ - new charts.Series( + charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.timeCurrent, + measureFn: (sales, _) => sales.sales, data: myDesktopData, ), - new charts.Series( + charts.Series( id: 'Tablet', colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.timeCurrent, + measureFn: (sales, _) => sales.sales, data: myTabletData, ), - new charts.Series( + charts.Series( id: 'Annotation Series 1', colorFn: (_, __) => charts.MaterialPalette.gray.shadeDefault, // A point shape will be drawn at the location of the domain. - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, + domainFn: (sales, _) => sales.timeCurrent, // A range shape will be drawn between the lower and upper domain // bounds. The range will be drawn underneath the domain point. - domainLowerBoundFn: (TimeSeriesSales row, _) => row.timePrevious, - domainUpperBoundFn: (TimeSeriesSales row, _) => row.timeTarget, + domainLowerBoundFn: (row, _) => row.timePrevious, + domainUpperBoundFn: (row, _) => row.timeTarget, // No measure values are needed for symbol annotations. measureFn: (_, __) => null, data: myAnnotationDataTop, @@ -260,15 +255,15 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { // Optional radius for the annotation range. If not specified, this will // default to the same radius as the domain point. ..setAttribute(charts.boundsLineRadiusPxKey, 3.5), - new charts.Series( + charts.Series( id: 'Annotation Series 2', colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, // A point shape will be drawn at the location of the domain. - domainFn: (TimeSeriesSales sales, _) => sales.timeCurrent, + domainFn: (sales, _) => sales.timeCurrent, // A range shape will be drawn between the lower and upper domain // bounds. The range will be drawn underneath the domain point. - domainLowerBoundFn: (TimeSeriesSales row, _) => row.timePrevious, - domainUpperBoundFn: (TimeSeriesSales row, _) => row.timeTarget, + domainLowerBoundFn: (row, _) => row.timePrevious, + domainUpperBoundFn: (row, _) => row.timeTarget, // No measure values are needed for symbol annotations. measureFn: (_, __) => null, data: myAnnotationDataBottom, @@ -284,10 +279,6 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - final DateTime timeCurrent; - final DateTime? timePrevious; - final DateTime? timeTarget; - final int? sales; TimeSeriesSales({ required this.timeCurrent, @@ -295,4 +286,8 @@ class TimeSeriesSales { this.timeTarget, this.sales, }); + final DateTime timeCurrent; + final DateTime? timePrevious; + final DateTime? timeTarget; + final int? sales; } diff --git a/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart b/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart index f60d6dda1..d77b0a687 100644 --- a/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart +++ b/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart @@ -13,68 +13,65 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:example/gallery_scaffold.dart'; +import 'package:example/time_series_chart/confidence_interval.dart'; +import 'package:example/time_series_chart/end_points_axis.dart'; +import 'package:example/time_series_chart/line_annotation.dart'; +import 'package:example/time_series_chart/range_annotation.dart'; +import 'package:example/time_series_chart/range_annotation_margin.dart'; +import 'package:example/time_series_chart/simple.dart'; +import 'package:example/time_series_chart/symbol_annotation.dart'; +import 'package:example/time_series_chart/with_bar_renderer.dart'; import 'package:flutter/material.dart'; -import '../gallery_scaffold.dart'; -import 'confidence_interval.dart'; -import 'end_points_axis.dart'; -import 'line_annotation.dart'; -import 'range_annotation.dart'; -import 'range_annotation_margin.dart'; -import 'simple.dart'; -import 'symbol_annotation.dart'; -import 'with_bar_renderer.dart'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), +List buildGallery() => [ + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Time Series Chart', subtitle: 'Simple single time series chart', - childBuilder: () => new SimpleTimeSeriesChart.withRandomData(), + childBuilder: SimpleTimeSeriesChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'End Points Axis Time Series Chart', subtitle: 'Time series chart with an end points axis', - childBuilder: () => new EndPointsAxisTimeSeriesChart.withRandomData(), + childBuilder: EndPointsAxisTimeSeriesChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Line Annotation on Time Series Chart', subtitle: 'Time series chart with future line annotation', - childBuilder: () => new TimeSeriesLineAnnotationChart.withRandomData(), + childBuilder: TimeSeriesLineAnnotationChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Range Annotation on Time Series Chart', subtitle: 'Time series chart with future range annotation', - childBuilder: () => new TimeSeriesRangeAnnotationChart.withRandomData(), + childBuilder: TimeSeriesRangeAnnotationChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Range Annotation Margin Labels on Time Series Chart', subtitle: 'Time series chart with range annotations with labels in margins', - childBuilder: () => - new TimeSeriesRangeAnnotationMarginChart.withRandomData(), + childBuilder: TimeSeriesRangeAnnotationMarginChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Symbol Annotation Time Series Chart', subtitle: 'Time series chart with annotation data below the draw area', - childBuilder: () => new TimeSeriesSymbolAnnotationChart.withRandomData(), + childBuilder: TimeSeriesSymbolAnnotationChart.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Time Series Chart with Bars', subtitle: 'Time series chart using the bar renderer', - childBuilder: () => new TimeSeriesBar.withRandomData(), + childBuilder: TimeSeriesBar.withRandomData, ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.show_chart), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), title: 'Time Series Chart with Confidence Interval', subtitle: 'Draws area around the confidence interval', - childBuilder: () => new TimeSeriesConfidenceInterval.withRandomData(), + childBuilder: TimeSeriesConfidenceInterval.withRandomData, ), ]; -} diff --git a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart index 4bf35dde0..a542b25e1 100644 --- a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart +++ b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart @@ -14,135 +14,130 @@ // limitations under the License. /// Example of a time series chart using a bar renderer. +library; + // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; + +import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:flutter/material.dart'; class TimeSeriesBar extends StatelessWidget { - final List> seriesList; - final bool animate; - TimeSeriesBar(this.seriesList, {this.animate = false}); + const TimeSeriesBar(this.seriesList, {super.key, this.animate = false}); - /// Creates a [TimeSeriesChart] with sample data and no transition. - factory TimeSeriesBar.withSampleData() { - return new TimeSeriesBar( + /// Creates a [charts.TimeSeriesChart] with sample data and no transition. + factory TimeSeriesBar.withSampleData() => TimeSeriesBar( _createSampleData(), - // Disable animations for image tests. - animate: false, ); - } // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesBar.withRandomData() { - return new TimeSeriesBar(_createRandomData()); - } + factory TimeSeriesBar.withRandomData() => TimeSeriesBar(_createRandomData()); + final List> seriesList; + final bool animate; /// Create random data. static List> _createRandomData() { - final random = new Random(); + final random = Random(); final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 1), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 2), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 3), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 4), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 5), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 6), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 7), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 8), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 9), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 10), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 11), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 12), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 13), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 14), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 15), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 16), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 17), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 18), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 20), random.nextInt(100)), - new TimeSeriesSales(new DateTime(2017, 9, 21), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 2), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 3), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 4), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 5), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 6), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 7), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 8), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 9), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 10), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 11), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 12), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 13), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 14), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 15), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 16), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 17), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 18), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 20), random.nextInt(100)), + TimeSeriesSales(DateTime(2017, 9, 21), random.nextInt(100)), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - return new charts.TimeSeriesChart( + Widget build(BuildContext context) => charts.TimeSeriesChart( seriesList, animate: animate, // Set the default renderer to a bar renderer. // This can also be one of the custom renderers of the time series chart. - defaultRenderer: new charts.BarRendererConfig(), + defaultRenderer: charts.BarRendererConfig(), // It is recommended that default interactions be turned off if using bar // renderer, because the line point highlighter is the default for time // series chart. defaultInteractions: false, // If default interactions were removed, optionally add select nearest // and the domain highlighter that are typical for bar charts. - behaviors: [new charts.SelectNearest(), new charts.DomainHighlighter()], + behaviors: [charts.SelectNearest(), charts.DomainHighlighter()], ); - } /// Create one series with sample hard coded data. static List> _createSampleData() { final data = [ - new TimeSeriesSales(new DateTime(2017, 9, 1), 5), - new TimeSeriesSales(new DateTime(2017, 9, 2), 5), - new TimeSeriesSales(new DateTime(2017, 9, 3), 25), - new TimeSeriesSales(new DateTime(2017, 9, 4), 100), - new TimeSeriesSales(new DateTime(2017, 9, 5), 75), - new TimeSeriesSales(new DateTime(2017, 9, 6), 88), - new TimeSeriesSales(new DateTime(2017, 9, 7), 65), - new TimeSeriesSales(new DateTime(2017, 9, 8), 91), - new TimeSeriesSales(new DateTime(2017, 9, 9), 100), - new TimeSeriesSales(new DateTime(2017, 9, 10), 111), - new TimeSeriesSales(new DateTime(2017, 9, 11), 90), - new TimeSeriesSales(new DateTime(2017, 9, 12), 50), - new TimeSeriesSales(new DateTime(2017, 9, 13), 40), - new TimeSeriesSales(new DateTime(2017, 9, 14), 30), - new TimeSeriesSales(new DateTime(2017, 9, 15), 40), - new TimeSeriesSales(new DateTime(2017, 9, 16), 50), - new TimeSeriesSales(new DateTime(2017, 9, 17), 30), - new TimeSeriesSales(new DateTime(2017, 9, 18), 35), - new TimeSeriesSales(new DateTime(2017, 9, 19), 40), - new TimeSeriesSales(new DateTime(2017, 9, 20), 32), - new TimeSeriesSales(new DateTime(2017, 9, 21), 31), + TimeSeriesSales(DateTime(2017, 9), 5), + TimeSeriesSales(DateTime(2017, 9, 2), 5), + TimeSeriesSales(DateTime(2017, 9, 3), 25), + TimeSeriesSales(DateTime(2017, 9, 4), 100), + TimeSeriesSales(DateTime(2017, 9, 5), 75), + TimeSeriesSales(DateTime(2017, 9, 6), 88), + TimeSeriesSales(DateTime(2017, 9, 7), 65), + TimeSeriesSales(DateTime(2017, 9, 8), 91), + TimeSeriesSales(DateTime(2017, 9, 9), 100), + TimeSeriesSales(DateTime(2017, 9, 10), 111), + TimeSeriesSales(DateTime(2017, 9, 11), 90), + TimeSeriesSales(DateTime(2017, 9, 12), 50), + TimeSeriesSales(DateTime(2017, 9, 13), 40), + TimeSeriesSales(DateTime(2017, 9, 14), 30), + TimeSeriesSales(DateTime(2017, 9, 15), 40), + TimeSeriesSales(DateTime(2017, 9, 16), 50), + TimeSeriesSales(DateTime(2017, 9, 17), 30), + TimeSeriesSales(DateTime(2017, 9, 18), 35), + TimeSeriesSales(DateTime(2017, 9, 19), 40), + TimeSeriesSales(DateTime(2017, 9, 20), 32), + TimeSeriesSales(DateTime(2017, 9, 21), 31), ]; return [ - new charts.Series( + charts.Series( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (TimeSeriesSales sales, _) => sales.time, - measureFn: (TimeSeriesSales sales, _) => sales.sales, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, data: data, - ) + ), ]; } } /// Sample time series data type. class TimeSeriesSales { - final DateTime time; - final int sales; TimeSeriesSales(this.time, this.sales); + final DateTime time; + final int sales; } diff --git a/charts_flutter/example/pubspec.yaml b/charts_flutter/example/pubspec.yaml index c7560cc27..44a76f698 100644 --- a/charts_flutter/example/pubspec.yaml +++ b/charts_flutter/example/pubspec.yaml @@ -19,3 +19,5 @@ dependencies: intl: ^0.19.0 flutter: uses-material-design: true +dev_dependencies: + austerity: ^1.2.0 From e8c9a93301dc9005080ca7679919f0d7767453ff Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Wed, 18 Sep 2024 05:58:08 +1000 Subject: [PATCH 2/9] fixes --- .../axes/horizontal_bar_secondary_axis.dart | 7 +- .../lib/axes/integer_only_measure_axis.dart | 38 +-- .../example/lib/axes/line_disjoint_axis.dart | 63 +++-- .../axes/measure_axis_label_alignment.dart | 59 ++-- .../lib/axes/nonzero_bound_measure_axis.dart | 23 +- .../lib/axes/numeric_initial_viewport.dart | 36 +-- .../lib/axes/ordinal_initial_viewport.dart | 40 +-- .../lib/axes/short_tick_length_axis.dart | 26 +- .../example/lib/bar_chart/bar_gallery.dart | 256 +++++++++--------- .../lib/bar_chart/custom_rounded_bars.dart | 20 +- .../example/lib/bar_chart/grouped.dart | 17 +- .../lib/bar_chart/grouped_fill_color.dart | 29 +- .../bar_chart/grouped_single_target_line.dart | 101 ++++--- .../lib/bar_chart/grouped_stacked.dart | 23 +- .../grouped_stacked_weight_pattern.dart | 42 +-- .../lib/bar_chart/grouped_target_line.dart | 29 +- .../example/lib/bar_chart/horizontal.dart | 24 +- .../lib/bar_chart/horizontal_bar_label.dart | 69 ++--- .../horizontal_bar_label_custom.dart | 41 +-- .../horizontal_pattern_forward_hatch.dart | 35 +-- .../lib/bar_chart/pattern_forward_hatch.dart | 32 ++- .../example/lib/bar_chart/simple.dart | 15 +- .../example/lib/bar_chart/spark_bar.dart | 4 +- .../example/lib/bar_chart/stacked.dart | 17 +- .../lib/bar_chart/stacked_fill_color.dart | 29 +- .../lib/bar_chart/stacked_horizontal.dart | 35 +-- .../lib/bar_chart/stacked_target_line.dart | 31 ++- .../lib/bar_chart/vertical_bar_label.dart | 63 +++-- .../lib/behaviors/behaviors_gallery.dart | 178 ++++++------ .../example/lib/behaviors/chart_title.dart | 53 ++-- .../behaviors/selection_bar_highlight.dart | 41 ++- .../behaviors/selection_callback_example.dart | 4 +- .../lib/behaviors/selection_user_managed.dart | 30 +- .../example/lib/behaviors/slider.dart | 2 +- .../lib/combo_chart/date_time_line_point.dart | 76 +++--- .../lib/combo_chart/numeric_line_bar.dart | 48 ++-- charts_flutter/example/lib/home.dart | 87 +++--- .../example/lib/i18n/rtl_line_segments.dart | 57 ++-- .../example/lib/line_chart/segments.dart | 12 +- .../time_series_chart/end_points_axis.dart | 31 ++- .../time_series_chart/line_annotation.dart | 43 +-- .../time_series_chart/range_annotation.dart | 37 ++- .../range_annotation_margin.dart | 63 +++-- .../example/lib/time_series_chart/simple.dart | 29 +- .../time_series_chart/symbol_annotation.dart | 75 +++-- charts_flutter/example/pubspec.yaml | 2 +- 46 files changed, 1126 insertions(+), 946 deletions(-) diff --git a/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart b/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart index 97cdc9c86..2c605c43c 100644 --- a/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart +++ b/charts_flutter/example/lib/axes/horizontal_bar_secondary_axis.dart @@ -37,8 +37,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: primary and secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class HorizontalBarChartWithSecondaryAxis extends StatelessWidget { - const HorizontalBarChartWithSecondaryAxis(this.seriesList, - {super.key, this.animate = false}); + const HorizontalBarChartWithSecondaryAxis( + this.seriesList, { + super.key, + this.animate = false, + }); factory HorizontalBarChartWithSecondaryAxis.withSampleData() => HorizontalBarChartWithSecondaryAxis( diff --git a/charts_flutter/example/lib/axes/integer_only_measure_axis.dart b/charts_flutter/example/lib/axes/integer_only_measure_axis.dart index da5a62f16..7afc857db 100644 --- a/charts_flutter/example/lib/axes/integer_only_measure_axis.dart +++ b/charts_flutter/example/lib/axes/integer_only_measure_axis.dart @@ -29,19 +29,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class IntegerOnlyMeasureAxis extends StatelessWidget { - - const IntegerOnlyMeasureAxis(this.seriesList, {super.key, this.animate = false}); + const IntegerOnlyMeasureAxis( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory IntegerOnlyMeasureAxis.withSampleData() => IntegerOnlyMeasureAxis( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory IntegerOnlyMeasureAxis.withRandomData() => IntegerOnlyMeasureAxis(_createRandomData()); + factory IntegerOnlyMeasureAxis.withRandomData() => + IntegerOnlyMeasureAxis(_createRandomData()); final List> seriesList; final bool animate; @@ -76,18 +80,20 @@ class IntegerOnlyMeasureAxis extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Provides a custom axis ensuring that the ticks are in whole numbers. - primaryMeasureAxis: const charts.NumericAxisSpec( + seriesList, + animate: animate, + // Provides a custom axis ensuring that the ticks are in whole numbers. + primaryMeasureAxis: const charts.NumericAxisSpec( tickProviderSpec: charts.BasicNumericTickProviderSpec( - // Make sure we don't have values less than 1 as ticks - // (ie: counts). - dataIsInWholeNumbers: true, - // Fixed tick count to highlight the integer only behavior - // generating ticks [0, 1, 2, 3, 4]. - desiredTickCount: 5,),), - ); + // Make sure we don't have values less than 1 as ticks + // (ie: counts). + dataIsInWholeNumbers: true, + // Fixed tick count to highlight the integer only behavior + // generating ticks [0, 1, 2, 3, 4]. + desiredTickCount: 5, + ), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/axes/line_disjoint_axis.dart b/charts_flutter/example/lib/axes/line_disjoint_axis.dart index 1103efae7..9163ae118 100644 --- a/charts_flutter/example/lib/axes/line_disjoint_axis.dart +++ b/charts_flutter/example/lib/axes/line_disjoint_axis.dart @@ -31,19 +31,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DisjointMeasureAxisLineChart extends StatelessWidget { - - const DisjointMeasureAxisLineChart(this.seriesList, {super.key, this.animate = false}); + const DisjointMeasureAxisLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. - factory DisjointMeasureAxisLineChart.withSampleData() => DisjointMeasureAxisLineChart( - _createSampleData(), - ); + factory DisjointMeasureAxisLineChart.withSampleData() => + DisjointMeasureAxisLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DisjointMeasureAxisLineChart.withRandomData() => DisjointMeasureAxisLineChart(_createRandomData()); + factory DisjointMeasureAxisLineChart.withRandomData() => + DisjointMeasureAxisLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -91,10 +96,11 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // the axis itself gets rendered. This helps us draw the gridlines on the // chart. charts.Series( - id: 'Fake Series', - domainFn: (clickCount, _) => clickCount.year, - measureFn: (clickCount, _) => clickCount.clickCount, - data: [],), + id: 'Fake Series', + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, + data: [], + ), charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, @@ -136,7 +142,8 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, animate: animate, // Configure a primary measure axis that will render gridlines across // the chart. This axis uses fake ticks with no labels to ensure that we @@ -145,16 +152,17 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // We do this because disjoint measure axes do not draw any tick // elements on the chart. primaryMeasureAxis: const charts.NumericAxisSpec( - tickProviderSpec: charts.StaticNumericTickProviderSpec( - // Create the ticks to be used the domain axis. - >[ - charts.TickSpec(0, label: ''), - charts.TickSpec(1, label: ''), - charts.TickSpec(2, label: ''), - charts.TickSpec(3, label: ''), - charts.TickSpec(4, label: ''), - ], - ),), + tickProviderSpec: charts.StaticNumericTickProviderSpec( + // Create the ticks to be used the domain axis. + >[ + charts.TickSpec(0, label: ''), + charts.TickSpec(1, label: ''), + charts.TickSpec(2, label: ''), + charts.TickSpec(3, label: ''), + charts.TickSpec(4, label: ''), + ], + ), + ), // Create one disjoint measure axis per series on the chart. // // Disjoint measure axes will be used to scale the rendered data, @@ -165,7 +173,8 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { 'axis 2': const charts.NumericAxisSpec(), 'axis 3': const charts.NumericAxisSpec(), 'axis 4': const charts.NumericAxisSpec(), - }),); + }), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -209,10 +218,11 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { // the axis itself gets rendered. This helps us draw the gridlines on the // chart. charts.Series( - id: 'Fake Series', - domainFn: (clickCount, _) => clickCount.year, - measureFn: (clickCount, _) => clickCount.clickCount, - data: [],), + id: 'Fake Series', + domainFn: (clickCount, _) => clickCount.year, + measureFn: (clickCount, _) => clickCount.clickCount, + data: [], + ), charts.Series( id: 'Desktop', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, @@ -255,7 +265,6 @@ class DisjointMeasureAxisLineChart extends StatelessWidget { /// Sample linear data type. class LinearClicks { - LinearClicks(this.year, {this.clickCount, this.clickRate}); final int year; final int? clickCount; diff --git a/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart b/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart index 45f1e272f..7e87c56c6 100644 --- a/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart +++ b/charts_flutter/example/lib/axes/measure_axis_label_alignment.dart @@ -25,18 +25,23 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of using a custom primary measure replacing the renderSpec with one /// that aligns the text under the tick and left justifies. class MeasureAxisLabelAlignment extends StatelessWidget { + const MeasureAxisLabelAlignment( + this.seriesList, { + super.key, + this.animate = false, + }); - const MeasureAxisLabelAlignment(this.seriesList, {super.key, this.animate = false}); - - factory MeasureAxisLabelAlignment.withSampleData() => MeasureAxisLabelAlignment( - _createSampleData(), - ); + factory MeasureAxisLabelAlignment.withSampleData() => + MeasureAxisLabelAlignment( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory MeasureAxisLabelAlignment.withRandomData() => MeasureAxisLabelAlignment(_createRandomData()); + factory MeasureAxisLabelAlignment.withRandomData() => + MeasureAxisLabelAlignment(_createRandomData()); final List> seriesList; final bool animate; @@ -64,28 +69,29 @@ class MeasureAxisLabelAlignment extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, + seriesList, + animate: animate, - /// Customize the primary measure axis using a small tick renderer. - /// Use String instead of num for ordinal domain axis - /// (typically bar charts). - primaryMeasureAxis: const charts.NumericAxisSpec( + /// Customize the primary measure axis using a small tick renderer. + /// Use String instead of num for ordinal domain axis + /// (typically bar charts). + primaryMeasureAxis: const charts.NumericAxisSpec( renderSpec: charts.GridlineRendererSpec( - // Display the measure axis labels below the gridline. - // - // 'Before' & 'after' follow the axis value direction. - // Vertical axes draw 'before' below & 'after' above the tick. - // Horizontal axes draw 'before' left & 'after' right the tick. - labelAnchor: charts.TickLabelAnchor.before, - - // Left justify the text in the axis. - // - // Note: outside means that the secondary measure axis would right - // justify. - labelJustification: charts.TickLabelJustification.outside, - ),), - ); + // Display the measure axis labels below the gridline. + // + // 'Before' & 'after' follow the axis value direction. + // Vertical axes draw 'before' below & 'after' above the tick. + // Horizontal axes draw 'before' left & 'after' right the tick. + labelAnchor: charts.TickLabelAnchor.before, + + // Left justify the text in the axis. + // + // Note: outside means that the secondary measure axis would right + // justify. + labelJustification: charts.TickLabelJustification.outside, + ), + ), + ); /// Create series list with single series static List> _createSampleData() { @@ -109,7 +115,6 @@ class MeasureAxisLabelAlignment extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart b/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart index 38841dd8e..0d95f529c 100644 --- a/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart +++ b/charts_flutter/example/lib/axes/nonzero_bound_measure_axis.dart @@ -25,19 +25,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class NonzeroBoundMeasureAxis extends StatelessWidget { - - const NonzeroBoundMeasureAxis(this.seriesList, {super.key, this.animate = false}); + const NonzeroBoundMeasureAxis( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory NonzeroBoundMeasureAxis.withSampleData() => NonzeroBoundMeasureAxis( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NonzeroBoundMeasureAxis.withRandomData() => NonzeroBoundMeasureAxis(_createRandomData()); + factory NonzeroBoundMeasureAxis.withRandomData() => + NonzeroBoundMeasureAxis(_createRandomData()); final List> seriesList; final bool animate; @@ -71,13 +75,16 @@ class NonzeroBoundMeasureAxis extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, animate: animate, // Provide a tickProviderSpec which does NOT require that zero is // included. primaryMeasureAxis: const charts.NumericAxisSpec( - tickProviderSpec: - charts.BasicNumericTickProviderSpec(zeroBound: false),),); + tickProviderSpec: + charts.BasicNumericTickProviderSpec(zeroBound: false), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart index 724b5a6be..57bcb19fb 100644 --- a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart +++ b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart @@ -20,10 +20,10 @@ /// /// In this example, the series list has numeric data from 0 to 10, but we /// want to show from 3 to 7. -/// We can do this by specifying an [charts.NumericExtents] in [charts.NumericAxisSpec]. +/// We can do this by specifying an [charts.NumericExtents] in +/// [charts.NumericAxisSpec]. library; - // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; @@ -32,19 +32,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class NumericInitialViewport extends StatelessWidget { - - const NumericInitialViewport(this.seriesList, {super.key, this.animate = false}); + const NumericInitialViewport( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory NumericInitialViewport.withSampleData() => NumericInitialViewport( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericInitialViewport.withRandomData() => NumericInitialViewport(_createRandomData()); + factory NumericInitialViewport.withRandomData() => + NumericInitialViewport(_createRandomData()); final List> seriesList; final bool animate; @@ -80,16 +84,17 @@ class NumericInitialViewport extends StatelessWidget { @override Widget build(BuildContext context) => charts.LineChart( - seriesList, - animate: animate, - domainAxis: const charts.NumericAxisSpec( + seriesList, + animate: animate, + domainAxis: const charts.NumericAxisSpec( // Set the initial viewport by providing a new AxisSpec with the // desired viewport, in NumericExtents. - viewport: charts.NumericExtents(3.0, 7.0),), - // Optionally add a pan or pan and zoom behavior. - // If pan/zoom is not added, the viewport specified remains the viewport. - behaviors: [charts.PanAndZoomBehavior()], - ); + viewport: charts.NumericExtents(3.0, 7.0), + ), + // Optionally add a pan or pan and zoom behavior. + // If pan/zoom is not added, the viewport specified remains the viewport. + behaviors: [charts.PanAndZoomBehavior()], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -121,7 +126,6 @@ class NumericInitialViewport extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart b/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart index 73ded3326..dd20c134e 100644 --- a/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart +++ b/charts_flutter/example/lib/axes/ordinal_initial_viewport.dart @@ -20,10 +20,10 @@ /// /// In this example, the series list has ordinal data from year 2014 to 2030, /// but we want to show starting at 2018 and we only want to show 4 values. -/// We can do this by specifying an [charts.OrdinalViewport] in [charts.OrdinalAxisSpec]. +/// We can do this by specifying an [charts.OrdinalViewport] in +/// [charts.OrdinalAxisSpec]. library; - // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; @@ -32,19 +32,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class OrdinalInitialViewport extends StatelessWidget { - - const OrdinalInitialViewport(this.seriesList, {super.key, this.animate = false}); + const OrdinalInitialViewport( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory OrdinalInitialViewport.withSampleData() => OrdinalInitialViewport( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory OrdinalInitialViewport.withRandomData() => OrdinalInitialViewport(_createRandomData()); + factory OrdinalInitialViewport.withRandomData() => + OrdinalInitialViewport(_createRandomData()); final List> seriesList; final bool animate; @@ -86,16 +90,17 @@ class OrdinalInitialViewport extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Set the initial viewport by providing a new AxisSpec with the - // desired viewport: a starting domain and the data size. - domainAxis: charts.OrdinalAxisSpec( - viewport: charts.OrdinalViewport('2018', 4),), - // Optionally add a pan or pan and zoom behavior. - // If pan/zoom is not added, the viewport specified remains the viewport. - behaviors: [charts.PanAndZoomBehavior()], - ); + seriesList, + animate: animate, + // Set the initial viewport by providing a new AxisSpec with the + // desired viewport: a starting domain and the data size. + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4), + ), + // Optionally add a pan or pan and zoom behavior. + // If pan/zoom is not added, the viewport specified remains the viewport. + behaviors: [charts.PanAndZoomBehavior()], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -133,7 +138,6 @@ class OrdinalInitialViewport extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/axes/short_tick_length_axis.dart b/charts_flutter/example/lib/axes/short_tick_length_axis.dart index bdf50fb09..5c4003b7b 100644 --- a/charts_flutter/example/lib/axes/short_tick_length_axis.dart +++ b/charts_flutter/example/lib/axes/short_tick_length_axis.dart @@ -29,18 +29,18 @@ import 'package:nimble_charts/flutter.dart' as charts; /// There are many axis styling options in the SmallTickRenderer allowing you /// to customize the font, tick lengths, and offsets. class ShortTickLengthAxis extends StatelessWidget { - const ShortTickLengthAxis(this.seriesList, {super.key, this.animate = false}); factory ShortTickLengthAxis.withSampleData() => ShortTickLengthAxis( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ShortTickLengthAxis.withRandomData() => ShortTickLengthAxis(_createRandomData()); + factory ShortTickLengthAxis.withRandomData() => + ShortTickLengthAxis(_createRandomData()); final List> seriesList; final bool animate; @@ -68,17 +68,18 @@ class ShortTickLengthAxis extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, + seriesList, + animate: animate, - /// Customize the primary measure axis using a small tick renderer. - /// Note: use String instead of num for ordinal domain axis - /// (typically bar charts). - primaryMeasureAxis: const charts.NumericAxisSpec( + /// Customize the primary measure axis using a small tick renderer. + /// Note: use String instead of num for ordinal domain axis + /// (typically bar charts). + primaryMeasureAxis: const charts.NumericAxisSpec( renderSpec: charts.SmallTickRendererSpec( // Tick and Label styling here. - ),), - ); + ), + ), + ); /// Create series list with single series static List> _createSampleData() { @@ -102,7 +103,6 @@ class ShortTickLengthAxis extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/bar_gallery.dart b/charts_flutter/example/lib/bar_chart/bar_gallery.dart index cc0eb2a40..6db172122 100644 --- a/charts_flutter/example/lib/bar_chart/bar_gallery.dart +++ b/charts_flutter/example/lib/bar_chart/bar_gallery.dart @@ -36,125 +36,137 @@ import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Simple Bar Chart', - subtitle: 'Simple bar chart with a single series', - childBuilder: SimpleBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Stacked Bar Chart', - subtitle: 'Stacked bar chart with multiple series', - childBuilder: StackedBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Grouped Bar Chart', - subtitle: 'Grouped bar chart with multiple series', - childBuilder: GroupedBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Grouped Stacked Bar Chart', - subtitle: 'Grouped and stacked bar chart with multiple series', - childBuilder: GroupedStackedBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Grouped Bar Target Line Chart', - subtitle: 'Grouped bar target line chart with multiple series', - childBuilder: GroupedBarTargetLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Grouped Bar Single Target Line Chart', - subtitle: - 'Grouped bar target line chart with multiple series and a single target', - childBuilder: GroupedBarSingleTargetLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Stacked Bar Target Line Chart', - subtitle: 'Stacked bar target line chart with multiple series', - childBuilder: StackedBarTargetLineChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Horizontal Bar Chart', - subtitle: 'Horizontal bar chart with a single series', - childBuilder: HorizontalBarChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Stacked Horizontal Bar Chart', - subtitle: 'Stacked horizontal bar chart with multiple series', - childBuilder: StackedHorizontalBarChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Horizontal Bar Chart with Bar Labels', - subtitle: 'Horizontal bar chart with a single series and bar labels', - childBuilder: HorizontalBarLabelChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Horizontal Bar Chart with Custom Bar Labels', - subtitle: 'Bar labels with customized styling', - childBuilder: HorizontalBarLabelCustomChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Vertical Bar Chart with Bar Labels', - subtitle: 'Vertical bar chart with a single series and bar labels', - childBuilder: VerticalBarLabelChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Spark Bar Chart', - subtitle: 'Spark Bar Chart', - childBuilder: SparkBar.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Grouped Fill Color Bar Chart', - subtitle: 'Grouped bar chart with fill colors', - childBuilder: GroupedFillColorBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Stacked Fill Color Bar Chart', - subtitle: 'Stacked bar chart with fill colors', - childBuilder: StackedFillColorBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Pattern Forward Hatch Bar Chart', - subtitle: 'Pattern Forward Hatch Bar Chart', - childBuilder: PatternForwardHatchBarChart.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Horizontal Pattern Forward Hatch Bar Chart', - subtitle: 'Horizontal Pattern Forward Hatch Bar Chart', - childBuilder: HorizontalPatternForwardHatchBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Weight Pattern Bar Chart', - subtitle: 'Grouped and stacked bar chart with a weight pattern', - childBuilder: GroupedStackedWeightPatternBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Bar Chart with custom bar radius', - subtitle: 'Custom rounded bar corners', - childBuilder: CustomRoundedBars.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Simple Bar Chart', + subtitle: 'Simple bar chart with a single series', + childBuilder: SimpleBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Stacked Bar Chart', + subtitle: 'Stacked bar chart with multiple series', + childBuilder: StackedBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Grouped Bar Chart', + subtitle: 'Grouped bar chart with multiple series', + childBuilder: GroupedBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Grouped Stacked Bar Chart', + subtitle: 'Grouped and stacked bar chart with multiple series', + childBuilder: GroupedStackedBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Grouped Bar Target Line Chart', + subtitle: 'Grouped bar target line chart with multiple series', + childBuilder: GroupedBarTargetLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Grouped Bar Single Target Line Chart', + subtitle: + 'Grouped bar target line chart with multiple series and a single target', + childBuilder: GroupedBarSingleTargetLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Stacked Bar Target Line Chart', + subtitle: 'Stacked bar target line chart with multiple series', + childBuilder: StackedBarTargetLineChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Horizontal Bar Chart', + subtitle: 'Horizontal bar chart with a single series', + childBuilder: HorizontalBarChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Stacked Horizontal Bar Chart', + subtitle: 'Stacked horizontal bar chart with multiple series', + childBuilder: StackedHorizontalBarChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Horizontal Bar Chart with Bar Labels', + subtitle: 'Horizontal bar chart with a single series and bar labels', + childBuilder: HorizontalBarLabelChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Horizontal Bar Chart with Custom Bar Labels', + subtitle: 'Bar labels with customized styling', + childBuilder: HorizontalBarLabelCustomChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Vertical Bar Chart with Bar Labels', + subtitle: 'Vertical bar chart with a single series and bar labels', + childBuilder: VerticalBarLabelChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Spark Bar Chart', + subtitle: 'Spark Bar Chart', + childBuilder: SparkBar.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Grouped Fill Color Bar Chart', + subtitle: 'Grouped bar chart with fill colors', + childBuilder: GroupedFillColorBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Stacked Fill Color Bar Chart', + subtitle: 'Stacked bar chart with fill colors', + childBuilder: StackedFillColorBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Pattern Forward Hatch Bar Chart', + subtitle: 'Pattern Forward Hatch Bar Chart', + childBuilder: PatternForwardHatchBarChart.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Horizontal Pattern Forward Hatch Bar Chart', + subtitle: 'Horizontal Pattern Forward Hatch Bar Chart', + childBuilder: HorizontalPatternForwardHatchBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Weight Pattern Bar Chart', + subtitle: 'Grouped and stacked bar chart with a weight pattern', + childBuilder: GroupedStackedWeightPatternBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Bar Chart with custom bar radius', + subtitle: 'Custom rounded bar corners', + childBuilder: CustomRoundedBars.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart b/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart index 402a8c510..8397d7810 100644 --- a/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart +++ b/charts_flutter/example/lib/bar_chart/custom_rounded_bars.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class CustomRoundedBars extends StatelessWidget { - const CustomRoundedBars(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with custom rounded bars. factory CustomRoundedBars.withSampleData() => CustomRoundedBars( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory CustomRoundedBars.withRandomData() => CustomRoundedBars(_createRandomData()); + factory CustomRoundedBars.withRandomData() => + CustomRoundedBars(_createRandomData()); final List> seriesList; final bool animate; @@ -65,15 +65,16 @@ class CustomRoundedBars extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - defaultRenderer: charts.BarRendererConfig( + seriesList, + animate: animate, + defaultRenderer: charts.BarRendererConfig( // By default, bar renderer will draw rounded bars with a constant // radius of 30. // To not have any rounded corners, use [NoCornerStrategy] // To change the radius of the bars, use [ConstCornerStrategy] - cornerStrategy: const charts.ConstCornerStrategy(30),), - ); + cornerStrategy: const charts.ConstCornerStrategy(30), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -98,7 +99,6 @@ class CustomRoundedBars extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped.dart b/charts_flutter/example/lib/bar_chart/grouped.dart index 69539936d..4d635d630 100644 --- a/charts_flutter/example/lib/bar_chart/grouped.dart +++ b/charts_flutter/example/lib/bar_chart/grouped.dart @@ -23,18 +23,18 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarChart extends StatelessWidget { - const GroupedBarChart(this.seriesList, {super.key, this.animate = false}); factory GroupedBarChart.withSampleData() => GroupedBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarChart.withRandomData() => GroupedBarChart(_createRandomData()); + factory GroupedBarChart.withRandomData() => + GroupedBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -88,10 +88,10 @@ class GroupedBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + ); /// Create series list with multiple series static List> _createSampleData() { @@ -141,7 +141,6 @@ class GroupedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart b/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart index cfacf2c51..d471fd639 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_fill_color.dart @@ -25,18 +25,22 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a grouped bar chart with three series, each rendered with /// different fill colors. class GroupedFillColorBarChart extends StatelessWidget { - - const GroupedFillColorBarChart(this.seriesList, {super.key, this.animate = false}); + const GroupedFillColorBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); factory GroupedFillColorBarChart.withSampleData() => GroupedFillColorBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedFillColorBarChart.withRandomData() => GroupedFillColorBarChart(_createRandomData()); + factory GroupedFillColorBarChart.withRandomData() => + GroupedFillColorBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -100,12 +104,14 @@ class GroupedFillColorBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Configure a stroke width to enable borders on the bars. - defaultRenderer: charts.BarRendererConfig( - groupingType: charts.BarGroupingType.grouped, strokeWidthPx: 2,), - ); + seriesList, + animate: animate, + // Configure a stroke width to enable borders on the bars. + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.grouped, + strokeWidthPx: 2, + ), + ); /// Create series list with multiple series static List> _createSampleData() { @@ -165,7 +171,6 @@ class GroupedFillColorBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart b/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart index 2bc8b88d1..592320d62 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_single_target_line.dart @@ -23,18 +23,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarSingleTargetLineChart extends StatelessWidget { + const GroupedBarSingleTargetLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); - const GroupedBarSingleTargetLineChart(this.seriesList, {super.key, this.animate = false}); - - factory GroupedBarSingleTargetLineChart.withSampleData() => GroupedBarSingleTargetLineChart( - _createSampleData(), - ); + factory GroupedBarSingleTargetLineChart.withSampleData() => + GroupedBarSingleTargetLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarSingleTargetLineChart.withRandomData() => GroupedBarSingleTargetLineChart(_createRandomData()); + factory GroupedBarSingleTargetLineChart.withRandomData() => + GroupedBarSingleTargetLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -72,25 +77,29 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { return [ charts.Series( - id: 'Desktop', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: desktopSalesData,), + id: 'Desktop', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData, + ), charts.Series( - id: 'Tablet', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: tableSalesData,), + id: 'Tablet', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData, + ), charts.Series( - id: 'Mobile', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,), + id: 'Mobile', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ), charts.Series( - id: 'Desktop Target Line', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: targetLineData,) + id: 'Desktop Target Line', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: targetLineData, + ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), ]; @@ -98,14 +107,17 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart( + seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, customSeriesRenderers: [ charts.BarTargetLineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customTargetLine',), - ],); + // ID used to link series to this renderer. + customRendererId: 'customTargetLine', + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -139,25 +151,29 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { return [ charts.Series( - id: 'Desktop', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: desktopSalesData,), + id: 'Desktop', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData, + ), charts.Series( - id: 'Tablet', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: tableSalesData,), + id: 'Tablet', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData, + ), charts.Series( - id: 'Mobile', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,), + id: 'Mobile', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ), charts.Series( - id: 'Desktop Target Line', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: targetLineData,) + id: 'Desktop Target Line', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: targetLineData, + ) // Configure our custom bar target renderer for this series. ..setAttribute(charts.rendererIdKey, 'customTargetLine'), ]; @@ -166,7 +182,6 @@ class GroupedBarSingleTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked.dart index fd861e972..6a84a105b 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked.dart @@ -23,18 +23,22 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedStackedBarChart extends StatelessWidget { - - const GroupedStackedBarChart(this.seriesList, {super.key, this.animate = false}); + const GroupedStackedBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); factory GroupedStackedBarChart.withSampleData() => GroupedStackedBarChart( - createSampleData(), - ); + createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedStackedBarChart.withRandomData() => GroupedStackedBarChart(_createRandomData()); + factory GroupedStackedBarChart.withRandomData() => + GroupedStackedBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -133,10 +137,10 @@ class GroupedStackedBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.groupedStacked, - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.groupedStacked, + ); /// Create series list with multiple series static List> createSampleData() { @@ -231,7 +235,6 @@ class GroupedStackedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart index a373ef374..3e057042e 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart @@ -27,18 +27,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedStackedWeightPatternBarChart extends StatelessWidget { + const GroupedStackedWeightPatternBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); - const GroupedStackedWeightPatternBarChart(this.seriesList, {super.key, this.animate = false}); - - factory GroupedStackedWeightPatternBarChart.withSampleData() => GroupedStackedWeightPatternBarChart( - createSampleData(), - ); + factory GroupedStackedWeightPatternBarChart.withSampleData() => + GroupedStackedWeightPatternBarChart( + createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedStackedWeightPatternBarChart.withRandomData() => GroupedStackedWeightPatternBarChart(_createRandomData()); + factory GroupedStackedWeightPatternBarChart.withRandomData() => + GroupedStackedWeightPatternBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -137,18 +142,18 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Configure the bar renderer in grouped stacked rendering mode with a - // custom weight pattern. - // - // The first stack of bars in each group is configured to be twice as wide - // as the second stack of bars in each group. - defaultRenderer: charts.BarRendererConfig( - groupingType: charts.BarGroupingType.groupedStacked, - weightPattern: [2, 1], - ), - ); + seriesList, + animate: animate, + // Configure the bar renderer in grouped stacked rendering mode with a + // custom weight pattern. + // + // The first stack of bars in each group is configured to be twice as wide + // as the second stack of bars in each group. + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.groupedStacked, + weightPattern: [2, 1], + ), + ); /// Create series list with multiple series static List> createSampleData() { @@ -243,7 +248,6 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/grouped_target_line.dart b/charts_flutter/example/lib/bar_chart/grouped_target_line.dart index ef88f0412..5ac74b301 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_target_line.dart @@ -23,18 +23,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GroupedBarTargetLineChart extends StatelessWidget { + const GroupedBarTargetLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); - const GroupedBarTargetLineChart(this.seriesList, {super.key, this.animate = false}); - - factory GroupedBarTargetLineChart.withSampleData() => GroupedBarTargetLineChart( - _createSampleData(), - ); + factory GroupedBarTargetLineChart.withSampleData() => + GroupedBarTargetLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory GroupedBarTargetLineChart.withRandomData() => GroupedBarTargetLineChart(_createRandomData()); + factory GroupedBarTargetLineChart.withRandomData() => + GroupedBarTargetLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -132,14 +137,17 @@ class GroupedBarTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart( + seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, customSeriesRenderers: [ charts.BarTargetLineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customTargetLine',), - ],); + // ID used to link series to this renderer. + customRendererId: 'customTargetLine', + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -234,7 +242,6 @@ class GroupedBarTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/horizontal.dart b/charts_flutter/example/lib/bar_chart/horizontal.dart index 6aa8b02b6..a175ceef0 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class HorizontalBarChart extends StatelessWidget { - const HorizontalBarChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory HorizontalBarChart.withSampleData() => HorizontalBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarChart.withRandomData() => HorizontalBarChart(_createRandomData()); + factory HorizontalBarChart.withRandomData() => + HorizontalBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -63,14 +63,13 @@ class HorizontalBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // For horizontal bar charts, set the [vertical] flag to false. - return charts.BarChart( - seriesList, - animate: animate, - vertical: false, - ); - } + Widget build(BuildContext context) => + // For horizontal bar charts, set the [vertical] flag to false. + charts.BarChart( + seriesList, + animate: animate, + vertical: false, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -94,7 +93,6 @@ class HorizontalBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart b/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart index b5504b81e..9284e9f89 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_bar_label.dart @@ -24,19 +24,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class HorizontalBarLabelChart extends StatelessWidget { - - const HorizontalBarLabelChart(this.seriesList, {super.key, this.animate = false}); + const HorizontalBarLabelChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory HorizontalBarLabelChart.withSampleData() => HorizontalBarLabelChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarLabelChart.withRandomData() => HorizontalBarLabelChart(_createRandomData()); + factory HorizontalBarLabelChart.withRandomData() => + HorizontalBarLabelChart(_createRandomData()); final List> seriesList; final bool animate; @@ -53,13 +57,13 @@ class HorizontalBarLabelChart extends StatelessWidget { return [ charts.Series( - id: 'Sales', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: data, - // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - '${sales.year}: \$${sales.sales}',), + id: 'Sales', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: data, + // Set a label accessor to control the text of the bar label. + labelAccessorFn: (sales, _) => '${sales.year}: \$${sales.sales}', + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -73,19 +77,19 @@ class HorizontalBarLabelChart extends StatelessWidget { // [insideLabelStyleSpec] and [outsideLabelStyleSpec]. @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - vertical: false, - // Set a bar label decorator. - // Example configuring different styles for inside/outside: - // barRendererDecorator: new charts.BarLabelDecorator( - // insideLabelStyleSpec: new charts.TextStyleSpec(...), - // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - barRendererDecorator: charts.BarLabelDecorator(), - // Hide domain axis. - domainAxis: - const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), - ); + seriesList, + animate: animate, + vertical: false, + // Set a bar label decorator. + // Example configuring different styles for inside/outside: + // barRendererDecorator: new charts.BarLabelDecorator( + // insideLabelStyleSpec: new charts.TextStyleSpec(...), + // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), + barRendererDecorator: charts.BarLabelDecorator(), + // Hide domain axis. + domainAxis: + const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -98,20 +102,19 @@ class HorizontalBarLabelChart extends StatelessWidget { return [ charts.Series( - id: 'Sales', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: data, - // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - '${sales.year}: \$${sales.sales}',), + id: 'Sales', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: data, + // Set a label accessor to control the text of the bar label. + labelAccessorFn: (sales, _) => '${sales.year}: \$${sales.sales}', + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart b/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart index 3e1390393..3d5701e4f 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_bar_label_custom.dart @@ -24,21 +24,27 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class HorizontalBarLabelCustomChart extends StatelessWidget { - - const HorizontalBarLabelCustomChart(this.seriesList, {super.key, this.animate = false}); + const HorizontalBarLabelCustomChart( + this.seriesList, { + super.key, + this.animate = false, + }); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalBarLabelCustomChart.withRandomData() => HorizontalBarLabelCustomChart(_createRandomData()); + factory HorizontalBarLabelCustomChart.withRandomData() => + HorizontalBarLabelCustomChart(_createRandomData()); final List> seriesList; final bool animate; /// Creates a [charts.BarChart] with sample data and no transition. - static HorizontalBarLabelCustomChart createWithSampleData() => HorizontalBarLabelCustomChart( - _createSampleData(), - ); + // ignore: sort_constructors_first + factory HorizontalBarLabelCustomChart.createWithSampleData() => + HorizontalBarLabelCustomChart( + _createSampleData(), + ); /// Create random data. static List> _createRandomData() { @@ -58,8 +64,7 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - '${sales.year}: \$${sales.sales}', + labelAccessorFn: (sales, _) => '${sales.year}: \$${sales.sales}', insideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault @@ -82,14 +87,14 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { // style, set the style accessor functions on the series. @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - vertical: false, - barRendererDecorator: charts.BarLabelDecorator(), - // Hide domain axis. - domainAxis: - const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), - ); + seriesList, + animate: animate, + vertical: false, + barRendererDecorator: charts.BarLabelDecorator(), + // Hide domain axis. + domainAxis: + const charts.OrdinalAxisSpec(renderSpec: charts.NoneRenderSpec()), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -107,8 +112,7 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - '${sales.year}: \$${sales.sales}', + labelAccessorFn: (sales, _) => '${sales.year}: \$${sales.sales}', insideLabelStyleAccessorFn: (sales, _) { final color = (sales.year == '2014') ? charts.MaterialPalette.red.shadeDefault @@ -128,7 +132,6 @@ class HorizontalBarLabelCustomChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart b/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart index 16d8c6e42..0ec33bfe7 100644 --- a/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart +++ b/charts_flutter/example/lib/bar_chart/horizontal_pattern_forward_hatch.dart @@ -27,19 +27,23 @@ import 'package:nimble_charts/flutter.dart' as charts; /// The second series of bars is rendered with a pattern by defining a /// fillPatternFn mapping function. class HorizontalPatternForwardHatchBarChart extends StatelessWidget { + const HorizontalPatternForwardHatchBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); - const HorizontalPatternForwardHatchBarChart(this.seriesList, - {super.key, this.animate = false,}); - - factory HorizontalPatternForwardHatchBarChart.withSampleData() => HorizontalPatternForwardHatchBarChart( - _createSampleData(), - ); + factory HorizontalPatternForwardHatchBarChart.withSampleData() => + HorizontalPatternForwardHatchBarChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory HorizontalPatternForwardHatchBarChart.withRandomData() => HorizontalPatternForwardHatchBarChart(_createRandomData()); + factory HorizontalPatternForwardHatchBarChart.withRandomData() => + HorizontalPatternForwardHatchBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -80,8 +84,7 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { domainFn: (sales, _) => sales.year, measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (sales, _) => - charts.FillPatternType.forwardHatch, + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), charts.Series( id: 'Mobile', @@ -95,11 +98,11 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - vertical: false, - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + vertical: false, + ); /// Create series list with multiple series static List> _createSampleData() { @@ -136,8 +139,7 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { domainFn: (sales, _) => sales.year, measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (sales, _) => - charts.FillPatternType.forwardHatch, + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), charts.Series( id: 'Mobile', @@ -151,7 +153,6 @@ class HorizontalPatternForwardHatchBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart b/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart index bdabdf9ea..5aa6a96ac 100644 --- a/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart +++ b/charts_flutter/example/lib/bar_chart/pattern_forward_hatch.dart @@ -26,18 +26,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PatternForwardHatchBarChart extends StatelessWidget { + const PatternForwardHatchBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); - const PatternForwardHatchBarChart(this.seriesList, {super.key, this.animate = false}); - - factory PatternForwardHatchBarChart.withSampleData() => PatternForwardHatchBarChart( - _createSampleData(), - ); + factory PatternForwardHatchBarChart.withSampleData() => + PatternForwardHatchBarChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PatternForwardHatchBarChart.withRandomData() => PatternForwardHatchBarChart(_createRandomData()); + factory PatternForwardHatchBarChart.withRandomData() => + PatternForwardHatchBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -78,8 +83,7 @@ class PatternForwardHatchBarChart extends StatelessWidget { domainFn: (sales, _) => sales.year, measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (sales, _) => - charts.FillPatternType.forwardHatch, + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), charts.Series( id: 'Mobile', @@ -93,10 +97,10 @@ class PatternForwardHatchBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + ); /// Create series list with multiple series static List> _createSampleData() { @@ -133,8 +137,7 @@ class PatternForwardHatchBarChart extends StatelessWidget { domainFn: (sales, _) => sales.year, measureFn: (sales, _) => sales.sales, data: tableSalesData, - fillPatternFn: (sales, _) => - charts.FillPatternType.forwardHatch, + fillPatternFn: (sales, _) => charts.FillPatternType.forwardHatch, ), charts.Series( id: 'Mobile', @@ -148,7 +151,6 @@ class PatternForwardHatchBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/simple.dart b/charts_flutter/example/lib/bar_chart/simple.dart index 90d3601d9..ccf1001cc 100644 --- a/charts_flutter/example/lib/bar_chart/simple.dart +++ b/charts_flutter/example/lib/bar_chart/simple.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleBarChart extends StatelessWidget { - const SimpleBarChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory SimpleBarChart.withSampleData() => SimpleBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleBarChart.withRandomData() => SimpleBarChart(_createRandomData()); + factory SimpleBarChart.withRandomData() => + SimpleBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -65,9 +65,9 @@ class SimpleBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - ); + seriesList, + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -92,7 +92,6 @@ class SimpleBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/spark_bar.dart b/charts_flutter/example/lib/bar_chart/spark_bar.dart index a2e5c494d..435ae0cba 100644 --- a/charts_flutter/example/lib/bar_chart/spark_bar.dart +++ b/charts_flutter/example/lib/bar_chart/spark_bar.dart @@ -75,8 +75,8 @@ class SparkBar extends StatelessWidget { /// Assign a custom style for the measure axis. /// - /// The NoneRenderSpec only draws an axis line (and even that can be hidden - /// with showAxisLine=false). + /// The NoneRenderSpec only draws an axis line (and even that can be + /// hidden with showAxisLine=false). primaryMeasureAxis: const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()), diff --git a/charts_flutter/example/lib/bar_chart/stacked.dart b/charts_flutter/example/lib/bar_chart/stacked.dart index a02fa355e..0321d1d9e 100644 --- a/charts_flutter/example/lib/bar_chart/stacked.dart +++ b/charts_flutter/example/lib/bar_chart/stacked.dart @@ -23,19 +23,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedBarChart extends StatelessWidget { - const StackedBarChart(this.seriesList, {super.key, this.animate = false}); /// Creates a stacked [charts.BarChart] with sample data and no transition. factory StackedBarChart.withSampleData() => StackedBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedBarChart.withRandomData() => StackedBarChart(_createRandomData()); + factory StackedBarChart.withRandomData() => + StackedBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -89,10 +89,10 @@ class StackedBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.stacked, - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.stacked, + ); /// Create series list with multiple series static List> _createSampleData() { @@ -142,7 +142,6 @@ class StackedBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart b/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart index bb0f1deb9..ee037011a 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_fill_color.dart @@ -25,18 +25,22 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a stacked bar chart with three series, each rendered with /// different fill colors. class StackedFillColorBarChart extends StatelessWidget { - - const StackedFillColorBarChart(this.seriesList, {super.key, this.animate = false}); + const StackedFillColorBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); factory StackedFillColorBarChart.withSampleData() => StackedFillColorBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedFillColorBarChart.withRandomData() => StackedFillColorBarChart(_createRandomData()); + factory StackedFillColorBarChart.withRandomData() => + StackedFillColorBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -100,12 +104,14 @@ class StackedFillColorBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Configure a stroke width to enable borders on the bars. - defaultRenderer: charts.BarRendererConfig( - groupingType: charts.BarGroupingType.stacked, strokeWidthPx: 2,), - ); + seriesList, + animate: animate, + // Configure a stroke width to enable borders on the bars. + defaultRenderer: charts.BarRendererConfig( + groupingType: charts.BarGroupingType.stacked, + strokeWidthPx: 2, + ), + ); /// Create series list with multiple series static List> _createSampleData() { @@ -165,7 +171,6 @@ class StackedFillColorBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart b/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart index a32738380..6bf2c207b 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_horizontal.dart @@ -23,19 +23,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedHorizontalBarChart extends StatelessWidget { - - const StackedHorizontalBarChart(this.seriesList, {super.key, this.animate = false}); + const StackedHorizontalBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a stacked [charts.BarChart] with sample data and no transition. - factory StackedHorizontalBarChart.withSampleData() => StackedHorizontalBarChart( - _createSampleData(), - ); + factory StackedHorizontalBarChart.withSampleData() => + StackedHorizontalBarChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedHorizontalBarChart.withRandomData() => StackedHorizontalBarChart(_createRandomData()); + factory StackedHorizontalBarChart.withRandomData() => + StackedHorizontalBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -88,15 +93,14 @@ class StackedHorizontalBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // For horizontal bar charts, set the [vertical] flag to false. - return charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.stacked, - vertical: false, - ); - } + Widget build(BuildContext context) => + // For horizontal bar charts, set the [vertical] flag to false. + charts.BarChart( + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.stacked, + vertical: false, + ); /// Create series list with multiple series static List> _createSampleData() { @@ -146,7 +150,6 @@ class StackedHorizontalBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/stacked_target_line.dart b/charts_flutter/example/lib/bar_chart/stacked_target_line.dart index 061e822d3..bad4f4c7b 100644 --- a/charts_flutter/example/lib/bar_chart/stacked_target_line.dart +++ b/charts_flutter/example/lib/bar_chart/stacked_target_line.dart @@ -23,19 +23,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedBarTargetLineChart extends StatelessWidget { - - const StackedBarTargetLineChart(this.seriesList, {super.key, this.animate = false}); + const StackedBarTargetLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a stacked [charts.BarChart] with sample data and no transition. - factory StackedBarTargetLineChart.withSampleData() => StackedBarTargetLineChart( - _createSampleData(), - ); + factory StackedBarTargetLineChart.withSampleData() => + StackedBarTargetLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedBarTargetLineChart.withRandomData() => StackedBarTargetLineChart(_createRandomData()); + factory StackedBarTargetLineChart.withRandomData() => + StackedBarTargetLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -133,15 +138,18 @@ class StackedBarTargetLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.BarChart(seriesList, + Widget build(BuildContext context) => charts.BarChart( + seriesList, animate: animate, barGroupingType: charts.BarGroupingType.stacked, customSeriesRenderers: [ charts.BarTargetLineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customTargetLine', - groupingType: charts.BarGroupingType.stacked,), - ],); + // ID used to link series to this renderer. + customRendererId: 'customTargetLine', + groupingType: charts.BarGroupingType.stacked, + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -236,7 +244,6 @@ class StackedBarTargetLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart index d368bb933..32dc1ea64 100644 --- a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart +++ b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart @@ -24,19 +24,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class VerticalBarLabelChart extends StatelessWidget { - - const VerticalBarLabelChart(this.seriesList, {super.key, this.animate = false}); + const VerticalBarLabelChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory VerticalBarLabelChart.withSampleData() => VerticalBarLabelChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory VerticalBarLabelChart.withRandomData() => VerticalBarLabelChart(_createRandomData()); + factory VerticalBarLabelChart.withRandomData() => + VerticalBarLabelChart(_createRandomData()); final List> seriesList; final bool animate; @@ -53,13 +57,13 @@ class VerticalBarLabelChart extends StatelessWidget { return [ charts.Series( - id: 'Sales', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: data, - // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - sales.sales,), + id: 'Sales', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: data, + // Set a label accessor to control the text of the bar label. + labelAccessorFn: (sales, _) => sales.sales, + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @@ -73,16 +77,16 @@ class VerticalBarLabelChart extends StatelessWidget { // [insideLabelStyleSpec] and [outsideLabelStyleSpec]. @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Set a bar label decorator. - // Example configuring different styles for inside/outside: - // barRendererDecorator: new charts.BarLabelDecorator( - // insideLabelStyleSpec: new charts.TextStyleSpec(...), - // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - barRendererDecorator: charts.BarLabelDecorator(), - domainAxis: const charts.OrdinalAxisSpec(), - ); + seriesList, + animate: animate, + // Set a bar label decorator. + // Example configuring different styles for inside/outside: + // barRendererDecorator: new charts.BarLabelDecorator( + // insideLabelStyleSpec: new charts.TextStyleSpec(...), + // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), + barRendererDecorator: charts.BarLabelDecorator(), + domainAxis: const charts.OrdinalAxisSpec(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -95,20 +99,19 @@ class VerticalBarLabelChart extends StatelessWidget { return [ charts.Series( - id: 'Sales', - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: data, - // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => - '\$${sales.sales}',), + id: 'Sales', + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: data, + // Set a label accessor to control the text of the bar label. + labelAccessorFn: (sales, _) => '\$${sales.sales}', + ), ]; } } /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart index bde5163db..e2c4de244 100644 --- a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart +++ b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart @@ -30,91 +30,93 @@ import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Selection Bar Highlight', - subtitle: 'Simple bar chart with tap activation', - childBuilder: SelectionBarHighlight.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Selection Line Highlight', - subtitle: 'Line chart with tap and drag activation', - childBuilder: SelectionLineHighlight.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Selection Line Highlight Custom Shape', - subtitle: 'Line chart with tap and drag activation and a custom shape', - childBuilder: SelectionLineHighlightCustomShape.withRandomData, - ), - //TODO - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.flag), - // title: 'Selection Scatter Plot Highlight', - // subtitle: 'Scatter plot chart with tap and drag activation', - // childBuilder: () => new SelectionScatterPlotHighlight.withRandomData(), - // ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Selection Callback Example', - subtitle: 'Timeseries that updates external components on selection', - childBuilder: SelectionCallbackExample.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'User managed selection', - subtitle: - 'Example where selection can be set and cleared programmatically', - childBuilder: SelectionUserManaged.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Bar Chart with initial selection', - subtitle: 'Single series with initial selection', - childBuilder: InitialSelection.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Line Chart with Chart Titles', - subtitle: 'Line chart with four chart titles', - childBuilder: ChartTitleLine.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'Line Chart with Slider', - subtitle: 'Line chart with a slider behavior', - childBuilder: SliderLine.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Percent of Domain', - subtitle: 'Stacked bar chart with measures calculated as percent of ' 'domain', - childBuilder: PercentOfDomainBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Percent of Domain by Category', - subtitle: 'Grouped stacked bar chart with measures calculated as ' - 'percent of domain and series category', - childBuilder: PercentOfDomainByCategoryBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Percent of Series', - subtitle: 'Grouped bar chart with measures calculated as percent of ' 'series', - childBuilder: PercentOfSeriesBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Sliding viewport on domain selection', - subtitle: 'Center viewport on selected domain', - childBuilder: SlidingViewportOnSelection.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Initial hint animation ', - subtitle: 'Animate into final viewport', - childBuilder: InitialHintAnimation.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Selection Bar Highlight', + subtitle: 'Simple bar chart with tap activation', + childBuilder: SelectionBarHighlight.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Selection Line Highlight', + subtitle: 'Line chart with tap and drag activation', + childBuilder: SelectionLineHighlight.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Selection Line Highlight Custom Shape', + subtitle: 'Line chart with tap and drag activation and a custom shape', + childBuilder: SelectionLineHighlightCustomShape.withRandomData, + ), + //TODO + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.flag), + // title: 'Selection Scatter Plot Highlight', + // subtitle: 'Scatter plot chart with tap and drag activation', + // childBuilder: () => new SelectionScatterPlotHighlight.withRandomData(), + // ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Selection Callback Example', + subtitle: 'Timeseries that updates external components on selection', + childBuilder: SelectionCallbackExample.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'User managed selection', + subtitle: + 'Example where selection can be set and cleared programmatically', + childBuilder: SelectionUserManaged.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Bar Chart with initial selection', + subtitle: 'Single series with initial selection', + childBuilder: InitialSelection.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Line Chart with Chart Titles', + subtitle: 'Line chart with four chart titles', + childBuilder: ChartTitleLine.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'Line Chart with Slider', + subtitle: 'Line chart with a slider behavior', + childBuilder: SliderLine.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Percent of Domain', + subtitle: 'Stacked bar chart with measures calculated as percent of ' + 'domain', + childBuilder: PercentOfDomainBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Percent of Domain by Category', + subtitle: 'Grouped stacked bar chart with measures calculated as ' + 'percent of domain and series category', + childBuilder: PercentOfDomainByCategoryBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Percent of Series', + subtitle: 'Grouped bar chart with measures calculated as percent of ' + 'series', + childBuilder: PercentOfSeriesBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Sliding viewport on domain selection', + subtitle: 'Center viewport on selected domain', + childBuilder: SlidingViewportOnSelection.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Initial hint animation ', + subtitle: 'Animate into final viewport', + childBuilder: InitialHintAnimation.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/behaviors/chart_title.dart b/charts_flutter/example/lib/behaviors/chart_title.dart index 765ae450e..d4e443c98 100644 --- a/charts_flutter/example/lib/behaviors/chart_title.dart +++ b/charts_flutter/example/lib/behaviors/chart_title.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START +// ignore_for_file: lines_longer_than_80_chars + import 'dart:math'; import 'package:flutter/material.dart'; @@ -24,19 +26,19 @@ import 'package:nimble_charts/flutter.dart' as charts; /// A series of [charts.ChartTitle] behaviors are used to render titles, one per /// margin. class ChartTitleLine extends StatelessWidget { - const ChartTitleLine(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory ChartTitleLine.withSampleData() => ChartTitleLine( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ChartTitleLine.withRandomData() => ChartTitleLine(_createRandomData()); + factory ChartTitleLine.withRandomData() => + ChartTitleLine(_createRandomData()); final List> seriesList; final bool animate; @@ -64,14 +66,15 @@ class ChartTitleLine extends StatelessWidget { @override Widget build(BuildContext context) => charts.LineChart( - seriesList, - animate: animate, - // Configures four [ChartTitle] behaviors to render titles in each chart - // margin. The top title has a sub-title, and is aligned to the left edge - // of the chart. The other titles are aligned with the middle of the draw - // area. - behaviors: [ - charts.ChartTitle('Top title text', + seriesList, + animate: animate, + // Configures four [ChartTitle] behaviors to render titles in each chart + // margin. The top title has a sub-title, and is aligned to the left edge + // of the chart. The other titles are aligned with the middle of the draw + // area. + behaviors: [ + charts.ChartTitle( + 'Top title text', subTitle: 'Top sub-title text', behaviorPosition: charts.BehaviorPosition.top, titleOutsideJustification: charts.OutsideJustification.start, @@ -79,21 +82,28 @@ class ChartTitleLine extends StatelessWidget { // rendering the text too close to the top measure axis tick label. // The top tick label may extend upwards into the top margin region // if it is located at the top of the draw area. - innerPadding: 18,), - charts.ChartTitle('Bottom title text', + innerPadding: 18, + ), + charts.ChartTitle( + 'Bottom title text', behaviorPosition: charts.BehaviorPosition.bottom, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea,), - charts.ChartTitle('Start title', + charts.OutsideJustification.middleDrawArea, + ), + charts.ChartTitle( + 'Start title', behaviorPosition: charts.BehaviorPosition.start, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea,), - charts.ChartTitle('End title', + charts.OutsideJustification.middleDrawArea, + ), + charts.ChartTitle( + 'End title', behaviorPosition: charts.BehaviorPosition.end, titleOutsideJustification: - charts.OutsideJustification.middleDrawArea,), - ], - ); + charts.OutsideJustification.middleDrawArea, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -117,7 +127,6 @@ class ChartTitleLine extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart index 9b0edfc9c..f4f9acbab 100644 --- a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart @@ -20,19 +20,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionBarHighlight extends StatelessWidget { - - const SelectionBarHighlight(this.seriesList, {super.key, this.animate = false}); + const SelectionBarHighlight(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory SelectionBarHighlight.withSampleData() => SelectionBarHighlight( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionBarHighlight.withRandomData() => SelectionBarHighlight(_createRandomData()); + factory SelectionBarHighlight.withRandomData() => + SelectionBarHighlight(_createRandomData()); final List> seriesList; final bool animate; @@ -59,21 +60,20 @@ class SelectionBarHighlight extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // This is just a simple bar chart with optional property - // [defaultInteractions] set to true to include the default - // interactions/behaviors when building the chart. - // This includes bar highlighting. - // - // Note: defaultInteractions defaults to true. - // - // [defaultInteractions] can be set to false to avoid the default - // interactions. - return charts.BarChart( - seriesList, - animate: animate, - ); - } + Widget build(BuildContext context) => + // This is just a simple bar chart with optional property + // [defaultInteractions] set to true to include the default + // interactions/behaviors when building the chart. + // This includes bar highlighting. + // + // Note: defaultInteractions defaults to true. + // + // [defaultInteractions] can be set to false to avoid the default + // interactions. + charts.BarChart( + seriesList, + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -97,7 +97,6 @@ class SelectionBarHighlight extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_callback_example.dart b/charts_flutter/example/lib/behaviors/selection_callback_example.dart index 4ff7ba850..453da3d28 100644 --- a/charts_flutter/example/lib/behaviors/selection_callback_example.dart +++ b/charts_flutter/example/lib/behaviors/selection_callback_example.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Timeseries chart with example of updating external state based on selection. /// /// A SelectionModelConfig can be provided for each of the different @@ -132,7 +134,7 @@ class _SelectionCallbackState extends State { // Listens to the underlying selection changes, and updates the information // relevant to building the primitive legend like information under the // chart. - _onSelectionChanged(charts.SelectionModel model) { + void _onSelectionChanged(charts.SelectionModel model) { final selectedDatum = model.selectedDatum; DateTime? time; diff --git a/charts_flutter/example/lib/behaviors/selection_user_managed.dart b/charts_flutter/example/lib/behaviors/selection_user_managed.dart index 91a70b3f7..5f57b0e95 100644 --- a/charts_flutter/example/lib/behaviors/selection_user_managed.dart +++ b/charts_flutter/example/lib/behaviors/selection_user_managed.dart @@ -32,19 +32,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionUserManaged extends StatefulWidget { - - const SelectionUserManaged(this.seriesList, {super.key, this.animate = false}); + const SelectionUserManaged(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory SelectionUserManaged.withSampleData() => SelectionUserManaged( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionUserManaged.withRandomData() => SelectionUserManaged(_createRandomData()); + factory SelectionUserManaged.withRandomData() => + SelectionUserManaged(_createRandomData()); final List> seriesList; final bool animate; @@ -105,7 +106,8 @@ class SelectionUserManagedState extends State { animate: false, //widget.animate, selectionModels: [ charts.SelectionModelConfig( - updatedListener: _infoSelectionModelUpdated,), + updatedListener: _infoSelectionModelUpdated, + ), ], // Pass in the state you manage to the chart. This will be used to // override the internal chart state. @@ -113,17 +115,22 @@ class SelectionUserManagedState extends State { // The initial selection can still be optionally added by adding the // initial selection behavior. behaviors: [ - charts.InitialSelection(selectedDataConfig: [ - charts.SeriesDatumConfig('Sales', '2016'), - ],), + charts.InitialSelection( + selectedDataConfig: [ + charts.SeriesDatumConfig('Sales', '2016'), + ], + ), ], ); final clearSelection = MaterialButton( - onPressed: _handleClearSelection, child: const Text('Clear Selection'),); + onPressed: _handleClearSelection, + child: const Text('Clear Selection'), + ); return Column( - children: [SizedBox(height: 150, child: chart), clearSelection],); + children: [SizedBox(height: 150, child: chart), clearSelection], + ); } void _infoSelectionModelUpdated(charts.SelectionModel model) { @@ -151,7 +158,6 @@ class SelectionUserManagedState extends State { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/slider.dart b/charts_flutter/example/lib/behaviors/slider.dart index e6a623b63..cd811d9ba 100644 --- a/charts_flutter/example/lib/behaviors/slider.dart +++ b/charts_flutter/example/lib/behaviors/slider.dart @@ -103,7 +103,7 @@ class _SliderCallbackState extends State { Point? _sliderPosition; // Handles callbacks when the user drags the slider. - _onSliderChange(Point point, domain, String roleId, + void _onSliderChange(Point point, domain, String roleId, charts.SliderListenerDragState dragState,) { // Request a build. void rebuild(_) { diff --git a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart index d0fc3f457..99e1a5f90 100644 --- a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart @@ -30,19 +30,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DateTimeComboLinePointChart extends StatelessWidget { - - const DateTimeComboLinePointChart(this.seriesList, {super.key, this.animate = false}); + const DateTimeComboLinePointChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory DateTimeComboLinePointChart.withSampleData() => DateTimeComboLinePointChart( - _createSampleData(), - ); + factory DateTimeComboLinePointChart.withSampleData() => + DateTimeComboLinePointChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DateTimeComboLinePointChart.withRandomData() => DateTimeComboLinePointChart(_createRandomData()); + factory DateTimeComboLinePointChart.withRandomData() => + DateTimeComboLinePointChart(_createRandomData()); final List> seriesList; final bool animate; @@ -87,11 +92,12 @@ class DateTimeComboLinePointChart extends StatelessWidget { data: tableSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.time, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -100,24 +106,26 @@ class DateTimeComboLinePointChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Configure the default renderer as a line renderer. This will be used - // for any series that does not define a rendererIdKey. - // - // This is the default configuration, but is shown here for illustration. - defaultRenderer: charts.LineRendererConfig(), - // Custom renderer configuration for the point series. - customSeriesRenderers: [ - charts.PointRendererConfig( + seriesList, + animate: animate, + // Configure the default renderer as a line renderer. This will be used + // for any series that does not define a rendererIdKey. + // + // This is the default configuration, but is shown here for + // illustration. + defaultRenderer: charts.LineRendererConfig(), + // Custom renderer configuration for the point series. + customSeriesRenderers: [ + charts.PointRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customPoint',), - ], - // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. - dateTimeFactory: const charts.LocalDateTimeFactory(), - ); + customRendererId: 'customPoint', + ), + ], + // Optionally pass in a [DateTimeFactory] used by the chart. The factory + // should create the same type of [DateTime] as the data provided. If none + // specified, the default creates local date time. + dateTimeFactory: const charts.LocalDateTimeFactory(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -158,11 +166,12 @@ class DateTimeComboLinePointChart extends StatelessWidget { data: tableSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.time, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.time, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -171,7 +180,6 @@ class DateTimeComboLinePointChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart b/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart index bd89d1476..4a050cbfd 100644 --- a/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart +++ b/charts_flutter/example/lib/combo_chart/numeric_line_bar.dart @@ -25,19 +25,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class NumericComboLineBarChart extends StatelessWidget { - - const NumericComboLineBarChart(this.seriesList, {super.key, this.animate = false}); + const NumericComboLineBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory NumericComboLineBarChart.withSampleData() => NumericComboLineBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericComboLineBarChart.withRandomData() => NumericComboLineBarChart(_createRandomData()); + factory NumericComboLineBarChart.withRandomData() => + NumericComboLineBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -86,17 +90,19 @@ class NumericComboLineBarChart extends StatelessWidget { // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,), + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.NumericComboChart(seriesList, + Widget build(BuildContext context) => charts.NumericComboChart( + seriesList, animate: animate, // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. @@ -104,9 +110,11 @@ class NumericComboLineBarChart extends StatelessWidget { // Custom renderer configuration for the bar series. customSeriesRenderers: [ charts.BarRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customBar',), - ],); + // ID used to link series to this renderer. + customRendererId: 'customBar', + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -151,18 +159,18 @@ class NumericComboLineBarChart extends StatelessWidget { // Configure our custom bar renderer for this series. ..setAttribute(charts.rendererIdKey, 'customBar'), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,), + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ), ]; } } /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/home.dart b/charts_flutter/example/lib/home.dart index a9c8f63b2..aa4576910 100644 --- a/charts_flutter/example/lib/home.dart +++ b/charts_flutter/example/lib/home.dart @@ -19,16 +19,19 @@ import 'package:example/a11y/a11y_gallery.dart' as a11y show buildGallery; import 'package:example/app_config.dart'; import 'package:example/axes/axes_gallery.dart' as axes show buildGallery; import 'package:example/bar_chart/bar_gallery.dart' as bar show buildGallery; -import 'package:example/behaviors/behaviors_gallery.dart' as behaviors show buildGallery; -import 'package:example/combo_chart/combo_gallery.dart' as combo show buildGallery; +import 'package:example/behaviors/behaviors_gallery.dart' as behaviors + show buildGallery; +import 'package:example/combo_chart/combo_gallery.dart' as combo + show buildGallery; import 'package:example/i18n/i18n_gallery.dart' as i18n show buildGallery; -import 'package:example/legends/legends_gallery.dart' as legends show buildGallery; +import 'package:example/legends/legends_gallery.dart' as legends + show buildGallery; import 'package:example/line_chart/line_gallery.dart' as line show buildGallery; import 'package:example/pie_chart/pie_gallery.dart' as pie show buildGallery; -import 'package:example/scatter_plot_chart/scatter_plot_gallery.dart' as scatter_plot - show buildGallery; -import 'package:example/time_series_chart/time_series_gallery.dart' as time_series - show buildGallery; +import 'package:example/scatter_plot_chart/scatter_plot_gallery.dart' + as scatter_plot show buildGallery; +import 'package:example/time_series_chart/time_series_gallery.dart' + as time_series show buildGallery; import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; @@ -36,7 +39,6 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// This renders a list of all available demos. class Home extends StatelessWidget { - Home({ super.key, }); @@ -54,49 +56,32 @@ class Home extends StatelessWidget { @override Widget build(BuildContext context) { - final galleries = []; - - galleries.addAll( - a11yGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example bar charts. - galleries.addAll( - barGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example time series charts. - galleries.addAll(timeSeriesGalleries - .map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example line charts. - galleries.addAll( - lineGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example scatter plot charts. - galleries.addAll(scatterPlotGalleries - .map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example pie charts. - galleries.addAll( - comboGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example pie charts. - galleries.addAll( - pieGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add example custom axis. - galleries.addAll( - axesGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); - - galleries.addAll(behaviorsGalleries - .map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add legends examples - galleries.addAll(legendsGalleries - .map((gallery) => gallery.buildGalleryListTile(context)),); - - // Add examples for i18n. - galleries.addAll( - i18nGalleries.map((gallery) => gallery.buildGalleryListTile(context)),); + final galleries = [ + ...a11yGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + // Add example bar charts. + ...barGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + // Add example time series charts. + ...timeSeriesGalleries + .map((gallery) => gallery.buildGalleryListTile(context)), + // Add example line charts. + ...lineGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + // Add example scatter plot charts. + ...scatterPlotGalleries + .map((gallery) => gallery.buildGalleryListTile(context)), + // Add example pie charts. + ...comboGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + // Add example pie charts. + ...pieGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + // Add example custom axis. + ...axesGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + ...behaviorsGalleries + .map((gallery) => gallery.buildGalleryListTile(context)), + // Add legends examples + ...legendsGalleries + .map((gallery) => gallery.buildGalleryListTile(context)), + // Add examples for i18n. + ...i18nGalleries.map((gallery) => gallery.buildGalleryListTile(context)), + ]; _setupPerformance(); diff --git a/charts_flutter/example/lib/i18n/rtl_line_segments.dart b/charts_flutter/example/lib/i18n/rtl_line_segments.dart index 70c798732..0a8622e2d 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_segments.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_segments.dart @@ -36,19 +36,19 @@ import 'package:nimble_charts/flutter.dart' as charts; import 'package:nimble_charts/flutter.dart'; class RTLLineSegments extends StatelessWidget { - const RTLLineSegments(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory RTLLineSegments.withSampleData() => RTLLineSegments( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLLineSegments.withRandomData() => RTLLineSegments(_createRandomData()); + factory RTLLineSegments.withRandomData() => + RTLLineSegments(_createRandomData()); final List> seriesList; final bool animate; @@ -99,8 +99,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? blue[1] : blue[0], + colorFn: (sales, _) => sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -110,8 +109,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? red[1] : red[0], + colorFn: (sales, _) => sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -121,8 +119,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? green[1] : green[0], + colorFn: (sales, _) => sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -134,27 +131,27 @@ class RTLLineSegments extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // Charts will determine if RTL is enabled by checking the directionality by - // requesting Directionality.of(context). This returns the text direction - // from the closest instance of that encloses the context passed to build - // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This - // means that the directionality widget does not have to directly wrap each - // chart. It is show here as an example only. - // - // By default, when a chart detects RTL: - // Measure axis positions are flipped. Primary measure axis is on the right - // and the secondary measure axis is on the left (when used). - // Domain axis' first domain starts on the right and grows left. - return Directionality( + Widget build(BuildContext context) => + // Charts will determine if RTL is enabled by checking the directionality by + // requesting Directionality.of(context). This returns the text direction + // from the closest instance of that encloses the context passed to build + // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This + // means that the directionality widget does not have to directly wrap each + // chart. It is show here as an example only. + // + // By default, when a chart detects RTL: + // Measure axis positions are flipped. Primary measure axis is on the right + // and the secondary measure axis is on the left (when used). + // Domain axis' first domain starts on the right and grows left. + Directionality( textDirection: TextDirection.rtl, child: charts.LineChart( seriesList, defaultRenderer: charts.LineRendererConfig(includeArea: true, stacked: true), animate: animate, - ),); - } + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -201,8 +198,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? blue[1] : blue[0], + colorFn: (sales, _) => sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -212,8 +208,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? red[1] : red[0], + colorFn: (sales, _) => sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -223,8 +218,7 @@ class RTLLineSegments extends StatelessWidget { charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year % 2 == 0 ? green[1] : green[0], + colorFn: (sales, _) => sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -237,7 +231,6 @@ class RTLLineSegments extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/segments.dart b/charts_flutter/example/lib/line_chart/segments.dart index 3ae308cb5..4afd9b6cc 100644 --- a/charts_flutter/example/lib/line_chart/segments.dart +++ b/charts_flutter/example/lib/line_chart/segments.dart @@ -99,7 +99,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Color Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? blue[1] : blue[0], + sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -110,7 +110,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? red[1] : red[0], + sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -121,7 +121,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? green[1] : green[0], + sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -184,7 +184,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Color Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? blue[1] : blue[0], + sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -195,7 +195,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? red[1] : red[0], + sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -206,7 +206,7 @@ class SegmentsLineChart extends StatelessWidget { id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. colorFn: (sales, _) => - sales.year % 2 == 0 ? green[1] : green[0], + sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, diff --git a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart index caac946e2..da0ecb83e 100644 --- a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart +++ b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart @@ -26,19 +26,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class EndPointsAxisTimeSeriesChart extends StatelessWidget { - - const EndPointsAxisTimeSeriesChart(this.seriesList, {super.key, this.animate = false}); + const EndPointsAxisTimeSeriesChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory EndPointsAxisTimeSeriesChart.withSampleData() => EndPointsAxisTimeSeriesChart( - _createSampleData(), - ); + factory EndPointsAxisTimeSeriesChart.withSampleData() => + EndPointsAxisTimeSeriesChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory EndPointsAxisTimeSeriesChart.withRandomData() => EndPointsAxisTimeSeriesChart(_createRandomData()); + factory EndPointsAxisTimeSeriesChart.withRandomData() => + EndPointsAxisTimeSeriesChart(_createRandomData()); final List> seriesList; final bool animate; @@ -67,14 +69,14 @@ class EndPointsAxisTimeSeriesChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Configures an axis spec that is configured to render one tick at each - // end of the axis range, anchored "inside" the axis. The start tick label - // will be left-aligned with its tick mark, and the end tick label will be - // right-aligned with its tick mark. - domainAxis: const charts.EndPointsTimeAxisSpec(), - ); + seriesList, + animate: animate, + // Configures an axis spec that is configured to render one tick at each + // end of the axis range, anchored "inside" the axis. The start tick label + // will be left-aligned with its tick mark, and the end tick label will be + // right-aligned with its tick mark. + domainAxis: const charts.EndPointsTimeAxisSpec(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -99,7 +101,6 @@ class EndPointsAxisTimeSeriesChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/line_annotation.dart b/charts_flutter/example/lib/time_series_chart/line_annotation.dart index ad59db4a8..ce22d0dcc 100644 --- a/charts_flutter/example/lib/time_series_chart/line_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/line_annotation.dart @@ -31,19 +31,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesLineAnnotationChart extends StatelessWidget { - - const TimeSeriesLineAnnotationChart(this.seriesList, {super.key, this.animate = false}); + const TimeSeriesLineAnnotationChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory TimeSeriesLineAnnotationChart.withSampleData() => TimeSeriesLineAnnotationChart( - _createSampleData(), - ); + factory TimeSeriesLineAnnotationChart.withSampleData() => + TimeSeriesLineAnnotationChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesLineAnnotationChart.withRandomData() => TimeSeriesLineAnnotationChart(_createRandomData()); + factory TimeSeriesLineAnnotationChart.withRandomData() => + TimeSeriesLineAnnotationChart(_createRandomData()); final List> seriesList; final bool animate; @@ -70,16 +72,24 @@ class TimeSeriesLineAnnotationChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ - charts.RangeAnnotation([ - charts.LineAnnotationSegment( - DateTime(2017, 10, 4), charts.RangeAnnotationAxisType.domain, - startLabel: 'Oct 4',), - charts.LineAnnotationSegment( - DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain, - endLabel: 'Oct 15',), - ]), - ],); + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, + animate: animate, + behaviors: [ + charts.RangeAnnotation([ + charts.LineAnnotationSegment( + DateTime(2017, 10, 4), + charts.RangeAnnotationAxisType.domain, + startLabel: 'Oct 4', + ), + charts.LineAnnotationSegment( + DateTime(2017, 10, 15), + charts.RangeAnnotationAxisType.domain, + endLabel: 'Oct 15', + ), + ]), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -103,7 +113,6 @@ class TimeSeriesLineAnnotationChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/range_annotation.dart b/charts_flutter/example/lib/time_series_chart/range_annotation.dart index 493cbd23d..ca94610d7 100644 --- a/charts_flutter/example/lib/time_series_chart/range_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/range_annotation.dart @@ -31,19 +31,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesRangeAnnotationChart extends StatelessWidget { - - const TimeSeriesRangeAnnotationChart(this.seriesList, {super.key, this.animate = false}); + const TimeSeriesRangeAnnotationChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory TimeSeriesRangeAnnotationChart.withSampleData() => TimeSeriesRangeAnnotationChart( - _createSampleData(), - ); + factory TimeSeriesRangeAnnotationChart.withSampleData() => + TimeSeriesRangeAnnotationChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesRangeAnnotationChart.withRandomData() => TimeSeriesRangeAnnotationChart(_createRandomData()); + factory TimeSeriesRangeAnnotationChart.withRandomData() => + TimeSeriesRangeAnnotationChart(_createRandomData()); final List> seriesList; final bool animate; @@ -70,12 +75,19 @@ class TimeSeriesRangeAnnotationChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, animate: animate, behaviors: [ - charts.RangeAnnotation([ - charts.RangeAnnotationSegment(DateTime(2017, 10, 4), - DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain,), - ]), - ],); + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, + animate: animate, + behaviors: [ + charts.RangeAnnotation([ + charts.RangeAnnotationSegment( + DateTime(2017, 10, 4), + DateTime(2017, 10, 15), + charts.RangeAnnotationAxisType.domain, + ), + ]), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -99,7 +111,6 @@ class TimeSeriesRangeAnnotationChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart b/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart index d24c22ba1..363f9cc25 100644 --- a/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart +++ b/charts_flutter/example/lib/time_series_chart/range_annotation_margin.dart @@ -25,19 +25,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesRangeAnnotationMarginChart extends StatelessWidget { - - const TimeSeriesRangeAnnotationMarginChart(this.seriesList, {super.key, this.animate = false}); + const TimeSeriesRangeAnnotationMarginChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory TimeSeriesRangeAnnotationMarginChart.withSampleData() => TimeSeriesRangeAnnotationMarginChart( - _createSampleData(), - ); + factory TimeSeriesRangeAnnotationMarginChart.withSampleData() => + TimeSeriesRangeAnnotationMarginChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesRangeAnnotationMarginChart.withRandomData() => TimeSeriesRangeAnnotationMarginChart(_createRandomData()); + factory TimeSeriesRangeAnnotationMarginChart.withRandomData() => + TimeSeriesRangeAnnotationMarginChart(_createRandomData()); final List> seriesList; final bool animate; @@ -66,21 +71,24 @@ class TimeSeriesRangeAnnotationMarginChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.TimeSeriesChart(seriesList, + Widget build(BuildContext context) => charts.TimeSeriesChart( + seriesList, animate: animate, // Allow enough space in the left and right chart margins for the // annotations. layoutConfig: charts.LayoutConfig( - leftMarginSpec: charts.MarginSpec.fixedPixel(60), - topMarginSpec: charts.MarginSpec.fixedPixel(20), - rightMarginSpec: charts.MarginSpec.fixedPixel(60), - bottomMarginSpec: charts.MarginSpec.fixedPixel(20),), + leftMarginSpec: charts.MarginSpec.fixedPixel(60), + topMarginSpec: charts.MarginSpec.fixedPixel(20), + rightMarginSpec: charts.MarginSpec.fixedPixel(60), + bottomMarginSpec: charts.MarginSpec.fixedPixel(20), + ), behaviors: [ // Define one domain and two measure annotations configured to render // labels in the chart margins. - charts.RangeAnnotation([ - charts.RangeAnnotationSegment( + charts.RangeAnnotation( + [ + charts.RangeAnnotationSegment( DateTime(2017, 10, 4), DateTime(2017, 10, 15), charts.RangeAnnotationAxisType.domain, @@ -89,21 +97,31 @@ class TimeSeriesRangeAnnotationMarginChart extends StatelessWidget { labelAnchor: charts.AnnotationLabelAnchor.end, color: charts.MaterialPalette.gray.shade200, // Override the default vertical direction for domain labels. - labelDirection: charts.AnnotationLabelDirection.horizontal,), - charts.RangeAnnotationSegment( - 15, 20, charts.RangeAnnotationAxisType.measure, + labelDirection: charts.AnnotationLabelDirection.horizontal, + ), + charts.RangeAnnotationSegment( + 15, + 20, + charts.RangeAnnotationAxisType.measure, startLabel: 'M1 Start', endLabel: 'M1 End', labelAnchor: charts.AnnotationLabelAnchor.end, - color: charts.MaterialPalette.gray.shade300,), - charts.RangeAnnotationSegment( - 35, 65, charts.RangeAnnotationAxisType.measure, + color: charts.MaterialPalette.gray.shade300, + ), + charts.RangeAnnotationSegment( + 35, + 65, + charts.RangeAnnotationAxisType.measure, startLabel: 'M2 Start', endLabel: 'M2 End', labelAnchor: charts.AnnotationLabelAnchor.start, - color: charts.MaterialPalette.gray.shade300,), - ], defaultLabelPosition: charts.AnnotationLabelPosition.margin,), - ],); + color: charts.MaterialPalette.gray.shade300, + ), + ], + defaultLabelPosition: charts.AnnotationLabelPosition.margin, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -127,7 +145,6 @@ class TimeSeriesRangeAnnotationMarginChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/simple.dart b/charts_flutter/example/lib/time_series_chart/simple.dart index c1894db41..c6cb230e5 100644 --- a/charts_flutter/example/lib/time_series_chart/simple.dart +++ b/charts_flutter/example/lib/time_series_chart/simple.dart @@ -24,19 +24,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleTimeSeriesChart extends StatelessWidget { - - const SimpleTimeSeriesChart(this.seriesList, {super.key, this.animate = false}); + const SimpleTimeSeriesChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory SimpleTimeSeriesChart.withSampleData() => SimpleTimeSeriesChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleTimeSeriesChart.withRandomData() => SimpleTimeSeriesChart(_createRandomData()); + factory SimpleTimeSeriesChart.withRandomData() => + SimpleTimeSeriesChart(_createRandomData()); final List> seriesList; final bool animate; @@ -65,13 +69,13 @@ class SimpleTimeSeriesChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. - dateTimeFactory: const charts.LocalDateTimeFactory(), - ); + seriesList, + animate: animate, + // Optionally pass in a [DateTimeFactory] used by the chart. The factory + // should create the same type of [DateTime] as the data provided. If none + // specified, the default creates local date time. + dateTimeFactory: const charts.LocalDateTimeFactory(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -96,7 +100,6 @@ class SimpleTimeSeriesChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart index 82d655aa5..defb4bc81 100644 --- a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart @@ -35,19 +35,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesSymbolAnnotationChart extends StatelessWidget { - - const TimeSeriesSymbolAnnotationChart(this.seriesList, {super.key, this.animate = false}); + const TimeSeriesSymbolAnnotationChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory TimeSeriesSymbolAnnotationChart.withSampleData() => TimeSeriesSymbolAnnotationChart( - _createSampleData(), - ); + factory TimeSeriesSymbolAnnotationChart.withSampleData() => + TimeSeriesSymbolAnnotationChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesSymbolAnnotationChart.withRandomData() => TimeSeriesSymbolAnnotationChart(_createRandomData()); + factory TimeSeriesSymbolAnnotationChart.withRandomData() => + TimeSeriesSymbolAnnotationChart(_createRandomData()); final List> seriesList; final bool animate; @@ -57,24 +62,40 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { final myDesktopData = [ TimeSeriesSales( - timeCurrent: DateTime(2017, 9, 19), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 9, 19), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 9, 26), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 9, 26), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 10, 3), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 10, 3), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 10, 10), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 10, 10), + sales: random.nextInt(100), + ), ]; final myTabletData = [ TimeSeriesSales( - timeCurrent: DateTime(2017, 9, 19), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 9, 19), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 9, 26), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 9, 26), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 10, 3), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 10, 3), + sales: random.nextInt(100), + ), TimeSeriesSales( - timeCurrent: DateTime(2017, 10, 10), sales: random.nextInt(100),), + timeCurrent: DateTime(2017, 10, 10), + sales: random.nextInt(100), + ), ]; // Example of a series with two range annotations. A regular point shape @@ -160,19 +181,20 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Custom renderer configuration for the point series. - customSeriesRenderers: [ - charts.SymbolAnnotationRendererConfig( + seriesList, + animate: animate, + // Custom renderer configuration for the point series. + customSeriesRenderers: [ + charts.SymbolAnnotationRendererConfig( // ID used to link series to this renderer. - customRendererId: 'customSymbolAnnotation',), - ], - // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. - dateTimeFactory: const charts.LocalDateTimeFactory(), - ); + customRendererId: 'customSymbolAnnotation', + ), + ], + // Optionally pass in a [DateTimeFactory] used by the chart. The factory + // should create the same type of [DateTime] as the data provided. + // If none specified, the default creates local date time. + dateTimeFactory: const charts.LocalDateTimeFactory(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -279,7 +301,6 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales({ required this.timeCurrent, this.timePrevious, diff --git a/charts_flutter/example/pubspec.yaml b/charts_flutter/example/pubspec.yaml index 44a76f698..33404beb4 100644 --- a/charts_flutter/example/pubspec.yaml +++ b/charts_flutter/example/pubspec.yaml @@ -6,9 +6,9 @@ environment: flutter: '>=3.0.0 <4.0.0' dependencies: + cupertino_icons: ^1.0.8 nimble_charts: path: ../ - cupertino_icons: ^1.0.8 flutter: sdk: flutter flutter_web_plugins: From b40d1bd8f61520b2f154b264e6116ba6f89c9aad Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Wed, 18 Sep 2024 06:02:14 +1000 Subject: [PATCH 3/9] fixes --- .../example/lib/a11y/a11y_gallery.dart | 16 +- .../a11y/domain_a11y_explore_bar_chart.dart | 9 +- charts_flutter/example/lib/app_config.dart | 15 +- .../example/lib/axes/axes_gallery.dart | 200 +++++++------- .../lib/axes/numeric_initial_viewport.dart | 2 +- .../lib/axes/statically_provided_ticks.dart | 32 +-- .../example/lib/bar_chart/spark_bar.dart | 48 ++-- .../lib/behaviors/initial_hint_animation.dart | 56 ++-- .../lib/behaviors/initial_selection.dart | 48 ++-- .../lib/behaviors/percent_of_domain.dart | 40 +-- .../percent_of_domain_by_category.dart | 50 ++-- .../lib/behaviors/percent_of_series.dart | 37 +-- .../behaviors/selection_callback_example.dart | 40 +-- .../behaviors/selection_line_highlight.dart | 53 ++-- ...selection_line_highlight_custom_shape.dart | 62 +++-- .../selection_scatter_plot_highlight.dart | 196 ++++++++++---- .../example/lib/behaviors/slider.dart | 111 ++++---- .../sliding_viewport_on_selection.dart | 49 ++-- .../lib/combo_chart/combo_gallery.dart | 62 ++--- .../lib/combo_chart/date_time_line_point.dart | 2 +- .../lib/combo_chart/numeric_line_point.dart | 48 ++-- .../lib/combo_chart/ordinal_bar_line.dart | 92 ++++--- .../lib/combo_chart/scatter_plot_line.dart | 63 +++-- .../example/lib/gallery_scaffold.dart | 47 ++-- .../example/lib/i18n/i18n_gallery.dart | 50 ++-- .../example/lib/i18n/rtl_bar_chart.dart | 19 +- .../example/lib/i18n/rtl_line_chart.dart | 17 +- .../example/lib/i18n/rtl_series_legend.dart | 30 ++- .../lib/legends/datum_legend_options.dart | 74 ++--- .../legends/datum_legend_with_measures.dart | 90 +++---- .../legends/default_hidden_series_legend.dart | 39 +-- .../lib/legends/legend_custom_symbol.dart | 43 +-- .../example/lib/legends/legends_gallery.dart | 104 +++---- .../lib/legends/series_legend_options.dart | 73 +++-- .../legends/series_legend_with_measures.dart | 93 ++++--- .../lib/legends/simple_datum_legend.dart | 21 +- .../lib/legends/simple_series_legend.dart | 23 +- .../lib/line_chart/animation_zoom.dart | 22 +- .../example/lib/line_chart/area_and_line.dart | 24 +- .../example/lib/line_chart/dash_pattern.dart | 15 +- .../lib/line_chart/line_annotation.dart | 65 +++-- .../example/lib/line_chart/line_gallery.dart | 159 +++++------ .../example/lib/line_chart/points.dart | 15 +- .../lib/line_chart/range_annotation.dart | 72 +++-- .../line_chart/range_annotation_margin.dart | 63 +++-- .../example/lib/line_chart/segments.dart | 33 +-- .../example/lib/line_chart/simple.dart | 12 +- .../example/lib/line_chart/simple_nulls.dart | 15 +- .../example/lib/line_chart/stacked_area.dart | 21 +- .../line_chart/stacked_area_custom_color.dart | 24 +- .../lib/line_chart/stacked_area_nulls.dart | 21 +- charts_flutter/example/lib/main.dart | 3 +- .../example/lib/pie_chart/auto_label.dart | 18 +- .../example/lib/pie_chart/donut.dart | 12 +- .../example/lib/pie_chart/gauge.dart | 15 +- .../example/lib/pie_chart/outside_label.dart | 30 ++- .../example/lib/pie_chart/partial_pie.dart | 6 +- .../example/lib/pie_chart/pie_gallery.dart | 80 +++--- .../example/lib/pie_chart/simple.dart | 12 +- .../scatter_plot_chart/animation_zoom.dart | 24 +- .../scatter_plot_chart/bucketing_axis.dart | 255 ++++++++++-------- .../scatter_plot_chart/comparison_points.dart | 53 ++-- .../scatter_plot_gallery.dart | 65 ++--- .../lib/scatter_plot_chart/shapes.dart | 184 ++++++++++--- .../lib/scatter_plot_chart/simple.dart | 15 +- .../confidence_interval.dart | 29 +- .../time_series_chart/symbol_annotation.dart | 2 +- .../time_series_gallery.dart | 100 +++---- .../time_series_chart/with_bar_renderer.dart | 32 ++- 69 files changed, 1987 insertions(+), 1563 deletions(-) diff --git a/charts_flutter/example/lib/a11y/a11y_gallery.dart b/charts_flutter/example/lib/a11y/a11y_gallery.dart index 51f8408e7..c743f043f 100644 --- a/charts_flutter/example/lib/a11y/a11y_gallery.dart +++ b/charts_flutter/example/lib/a11y/a11y_gallery.dart @@ -17,11 +17,11 @@ import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.accessibility), - title: 'Screen reader enabled bar chart', - subtitle: 'Requires TalkBack or Voiceover turned on to work. ' - 'Bar chart with domain selection explore mode behavior.', - childBuilder: DomainA11yExploreBarChart.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.accessibility), + title: 'Screen reader enabled bar chart', + subtitle: 'Requires TalkBack or Voiceover turned on to work. ' + 'Bar chart with domain selection explore mode behavior.', + childBuilder: DomainA11yExploreBarChart.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart index 62f3e36c5..35c8d34e7 100644 --- a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart +++ b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart @@ -108,11 +108,12 @@ class DomainA11yExploreBarChart extends StatelessWidget { /// domain, it vocalizes the series display name and the measure and a /// description of that measure. String vocalizeDomainAndMeasures(List seriesDatums) { - final buffer = StringBuffer().. + final buffer = StringBuffer() + .. - // The datum's type in this case is [OrdinalSales]. - // So we can access year and sales information here. - write(seriesDatums.first.datum.year); + // The datum's type in this case is [OrdinalSales]. + // So we can access year and sales information here. + write(seriesDatums.first.datum.year); for (final seriesDatum in seriesDatums) { final series = seriesDatum.series; diff --git a/charts_flutter/example/lib/app_config.dart b/charts_flutter/example/lib/app_config.dart index 0eee0d66f..b6c74fbe6 100644 --- a/charts_flutter/example/lib/app_config.dart +++ b/charts_flutter/example/lib/app_config.dart @@ -17,7 +17,6 @@ import 'package:flutter/material.dart'; /// A particular configuration of the app. class AppConfig { - AppConfig({ required this.appName, required this.appLink, @@ -30,10 +29,10 @@ class AppConfig { /// The default configuration of the app. AppConfig get defaultConfig => AppConfig( - appName: 'Charts Gallery', - appLink: '', - theme: ThemeData( - brightness: Brightness.light, - primarySwatch: Colors.lightBlue, - ), - ); + appName: 'Charts Gallery', + appLink: '', + theme: ThemeData( + brightness: Brightness.light, + primarySwatch: Colors.lightBlue, + ), + ); diff --git a/charts_flutter/example/lib/axes/axes_gallery.dart b/charts_flutter/example/lib/axes/axes_gallery.dart index 4797046ee..178dcce2d 100644 --- a/charts_flutter/example/lib/axes/axes_gallery.dart +++ b/charts_flutter/example/lib/axes/axes_gallery.dart @@ -33,102 +33,104 @@ import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Bar chart with Secondary Measure Axis', - subtitle: 'Bar chart with a series using a secondary measure axis', - childBuilder: BarChartWithSecondaryAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Bar chart with Secondary Measure Axis only', - subtitle: 'Bar chart with both series using secondary measure axis', - childBuilder: BarChartWithSecondaryAxisOnly.withRandomData, - ), - GalleryScaffold( - listTileIcon: Transform.rotate( - angle: 1.5708, child: const Icon(Icons.insert_chart),), - title: 'Horizontal bar chart with Secondary Measure Axis', - subtitle: - 'Horizontal Bar chart with a series using secondary measure axis', - childBuilder: HorizontalBarChartWithSecondaryAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Short Ticks Axis', - subtitle: 'Bar chart with the primary measure axis having short ticks', - childBuilder: ShortTickLengthAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Custom Axis Fonts', - subtitle: 'Bar chart with custom axis font size and color', - childBuilder: CustomFontSizeAndColor.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Label Alignment Axis', - subtitle: 'Bar chart with custom measure axis label alignments', - childBuilder: MeasureAxisLabelAlignment.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'No Axis', - subtitle: 'Bar chart with only the axis line drawn', - childBuilder: HiddenTicksAndLabelsAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Statically Provided Ticks', - subtitle: 'Bar chart with statically provided ticks', - childBuilder: StaticallyProvidedTicks.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Custom Formatter', - subtitle: 'Timeseries with custom domain and measure tick formatters', - childBuilder: CustomAxisTickFormatters.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Custom Tick Count', - subtitle: 'Timeseries with custom measure axis tick count', - childBuilder: CustomMeasureTickCount.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Integer Measure Ticks', - subtitle: 'Timeseries with only whole number measure axis ticks', - childBuilder: IntegerOnlyMeasureAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Non-zero bound Axis', - subtitle: 'Timeseries with measure axis that does not include zero', - childBuilder: NonzeroBoundMeasureAxis.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Ordinal axis with initial viewport', - subtitle: 'Single series with initial viewport', - childBuilder: OrdinalInitialViewport.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Numeric axis with initial viewport', - subtitle: 'Initial viewport is set to a subset of the data', - childBuilder: NumericInitialViewport.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Gridline dash pattern', - subtitle: 'Timeseries with measure gridlines that have a dash pattern', - childBuilder: GridlineDashPattern.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Disjoint Measure Axes', - subtitle: 'Line chart with disjoint measure axes', - childBuilder: DisjointMeasureAxisLineChart.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Bar chart with Secondary Measure Axis', + subtitle: 'Bar chart with a series using a secondary measure axis', + childBuilder: BarChartWithSecondaryAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Bar chart with Secondary Measure Axis only', + subtitle: 'Bar chart with both series using secondary measure axis', + childBuilder: BarChartWithSecondaryAxisOnly.withRandomData, + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: 'Horizontal bar chart with Secondary Measure Axis', + subtitle: + 'Horizontal Bar chart with a series using secondary measure axis', + childBuilder: HorizontalBarChartWithSecondaryAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Short Ticks Axis', + subtitle: 'Bar chart with the primary measure axis having short ticks', + childBuilder: ShortTickLengthAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Custom Axis Fonts', + subtitle: 'Bar chart with custom axis font size and color', + childBuilder: CustomFontSizeAndColor.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Label Alignment Axis', + subtitle: 'Bar chart with custom measure axis label alignments', + childBuilder: MeasureAxisLabelAlignment.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'No Axis', + subtitle: 'Bar chart with only the axis line drawn', + childBuilder: HiddenTicksAndLabelsAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Statically Provided Ticks', + subtitle: 'Bar chart with statically provided ticks', + childBuilder: StaticallyProvidedTicks.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Custom Formatter', + subtitle: 'Timeseries with custom domain and measure tick formatters', + childBuilder: CustomAxisTickFormatters.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Custom Tick Count', + subtitle: 'Timeseries with custom measure axis tick count', + childBuilder: CustomMeasureTickCount.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Integer Measure Ticks', + subtitle: 'Timeseries with only whole number measure axis ticks', + childBuilder: IntegerOnlyMeasureAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Non-zero bound Axis', + subtitle: 'Timeseries with measure axis that does not include zero', + childBuilder: NonzeroBoundMeasureAxis.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Ordinal axis with initial viewport', + subtitle: 'Single series with initial viewport', + childBuilder: OrdinalInitialViewport.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Numeric axis with initial viewport', + subtitle: 'Initial viewport is set to a subset of the data', + childBuilder: NumericInitialViewport.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Gridline dash pattern', + subtitle: 'Timeseries with measure gridlines that have a dash pattern', + childBuilder: GridlineDashPattern.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Disjoint Measure Axes', + subtitle: 'Line chart with disjoint measure axes', + childBuilder: DisjointMeasureAxisLineChart.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart index 57bcb19fb..3edfdfbdd 100644 --- a/charts_flutter/example/lib/axes/numeric_initial_viewport.dart +++ b/charts_flutter/example/lib/axes/numeric_initial_viewport.dart @@ -20,7 +20,7 @@ /// /// In this example, the series list has numeric data from 0 to 10, but we /// want to show from 3 to 7. -/// We can do this by specifying an [charts.NumericExtents] in +/// We can do this by specifying an [charts.NumericExtents] in /// [charts.NumericAxisSpec]. library; diff --git a/charts_flutter/example/lib/axes/statically_provided_ticks.dart b/charts_flutter/example/lib/axes/statically_provided_ticks.dart index 00b2e3c2a..ce9d7bf9f 100644 --- a/charts_flutter/example/lib/axes/statically_provided_ticks.dart +++ b/charts_flutter/example/lib/axes/statically_provided_ticks.dart @@ -36,18 +36,19 @@ import 'package:nimble_charts/flutter.dart' as charts; /// For datetime axis, the [charts.StaticDateTimeTickProviderSpec] can be used by /// passing in a list of ticks defined with [charts.TickSpec] of datetime. class StaticallyProvidedTicks extends StatelessWidget { - - const StaticallyProvidedTicks(this.seriesList, {super.key, this.animate = false}); + const StaticallyProvidedTicks(this.seriesList, + {super.key, this.animate = false}); factory StaticallyProvidedTicks.withSampleData() => StaticallyProvidedTicks( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StaticallyProvidedTicks.withRandomData() => StaticallyProvidedTicks(_createRandomData()); + factory StaticallyProvidedTicks.withRandomData() => + StaticallyProvidedTicks(_createRandomData()); final List> seriesList; final bool animate; @@ -78,13 +79,15 @@ class StaticallyProvidedTicks extends StatelessWidget { // Create the ticks to be used the domain axis. final staticTicks = >[ const charts.TickSpec( - // Value must match the domain value. - '2014', - // Optional label for this tick, defaults to domain value if not set. - label: 'Year 2014', - // The styling for this tick. - style: charts.TextStyleSpec( - color: charts.Color(r: 0x4C, g: 0xAF, b: 0x50),),), + // Value must match the domain value. + '2014', + // Optional label for this tick, defaults to domain value if not set. + label: 'Year 2014', + // The styling for this tick. + style: charts.TextStyleSpec( + color: charts.Color(r: 0x4C, g: 0xAF, b: 0x50), + ), + ), // If no text style is specified - the style from renderSpec will be used // if one is specified. const charts.TickSpec('2015'), @@ -96,8 +99,8 @@ class StaticallyProvidedTicks extends StatelessWidget { seriesList, animate: animate, domainAxis: charts.OrdinalAxisSpec( - tickProviderSpec: - charts.StaticOrdinalTickProviderSpec(staticTicks),), + tickProviderSpec: charts.StaticOrdinalTickProviderSpec(staticTicks), + ), ); } @@ -123,7 +126,6 @@ class StaticallyProvidedTicks extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/bar_chart/spark_bar.dart b/charts_flutter/example/lib/bar_chart/spark_bar.dart index 435ae0cba..e2b2aaf5c 100644 --- a/charts_flutter/example/lib/bar_chart/spark_bar.dart +++ b/charts_flutter/example/lib/bar_chart/spark_bar.dart @@ -24,12 +24,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a Spark Bar by hiding both axis, reducing the chart margins. class SparkBar extends StatelessWidget { - const SparkBar(this.seriesList, {super.key, this.animate = false}); factory SparkBar.withSampleData() => SparkBar( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -70,33 +69,35 @@ class SparkBar extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - - /// Assign a custom style for the measure axis. - /// - /// The NoneRenderSpec only draws an axis line (and even that can be - /// hidden with showAxisLine=false). - primaryMeasureAxis: - const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()), - - /// This is an OrdinalAxisSpec to match up with BarChart's default - /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for - /// other charts). - domainAxis: const charts.OrdinalAxisSpec( + seriesList, + animate: animate, + + /// Assign a custom style for the measure axis. + /// + /// The NoneRenderSpec only draws an axis line (and even that can be + /// hidden with showAxisLine=false). + primaryMeasureAxis: + const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()), + + /// This is an OrdinalAxisSpec to match up with BarChart's default + /// ordinal domain axis (use NumericAxisSpec or DateTimeAxisSpec for + /// other charts). + domainAxis: const charts.OrdinalAxisSpec( // Make sure that we draw the domain axis line. showAxisLine: true, // But don't draw anything else. - renderSpec: charts.NoneRenderSpec(),), + renderSpec: charts.NoneRenderSpec(), + ), - // With a spark chart we likely don't want large chart margins. - // 1px is the smallest we can make each margin. - layoutConfig: charts.LayoutConfig( + // With a spark chart we likely don't want large chart margins. + // 1px is the smallest we can make each margin. + layoutConfig: charts.LayoutConfig( leftMarginSpec: charts.MarginSpec.fixedPixel(0), topMarginSpec: charts.MarginSpec.fixedPixel(0), rightMarginSpec: charts.MarginSpec.fixedPixel(0), - bottomMarginSpec: charts.MarginSpec.fixedPixel(0),), - ); + bottomMarginSpec: charts.MarginSpec.fixedPixel(0), + ), + ); /// Create series list with single series static List> _createSampleData() { @@ -127,7 +128,6 @@ class SparkBar extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart index a0b8a8866..577b87e53 100644 --- a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart +++ b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart @@ -42,7 +42,6 @@ /// the right until 2018 is the first value in the viewport. library; - // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; @@ -51,19 +50,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class InitialHintAnimation extends StatelessWidget { - - const InitialHintAnimation(this.seriesList, {super.key, this.animate = false}); + const InitialHintAnimation(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory InitialHintAnimation.withSampleData() => InitialHintAnimation( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory InitialHintAnimation.withRandomData() => InitialHintAnimation(_createRandomData()); + factory InitialHintAnimation.withRandomData() => + InitialHintAnimation(_createRandomData()); final List> seriesList; final bool animate; @@ -105,27 +105,28 @@ class InitialHintAnimation extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - // Optionally turn off the animation that animates values up from the - // bottom of the domain axis. If animation is on, the bars will animate up - // and then animate to the final viewport. - animationDuration: Duration.zero, - // Set the initial viewport by providing a new AxisSpec with the - // desired viewport: a starting domain and the data size. - domainAxis: charts.OrdinalAxisSpec( - viewport: charts.OrdinalViewport('2018', 4),), - behaviors: [ - // Add this behavior to show initial hint animation that will pan to the - // final desired viewport. - // The duration of the animation can be adjusted by pass in - // [hintDuration]. By default this is 3000ms. - charts.InitialHintBehavior(maxHintTranslate: 4), - // Optionally add a pan or pan and zoom behavior. - // If pan/zoom is not added, the viewport specified remains the viewport - charts.PanAndZoomBehavior(), - ], - ); + seriesList, + animate: animate, + // Optionally turn off the animation that animates values up from the + // bottom of the domain axis. If animation is on, the bars will animate up + // and then animate to the final viewport. + animationDuration: Duration.zero, + // Set the initial viewport by providing a new AxisSpec with the + // desired viewport: a starting domain and the data size. + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4), + ), + behaviors: [ + // Add this behavior to show initial hint animation that will pan to the + // final desired viewport. + // The duration of the animation can be adjusted by pass in + // [hintDuration]. By default this is 3000ms. + charts.InitialHintBehavior(maxHintTranslate: 4), + // Optionally add a pan or pan and zoom behavior. + // If pan/zoom is not added, the viewport specified remains the viewport + charts.PanAndZoomBehavior(), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -163,7 +164,6 @@ class InitialHintAnimation extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/initial_selection.dart b/charts_flutter/example/lib/behaviors/initial_selection.dart index 61a2a424d..95fccc4f3 100644 --- a/charts_flutter/example/lib/behaviors/initial_selection.dart +++ b/charts_flutter/example/lib/behaviors/initial_selection.dart @@ -25,7 +25,6 @@ /// that updates the selection. library; - // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; @@ -34,19 +33,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class InitialSelection extends StatelessWidget { - const InitialSelection(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with initial selection behavior. factory InitialSelection.withSampleData() => InitialSelection( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory InitialSelection.withRandomData() => InitialSelection(_createRandomData()); + factory InitialSelection.withRandomData() => + InitialSelection(_createRandomData()); final List> seriesList; final bool animate; @@ -75,24 +74,26 @@ class InitialSelection extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - behaviors: [ - // Initial selection can be configured by passing in: - // - // A list of datum config, specified with series ID and domain value. - // A list of series config, which is a list of series ID(s). - // - // Initial selection can be applied to any chart type. - // - // [BarChart] by default includes behaviors [SelectNearest] and - // [DomainHighlighter]. So this behavior shows the initial selection - // highlighted and when another datum is tapped, the selection changes. - charts.InitialSelection(selectedDataConfig: [ - charts.SeriesDatumConfig('Sales', '2016'), - ],), - ], - ); + seriesList, + animate: animate, + behaviors: [ + // Initial selection can be configured by passing in: + // + // A list of datum config, specified with series ID and domain value. + // A list of series config, which is a list of series ID(s). + // + // Initial selection can be applied to any chart type. + // + // [BarChart] by default includes behaviors [SelectNearest] and + // [DomainHighlighter]. So this behavior shows the initial selection + // highlighted and when another datum is tapped, the selection changes. + charts.InitialSelection( + selectedDataConfig: [ + charts.SeriesDatumConfig('Sales', '2016'), + ], + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -117,7 +118,6 @@ class InitialSelection extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/percent_of_domain.dart b/charts_flutter/example/lib/behaviors/percent_of_domain.dart index 3768cfd73..e5bf856e6 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_domain.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_domain.dart @@ -26,19 +26,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfDomainBarChart extends StatelessWidget { - - const PercentOfDomainBarChart(this.seriesList, {super.key, this.animate = false}); + const PercentOfDomainBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a stacked [charts.BarChart] with sample data and no transition. factory PercentOfDomainBarChart.withSampleData() => PercentOfDomainBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfDomainBarChart.withRandomData() => PercentOfDomainBarChart(_createRandomData()); + factory PercentOfDomainBarChart.withRandomData() => + PercentOfDomainBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -92,19 +96,18 @@ class PercentOfDomainBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.stacked, - // Configures a [PercentInjector] behavior that will calculate measure - // values as the percentage of the total of all data that shares a - // domain value. - behaviors: [ - charts.PercentInjector( - ,), - ], - // Configure the axis spec to show percentage values. - primaryMeasureAxis: charts.PercentAxisSpec(), - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.stacked, + // Configures a [PercentInjector] behavior that will calculate measure + // values as the percentage of the total of all data that shares a + // domain value. + behaviors: [ + charts.PercentInjector(), + ], + // Configure the axis spec to show percentage values. + primaryMeasureAxis: charts.PercentAxisSpec(), + ); /// Create series list with multiple series static List> _createSampleData() { @@ -154,7 +157,6 @@ class PercentOfDomainBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart index 6001e4e16..111e93c55 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart @@ -27,18 +27,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfDomainByCategoryBarChart extends StatelessWidget { + const PercentOfDomainByCategoryBarChart(this.seriesList, + {super.key, this.animate = false}); - const PercentOfDomainByCategoryBarChart(this.seriesList, {super.key, this.animate = false}); - - factory PercentOfDomainByCategoryBarChart.withSampleData() => PercentOfDomainByCategoryBarChart( - createSampleData(), - ); + factory PercentOfDomainByCategoryBarChart.withSampleData() => + PercentOfDomainByCategoryBarChart( + createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfDomainByCategoryBarChart.withRandomData() => PercentOfDomainByCategoryBarChart(_createRandomData()); + factory PercentOfDomainByCategoryBarChart.withRandomData() => + PercentOfDomainByCategoryBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -137,23 +139,24 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.groupedStacked, - // Configures a [PercentInjector] behavior that will calculate measure - // values as the percentage of the total of all data that shares both a - // domain and a series category. - // - // We use this option on a grouped stacked bar chart to ensure that the - // total value for each bar stack is 100%. A stacked bar chart that does - // not group by series category would use the "domain" option. - behaviors: [ - charts.PercentInjector( - totalType: charts.PercentInjectorTotalType.domainBySeriesCategory,), - ], - // Configure the axis spec to show percentage values. - primaryMeasureAxis: charts.PercentAxisSpec(), - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.groupedStacked, + // Configures a [PercentInjector] behavior that will calculate measure + // values as the percentage of the total of all data that shares both a + // domain and a series category. + // + // We use this option on a grouped stacked bar chart to ensure that the + // total value for each bar stack is 100%. A stacked bar chart that does + // not group by series category would use the "domain" option. + behaviors: [ + charts.PercentInjector( + totalType: charts.PercentInjectorTotalType.domainBySeriesCategory, + ), + ], + // Configure the axis spec to show percentage values. + primaryMeasureAxis: charts.PercentAxisSpec(), + ); /// Create series list with multiple series static List> createSampleData() { @@ -248,7 +251,6 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/percent_of_series.dart b/charts_flutter/example/lib/behaviors/percent_of_series.dart index 01b4f981b..155184ad6 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_series.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_series.dart @@ -24,19 +24,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfSeriesBarChart extends StatelessWidget { - - const PercentOfSeriesBarChart(this.seriesList, {super.key, this.animate = false}); + const PercentOfSeriesBarChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a stacked [charts.BarChart] with sample data and no transition. factory PercentOfSeriesBarChart.withSampleData() => PercentOfSeriesBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PercentOfSeriesBarChart.withRandomData() => PercentOfSeriesBarChart(_createRandomData()); + factory PercentOfSeriesBarChart.withRandomData() => + PercentOfSeriesBarChart(_createRandomData()); final List> seriesList; final bool animate; @@ -68,18 +69,19 @@ class PercentOfSeriesBarChart extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Configures a [PercentInjector] behavior that will calculate measure - // values as the percentage of the total of all data in its series. - behaviors: [ - charts.PercentInjector( - totalType: charts.PercentInjectorTotalType.series,), - ], - // Configure the axis spec to show percentage values. - primaryMeasureAxis: charts.PercentAxisSpec(), - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Configures a [PercentInjector] behavior that will calculate measure + // values as the percentage of the total of all data in its series. + behaviors: [ + charts.PercentInjector( + totalType: charts.PercentInjectorTotalType.series, + ), + ], + // Configure the axis spec to show percentage values. + primaryMeasureAxis: charts.PercentAxisSpec(), + ); /// Create series list with multiple series static List> _createSampleData() { @@ -107,7 +109,6 @@ class PercentOfSeriesBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_callback_example.dart b/charts_flutter/example/lib/behaviors/selection_callback_example.dart index 453da3d28..4f1b4f07f 100644 --- a/charts_flutter/example/lib/behaviors/selection_callback_example.dart +++ b/charts_flutter/example/lib/behaviors/selection_callback_example.dart @@ -38,19 +38,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionCallbackExample extends StatefulWidget { - - const SelectionCallbackExample(this.seriesList, {super.key, this.animate = false}); + const SelectionCallbackExample(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory SelectionCallbackExample.withSampleData() => SelectionCallbackExample( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionCallbackExample.withRandomData() => SelectionCallbackExample(_createRandomData()); + factory SelectionCallbackExample.withRandomData() => + SelectionCallbackExample(_createRandomData()); final List> seriesList; final bool animate; @@ -164,23 +165,27 @@ class _SelectionCallbackState extends State { // The children consist of a Chart and Text widgets below to hold the info. final children = [ SizedBox( - height: 150, - child: charts.TimeSeriesChart( - widget.seriesList, - animate: widget.animate, - selectionModels: [ - charts.SelectionModelConfig( - changedListener: _onSelectionChanged, - ), - ], - ),), + height: 150, + child: charts.TimeSeriesChart( + widget.seriesList, + animate: widget.animate, + selectionModels: [ + charts.SelectionModelConfig( + changedListener: _onSelectionChanged, + ), + ], + ), + ), ]; // If there is a selection, then include the details. if (_time != null) { - children.add(Padding( + children.add( + Padding( padding: const EdgeInsets.only(top: 5), - child: Text(_time.toString()),),); + child: Text(_time.toString()), + ), + ); } _measures.forEach((series, value) { children.add(Text('$series: $value')); @@ -192,7 +197,6 @@ class _SelectionCallbackState extends State { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart index 3ff2c0b9f..75374d4f7 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart @@ -20,19 +20,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionLineHighlight extends StatelessWidget { - - const SelectionLineHighlight(this.seriesList, {super.key, this.animate = false}); + const SelectionLineHighlight(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory SelectionLineHighlight.withSampleData() => SelectionLineHighlight( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionLineHighlight.withRandomData() => SelectionLineHighlight(_createRandomData()); + factory SelectionLineHighlight.withRandomData() => + SelectionLineHighlight(_createRandomData()); final List> seriesList; final bool animate; @@ -70,27 +71,32 @@ class SelectionLineHighlight extends StatelessWidget { // // As an alternative, [defaultInteractions] can be set to true to include // the default chart interactions, including a LinePointHighlighter. - return charts.LineChart(seriesList, animate: animate, behaviors: [ - // Optional - Configures a [LinePointHighlighter] behavior with a - // vertical follow line. A vertical follow line is included by - // default, but is shown here as an example configuration. - // - // By default, the line has default dash pattern of [1,3]. This can be - // set by providing a [dashPattern] or it can be turned off by passing in - // an empty list. An empty list is necessary because passing in a null - // value will be treated the same as not passing in a value at all. - charts.LinePointHighlighter( + return charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + // Optional - Configures a [LinePointHighlighter] behavior with a + // vertical follow line. A vertical follow line is included by + // default, but is shown here as an example configuration. + // + // By default, the line has default dash pattern of [1,3]. This can be + // set by providing a [dashPattern] or it can be turned off by passing in + // an empty list. An empty list is necessary because passing in a null + // value will be treated the same as not passing in a value at all. + charts.LinePointHighlighter( showHorizontalFollowLine: charts.LinePointHighlighterFollowLineType.none, showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest,), - // Optional - By default, select nearest is configured to trigger - // with tap so that a user can have pan/zoom behavior and line point - // highlighter. Changing the trigger to tap and drag allows the - // highlighter to follow the dragging gesture but it is not - // recommended to be used when pan/zoom behavior is enabled. - charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), - ],); + charts.LinePointHighlighterFollowLineType.nearest, + ), + // Optional - By default, select nearest is configured to trigger + // with tap so that a user can have pan/zoom behavior and line point + // highlighter. Changing the trigger to tap and drag allows the + // highlighter to follow the dragging gesture but it is not + // recommended to be used when pan/zoom behavior is enabled. + charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), + ], + ); } /// Create one series with sample hard coded data. @@ -115,7 +121,6 @@ class SelectionLineHighlight extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart index 3740682d6..09ebe493d 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart @@ -20,19 +20,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionLineHighlightCustomShape extends StatelessWidget { - - const SelectionLineHighlightCustomShape(this.seriesList, {super.key, this.animate = false}); + const SelectionLineHighlightCustomShape(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. - factory SelectionLineHighlightCustomShape.withSampleData() => SelectionLineHighlightCustomShape( - _createSampleData(), - ); + factory SelectionLineHighlightCustomShape.withSampleData() => + SelectionLineHighlightCustomShape( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionLineHighlightCustomShape.withRandomData() => SelectionLineHighlightCustomShape(_createRandomData()); + factory SelectionLineHighlightCustomShape.withRandomData() => + SelectionLineHighlightCustomShape(_createRandomData()); final List> seriesList; final bool animate; @@ -69,31 +71,36 @@ class SelectionLineHighlightCustomShape extends StatelessWidget { // // As an alternative, [defaultInteractions] can be set to true to include // the default chart interactions, including a LinePointHighlighter. - return charts.LineChart(seriesList, animate: animate, behaviors: [ - // Optional - Configures a [LinePointHighlighter] behavior with a - // vertical follow line. A vertical follow line is included by - // default, but is shown here as an example configuration. - // - // By default, the line has default dash pattern of [1,3]. This can be - // set by providing a [dashPattern] or it can be turned off by passing in - // an empty list. An empty list is necessary because passing in a null - // value will be treated the same as not passing in a value at all. - // - // The symbol renderer is configured to render a hollow shape, for - // demonstration. - charts.LinePointHighlighter( + return charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + // Optional - Configures a [LinePointHighlighter] behavior with a + // vertical follow line. A vertical follow line is included by + // default, but is shown here as an example configuration. + // + // By default, the line has default dash pattern of [1,3]. This can be + // set by providing a [dashPattern] or it can be turned off by passing in + // an empty list. An empty list is necessary because passing in a null + // value will be treated the same as not passing in a value at all. + // + // The symbol renderer is configured to render a hollow shape, for + // demonstration. + charts.LinePointHighlighter( showHorizontalFollowLine: charts.LinePointHighlighterFollowLineType.none, showVerticalFollowLine: charts.LinePointHighlighterFollowLineType.nearest, - symbolRenderer: charts.RectSymbolRenderer(isSolid: false),), - // Optional - By default, select nearest is configured to trigger - // with tap so that a user can have pan/zoom behavior and line point - // highlighter. Changing the trigger to tap and drag allows the - // highlighter to follow the dragging gesture but it is not - // recommended to be used when pan/zoom behavior is enabled. - charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), - ],); + symbolRenderer: charts.RectSymbolRenderer(isSolid: false), + ), + // Optional - By default, select nearest is configured to trigger + // with tap so that a user can have pan/zoom behavior and line point + // highlighter. Changing the trigger to tap and drag allows the + // highlighter to follow the dragging gesture but it is not + // recommended to be used when pan/zoom behavior is enabled. + charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), + ], + ); } /// Create one series with sample hard coded data. @@ -118,7 +125,6 @@ class SelectionLineHighlightCustomShape extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart index 46c13369f..b5ad9212d 100644 --- a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart @@ -41,19 +41,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionScatterPlotHighlight extends StatelessWidget { - - const SelectionScatterPlotHighlight(this.seriesList, {super.key, this.animate = false}); + const SelectionScatterPlotHighlight(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. - factory SelectionScatterPlotHighlight.withSampleData() => SelectionScatterPlotHighlight( - _createSampleData(), - ); + factory SelectionScatterPlotHighlight.withSampleData() => + SelectionScatterPlotHighlight( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SelectionScatterPlotHighlight.withRandomData() => SelectionScatterPlotHighlight(_createRandomData()); + factory SelectionScatterPlotHighlight.withRandomData() => + SelectionScatterPlotHighlight(_createRandomData()); final List> seriesList; final bool animate; @@ -64,33 +66,105 @@ class SelectionScatterPlotHighlight extends StatelessWidget { double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final data = [ - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + 'circle', + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow circle, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + 'circle', + charts.MaterialPalette.white, + 2, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + 'circle', + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow circle, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + 'circle', + charts.MaterialPalette.white, + 2, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow square, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, null, charts.MaterialPalette.white, 2,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + null, + charts.MaterialPalette.white, + 2, + ), ]; const maxMeasure = 100; @@ -119,7 +193,9 @@ class SelectionScatterPlotHighlight extends StatelessWidget { ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (index) => data[index].shape,) + charts.pointSymbolRendererFnKey, + (index) => data[index].shape, + ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; @@ -127,7 +203,8 @@ class SelectionScatterPlotHighlight extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, animate: animate, behaviors: [ // Optional - Configures a [LinePointHighlighter] behavior with @@ -140,25 +217,29 @@ class SelectionScatterPlotHighlight extends StatelessWidget { // null value will be treated the same as not passing in a value at // all. charts.LinePointHighlighter( - showHorizontalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest, - showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest,), + showHorizontalFollowLine: + charts.LinePointHighlighterFollowLineType.nearest, + showVerticalFollowLine: + charts.LinePointHighlighterFollowLineType.nearest, + ), // Optional - By default, select nearest is configured to trigger // with tap so that a user can have pan/zoom behavior and line point // highlighter. Changing the trigger to tap and drag allows the // highlighter to follow the dragging gesture but it is not // recommended to be used when pan/zoom behavior is enabled. charts.SelectNearest( - eventTrigger: charts.SelectionTrigger.tapAndDrag,), + eventTrigger: charts.SelectionTrigger.tapAndDrag, + ), ], // Configure the point renderer to have a map of custom symbol // renderers. - defaultRenderer: - charts.PointRendererConfig(customSymbolRenderers: { - 'circle': charts.CircleSymbolRenderer(), - 'rect': charts.RectSymbolRenderer(), - },),); + defaultRenderer: charts.PointRendererConfig( + customSymbolRenderers: { + 'circle': charts.CircleSymbolRenderer(), + 'rect': charts.RectSymbolRenderer(), + }, + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -168,7 +249,13 @@ class SelectionScatterPlotHighlight extends StatelessWidget { LinearSales(12, 75, 4, null, null, null), // Render a hollow circle, filled in with white. LinearSales( - 13, 225, 5, 'circle', charts.MaterialPalette.white, 2,), + 13, + 225, + 5, + 'circle', + charts.MaterialPalette.white, + 2, + ), LinearSales(16, 50, 4, null, null, null), LinearSales(24, 75, 3, null, null, null), LinearSales(25, 100, 3, 'circle', null, null), @@ -176,7 +263,13 @@ class SelectionScatterPlotHighlight extends StatelessWidget { LinearSales(37, 10, 4.5, null, null, null), // Render a hollow circle, filled in with white. LinearSales( - 45, 300, 8, 'circle', charts.MaterialPalette.white, 2,), + 45, + 300, + 8, + 'circle', + charts.MaterialPalette.white, + 2, + ), LinearSales(52, 15, 4, null, null, null), // Render a hollow square, filled in with white. LinearSales(56, 200, 7, null, charts.MaterialPalette.white, 2), @@ -209,7 +302,9 @@ class SelectionScatterPlotHighlight extends StatelessWidget { ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (index) => data[index].shape,) + charts.pointSymbolRendererFnKey, + (index) => data[index].shape, + ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; @@ -218,9 +313,14 @@ class SelectionScatterPlotHighlight extends StatelessWidget { /// Sample linear data type. class LinearSales { - - LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, - this.strokeWidth,); + LinearSales( + this.year, + this.sales, + this.radius, + this.shape, + this.fillColor, + this.strokeWidth, + ); final int year; final int sales; final double radius; diff --git a/charts_flutter/example/lib/behaviors/slider.dart b/charts_flutter/example/lib/behaviors/slider.dart index cd811d9ba..a6b3dc602 100644 --- a/charts_flutter/example/lib/behaviors/slider.dart +++ b/charts_flutter/example/lib/behaviors/slider.dart @@ -34,13 +34,12 @@ import 'package:nimble_charts/flutter.dart'; /// [charts.Slider.moveSliderToDomain] can be called to programmatically position the /// slider. This is useful for synchronizing the slider with external elements. class SliderLine extends StatefulWidget { - const SliderLine(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory SliderLine.withSampleData() => SliderLine( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -103,8 +102,12 @@ class _SliderCallbackState extends State { Point? _sliderPosition; // Handles callbacks when the user drags the slider. - void _onSliderChange(Point point, domain, String roleId, - charts.SliderListenerDragState dragState,) { + void _onSliderChange( + Point point, + domain, + String roleId, + charts.SliderListenerDragState dragState, + ) { // Request a build. void rebuild(_) { setState(() { @@ -122,60 +125,73 @@ class _SliderCallbackState extends State { // The children consist of a Chart and Text widgets below to hold the info. final children = [ SizedBox( - height: 150, - child: charts.LineChart( - widget.seriesList, - animate: widget.animate, - // Configures a [Slider] behavior. - // - // Available options include: - // - // [eventTrigger] configures the type of mouse gesture that controls - // the slider. - // - // [handleRenderer] draws a handle for the slider. Defaults to a - // rectangle. - // - // [initialDomainValue] sets the initial position of the slider in - // domain units. The default is the center of the chart. - // - // [onChangeCallback] will be called when the position of the slider - // changes during a drag event. - // - // [roleId] optional custom role ID for the slider. This can be used to - // allow multiple [Slider] behaviors on the same chart. Normally, there can - // only be one slider (per event trigger type) on a chart. This setting - // allows for configuring multiple independent sliders. - // - // [snapToDatum] configures the slider to snap snap onto the nearest - // datum (by domain distance) when dragged. By default, the slider - // can be positioned anywhere along the domain axis. - // - // [style] takes in a [SliderStyle] configuration object, and - // configures the color and sizing of the slider line and handle. - behaviors: [ - charts.Slider( - initialDomainValue: 1.0, onChangeCallback: _onSliderChange,), - ], - ),), + height: 150, + child: charts.LineChart( + widget.seriesList, + animate: widget.animate, + // Configures a [Slider] behavior. + // + // Available options include: + // + // [eventTrigger] configures the type of mouse gesture that controls + // the slider. + // + // [handleRenderer] draws a handle for the slider. Defaults to a + // rectangle. + // + // [initialDomainValue] sets the initial position of the slider in + // domain units. The default is the center of the chart. + // + // [onChangeCallback] will be called when the position of the slider + // changes during a drag event. + // + // [roleId] optional custom role ID for the slider. This can be used to + // allow multiple [Slider] behaviors on the same chart. Normally, there can + // only be one slider (per event trigger type) on a chart. This setting + // allows for configuring multiple independent sliders. + // + // [snapToDatum] configures the slider to snap snap onto the nearest + // datum (by domain distance) when dragged. By default, the slider + // can be positioned anywhere along the domain axis. + // + // [style] takes in a [SliderStyle] configuration object, and + // configures the color and sizing of the slider line and handle. + behaviors: [ + charts.Slider( + initialDomainValue: 1.0, + onChangeCallback: _onSliderChange, + ), + ], + ), + ), ]; // If there is a slider change event, then include the details. if (_sliderDomainValue != null) { - children.add(Padding( + children.add( + Padding( padding: const EdgeInsets.only(top: 5), - child: Text('Slider domain value: $_sliderDomainValue'),),); + child: Text('Slider domain value: $_sliderDomainValue'), + ), + ); } if (_sliderPosition != null) { - children.add(Padding( + children.add( + Padding( padding: const EdgeInsets.only(top: 5), child: Text( - 'Slider position: ${_sliderPosition!.x}, ${_sliderPosition!.y}',),),); + 'Slider position: ${_sliderPosition!.x}, ${_sliderPosition!.y}', + ), + ), + ); } if (_sliderDragState != null) { - children.add(Padding( + children.add( + Padding( padding: const EdgeInsets.only(top: 5), - child: Text('Slider drag state: $_sliderDragState'),),); + child: Text('Slider drag state: $_sliderDragState'), + ), + ); } return Column(children: children); @@ -184,7 +200,6 @@ class _SliderCallbackState extends State { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart index 0441221a2..08eacccae 100644 --- a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart +++ b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart @@ -16,7 +16,6 @@ /// Example of the chart behavior that centers the viewport on domain selection. library; - // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; @@ -25,19 +24,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SlidingViewportOnSelection extends StatelessWidget { - - const SlidingViewportOnSelection(this.seriesList, {super.key, this.animate = false}); + const SlidingViewportOnSelection(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. - factory SlidingViewportOnSelection.withSampleData() => SlidingViewportOnSelection( - _createSampleData(), - ); + factory SlidingViewportOnSelection.withSampleData() => + SlidingViewportOnSelection( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SlidingViewportOnSelection.withRandomData() => SlidingViewportOnSelection(_createRandomData()); + factory SlidingViewportOnSelection.withRandomData() => + SlidingViewportOnSelection(_createRandomData()); final List> seriesList; final bool animate; @@ -79,22 +80,23 @@ class SlidingViewportOnSelection extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - behaviors: [ - // Add the sliding viewport behavior to have the viewport center on the - // domain that is currently selected. - charts.SlidingViewport(), - // A pan and zoom behavior helps demonstrate the sliding viewport - // behavior by allowing the data visible in the viewport to be adjusted - // dynamically. - charts.PanAndZoomBehavior(), - ], - // Set an initial viewport to demonstrate the sliding viewport behavior on - // initial chart load. - domainAxis: charts.OrdinalAxisSpec( - viewport: charts.OrdinalViewport('2018', 4),), - ); + seriesList, + animate: animate, + behaviors: [ + // Add the sliding viewport behavior to have the viewport center on the + // domain that is currently selected. + charts.SlidingViewport(), + // A pan and zoom behavior helps demonstrate the sliding viewport + // behavior by allowing the data visible in the viewport to be adjusted + // dynamically. + charts.PanAndZoomBehavior(), + ], + // Set an initial viewport to demonstrate the sliding viewport behavior on + // initial chart load. + domainAxis: charts.OrdinalAxisSpec( + viewport: charts.OrdinalViewport('2018', 4), + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -132,7 +134,6 @@ class SlidingViewportOnSelection extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/combo_chart/combo_gallery.dart b/charts_flutter/example/lib/combo_chart/combo_gallery.dart index 3b8613b2d..6879b93ea 100644 --- a/charts_flutter/example/lib/combo_chart/combo_gallery.dart +++ b/charts_flutter/example/lib/combo_chart/combo_gallery.dart @@ -22,34 +22,34 @@ import 'package:example/gallery_scaffold.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Ordinal Combo Chart', - subtitle: 'Ordinal combo chart with bars and lines', - childBuilder: OrdinalComboBarLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Numeric Line Bar Combo Chart', - subtitle: 'Numeric combo chart with lines and bars', - childBuilder: NumericComboLineBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Numeric Line Points Combo Chart', - subtitle: 'Numeric combo chart with lines and points', - childBuilder: NumericComboLinePointChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Time Series Combo Chart', - subtitle: 'Time series combo chart with lines and points', - childBuilder: DateTimeComboLinePointChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.scatter_plot), - title: 'Scatter Plot Combo Chart', - subtitle: 'Scatter plot combo chart with a line', - childBuilder: ScatterPlotComboLineChart.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Ordinal Combo Chart', + subtitle: 'Ordinal combo chart with bars and lines', + childBuilder: OrdinalComboBarLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Numeric Line Bar Combo Chart', + subtitle: 'Numeric combo chart with lines and bars', + childBuilder: NumericComboLineBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Numeric Line Points Combo Chart', + subtitle: 'Numeric combo chart with lines and points', + childBuilder: NumericComboLinePointChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Time Series Combo Chart', + subtitle: 'Time series combo chart with lines and points', + childBuilder: DateTimeComboLinePointChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), + title: 'Scatter Plot Combo Chart', + subtitle: 'Scatter plot combo chart with a line', + childBuilder: ScatterPlotComboLineChart.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart index 99e1a5f90..3e5389b1b 100644 --- a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart @@ -111,7 +111,7 @@ class DateTimeComboLinePointChart extends StatelessWidget { // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. // - // This is the default configuration, but is shown here for + // This is the default configuration, but is shown here for // illustration. defaultRenderer: charts.LineRendererConfig(), // Custom renderer configuration for the point series. diff --git a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart index fc244b830..083f35e0b 100644 --- a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart @@ -30,19 +30,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class NumericComboLinePointChart extends StatelessWidget { - - const NumericComboLinePointChart(this.seriesList, {super.key, this.animate = false}); + const NumericComboLinePointChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. - factory NumericComboLinePointChart.withSampleData() => NumericComboLinePointChart( - _createSampleData(), - ); + factory NumericComboLinePointChart.withSampleData() => + NumericComboLinePointChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory NumericComboLinePointChart.withRandomData() => NumericComboLinePointChart(_createRandomData()); + factory NumericComboLinePointChart.withRandomData() => + NumericComboLinePointChart(_createRandomData()); final List> seriesList; final bool animate; @@ -87,11 +89,12 @@ class NumericComboLinePointChart extends StatelessWidget { data: tableSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -99,7 +102,8 @@ class NumericComboLinePointChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.NumericComboChart(seriesList, + Widget build(BuildContext context) => charts.NumericComboChart( + seriesList, animate: animate, // Configure the default renderer as a line renderer. This will be used // for any series that does not define a rendererIdKey. @@ -107,9 +111,11 @@ class NumericComboLinePointChart extends StatelessWidget { // Custom renderer configuration for the point series. customSeriesRenderers: [ charts.PointRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customPoint',), - ],); + // ID used to link series to this renderer. + customRendererId: 'customPoint', + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -150,11 +156,12 @@ class NumericComboLinePointChart extends StatelessWidget { data: tableSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom point renderer for this series. ..setAttribute(charts.rendererIdKey, 'customPoint'), ]; @@ -163,7 +170,6 @@ class NumericComboLinePointChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart index 2dd8e2534..3bc4a259c 100644 --- a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart +++ b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart @@ -24,18 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class OrdinalComboBarLineChart extends StatelessWidget { - - const OrdinalComboBarLineChart(this.seriesList, {super.key, this.animate = false}); + const OrdinalComboBarLineChart(this.seriesList, + {super.key, this.animate = false}); factory OrdinalComboBarLineChart.withSampleData() => OrdinalComboBarLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory OrdinalComboBarLineChart.withRandomData() => OrdinalComboBarLineChart(_createRandomData()); + factory OrdinalComboBarLineChart.withRandomData() => + OrdinalComboBarLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -66,23 +67,26 @@ class OrdinalComboBarLineChart extends StatelessWidget { return [ charts.Series( - id: 'Desktop', - colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: desktopSalesData,), + id: 'Desktop', + colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData, + ), charts.Series( - id: 'Tablet', - colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: tableSalesData,), + id: 'Tablet', + colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData, + ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -90,18 +94,22 @@ class OrdinalComboBarLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.OrdinalComboChart(seriesList, + Widget build(BuildContext context) => charts.OrdinalComboChart( + seriesList, animate: animate, // Configure the default renderer as a bar renderer. defaultRenderer: charts.BarRendererConfig( - groupingType: charts.BarGroupingType.grouped,), + groupingType: charts.BarGroupingType.grouped, + ), // Custom renderer configuration for the line series. This will be used for // any series that does not define a rendererIdKey. customSeriesRenderers: [ charts.LineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customLine',), - ],); + // ID used to link series to this renderer. + customRendererId: 'customLine', + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -128,23 +136,26 @@ class OrdinalComboBarLineChart extends StatelessWidget { return [ charts.Series( - id: 'Desktop', - colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: desktopSalesData,), + id: 'Desktop', + colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: desktopSalesData, + ), charts.Series( - id: 'Tablet', - colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: tableSalesData,), + id: 'Tablet', + colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: tableSalesData, + ), charts.Series( - id: 'Mobile ', - colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: mobileSalesData,) + id: 'Mobile ', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: mobileSalesData, + ) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -153,7 +164,6 @@ class OrdinalComboBarLineChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart index c1c0bf730..e4d39fae8 100644 --- a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart +++ b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart @@ -25,19 +25,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class ScatterPlotComboLineChart extends StatelessWidget { - - const ScatterPlotComboLineChart(this.seriesList, {super.key, this.animate = false}); + const ScatterPlotComboLineChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. - factory ScatterPlotComboLineChart.withSampleData() => ScatterPlotComboLineChart( - _createSampleData(), - ); + factory ScatterPlotComboLineChart.withSampleData() => + ScatterPlotComboLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ScatterPlotComboLineChart.withRandomData() => ScatterPlotComboLineChart(_createRandomData()); + factory ScatterPlotComboLineChart.withRandomData() => + ScatterPlotComboLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -65,7 +67,10 @@ class ScatterPlotComboLineChart extends StatelessWidget { final myRegressionData = [ LinearSales(0, desktopSalesData[0].sales, 3.5), LinearSales( - 100, desktopSalesData[desktopSalesData.length - 1].sales, 7.5,), + 100, + desktopSalesData[desktopSalesData.length - 1].sales, + 7.5, + ), ]; const maxMeasure = 100; @@ -93,11 +98,12 @@ class ScatterPlotComboLineChart extends StatelessWidget { data: desktopSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: myRegressionData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: myRegressionData, + ) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -105,7 +111,8 @@ class ScatterPlotComboLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, animate: animate, // Configure the default renderer as a point renderer. This will be used // for any series that does not define a rendererIdKey. @@ -116,14 +123,16 @@ class ScatterPlotComboLineChart extends StatelessWidget { // Custom renderer configuration for the line series. customSeriesRenderers: [ charts.LineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customLine', - // Configure the regression line to be painted above the points. - // - // By default, series drawn by the point renderer are painted on - // top of those drawn by a line renderer. - layoutPaintOrder: charts.LayoutViewPaintOrder.point + 1,), - ],); + // ID used to link series to this renderer. + customRendererId: 'customLine', + // Configure the regression line to be painted above the points. + // + // By default, series drawn by the point renderer are painted on + // top of those drawn by a line renderer. + layoutPaintOrder: charts.LayoutViewPaintOrder.point + 1, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -172,11 +181,12 @@ class ScatterPlotComboLineChart extends StatelessWidget { data: desktopSalesData, ), charts.Series( - id: 'Mobile', - colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.sales, - data: myRegressionData,) + id: 'Mobile', + colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.sales, + data: myRegressionData, + ) // Configure our custom line renderer for this series. ..setAttribute(charts.rendererIdKey, 'customLine'), ]; @@ -185,7 +195,6 @@ class ScatterPlotComboLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales, this.radius); final int year; final int sales; diff --git a/charts_flutter/example/lib/gallery_scaffold.dart b/charts_flutter/example/lib/gallery_scaffold.dart index 568d3e51f..204e967f7 100644 --- a/charts_flutter/example/lib/gallery_scaffold.dart +++ b/charts_flutter/example/lib/gallery_scaffold.dart @@ -19,9 +19,14 @@ typedef GalleryWidgetBuilder = Widget Function(); /// Helper to build gallery. class GalleryScaffold extends StatefulWidget { - - const GalleryScaffold({required this.listTileIcon, required this.title, required this.subtitle, required this.childBuilder, super.key, + const GalleryScaffold({ + required this.listTileIcon, + required this.title, + required this.subtitle, + required this.childBuilder, + super.key, }); + /// The widget used for leading in a [ListTile]. final Widget listTileIcon; final String title; @@ -30,31 +35,37 @@ class GalleryScaffold extends StatefulWidget { /// Gets the gallery Widget buildGalleryListTile(BuildContext context) => ListTile( - leading: listTileIcon, - title: Text(title), - subtitle: Text(subtitle), - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (_) => this)); - },); + leading: listTileIcon, + title: Text(title), + subtitle: Text(subtitle), + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (_) => this)); + }, + ); @override - _GalleryScaffoldState createState() => _GalleryScaffoldState(); + GalleryScaffoldState createState() => GalleryScaffoldState(); } -class _GalleryScaffoldState extends State { +class GalleryScaffoldState extends State { void _handleButtonPress() { setState(() {}); } @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: Text(widget.title)), - body: Padding( + appBar: AppBar(title: Text(widget.title)), + body: Padding( padding: const EdgeInsets.all(8), - child: Column(children: [ - SizedBox(height: 250, child: widget.childBuilder()), - ],),), - floatingActionButton: FloatingActionButton( - onPressed: _handleButtonPress, child: const Icon(Icons.refresh),), - ); + child: Column( + children: [ + SizedBox(height: 250, child: widget.childBuilder()), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _handleButtonPress, + child: const Icon(Icons.refresh), + ), + ); } diff --git a/charts_flutter/example/lib/i18n/i18n_gallery.dart b/charts_flutter/example/lib/i18n/i18n_gallery.dart index dc5b21746..fb95ff94d 100644 --- a/charts_flutter/example/lib/i18n/i18n_gallery.dart +++ b/charts_flutter/example/lib/i18n/i18n_gallery.dart @@ -21,28 +21,28 @@ import 'package:example/i18n/rtl_series_legend.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'RTL Bar Chart', - subtitle: 'Simple bar chart in RTL', - childBuilder: RTLBarChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'RTL Line Chart', - subtitle: 'Simple line chart in RTL', - childBuilder: RTLLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'RTL Line Segments', - subtitle: 'Stacked area chart with style segments in RTL', - childBuilder: RTLLineSegments.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.flag), - title: 'RTL Series Legend', - subtitle: 'Series legend in RTL', - childBuilder: RTLSeriesLegend.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'RTL Bar Chart', + subtitle: 'Simple bar chart in RTL', + childBuilder: RTLBarChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'RTL Line Chart', + subtitle: 'Simple line chart in RTL', + childBuilder: RTLLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'RTL Line Segments', + subtitle: 'Stacked area chart with style segments in RTL', + childBuilder: RTLLineSegments.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.flag), + title: 'RTL Series Legend', + subtitle: 'Series legend in RTL', + childBuilder: RTLSeriesLegend.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart index bd913ae3a..4d541a565 100644 --- a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart @@ -25,13 +25,12 @@ import 'package:nimble_charts/flutter.dart' as charts; import 'package:nimble_charts/flutter.dart'; class RTLBarChart extends StatelessWidget { - const RTLBarChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory RTLBarChart.withSampleData() => RTLBarChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -80,12 +79,13 @@ class RTLBarChart extends StatelessWidget { // Optionally, [RTLSpec] can be passed in when creating the chart to specify // chart display settings in RTL mode. return Directionality( - textDirection: TextDirection.rtl, - child: charts.BarChart( - seriesList, - animate: animate, - vertical: false, - ),); + textDirection: TextDirection.rtl, + child: charts.BarChart( + seriesList, + animate: animate, + vertical: false, + ), + ); } /// Create one series with sample hard coded data. @@ -110,7 +110,6 @@ class RTLBarChart extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/i18n/rtl_line_chart.dart b/charts_flutter/example/lib/i18n/rtl_line_chart.dart index aa0ef3c46..7f72db6db 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_chart.dart @@ -25,13 +25,12 @@ import 'package:nimble_charts/flutter.dart' as charts; import 'package:nimble_charts/flutter.dart'; class RTLLineChart extends StatelessWidget { - const RTLLineChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory RTLLineChart.withSampleData() => RTLLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -77,11 +76,12 @@ class RTLLineChart extends StatelessWidget { // and the secondary measure axis is on the left (when used). // Domain axis' first domain starts on the right and grows left. return Directionality( - textDirection: TextDirection.rtl, - child: charts.LineChart( - seriesList, - animate: animate, - ),); + textDirection: TextDirection.rtl, + child: charts.LineChart( + seriesList, + animate: animate, + ), + ); } /// Create one series with sample hard coded data. @@ -106,7 +106,6 @@ class RTLLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/i18n/rtl_series_legend.dart b/charts_flutter/example/lib/i18n/rtl_series_legend.dart index 33cf3f439..af374358c 100644 --- a/charts_flutter/example/lib/i18n/rtl_series_legend.dart +++ b/charts_flutter/example/lib/i18n/rtl_series_legend.dart @@ -25,19 +25,19 @@ import 'package:nimble_charts/flutter.dart' as charts; import 'package:nimble_charts/flutter.dart'; class RTLSeriesLegend extends StatelessWidget { - const RTLSeriesLegend(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.BarChart] with sample data and no transition. factory RTLSeriesLegend.withSampleData() => RTLSeriesLegend( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory RTLSeriesLegend.withRandomData() => RTLSeriesLegend(_createRandomData()); + factory RTLSeriesLegend.withRandomData() => + RTLSeriesLegend(_createRandomData()); final List> seriesList; final bool animate; @@ -125,15 +125,18 @@ class RTLSeriesLegend extends StatelessWidget { // order to show these effects, but are not required for SeriesLegend to // work with the correct directionality. return Directionality( - textDirection: TextDirection.rtl, - child: charts.BarChart( - seriesList, - animate: animate, - behaviors: [ - charts.SeriesLegend( - position: charts.BehaviorPosition.end, desiredMaxRows: 2,), - ], - ),); + textDirection: TextDirection.rtl, + child: charts.BarChart( + seriesList, + animate: animate, + behaviors: [ + charts.SeriesLegend( + position: charts.BehaviorPosition.end, + desiredMaxRows: 2, + ), + ], + ), + ); } /// Create series list with multiple series @@ -197,7 +200,6 @@ class RTLSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/legends/datum_legend_options.dart b/charts_flutter/example/lib/legends/datum_legend_options.dart index a61172435..77fc14a13 100644 --- a/charts_flutter/example/lib/legends/datum_legend_options.dart +++ b/charts_flutter/example/lib/legends/datum_legend_options.dart @@ -27,18 +27,18 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DatumLegendOptions extends StatelessWidget { - const DatumLegendOptions(this.seriesList, {super.key, this.animate = false}); factory DatumLegendOptions.withSampleData() => DatumLegendOptions( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DatumLegendOptions.withRandomData() => DatumLegendOptions(_createRandomData()); + factory DatumLegendOptions.withRandomData() => + DatumLegendOptions(_createRandomData()); final List> seriesList; final bool animate; @@ -66,40 +66,41 @@ class DatumLegendOptions extends StatelessWidget { @override Widget build(BuildContext context) => charts.PieChart( - seriesList, - animate: animate, - // Add the legend behavior to the chart to turn on legends. - // This example shows how to change the position and justification of - // the legend, in addition to altering the max rows and padding. - behaviors: [ - charts.DatumLegend( - // Positions for "start" and "end" will be left and right respectively - // for widgets with a build context that has directionality ltr. - // For rtl, "start" and "end" will be right and left respectively. - // Since this example has directionality of ltr, the legend is - // positioned on the right side of the chart. - position: charts.BehaviorPosition.end, - // For a legend that is positioned on the left or right of the chart, - // setting the justification for [endDrawArea] is aligned to the - // bottom of the chart draw area. - outsideJustification: charts.OutsideJustification.endDrawArea, - // By default, if the position of the chart is on the left or right of - // the chart, [horizontalFirst] is set to false. This means that the - // legend entries will grow as new rows first instead of a new column. - horizontalFirst: false, - // By setting this value to 2, the legend entries will grow up to two - // rows before adding a new column. - desiredMaxRows: 2, - // This defines the padding around each legend entry. - cellPadding: const EdgeInsets.only(right: 4, bottom: 4), - // Render the legend entry text with custom styles. - entryTextStyle: charts.TextStyleSpec( + seriesList, + animate: animate, + // Add the legend behavior to the chart to turn on legends. + // This example shows how to change the position and justification of + // the legend, in addition to altering the max rows and padding. + behaviors: [ + charts.DatumLegend( + // Positions for "start" and "end" will be left and right respectively + // for widgets with a build context that has directionality ltr. + // For rtl, "start" and "end" will be right and left respectively. + // Since this example has directionality of ltr, the legend is + // positioned on the right side of the chart. + position: charts.BehaviorPosition.end, + // For a legend that is positioned on the left or right of the chart, + // setting the justification for [endDrawArea] is aligned to the + // bottom of the chart draw area. + outsideJustification: charts.OutsideJustification.endDrawArea, + // By default, if the position of the chart is on the left or right of + // the chart, [horizontalFirst] is set to false. This means that the + // legend entries will grow as new rows first instead of a new column. + horizontalFirst: false, + // By setting this value to 2, the legend entries will grow up to two + // rows before adding a new column. + desiredMaxRows: 2, + // This defines the padding around each legend entry. + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), + // Render the legend entry text with custom styles. + entryTextStyle: charts.TextStyleSpec( color: charts.MaterialPalette.purple.shadeDefault, fontFamily: 'Georgia', - fontSize: 11,), - ), - ], - ); + fontSize: 11, + ), + ), + ], + ); /// Create series list with one series static List> _createSampleData() { @@ -123,7 +124,6 @@ class DatumLegendOptions extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart index c3c1aa6d0..af201f384 100644 --- a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart @@ -30,18 +30,19 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// Also shows the option to provide a custom measure formatter. class DatumLegendWithMeasures extends StatelessWidget { - - const DatumLegendWithMeasures(this.seriesList, {super.key, this.animate = false}); + const DatumLegendWithMeasures(this.seriesList, + {super.key, this.animate = false}); factory DatumLegendWithMeasures.withSampleData() => DatumLegendWithMeasures( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DatumLegendWithMeasures.withRandomData() => DatumLegendWithMeasures(_createRandomData()); + factory DatumLegendWithMeasures.withRandomData() => + DatumLegendWithMeasures(_createRandomData()); final List> seriesList; final bool animate; @@ -69,45 +70,45 @@ class DatumLegendWithMeasures extends StatelessWidget { @override Widget build(BuildContext context) => charts.PieChart( - seriesList, - animate: animate, - // Add the legend behavior to the chart to turn on legends. - // This example shows how to optionally show measure and provide a custom - // formatter. - behaviors: [ - // EXCLUDE_FROM_GALLERY_DOCS_START - // This section is excluded from being copied to the gallery. - // This is added in order to generate the image for the gallery to show - // an initial selection so that measure values are shown in the gallery. - charts.InitialSelection( - selectedDataConfig: [ - charts.SeriesDatumConfig('Sales', 0), - ], - ), - // EXCLUDE_FROM_GALLERY_DOCS_END - charts.DatumLegend( - // Positions for "start" and "end" will be left and right respectively - // for widgets with a build context that has directionality ltr. - // For rtl, "start" and "end" will be right and left respectively. - // Since this example has directionality of ltr, the legend is - // positioned on the right side of the chart. - position: charts.BehaviorPosition.end, - // By default, if the position of the chart is on the left or right of - // the chart, [horizontalFirst] is set to false. This means that the - // legend entries will grow as new rows first instead of a new column. - horizontalFirst: false, - // This defines the padding around each legend entry. - cellPadding: const EdgeInsets.only(right: 4, bottom: 4), - // Set [showMeasures] to true to display measures in series legend. - showMeasures: true, - // Configure the measure value to be shown by default in the legend. - legendDefaultMeasure: charts.LegendDefaultMeasure.firstValue, - // Optionally provide a measure formatter to format the measure value. - // If none is specified the value is formatted as a decimal. - measureFormatter: (value) => value == null ? '-' : '${value}k', - ), - ], - ); + seriesList, + animate: animate, + // Add the legend behavior to the chart to turn on legends. + // This example shows how to optionally show measure and provide a custom + // formatter. + behaviors: [ + // EXCLUDE_FROM_GALLERY_DOCS_START + // This section is excluded from being copied to the gallery. + // This is added in order to generate the image for the gallery to show + // an initial selection so that measure values are shown in the gallery. + charts.InitialSelection( + selectedDataConfig: [ + charts.SeriesDatumConfig('Sales', 0), + ], + ), + // EXCLUDE_FROM_GALLERY_DOCS_END + charts.DatumLegend( + // Positions for "start" and "end" will be left and right respectively + // for widgets with a build context that has directionality ltr. + // For rtl, "start" and "end" will be right and left respectively. + // Since this example has directionality of ltr, the legend is + // positioned on the right side of the chart. + position: charts.BehaviorPosition.end, + // By default, if the position of the chart is on the left or right of + // the chart, [horizontalFirst] is set to false. This means that the + // legend entries will grow as new rows first instead of a new column. + horizontalFirst: false, + // This defines the padding around each legend entry. + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), + // Set [showMeasures] to true to display measures in series legend. + showMeasures: true, + // Configure the measure value to be shown by default in the legend. + legendDefaultMeasure: charts.LegendDefaultMeasure.firstValue, + // Optionally provide a measure formatter to format the measure value. + // If none is specified the value is formatted as a decimal. + measureFormatter: (value) => value == null ? '-' : '${value}k', + ), + ], + ); /// Create series list with one series static List> _createSampleData() { @@ -131,7 +132,6 @@ class DatumLegendWithMeasures extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart index 78ec15137..717f50e46 100644 --- a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart +++ b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart @@ -23,18 +23,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DefaultHiddenSeriesLegend extends StatelessWidget { + const DefaultHiddenSeriesLegend(this.seriesList, + {super.key, this.animate = false}); - const DefaultHiddenSeriesLegend(this.seriesList, {super.key, this.animate = false}); - - factory DefaultHiddenSeriesLegend.withSampleData() => DefaultHiddenSeriesLegend( - _createSampleData(), - ); + factory DefaultHiddenSeriesLegend.withSampleData() => + DefaultHiddenSeriesLegend( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DefaultHiddenSeriesLegend.withRandomData() => DefaultHiddenSeriesLegend(_createRandomData()); + factory DefaultHiddenSeriesLegend.withRandomData() => + DefaultHiddenSeriesLegend(_createRandomData()); final List> seriesList; final bool animate; @@ -101,18 +103,18 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. - behaviors: [ - charts.SeriesLegend( - // Configures the "Other" series to be hidden on first chart draw. - defaultHiddenSeries: const ['Other'], - ), - ], - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Add the series legend behavior to the chart to turn on series legends. + // By default the legend will display above the chart. + behaviors: [ + charts.SeriesLegend( + // Configures the "Other" series to be hidden on first chart draw. + defaultHiddenSeries: const ['Other'], + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -175,7 +177,6 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/legends/legend_custom_symbol.dart b/charts_flutter/example/lib/legends/legend_custom_symbol.dart index 88d6da548..26c50ee1d 100644 --- a/charts_flutter/example/lib/legends/legend_custom_symbol.dart +++ b/charts_flutter/example/lib/legends/legend_custom_symbol.dart @@ -29,7 +29,6 @@ import 'package:nimble_charts_common/common.dart' as common; /// /// This is used to show that legend symbols can be assigned a custom symbol. class IconRenderer extends charts.CustomSymbolRenderer { - IconRenderer(this.iconData); final IconData iconData; @@ -47,24 +46,26 @@ class IconRenderer extends charts.CustomSymbolRenderer { } return SizedBox.fromSize( - size: size, - child: Icon(iconData, color: color?.toDartColor(), size: 12),); + size: size, + child: Icon(iconData, color: color?.toDartColor(), size: 12), + ); } } class LegendWithCustomSymbol extends StatelessWidget { - - const LegendWithCustomSymbol(this.seriesList, {super.key, this.animate = false}); + const LegendWithCustomSymbol(this.seriesList, + {super.key, this.animate = false}); factory LegendWithCustomSymbol.withSampleData() => LegendWithCustomSymbol( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LegendWithCustomSymbol.withRandomData() => LegendWithCustomSymbol(_createRandomData()); + factory LegendWithCustomSymbol.withRandomData() => + LegendWithCustomSymbol(_createRandomData()); final List> seriesList; final bool animate; @@ -131,18 +132,19 @@ class LegendWithCustomSymbol extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Add the legend behavior to the chart to turn on legends. - // By default the legend will display above the chart. - // - // To change the symbol used in the legend, set the renderer attribute of - // symbolRendererKey to a SymbolRenderer. - behaviors: [charts.SeriesLegend()], - defaultRenderer: charts.BarRendererConfig( - symbolRenderer: IconRenderer(Icons.cloud),), - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Add the legend behavior to the chart to turn on legends. + // By default the legend will display above the chart. + // + // To change the symbol used in the legend, set the renderer attribute of + // symbolRendererKey to a SymbolRenderer. + behaviors: [charts.SeriesLegend()], + defaultRenderer: charts.BarRendererConfig( + symbolRenderer: IconRenderer(Icons.cloud), + ), + ); /// Create series list with multiple series static List> _createSampleData() { @@ -205,7 +207,6 @@ class LegendWithCustomSymbol extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/legends/legends_gallery.dart b/charts_flutter/example/lib/legends/legends_gallery.dart index 0507293ab..57dd8ccba 100644 --- a/charts_flutter/example/lib/legends/legends_gallery.dart +++ b/charts_flutter/example/lib/legends/legends_gallery.dart @@ -23,55 +23,55 @@ import 'package:example/legends/simple_series_legend.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Series Legend', - subtitle: 'A series legend for a bar chart with default settings', - childBuilder: SimpleSeriesLegend.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Series Legend Options', - subtitle: - 'A series legend with custom positioning and spacing for a bar chart', - childBuilder: LegendOptions.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Series Legend Custom Symbol', - subtitle: 'A series legend using a custom symbol renderer', - childBuilder: LegendWithCustomSymbol.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Default Hidden Series Legend', - subtitle: 'A series legend showing a series hidden by default', - childBuilder: DefaultHiddenSeriesLegend.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.insert_chart), - title: 'Series legend with measures', - subtitle: 'Series legend with measures and measure formatting', - childBuilder: LegendWithMeasures.withRandomData, - ), - //TODO: - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Datum Legend', - // subtitle: 'A datum legend for a pie chart with default settings', - // childBuilder: () => new SimpleDatumLegend.withRandomData(), - // ), - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Datum Legend Options', - // subtitle: - // 'A datum legend with custom positioning and spacing for a pie chart', - // childBuilder: () => new DatumLegendOptions.withRandomData(), - // ), - const GalleryScaffold( - listTileIcon: Icon(Icons.pie_chart), - title: 'Datum legend with measures', - subtitle: 'Datum legend with measures and measure formatting', - childBuilder: DatumLegendWithMeasures.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Series Legend', + subtitle: 'A series legend for a bar chart with default settings', + childBuilder: SimpleSeriesLegend.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Series Legend Options', + subtitle: + 'A series legend with custom positioning and spacing for a bar chart', + childBuilder: LegendOptions.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Series Legend Custom Symbol', + subtitle: 'A series legend using a custom symbol renderer', + childBuilder: LegendWithCustomSymbol.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Default Hidden Series Legend', + subtitle: 'A series legend showing a series hidden by default', + childBuilder: DefaultHiddenSeriesLegend.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.insert_chart), + title: 'Series legend with measures', + subtitle: 'Series legend with measures and measure formatting', + childBuilder: LegendWithMeasures.withRandomData, + ), + //TODO: + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Datum Legend', + // subtitle: 'A datum legend for a pie chart with default settings', + // childBuilder: () => new SimpleDatumLegend.withRandomData(), + // ), + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Datum Legend Options', + // subtitle: + // 'A datum legend with custom positioning and spacing for a pie chart', + // childBuilder: () => new DatumLegendOptions.withRandomData(), + // ), + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), + title: 'Datum legend with measures', + subtitle: 'Datum legend with measures and measure formatting', + childBuilder: DatumLegendWithMeasures.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/legends/series_legend_options.dart b/charts_flutter/example/lib/legends/series_legend_options.dart index 6c7b1853e..3d8d3f827 100644 --- a/charts_flutter/example/lib/legends/series_legend_options.dart +++ b/charts_flutter/example/lib/legends/series_legend_options.dart @@ -27,12 +27,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LegendOptions extends StatelessWidget { - const LegendOptions(this.seriesList, {super.key, this.animate = false}); factory LegendOptions.withSampleData() => LegendOptions( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -105,41 +104,42 @@ class LegendOptions extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Add the legend behavior to the chart to turn on legends. - // This example shows how to change the position and justification of - // the legend, in addition to altering the max rows and padding. - behaviors: [ - charts.SeriesLegend( - // Positions for "start" and "end" will be left and right respectively - // for widgets with a build context that has directionality ltr. - // For rtl, "start" and "end" will be right and left respectively. - // Since this example has directionality of ltr, the legend is - // positioned on the right side of the chart. - position: charts.BehaviorPosition.end, - // For a legend that is positioned on the left or right of the chart, - // setting the justification for [endDrawArea] is aligned to the - // bottom of the chart draw area. - outsideJustification: charts.OutsideJustification.endDrawArea, - // By default, if the position of the chart is on the left or right of - // the chart, [horizontalFirst] is set to false. This means that the - // legend entries will grow as new rows first instead of a new column. - horizontalFirst: false, - // By setting this value to 2, the legend entries will grow up to two - // rows before adding a new column. - desiredMaxRows: 2, - // This defines the padding around each legend entry. - cellPadding: const EdgeInsets.only(right: 4, bottom: 4), - // Render the legend entry text with custom styles. - entryTextStyle: charts.TextStyleSpec( + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Add the legend behavior to the chart to turn on legends. + // This example shows how to change the position and justification of + // the legend, in addition to altering the max rows and padding. + behaviors: [ + charts.SeriesLegend( + // Positions for "start" and "end" will be left and right respectively + // for widgets with a build context that has directionality ltr. + // For rtl, "start" and "end" will be right and left respectively. + // Since this example has directionality of ltr, the legend is + // positioned on the right side of the chart. + position: charts.BehaviorPosition.end, + // For a legend that is positioned on the left or right of the chart, + // setting the justification for [endDrawArea] is aligned to the + // bottom of the chart draw area. + outsideJustification: charts.OutsideJustification.endDrawArea, + // By default, if the position of the chart is on the left or right of + // the chart, [horizontalFirst] is set to false. This means that the + // legend entries will grow as new rows first instead of a new column. + horizontalFirst: false, + // By setting this value to 2, the legend entries will grow up to two + // rows before adding a new column. + desiredMaxRows: 2, + // This defines the padding around each legend entry. + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), + // Render the legend entry text with custom styles. + entryTextStyle: charts.TextStyleSpec( color: charts.MaterialPalette.purple.shadeDefault, fontFamily: 'Georgia', - fontSize: 11,), - ), - ], - ); + fontSize: 11, + ), + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -202,7 +202,6 @@ class LegendOptions extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/legends/series_legend_with_measures.dart b/charts_flutter/example/lib/legends/series_legend_with_measures.dart index b641b1d69..30c64460a 100644 --- a/charts_flutter/example/lib/legends/series_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/series_legend_with_measures.dart @@ -31,18 +31,18 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// Also shows the option to provide a custom measure formatter. class LegendWithMeasures extends StatelessWidget { - const LegendWithMeasures(this.seriesList, {super.key, this.animate = false}); factory LegendWithMeasures.withSampleData() => LegendWithMeasures( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LegendWithMeasures.withRandomData() => LegendWithMeasures(_createRandomData()); + factory LegendWithMeasures.withRandomData() => + LegendWithMeasures(_createRandomData()); final List> seriesList; final bool animate; @@ -109,48 +109,48 @@ class LegendWithMeasures extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Add the legend behavior to the chart to turn on legends. - // This example shows how to optionally show measure and provide a custom - // formatter. - behaviors: [ - // EXCLUDE_FROM_GALLERY_DOCS_START - // This section is excluded from being copied to the gallery. - // This is added in order to generate the image for the gallery to show - // an initial selection so that measure values are shown in the gallery. - charts.InitialSelection( - selectedDataConfig: [ - charts.SeriesDatumConfig('Desktop', '2016'), - charts.SeriesDatumConfig('Tablet', '2016'), - charts.SeriesDatumConfig('Mobile', '2016'), - charts.SeriesDatumConfig('Other', '2016'), - ], - ), - // EXCLUDE_FROM_GALLERY_DOCS_END - charts.SeriesLegend( - // Positions for "start" and "end" will be left and right respectively - // for widgets with a build context that has directionality ltr. - // For rtl, "start" and "end" will be right and left respectively. - // Since this example has directionality of ltr, the legend is - // positioned on the right side of the chart. - position: charts.BehaviorPosition.end, - // By default, if the position of the chart is on the left or right of - // the chart, [horizontalFirst] is set to false. This means that the - // legend entries will grow as new rows first instead of a new column. - horizontalFirst: false, - // This defines the padding around each legend entry. - cellPadding: const EdgeInsets.only(right: 4, bottom: 4), - // Set show measures to true to display measures in series legend, - // when the datum is selected. - showMeasures: true, - // Optionally provide a measure formatter to format the measure value. - // If none is specified the value is formatted as a decimal. - measureFormatter: (value) => value == null ? '-' : '${value}k', - ), - ], - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Add the legend behavior to the chart to turn on legends. + // This example shows how to optionally show measure and provide a custom + // formatter. + behaviors: [ + // EXCLUDE_FROM_GALLERY_DOCS_START + // This section is excluded from being copied to the gallery. + // This is added in order to generate the image for the gallery to show + // an initial selection so that measure values are shown in the gallery. + charts.InitialSelection( + selectedDataConfig: [ + charts.SeriesDatumConfig('Desktop', '2016'), + charts.SeriesDatumConfig('Tablet', '2016'), + charts.SeriesDatumConfig('Mobile', '2016'), + charts.SeriesDatumConfig('Other', '2016'), + ], + ), + // EXCLUDE_FROM_GALLERY_DOCS_END + charts.SeriesLegend( + // Positions for "start" and "end" will be left and right respectively + // for widgets with a build context that has directionality ltr. + // For rtl, "start" and "end" will be right and left respectively. + // Since this example has directionality of ltr, the legend is + // positioned on the right side of the chart. + position: charts.BehaviorPosition.end, + // By default, if the position of the chart is on the left or right of + // the chart, [horizontalFirst] is set to false. This means that the + // legend entries will grow as new rows first instead of a new column. + horizontalFirst: false, + // This defines the padding around each legend entry. + cellPadding: const EdgeInsets.only(right: 4, bottom: 4), + // Set show measures to true to display measures in series legend, + // when the datum is selected. + showMeasures: true, + // Optionally provide a measure formatter to format the measure value. + // If none is specified the value is formatted as a decimal. + measureFormatter: (value) => value == null ? '-' : '${value}k', + ), + ], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -213,7 +213,6 @@ class LegendWithMeasures extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/legends/simple_datum_legend.dart b/charts_flutter/example/lib/legends/simple_datum_legend.dart index fe8d34925..249f84c6d 100644 --- a/charts_flutter/example/lib/legends/simple_datum_legend.dart +++ b/charts_flutter/example/lib/legends/simple_datum_legend.dart @@ -23,18 +23,18 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleDatumLegend extends StatelessWidget { - const SimpleDatumLegend(this.seriesList, {super.key, this.animate = false}); factory SimpleDatumLegend.withSampleData() => SimpleDatumLegend( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleDatumLegend.withRandomData() => SimpleDatumLegend(_createRandomData()); + factory SimpleDatumLegend.withRandomData() => + SimpleDatumLegend(_createRandomData()); final List> seriesList; final bool animate; @@ -62,12 +62,12 @@ class SimpleDatumLegend extends StatelessWidget { @override Widget build(BuildContext context) => charts.PieChart( - seriesList, - animate: animate, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. - behaviors: [charts.DatumLegend()], - ); + seriesList, + animate: animate, + // Add the series legend behavior to the chart to turn on series legends. + // By default the legend will display above the chart. + behaviors: [charts.DatumLegend()], + ); /// Create series list with one series static List> _createSampleData() { @@ -91,7 +91,6 @@ class SimpleDatumLegend extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/legends/simple_series_legend.dart b/charts_flutter/example/lib/legends/simple_series_legend.dart index 34f59446f..954f2d4c6 100644 --- a/charts_flutter/example/lib/legends/simple_series_legend.dart +++ b/charts_flutter/example/lib/legends/simple_series_legend.dart @@ -23,18 +23,18 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleSeriesLegend extends StatelessWidget { - const SimpleSeriesLegend(this.seriesList, {super.key, this.animate = false}); factory SimpleSeriesLegend.withSampleData() => SimpleSeriesLegend( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleSeriesLegend.withRandomData() => SimpleSeriesLegend(_createRandomData()); + factory SimpleSeriesLegend.withRandomData() => + SimpleSeriesLegend(_createRandomData()); final List> seriesList; final bool animate; @@ -101,13 +101,13 @@ class SimpleSeriesLegend extends StatelessWidget { @override Widget build(BuildContext context) => charts.BarChart( - seriesList, - animate: animate, - barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. - behaviors: [charts.SeriesLegend()], - ); + seriesList, + animate: animate, + barGroupingType: charts.BarGroupingType.grouped, + // Add the series legend behavior to the chart to turn on series legends. + // By default the legend will display above the chart. + behaviors: [charts.SeriesLegend()], + ); /// Create series list with multiple series static List> _createSampleData() { @@ -170,7 +170,6 @@ class SimpleSeriesLegend extends StatelessWidget { /// Sample ordinal data type. class OrdinalSales { - OrdinalSales(this.year, this.sales); final String year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/animation_zoom.dart b/charts_flutter/example/lib/line_chart/animation_zoom.dart index 6871a6a85..417ef7b5c 100644 --- a/charts_flutter/example/lib/line_chart/animation_zoom.dart +++ b/charts_flutter/example/lib/line_chart/animation_zoom.dart @@ -25,19 +25,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineAnimationZoomChart extends StatelessWidget { - - const LineAnimationZoomChart(this.seriesList, {super.key, this.animate = false}); + const LineAnimationZoomChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory LineAnimationZoomChart.withSampleData() => LineAnimationZoomChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineAnimationZoomChart.withRandomData() => LineAnimationZoomChart(_createRandomData()); + factory LineAnimationZoomChart.withRandomData() => + LineAnimationZoomChart(_createRandomData()); final List> seriesList; final bool animate; @@ -63,9 +64,13 @@ class LineAnimationZoomChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ - charts.PanAndZoomBehavior(), - ],); + Widget build(BuildContext context) => charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + charts.PanAndZoomBehavior(), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -89,7 +94,6 @@ class LineAnimationZoomChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/area_and_line.dart b/charts_flutter/example/lib/line_chart/area_and_line.dart index 8cd315297..690d2ac57 100644 --- a/charts_flutter/example/lib/line_chart/area_and_line.dart +++ b/charts_flutter/example/lib/line_chart/area_and_line.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class AreaAndLineChart extends StatelessWidget { - const AreaAndLineChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory AreaAndLineChart.withSampleData() => AreaAndLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory AreaAndLineChart.withRandomData() => AreaAndLineChart(_createRandomData()); + factory AreaAndLineChart.withRandomData() => + AreaAndLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -80,15 +80,18 @@ class AreaAndLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, animate: animate, customSeriesRenderers: [ charts.LineRendererConfig( - // ID used to link series to this renderer. - customRendererId: 'customArea', - includeArea: true, - stacked: true,), - ],); + // ID used to link series to this renderer. + customRendererId: 'customArea', + includeArea: true, + stacked: true, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -129,7 +132,6 @@ class AreaAndLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/dash_pattern.dart b/charts_flutter/example/lib/line_chart/dash_pattern.dart index 45eb89c57..38b43257c 100644 --- a/charts_flutter/example/lib/line_chart/dash_pattern.dart +++ b/charts_flutter/example/lib/line_chart/dash_pattern.dart @@ -25,19 +25,20 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a line chart rendered with dash patterns. class DashPatternLineChart extends StatelessWidget { - - const DashPatternLineChart(this.seriesList, {super.key, this.animate = false}); + const DashPatternLineChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory DashPatternLineChart.withSampleData() => DashPatternLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DashPatternLineChart.withRandomData() => DashPatternLineChart(_createRandomData()); + factory DashPatternLineChart.withRandomData() => + DashPatternLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -95,7 +96,8 @@ class DashPatternLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); + Widget build(BuildContext context) => + charts.LineChart(seriesList, animate: animate); /// Create three series with sample hard coded data. static List> _createSampleData() { @@ -150,7 +152,6 @@ class DashPatternLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/line_annotation.dart b/charts_flutter/example/lib/line_chart/line_annotation.dart index 00ce4efb3..380801119 100644 --- a/charts_flutter/example/lib/line_chart/line_annotation.dart +++ b/charts_flutter/example/lib/line_chart/line_annotation.dart @@ -24,8 +24,8 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineLineAnnotationChart extends StatelessWidget { - - const LineLineAnnotationChart(this.seriesList, {super.key, this.animate = false}); + const LineLineAnnotationChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and line annotations. /// @@ -33,14 +33,15 @@ class LineLineAnnotationChart extends StatelessWidget { /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. factory LineLineAnnotationChart.withSampleData() => LineLineAnnotationChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineLineAnnotationChart.withRandomData() => LineLineAnnotationChart(_createRandomData()); + factory LineLineAnnotationChart.withRandomData() => + LineLineAnnotationChart(_createRandomData()); final List> seriesList; final bool animate; @@ -69,26 +70,39 @@ class LineLineAnnotationChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ - charts.RangeAnnotation([ - charts.LineAnnotationSegment( - 1.0, charts.RangeAnnotationAxisType.domain, - startLabel: 'Domain 1',), - charts.LineAnnotationSegment( - 4, charts.RangeAnnotationAxisType.domain, - endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200,), - charts.LineAnnotationSegment( - 20, charts.RangeAnnotationAxisType.measure, - startLabel: 'Measure 1 Start', - endLabel: 'Measure 1 End', - color: charts.MaterialPalette.gray.shade300,), - charts.LineAnnotationSegment( - 65, charts.RangeAnnotationAxisType.measure, - startLabel: 'Measure 2 Start', - endLabel: 'Measure 2 End', - color: charts.MaterialPalette.gray.shade400,), - ]), - ],); + Widget build(BuildContext context) => charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + charts.RangeAnnotation([ + charts.LineAnnotationSegment( + 1.0, + charts.RangeAnnotationAxisType.domain, + startLabel: 'Domain 1', + ), + charts.LineAnnotationSegment( + 4, + charts.RangeAnnotationAxisType.domain, + endLabel: 'Domain 2', + color: charts.MaterialPalette.gray.shade200, + ), + charts.LineAnnotationSegment( + 20, + charts.RangeAnnotationAxisType.measure, + startLabel: 'Measure 1 Start', + endLabel: 'Measure 1 End', + color: charts.MaterialPalette.gray.shade300, + ), + charts.LineAnnotationSegment( + 65, + charts.RangeAnnotationAxisType.measure, + startLabel: 'Measure 2 Start', + endLabel: 'Measure 2 End', + color: charts.MaterialPalette.gray.shade400, + ), + ]), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -112,7 +126,6 @@ class LineLineAnnotationChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/line_gallery.dart b/charts_flutter/example/lib/line_chart/line_gallery.dart index d743f3fcc..ef340d38c 100644 --- a/charts_flutter/example/lib/line_chart/line_gallery.dart +++ b/charts_flutter/example/lib/line_chart/line_gallery.dart @@ -30,82 +30,83 @@ import 'package:example/line_chart/stacked_area_nulls.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Simple Line Chart', - subtitle: 'With a single series and default line point highlighter', - childBuilder: SimpleLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Stacked Area Chart', - subtitle: 'Stacked area chart with three series', - childBuilder: StackedAreaLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Stacked Area Custom Color Chart', - subtitle: 'Stacked area chart with custom area skirt color', - childBuilder: StackedAreaCustomColorLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Area and Line Combo Chart', - subtitle: 'Combo chart with one line series and one area series', - childBuilder: AreaAndLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Points Line Chart', - subtitle: 'Line chart with points on a single series', - childBuilder: PointsLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Null Data Line Chart', - subtitle: 'With a single series and null measure values', - childBuilder: SimpleNullsLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Stacked Area with Nulls Chart', - subtitle: 'Stacked area chart with three series and null measure values', - childBuilder: StackedAreaNullsLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Dash Pattern Line Chart', - subtitle: 'Line chart with dash patterns', - childBuilder: DashPatternLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Segments Line Chart', - subtitle: 'Line chart with changes of style for each line', - childBuilder: SegmentsLineChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Line Annotation Line Chart', - subtitle: 'Line chart with line annotations', - childBuilder: LineLineAnnotationChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Range Annotation Line Chart', - subtitle: 'Line chart with range annotations', - childBuilder: LineRangeAnnotationChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Range Annotation Margin Labels Line Chart', - subtitle: 'Line chart with range annotations with labels in margins', - childBuilder: LineRangeAnnotationMarginChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Pan and Zoom Line Chart', - subtitle: 'Simple line chart pan and zoom behaviors enabled', - childBuilder: LineAnimationZoomChart.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Simple Line Chart', + subtitle: 'With a single series and default line point highlighter', + childBuilder: SimpleLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Stacked Area Chart', + subtitle: 'Stacked area chart with three series', + childBuilder: StackedAreaLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Stacked Area Custom Color Chart', + subtitle: 'Stacked area chart with custom area skirt color', + childBuilder: StackedAreaCustomColorLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Area and Line Combo Chart', + subtitle: 'Combo chart with one line series and one area series', + childBuilder: AreaAndLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Points Line Chart', + subtitle: 'Line chart with points on a single series', + childBuilder: PointsLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Null Data Line Chart', + subtitle: 'With a single series and null measure values', + childBuilder: SimpleNullsLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Stacked Area with Nulls Chart', + subtitle: + 'Stacked area chart with three series and null measure values', + childBuilder: StackedAreaNullsLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Dash Pattern Line Chart', + subtitle: 'Line chart with dash patterns', + childBuilder: DashPatternLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Segments Line Chart', + subtitle: 'Line chart with changes of style for each line', + childBuilder: SegmentsLineChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Line Annotation Line Chart', + subtitle: 'Line chart with line annotations', + childBuilder: LineLineAnnotationChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Range Annotation Line Chart', + subtitle: 'Line chart with range annotations', + childBuilder: LineRangeAnnotationChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Range Annotation Margin Labels Line Chart', + subtitle: 'Line chart with range annotations with labels in margins', + childBuilder: LineRangeAnnotationMarginChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Pan and Zoom Line Chart', + subtitle: 'Simple line chart pan and zoom behaviors enabled', + childBuilder: LineAnimationZoomChart.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/line_chart/points.dart b/charts_flutter/example/lib/line_chart/points.dart index bd456d00b..74ad250d9 100644 --- a/charts_flutter/example/lib/line_chart/points.dart +++ b/charts_flutter/example/lib/line_chart/points.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PointsLineChart extends StatelessWidget { - const PointsLineChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory PointsLineChart.withSampleData() => PointsLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PointsLineChart.withRandomData() => PointsLineChart(_createRandomData()); + factory PointsLineChart.withRandomData() => + PointsLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -64,9 +64,11 @@ class PointsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, animate: animate, - defaultRenderer: charts.LineRendererConfig(includePoints: true),); + defaultRenderer: charts.LineRendererConfig(includePoints: true), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -91,7 +93,6 @@ class PointsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/range_annotation.dart b/charts_flutter/example/lib/line_chart/range_annotation.dart index 264d3d010..dd959730a 100644 --- a/charts_flutter/example/lib/line_chart/range_annotation.dart +++ b/charts_flutter/example/lib/line_chart/range_annotation.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineRangeAnnotationChart extends StatelessWidget { - - const LineRangeAnnotationChart(this.seriesList, {super.key, this.animate = false}); + const LineRangeAnnotationChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and range annotations. /// @@ -33,14 +36,15 @@ class LineRangeAnnotationChart extends StatelessWidget { /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. factory LineRangeAnnotationChart.withSampleData() => LineRangeAnnotationChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineRangeAnnotationChart.withRandomData() => LineRangeAnnotationChart(_createRandomData()); + factory LineRangeAnnotationChart.withRandomData() => + LineRangeAnnotationChart(_createRandomData()); final List> seriesList; final bool animate; @@ -69,26 +73,43 @@ class LineRangeAnnotationChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate, behaviors: [ - charts.RangeAnnotation([ - charts.RangeAnnotationSegment( - 0.5, 1.0, charts.RangeAnnotationAxisType.domain, - startLabel: 'Domain 1',), - charts.RangeAnnotationSegment( - 2, 4, charts.RangeAnnotationAxisType.domain, - endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200,), - charts.RangeAnnotationSegment( - 15, 20, charts.RangeAnnotationAxisType.measure, - startLabel: 'Measure 1 Start', - endLabel: 'Measure 1 End', - color: charts.MaterialPalette.gray.shade300,), - charts.RangeAnnotationSegment( - 35, 65, charts.RangeAnnotationAxisType.measure, - startLabel: 'Measure 2 Start', - endLabel: 'Measure 2 End', - color: charts.MaterialPalette.gray.shade400,), - ]), - ],); + Widget build(BuildContext context) => charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + charts.RangeAnnotation([ + charts.RangeAnnotationSegment( + 0.5, + 1.0, + charts.RangeAnnotationAxisType.domain, + startLabel: 'Domain 1', + ), + charts.RangeAnnotationSegment( + 2, + 4, + charts.RangeAnnotationAxisType.domain, + endLabel: 'Domain 2', + color: charts.MaterialPalette.gray.shade200, + ), + charts.RangeAnnotationSegment( + 15, + 20, + charts.RangeAnnotationAxisType.measure, + startLabel: 'Measure 1 Start', + endLabel: 'Measure 1 End', + color: charts.MaterialPalette.gray.shade300, + ), + charts.RangeAnnotationSegment( + 35, + 65, + charts.RangeAnnotationAxisType.measure, + startLabel: 'Measure 2 Start', + endLabel: 'Measure 2 End', + color: charts.MaterialPalette.gray.shade400, + ), + ]), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -112,7 +133,6 @@ class LineRangeAnnotationChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/range_annotation_margin.dart b/charts_flutter/example/lib/line_chart/range_annotation_margin.dart index 2d5a37630..86c30e417 100644 --- a/charts_flutter/example/lib/line_chart/range_annotation_margin.dart +++ b/charts_flutter/example/lib/line_chart/range_annotation_margin.dart @@ -25,23 +25,28 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineRangeAnnotationMarginChart extends StatelessWidget { - - const LineRangeAnnotationMarginChart(this.seriesList, {super.key, this.animate = false}); + const LineRangeAnnotationMarginChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and range annotations. /// /// The second annotation extends beyond the range of the series data, /// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag. /// This can be set to false to disable range extension. - factory LineRangeAnnotationMarginChart.withSampleData() => LineRangeAnnotationMarginChart( - _createSampleData(), - ); + factory LineRangeAnnotationMarginChart.withSampleData() => + LineRangeAnnotationMarginChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory LineRangeAnnotationMarginChart.withRandomData() => LineRangeAnnotationMarginChart(_createRandomData()); + factory LineRangeAnnotationMarginChart.withRandomData() => + LineRangeAnnotationMarginChart(_createRandomData()); final List> seriesList; final bool animate; @@ -70,42 +75,55 @@ class LineRangeAnnotationMarginChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, animate: animate, // Allow enough space in the left and right chart margins for the // annotations. layoutConfig: charts.LayoutConfig( - leftMarginSpec: charts.MarginSpec.fixedPixel(60), - topMarginSpec: charts.MarginSpec.fixedPixel(20), - rightMarginSpec: charts.MarginSpec.fixedPixel(60), - bottomMarginSpec: charts.MarginSpec.fixedPixel(20),), + leftMarginSpec: charts.MarginSpec.fixedPixel(60), + topMarginSpec: charts.MarginSpec.fixedPixel(20), + rightMarginSpec: charts.MarginSpec.fixedPixel(60), + bottomMarginSpec: charts.MarginSpec.fixedPixel(20), + ), behaviors: [ // Define one domain and two measure annotations configured to render // labels in the chart margins. - charts.RangeAnnotation([ - charts.RangeAnnotationSegment( + charts.RangeAnnotation( + [ + charts.RangeAnnotationSegment( 0.5, 1.0, charts.RangeAnnotationAxisType.domain, startLabel: 'D1 Start', endLabel: 'D1 End', labelAnchor: charts.AnnotationLabelAnchor.end, color: charts.MaterialPalette.gray.shade200, // Override the default vertical direction for domain labels. - labelDirection: charts.AnnotationLabelDirection.horizontal,), - charts.RangeAnnotationSegment( - 15, 20, charts.RangeAnnotationAxisType.measure, + labelDirection: charts.AnnotationLabelDirection.horizontal, + ), + charts.RangeAnnotationSegment( + 15, + 20, + charts.RangeAnnotationAxisType.measure, startLabel: 'M1 Start', endLabel: 'M1 End', labelAnchor: charts.AnnotationLabelAnchor.end, - color: charts.MaterialPalette.gray.shade300,), - charts.RangeAnnotationSegment( - 35, 65, charts.RangeAnnotationAxisType.measure, + color: charts.MaterialPalette.gray.shade300, + ), + charts.RangeAnnotationSegment( + 35, + 65, + charts.RangeAnnotationAxisType.measure, startLabel: 'M2 Start', endLabel: 'M2 End', labelAnchor: charts.AnnotationLabelAnchor.start, - color: charts.MaterialPalette.gray.shade400,), - ], defaultLabelPosition: charts.AnnotationLabelPosition.margin,), - ],); + color: charts.MaterialPalette.gray.shade400, + ), + ], + defaultLabelPosition: charts.AnnotationLabelPosition.margin, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -129,7 +147,6 @@ class LineRangeAnnotationMarginChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/segments.dart b/charts_flutter/example/lib/line_chart/segments.dart index 4afd9b6cc..bf93061ab 100644 --- a/charts_flutter/example/lib/line_chart/segments.dart +++ b/charts_flutter/example/lib/line_chart/segments.dart @@ -35,19 +35,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SegmentsLineChart extends StatelessWidget { - const SegmentsLineChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory SegmentsLineChart.withSampleData() => SegmentsLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SegmentsLineChart.withRandomData() => SegmentsLineChart(_createRandomData()); + factory SegmentsLineChart.withRandomData() => + SegmentsLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -98,8 +98,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? blue[1] : blue[0], + colorFn: (sales, _) => sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -109,8 +108,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? red[1] : red[0], + colorFn: (sales, _) => sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -120,8 +118,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? green[1] : green[0], + colorFn: (sales, _) => sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -133,10 +130,12 @@ class SegmentsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, defaultRenderer: charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate,); + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -183,8 +182,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Color Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? blue[1] : blue[0], + colorFn: (sales, _) => sales.year.isEven ? blue[1] : blue[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -194,8 +192,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Dash Pattern Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? red[1] : red[0], + colorFn: (sales, _) => sales.year.isEven ? red[1] : red[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -205,8 +202,7 @@ class SegmentsLineChart extends StatelessWidget { charts.Series( id: 'Stroke Width Change', // Light shade for even years, dark shade for odd. - colorFn: (sales, _) => - sales.year.isEven ? green[1] : green[0], + colorFn: (sales, _) => sales.year.isEven ? green[1] : green[0], dashPatternFn: (sales, _) => sales.dashPattern, strokeWidthPxFn: (sales, _) => sales.strokeWidthPx, domainFn: (sales, _) => sales.year, @@ -219,7 +215,6 @@ class SegmentsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales, this.dashPattern, this.strokeWidthPx); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/simple.dart b/charts_flutter/example/lib/line_chart/simple.dart index 6f818fb58..83900b9cc 100644 --- a/charts_flutter/example/lib/line_chart/simple.dart +++ b/charts_flutter/example/lib/line_chart/simple.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleLineChart extends StatelessWidget { - const SimpleLineChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory SimpleLineChart.withSampleData() => SimpleLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleLineChart.withRandomData() => SimpleLineChart(_createRandomData()); + factory SimpleLineChart.withRandomData() => + SimpleLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -64,7 +64,8 @@ class SimpleLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); + Widget build(BuildContext context) => + charts.LineChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -89,7 +90,6 @@ class SimpleLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/simple_nulls.dart b/charts_flutter/example/lib/line_chart/simple_nulls.dart index 39877412c..981628e25 100644 --- a/charts_flutter/example/lib/line_chart/simple_nulls.dart +++ b/charts_flutter/example/lib/line_chart/simple_nulls.dart @@ -28,19 +28,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleNullsLineChart extends StatelessWidget { - - const SimpleNullsLineChart(this.seriesList, {super.key, this.animate = false}); + const SimpleNullsLineChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. factory SimpleNullsLineChart.withSampleData() => SimpleNullsLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleNullsLineChart.withRandomData() => SimpleNullsLineChart(_createRandomData()); + factory SimpleNullsLineChart.withRandomData() => + SimpleNullsLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -105,7 +106,8 @@ class SimpleNullsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, animate: animate); + Widget build(BuildContext context) => + charts.LineChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -167,7 +169,6 @@ class SimpleNullsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int? sales; diff --git a/charts_flutter/example/lib/line_chart/stacked_area.dart b/charts_flutter/example/lib/line_chart/stacked_area.dart index dbb14a6e0..c1609dadb 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area.dart @@ -24,19 +24,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedAreaLineChart extends StatelessWidget { - - const StackedAreaLineChart(this.seriesList, {super.key, this.animate = false}); + const StackedAreaLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory StackedAreaLineChart.withSampleData() => StackedAreaLineChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaLineChart.withRandomData() => StackedAreaLineChart(_createRandomData()); + factory StackedAreaLineChart.withRandomData() => + StackedAreaLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -92,10 +96,12 @@ class StackedAreaLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, defaultRenderer: charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate,); + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -148,7 +154,6 @@ class StackedAreaLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart b/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart index 64db3e9ec..466335a65 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area_custom_color.dart @@ -28,19 +28,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedAreaCustomColorLineChart extends StatelessWidget { - - const StackedAreaCustomColorLineChart(this.seriesList, {super.key, this.animate = false}); + const StackedAreaCustomColorLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. - factory StackedAreaCustomColorLineChart.withSampleData() => StackedAreaCustomColorLineChart( - _createSampleData(), - ); + factory StackedAreaCustomColorLineChart.withSampleData() => + StackedAreaCustomColorLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaCustomColorLineChart.withRandomData() => StackedAreaCustomColorLineChart(_createRandomData()); + factory StackedAreaCustomColorLineChart.withRandomData() => + StackedAreaCustomColorLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -96,10 +101,12 @@ class StackedAreaCustomColorLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, defaultRenderer: charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate,); + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -163,7 +170,6 @@ class StackedAreaCustomColorLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart index 1b5c5f2d1..0e1306f1c 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart @@ -37,19 +37,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedAreaNullsLineChart extends StatelessWidget { - - const StackedAreaNullsLineChart(this.seriesList, {super.key, this.animate = false}); + const StackedAreaNullsLineChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.LineChart] with sample data and no transition. - factory StackedAreaNullsLineChart.withSampleData() => StackedAreaNullsLineChart( - _createSampleData(), - ); + factory StackedAreaNullsLineChart.withSampleData() => + StackedAreaNullsLineChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory StackedAreaNullsLineChart.withRandomData() => StackedAreaNullsLineChart(_createRandomData()); + factory StackedAreaNullsLineChart.withRandomData() => + StackedAreaNullsLineChart(_createRandomData()); final List> seriesList; final bool animate; @@ -114,10 +116,12 @@ class StackedAreaNullsLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.LineChart(seriesList, + Widget build(BuildContext context) => charts.LineChart( + seriesList, defaultRenderer: charts.LineRendererConfig(includeArea: true, stacked: true), - animate: animate,); + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -179,7 +183,6 @@ class StackedAreaNullsLineChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int? sales; diff --git a/charts_flutter/example/lib/main.dart b/charts_flutter/example/lib/main.dart index bb0fcd1dd..68cbb8e2c 100644 --- a/charts_flutter/example/lib/main.dart +++ b/charts_flutter/example/lib/main.dart @@ -34,7 +34,8 @@ class GalleryAppState extends State { debugShowCheckedModeBanner: false, title: defaultConfig.appName, theme: defaultConfig.theme, - home: Home(),); + home: Home(), + ); } void main() { diff --git a/charts_flutter/example/lib/pie_chart/auto_label.dart b/charts_flutter/example/lib/pie_chart/auto_label.dart index bce273dd9..78835c6d2 100644 --- a/charts_flutter/example/lib/pie_chart/auto_label.dart +++ b/charts_flutter/example/lib/pie_chart/auto_label.dart @@ -25,19 +25,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DonutAutoLabelChart extends StatelessWidget { - const DonutAutoLabelChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.PieChart] with sample data and no transition. factory DonutAutoLabelChart.withSampleData() => DonutAutoLabelChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory DonutAutoLabelChart.withRandomData() => DonutAutoLabelChart(_createRandomData()); + factory DonutAutoLabelChart.withRandomData() => + DonutAutoLabelChart(_createRandomData()); final List> seriesList; final bool animate; @@ -66,7 +66,8 @@ class DonutAutoLabelChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart( + seriesList, animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. @@ -84,8 +85,10 @@ class DonutAutoLabelChart extends StatelessWidget { // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), defaultRenderer: charts.ArcRendererConfig( - arcWidth: 60, - arcRendererDecorators: [charts.ArcLabelDecorator()],),); + arcWidth: 60, + arcRendererDecorators: [charts.ArcLabelDecorator()], + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -111,7 +114,6 @@ class DonutAutoLabelChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/pie_chart/donut.dart b/charts_flutter/example/lib/pie_chart/donut.dart index a627c6e82..ef5243e0f 100644 --- a/charts_flutter/example/lib/pie_chart/donut.dart +++ b/charts_flutter/example/lib/pie_chart/donut.dart @@ -24,13 +24,12 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DonutPieChart extends StatelessWidget { - const DonutPieChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.PieChart] with sample data and no transition. factory DonutPieChart.withSampleData() => DonutPieChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -63,11 +62,13 @@ class DonutPieChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart( + seriesList, animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. - defaultRenderer: charts.ArcRendererConfig(arcWidth: 60),); + defaultRenderer: charts.ArcRendererConfig(arcWidth: 60), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -91,7 +92,6 @@ class DonutPieChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/pie_chart/gauge.dart b/charts_flutter/example/lib/pie_chart/gauge.dart index b0c3e80c1..08781fda8 100644 --- a/charts_flutter/example/lib/pie_chart/gauge.dart +++ b/charts_flutter/example/lib/pie_chart/gauge.dart @@ -25,13 +25,12 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class GaugeChart extends StatelessWidget { - const GaugeChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.PieChart] with sample data and no transition. factory GaugeChart.withSampleData() => GaugeChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -64,13 +63,18 @@ class GaugeChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart( + seriesList, animate: animate, // Configure the width of the pie slices to 30px. The remaining space in // the chart will be left as a hole in the center. Adjust the start // angle and the arc length of the pie so it resembles a gauge. defaultRenderer: charts.ArcRendererConfig( - arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi,),); + arcWidth: 30, + startAngle: 4 / 5 * pi, + arcLength: 7 / 5 * pi, + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -94,7 +98,6 @@ class GaugeChart extends StatelessWidget { /// Sample data type. class GaugeSegment { - GaugeSegment(this.segment, this.size); final String segment; final int size; diff --git a/charts_flutter/example/lib/pie_chart/outside_label.dart b/charts_flutter/example/lib/pie_chart/outside_label.dart index 8b7a44960..36f4c83d0 100644 --- a/charts_flutter/example/lib/pie_chart/outside_label.dart +++ b/charts_flutter/example/lib/pie_chart/outside_label.dart @@ -24,19 +24,23 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PieOutsideLabelChart extends StatelessWidget { - - const PieOutsideLabelChart(this.seriesList, {super.key, this.animate = false}); + const PieOutsideLabelChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.PieChart] with sample data and no transition. factory PieOutsideLabelChart.withSampleData() => PieOutsideLabelChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory PieOutsideLabelChart.withRandomData() => PieOutsideLabelChart(_createRandomData()); + factory PieOutsideLabelChart.withRandomData() => + PieOutsideLabelChart(_createRandomData()); final List> seriesList; final bool animate; @@ -65,7 +69,8 @@ class PieOutsideLabelChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.PieChart(seriesList, + Widget build(BuildContext context) => charts.PieChart( + seriesList, animate: animate, // Add an [ArcLabelDecorator] configured to render labels outside of the // arc with a leader line. @@ -77,10 +82,14 @@ class PieOutsideLabelChart extends StatelessWidget { // new charts.ArcLabelDecorator( // insideLabelStyleSpec: new charts.TextStyleSpec(...), // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), - defaultRenderer: charts.ArcRendererConfig(arcRendererDecorators: [ - charts.ArcLabelDecorator( - labelPosition: charts.ArcLabelPosition.outside,), - ],),); + defaultRenderer: charts.ArcRendererConfig( + arcRendererDecorators: [ + charts.ArcLabelDecorator( + labelPosition: charts.ArcLabelPosition.outside, + ), + ], + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -106,7 +115,6 @@ class PieOutsideLabelChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/pie_chart/partial_pie.dart b/charts_flutter/example/lib/pie_chart/partial_pie.dart index 4175d15d7..4b742f116 100644 --- a/charts_flutter/example/lib/pie_chart/partial_pie.dart +++ b/charts_flutter/example/lib/pie_chart/partial_pie.dart @@ -26,7 +26,6 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Creates a partial pie chart where the data does not cover a full revolution. class PartialPieChart extends StatelessWidget { - const PartialPieChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [PartialPieChart] with sample data and no transition. @@ -70,7 +69,9 @@ class PartialPieChart extends StatelessWidget { domainFn: (sales, _) => sales.year, measureFn: (sales, _) => sales.sales, data: List.generate( - 4, (index) => LinearSales(index, random.nextInt(100)),), + 4, + (index) => LinearSales(index, random.nextInt(100)), + ), ), ]; } @@ -78,7 +79,6 @@ class PartialPieChart extends StatelessWidget { /// Represents linear sales data. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/pie_chart/pie_gallery.dart b/charts_flutter/example/lib/pie_chart/pie_gallery.dart index ae7d21a61..ee952db2f 100644 --- a/charts_flutter/example/lib/pie_chart/pie_gallery.dart +++ b/charts_flutter/example/lib/pie_chart/pie_gallery.dart @@ -19,43 +19,43 @@ import 'package:example/pie_chart/simple.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.pie_chart), - title: 'Simple Pie Chart', - subtitle: 'With a single series', - childBuilder: SimplePieChart.withRandomData, - ), - //TODO: - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Outside Label Pie Chart', - // subtitle: 'With a single series and labels outside the arcs', - // childBuilder: () => new PieOutsideLabelChart.withRandomData(), - // ), - const GalleryScaffold( - listTileIcon: Icon(Icons.pie_chart), - title: 'Partial Pie Chart', - subtitle: "That doesn't cover a full revolution", - childBuilder: PartialPieChart.withRandomData, - ), - //TODO: - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Simple Donut Chart', - // subtitle: 'With a single series and a hole in the middle', - // childBuilder: () => new DonutPieChart.withRandomData(), - // ), - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Auto Label Donut Chart', - // subtitle: - // 'With a single series, a hole in the middle, and auto-positioned labels', - // childBuilder: () => new DonutAutoLabelChart.withRandomData(), - // ), - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.pie_chart), - // title: 'Gauge Chart', - // subtitle: 'That doesn\'t cover a full revolution', - // childBuilder: () => new GaugeChart.withRandomData(), - // ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), + title: 'Simple Pie Chart', + subtitle: 'With a single series', + childBuilder: SimplePieChart.withRandomData, + ), + //TODO: + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Outside Label Pie Chart', + // subtitle: 'With a single series and labels outside the arcs', + // childBuilder: () => new PieOutsideLabelChart.withRandomData(), + // ), + const GalleryScaffold( + listTileIcon: Icon(Icons.pie_chart), + title: 'Partial Pie Chart', + subtitle: "That doesn't cover a full revolution", + childBuilder: PartialPieChart.withRandomData, + ), + //TODO: + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Simple Donut Chart', + // subtitle: 'With a single series and a hole in the middle', + // childBuilder: () => new DonutPieChart.withRandomData(), + // ), + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Auto Label Donut Chart', + // subtitle: + // 'With a single series, a hole in the middle, and auto-positioned labels', + // childBuilder: () => new DonutAutoLabelChart.withRandomData(), + // ), + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.pie_chart), + // title: 'Gauge Chart', + // subtitle: 'That doesn\'t cover a full revolution', + // childBuilder: () => new GaugeChart.withRandomData(), + // ), + ]; diff --git a/charts_flutter/example/lib/pie_chart/simple.dart b/charts_flutter/example/lib/pie_chart/simple.dart index 9facbcc59..f50edc73a 100644 --- a/charts_flutter/example/lib/pie_chart/simple.dart +++ b/charts_flutter/example/lib/pie_chart/simple.dart @@ -24,19 +24,19 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimplePieChart extends StatelessWidget { - const SimplePieChart(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.PieChart] with sample data and no transition. factory SimplePieChart.withSampleData() => SimplePieChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimplePieChart.withRandomData() => SimplePieChart(_createRandomData()); + factory SimplePieChart.withRandomData() => + SimplePieChart(_createRandomData()); final List> seriesList; final bool animate; @@ -63,7 +63,8 @@ class SimplePieChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.PieChart(seriesList, animate: animate); + Widget build(BuildContext context) => + charts.PieChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -87,7 +88,6 @@ class SimplePieChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales); final int year; final int sales; diff --git a/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart b/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart index 4a30db2dd..87b9efc2b 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/animation_zoom.dart @@ -25,19 +25,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class ScatterPlotAnimationZoomChart extends StatelessWidget { - - const ScatterPlotAnimationZoomChart(this.seriesList, {super.key, this.animate = false}); + const ScatterPlotAnimationZoomChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. - factory ScatterPlotAnimationZoomChart.withSampleData() => ScatterPlotAnimationZoomChart( - _createSampleData(), - ); + factory ScatterPlotAnimationZoomChart.withSampleData() => + ScatterPlotAnimationZoomChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ScatterPlotAnimationZoomChart.withRandomData() => ScatterPlotAnimationZoomChart(_createRandomData()); + factory ScatterPlotAnimationZoomChart.withRandomData() => + ScatterPlotAnimationZoomChart(_createRandomData()); final List> seriesList; final bool animate; @@ -80,11 +85,13 @@ class ScatterPlotAnimationZoomChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, animate: animate, behaviors: [ charts.PanAndZoomBehavior(), - ],); + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -131,7 +138,6 @@ class ScatterPlotAnimationZoomChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales, this.radius); final int year; final int sales; diff --git a/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart b/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart index d8e29b33f..450205189 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/bucketing_axis.dart @@ -29,19 +29,24 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class BucketingAxisScatterPlotChart extends StatelessWidget { - - const BucketingAxisScatterPlotChart(this.seriesList, {super.key, this.animate = false}); + const BucketingAxisScatterPlotChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. - factory BucketingAxisScatterPlotChart.withSampleData() => BucketingAxisScatterPlotChart( - _createSampleData(), - ); + factory BucketingAxisScatterPlotChart.withSampleData() => + BucketingAxisScatterPlotChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory BucketingAxisScatterPlotChart.withRandomData() => BucketingAxisScatterPlotChart(_createRandomData()); + factory BucketingAxisScatterPlotChart.withRandomData() => + BucketingAxisScatterPlotChart(_createRandomData()); final List> seriesList; final bool animate; @@ -56,114 +61,151 @@ class BucketingAxisScatterPlotChart extends StatelessWidget { // the "Other" series. final myFakeDesktopData = [ LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), + random.nextInt(100), + (random.nextInt(50) + 50) / 100, + makeRadius(6), + ), ]; final myFakeTabletData = [ LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), + random.nextInt(100), + (random.nextInt(50) + 50) / 100, + makeRadius(6), + ), ]; final myFakeMobileData = [ LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), + random.nextInt(100), + (random.nextInt(50) + 50) / 100, + makeRadius(6), + ), ]; final myFakeChromebookData = [ LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), + random.nextInt(100), + (random.nextInt(50) + 50) / 100, + makeRadius(6), + ), ]; final myFakeHomeData = [ LinearSales( - random.nextInt(100), (random.nextInt(50) + 50) / 100, makeRadius(6),), + random.nextInt(100), + (random.nextInt(50) + 50) / 100, + makeRadius(6), + ), ]; // Make sure that the "Other" series values are smaller. final myFakeOtherData = [ LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), LinearSales( - random.nextInt(100), random.nextInt(50) / 100, makeRadius(6),), + random.nextInt(100), + random.nextInt(50) / 100, + makeRadius(6), + ), ]; return [ charts.Series( - id: 'Desktop', - colorFn: (sales, _) => - charts.MaterialPalette.blue.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeDesktopData,), + id: 'Desktop', + colorFn: (sales, _) => charts.MaterialPalette.blue.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeDesktopData, + ), charts.Series( - id: 'Tablet', - colorFn: (sales, _) => - charts.MaterialPalette.red.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeTabletData,), + id: 'Tablet', + colorFn: (sales, _) => charts.MaterialPalette.red.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeTabletData, + ), charts.Series( - id: 'Mobile', - colorFn: (sales, _) => - charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeMobileData,), + id: 'Mobile', + colorFn: (sales, _) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeMobileData, + ), charts.Series( - id: 'Chromebook', - colorFn: (sales, _) => - charts.MaterialPalette.purple.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeChromebookData,), + id: 'Chromebook', + colorFn: (sales, _) => charts.MaterialPalette.purple.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeChromebookData, + ), charts.Series( - id: 'Home', - colorFn: (sales, _) => - charts.MaterialPalette.indigo.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeHomeData,), + id: 'Home', + colorFn: (sales, _) => charts.MaterialPalette.indigo.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeHomeData, + ), charts.Series( - id: 'Other', - colorFn: (sales, _) => - charts.MaterialPalette.gray.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeOtherData,), + id: 'Other', + colorFn: (sales, _) => charts.MaterialPalette.gray.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeOtherData, + ), ]; } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, // Set up a bucketing axis that will place all values below 0.1 (10%) // into a bucket at the bottom of the chart. // // Configure a tick count of 3 so that we get 100%, 50%, and the // threshold. primaryMeasureAxis: charts.BucketingAxisSpec( - threshold: 0.1, - tickProviderSpec: const charts.BucketingNumericTickProviderSpec( - desiredTickCount: 3,),), + threshold: 0.1, + tickProviderSpec: const charts.BucketingNumericTickProviderSpec( + desiredTickCount: 3, + ), + ), // Add a series legend to display the series names. behaviors: [ charts.SeriesLegend(position: charts.BehaviorPosition.end), ], - animate: animate,); + animate: animate, + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -198,60 +240,59 @@ class BucketingAxisScatterPlotChart extends StatelessWidget { return [ charts.Series( - id: 'Desktop', - colorFn: (sales, _) => - charts.MaterialPalette.blue.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeDesktopData,), + id: 'Desktop', + colorFn: (sales, _) => charts.MaterialPalette.blue.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeDesktopData, + ), charts.Series( - id: 'Tablet', - colorFn: (sales, _) => - charts.MaterialPalette.red.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeTabletData,), + id: 'Tablet', + colorFn: (sales, _) => charts.MaterialPalette.red.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeTabletData, + ), charts.Series( - id: 'Mobile', - colorFn: (sales, _) => - charts.MaterialPalette.green.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeMobileData,), + id: 'Mobile', + colorFn: (sales, _) => charts.MaterialPalette.green.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeMobileData, + ), charts.Series( - id: 'Chromebook', - colorFn: (sales, _) => - charts.MaterialPalette.purple.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeChromebookData,), + id: 'Chromebook', + colorFn: (sales, _) => charts.MaterialPalette.purple.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeChromebookData, + ), charts.Series( - id: 'Home', - colorFn: (sales, _) => - charts.MaterialPalette.indigo.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeHomeData,), + id: 'Home', + colorFn: (sales, _) => charts.MaterialPalette.indigo.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeHomeData, + ), charts.Series( - id: 'Other', - colorFn: (sales, _) => - charts.MaterialPalette.gray.shadeDefault, - domainFn: (sales, _) => sales.year, - measureFn: (sales, _) => sales.revenueShare, - radiusPxFn: (sales, _) => sales.radius, - data: myFakeOtherData,), + id: 'Other', + colorFn: (sales, _) => charts.MaterialPalette.gray.shadeDefault, + domainFn: (sales, _) => sales.year, + measureFn: (sales, _) => sales.revenueShare, + radiusPxFn: (sales, _) => sales.radius, + data: myFakeOtherData, + ), ]; } } /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.revenueShare, this.radius); final int year; final double revenueShare; diff --git a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart index 2edcdbd6b..f1e44acfc 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart @@ -24,19 +24,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class ComparisonPointsScatterPlotChart extends StatelessWidget { - - const ComparisonPointsScatterPlotChart(this.seriesList, {super.key, this.animate = false}); + const ComparisonPointsScatterPlotChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. - factory ComparisonPointsScatterPlotChart.withSampleData() => ComparisonPointsScatterPlotChart( - _createSampleData(), - ); + factory ComparisonPointsScatterPlotChart.withSampleData() => + ComparisonPointsScatterPlotChart( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ComparisonPointsScatterPlotChart.withRandomData() => ComparisonPointsScatterPlotChart(_createRandomData()); + factory ComparisonPointsScatterPlotChart.withRandomData() => + ComparisonPointsScatterPlotChart(_createRandomData()); final List> seriesList; final bool animate; @@ -92,19 +94,30 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { final salesLower = (sales * 0.8).round(); final salesUpper = sales; - return LinearSales(year, yearLower, yearUpper, sales, salesLower, - salesUpper, makeRadius(4),); + return LinearSales( + year, + yearLower, + yearUpper, + sales, + salesLower, + salesUpper, + makeRadius(4), + ); } // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, animate: animate, - defaultRenderer: - charts.PointRendererConfig(pointRendererDecorators: [ - charts.ComparisonPointsDecorator( - symbolRenderer: charts.CylinderSymbolRenderer(),), - ],),); + defaultRenderer: charts.PointRendererConfig( + pointRendererDecorators: [ + charts.ComparisonPointsDecorator( + symbolRenderer: charts.CylinderSymbolRenderer(), + ), + ], + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -151,9 +164,15 @@ class ComparisonPointsScatterPlotChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - - LinearSales(this.year, this.yearLower, this.yearUpper, this.sales, - this.salesLower, this.salesUpper, this.radius,); + LinearSales( + this.year, + this.yearLower, + this.yearUpper, + this.sales, + this.salesLower, + this.salesUpper, + this.radius, + ); final int year; final int yearLower; final int yearUpper; diff --git a/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart b/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart index f21e7866f..d62487820 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/scatter_plot_gallery.dart @@ -21,35 +21,36 @@ import 'package:example/scatter_plot_chart/simple.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.scatter_plot), - title: 'Simple Scatter Plot Chart', - subtitle: 'With a single series', - childBuilder: SimpleScatterPlotChart.withRandomData, - ), - //TODO: - // new GalleryScaffold( - // listTileIcon: new Icon(Icons.scatter_plot), - // title: 'Shapes Scatter Plot Chart', - // subtitle: 'With custom shapes', - // childBuilder: () => new ShapesScatterPlotChart.withRandomData(), - // ), - const GalleryScaffold( - listTileIcon: Icon(Icons.scatter_plot), - title: 'Comparison Points Scatter Plot Chart', - subtitle: 'Scatter plot chart with comparison points', - childBuilder: ComparisonPointsScatterPlotChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.scatter_plot), - title: 'Pan and Zoom Scatter Plot Chart', - subtitle: 'Simple scatter plot chart pan and zoom behaviors enabled', - childBuilder: ScatterPlotAnimationZoomChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.scatter_plot), - title: 'Bucketing Axis Scatter Plot Chart', - subtitle: 'Scatter plot with a measure axis that buckets values less ' 'than 10% into a single region below the draw area', - childBuilder: BucketingAxisScatterPlotChart.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), + title: 'Simple Scatter Plot Chart', + subtitle: 'With a single series', + childBuilder: SimpleScatterPlotChart.withRandomData, + ), + //TODO: + // new GalleryScaffold( + // listTileIcon: new Icon(Icons.scatter_plot), + // title: 'Shapes Scatter Plot Chart', + // subtitle: 'With custom shapes', + // childBuilder: () => new ShapesScatterPlotChart.withRandomData(), + // ), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), + title: 'Comparison Points Scatter Plot Chart', + subtitle: 'Scatter plot chart with comparison points', + childBuilder: ComparisonPointsScatterPlotChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), + title: 'Pan and Zoom Scatter Plot Chart', + subtitle: 'Simple scatter plot chart pan and zoom behaviors enabled', + childBuilder: ScatterPlotAnimationZoomChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.scatter_plot), + title: 'Bucketing Axis Scatter Plot Chart', + subtitle: 'Scatter plot with a measure axis that buckets values less ' + 'than 10% into a single region below the draw area', + childBuilder: BucketingAxisScatterPlotChart.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart index 503aa83ab..1d3985d72 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart @@ -36,19 +36,23 @@ import 'package:nimble_charts/flutter.dart' as charts; import 'package:nimble_charts/flutter.dart'; class ShapesScatterPlotChart extends StatelessWidget { - - const ShapesScatterPlotChart(this.seriesList, {super.key, this.animate = false}); + const ShapesScatterPlotChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory ShapesScatterPlotChart.withSampleData() => ShapesScatterPlotChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory ShapesScatterPlotChart.withRandomData() => ShapesScatterPlotChart(_createRandomData()); + factory ShapesScatterPlotChart.withRandomData() => + ShapesScatterPlotChart(_createRandomData()); final List> seriesList; final bool animate; @@ -59,33 +63,105 @@ class ShapesScatterPlotChart extends StatelessWidget { double makeRadius(int value) => (random.nextInt(value) + 2).toDouble(); final data = [ - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + 'circle', + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow circle, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - 'circle', null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + 'circle', + charts.MaterialPalette.white, + 2, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + 'circle', + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow circle, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2,), - LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), - null, null, null,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + 'circle', + charts.MaterialPalette.white, + 2, + ), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(6), + null, + null, + null, + ), // Render a hollow square, filled in with white. - LinearSales(random.nextInt(100), random.nextInt(100), - makeRadius(4) + 4, null, charts.MaterialPalette.white, 2,), + LinearSales( + random.nextInt(100), + random.nextInt(100), + makeRadius(4) + 4, + null, + charts.MaterialPalette.white, + 2, + ), ]; const maxMeasure = 100; @@ -114,7 +190,9 @@ class ShapesScatterPlotChart extends StatelessWidget { ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (index) => data[index].shape,) + charts.pointSymbolRendererFnKey, + (index) => data[index].shape, + ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; @@ -122,15 +200,18 @@ class ShapesScatterPlotChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, + Widget build(BuildContext context) => charts.ScatterPlotChart( + seriesList, animate: animate, // Configure the point renderer to have a map of custom symbol // renderers. - defaultRenderer: - charts.PointRendererConfig(customSymbolRenderers: { - 'circle': charts.CircleSymbolRenderer(), - 'rect': charts.RectSymbolRenderer(), - },),); + defaultRenderer: charts.PointRendererConfig( + customSymbolRenderers: { + 'circle': charts.CircleSymbolRenderer(), + 'rect': charts.RectSymbolRenderer(), + }, + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -140,7 +221,13 @@ class ShapesScatterPlotChart extends StatelessWidget { LinearSales(12, 75, 4, null, null, null), // Render a hollow circle, filled in with white. LinearSales( - 13, 225, 5, 'circle', charts.MaterialPalette.white, 2,), + 13, + 225, + 5, + 'circle', + charts.MaterialPalette.white, + 2, + ), LinearSales(16, 50, 4, null, null, null), LinearSales(24, 75, 3, null, null, null), LinearSales(25, 100, 3, 'circle', null, null), @@ -148,7 +235,13 @@ class ShapesScatterPlotChart extends StatelessWidget { LinearSales(37, 10, 4.5, null, null, null), // Render a hollow circle, filled in with white. LinearSales( - 45, 300, 8, 'circle', charts.MaterialPalette.white, 2,), + 45, + 300, + 8, + 'circle', + charts.MaterialPalette.white, + 2, + ), LinearSales(52, 15, 4, null, null, null), // Render a hollow square, filled in with white. LinearSales(56, 200, 7, null, charts.MaterialPalette.white, 2), @@ -181,7 +274,9 @@ class ShapesScatterPlotChart extends StatelessWidget { ) // Accessor function that associates each datum with a symbol renderer. ..setAttribute( - charts.pointSymbolRendererFnKey, (index) => data[index].shape,) + charts.pointSymbolRendererFnKey, + (index) => data[index].shape, + ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), ]; @@ -190,9 +285,14 @@ class ShapesScatterPlotChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - - LinearSales(this.year, this.sales, this.radius, this.shape, this.fillColor, - this.strokeWidth,); + LinearSales( + this.year, + this.sales, + this.radius, + this.shape, + this.fillColor, + this.strokeWidth, + ); final int year; final int sales; final double radius; diff --git a/charts_flutter/example/lib/scatter_plot_chart/simple.dart b/charts_flutter/example/lib/scatter_plot_chart/simple.dart index 41aa8695c..705f715b1 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/simple.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/simple.dart @@ -24,19 +24,20 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleScatterPlotChart extends StatelessWidget { - - const SimpleScatterPlotChart(this.seriesList, {super.key, this.animate = false}); + const SimpleScatterPlotChart(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory SimpleScatterPlotChart.withSampleData() => SimpleScatterPlotChart( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory SimpleScatterPlotChart.withRandomData() => SimpleScatterPlotChart(_createRandomData()); + factory SimpleScatterPlotChart.withRandomData() => + SimpleScatterPlotChart(_createRandomData()); final List> seriesList; final bool animate; @@ -88,7 +89,8 @@ class SimpleScatterPlotChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) => charts.ScatterPlotChart(seriesList, animate: animate); + Widget build(BuildContext context) => + charts.ScatterPlotChart(seriesList, animate: animate); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -137,7 +139,6 @@ class SimpleScatterPlotChart extends StatelessWidget { /// Sample linear data type. class LinearSales { - LinearSales(this.year, this.sales, this.radius); final int year; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart index 02999df32..a0ebb3d8d 100644 --- a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart +++ b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart @@ -27,19 +27,21 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesConfidenceInterval extends StatelessWidget { - - const TimeSeriesConfidenceInterval(this.seriesList, {super.key, this.animate = false}); + const TimeSeriesConfidenceInterval(this.seriesList, + {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. - factory TimeSeriesConfidenceInterval.withSampleData() => TimeSeriesConfidenceInterval( - _createSampleData(), - ); + factory TimeSeriesConfidenceInterval.withSampleData() => + TimeSeriesConfidenceInterval( + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. // It is used for creating random series data to demonstrate animation in // the example app only. - factory TimeSeriesConfidenceInterval.withRandomData() => TimeSeriesConfidenceInterval(_createRandomData()); + factory TimeSeriesConfidenceInterval.withRandomData() => + TimeSeriesConfidenceInterval(_createRandomData()); final List> seriesList; final bool animate; @@ -72,13 +74,13 @@ class TimeSeriesConfidenceInterval extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. - dateTimeFactory: const charts.LocalDateTimeFactory(), - ); + seriesList, + animate: animate, + // Optionally pass in a [DateTimeFactory] used by the chart. The factory + // should create the same type of [DateTime] as the data provided. If none + // specified, the default creates local date time. + dateTimeFactory: const charts.LocalDateTimeFactory(), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -107,7 +109,6 @@ class TimeSeriesConfidenceInterval extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; diff --git a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart index defb4bc81..e1b5d7f86 100644 --- a/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/symbol_annotation.dart @@ -191,7 +191,7 @@ class TimeSeriesSymbolAnnotationChart extends StatelessWidget { ), ], // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. + // should create the same type of [DateTime] as the data provided. // If none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart b/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart index d77b0a687..64b70282c 100644 --- a/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart +++ b/charts_flutter/example/lib/time_series_chart/time_series_gallery.dart @@ -25,53 +25,53 @@ import 'package:example/time_series_chart/with_bar_renderer.dart'; import 'package:flutter/material.dart'; List buildGallery() => [ - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Time Series Chart', - subtitle: 'Simple single time series chart', - childBuilder: SimpleTimeSeriesChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'End Points Axis Time Series Chart', - subtitle: 'Time series chart with an end points axis', - childBuilder: EndPointsAxisTimeSeriesChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Line Annotation on Time Series Chart', - subtitle: 'Time series chart with future line annotation', - childBuilder: TimeSeriesLineAnnotationChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Range Annotation on Time Series Chart', - subtitle: 'Time series chart with future range annotation', - childBuilder: TimeSeriesRangeAnnotationChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Range Annotation Margin Labels on Time Series Chart', - subtitle: - 'Time series chart with range annotations with labels in margins', - childBuilder: TimeSeriesRangeAnnotationMarginChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Symbol Annotation Time Series Chart', - subtitle: 'Time series chart with annotation data below the draw area', - childBuilder: TimeSeriesSymbolAnnotationChart.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Time Series Chart with Bars', - subtitle: 'Time series chart using the bar renderer', - childBuilder: TimeSeriesBar.withRandomData, - ), - const GalleryScaffold( - listTileIcon: Icon(Icons.show_chart), - title: 'Time Series Chart with Confidence Interval', - subtitle: 'Draws area around the confidence interval', - childBuilder: TimeSeriesConfidenceInterval.withRandomData, - ), - ]; + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Time Series Chart', + subtitle: 'Simple single time series chart', + childBuilder: SimpleTimeSeriesChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'End Points Axis Time Series Chart', + subtitle: 'Time series chart with an end points axis', + childBuilder: EndPointsAxisTimeSeriesChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Line Annotation on Time Series Chart', + subtitle: 'Time series chart with future line annotation', + childBuilder: TimeSeriesLineAnnotationChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Range Annotation on Time Series Chart', + subtitle: 'Time series chart with future range annotation', + childBuilder: TimeSeriesRangeAnnotationChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Range Annotation Margin Labels on Time Series Chart', + subtitle: + 'Time series chart with range annotations with labels in margins', + childBuilder: TimeSeriesRangeAnnotationMarginChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Symbol Annotation Time Series Chart', + subtitle: 'Time series chart with annotation data below the draw area', + childBuilder: TimeSeriesSymbolAnnotationChart.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Time Series Chart with Bars', + subtitle: 'Time series chart using the bar renderer', + childBuilder: TimeSeriesBar.withRandomData, + ), + const GalleryScaffold( + listTileIcon: Icon(Icons.show_chart), + title: 'Time Series Chart with Confidence Interval', + subtitle: 'Draws area around the confidence interval', + childBuilder: TimeSeriesConfidenceInterval.withRandomData, + ), + ]; diff --git a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart index a542b25e1..a780f553d 100644 --- a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart +++ b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart @@ -24,13 +24,12 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesBar extends StatelessWidget { - const TimeSeriesBar(this.seriesList, {super.key, this.animate = false}); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory TimeSeriesBar.withSampleData() => TimeSeriesBar( - _createSampleData(), - ); + _createSampleData(), + ); // EXCLUDE_FROM_GALLERY_DOCS_START // This section is excluded from being copied to the gallery. @@ -82,19 +81,19 @@ class TimeSeriesBar extends StatelessWidget { @override Widget build(BuildContext context) => charts.TimeSeriesChart( - seriesList, - animate: animate, - // Set the default renderer to a bar renderer. - // This can also be one of the custom renderers of the time series chart. - defaultRenderer: charts.BarRendererConfig(), - // It is recommended that default interactions be turned off if using bar - // renderer, because the line point highlighter is the default for time - // series chart. - defaultInteractions: false, - // If default interactions were removed, optionally add select nearest - // and the domain highlighter that are typical for bar charts. - behaviors: [charts.SelectNearest(), charts.DomainHighlighter()], - ); + seriesList, + animate: animate, + // Set the default renderer to a bar renderer. + // This can also be one of the custom renderers of the time series chart. + defaultRenderer: charts.BarRendererConfig(), + // It is recommended that default interactions be turned off if using bar + // renderer, because the line point highlighter is the default for time + // series chart. + defaultInteractions: false, + // If default interactions were removed, optionally add select nearest + // and the domain highlighter that are typical for bar charts. + behaviors: [charts.SelectNearest(), charts.DomainHighlighter()], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { @@ -136,7 +135,6 @@ class TimeSeriesBar extends StatelessWidget { /// Sample time series data type. class TimeSeriesSales { - TimeSeriesSales(this.time, this.sales); final DateTime time; final int sales; From f1b41ab7feea7f89bdd25f4c3e78f743d67a2afc Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Wed, 18 Sep 2024 06:10:26 +1000 Subject: [PATCH 4/9] fixes --- .../example/lib/axes/bar_secondary_axis.dart | 7 +- .../lib/axes/custom_measure_tick_count.dart | 7 +- .../axes/hidden_ticks_and_labels_axis.dart | 7 +- .../lib/axes/statically_provided_ticks.dart | 9 +- .../example/lib/bar_chart/bar_gallery.dart | 3 +- .../grouped_stacked_weight_pattern.dart | 4 +- .../lib/behaviors/behaviors_gallery.dart | 3 +- .../lib/behaviors/initial_hint_animation.dart | 9 +- .../lib/behaviors/initial_selection.dart | 3 +- .../percent_of_domain_by_category.dart | 7 +- .../lib/behaviors/percent_of_series.dart | 7 +- .../behaviors/selection_bar_highlight.dart | 7 +- .../behaviors/selection_callback_example.dart | 7 +- .../behaviors/selection_line_highlight.dart | 86 +++++++++-------- ...selection_line_highlight_custom_shape.dart | 92 ++++++++++--------- .../selection_scatter_plot_highlight.dart | 7 +- .../lib/behaviors/selection_user_managed.dart | 7 +- .../sliding_viewport_on_selection.dart | 9 +- .../lib/combo_chart/date_time_line_point.dart | 4 +- .../lib/combo_chart/numeric_line_point.dart | 7 +- .../lib/combo_chart/ordinal_bar_line.dart | 11 ++- .../lib/combo_chart/scatter_plot_line.dart | 7 +- .../example/lib/gallery_scaffold.dart | 7 +- .../example/lib/i18n/rtl_bar_chart.dart | 47 +++++----- .../example/lib/i18n/rtl_line_chart.dart | 39 ++++---- .../example/lib/i18n/rtl_series_legend.dart | 69 +++++++------- .../legends/datum_legend_with_measures.dart | 9 +- .../legends/default_hidden_series_legend.dart | 11 ++- .../lib/legends/legend_custom_symbol.dart | 7 +- .../lib/legends/simple_series_legend.dart | 4 +- .../lib/line_chart/animation_zoom.dart | 7 +- .../example/lib/line_chart/dash_pattern.dart | 7 +- .../lib/line_chart/line_annotation.dart | 7 +- .../example/lib/line_chart/simple_nulls.dart | 7 +- .../lib/line_chart/stacked_area_nulls.dart | 7 +- .../example/lib/pie_chart/pie_gallery.dart | 3 +- .../scatter_plot_chart/comparison_points.dart | 7 +- .../lib/scatter_plot_chart/simple.dart | 7 +- .../confidence_interval.dart | 11 ++- .../time_series_chart/end_points_axis.dart | 9 +- .../time_series_chart/line_annotation.dart | 7 +- .../example/lib/time_series_chart/simple.dart | 4 +- .../time_series_chart/with_bar_renderer.dart | 2 + charts_flutter/example/pubspec.yaml | 11 ++- 44 files changed, 356 insertions(+), 243 deletions(-) diff --git a/charts_flutter/example/lib/axes/bar_secondary_axis.dart b/charts_flutter/example/lib/axes/bar_secondary_axis.dart index 9bb057dd0..ed4834934 100644 --- a/charts_flutter/example/lib/axes/bar_secondary_axis.dart +++ b/charts_flutter/example/lib/axes/bar_secondary_axis.dart @@ -37,8 +37,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Note: primary and secondary may flip left and right positioning when /// RTL.flipAxisLocations is set. class BarChartWithSecondaryAxis extends StatelessWidget { - const BarChartWithSecondaryAxis(this.seriesList, - {super.key, this.animate = false}); + const BarChartWithSecondaryAxis( + this.seriesList, { + super.key, + this.animate = false, + }); factory BarChartWithSecondaryAxis.withSampleData() => BarChartWithSecondaryAxis( diff --git a/charts_flutter/example/lib/axes/custom_measure_tick_count.dart b/charts_flutter/example/lib/axes/custom_measure_tick_count.dart index d2d6a925f..fe4d08141 100644 --- a/charts_flutter/example/lib/axes/custom_measure_tick_count.dart +++ b/charts_flutter/example/lib/axes/custom_measure_tick_count.dart @@ -28,8 +28,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class CustomMeasureTickCount extends StatelessWidget { - const CustomMeasureTickCount(this.seriesList, - {super.key, this.animate = false}); + const CustomMeasureTickCount( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory CustomMeasureTickCount.withSampleData() => CustomMeasureTickCount( diff --git a/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart b/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart index 036d036da..40ebc4b9f 100644 --- a/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart +++ b/charts_flutter/example/lib/axes/hidden_ticks_and_labels_axis.dart @@ -24,8 +24,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of hiding both axis. class HiddenTicksAndLabelsAxis extends StatelessWidget { - const HiddenTicksAndLabelsAxis(this.seriesList, - {super.key, this.animate = false}); + const HiddenTicksAndLabelsAxis( + this.seriesList, { + super.key, + this.animate = false, + }); factory HiddenTicksAndLabelsAxis.withSampleData() => HiddenTicksAndLabelsAxis( _createSampleData(), diff --git a/charts_flutter/example/lib/axes/statically_provided_ticks.dart b/charts_flutter/example/lib/axes/statically_provided_ticks.dart index ce9d7bf9f..607f8f166 100644 --- a/charts_flutter/example/lib/axes/statically_provided_ticks.dart +++ b/charts_flutter/example/lib/axes/statically_provided_ticks.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of axis using statically provided ticks. library; @@ -36,8 +38,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// For datetime axis, the [charts.StaticDateTimeTickProviderSpec] can be used by /// passing in a list of ticks defined with [charts.TickSpec] of datetime. class StaticallyProvidedTicks extends StatelessWidget { - const StaticallyProvidedTicks(this.seriesList, - {super.key, this.animate = false}); + const StaticallyProvidedTicks( + this.seriesList, { + super.key, + this.animate = false, + }); factory StaticallyProvidedTicks.withSampleData() => StaticallyProvidedTicks( _createSampleData(), diff --git a/charts_flutter/example/lib/bar_chart/bar_gallery.dart b/charts_flutter/example/lib/bar_chart/bar_gallery.dart index 6db172122..7aba04937 100644 --- a/charts_flutter/example/lib/bar_chart/bar_gallery.dart +++ b/charts_flutter/example/lib/bar_chart/bar_gallery.dart @@ -70,7 +70,8 @@ List buildGallery() => [ listTileIcon: Icon(Icons.insert_chart), title: 'Grouped Bar Single Target Line Chart', subtitle: - 'Grouped bar target line chart with multiple series and a single target', + 'Grouped bar target line chart with ' + 'multiple series and a single target', childBuilder: GroupedBarSingleTargetLineChart.withRandomData, ), const GalleryScaffold( diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart index 3e057042e..3cf74fd33 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart @@ -147,8 +147,8 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { // Configure the bar renderer in grouped stacked rendering mode with a // custom weight pattern. // - // The first stack of bars in each group is configured to be twice as wide - // as the second stack of bars in each group. + // The first stack of bars in each group is configured to be twice as + // wide as the second stack of bars in each group. defaultRenderer: charts.BarRendererConfig( groupingType: charts.BarGroupingType.groupedStacked, weightPattern: [2, 1], diff --git a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart index e2c4de244..343d44c9a 100644 --- a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart +++ b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart @@ -53,7 +53,8 @@ List buildGallery() => [ // listTileIcon: new Icon(Icons.flag), // title: 'Selection Scatter Plot Highlight', // subtitle: 'Scatter plot chart with tap and drag activation', - // childBuilder: () => new SelectionScatterPlotHighlight.withRandomData(), + // childBuilder: () => + //new SelectionScatterPlotHighlight.withRandomData(), // ), const GalleryScaffold( listTileIcon: Icon(Icons.flag), diff --git a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart index 577b87e53..664a6f2a5 100644 --- a/charts_flutter/example/lib/behaviors/initial_hint_animation.dart +++ b/charts_flutter/example/lib/behaviors/initial_hint_animation.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of initial hint animation behavior. /// /// To see the animation, please run the example app and select @@ -50,8 +52,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class InitialHintAnimation extends StatelessWidget { - const InitialHintAnimation(this.seriesList, - {super.key, this.animate = false}); + const InitialHintAnimation( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory InitialHintAnimation.withSampleData() => InitialHintAnimation( diff --git a/charts_flutter/example/lib/behaviors/initial_selection.dart b/charts_flutter/example/lib/behaviors/initial_selection.dart index 95fccc4f3..f8e568bd7 100644 --- a/charts_flutter/example/lib/behaviors/initial_selection.dart +++ b/charts_flutter/example/lib/behaviors/initial_selection.dart @@ -86,7 +86,8 @@ class InitialSelection extends StatelessWidget { // // [BarChart] by default includes behaviors [SelectNearest] and // [DomainHighlighter]. So this behavior shows the initial selection - // highlighted and when another datum is tapped, the selection changes. + // highlighted and when another datum is tapped, the selection changes + // . charts.InitialSelection( selectedDataConfig: [ charts.SeriesDatumConfig('Sales', '2016'), diff --git a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart index 111e93c55..95377e80e 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_domain_by_category.dart @@ -27,8 +27,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfDomainByCategoryBarChart extends StatelessWidget { - const PercentOfDomainByCategoryBarChart(this.seriesList, - {super.key, this.animate = false}); + const PercentOfDomainByCategoryBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); factory PercentOfDomainByCategoryBarChart.withSampleData() => PercentOfDomainByCategoryBarChart( diff --git a/charts_flutter/example/lib/behaviors/percent_of_series.dart b/charts_flutter/example/lib/behaviors/percent_of_series.dart index 155184ad6..5945541e1 100644 --- a/charts_flutter/example/lib/behaviors/percent_of_series.dart +++ b/charts_flutter/example/lib/behaviors/percent_of_series.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class PercentOfSeriesBarChart extends StatelessWidget { - const PercentOfSeriesBarChart(this.seriesList, - {super.key, this.animate = false}); + const PercentOfSeriesBarChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a stacked [charts.BarChart] with sample data and no transition. factory PercentOfSeriesBarChart.withSampleData() => PercentOfSeriesBarChart( diff --git a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart index f4f9acbab..7089a913c 100644 --- a/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_bar_highlight.dart @@ -20,8 +20,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionBarHighlight extends StatelessWidget { - const SelectionBarHighlight(this.seriesList, - {super.key, this.animate = false}); + const SelectionBarHighlight( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory SelectionBarHighlight.withSampleData() => SelectionBarHighlight( diff --git a/charts_flutter/example/lib/behaviors/selection_callback_example.dart b/charts_flutter/example/lib/behaviors/selection_callback_example.dart index 4f1b4f07f..dc5e56266 100644 --- a/charts_flutter/example/lib/behaviors/selection_callback_example.dart +++ b/charts_flutter/example/lib/behaviors/selection_callback_example.dart @@ -38,8 +38,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionCallbackExample extends StatefulWidget { - const SelectionCallbackExample(this.seriesList, - {super.key, this.animate = false}); + const SelectionCallbackExample( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory SelectionCallbackExample.withSampleData() => SelectionCallbackExample( diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart index 75374d4f7..d80e09f10 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START +// ignore_for_file: lines_longer_than_80_chars + import 'dart:math'; import 'package:flutter/material.dart'; @@ -20,8 +22,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionLineHighlight extends StatelessWidget { - const SelectionLineHighlight(this.seriesList, - {super.key, this.animate = false}); + const SelectionLineHighlight( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory SelectionLineHighlight.withSampleData() => SelectionLineHighlight( @@ -60,44 +65,45 @@ class SelectionLineHighlight extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // This is just a simple line chart with a behavior that highlights the - // selected points along the lines. A point will be drawn at the selected - // datum's x,y coordinate, and a vertical follow line will be drawn through - // it. - // - // A [Charts.LinePointHighlighter] behavior is added manually to enable the - // highlighting effect. - // - // As an alternative, [defaultInteractions] can be set to true to include - // the default chart interactions, including a LinePointHighlighter. - return charts.LineChart( - seriesList, - animate: animate, - behaviors: [ - // Optional - Configures a [LinePointHighlighter] behavior with a - // vertical follow line. A vertical follow line is included by - // default, but is shown here as an example configuration. - // - // By default, the line has default dash pattern of [1,3]. This can be - // set by providing a [dashPattern] or it can be turned off by passing in - // an empty list. An empty list is necessary because passing in a null - // value will be treated the same as not passing in a value at all. - charts.LinePointHighlighter( - showHorizontalFollowLine: - charts.LinePointHighlighterFollowLineType.none, - showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest, - ), - // Optional - By default, select nearest is configured to trigger - // with tap so that a user can have pan/zoom behavior and line point - // highlighter. Changing the trigger to tap and drag allows the - // highlighter to follow the dragging gesture but it is not - // recommended to be used when pan/zoom behavior is enabled. - charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), - ], - ); - } + Widget build(BuildContext context) => + // This is just a simple line chart with a behavior that highlights the + // selected points along the lines. A point will be drawn at the selected + // datum's x,y coordinate, and a vertical follow line will be drawn through + // it. + // + // A [Charts.LinePointHighlighter] behavior is added manually to enable the + // highlighting effect. + // + // As an alternative, [defaultInteractions] can be set to true to include + // the default chart interactions, including a LinePointHighlighter. + charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + // Optional - Configures a [LinePointHighlighter] behavior with a + // vertical follow line. A vertical follow line is included by + // default, but is shown here as an example configuration. + // + // By default, the line has default dash pattern of [1,3]. This can be + // set by providing a [dashPattern] or it can be turned off by passing in + // an empty list. An empty list is necessary because passing in a null + // value will be treated the same as not passing in a value at all. + charts.LinePointHighlighter( + showHorizontalFollowLine: + charts.LinePointHighlighterFollowLineType.none, + showVerticalFollowLine: + charts.LinePointHighlighterFollowLineType.nearest, + ), + // Optional - By default, select nearest is configured to trigger + // with tap so that a user can have pan/zoom behavior and line point + // highlighter. Changing the trigger to tap and drag allows the + // highlighter to follow the dragging gesture but it is not + // recommended to be used when pan/zoom behavior is enabled. + charts.SelectNearest( + eventTrigger: charts.SelectionTrigger.tapAndDrag, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart index 09ebe493d..eb14302c8 100644 --- a/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart +++ b/charts_flutter/example/lib/behaviors/selection_line_highlight_custom_shape.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START +// ignore_for_file: lines_longer_than_80_chars + import 'dart:math'; import 'package:flutter/material.dart'; @@ -20,8 +22,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionLineHighlightCustomShape extends StatelessWidget { - const SelectionLineHighlightCustomShape(this.seriesList, - {super.key, this.animate = false}); + const SelectionLineHighlightCustomShape( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory SelectionLineHighlightCustomShape.withSampleData() => @@ -61,47 +66,48 @@ class SelectionLineHighlightCustomShape extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // This is a simple line chart with a behavior that highlights hovered - // lines. A hollow rectangular shape will be drawn at the hovered datum's - // x,y coordinate, and a vertical follow line will be drawn through it. - // - // A [Charts.LinePointHighlighter] behavior is added manually to enable the - // highlighting effect. - // - // As an alternative, [defaultInteractions] can be set to true to include - // the default chart interactions, including a LinePointHighlighter. - return charts.LineChart( - seriesList, - animate: animate, - behaviors: [ - // Optional - Configures a [LinePointHighlighter] behavior with a - // vertical follow line. A vertical follow line is included by - // default, but is shown here as an example configuration. - // - // By default, the line has default dash pattern of [1,3]. This can be - // set by providing a [dashPattern] or it can be turned off by passing in - // an empty list. An empty list is necessary because passing in a null - // value will be treated the same as not passing in a value at all. - // - // The symbol renderer is configured to render a hollow shape, for - // demonstration. - charts.LinePointHighlighter( - showHorizontalFollowLine: - charts.LinePointHighlighterFollowLineType.none, - showVerticalFollowLine: - charts.LinePointHighlighterFollowLineType.nearest, - symbolRenderer: charts.RectSymbolRenderer(isSolid: false), - ), - // Optional - By default, select nearest is configured to trigger - // with tap so that a user can have pan/zoom behavior and line point - // highlighter. Changing the trigger to tap and drag allows the - // highlighter to follow the dragging gesture but it is not - // recommended to be used when pan/zoom behavior is enabled. - charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag), - ], - ); - } + Widget build(BuildContext context) => + // This is a simple line chart with a behavior that highlights hovered + // lines. A hollow rectangular shape will be drawn at the hovered datum's + // x,y coordinate, and a vertical follow line will be drawn through it. + // + // A [Charts.LinePointHighlighter] behavior is added manually to enable the + // highlighting effect. + // + // As an alternative, [defaultInteractions] can be set to true to include + // the default chart interactions, including a LinePointHighlighter. + charts.LineChart( + seriesList, + animate: animate, + behaviors: [ + // Optional - Configures a [LinePointHighlighter] behavior with a + // vertical follow line. A vertical follow line is included by + // default, but is shown here as an example configuration. + // + // By default, the line has default dash pattern of [1,3]. This can be + // set by providing a [dashPattern] or it can be turned off by passing in + // an empty list. An empty list is necessary because passing in a null + // value will be treated the same as not passing in a value at all. + // + // The symbol renderer is configured to render a hollow shape, for + // demonstration. + charts.LinePointHighlighter( + showHorizontalFollowLine: + charts.LinePointHighlighterFollowLineType.none, + showVerticalFollowLine: + charts.LinePointHighlighterFollowLineType.nearest, + symbolRenderer: charts.RectSymbolRenderer(isSolid: false), + ), + // Optional - By default, select nearest is configured to trigger + // with tap so that a user can have pan/zoom behavior and line point + // highlighter. Changing the trigger to tap and drag allows the + // highlighter to follow the dragging gesture but it is not + // recommended to be used when pan/zoom behavior is enabled. + charts.SelectNearest( + eventTrigger: charts.SelectionTrigger.tapAndDrag, + ), + ], + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart index b5ad9212d..9a4a7351b 100644 --- a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart @@ -41,8 +41,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionScatterPlotHighlight extends StatelessWidget { - const SelectionScatterPlotHighlight(this.seriesList, - {super.key, this.animate = false}); + const SelectionScatterPlotHighlight( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory SelectionScatterPlotHighlight.withSampleData() => diff --git a/charts_flutter/example/lib/behaviors/selection_user_managed.dart b/charts_flutter/example/lib/behaviors/selection_user_managed.dart index 5f57b0e95..ef5092950 100644 --- a/charts_flutter/example/lib/behaviors/selection_user_managed.dart +++ b/charts_flutter/example/lib/behaviors/selection_user_managed.dart @@ -32,8 +32,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SelectionUserManaged extends StatefulWidget { - const SelectionUserManaged(this.seriesList, - {super.key, this.animate = false}); + const SelectionUserManaged( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory SelectionUserManaged.withSampleData() => SelectionUserManaged( diff --git a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart index 08eacccae..308b245fb 100644 --- a/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart +++ b/charts_flutter/example/lib/behaviors/sliding_viewport_on_selection.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of the chart behavior that centers the viewport on domain selection. library; @@ -24,8 +26,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SlidingViewportOnSelection extends StatelessWidget { - const SlidingViewportOnSelection(this.seriesList, - {super.key, this.animate = false}); + const SlidingViewportOnSelection( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.BarChart] with sample data and no transition. factory SlidingViewportOnSelection.withSampleData() => diff --git a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart index 3e5389b1b..72652e28b 100644 --- a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart @@ -122,8 +122,8 @@ class DateTimeComboLinePointChart extends StatelessWidget { ), ], // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. + // should create the same type of [DateTime] as the data provided. If + // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart index 083f35e0b..c5e5947df 100644 --- a/charts_flutter/example/lib/combo_chart/numeric_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/numeric_line_point.dart @@ -30,8 +30,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class NumericComboLinePointChart extends StatelessWidget { - const NumericComboLinePointChart(this.seriesList, - {super.key, this.animate = false}); + const NumericComboLinePointChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory NumericComboLinePointChart.withSampleData() => diff --git a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart index 3bc4a259c..ea386a774 100644 --- a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart +++ b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class OrdinalComboBarLineChart extends StatelessWidget { - const OrdinalComboBarLineChart(this.seriesList, - {super.key, this.animate = false}); + const OrdinalComboBarLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); factory OrdinalComboBarLineChart.withSampleData() => OrdinalComboBarLineChart( _createSampleData(), @@ -101,8 +104,8 @@ class OrdinalComboBarLineChart extends StatelessWidget { defaultRenderer: charts.BarRendererConfig( groupingType: charts.BarGroupingType.grouped, ), - // Custom renderer configuration for the line series. This will be used for - // any series that does not define a rendererIdKey. + // Custom renderer configuration for the line series. This will be used + // for any series that does not define a rendererIdKey. customSeriesRenderers: [ charts.LineRendererConfig( // ID used to link series to this renderer. diff --git a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart index e4d39fae8..4b833975a 100644 --- a/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart +++ b/charts_flutter/example/lib/combo_chart/scatter_plot_line.dart @@ -25,8 +25,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class ScatterPlotComboLineChart extends StatelessWidget { - const ScatterPlotComboLineChart(this.seriesList, - {super.key, this.animate = false}); + const ScatterPlotComboLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory ScatterPlotComboLineChart.withSampleData() => diff --git a/charts_flutter/example/lib/gallery_scaffold.dart b/charts_flutter/example/lib/gallery_scaffold.dart index 204e967f7..036b15797 100644 --- a/charts_flutter/example/lib/gallery_scaffold.dart +++ b/charts_flutter/example/lib/gallery_scaffold.dart @@ -38,8 +38,11 @@ class GalleryScaffold extends StatefulWidget { leading: listTileIcon, title: Text(title), subtitle: Text(subtitle), - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (_) => this)); + onTap: () async { + await Navigator.push( + context, + MaterialPageRoute(builder: (_) => this), + ); }, ); diff --git a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart index 4d541a565..dec414102 100644 --- a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart @@ -63,30 +63,29 @@ class RTLBarChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // Charts will determine if RTL is enabled by checking the directionality by - // requesting Directionality.of(context). This returns the text direction - // from the closest instance of that encloses the context passed to build - // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This - // means that the directionality widget does not have to directly wrap each - // chart. It is show here as an example only. - // - // By default, when a chart detects RTL: - // Measure axis positions are flipped. Primary measure axis is on the right - // and the secondary measure axis is on the left (when used). - // Domain axis' first domain starts on the right and grows left. - // - // Optionally, [RTLSpec] can be passed in when creating the chart to specify - // chart display settings in RTL mode. - return Directionality( - textDirection: TextDirection.rtl, - child: charts.BarChart( - seriesList, - animate: animate, - vertical: false, - ), - ); - } + Widget build(BuildContext context) => + // Charts will determine if RTL is enabled by checking the directionality by + // requesting Directionality.of(context). This returns the text direction + // from the closest instance of that encloses the context passed to build + // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This + // means that the directionality widget does not have to directly wrap each + // chart. It is show here as an example only. + // + // By default, when a chart detects RTL: + // Measure axis positions are flipped. Primary measure axis is on the right + // and the secondary measure axis is on the left (when used). + // Domain axis' first domain starts on the right and grows left. + // + // Optionally, [RTLSpec] can be passed in when creating the chart to specify + // chart display settings in RTL mode. + Directionality( + textDirection: TextDirection.rtl, + child: charts.BarChart( + seriesList, + animate: animate, + vertical: false, + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/i18n/rtl_line_chart.dart b/charts_flutter/example/lib/i18n/rtl_line_chart.dart index 7f72db6db..ec362a3a9 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_chart.dart @@ -63,26 +63,25 @@ class RTLLineChart extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // Charts will determine if RTL is enabled by checking the directionality by - // requesting Directionality.of(context). This returns the text direction - // from the closest instance of that encloses the context passed to build - // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This - // means that the directionality widget does not have to directly wrap each - // chart. It is show here as an example only. - // - // By default, when a chart detects RTL: - // Measure axis positions are flipped. Primary measure axis is on the right - // and the secondary measure axis is on the left (when used). - // Domain axis' first domain starts on the right and grows left. - return Directionality( - textDirection: TextDirection.rtl, - child: charts.LineChart( - seriesList, - animate: animate, - ), - ); - } + Widget build(BuildContext context) => + // Charts will determine if RTL is enabled by checking the directionality by + // requesting Directionality.of(context). This returns the text direction + // from the closest instance of that encloses the context passed to build + // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This + // means that the directionality widget does not have to directly wrap each + // chart. It is show here as an example only. + // + // By default, when a chart detects RTL: + // Measure axis positions are flipped. Primary measure axis is on the right + // and the secondary measure axis is on the left (when used). + // Domain axis' first domain starts on the right and grows left. + Directionality( + textDirection: TextDirection.rtl, + child: charts.LineChart( + seriesList, + animate: animate, + ), + ); /// Create one series with sample hard coded data. static List> _createSampleData() { diff --git a/charts_flutter/example/lib/i18n/rtl_series_legend.dart b/charts_flutter/example/lib/i18n/rtl_series_legend.dart index af374358c..1ec0a8fc8 100644 --- a/charts_flutter/example/lib/i18n/rtl_series_legend.dart +++ b/charts_flutter/example/lib/i18n/rtl_series_legend.dart @@ -103,41 +103,40 @@ class RTLSeriesLegend extends StatelessWidget { // EXCLUDE_FROM_GALLERY_DOCS_END @override - Widget build(BuildContext context) { - // Charts will determine if RTL is enabled by checking the directionality by - // requesting Directionality.of(context). This returns the text direction - // from the closest instance of that encloses the context passed to build - // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This - // means that the directionality widget does not have to directly wrap each - // chart. It is show here as an example only. - // - // When the legend behavior detects RTL: - // [BehaviorPosition.start] is to the right of the chart. - // [BehaviorPosition.end] is to the left of the chart. - // - // If the [BehaviorPosition] is top or bottom, the start justification - // is to the right, and the end justification is to the left. - // - // The legend's tabular layout will also layout rows and columns from right - // to left. - // - // The below example changes the position to 'start' and max rows of 2 in - // order to show these effects, but are not required for SeriesLegend to - // work with the correct directionality. - return Directionality( - textDirection: TextDirection.rtl, - child: charts.BarChart( - seriesList, - animate: animate, - behaviors: [ - charts.SeriesLegend( - position: charts.BehaviorPosition.end, - desiredMaxRows: 2, - ), - ], - ), - ); - } + Widget build(BuildContext context) => + // Charts will determine if RTL is enabled by checking the directionality by + // requesting Directionality.of(context). This returns the text direction + // from the closest instance of that encloses the context passed to build + // the chart. A [TextDirection.rtl] will be treated as a RTL chart. This + // means that the directionality widget does not have to directly wrap each + // chart. It is show here as an example only. + // + // When the legend behavior detects RTL: + // [BehaviorPosition.start] is to the right of the chart. + // [BehaviorPosition.end] is to the left of the chart. + // + // If the [BehaviorPosition] is top or bottom, the start justification + // is to the right, and the end justification is to the left. + // + // The legend's tabular layout will also layout rows and columns from right + // to left. + // + // The below example changes the position to 'start' and max rows of 2 in + // order to show these effects, but are not required for SeriesLegend to + // work with the correct directionality. + Directionality( + textDirection: TextDirection.rtl, + child: charts.BarChart( + seriesList, + animate: animate, + behaviors: [ + charts.SeriesLegend( + position: charts.BehaviorPosition.end, + desiredMaxRows: 2, + ), + ], + ), + ); /// Create series list with multiple series static List> _createSampleData() { diff --git a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart index af201f384..2e4602e27 100644 --- a/charts_flutter/example/lib/legends/datum_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/datum_legend_with_measures.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Bar chart with example of a legend with customized position, justification, /// desired max rows, and padding. These options are shown as an example of how /// to use the customizations, they do not necessary have to be used together in @@ -30,8 +32,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// /// Also shows the option to provide a custom measure formatter. class DatumLegendWithMeasures extends StatelessWidget { - const DatumLegendWithMeasures(this.seriesList, - {super.key, this.animate = false}); + const DatumLegendWithMeasures( + this.seriesList, { + super.key, + this.animate = false, + }); factory DatumLegendWithMeasures.withSampleData() => DatumLegendWithMeasures( _createSampleData(), diff --git a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart index 717f50e46..7320f809a 100644 --- a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart +++ b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart @@ -23,8 +23,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class DefaultHiddenSeriesLegend extends StatelessWidget { - const DefaultHiddenSeriesLegend(this.seriesList, - {super.key, this.animate = false}); + const DefaultHiddenSeriesLegend( + this.seriesList, { + super.key, + this.animate = false, + }); factory DefaultHiddenSeriesLegend.withSampleData() => DefaultHiddenSeriesLegend( @@ -106,8 +109,8 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. + // Add the series legend behavior to the chart to turn on series + // legends. By default the legend will display above the chart. behaviors: [ charts.SeriesLegend( // Configures the "Other" series to be hidden on first chart draw. diff --git a/charts_flutter/example/lib/legends/legend_custom_symbol.dart b/charts_flutter/example/lib/legends/legend_custom_symbol.dart index 26c50ee1d..ff4736bc4 100644 --- a/charts_flutter/example/lib/legends/legend_custom_symbol.dart +++ b/charts_flutter/example/lib/legends/legend_custom_symbol.dart @@ -53,8 +53,11 @@ class IconRenderer extends charts.CustomSymbolRenderer { } class LegendWithCustomSymbol extends StatelessWidget { - const LegendWithCustomSymbol(this.seriesList, - {super.key, this.animate = false}); + const LegendWithCustomSymbol( + this.seriesList, { + super.key, + this.animate = false, + }); factory LegendWithCustomSymbol.withSampleData() => LegendWithCustomSymbol( _createSampleData(), diff --git a/charts_flutter/example/lib/legends/simple_series_legend.dart b/charts_flutter/example/lib/legends/simple_series_legend.dart index 954f2d4c6..745166a8a 100644 --- a/charts_flutter/example/lib/legends/simple_series_legend.dart +++ b/charts_flutter/example/lib/legends/simple_series_legend.dart @@ -104,8 +104,8 @@ class SimpleSeriesLegend extends StatelessWidget { seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. + // Add the series legend behavior to the chart to turn on series + // legends. By default the legend will display above the chart. behaviors: [charts.SeriesLegend()], ); diff --git a/charts_flutter/example/lib/line_chart/animation_zoom.dart b/charts_flutter/example/lib/line_chart/animation_zoom.dart index 417ef7b5c..e38925f63 100644 --- a/charts_flutter/example/lib/line_chart/animation_zoom.dart +++ b/charts_flutter/example/lib/line_chart/animation_zoom.dart @@ -25,8 +25,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineAnimationZoomChart extends StatelessWidget { - const LineAnimationZoomChart(this.seriesList, - {super.key, this.animate = false}); + const LineAnimationZoomChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory LineAnimationZoomChart.withSampleData() => LineAnimationZoomChart( diff --git a/charts_flutter/example/lib/line_chart/dash_pattern.dart b/charts_flutter/example/lib/line_chart/dash_pattern.dart index 38b43257c..77fef87bf 100644 --- a/charts_flutter/example/lib/line_chart/dash_pattern.dart +++ b/charts_flutter/example/lib/line_chart/dash_pattern.dart @@ -25,8 +25,11 @@ import 'package:nimble_charts/flutter.dart' as charts; /// Example of a line chart rendered with dash patterns. class DashPatternLineChart extends StatelessWidget { - const DashPatternLineChart(this.seriesList, - {super.key, this.animate = false}); + const DashPatternLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory DashPatternLineChart.withSampleData() => DashPatternLineChart( diff --git a/charts_flutter/example/lib/line_chart/line_annotation.dart b/charts_flutter/example/lib/line_chart/line_annotation.dart index 380801119..84db19c3d 100644 --- a/charts_flutter/example/lib/line_chart/line_annotation.dart +++ b/charts_flutter/example/lib/line_chart/line_annotation.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class LineLineAnnotationChart extends StatelessWidget { - const LineLineAnnotationChart(this.seriesList, - {super.key, this.animate = false}); + const LineLineAnnotationChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and line annotations. /// diff --git a/charts_flutter/example/lib/line_chart/simple_nulls.dart b/charts_flutter/example/lib/line_chart/simple_nulls.dart index 981628e25..85d76c046 100644 --- a/charts_flutter/example/lib/line_chart/simple_nulls.dart +++ b/charts_flutter/example/lib/line_chart/simple_nulls.dart @@ -28,8 +28,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleNullsLineChart extends StatelessWidget { - const SimpleNullsLineChart(this.seriesList, - {super.key, this.animate = false}); + const SimpleNullsLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory SimpleNullsLineChart.withSampleData() => SimpleNullsLineChart( diff --git a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart index 0e1306f1c..db4052ba1 100644 --- a/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart +++ b/charts_flutter/example/lib/line_chart/stacked_area_nulls.dart @@ -37,8 +37,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class StackedAreaNullsLineChart extends StatelessWidget { - const StackedAreaNullsLineChart(this.seriesList, - {super.key, this.animate = false}); + const StackedAreaNullsLineChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.LineChart] with sample data and no transition. factory StackedAreaNullsLineChart.withSampleData() => diff --git a/charts_flutter/example/lib/pie_chart/pie_gallery.dart b/charts_flutter/example/lib/pie_chart/pie_gallery.dart index ee952db2f..406a0b327 100644 --- a/charts_flutter/example/lib/pie_chart/pie_gallery.dart +++ b/charts_flutter/example/lib/pie_chart/pie_gallery.dart @@ -49,7 +49,8 @@ List buildGallery() => [ // listTileIcon: new Icon(Icons.pie_chart), // title: 'Auto Label Donut Chart', // subtitle: - // 'With a single series, a hole in the middle, and auto-positioned labels', + // 'With a single series, a hole in the middle, ' + //'and auto-positioned labels', // childBuilder: () => new DonutAutoLabelChart.withRandomData(), // ), // new GalleryScaffold( diff --git a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart index f1e44acfc..849b572ab 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/comparison_points.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class ComparisonPointsScatterPlotChart extends StatelessWidget { - const ComparisonPointsScatterPlotChart(this.seriesList, - {super.key, this.animate = false}); + const ComparisonPointsScatterPlotChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory ComparisonPointsScatterPlotChart.withSampleData() => diff --git a/charts_flutter/example/lib/scatter_plot_chart/simple.dart b/charts_flutter/example/lib/scatter_plot_chart/simple.dart index 705f715b1..a13bb5abc 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/simple.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/simple.dart @@ -24,8 +24,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class SimpleScatterPlotChart extends StatelessWidget { - const SimpleScatterPlotChart(this.seriesList, - {super.key, this.animate = false}); + const SimpleScatterPlotChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.ScatterPlotChart] with sample data and no transition. factory SimpleScatterPlotChart.withSampleData() => SimpleScatterPlotChart( diff --git a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart index a0ebb3d8d..c40587f92 100644 --- a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart +++ b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart @@ -27,8 +27,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesConfidenceInterval extends StatelessWidget { - const TimeSeriesConfidenceInterval(this.seriesList, - {super.key, this.animate = false}); + const TimeSeriesConfidenceInterval( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory TimeSeriesConfidenceInterval.withSampleData() => @@ -77,8 +80,8 @@ class TimeSeriesConfidenceInterval extends StatelessWidget { seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. + // should create the same type of [DateTime] as the data provided. If + // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart index da0ecb83e..3ddf55cb3 100644 --- a/charts_flutter/example/lib/time_series_chart/end_points_axis.dart +++ b/charts_flutter/example/lib/time_series_chart/end_points_axis.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of a time series chart with an end points domain axis. /// /// An end points axis generates two ticks, one at each end of the axis range. @@ -26,8 +28,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class EndPointsAxisTimeSeriesChart extends StatelessWidget { - const EndPointsAxisTimeSeriesChart(this.seriesList, - {super.key, this.animate = false}); + const EndPointsAxisTimeSeriesChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory EndPointsAxisTimeSeriesChart.withSampleData() => diff --git a/charts_flutter/example/lib/time_series_chart/line_annotation.dart b/charts_flutter/example/lib/time_series_chart/line_annotation.dart index ce22d0dcc..30740ad18 100644 --- a/charts_flutter/example/lib/time_series_chart/line_annotation.dart +++ b/charts_flutter/example/lib/time_series_chart/line_annotation.dart @@ -31,8 +31,11 @@ import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; class TimeSeriesLineAnnotationChart extends StatelessWidget { - const TimeSeriesLineAnnotationChart(this.seriesList, - {super.key, this.animate = false}); + const TimeSeriesLineAnnotationChart( + this.seriesList, { + super.key, + this.animate = false, + }); /// Creates a [charts.TimeSeriesChart] with sample data and no transition. factory TimeSeriesLineAnnotationChart.withSampleData() => diff --git a/charts_flutter/example/lib/time_series_chart/simple.dart b/charts_flutter/example/lib/time_series_chart/simple.dart index c6cb230e5..297fa2406 100644 --- a/charts_flutter/example/lib/time_series_chart/simple.dart +++ b/charts_flutter/example/lib/time_series_chart/simple.dart @@ -72,8 +72,8 @@ class SimpleTimeSeriesChart extends StatelessWidget { seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If none - // specified, the default creates local date time. + // should create the same type of [DateTime] as the data provided. If + // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart index a780f553d..2d0bebe33 100644 --- a/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart +++ b/charts_flutter/example/lib/time_series_chart/with_bar_renderer.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of a time series chart using a bar renderer. library; diff --git a/charts_flutter/example/pubspec.yaml b/charts_flutter/example/pubspec.yaml index 33404beb4..a47851d9a 100644 --- a/charts_flutter/example/pubspec.yaml +++ b/charts_flutter/example/pubspec.yaml @@ -7,16 +7,17 @@ environment: dependencies: cupertino_icons: ^1.0.8 - nimble_charts: - path: ../ flutter: sdk: flutter - flutter_web_plugins: - sdk: flutter flutter_test: sdk: flutter - meta: ^1.1.1 + flutter_web_plugins: + sdk: flutter intl: ^0.19.0 + meta: ^1.1.1 + nimble_charts: + path: ../ + nimble_charts_common: any flutter: uses-material-design: true dev_dependencies: From 4990300b02bb2a5e74d61e1f4100ea23448f694b Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Fri, 20 Sep 2024 06:26:58 +1000 Subject: [PATCH 5/9] austerity fixes --- charts_flutter/example/analysis_options.yaml | 5 + .../a11y/domain_a11y_explore_bar_chart.dart | 4 +- .../example/lib/bar_chart/bar_gallery.dart | 359 ++++++++++-------- .../lib/bar_chart/vertical_bar_label.dart | 2 +- .../behaviors/selection_callback_example.dart | 8 +- .../selection_scatter_plot_highlight.dart | 8 +- .../example/lib/behaviors/slider.dart | 10 +- .../example/lib/i18n/rtl_bar_chart.dart | 2 + .../lib/legends/datum_legend_options.dart | 4 +- .../lib/legends/legend_custom_symbol.dart | 6 +- .../example/lib/legends/legends_gallery.dart | 5 +- .../lib/legends/series_legend_options.dart | 12 +- .../legends/series_legend_with_measures.dart | 2 + .../lib/legends/simple_datum_legend.dart | 6 +- .../example/lib/pie_chart/auto_label.dart | 2 +- .../example/lib/pie_chart/donut.dart | 2 +- .../example/lib/pie_chart/gauge.dart | 2 +- .../example/lib/pie_chart/outside_label.dart | 2 +- .../lib/scatter_plot_chart/shapes.dart | 8 +- charts_flutter/lib/flutter.dart | 3 +- charts_flutter/lib/src/symbol_renderer.dart | 1 - charts_flutter/lib/src/util/color.dart | 9 + 22 files changed, 266 insertions(+), 196 deletions(-) diff --git a/charts_flutter/example/analysis_options.yaml b/charts_flutter/example/analysis_options.yaml index bc7a72fda..7e3519467 100644 --- a/charts_flutter/example/analysis_options.yaml +++ b/charts_flutter/example/analysis_options.yaml @@ -4,4 +4,9 @@ include: package:austerity/analysis_options.yaml analyzer: errors: comment_references: warning + avoid_dynamic_calls: warning + avoid_annotating_with_dynamic: warning + + unreachable_from_main: ignore + public_member_api_docs: ignore \ No newline at end of file diff --git a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart index 35c8d34e7..d6f87ee06 100644 --- a/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart +++ b/charts_flutter/example/lib/a11y/domain_a11y_explore_bar_chart.dart @@ -107,7 +107,9 @@ class DomainA11yExploreBarChart extends StatelessWidget { /// This example vocalizes the domain, then for each series that has that /// domain, it vocalizes the series display name and the measure and a /// description of that measure. - String vocalizeDomainAndMeasures(List seriesDatums) { + String vocalizeDomainAndMeasures( + List> seriesDatums, + ) { final buffer = StringBuffer() .. diff --git a/charts_flutter/example/lib/bar_chart/bar_gallery.dart b/charts_flutter/example/lib/bar_chart/bar_gallery.dart index 6ccfebc51..5c04c8081 100644 --- a/charts_flutter/example/lib/bar_chart/bar_gallery.dart +++ b/charts_flutter/example/lib/bar_chart/bar_gallery.dart @@ -13,7 +13,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -import '../main.dart' as m; +import 'package:example/bar_chart/custom_rounded_bars.dart'; +import 'package:example/bar_chart/grouped.dart'; +import 'package:example/bar_chart/grouped_fill_color.dart'; +import 'package:example/bar_chart/grouped_single_target_line.dart'; +import 'package:example/bar_chart/grouped_stacked.dart'; +import 'package:example/bar_chart/grouped_stacked_weight_pattern.dart'; +import 'package:example/bar_chart/grouped_target_line.dart'; +import 'package:example/bar_chart/horizontal.dart'; +import 'package:example/bar_chart/horizontal_bar_label.dart'; +import 'package:example/bar_chart/horizontal_bar_label_custom.dart'; +import 'package:example/bar_chart/horizontal_pattern_forward_hatch.dart'; +import 'package:example/bar_chart/pattern_forward_hatch.dart'; +import 'package:example/bar_chart/simple.dart'; +import 'package:example/bar_chart/spark_bar.dart'; +import 'package:example/bar_chart/stacked.dart'; +import 'package:example/bar_chart/stacked_fill_color.dart'; +import 'package:example/bar_chart/stacked_horizontal.dart'; +import 'package:example/bar_chart/stacked_target_line.dart'; +import 'package:example/bar_chart/vertical_bar_label.dart'; +import 'package:example/gallery_scaffold.dart'; + +import 'package:example/main.dart' as m; import 'package:flutter/material.dart'; const simpleBarChartTileTitle = 'Simple Bar Chart'; @@ -39,166 +60,176 @@ const horizontalPatternForwardHatchChart = const weightedPatternChart = 'Weight Pattern Bar Chart'; const barChartWithCustomBarRadius = 'Bar Chart with custom bar radius'; -List buildGallery() { - return [ - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: simpleBarChartTileTitle, - subtitle: 'Simple bar chart with a single series', - childBuilder: () => m.useRandomData - ? SimpleBarChart.withRandomData() - : SimpleBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: stackedBarChartTileTitle, - subtitle: 'Stacked bar chart with multiple series', - childBuilder: () => m.useRandomData - ? StackedBarChart.withRandomData() - : StackedBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: groupedBarChartTileTitle, - subtitle: 'Grouped bar chart with multiple series', - childBuilder: () => m.useRandomData - ? GroupedBarChart.withRandomData() - : GroupedBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: groupedStackedBarChartTileTitle, - subtitle: 'Grouped and stacked bar chart with multiple series', - childBuilder: () => m.useRandomData - ? GroupedStackedBarChart.withRandomData() - : GroupedStackedBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: groupedBarTargetLineChartTileTitle, - subtitle: 'Grouped bar target line chart with multiple series', - childBuilder: () => m.useRandomData - ? GroupedBarTargetLineChart.withRandomData() - : GroupedBarTargetLineChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: groupedBarSingleTargetLineChartTileTitle, - subtitle: - 'Grouped bar target line chart with multiple series and a single target', - childBuilder: () => m.useRandomData - ? GroupedBarSingleTargetLineChart.withRandomData() - : GroupedBarSingleTargetLineChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: stackedBarTargetLineChart, - subtitle: 'Stacked bar target line chart with multiple series', - childBuilder: () => m.useRandomData - ? StackedBarTargetLineChart.withRandomData() - : StackedBarTargetLineChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: horizontalBarChart, - subtitle: 'Horizontal bar chart with a single series', - childBuilder: () => m.useRandomData - ? HorizontalBarChart.withRandomData() - : HorizontalBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: stackedHorizontalBarChart, - subtitle: 'Stacked horizontal bar chart with multiple series', - childBuilder: () => m.useRandomData - ? StackedHorizontalBarChart.withRandomData() - : StackedHorizontalBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: horizontalBarLabelChart, - subtitle: 'Horizontal bar chart with a single series and bar labels', - childBuilder: () => m.useRandomData - ? HorizontalBarLabelChart.withRandomData() - : HorizontalBarLabelChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: horizontalBarLabelCustomChart, - subtitle: 'Bar labels with customized styling', - childBuilder: () => m.useRandomData - ? HorizontalBarLabelCustomChart.withRandomData() - : HorizontalBarLabelCustomChart.createWithSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: verticalBarLabelChart, - subtitle: 'Vertical bar chart with a single series and bar labels', - childBuilder: () => m.useRandomData - ? VerticalBarLabelChart.withRandomData() - : VerticalBarLabelChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: sparkBarChart, - subtitle: 'Spark Bar Chart', - childBuilder: () => m.useRandomData - ? SparkBar.withRandomData() - : SparkBar.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: groupedFillColorChart, - subtitle: 'Grouped bar chart with fill colors', - childBuilder: () => m.useRandomData - ? GroupedFillColorBarChart.withRandomData() - : GroupedFillColorBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: stackedFillColorChart, - subtitle: 'Stacked bar chart with fill colors', - childBuilder: () => m.useRandomData - ? StackedFillColorBarChart.withRandomData() - : StackedFillColorBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: patternForwardHatchChart, - subtitle: 'Pattern Forward Hatch Bar Chart', - childBuilder: () => m.useRandomData - ? PatternForwardHatchBarChart.withRandomData() - : PatternForwardHatchBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Transform.rotate( - angle: 1.5708, child: new Icon(Icons.insert_chart)), - title: horizontalPatternForwardHatchChart, - subtitle: 'Horizontal Pattern Forward Hatch Bar Chart', - childBuilder: () => m.useRandomData - ? HorizontalPatternForwardHatchBarChart.withRandomData() - : HorizontalPatternForwardHatchBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: weightedPatternChart, - subtitle: 'Grouped and stacked bar chart with a weight pattern', - childBuilder: () => m.useRandomData - ? GroupedStackedWeightPatternBarChart.withRandomData() - : GroupedStackedWeightPatternBarChart.withSampleData(), - ), - new GalleryScaffold( - listTileIcon: new Icon(Icons.insert_chart), - title: barChartWithCustomBarRadius, - subtitle: 'Custom rounded bar corners', - childBuilder: () => m.useRandomData - ? CustomRoundedBars.withRandomData() - : CustomRoundedBars.withSampleData(), - ), - ]; -} +List buildGallery() => [ + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: simpleBarChartTileTitle, + subtitle: 'Simple bar chart with a single series', + childBuilder: () => m.useRandomData + ? SimpleBarChart.withRandomData() + : SimpleBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: stackedBarChartTileTitle, + subtitle: 'Stacked bar chart with multiple series', + childBuilder: () => m.useRandomData + ? StackedBarChart.withRandomData() + : StackedBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: groupedBarChartTileTitle, + subtitle: 'Grouped bar chart with multiple series', + childBuilder: () => m.useRandomData + ? GroupedBarChart.withRandomData() + : GroupedBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: groupedStackedBarChartTileTitle, + subtitle: 'Grouped and stacked bar chart with multiple series', + childBuilder: () => m.useRandomData + ? GroupedStackedBarChart.withRandomData() + : GroupedStackedBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: groupedBarTargetLineChartTileTitle, + subtitle: 'Grouped bar target line chart with multiple series', + childBuilder: () => m.useRandomData + ? GroupedBarTargetLineChart.withRandomData() + : GroupedBarTargetLineChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: groupedBarSingleTargetLineChartTileTitle, + subtitle: 'Grouped bar target line chart ' + 'with multiple series and a single target', + childBuilder: () => m.useRandomData + ? GroupedBarSingleTargetLineChart.withRandomData() + : GroupedBarSingleTargetLineChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: stackedBarTargetLineChart, + subtitle: 'Stacked bar target line chart with multiple series', + childBuilder: () => m.useRandomData + ? StackedBarTargetLineChart.withRandomData() + : StackedBarTargetLineChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: horizontalBarChart, + subtitle: 'Horizontal bar chart with a single series', + childBuilder: () => m.useRandomData + ? HorizontalBarChart.withRandomData() + : HorizontalBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: stackedHorizontalBarChart, + subtitle: 'Stacked horizontal bar chart with multiple series', + childBuilder: () => m.useRandomData + ? StackedHorizontalBarChart.withRandomData() + : StackedHorizontalBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: horizontalBarLabelChart, + subtitle: 'Horizontal bar chart with a single series and bar labels', + childBuilder: () => m.useRandomData + ? HorizontalBarLabelChart.withRandomData() + : HorizontalBarLabelChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: horizontalBarLabelCustomChart, + subtitle: 'Bar labels with customized styling', + childBuilder: () => m.useRandomData + ? HorizontalBarLabelCustomChart.withRandomData() + : HorizontalBarLabelCustomChart.createWithSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: verticalBarLabelChart, + subtitle: 'Vertical bar chart with a single series and bar labels', + childBuilder: () => m.useRandomData + ? VerticalBarLabelChart.withRandomData() + : VerticalBarLabelChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: sparkBarChart, + subtitle: 'Spark Bar Chart', + childBuilder: () => m.useRandomData + ? SparkBar.withRandomData() + : SparkBar.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: groupedFillColorChart, + subtitle: 'Grouped bar chart with fill colors', + childBuilder: () => m.useRandomData + ? GroupedFillColorBarChart.withRandomData() + : GroupedFillColorBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: stackedFillColorChart, + subtitle: 'Stacked bar chart with fill colors', + childBuilder: () => m.useRandomData + ? StackedFillColorBarChart.withRandomData() + : StackedFillColorBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: patternForwardHatchChart, + subtitle: 'Pattern Forward Hatch Bar Chart', + childBuilder: () => m.useRandomData + ? PatternForwardHatchBarChart.withRandomData() + : PatternForwardHatchBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: Transform.rotate( + angle: 1.5708, + child: const Icon(Icons.insert_chart), + ), + title: horizontalPatternForwardHatchChart, + subtitle: 'Horizontal Pattern Forward Hatch Bar Chart', + childBuilder: () => m.useRandomData + ? HorizontalPatternForwardHatchBarChart.withRandomData() + : HorizontalPatternForwardHatchBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: weightedPatternChart, + subtitle: 'Grouped and stacked bar chart with a weight pattern', + childBuilder: () => m.useRandomData + ? GroupedStackedWeightPatternBarChart.withRandomData() + : GroupedStackedWeightPatternBarChart.withSampleData(), + ), + GalleryScaffold( + listTileIcon: const Icon(Icons.insert_chart), + title: barChartWithCustomBarRadius, + subtitle: 'Custom rounded bar corners', + childBuilder: () => m.useRandomData + ? CustomRoundedBars.withRandomData() + : CustomRoundedBars.withSampleData(), + ), + ]; diff --git a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart index 32dc1ea64..26028beb2 100644 --- a/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart +++ b/charts_flutter/example/lib/bar_chart/vertical_bar_label.dart @@ -62,7 +62,7 @@ class VerticalBarLabelChart extends StatelessWidget { measureFn: (sales, _) => sales.sales, data: data, // Set a label accessor to control the text of the bar label. - labelAccessorFn: (sales, _) => sales.sales, + labelAccessorFn: (sales, _) => sales.sales.toString(), ), ]; } diff --git a/charts_flutter/example/lib/behaviors/selection_callback_example.dart b/charts_flutter/example/lib/behaviors/selection_callback_example.dart index dc5e56266..1f198f660 100644 --- a/charts_flutter/example/lib/behaviors/selection_callback_example.dart +++ b/charts_flutter/example/lib/behaviors/selection_callback_example.dart @@ -138,7 +138,7 @@ class _SelectionCallbackState extends State { // Listens to the underlying selection changes, and updates the information // relevant to building the primitive legend like information under the // chart. - void _onSelectionChanged(charts.SelectionModel model) { + void _onSelectionChanged(charts.SelectionModel model) { final selectedDatum = model.selectedDatum; DateTime? time; @@ -150,9 +150,11 @@ class _SelectionCallbackState extends State { // Walk the selection updating the measures map, storing off the sales and // series name for each selection point. if (selectedDatum.isNotEmpty) { - time = selectedDatum.first.datum.time; + // TODO: casting + time = selectedDatum.first.datum.time as DateTime?; for (final datumPair in selectedDatum) { - measures[datumPair.series.displayName!] = datumPair.datum.sales; + //TODO: casting + measures[datumPair.series.displayName!] = datumPair.datum.sales as num; } } diff --git a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart index 9a4a7351b..5f37ce348 100644 --- a/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart +++ b/charts_flutter/example/lib/behaviors/selection_scatter_plot_highlight.dart @@ -172,6 +172,8 @@ class SelectionScatterPlotHighlight extends StatelessWidget { const maxMeasure = 100; + String? getShape(int index) => data[index].shape; + return [ charts.Series( id: 'Sales', @@ -197,7 +199,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget { // Accessor function that associates each datum with a symbol renderer. ..setAttribute( charts.pointSymbolRendererFnKey, - (index) => data[index].shape, + getShape, ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), @@ -280,6 +282,8 @@ class SelectionScatterPlotHighlight extends StatelessWidget { const maxMeasure = 300; + String? getShape(int index) => data[index].shape; + return [ charts.Series( id: 'Sales', @@ -306,7 +310,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget { // Accessor function that associates each datum with a symbol renderer. ..setAttribute( charts.pointSymbolRendererFnKey, - (index) => data[index].shape, + getShape, ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), diff --git a/charts_flutter/example/lib/behaviors/slider.dart b/charts_flutter/example/lib/behaviors/slider.dart index a6b3dc602..918f2f309 100644 --- a/charts_flutter/example/lib/behaviors/slider.dart +++ b/charts_flutter/example/lib/behaviors/slider.dart @@ -13,17 +13,18 @@ // See the License for the specific language governing permissions and // limitations under the License. // EXCLUDE_FROM_GALLERY_DOCS_START +// ignore_for_file: lines_longer_than_80_chars + import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/flutter.dart'; /// This is just a simple line chart with a behavior that adds slider controls. /// -/// A [Slider] behavior is added manually to enable slider controls, with an +/// A Slider behavior is added manually to enable slider controls, with an /// initial position at 1 along the domain axis. /// /// An onChange event handler has been configured to demonstrate updating a div @@ -104,14 +105,15 @@ class _SliderCallbackState extends State { // Handles callbacks when the user drags the slider. void _onSliderChange( Point point, - domain, + dynamic domain, String roleId, charts.SliderListenerDragState dragState, ) { // Request a build. void rebuild(_) { setState(() { - _sliderDomainValue = (domain * 10).round() / 10; + //TODO: casting + _sliderDomainValue = (domain * 10).round() / 10 as num; _sliderDragState = dragState.toString(); _sliderPosition = point; }); diff --git a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart index dec414102..b1a52bff0 100644 --- a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// RTL Bar chart example library; diff --git a/charts_flutter/example/lib/legends/datum_legend_options.dart b/charts_flutter/example/lib/legends/datum_legend_options.dart index 77fc14a13..5504f310c 100644 --- a/charts_flutter/example/lib/legends/datum_legend_options.dart +++ b/charts_flutter/example/lib/legends/datum_legend_options.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Pie chart with example of a legend with customized position, justification, /// desired max rows, padding, and entry text styles. These options are shown as /// an example of how to use the customizations, they do not necessary have to @@ -72,7 +74,7 @@ class DatumLegendOptions extends StatelessWidget { // This example shows how to change the position and justification of // the legend, in addition to altering the max rows and padding. behaviors: [ - charts.DatumLegend( + charts.DatumLegend( // Positions for "start" and "end" will be left and right respectively // for widgets with a build context that has directionality ltr. // For rtl, "start" and "end" will be right and left respectively. diff --git a/charts_flutter/example/lib/legends/legend_custom_symbol.dart b/charts_flutter/example/lib/legends/legend_custom_symbol.dart index ff4736bc4..4bcb198a0 100644 --- a/charts_flutter/example/lib/legends/legend_custom_symbol.dart +++ b/charts_flutter/example/lib/legends/legend_custom_symbol.dart @@ -22,7 +22,7 @@ import 'dart:math'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:flutter/material.dart'; import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/src/util/color.dart'; +import 'package:nimble_charts/flutter.dart'; import 'package:nimble_charts_common/common.dart' as common; /// Example custom renderer that renders [IconData]. @@ -141,8 +141,8 @@ class LegendWithCustomSymbol extends StatelessWidget { // Add the legend behavior to the chart to turn on legends. // By default the legend will display above the chart. // - // To change the symbol used in the legend, set the renderer attribute of - // symbolRendererKey to a SymbolRenderer. + // To change the symbol used in the legend, set the renderer attribute + // of symbolRendererKey to a SymbolRenderer. behaviors: [charts.SeriesLegend()], defaultRenderer: charts.BarRendererConfig( symbolRenderer: IconRenderer(Icons.cloud), diff --git a/charts_flutter/example/lib/legends/legends_gallery.dart b/charts_flutter/example/lib/legends/legends_gallery.dart index 57dd8ccba..6fbbd4162 100644 --- a/charts_flutter/example/lib/legends/legends_gallery.dart +++ b/charts_flutter/example/lib/legends/legends_gallery.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + import 'package:example/gallery_scaffold.dart'; import 'package:example/legends/datum_legend_with_measures.dart'; import 'package:example/legends/default_hidden_series_legend.dart'; @@ -33,7 +35,8 @@ List buildGallery() => [ listTileIcon: Icon(Icons.insert_chart), title: 'Series Legend Options', subtitle: - 'A series legend with custom positioning and spacing for a bar chart', + 'A series legend with custom positioning ' + 'and spacing for a bar chart', childBuilder: LegendOptions.withRandomData, ), const GalleryScaffold( diff --git a/charts_flutter/example/lib/legends/series_legend_options.dart b/charts_flutter/example/lib/legends/series_legend_options.dart index 3d8d3f827..6ef385048 100644 --- a/charts_flutter/example/lib/legends/series_legend_options.dart +++ b/charts_flutter/example/lib/legends/series_legend_options.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Bar chart with example of a legend with customized position, justification, /// desired max rows, padding, and entry text styles. These options are shown as /// an example of how to use the customizations, they do not necessary have to @@ -112,11 +114,11 @@ class LegendOptions extends StatelessWidget { // the legend, in addition to altering the max rows and padding. behaviors: [ charts.SeriesLegend( - // Positions for "start" and "end" will be left and right respectively - // for widgets with a build context that has directionality ltr. - // For rtl, "start" and "end" will be right and left respectively. - // Since this example has directionality of ltr, the legend is - // positioned on the right side of the chart. + // Positions for "start" and "end" will be left and right + // respectively for widgets with a build context that has + // directionality ltr. For rtl, "start" and "end" will be right + // and left respectively. Since this example has directionality + // of ltr, the legend is positioned on the right side of the chart. position: charts.BehaviorPosition.end, // For a legend that is positioned on the left or right of the chart, // setting the justification for [endDrawArea] is aligned to the diff --git a/charts_flutter/example/lib/legends/series_legend_with_measures.dart b/charts_flutter/example/lib/legends/series_legend_with_measures.dart index 30c64460a..215fdc0e8 100644 --- a/charts_flutter/example/lib/legends/series_legend_with_measures.dart +++ b/charts_flutter/example/lib/legends/series_legend_with_measures.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Bar chart with example of a legend with customized position, justification, /// desired max rows, and padding. These options are shown as an example of how /// to use the customizations, they do not necessary have to be used together in diff --git a/charts_flutter/example/lib/legends/simple_datum_legend.dart b/charts_flutter/example/lib/legends/simple_datum_legend.dart index 249f84c6d..f14f82d09 100644 --- a/charts_flutter/example/lib/legends/simple_datum_legend.dart +++ b/charts_flutter/example/lib/legends/simple_datum_legend.dart @@ -64,9 +64,9 @@ class SimpleDatumLegend extends StatelessWidget { Widget build(BuildContext context) => charts.PieChart( seriesList, animate: animate, - // Add the series legend behavior to the chart to turn on series legends. - // By default the legend will display above the chart. - behaviors: [charts.DatumLegend()], + // Add the series legend behavior to the chart to turn on series + // legends. By default the legend will display above the chart. + behaviors: [charts.DatumLegend()], ); /// Create series list with one series diff --git a/charts_flutter/example/lib/pie_chart/auto_label.dart b/charts_flutter/example/lib/pie_chart/auto_label.dart index 78835c6d2..572ef33a9 100644 --- a/charts_flutter/example/lib/pie_chart/auto_label.dart +++ b/charts_flutter/example/lib/pie_chart/auto_label.dart @@ -86,7 +86,7 @@ class DonutAutoLabelChart extends StatelessWidget { // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), defaultRenderer: charts.ArcRendererConfig( arcWidth: 60, - arcRendererDecorators: [charts.ArcLabelDecorator()], + arcRendererDecorators: [charts.ArcLabelDecorator()], ), ); diff --git a/charts_flutter/example/lib/pie_chart/donut.dart b/charts_flutter/example/lib/pie_chart/donut.dart index ef5243e0f..2e3daf6ed 100644 --- a/charts_flutter/example/lib/pie_chart/donut.dart +++ b/charts_flutter/example/lib/pie_chart/donut.dart @@ -67,7 +67,7 @@ class DonutPieChart extends StatelessWidget { animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. - defaultRenderer: charts.ArcRendererConfig(arcWidth: 60), + defaultRenderer: charts.ArcRendererConfig(arcWidth: 60), ); /// Create one series with sample hard coded data. diff --git a/charts_flutter/example/lib/pie_chart/gauge.dart b/charts_flutter/example/lib/pie_chart/gauge.dart index 08781fda8..457fdbca5 100644 --- a/charts_flutter/example/lib/pie_chart/gauge.dart +++ b/charts_flutter/example/lib/pie_chart/gauge.dart @@ -69,7 +69,7 @@ class GaugeChart extends StatelessWidget { // Configure the width of the pie slices to 30px. The remaining space in // the chart will be left as a hole in the center. Adjust the start // angle and the arc length of the pie so it resembles a gauge. - defaultRenderer: charts.ArcRendererConfig( + defaultRenderer: charts.ArcRendererConfig( arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi, diff --git a/charts_flutter/example/lib/pie_chart/outside_label.dart b/charts_flutter/example/lib/pie_chart/outside_label.dart index 36f4c83d0..98919d02a 100644 --- a/charts_flutter/example/lib/pie_chart/outside_label.dart +++ b/charts_flutter/example/lib/pie_chart/outside_label.dart @@ -84,7 +84,7 @@ class PieOutsideLabelChart extends StatelessWidget { // outsideLabelStyleSpec: new charts.TextStyleSpec(...)), defaultRenderer: charts.ArcRendererConfig( arcRendererDecorators: [ - charts.ArcLabelDecorator( + charts.ArcLabelDecorator( labelPosition: charts.ArcLabelPosition.outside, ), ], diff --git a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart index 1d3985d72..d911abe4f 100644 --- a/charts_flutter/example/lib/scatter_plot_chart/shapes.dart +++ b/charts_flutter/example/lib/scatter_plot_chart/shapes.dart @@ -166,6 +166,8 @@ class ShapesScatterPlotChart extends StatelessWidget { const maxMeasure = 100; + String? getShape(int index) => data[index].shape; + return [ charts.Series( id: 'Sales', @@ -191,7 +193,7 @@ class ShapesScatterPlotChart extends StatelessWidget { // Accessor function that associates each datum with a symbol renderer. ..setAttribute( charts.pointSymbolRendererFnKey, - (index) => data[index].shape, + getShape, ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), @@ -249,6 +251,8 @@ class ShapesScatterPlotChart extends StatelessWidget { const maxMeasure = 300; + String? getShape(int index) => data[index].shape; + return [ charts.Series( id: 'Sales', @@ -275,7 +279,7 @@ class ShapesScatterPlotChart extends StatelessWidget { // Accessor function that associates each datum with a symbol renderer. ..setAttribute( charts.pointSymbolRendererFnKey, - (index) => data[index].shape, + getShape, ) // Default symbol renderer ID for data that have no defined shape. ..setAttribute(charts.pointSymbolRendererIdKey, 'rect'), diff --git a/charts_flutter/lib/flutter.dart b/charts_flutter/lib/flutter.dart index 3a1ac9e64..4b53df2ef 100644 --- a/charts_flutter/lib/flutter.dart +++ b/charts_flutter/lib/flutter.dart @@ -115,7 +115,6 @@ export 'package:nimble_charts_common/common.dart' PointRendererDecorator, PointRendererElement, PointSymbolRenderer, - QuantumPalette, RTLSpec, RangeAnnotationAxisType, RangeAnnotationSegment, @@ -197,3 +196,5 @@ export 'src/time_series_chart.dart'; export 'src/user_managed_state.dart' show UserManagedSelectionModel, UserManagedState; export 'src/util/color.dart' show ColorUtil; +export 'src/util/color.dart' show ColorExtensions; +export 'src/util/color.dart' show UIColorExtensions; diff --git a/charts_flutter/lib/src/symbol_renderer.dart b/charts_flutter/lib/src/symbol_renderer.dart index d35fa4755..c2a09914a 100644 --- a/charts_flutter/lib/src/symbol_renderer.dart +++ b/charts_flutter/lib/src/symbol_renderer.dart @@ -19,7 +19,6 @@ import 'package:flutter/widgets.dart'; import 'package:nimble_charts/flutter.dart'; import 'package:nimble_charts/src/chart_canvas.dart' as cc; import 'package:nimble_charts/src/graphics_factory.dart' as gf; -import 'package:nimble_charts/src/util/color.dart'; import 'package:nimble_charts_common/common.dart' as common; /// Flutter widget responsible for painting a common SymbolRenderer from the diff --git a/charts_flutter/lib/src/util/color.dart b/charts_flutter/lib/src/util/color.dart index 49534ac98..ae279c790 100644 --- a/charts_flutter/lib/src/util/color.dart +++ b/charts_flutter/lib/src/util/color.dart @@ -18,15 +18,22 @@ import 'dart:ui' as ui; import 'package:nimble_charts/flutter.dart'; import 'package:nimble_charts_common/common.dart' as common show Color; +// ignore: avoid_classes_with_only_static_members +/// Utility class for converting between common and Flutter colors. class ColorUtil { + /// Converts a common color to a Flutter color. static ui.Color toDartColor(common.Color color) => color.toDartColor(); + /// Converts a Flutter color to a common color. static common.Color fromDartColor(ui.Color color) => color.fromDartColor(); } +/// Extension methods for common colors. extension ColorExtensions on Color { + /// Converts a common color to a Flutter color. ui.Color toDartColor() => ui.Color.fromARGB(a, r, g, b); + /// Returns a new color with the alpha channel multiplied by the given value. Color withAlpha(double alpha) => Color( r: r, g: g, @@ -35,7 +42,9 @@ extension ColorExtensions on Color { ); } +/// Extension methods for Flutter colors. extension UIColorExtensions on ui.Color { + /// Converts a Flutter color to a common color. common.Color fromDartColor() => common.Color( r: red, g: green, From ed00183d3211f56af0810b214f5a5234d41df314 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Fri, 20 Sep 2024 06:35:47 +1000 Subject: [PATCH 6/9] fix the issues --- charts_flutter/example/lib/gallery_scaffold.dart | 2 +- charts_flutter/example/lib/i18n/rtl_bar_chart.dart | 4 ++-- charts_flutter/example/lib/i18n/rtl_line_chart.dart | 6 ++++-- charts_flutter/example/lib/i18n/rtl_line_segments.dart | 6 ++++-- charts_flutter/example/lib/i18n/rtl_series_legend.dart | 6 ++++-- charts_flutter/test/example_widget_tests/example_test.dart | 6 +++--- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/charts_flutter/example/lib/gallery_scaffold.dart b/charts_flutter/example/lib/gallery_scaffold.dart index 036b15797..ce163fe3e 100644 --- a/charts_flutter/example/lib/gallery_scaffold.dart +++ b/charts_flutter/example/lib/gallery_scaffold.dart @@ -41,7 +41,7 @@ class GalleryScaffold extends StatefulWidget { onTap: () async { await Navigator.push( context, - MaterialPageRoute(builder: (_) => this), + MaterialPageRoute(builder: (_) => this), ); }, ); diff --git a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart index b1a52bff0..f534abe0a 100644 --- a/charts_flutter/example/lib/i18n/rtl_bar_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_bar_chart.dart @@ -20,11 +20,11 @@ library; // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; +import 'dart:ui' as ui; import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/flutter.dart'; class RTLBarChart extends StatelessWidget { const RTLBarChart(this.seriesList, {super.key, this.animate = false}); @@ -81,7 +81,7 @@ class RTLBarChart extends StatelessWidget { // Optionally, [RTLSpec] can be passed in when creating the chart to specify // chart display settings in RTL mode. Directionality( - textDirection: TextDirection.rtl, + textDirection: ui.TextDirection.rtl, child: charts.BarChart( seriesList, animate: animate, diff --git a/charts_flutter/example/lib/i18n/rtl_line_chart.dart b/charts_flutter/example/lib/i18n/rtl_line_chart.dart index ec362a3a9..a8dff9b83 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_chart.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_chart.dart @@ -13,16 +13,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// RTL Line chart example library; // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; +import 'dart:ui' as ui; import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/flutter.dart'; class RTLLineChart extends StatelessWidget { const RTLLineChart(this.seriesList, {super.key, this.animate = false}); @@ -76,7 +78,7 @@ class RTLLineChart extends StatelessWidget { // and the secondary measure axis is on the left (when used). // Domain axis' first domain starts on the right and grows left. Directionality( - textDirection: TextDirection.rtl, + textDirection: ui.TextDirection.rtl, child: charts.LineChart( seriesList, animate: animate, diff --git a/charts_flutter/example/lib/i18n/rtl_line_segments.dart b/charts_flutter/example/lib/i18n/rtl_line_segments.dart index 0a8622e2d..2d9c0dbc3 100644 --- a/charts_flutter/example/lib/i18n/rtl_line_segments.dart +++ b/charts_flutter/example/lib/i18n/rtl_line_segments.dart @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// Example of a RTL stacked area chart with changing styles within each line. /// /// Each series of data in this example contains different values for color, @@ -29,11 +31,11 @@ library; // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; +import 'dart:ui' as ui; import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/flutter.dart'; class RTLLineSegments extends StatelessWidget { const RTLLineSegments(this.seriesList, {super.key, this.animate = false}); @@ -144,7 +146,7 @@ class RTLLineSegments extends StatelessWidget { // and the secondary measure axis is on the left (when used). // Domain axis' first domain starts on the right and grows left. Directionality( - textDirection: TextDirection.rtl, + textDirection: ui.TextDirection.rtl, child: charts.LineChart( seriesList, defaultRenderer: diff --git a/charts_flutter/example/lib/i18n/rtl_series_legend.dart b/charts_flutter/example/lib/i18n/rtl_series_legend.dart index 1ec0a8fc8..7386c7e46 100644 --- a/charts_flutter/example/lib/i18n/rtl_series_legend.dart +++ b/charts_flutter/example/lib/i18n/rtl_series_legend.dart @@ -13,16 +13,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore_for_file: lines_longer_than_80_chars + /// RTL Bar chart example library; // EXCLUDE_FROM_GALLERY_DOCS_START import 'dart:math'; +import 'dart:ui' as ui; import 'package:flutter/material.dart'; // EXCLUDE_FROM_GALLERY_DOCS_END import 'package:nimble_charts/flutter.dart' as charts; -import 'package:nimble_charts/flutter.dart'; class RTLSeriesLegend extends StatelessWidget { const RTLSeriesLegend(this.seriesList, {super.key, this.animate = false}); @@ -125,7 +127,7 @@ class RTLSeriesLegend extends StatelessWidget { // order to show these effects, but are not required for SeriesLegend to // work with the correct directionality. Directionality( - textDirection: TextDirection.rtl, + textDirection: ui.TextDirection.rtl, child: charts.BarChart( seriesList, animate: animate, diff --git a/charts_flutter/test/example_widget_tests/example_test.dart b/charts_flutter/test/example_widget_tests/example_test.dart index 6c5c2781c..5deb1dfa5 100644 --- a/charts_flutter/test/example_widget_tests/example_test.dart +++ b/charts_flutter/test/example_widget_tests/example_test.dart @@ -19,7 +19,7 @@ void main() { testWidgets( 'Main Menu', (tester) async { - final galleryApp = m.GalleryApp(); + const galleryApp = m.GalleryApp(); await tester.pumpWidget(galleryApp); @@ -197,8 +197,8 @@ extension ExampleWidgetTestExtensions on WidgetTester { Future Function()? extra, double? scrollDelta, }) async { - //Create an pump - final galleryApp = m.GalleryApp(); + //Create and pump + const galleryApp = m.GalleryApp(); await pumpWidget(galleryApp); //Set the screen size of the widget From f4b20bc1c5ee77772e0b1ebcc9c9742b16c41873 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Fri, 20 Sep 2024 06:53:20 +1000 Subject: [PATCH 7/9] Fix imports --- .../example_widget_tests/example_test.dart | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/charts_flutter/test/example_widget_tests/example_test.dart b/charts_flutter/test/example_widget_tests/example_test.dart index 5deb1dfa5..12f3c7397 100644 --- a/charts_flutter/test/example_widget_tests/example_test.dart +++ b/charts_flutter/test/example_widget_tests/example_test.dart @@ -1,25 +1,21 @@ -// ignore_for_file: avoid_relative_lib_imports - +import 'package:example/bar_chart/bar_gallery.dart'; +import 'package:example/home.dart'; +import 'package:example/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:nimble_charts/flutter.dart' as charts; -import '../../example/lib/bar_chart/bar_gallery.dart' as b; - -import '../../example/lib/home.dart' as h; -import '../../example/lib/main.dart' as m; - import '../test_functions.dart'; /// Widget tests for the example app. void main() { group('ExampleApp Widget Tests', () { - m.useRandomData = false; + useRandomData = false; testWidgets( 'Main Menu', (tester) async { - const galleryApp = m.GalleryApp(); + const galleryApp = GalleryApp(); await tester.pumpWidget(galleryApp); @@ -29,7 +25,7 @@ void main() { await tester.pumpAndSettle(); - await matchesGolden( + await matchesGolden( 'example_menu', ); }, @@ -38,7 +34,7 @@ void main() { testWidgets( 'Navigates to Simple Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.simpleBarChartTileTitle, + simpleBarChartTileTitle, extra: () async { await tester.tap(find.byType(charts.BarChart)); await tester.pumpAndSettle(); @@ -49,42 +45,42 @@ void main() { testWidgets( 'Navigates to Stacked Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.stackedBarChartTileTitle, + stackedBarChartTileTitle, ), ); testWidgets( 'Navigates to Grouped Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.groupedBarChartTileTitle, + groupedBarChartTileTitle, ), ); testWidgets( 'Navigates to Grouped Stacked Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.groupedStackedBarChartTileTitle, + groupedStackedBarChartTileTitle, ), ); testWidgets( 'Navigates to Grouped Bar Target Line Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.groupedBarTargetLineChartTileTitle, + groupedBarTargetLineChartTileTitle, ), ); testWidgets( 'Navigates to Grouped Bar Single Target Line Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.groupedBarSingleTargetLineChartTileTitle, + groupedBarSingleTargetLineChartTileTitle, ), ); testWidgets( 'Navigates to Stacked Bar Target Line Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.stackedBarTargetLineChart, + stackedBarTargetLineChart, scrollDelta: 200, ), ); @@ -92,7 +88,7 @@ void main() { testWidgets( 'Navigates to Horizontal Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.horizontalBarChart, + horizontalBarChart, scrollDelta: 200, ), ); @@ -100,7 +96,7 @@ void main() { testWidgets( 'Navigates to Stacked Horizontal Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.stackedHorizontalBarChart, + stackedHorizontalBarChart, scrollDelta: 200, ), ); @@ -108,7 +104,7 @@ void main() { testWidgets( 'Navigates to Horizontal Bar Chart with Bar Labels and Renders', (tester) async => tester.navigateToChartAndGolden( - b.horizontalBarLabelChart, + horizontalBarLabelChart, scrollDelta: 200, ), ); @@ -116,7 +112,7 @@ void main() { testWidgets( 'Navigates to Horizontal Bar Chart with Custom Bar Labels and Renders', (tester) async => tester.navigateToChartAndGolden( - b.horizontalBarLabelCustomChart, + horizontalBarLabelCustomChart, scrollDelta: 300, ), ); @@ -124,7 +120,7 @@ void main() { testWidgets( 'Navigates to Vertical Bar Chart with Bar Labels and Renders', (tester) async => tester.navigateToChartAndGolden( - b.verticalBarLabelChart, + verticalBarLabelChart, scrollDelta: 300, ), ); @@ -132,7 +128,7 @@ void main() { testWidgets( 'Navigates to Spark Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.sparkBarChart, + sparkBarChart, scrollDelta: 300, ), ); @@ -140,7 +136,7 @@ void main() { testWidgets( 'Navigates to Grouped Fill Color Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.groupedFillColorChart, + groupedFillColorChart, scrollDelta: 300, ), ); @@ -148,7 +144,7 @@ void main() { testWidgets( 'Navigates to Stacked Fill Color Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.stackedFillColorChart, + stackedFillColorChart, scrollDelta: 300, ), ); @@ -158,7 +154,7 @@ void main() { testWidgets( 'Navigates to Pattern Forward Hatch Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.patternForwardHatchChart, + patternForwardHatchChart, scrollDelta: 300, ), skip: true, @@ -167,7 +163,7 @@ void main() { testWidgets( 'Navigates to Horizontal Pattern Forward Hatch Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.horizontalPatternForwardHatchChart, + horizontalPatternForwardHatchChart, scrollDelta: 300, ), ); @@ -175,7 +171,7 @@ void main() { testWidgets( 'Navigates to Weighted Pattern Bar Chart and Renders', (tester) async => tester.navigateToChartAndGolden( - b.weightedPatternChart, + weightedPatternChart, scrollDelta: 300, ), ); @@ -183,7 +179,7 @@ void main() { testWidgets( 'Navigates to Bar Chart with custom bar radius and Renders', (tester) async => tester.navigateToChartAndGolden( - b.barChartWithCustomBarRadius, + barChartWithCustomBarRadius, scrollDelta: 300, ), ); @@ -198,7 +194,7 @@ extension ExampleWidgetTestExtensions on WidgetTester { double? scrollDelta, }) async { //Create and pump - const galleryApp = m.GalleryApp(); + const galleryApp = GalleryApp(); await pumpWidget(galleryApp); //Set the screen size of the widget @@ -206,7 +202,7 @@ extension ExampleWidgetTestExtensions on WidgetTester { ..physicalSize = const Size(1200, 700) ..devicePixelRatio = 1; - expect(find.byType(h.Home), findsOneWidget); + expect(find.byType(Home), findsOneWidget); // Find the list tile by text final tileFinder = find.byWidgetPredicate( From a1be55b9c1995c9979752d487e7e6da0d78e975a Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Fri, 20 Sep 2024 06:54:16 +1000 Subject: [PATCH 8/9] fix imports --- charts_flutter/pubspec.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts_flutter/pubspec.yaml b/charts_flutter/pubspec.yaml index 7d569fa91..88689592c 100644 --- a/charts_flutter/pubspec.yaml +++ b/charts_flutter/pubspec.yaml @@ -19,6 +19,8 @@ dependencies: dev_dependencies: austerity: ^1.2.0 build_runner: ^2.4.12 + example: + path: example flutter_test: sdk: flutter mockito: ^5.0.0 From cb850a9dca30d5944dd9423e88d9070cf78e4476 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:10:24 +1000 Subject: [PATCH 9/9] format --- .../lib/bar_chart/grouped_stacked_weight_pattern.dart | 2 +- .../example/lib/behaviors/behaviors_gallery.dart | 2 +- .../example/lib/combo_chart/date_time_line_point.dart | 2 +- .../example/lib/combo_chart/ordinal_bar_line.dart | 2 +- .../example/lib/legends/default_hidden_series_legend.dart | 2 +- .../example/lib/legends/legend_custom_symbol.dart | 2 +- charts_flutter/example/lib/legends/legends_gallery.dart | 3 +-- .../example/lib/legends/series_legend_options.dart | 8 ++++---- .../example/lib/legends/simple_datum_legend.dart | 2 +- .../example/lib/legends/simple_series_legend.dart | 2 +- .../lib/time_series_chart/confidence_interval.dart | 2 +- charts_flutter/example/lib/time_series_chart/simple.dart | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) diff --git a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart index 3cf74fd33..7db363b70 100644 --- a/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart +++ b/charts_flutter/example/lib/bar_chart/grouped_stacked_weight_pattern.dart @@ -147,7 +147,7 @@ class GroupedStackedWeightPatternBarChart extends StatelessWidget { // Configure the bar renderer in grouped stacked rendering mode with a // custom weight pattern. // - // The first stack of bars in each group is configured to be twice as + // The first stack of bars in each group is configured to be twice as // wide as the second stack of bars in each group. defaultRenderer: charts.BarRendererConfig( groupingType: charts.BarGroupingType.groupedStacked, diff --git a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart index 343d44c9a..ce628d291 100644 --- a/charts_flutter/example/lib/behaviors/behaviors_gallery.dart +++ b/charts_flutter/example/lib/behaviors/behaviors_gallery.dart @@ -53,7 +53,7 @@ List buildGallery() => [ // listTileIcon: new Icon(Icons.flag), // title: 'Selection Scatter Plot Highlight', // subtitle: 'Scatter plot chart with tap and drag activation', - // childBuilder: () => + // childBuilder: () => //new SelectionScatterPlotHighlight.withRandomData(), // ), const GalleryScaffold( diff --git a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart index 72652e28b..98cd6fee5 100644 --- a/charts_flutter/example/lib/combo_chart/date_time_line_point.dart +++ b/charts_flutter/example/lib/combo_chart/date_time_line_point.dart @@ -122,7 +122,7 @@ class DateTimeComboLinePointChart extends StatelessWidget { ), ], // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If + // should create the same type of [DateTime] as the data provided. If // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart index ea386a774..32124455c 100644 --- a/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart +++ b/charts_flutter/example/lib/combo_chart/ordinal_bar_line.dart @@ -104,7 +104,7 @@ class OrdinalComboBarLineChart extends StatelessWidget { defaultRenderer: charts.BarRendererConfig( groupingType: charts.BarGroupingType.grouped, ), - // Custom renderer configuration for the line series. This will be used + // Custom renderer configuration for the line series. This will be used // for any series that does not define a rendererIdKey. customSeriesRenderers: [ charts.LineRendererConfig( diff --git a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart index 7320f809a..6a3a47cca 100644 --- a/charts_flutter/example/lib/legends/default_hidden_series_legend.dart +++ b/charts_flutter/example/lib/legends/default_hidden_series_legend.dart @@ -109,7 +109,7 @@ class DefaultHiddenSeriesLegend extends StatelessWidget { seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series + // Add the series legend behavior to the chart to turn on series // legends. By default the legend will display above the chart. behaviors: [ charts.SeriesLegend( diff --git a/charts_flutter/example/lib/legends/legend_custom_symbol.dart b/charts_flutter/example/lib/legends/legend_custom_symbol.dart index 4bcb198a0..1f30fb7dd 100644 --- a/charts_flutter/example/lib/legends/legend_custom_symbol.dart +++ b/charts_flutter/example/lib/legends/legend_custom_symbol.dart @@ -141,7 +141,7 @@ class LegendWithCustomSymbol extends StatelessWidget { // Add the legend behavior to the chart to turn on legends. // By default the legend will display above the chart. // - // To change the symbol used in the legend, set the renderer attribute + // To change the symbol used in the legend, set the renderer attribute // of symbolRendererKey to a SymbolRenderer. behaviors: [charts.SeriesLegend()], defaultRenderer: charts.BarRendererConfig( diff --git a/charts_flutter/example/lib/legends/legends_gallery.dart b/charts_flutter/example/lib/legends/legends_gallery.dart index 6fbbd4162..02fd43afe 100644 --- a/charts_flutter/example/lib/legends/legends_gallery.dart +++ b/charts_flutter/example/lib/legends/legends_gallery.dart @@ -34,8 +34,7 @@ List buildGallery() => [ const GalleryScaffold( listTileIcon: Icon(Icons.insert_chart), title: 'Series Legend Options', - subtitle: - 'A series legend with custom positioning ' + subtitle: 'A series legend with custom positioning ' 'and spacing for a bar chart', childBuilder: LegendOptions.withRandomData, ), diff --git a/charts_flutter/example/lib/legends/series_legend_options.dart b/charts_flutter/example/lib/legends/series_legend_options.dart index 6ef385048..6c8701df3 100644 --- a/charts_flutter/example/lib/legends/series_legend_options.dart +++ b/charts_flutter/example/lib/legends/series_legend_options.dart @@ -114,10 +114,10 @@ class LegendOptions extends StatelessWidget { // the legend, in addition to altering the max rows and padding. behaviors: [ charts.SeriesLegend( - // Positions for "start" and "end" will be left and right - // respectively for widgets with a build context that has - // directionality ltr. For rtl, "start" and "end" will be right - // and left respectively. Since this example has directionality + // Positions for "start" and "end" will be left and right + // respectively for widgets with a build context that has + // directionality ltr. For rtl, "start" and "end" will be right + // and left respectively. Since this example has directionality // of ltr, the legend is positioned on the right side of the chart. position: charts.BehaviorPosition.end, // For a legend that is positioned on the left or right of the chart, diff --git a/charts_flutter/example/lib/legends/simple_datum_legend.dart b/charts_flutter/example/lib/legends/simple_datum_legend.dart index f14f82d09..b62d5fc6a 100644 --- a/charts_flutter/example/lib/legends/simple_datum_legend.dart +++ b/charts_flutter/example/lib/legends/simple_datum_legend.dart @@ -64,7 +64,7 @@ class SimpleDatumLegend extends StatelessWidget { Widget build(BuildContext context) => charts.PieChart( seriesList, animate: animate, - // Add the series legend behavior to the chart to turn on series + // Add the series legend behavior to the chart to turn on series // legends. By default the legend will display above the chart. behaviors: [charts.DatumLegend()], ); diff --git a/charts_flutter/example/lib/legends/simple_series_legend.dart b/charts_flutter/example/lib/legends/simple_series_legend.dart index 745166a8a..6afc5595f 100644 --- a/charts_flutter/example/lib/legends/simple_series_legend.dart +++ b/charts_flutter/example/lib/legends/simple_series_legend.dart @@ -104,7 +104,7 @@ class SimpleSeriesLegend extends StatelessWidget { seriesList, animate: animate, barGroupingType: charts.BarGroupingType.grouped, - // Add the series legend behavior to the chart to turn on series + // Add the series legend behavior to the chart to turn on series // legends. By default the legend will display above the chart. behaviors: [charts.SeriesLegend()], ); diff --git a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart index c40587f92..893f2683f 100644 --- a/charts_flutter/example/lib/time_series_chart/confidence_interval.dart +++ b/charts_flutter/example/lib/time_series_chart/confidence_interval.dart @@ -80,7 +80,7 @@ class TimeSeriesConfidenceInterval extends StatelessWidget { seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If + // should create the same type of [DateTime] as the data provided. If // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); diff --git a/charts_flutter/example/lib/time_series_chart/simple.dart b/charts_flutter/example/lib/time_series_chart/simple.dart index 297fa2406..fe0e331aa 100644 --- a/charts_flutter/example/lib/time_series_chart/simple.dart +++ b/charts_flutter/example/lib/time_series_chart/simple.dart @@ -72,7 +72,7 @@ class SimpleTimeSeriesChart extends StatelessWidget { seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory - // should create the same type of [DateTime] as the data provided. If + // should create the same type of [DateTime] as the data provided. If // none specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), );