swimlane / ngx-charts

:bar_chart: Declarative Charting Framework for Angular
https://swimlane.github.io/ngx-charts/
MIT License
4.3k stars 1.15k forks source link

yScaleMin,xScaleMin,yScaleMax,xScaleMax have wrong type and do not work properly for zero #1754

Open uap-universe opened 2 years ago

uap-universe commented 2 years ago

Describe the bug This is wrong code: https://github.com/swimlane/ngx-charts/blob/0072792306943f91816e952c978f7b3240bd178e/projects/swimlane/ngx-charts/src/lib/line-chart/line-chart.component.ts#L399

The same mistake has been repeated for all scale min/max attributes.

To Reproduce Steps to reproduce the behavior:

  1. Go to the show case application
  2. Select a chart type supporting the {x,y}Scale{Min,Max} attributes
  3. Select zero
  4. See that it does not affect the chart

Expected behavior The axis min/max should be zero.

Actual behavior The attribute has the wrong type (should be number|undefined) and the test for undefined is wrong (should be yScaleMin !== undefined). So a zero is interpreted as falsy. Therefore, the ternary expression returns the calculated min/max instead of using zero.

ngx-charts version 20.1.0

Zoraiyo commented 2 years ago

Unfortunately, this error has been occurring for a long time. I have already created a PR that should solve this. #1627