RangeAnnotations along measure axis fail due to assuming range values are DateTime #74
Comments
continues to reproduce on charts version 0.4.0 |
Same problem here, but I got a suggestion: The problem is in the following code
_getAnnotationDatum() needs parameters of type D, which is (I strongly guess) is DateTime in the TimeSeriesChart . But at the measure axis the type should be int .
final annotationDatum = _getAnnotationDatum(annotation.startValue,
annotation.endValue, axis, annotation.axisType);
...
// _getAnnotationDatum() definition
_DatumAnnotation<D> _getAnnotationDatum(D startValue, D endValue,
ImmutableAxis<D> axis, RangeAnnotationAxisType axisType) {
final startPosition = axis.getLocation(startValue);
final endPosition = axis.getLocation(endValue);
return new _DatumAnnotation<D>(
startPosition: startPosition,
endPosition: endPosition,
axisType: axisType);
} My solutionBy inlining the final annotationDatum = new _DatumAnnotation<D>(
startPosition: axis.getLocation(annotation.startValue),
endPosition: axis.getLocation(annotation.endValue),
axisType: annotation.axisType); I don't have very good internal knowledge about this library, so I can not ensure that this will fix the bug completely and will not cause side effects. |
Thanks for the encouragement. By changing the type of the parameters on I tested the forthcoming pull request fix with: my app, the test code at the top of this issue, and the chart gallery app that comes with this chart package. Those that worked before continue to work the same. Those that failed with an exception before, now work. With this fixed, it exposes a painting oddity in the test code at the top. The annotation shading extends beyond the right edge of the chart. I consider that a separate issue, so I will not address that in a forthcoming pull request related to this issue. While investigating this bug, I saw several classes in class _DatumAnnotation<D>
class _AnimatedAnnotation<D>
class _AnnotationElement<D> |
- fixes issue so that measure axis annotations can be DateTime, int, or float
I just found out the bug is fixed now with 67709bc, but the new github version is not yet available via the packet manager. To temporarily work with the fixed (and enhanced version) I cloned the project and included charts_flutter locally: pubspec.yaml: charts_flutter:
path: <path_to_repo>/charts_flutter Just in case someone needs the fix asap ;) |
Range annotations along the measure axis fail due to assuming all annotation start/end values are DateTime.
Setup
Repo
main.dart
with code belowpubspec.yaml
the following dependency:charts_flutter: "^0.3.0"
Result
Notes
In charts_common/src/chart/common/behavior/range_annotation.dart:147 is a call to
_getAnnotationDatum()
which due to the generic's type, is assuming that thestartValue
andendValue
areDateTime
. However, on the measure axis in this repo, they areint
-> leading to the exception.I don't have an immediate recommendation as type changes to that class will likely cascade.
The only lines which cause the exception are 78-79 in the main.dart code below. I copied the code from this repo's example for annotations... changed the start/end values from
DateTime
toint
values... changed axis type tocharts.RangeAnnotationAxisType.measure
.main.dart
The text was updated successfully, but these errors were encountered: