A Svelte component library for composing responsive interactive data visualisations.
This package is in active but early development. The API should be regarded as unstable until version 1.0.0. The project is targetting Svelte 5 and uses runes.
The initial project goal was to develop the smallest set of fully-functional components needed to make a responsive scatterplot, using the project's approach to configuring component settings and managing state. This milestone has been reached. The list of components created to achieve this goal are listed below.
ColorSchemeObserver
Visualisation
Header
Footer
Graphic
Svg
Gridlines
AxisX
AxisY
Plot
CircleGeometry
The priorities for future work are:
- Create more geometry components
- Develop an approach to event handling to support pop-ups and other interactive components
- Develop an approach to implementing animation
If you want to try the existing components, the easiest way right now is to download and run the demo project.
-
Clone the project repository from GitHub
-
Run
npm install --force
to install the dependencies (theforce
argument is needed because the project uses Svelte 5, which is in beta) -
Run
npm run dev
to start the demo application on localhost:5173
It is also possible to install the package from NPM into a Vite Svelte template, but this requires modifying the template to run Svelte 5.
-
Create a Svelte project with Vite using
npm create vite@latest my-svelte-project -- --template svelte
-
Run
npm install
to install the dependencies -
Update Svelte to version 5 with
npm i svelte@next
-
Install the package with
npm install sveltevis
Note that you will need to edit main.js
in the Vite project to replace the old method of instantiating the app with the new method.
// Add import for createRoot function
import { createRoot } from 'svelte';
// Comment out old method of instantiation
// const app = new App({
// target: document.getElementById('app'),
// })
// Add new method
const app = createRoot(App, { target: document.getElementById("app") });
SvelteVis allows you to target the styles used in its components using your own stylesheet, so that the styles of your visualisations match your website. Importing SvelteVis components into a new project doesn't automatically add the default styles used in the demo application. However, if you want to use these stylesheets as a starting point for making modifications, they can be found in the css
folder: simply copy them as stylesheets to use in your own app.
The stylesheet for targeting SvelteVis components is called sveltevis.css
and this is the stylesheet you should modify to implement your own visualisation styles. The site.css
stylesheet is the css used for the demo application, and it doesn't contain any of the selectors used to target the visualisation components. Both of these default stylesheets are set up to provide alternate light and dark styles based on the operating system mode.