Closed calculabs closed 2 years ago
This is addressed in version 0.3.2 with a new parameter initialVisibleCandleCount
.
@h65wang Hey! Thank you for the quick response time with initialVisibleCandleCount
.
I believe I found an issue regarding it however.
Whenever I scroll past the original candle data, past the initialVisibleCandleCount
I get this error: in chart_painter.dart line 152
Failed assertion: line 52 pos 10: '<optimized out>': Offset argument contained a NaN value.
It seems once I pan to the right, passing the index of initialVisibleCandleCount
the entire graph crashes.
Thank you!
@kevincherryholme This is not a bug regarding the new parameter. It might be something wrong with your data, or other modifications you made in your fork.
@h65wang Hey! I think you're right that it does involve the data, but I think the exception can be avoided via code.
If you provide a list of CandleData with the exact same data, for example
[
CandleData(timestamp: DateTime.now().millisecondsSinceEpoch, open: 48, close: 51, volume: 4),
CandleData(timestamp: DateTime.now().millisecondsSinceEpoch, open: 48, close: 51, volume: 4),
CandleData(timestamp: DateTime.now().millisecondsSinceEpoch, open: 48, close: 51, volume: 4),
CandleData(timestamp: DateTime.now().millisecondsSinceEpoch, open: 48, close: 51, volume: 4),
CandleData(timestamp: DateTime.now().millisecondsSinceEpoch, open: 48, close: 51, volume: 4),
...
]
The fitVolume()
method of painter_params.dart
throws a NaN exception. Specifically, the volGridSize
equals to Infinity because we divide by 0. See below my results from debugging:
// This is the method:
double fitVolume(double y) {
try {
final gap = 12; // the gap between price bars and volume bars
final baseAmount = 2; // display at least "something" for the lowest volume
final volGridSize = (volumeHeight - baseAmount - gap) / (maxVol - minVol);
final vol = (y - minVol) * volGridSize;
return volumeHeight - vol + priceHeight - baseAmount;
} catch (e) {
print(e);
return 0;
}
}
Screenshot:
I believe this happens because (maxVol - minVol)
is (4 - 4)
which results to 0
. Dividing by zero throws the exception.
I am not sure if this means the data should be changed, or if we should change the fitVolume() method. What do you think @h65wang ?
I hope this helps clarify things! Cheers for the awesome package!
This has been fixed in v0.3.4.
Hello The initial zoom level doesn't work when I update the state of a widget which updates the candles for the same chart component. For example, a monthly and yearly view. If I move from yearly view to monthly view where candles in monthly few are much less then yearly view it throws error. However switching from monthly view to yearly works fine.
Would it be possible for you implement the ability to set a default zoom? By this, we mean zoomed all the way in or zoomed all the way out, when the chart is created.
Currently, it's zooming in a bit by default and there are candlesticks outside of the viewport width.