nativescript-community / nativescript-community/ui-chart
Bad reference when using cubic bezier for Line chart
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 37
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
Summary
There seems to be a crash with the cubic bezier generate function for the line chart renderer when the data set changes and the graph is redrawn.
We have a line chart that displays a set of data for a time frame (x-axis is time). The chart refreshes once a minute and slowly shifts the graph away. Our API also only returns data for the valid time frame, e.g. if on the first load we may have 12 data points, and on the next call the first (oldest) data point will no longer get sent down and the graph will no longer display it.
I have not been able to figure out the exact steps to make it happen, but the crash generally occurs when the app is open and the device is locked for a few minutes, after unlocking the device the app crashes.
JS: ERROR: UnhandledError Error: Calling js method onDraw failed
JS: TypeError: Cannot read property 'next' of undefined generateCubicPath(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:243:0)
JS: at draw(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:414:0)
JS: at drawDataSet(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:146:0)
JS: at drawData(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:129:0)
JS: at onDraw(file: node_modules/@nativescript-community/ui-chart/charts/BarLineChartBase.js:120:0)
JS: at onDraw(file: node_modules/@nativescript-community/ui-canvas/canvas.android.js:538:0)
Expected Behavior
No bad reference when computing the cubic bezier path.
Possible Solution
Add an extra check for the first pass of the cubic path generate logic.
Device (please complete the following information):
- Device: Google Pixel 4
- Android Version: 10.0
- Library Version: 1.2.14
Additional Context
The bad reference line in question is
https://github.com/nativescript-community/ui-chart/blob/2b6dd7fb328795b47b8beaf9a3e3efcf61fdbc37/src/charting/renderer/LineChartRenderer.ts#L353
https://github.com/nativescript-community/ui-chart/blob/2b6dd7fb328795b47b8beaf9a3e3efcf61fdbc37/src/charting/renderer/LineChartRenderer.ts#L320-L363
and my guess is this is happening because on the first run of this loop, j which is firstIndex is greater than 0, so the code tries to reference prevControlPoints which has not be created yet.
ADD A REWARD using Speed to SOLVE this issue QUICKLY and SUPPORT this project.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/charting/renderer/LineChartRenderer.ts, especially lines 320-363 referenced in the report, and compare them with the stack trace at generateCubicPath. Reproduce a redraw after the line-chart data shifts or changes, including the device-lock scenario if possible. Done means cubic-path generation no longer references an undefined value or crashes during redraw.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- data-visualization, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100