Plotfast
Canvas plotting library focused on performance.
Check it out with a million points here!
Usage
npm install plotfast
or yarn add plotfast
Or include the plotfast.min.js
script and it'll expose the Plotfast
global.
Then, in your HTML:
And initialize the plot in JS:
// Plot will be inserted into this div,// canvas creation handled automaticallyvar container = document; // Create the plotvar plot = container; // Generate 10k points of datavar data = plot; // Add the data to the plotplot; // Start rendering the plotplotstart;
Or use the React component (in beta):
; const data = ; const MyPlot = <Plot options= logging: true datasets= data options: type: 'line' />;
Features
Data
Data is an array of objects in the form { x, y }
. Data will be sorted by x
value on initialization.
// Add new data, with optionsplot; // Replace the data of an existing dataset// (Useful for server-side decimation)plot; // Remove a dataset, by indexplot; // Or by nameplot; // Or remove all datasetsplot;
Plot Options
var plot = container logging: true // Dimensions of the canvas width: 640 height: 480 // Labels to display on the axes xLabel: 'X axis' yLabel: 'Y axis' // Colors lineColor: 'lightgrey' textColor: 'black' backgroundColor: 'none' // Downsample data to improve performance downsample: true;
Data Options
var data = x: 1 y: 0 x: 2 y: 5 ; plot;
Events
// Fires whenever the view changes and gives the new// min/max for x and y.plot;
Development
- Clone repo, run
yarn install
- Start the development server with
yarn start
- Create a production build with
yarn build
Future Plans
- Flesh out plot customization/types
- In
Plot
React component, all normal Plotfast functionality should be exposed - Try using WebAssembly to speed up plot downsampling/rendering
Credit
Default downsampling algorithm provided by Sveinn Steinarsson's Largest Triangle Three Buckets Algorithm.
Icons are from Google's Material Icons.