yuankunzhang / charming

A visualization library for Rust
Apache License 2.0
1.85k stars 74 forks source link

Charts aren't self-validating, and Deno errors are hard to interpret #109

Open BatmanAoD opened 3 weeks ago

BatmanAoD commented 3 weeks ago

When a chart doesn't have all necessary components, the error isn't seen until attempting to render the chart. When rendering with Deno, the errors are difficult to understand.

For instance, when trying to create a scatterplot without axis definitions and symbol size, I got this error:

Error: could not generate plot: JavaScript runtime error: TypeError: Cannot read properties of undefined (reading 'get')
    at dx ([echarts.js]:45:242937)
    at cartesian2d ([echarts.js]:45:241875)
    at [echarts.js]:45:244376
    at vx ([echarts.js]:45:244413)
    at e.getInitialData ([echarts.js]:45:380659)
    at e.init ([echarts.js]:45:158807)
    at e.<anonymous> ([echarts.js]:45:113758)
    at Array.forEach (<anonymous>)
    at E ([echarts.js]:35:5056)
    at e.<anonymous> ([echarts.js]:45:113391)
caused by: JavaScript runtime error: TypeError: Cannot read properties of undefined (reading 'get')
    at dx ([echarts.js]:45:242937)
    at cartesian2d ([echarts.js]:45:241875)
    at [echarts.js]:45:244376
    at vx ([echarts.js]:45:244413)
    at e.getInitialData ([echarts.js]:45:380659)
    at e.init ([echarts.js]:45:158807)
    at e.<anonymous> ([echarts.js]:45:113758)
    at Array.forEach (<anonymous>)
    at E ([echarts.js]:35:5056)
    at e.<anonymous> ([echarts.js]:45:113391)

I think it would be good for charming to do some or all of these:

LukaOber commented 3 weeks ago

Provide a simple way to validate a Chart. (In a typical builder pattern, there's a build() function that turns the builder into a final object, and performs validation on it.)

Simple is an understatement, currently we are not doing any validation. This would require a huge amount of effort and also a shift in the library from a strict translation library to a check, validate and translate. I would be interested in implementing this, or help someone to implement this, but I am not sure if it is feasible. Is this being done in echarts when using JavaScript?

Document which elements of a chart are necessary for rendering

I think this would be easier, we could add some documentation on which components are needed. Do you know of an overview where we can easily see the required components for each chart type?

Do something to improve the JavaScript errors themselves (in particular, reading 'get' doesn't say what is missing)

This error message is bad, but I also believe we can't do anything about this. We are just calling the echarts library and the error is propagating from there. (But I am not a JavaScript person, I could be wrong on this)

BatmanAoD commented 3 weeks ago

Simple is an understatement, currently we are not doing any validation. This would require a huge amount of effort and also a shift in the library from a strict translation library to a check, validate and translate.

Right, sorry, I meant "simple" from the user's perspective.