Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a default zoom #6

Closed
calculabs opened this issue Nov 9, 2021 · 6 comments
Closed

Setting a default zoom #6

calculabs opened this issue Nov 9, 2021 · 6 comments

Comments

@calculabs
Copy link

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.

@h65wang
Copy link
Collaborator

h65wang commented Nov 9, 2021

This is addressed in version 0.3.2 with a new parameter initialVisibleCandleCount.

@kevincherryholme
Copy link

@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!

@h65wang
Copy link
Collaborator

h65wang commented Nov 10, 2021

@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.

@kevincherryholme
Copy link

@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:
image
image

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!

@h65wang
Copy link
Collaborator

h65wang commented Dec 22, 2021

This has been fixed in v0.3.4.

@akshg05
Copy link

akshg05 commented May 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants