From aa260453c7de2854eb829701ee4f28415b9efc69 Mon Sep 17 00:00:00 2001 From: Oleh Marchenko Date: Mon, 19 Aug 2024 12:15:30 +0300 Subject: [PATCH] added isDefault to `GridAxisData`s, painting `defaultDivisionInterval` if data is default --- CHANGELOG.md | 5 +++++ lib/src/candlestick/data.dart | 4 ++++ lib/src/common/chart.data.dart | 3 +++ lib/src/common/gridaxis/painter.dart | 2 +- lib/src/line/data.dart | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da66eab..357779c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 6.2.1 - 19.08.2024 + +* Changes of the `GridAxis` based charts (`LineChart`/`CandlestickChart`): + * Added extra condition (if data is default alongside with empty data) for painting `GridAxisSettings.defaultDivisionInterval`. + ## 6.2.0 - 19.08.2024 * Changes of the `GridAxis` based charts (`LineChart`/`CandlestickChart`): diff --git a/lib/src/candlestick/data.dart b/lib/src/candlestick/data.dart index c250bec..b63973e 100644 --- a/lib/src/candlestick/data.dart +++ b/lib/src/candlestick/data.dart @@ -146,6 +146,10 @@ class CandlestickChartData extends GridAxisData { @override double minValuePredicate(CandlestickData value) => value.low; + @override + bool get isDefault => + data.values.every((v) => v == const CandlestickData.zero()); + /// Creates a copy of the current object with new values specified in /// arguments. CandlestickChartData copyWith({ diff --git a/lib/src/common/chart.data.dart b/lib/src/common/chart.data.dart index e7eeb47..5d000d4 100644 --- a/lib/src/common/chart.data.dart +++ b/lib/src/common/chart.data.dart @@ -67,6 +67,9 @@ abstract class ChartData { /// It checks for [data] length to be greater than or equal to 1. bool get canDraw => data.isNotEmpty; + /// Checks whether every data entry is a default value ot not. + bool get isDefault; + /// Checks whether every data entry is less than or equal to `0` and any of /// it strictly less than `0` or not. bool get isNegative => diff --git a/lib/src/common/gridaxis/painter.dart b/lib/src/common/gridaxis/painter.dart index 810f8d3..361020a 100644 --- a/lib/src/common/gridaxis/painter.dart +++ b/lib/src/common/gridaxis/painter.dart @@ -97,7 +97,7 @@ class GridAxisPainter extends CustomPainter { } double labelValue; - if (data.data.isEmpty) { + if (data.data.isEmpty || data.isDefault) { labelValue = mult(math.max(settings.defaultDivisionInterval, 1), yEnd - i - 1); } else if (data.isNegative) { diff --git a/lib/src/line/data.dart b/lib/src/line/data.dart index f0d38c5..80a94c6 100644 --- a/lib/src/line/data.dart +++ b/lib/src/line/data.dart @@ -66,6 +66,9 @@ class LineChartData extends GridAxisData { @override double minValuePredicate(double value) => value; + @override + bool get isDefault => data.values.every((v) => v == 0); + /// {@macro ChartData.maxValue} /// (Omitting [limit] value) ///