@sketchmark/plugin-graph 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sketchmark contributors
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 ADDED
@@ -0,0 +1,69 @@
1
+ # @sketchmark/plugin-graph
2
+
3
+ Lightweight coordinate-plane graphing for Sketchmark.
4
+
5
+ This package keeps the core renderer small by compiling `graph.*` commands into ordinary Sketchmark `path`, `circle`, and `text` nodes. It focuses on plotting and teaching visuals, not symbolic math or CAS-style solving.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install sketchmark @sketchmark/plugin-graph
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { render } from "sketchmark";
17
+ import { graph } from "@sketchmark/plugin-graph";
18
+ import { annotations } from "@sketchmark/plugin-annotations";
19
+
20
+ render({
21
+ container: document.getElementById("diagram")!,
22
+ dsl: `
23
+ diagram
24
+ title label="Sine Graph"
25
+
26
+ graph.axes plane x=80 y=60 width=520 height=280 xmin=-6.28 xmax=6.28 ymin=-1.5 ymax=1.5 grid=true xlabel="x" ylabel="y"
27
+ graph.plot sinCurve axes=plane expr="sin(x)" label="sin(x)"
28
+ graph.point O axes=plane at=[0,0] label="O"
29
+ graph.point P axes=plane at=[1.57,1] label="P"
30
+
31
+ annot.dimension rise from=O to=P label="rise"
32
+ end
33
+ `.trim(),
34
+ plugins: [graph(), annotations()],
35
+ });
36
+ ```
37
+
38
+ ## Supported Commands
39
+
40
+ - `graph.axes <id> x=<n> y=<n> width=<n> height=<n> xmin=<n> xmax=<n> ymin=<n> ymax=<n> [grid=true] [ticks=true]`
41
+ - `graph.plot <id> axes=<axesId> expr="..." [from=<n>] [to=<n>] [samples=<n>] [label="..."]`
42
+ - `graph.point <id> axes=<axesId> at=[x,y] [label="..."] [r=<n>]`
43
+ - `graph.label <id> axes=<axesId> at=[x,y] text="..."` or `graph.label <id> target=<pointId> text="..."`
44
+ - `graph.line <id> axes=<axesId> from=[x1,y1] to=[x2,y2] [label="..."]`
45
+ - `graph.arrow <id> axes=<axesId> from=[x1,y1] to=[x2,y2] [label="..."]`
46
+ - `graph.region <id> axes=<axesId> points=[[x1,y1],[x2,y2],...] [label="..."]`
47
+ - `graph.tangent <id> axes=<axesId>|plot=<plotId> expr="..."|plot=<plotId> at=<n> [span=<n>] [label="..."]`
48
+ - `graph.area <id> axes=<axesId>|plot=<plotId> expr="..."|plot=<plotId> from=<n> to=<n> [baseline=<n>] [label="..."]`
49
+
50
+ ## Notes
51
+
52
+ - Graph commands are root-level in `v1`.
53
+ - The plugin auto-inserts `layout absolute` if the diagram does not declare a layout yet.
54
+ - If a diagram already declares a layout, it must be `layout absolute`.
55
+ - `graph.point` compiles to a real authored node, so existing `annot.*` commands can target graph points directly.
56
+ - `graph.plot`, `graph.tangent`, and `graph.area` support lightweight expression strings like `sin(x)`, `cos(x)`, `x^2`, `sqrt(x)`, and `exp(x)`.
57
+ - This is draw-first graphing, not a full symbolic math system.
58
+
59
+ ## Options
60
+
61
+ ```ts
62
+ graph({
63
+ autoAbsoluteLayout: true,
64
+ axisStroke: "#2b190d",
65
+ gridStroke: "#cbbba3",
66
+ pointRadius: 4,
67
+ samples: 96,
68
+ });
69
+ ```