question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uPlot does not take typed arrays as data

See original GitHub issue

This is a comment I got on stack overflow, when my example failed to render: https://stackoverflow.com/questions/72880591/using-uplot-with-svelte-does-not-render/72881761#72881761

I see that it does take typed arrays in the demo (https://github.com/leeoniya/uPlot/blob/master/demos/area-fill.html), but not when used as an npm package. Which is very confusing 🤔

Another (simpler) example is to use Vite with vanilla js, and the following files:

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Vite App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <link rel="stylesheet" href="node_modules/uplot/dist/uPlot.min.css"/>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

main.ts

import uPlot from 'uplot';

let data = [
  new Float32Array([1., 2., 3., 4., 5.]),
  new Float32Array([1., 3., 2., 5., 4.]),
];

const opts = {
  width: 600,
  height: 300,
  scales: {x: {time: false}},
  series: [
      {label: "x"},
      {label: "y", stroke: "red"},
  ],
};

new uPlot(opts, data, document.body);

If I remove Float32Array things get rendered properly. npm installs uplot version 1.6.21`.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leeoniyacommented, Jul 6, 2022

fixed in f0af226e735bafb21feb18755cb95dc1dbdcc7f1

0reactions
leeoniyacommented, Jul 6, 2022

ah, okay. if i omit AlignedData, then it complains. i can add TypedArray[] to the signature

Read more comments on GitHub >

github_iconTop Results From Across the Web

scatter plots · Issue #107 · leeoniya/uPlot - GitHub
I don't understand why this would need a different data ... nice benefit is we can use typed arrays too, and the value...
Read more >
Typed arrays - Binary data in the browser - web.dev
Typed Arrays are a relatively recent addition to browsers, born out of the need to have an efficient way to handle binary data...
Read more >
Using uPlot with svelte, does not render - Stack Overflow
uPlot does not take typed arrays as data; The reactive statement is a bit pointless, as it only triggers in a meaningful once...
Read more >
20. Typed Arrays - Exploring JS
Typed Arrays are an ECMAScript 6 API for handling binary data. ... a normal Array, but only allows a single type for its...
Read more >
ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
In web-development we meet binary data mostly while dealing with files (create, upload, download). Another typical use case is image ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found