@weasel-js/plot 0.0.0-stage → 1.15.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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/index.d.ts +679 -0
- package/dist/index.js +860 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 orochi235
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weasel-js/plot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Charts on weasel's scene graph. A chart is a scene node holding its spec, with
|
|
4
|
+
the marks it is drawn with as nodes under it, each keeping the value it stands
|
|
5
|
+
for; dragging a mark edits the spec.
|
|
6
|
+
|
|
7
|
+
Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic 2D
|
|
8
|
+
scene-graph canvas kit for React. See the
|
|
9
|
+
[API reference](https://orochi235.github.io/weasel/#pkg/plot).
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @weasel-js/plot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Two layers
|
|
16
|
+
|
|
17
|
+
**Scales, axes and marks.** A scale maps values onto a range and says which
|
|
18
|
+
values an axis marks and how they read: `linearScale`, `logScale`,
|
|
19
|
+
`bandScale`, `timeScale` (ticks on calendar units, in UTC) and `ordinalScale`.
|
|
20
|
+
`axisMarks` draws an axis from any of the first four: a rule, ticks, labels
|
|
21
|
+
measured through `@weasel-js/text`, grid lines and a title. The mark builders
|
|
22
|
+
(`barMark`, `spanMark`, `lineMark`, `areaMark`, `pointMark`, `arcMark`,
|
|
23
|
+
`ribbonMark`, `ruleMark`, `textMark`) each return a `PlotMark`: a key, a box,
|
|
24
|
+
and data the kit's own painters draw, with the datum under `plotMark`, so a
|
|
25
|
+
hit-test on a mark reaches its value.
|
|
26
|
+
|
|
27
|
+
**Chart specs.** `PlotData` is a union of chart specs on `kind`; today it holds
|
|
28
|
+
`xychart`, bar and line series over a category band or a numeric range.
|
|
29
|
+
`plotSpecs(data, { box })` compiles one to scene node specs: a group root whose
|
|
30
|
+
data is `{ plot: { data, theme } }`, then every mark under it, in the root's
|
|
31
|
+
frame. `replacePlotData` swaps a root's spec and rebuilds its marks as one undo
|
|
32
|
+
entry. `plotEditing({ scene })` gives the handle layer and the contribution
|
|
33
|
+
that bind a drag on a bar's end or a line's point to `plot.dragValue`;
|
|
34
|
+
`PlotView` hosts one chart on a canvas of its own with both wired.
|
|
35
|
+
|
|
36
|
+
Colors come from a `PlotTheme`, by role: `text`, `axis`, `grid`, and `series`,
|
|
37
|
+
which series take in turn. `plotThemeFrom` builds one from a resolved
|
|
38
|
+
`@weasel-js/theme` theme; `PLOT_THEME` is the weasel theme's dark mode.
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { registerCanvasFont } from '@weasel-js/font';
|
|
42
|
+
import { PlotView, type PlotData } from '@weasel-js/plot';
|
|
43
|
+
import { useState } from 'react';
|
|
44
|
+
|
|
45
|
+
registerCanvasFont('sans-serif');
|
|
46
|
+
|
|
47
|
+
const SALES: PlotData = {
|
|
48
|
+
kind: 'xychart',
|
|
49
|
+
title: 'Sales',
|
|
50
|
+
x: { kind: 'band', categories: ['jan', 'feb', 'mar'] },
|
|
51
|
+
y: { title: 'Revenue', min: 0, max: 100 },
|
|
52
|
+
series: [{ kind: 'bar', values: [20, 50, 80] }, { kind: 'line', values: [10, 60, 40] }],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export function Sales() {
|
|
56
|
+
const [data, setData] = useState(SALES);
|
|
57
|
+
return <PlotView data={data} onChange={setData} width={600} height={400} />;
|
|
58
|
+
}
|
|
59
|
+
```
|