echarts Give TypedArray as input

omvjsjqw  于 2022-11-13  发布在  Echarts
关注(0)|答案(1)|浏览(147)

In the documentation, it is written:
ECharts supports TypedArray, which occupies less memory than array and is more gabbage-collection-friendly. For big data visualization, it is suggested to use TypedArray to improve performance.

Yet this fail (using either float32 or float64):

dataset:{ dimensions: [ {name: 'x', type: 'float'}, {name: 'y', type: 'float'} ], source: [ Float32Array.from([1, 2, 3, 4, 5]), Float32Array.from([6, 7, 8, 9, 10]) ] }

While interestingly this works:

dataset:{ dimensions: [ {name: 'x', type: 'float'}, {name: 'y', type: 'float'} ], source: [ [1, 2, 3, 4, 5], Float32Array.from([6, 7, 8, 9, 10]) ] }

cpjpxq1n

cpjpxq1n1#

Yet this fail (using either float32 or float64):
dataset:{ dimensions: [ {name: 'x', type: 'float'}, {name: 'y', type: 'float'} ], source: [ Float32Array.from([1, 2, 3, 4, 5]), Float32Array.from([6, 7, 8, 9, 10]) ] }

This first version using two Float32Arrays doesn't work because the sourceFormat is detected as SOURCE_FORMAT_OBJECT_ROWS . Looking here (current master branch):

https://github.com/apache/incubator-echarts/blob/f765b203791b2a452cb5418d55e97a076ce532dc/src/data/Source.ts#L308-L310

The second version works since the check marks it as SOURCE_FORMAT_ARRAY_ROWS , which is what we want.

Just updating the check from

else if (isArray(item)) {

to

else if (isArray(item) || isTypedArray(item)) {

seems to be enough to make it work with typed arrays without extra conversions. I tested with line and bar series, no issues so far. I'll report back if I hit other issues.

@pissang, in another ticket, similar usage but without dataset , you mentioned this wasn't in the plans (#13335 (comment) in reply to @lukasberbuer). Would you consider this small change to enable us to use a dataset with a list of typed arrays?

相关问题