svelte-plots-basic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Svelte plots
2
+
3
+ ## Description
4
+
5
+ `svelte-plots-basic` is a [Svelte](https://svelte.dev) component library for creating very simple 2D plots/charts. It is currently under active development and breaking changes may occur. In its current state (v. 0.1.0) it allows to create bar, scatter, area and line charts as well as any combination of the four. The charts are created using [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) and are re-scalable.
6
+
7
+ The description is not complete yet and will be updated during February-March of 2022.
8
+
9
+ ## Installation
10
+
11
+ The set up process is similar to any other Svelte component library. Just use:
12
+
13
+ ```
14
+ npm -i -D svelte-plots-basic
15
+ ```
16
+
17
+ or, to install it with yarn:
18
+
19
+ ```
20
+ yarn add -D svelte-plots-basic
21
+ ```
22
+
23
+
24
+
25
+ ## Quick start
26
+
27
+ It is assumed that you already know the basics of Svelte.
28
+
29
+ Just create a new Svelte app following the [quick start guide](https://svelte.dev/blog/the-easiest-way-to-get-started). Then open `App.svelte` file, delete everything and write the following code, which creates a simple bar chart:
30
+
31
+ ```js
32
+ <script>
33
+ import {Axes, BarSeries} from 'svelte-plots';
34
+
35
+ // test data for the plot
36
+ const years = [2010, 2020, 2030, 2040, 2050];
37
+ const amount = [100, 200, 150, 300, -100];
38
+ </script>
39
+
40
+ <div class="plot">
41
+ <Axes>
42
+ <BarSeries
43
+ title="Economy"
44
+ showLabels="no"
45
+ faceColor="#e0e0e0"
46
+ edgeColor="#e0e0e0"
47
+ labels="{years}"
48
+ xValues="{years}"
49
+ yValues="{amount}"
50
+ />
51
+ </Axes>
52
+ </div>
53
+ ```
54
+
55
+ Then run `npm run dev` in terminal and open `localhost:5000` in browser. That is it.
56
+
57
+ Example below shows how to create a plot with axis, box and grid as well as how to combine several plot series together.
58
+
59
+ ```js
60
+ <script>
61
+ import {Axes, BarSeries} from 'svelte-plots';
62
+
63
+ // test data for the plot
64
+ const years = [2010, 2020, 2030, 2040, 2050];
65
+ const amount = [100, 200, 150, 300, -100];
66
+ </script>
67
+
68
+ <div class="plot">
69
+ <Axes>
70
+ // x and y axis with automatic ticks and grid lines
71
+ <XAxis showGrid="{true}"></XAxis>
72
+ <YAxis showGrid="{true}"></YAxis>
73
+
74
+ // bar, line and marker series with the same data values
75
+ <BarSeries
76
+ showLabels="no"
77
+ faceColor="#eee"
78
+ edgeColor="#eee"
79
+ xValues="{years}"
80
+ yValues="{amount}"
81
+ />
82
+ <LineSeries
83
+ lineColor="blue"
84
+ lineWidth="{2}"
85
+ xValues="{years}"
86
+ yValues="{amount}"
87
+ />
88
+ <ScatterSeries
89
+ marker="✺"
90
+ showLabels="hover"
91
+ markerColor="blue"
92
+ labels="{years}"
93
+ xValues="{years}"
94
+ yValues="{amount}"
95
+ />
96
+
97
+ // box around the axes
98
+ <Box />
99
+ </Axes>
100
+ </div>
101
+ ```
102
+
103
+ ## Details
104
+
105
+ The library has following components:
106
+
107
+ ### Axes
108
+
109
+ `Axes` this is a main component, which is responsible for showing all other plot elements (axis, labels, titles, primitives, series, etc.). The `Axes` component must be always a parent for all other components. It has four optional parameters:
110
+
111
+ * `limX` — vector with two values - x-axis limits (min and max) in plot units.
112
+ * `limY` — vector with two values - y-axis limits (min and max) in plot units.
113
+ * `title` — a text to be shown as a plot title (on top of the plot).
114
+ * `xLabel` — a label for x-axis (shown under the axis).
115
+ * `yLabel` — a label for y-axis (shown on the right side of the axis).
116
+
117
+ If limits are not provided, the component will compute them automatically when/if you add one or several plot series. If you want to show axes without any series or use primitives instead, you need to provide the values for limits explicitly.
118
+
119
+ The `Axes` operates in two coordinate systems. One is related to plot units. For example if you make a scatter plot for Height vs Weight of people, then the x-units will be cm and y-units will be kg. The x-axis will be directed from left to right and y-axis from bottom to up, like in conventional plots. The component then will automatically recompute the coordinates of all plot elements from the plot units to pixels, depending on the current size of the plot shown in browser.
120
+
121
+ ### XAxis and YAxis
122
+
123
+ Each component is responsible for visualization of the corresponding axis. The axis is shown in form of a line with outer ticks and related labels. Number of ticks and their values are computed automatically until you do not specify them as a component parameter. Each component has two optional parameters:
124
+
125
+ * `ticks` — vector with ticks
126
+ * `tickLabels` — vector with values to be shown as labels beside each tick
127
+ * `showGrid` — a logical parameter, which allows to show grid lines on the plot
128
+
129
+ The components must be placed in a particular slot of the parent `Axes` component.
130
+