@motionscript/math 0.0.0-stage → 0.1.0-alpha.10
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/CHANGELOG.md +144 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +389 -2
- package/dist/annotate/angle-mark.d.ts +96 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +97 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +115 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +99 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +80 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +80 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +71 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +45 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +28 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +29 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +79 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +109 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +109 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +163 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +32 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +92 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +72 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +87 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +20 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +66 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +31 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +71 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +51 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +59 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +57 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +43 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +71 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +71 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +58 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +63 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +71 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +89 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +60 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +67 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +43 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +57 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +159 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +184 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +64 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +72 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +76 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +122 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +70 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +41 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +60 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +77 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +174 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +240 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +114 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +161 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +197 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +157 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +101 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +91 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +168 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +186 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +98 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +139 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +10 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +101 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +56 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +98 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +25 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +247 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +187 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +126 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +109 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +42 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +99 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +34 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +43 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +58 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +207 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +261 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +96 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +53 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +80 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +137 -0
- package/src/annotate/curly-brace.ts +148 -0
- package/src/annotate/emphasis-mark.ts +118 -0
- package/src/engine.ts +86 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/component.ts +57 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +47 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +171 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +229 -0
- package/src/kit/furniture.ts +113 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +152 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +77 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +105 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +71 -0
- package/src/marks/plot-point.ts +102 -0
- package/src/marks/riemann-sum.ts +99 -0
- package/src/marks/tangent-line.ts +119 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +99 -0
- package/src/plots/function-plot.ts +220 -0
- package/src/plots/points-plot.ts +103 -0
- package/src/plots/stream-lines.ts +160 -0
- package/src/plots/traced-path.ts +70 -0
- package/src/plots/vector-field.ts +107 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +291 -0
- package/src/structures/sample-space.ts +210 -0
- package/src/systems/axes2d.ts +226 -0
- package/src/systems/number-line.ts +130 -0
- package/src/systems/number-plane.ts +232 -0
- package/src/systems/polar-plane.ts +177 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +15 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +97 -0
- package/src/tex/node.ts +74 -0
- package/src/tex/tween.ts +308 -0
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +267 -0
- package/src/three/curve-plot3d.ts +146 -0
- package/src/three/entries.ts +42 -0
- package/src/three/label3d.ts +52 -0
- package/src/three/plot-point3d.ts +63 -0
- package/src/three/space.ts +92 -0
- package/src/three/surface-plot3d.ts +318 -0
- package/src/three/vector-arrow3d.ts +88 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-field.js","sourceRoot":"","sources":["../../src/plots/vector-field.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAA6F,MAAM,mBAAmB,CAAC;AAClL,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAOzE,kHAAkH;AAClH,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,uGAAuG;AACvG,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AAExC,MAAM,KAAK,GAAG;IACV,GAAG,WAAW;IACd,sDAAsD;IACtD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAClD,6EAA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AAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,UAAU,EAAE,QAAQ,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IAC1C,MAAM,EAAE,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IACpH,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type NodeOf,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"../kit/coords\";\nimport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldProps, type FieldValues, type FieldSampler, type FieldStroke } from \"../kit/field-mark\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport interface VectorFieldProps extends FieldProps {\n spacing?: number;\n arrowScale?: number;\n}\n\n/** Past this many arrows the spacing is widened, so a field over a huge range is still a field and not a wash. */\nconst MAX_ARROWS = 2400;\n/** An arrow's head, as a share of its length and in pixels at most, and the half-angle it opens to. */\nconst HEAD_SHARE = 0.38;\nconst HEAD_MAX = 11;\nconst HEAD_ANGLE = (26 * Math.PI) / 180;\n\nconst state = {\n ...FIELD_STATE,\n /** How far apart the arrows stand, in graph units. */\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\n /** How long an arrow is drawn for a vector of length one, in graph units. */\n arrowScale: Types.number(0.4, { min: 0, step: 0.05 }),\n};\n\ninterface ArrowsValues extends FieldValues {\n readonly spacing: number;\n readonly arrowScale: number;\n}\n\nconst ARROWS: FieldDrawing<ArrowsValues> = {\n own: (s) => `${s.spacing}|${s.arrowScale}`,\n strokes: (s, map, field) => arrows(s, map, field),\n};\n\nconst traceArrows = (s: ArrowsValues, read: MarkReading) => traceField(\"vectorField\", ARROWS, s, read);\n\n/**\n * A grid of arrows showing a vector field, two parts in x and y: `(-y, x)`.\n * Each arrow is centred on its point and is as long as the field is strong\n * there, up to the spacing.\n */\nexport const VectorField = traced(component2d({\n key: \"vectorField\",\n state,\n defaults: { stroke: { weight: 2.5, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n commands: FIELD_COMMANDS,\n measure: (_measurer, s) => inkSize(traceArrows(s, reading(s)).runs),\n render: (ctx, s) => drawField(ctx, s, traceArrows(s, reading(s))),\n}), (s: ArrowsValues, read: MarkReading) => traceArrows(s, read).runs);\n\nexport type VectorField = NodeOf<typeof VectorField>;\n\nfunction arrows(s: ArrowsValues, map: CoordinateMap, field: FieldSampler): FieldStroke[] {\n const [x0, x1] = map.xRange;\n const [y0, y1] = map.yRange;\n let spacing = Math.max(s.spacing, 1e-6);\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\n while (count() > MAX_ARROWS) spacing *= 2;\n\n const drawn: FieldStroke[] = [];\n const v: Vector2 = { x: 0, y: 0 };\n const longest = spacing * 0.9;\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\n const gx = i * spacing;\n const gy = j * spacing;\n if (!field(gx, gy, v)) continue;\n const magnitude = Math.hypot(v.x, v.y);\n const length = Math.min(magnitude * s.arrowScale, longest);\n if (!(length > 0)) continue;\n const hx = ((v.x / magnitude) * length) / 2;\n const hy = ((v.y / magnitude) * length) / 2;\n const tail = map.toPoint(gx - hx, gy - hy);\n const head = map.toPoint(gx + hx, gy + hy);\n drawn.push({ runs: arrow(tail, head), magnitude });\n }\n }\n return drawn;\n}\n\n/** A shaft and the two barbs of its head, in pixels. */\nfunction arrow(tail: Vector2, head: Vector2): Vector2[][] {\n const dx = head.x - tail.x;\n const dy = head.y - tail.y;\n const length = Math.hypot(dx, dy);\n if (!(length > 0)) return [];\n const barb = Math.min(length * HEAD_SHARE, HEAD_MAX);\n const back = Math.atan2(dy, dx) + Math.PI;\n const at = (angle: number): Vector2 => ({ x: head.x + Math.cos(angle) * barb, y: head.y + Math.sin(angle) * barb });\n return [[tail, head], [at(back - HEAD_ANGLE), head, at(back + HEAD_ANGLE)]];\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Vector2 } from "@motionscript/sdk";
|
|
2
|
+
/** Where a graph's vertices are placed, inside a square from -1 to 1 each way, y up. */
|
|
3
|
+
export type GraphLayout = "circular" | "spring" | "tree" | "grid";
|
|
4
|
+
export declare const GRAPH_LAYOUTS: readonly GraphLayout[];
|
|
5
|
+
export interface GraphEdge {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
}
|
|
9
|
+
/** Each vertex's place under `layout`, by name. */
|
|
10
|
+
export declare function layOut(layout: GraphLayout, vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2>;
|
|
11
|
+
//# sourceMappingURL=graph-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-layout.d.ts","sourceRoot":"","sources":["../../src/structures/graph-layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,wFAAwF;AAExF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAA2C,CAAC;AAE5F,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACd;AAED,mDAAmD;AACnD,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAcxI"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export const GRAPH_LAYOUTS = ["circular", "spring", "tree", "grid"];
|
|
2
|
+
/** Each vertex's place under `layout`, by name. */
|
|
3
|
+
export function layOut(layout, vertices, edges, root) {
|
|
4
|
+
const n = vertices.length;
|
|
5
|
+
if (n === 0)
|
|
6
|
+
return new Map();
|
|
7
|
+
if (n === 1)
|
|
8
|
+
return new Map([[vertices[0], { x: 0, y: 0 }]]);
|
|
9
|
+
switch (layout) {
|
|
10
|
+
case "grid":
|
|
11
|
+
return grid(vertices);
|
|
12
|
+
case "tree":
|
|
13
|
+
return fill(tree(vertices, edges, root));
|
|
14
|
+
case "spring":
|
|
15
|
+
return fill(spring(vertices, edges));
|
|
16
|
+
default:
|
|
17
|
+
return circular(vertices);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function circular(vertices) {
|
|
21
|
+
const n = vertices.length;
|
|
22
|
+
// The first at the top, the rest clockwise, as a clock is read.
|
|
23
|
+
return new Map(vertices.map((name, i) => {
|
|
24
|
+
const angle = Math.PI / 2 - (2 * Math.PI * i) / n;
|
|
25
|
+
return [name, { x: Math.cos(angle), y: Math.sin(angle) }];
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
function grid(vertices) {
|
|
29
|
+
const columns = Math.ceil(Math.sqrt(vertices.length));
|
|
30
|
+
const rows = Math.ceil(vertices.length / columns);
|
|
31
|
+
const at = (i, count) => (count === 1 ? 0 : -1 + (2 * i) / (count - 1));
|
|
32
|
+
return new Map(vertices.map((name, i) => [name, { x: at(i % columns, columns), y: -at(Math.floor(i / columns), rows) }]));
|
|
33
|
+
}
|
|
34
|
+
function neighbours(vertices, edges) {
|
|
35
|
+
const near = new Map(vertices.map((name) => [name, []]));
|
|
36
|
+
for (const { from, to } of edges) {
|
|
37
|
+
if (from === to || !near.has(from) || !near.has(to))
|
|
38
|
+
continue;
|
|
39
|
+
near.get(from).push(to);
|
|
40
|
+
near.get(to).push(from);
|
|
41
|
+
}
|
|
42
|
+
return near;
|
|
43
|
+
}
|
|
44
|
+
/** Levels down from `root`, and across by the leaves under each, every component its own tree beside the last. */
|
|
45
|
+
function tree(vertices, edges, root) {
|
|
46
|
+
const near = neighbours(vertices, edges);
|
|
47
|
+
const placed = new Map();
|
|
48
|
+
let column = 0;
|
|
49
|
+
const visit = (name, depth, seen) => {
|
|
50
|
+
seen.add(name);
|
|
51
|
+
const children = near.get(name).filter((next) => !seen.has(next));
|
|
52
|
+
for (const child of children)
|
|
53
|
+
seen.add(child);
|
|
54
|
+
if (children.length === 0) {
|
|
55
|
+
placed.set(name, { x: column++, y: -depth });
|
|
56
|
+
return placed.get(name).x;
|
|
57
|
+
}
|
|
58
|
+
const xs = children.map((child) => visit(child, depth + 1, seen));
|
|
59
|
+
const x = (xs[0] + xs[xs.length - 1]) / 2;
|
|
60
|
+
placed.set(name, { x, y: -depth });
|
|
61
|
+
return x;
|
|
62
|
+
};
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
const first = near.has(root) ? root : vertices[0];
|
|
65
|
+
for (const start of [first, ...vertices])
|
|
66
|
+
if (!seen.has(start))
|
|
67
|
+
visit(start, 0, seen);
|
|
68
|
+
return placed;
|
|
69
|
+
}
|
|
70
|
+
/** Edges pull and every pair pushes, from the circle, for a fixed number of cooling steps: the same answer every time. */
|
|
71
|
+
function spring(vertices, edges) {
|
|
72
|
+
const n = vertices.length;
|
|
73
|
+
const index = new Map(vertices.map((name, i) => [name, i]));
|
|
74
|
+
const start = circular(vertices);
|
|
75
|
+
const x = vertices.map((name) => start.get(name).x);
|
|
76
|
+
const y = vertices.map((name) => start.get(name).y);
|
|
77
|
+
const links = edges.flatMap(({ from, to }) => {
|
|
78
|
+
const a = index.get(from);
|
|
79
|
+
const b = index.get(to);
|
|
80
|
+
return a === undefined || b === undefined || a === b ? [] : [[a, b]];
|
|
81
|
+
});
|
|
82
|
+
const k = Math.sqrt(4 / n);
|
|
83
|
+
const steps = 160;
|
|
84
|
+
for (let step = 0; step < steps; step++) {
|
|
85
|
+
const dx = new Float64Array(n);
|
|
86
|
+
const dy = new Float64Array(n);
|
|
87
|
+
for (let i = 0; i < n; i++) {
|
|
88
|
+
for (let j = i + 1; j < n; j++) {
|
|
89
|
+
let ex = x[i] - x[j];
|
|
90
|
+
let ey = y[i] - y[j];
|
|
91
|
+
let d = Math.hypot(ex, ey);
|
|
92
|
+
// Two on one spot are parted along a fixed, if arbitrary, line.
|
|
93
|
+
if (d < 1e-6)
|
|
94
|
+
[ex, ey, d] = [1e-3 * (i - j), 1e-3, 1e-3];
|
|
95
|
+
const push = (k * k) / d;
|
|
96
|
+
dx[i] += (ex / d) * push;
|
|
97
|
+
dy[i] += (ey / d) * push;
|
|
98
|
+
dx[j] -= (ex / d) * push;
|
|
99
|
+
dy[j] -= (ey / d) * push;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const [a, b] of links) {
|
|
103
|
+
const ex = x[a] - x[b];
|
|
104
|
+
const ey = y[a] - y[b];
|
|
105
|
+
const d = Math.max(Math.hypot(ex, ey), 1e-6);
|
|
106
|
+
const pull = (d * d) / k;
|
|
107
|
+
dx[a] -= (ex / d) * pull;
|
|
108
|
+
dy[a] -= (ey / d) * pull;
|
|
109
|
+
dx[b] += (ex / d) * pull;
|
|
110
|
+
dy[b] += (ey / d) * pull;
|
|
111
|
+
}
|
|
112
|
+
const limit = 0.12 * (1 - step / steps);
|
|
113
|
+
for (let i = 0; i < n; i++) {
|
|
114
|
+
const d = Math.hypot(dx[i], dy[i]);
|
|
115
|
+
if (d > 0) {
|
|
116
|
+
x[i] += (dx[i] / d) * Math.min(d, limit);
|
|
117
|
+
y[i] += (dy[i] / d) * Math.min(d, limit);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return new Map(vertices.map((name, i) => [name, { x: x[i], y: y[i] }]));
|
|
122
|
+
}
|
|
123
|
+
/** `placed` stretched to reach -1 and 1 on each axis it spreads along, and centred on the one it does not. */
|
|
124
|
+
function fill(placed) {
|
|
125
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
126
|
+
for (const p of placed.values()) {
|
|
127
|
+
minX = Math.min(minX, p.x);
|
|
128
|
+
maxX = Math.max(maxX, p.x);
|
|
129
|
+
minY = Math.min(minY, p.y);
|
|
130
|
+
maxY = Math.max(maxY, p.y);
|
|
131
|
+
}
|
|
132
|
+
const scale = (v, lo, hi) => (hi - lo < 1e-9 ? 0 : -1 + (2 * (v - lo)) / (hi - lo));
|
|
133
|
+
return new Map([...placed].map(([name, p]) => [name, { x: scale(p.x, minX, maxX), y: scale(p.y, minY, maxY) }]));
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=graph-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-layout.js","sourceRoot":"","sources":["../../src/struct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each way, y up. */\n\nexport type GraphLayout = \"circular\" | \"spring\" | \"tree\" | \"grid\";\n\nexport const GRAPH_LAYOUTS: readonly GraphLayout[] = [\"circular\", \"spring\", \"tree\", \"grid\"];\n\nexport interface GraphEdge {\n from: string;\n to: string;\n}\n\n/** Each vertex's place under `layout`, by name. */\nexport function layOut(layout: GraphLayout, vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\n const n = vertices.length;\n if (n === 0) return new Map();\n if (n === 1) return new Map([[vertices[0], { x: 0, y: 0 }]]);\n switch (layout) {\n case \"grid\":\n return grid(vertices);\n case \"tree\":\n return fill(tree(vertices, edges, root));\n case \"spring\":\n return fill(spring(vertices, edges));\n default:\n return circular(vertices);\n }\n}\n\nfunction circular(vertices: readonly string[]): Map<string, Vector2> {\n const n = vertices.length;\n // The first at the top, the rest clockwise, as a clock is read.\n return new Map(vertices.map((name, i) => {\n const angle = Math.PI / 2 - (2 * Math.PI * i) / n;\n return [name, { x: Math.cos(angle), y: Math.sin(angle) }];\n }));\n}\n\nfunction grid(vertices: readonly string[]): Map<string, Vector2> {\n const columns = Math.ceil(Math.sqrt(vertices.length));\n const rows = Math.ceil(vertices.length / columns);\n const at = (i: number, count: number) => (count === 1 ? 0 : -1 + (2 * i) / (count - 1));\n return new Map(vertices.map((name, i) => [name, { x: at(i % columns, columns), y: -at(Math.floor(i / columns), rows) }]));\n}\n\nfunction neighbours(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, string[]> {\n const near = new Map(vertices.map((name) => [name, [] as string[]]));\n for (const { from, to } of edges) {\n if (from === to || !near.has(from) || !near.has(to)) continue;\n near.get(from)!.push(to);\n near.get(to)!.push(from);\n }\n return near;\n}\n\n/** Levels down from `root`, and across by the leaves under each, every component its own tree beside the last. */\nfunction tree(vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\n const near = neighbours(vertices, edges);\n const placed = new Map<string, Vector2>();\n let column = 0;\n const visit = (name: string, depth: number, seen: Set<string>): number => {\n seen.add(name);\n const children = near.get(name)!.filter((next) => !seen.has(next));\n for (const child of children) seen.add(child);\n if (children.length === 0) {\n placed.set(name, { x: column++, y: -depth });\n return placed.get(name)!.x;\n }\n const xs = children.map((child) => visit(child, depth + 1, seen));\n const x = (xs[0] + xs[xs.length - 1]) / 2;\n placed.set(name, { x, y: -depth });\n return x;\n };\n const seen = new Set<string>();\n const first = near.has(root) ? root : vertices[0];\n for (const start of [first, ...vertices]) if (!seen.has(start)) visit(start, 0, seen);\n return placed;\n}\n\n/** Edges pull and every pair pushes, from the circle, for a fixed number of cooling steps: the same answer every time. */\nfunction spring(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, Vector2> {\n const n = vertices.length;\n const index = new Map(vertices.map((name, i) => [name, i]));\n const start = circular(vertices);\n const x = vertices.map((name) => start.get(name)!.x);\n const y = vertices.map((name) => start.get(name)!.y);\n const links = edges.flatMap(({ from, to }) => {\n const a = index.get(from);\n const b = index.get(to);\n return a === undefined || b === undefined || a === b ? [] : [[a, b] as const];\n });\n const k = Math.sqrt(4 / n);\n const steps = 160;\n for (let step = 0; step < steps; step++) {\n const dx = new Float64Array(n);\n const dy = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n let ex = x[i] - x[j];\n let ey = y[i] - y[j];\n let d = Math.hypot(ex, ey);\n // Two on one spot are parted along a fixed, if arbitrary, line.\n if (d < 1e-6) [ex, ey, d] = [1e-3 * (i - j), 1e-3, 1e-3];\n const push = (k * k) / d;\n dx[i] += (ex / d) * push;\n dy[i] += (ey / d) * push;\n dx[j] -= (ex / d) * push;\n dy[j] -= (ey / d) * push;\n }\n }\n for (const [a, b] of links) {\n const ex = x[a] - x[b];\n const ey = y[a] - y[b];\n const d = Math.max(Math.hypot(ex, ey), 1e-6);\n const pull = (d * d) / k;\n dx[a] -= (ex / d) * pull;\n dy[a] -= (ey / d) * pull;\n dx[b] += (ex / d) * pull;\n dy[b] += (ey / d) * pull;\n }\n const limit = 0.12 * (1 - step / steps);\n for (let i = 0; i < n; i++) {\n const d = Math.hypot(dx[i], dy[i]);\n if (d > 0) {\n x[i] += (dx[i] / d) * Math.min(d, limit);\n y[i] += (dy[i] / d) * Math.min(d, limit);\n }\n }\n }\n return new Map(vertices.map((name, i) => [name, { x: x[i], y: y[i] }]));\n}\n\n/** `placed` stretched to reach -1 and 1 on each axis it spreads along, and centred on the one it does not. */\nfunction fill(placed: Map<string, Vector2>): Map<string, Vector2> {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const p of placed.values()) {\n minX = Math.min(minX, p.x);\n maxX = Math.max(maxX, p.x);\n minY = Math.min(minY, p.y);\n maxY = Math.max(maxY, p.y);\n }\n const scale = (v: number, lo: number, hi: number) => (hi - lo < 1e-9 ? 0 : -1 + (2 * (v - lo)) / (hi - lo));\n return new Map([...placed].map(([name, p]) => [name, { x: scale(p.x, minX, maxX), y: scale(p.y, minY, maxY) }]));\n}\n"]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { type Color, type Fill, type FillResolved, type NodeOf, type NormalizedColor, type PaintProps, type ShadowResolved, type Size2D, type Stroke, type StrokeResolved, type Values, type Vector2, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow } from "@motionscript/sdk";
|
|
2
|
+
import { type PartFill, type PartFillResolved } from "../kit/part-fills.js";
|
|
3
|
+
import { type GraphEdge, type GraphLayout } from "./graph-layout.js";
|
|
4
|
+
/** A vertex placed by hand, in the graph's box from -1 to 1 each way, y up. */
|
|
5
|
+
export interface GraphPosition {
|
|
6
|
+
vertex: string;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
export interface NetworkGraphProps extends PaintProps {
|
|
11
|
+
vertices?: string[];
|
|
12
|
+
edges?: GraphEdge[];
|
|
13
|
+
directed?: boolean;
|
|
14
|
+
arrangement?: GraphLayout;
|
|
15
|
+
root?: string;
|
|
16
|
+
positions?: GraphPosition[];
|
|
17
|
+
vertexRadius?: number;
|
|
18
|
+
vertexStroke?: Stroke;
|
|
19
|
+
labels?: boolean;
|
|
20
|
+
labelSize?: number;
|
|
21
|
+
labelColor?: Color;
|
|
22
|
+
fontFamily?: string;
|
|
23
|
+
partFills?: PartFill[];
|
|
24
|
+
}
|
|
25
|
+
declare const state: {
|
|
26
|
+
vertices: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
27
|
+
edges: import("@motionscript/sdk").Type<GraphEdge[], GraphEdge[], false>;
|
|
28
|
+
/** Draw each edge as an arrow from its `from` to its `to`. */
|
|
29
|
+
directed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
30
|
+
arrangement: import("@motionscript/sdk").Type<GraphLayout, GraphLayout, false>;
|
|
31
|
+
/** The vertex a tree hangs from; left empty, the first. */
|
|
32
|
+
root: import("@motionscript/sdk").Type<string, string, false>;
|
|
33
|
+
/** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */
|
|
34
|
+
positions: import("@motionscript/sdk").Type<GraphPosition[], GraphPosition[], false>;
|
|
35
|
+
vertexRadius: import("@motionscript/sdk").Type<number, number, false>;
|
|
36
|
+
vertexStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
37
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
38
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
40
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
41
|
+
/** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */
|
|
42
|
+
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
43
|
+
/** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */
|
|
44
|
+
layoutFrom: import("@motionscript/sdk").Type<string, string, true>;
|
|
45
|
+
layoutMix: import("@motionscript/sdk").Type<number, number, true>;
|
|
46
|
+
fill: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
47
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
48
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
|
|
49
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
};
|
|
52
|
+
/** What a graph is drawn from: its own entries, as its fields and its node both read them. */
|
|
53
|
+
export type GraphValues = Values<typeof state>;
|
|
54
|
+
/**
|
|
55
|
+
* Vertices and the edges between them, arranged by a rule: in a circle, by
|
|
56
|
+
* springs, as a tree from `root`, or in a grid. Its `fill` is the vertices and
|
|
57
|
+
* its `stroke` the edges, with an arrowhead each when `directed`. `arrangeTo`
|
|
58
|
+
* moves every vertex to where another rule places it; `partFillTo` paints a
|
|
59
|
+
* vertex, or an edge written `a-b`. (`layout` is every node's own box.)
|
|
60
|
+
*/
|
|
61
|
+
export declare const NetworkGraph: import("@motionscript/sdk").Component<"networkGraph", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
62
|
+
vertices: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
63
|
+
edges: import("@motionscript/sdk").Type<GraphEdge[], GraphEdge[], false>;
|
|
64
|
+
/** Draw each edge as an arrow from its `from` to its `to`. */
|
|
65
|
+
directed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
66
|
+
arrangement: import("@motionscript/sdk").Type<GraphLayout, GraphLayout, false>;
|
|
67
|
+
/** The vertex a tree hangs from; left empty, the first. */
|
|
68
|
+
root: import("@motionscript/sdk").Type<string, string, false>;
|
|
69
|
+
/** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */
|
|
70
|
+
positions: import("@motionscript/sdk").Type<GraphPosition[], GraphPosition[], false>;
|
|
71
|
+
vertexRadius: import("@motionscript/sdk").Type<number, number, false>;
|
|
72
|
+
vertexStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
73
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
74
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
75
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
76
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
77
|
+
/** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */
|
|
78
|
+
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
79
|
+
/** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */
|
|
80
|
+
layoutFrom: import("@motionscript/sdk").Type<string, string, true>;
|
|
81
|
+
layoutMix: import("@motionscript/sdk").Type<number, number, true>;
|
|
82
|
+
fill: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
83
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
84
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
|
|
85
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
86
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
87
|
+
}>, {
|
|
88
|
+
readonly arrangeTo: {
|
|
89
|
+
readonly arrangement: import("@motionscript/sdk").Type<GraphLayout | undefined, GraphLayout | undefined, false>;
|
|
90
|
+
};
|
|
91
|
+
readonly partFillTo: {
|
|
92
|
+
readonly part: import("@motionscript/sdk").Type<string, string, false>;
|
|
93
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, Fill, false>;
|
|
94
|
+
};
|
|
95
|
+
readonly fillTo: readonly ["fill"];
|
|
96
|
+
readonly strokeTo: readonly ["stroke"];
|
|
97
|
+
readonly shadowTo: readonly ["shadow"];
|
|
98
|
+
readonly progressTo: readonly ["start", "end"];
|
|
99
|
+
readonly flash: {
|
|
100
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
101
|
+
};
|
|
102
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
103
|
+
vertices: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
104
|
+
edges: import("@motionscript/sdk").Type<GraphEdge[], GraphEdge[], false>;
|
|
105
|
+
/** Draw each edge as an arrow from its `from` to its `to`. */
|
|
106
|
+
directed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
107
|
+
arrangement: import("@motionscript/sdk").Type<GraphLayout, GraphLayout, false>;
|
|
108
|
+
/** The vertex a tree hangs from; left empty, the first. */
|
|
109
|
+
root: import("@motionscript/sdk").Type<string, string, false>;
|
|
110
|
+
/** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */
|
|
111
|
+
positions: import("@motionscript/sdk").Type<GraphPosition[], GraphPosition[], false>;
|
|
112
|
+
vertexRadius: import("@motionscript/sdk").Type<number, number, false>;
|
|
113
|
+
vertexStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
114
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
115
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
116
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
117
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
118
|
+
/** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */
|
|
119
|
+
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
120
|
+
/** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */
|
|
121
|
+
layoutFrom: import("@motionscript/sdk").Type<string, string, true>;
|
|
122
|
+
layoutMix: import("@motionscript/sdk").Type<number, number, true>;
|
|
123
|
+
fill: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
124
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
125
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
|
|
126
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
127
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
128
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
129
|
+
vertices: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
130
|
+
edges: import("@motionscript/sdk").Type<GraphEdge[], GraphEdge[], false>;
|
|
131
|
+
/** Draw each edge as an arrow from its `from` to its `to`. */
|
|
132
|
+
directed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
133
|
+
arrangement: import("@motionscript/sdk").Type<GraphLayout, GraphLayout, false>;
|
|
134
|
+
/** The vertex a tree hangs from; left empty, the first. */
|
|
135
|
+
root: import("@motionscript/sdk").Type<string, string, false>;
|
|
136
|
+
/** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */
|
|
137
|
+
positions: import("@motionscript/sdk").Type<GraphPosition[], GraphPosition[], false>;
|
|
138
|
+
vertexRadius: import("@motionscript/sdk").Type<number, number, false>;
|
|
139
|
+
vertexStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
140
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
141
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
142
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
143
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
144
|
+
/** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */
|
|
145
|
+
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
146
|
+
/** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */
|
|
147
|
+
layoutFrom: import("@motionscript/sdk").Type<string, string, true>;
|
|
148
|
+
layoutMix: import("@motionscript/sdk").Type<number, number, true>;
|
|
149
|
+
fill: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
150
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
151
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
|
|
152
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
153
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
154
|
+
}>, {
|
|
155
|
+
readonly arrangeTo: {
|
|
156
|
+
readonly arrangement: import("@motionscript/sdk").Type<GraphLayout | undefined, GraphLayout | undefined, false>;
|
|
157
|
+
};
|
|
158
|
+
readonly partFillTo: {
|
|
159
|
+
readonly part: import("@motionscript/sdk").Type<string, string, false>;
|
|
160
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, Fill, false>;
|
|
161
|
+
};
|
|
162
|
+
readonly fillTo: readonly ["fill"];
|
|
163
|
+
readonly strokeTo: readonly ["stroke"];
|
|
164
|
+
readonly shadowTo: readonly ["shadow"];
|
|
165
|
+
readonly progressTo: readonly ["start", "end"];
|
|
166
|
+
readonly flash: {
|
|
167
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
168
|
+
};
|
|
169
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
170
|
+
export type NetworkGraph = NodeOf<typeof NetworkGraph>;
|
|
171
|
+
/** Where each vertex is drawn in a graph of `size`, in pixels from its centre, y up. */
|
|
172
|
+
export declare function vertexPoints(graph: GraphValues, size: Size2D): Map<string, Vector2>;
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=network-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-graph.d.ts","sourceRoot":"","sources":["../../src/structures/network-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU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,WAAW,GAAG,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;IA9BrB,8DAA8D;;;IAG9D,2DAA2D;;IAE3D,2FAA2F;;;;;;;;IAQ3F,uFAAuF;;IAEvF,wFAAwF;;;;;;;;;;;;;;;;;;;;;;;;;;IAfxF,8DAA8D;;;IAG9D,2DAA2D;;IAE3D,2FAA2F;;;;;;;;IAQ3F,uFAAuF;;IAEvF,wFAAwF;;;;;;;;;;;IAfxF,8DAA8D;;;IAG9D,2DAA2D;;IAE3D,2FAA2F;;;;;;;;IAQ3F,uFAAuF;;IAEvF,wFAAwF;;;;;;;;;;;;;;;;;;;;;;;2BAiD1F,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEvD,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAanF"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { createBoundedCache } from "../kit/cache.js";
|
|
3
|
+
import { listed, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
|
|
4
|
+
import { drawLabels, loadFormulas } from "../kit/furniture.js";
|
|
5
|
+
import { lerpPartFills, partPaint, readPartFills, withPartFill } from "../kit/part-fills.js";
|
|
6
|
+
import { GRAPH_LAYOUTS, layOut } from "./graph-layout.js";
|
|
7
|
+
// Every list keeps each entry as it was written, a blank or a repeat included, so
|
|
8
|
+
// an editor showing the list shows the row it just added. What is drawn skips
|
|
9
|
+
// what is not complete yet (`names`, `links`).
|
|
10
|
+
function readVertices(value) {
|
|
11
|
+
return (Array.isArray(value) ? value : []).map((name) => String(name ?? ""));
|
|
12
|
+
}
|
|
13
|
+
// An edge reads from `{ from, to }` or a pair, so a list written by hand is as good as one from a table.
|
|
14
|
+
function readEdges(value) {
|
|
15
|
+
return (Array.isArray(value) ? value : []).map((edge) => {
|
|
16
|
+
const [from, to] = Array.isArray(edge) ? edge : [edge?.from, edge?.to];
|
|
17
|
+
return { from: String(from ?? ""), to: String(to ?? "") };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function readPositions(value) {
|
|
21
|
+
const at = (n) => (typeof n === "number" && Number.isFinite(n) ? n : 0);
|
|
22
|
+
return (Array.isArray(value) ? value : []).map((entry) => ({ vertex: String(entry?.vertex ?? ""), x: at(entry?.x), y: at(entry?.y) }));
|
|
23
|
+
}
|
|
24
|
+
/** How far a directed edge and the one back between the same two vertices bow apart, as a share of their length. */
|
|
25
|
+
const BOW = 0.12;
|
|
26
|
+
const NUL = String.fromCharCode(0);
|
|
27
|
+
const state = {
|
|
28
|
+
...PAINT,
|
|
29
|
+
vertices: Types.custom([], { resolve: readVertices, animatable: false, kind: "vector" }),
|
|
30
|
+
edges: Types.custom([], { resolve: readEdges, animatable: false, kind: "vector" }),
|
|
31
|
+
/** Draw each edge as an arrow from its `from` to its `to`. */
|
|
32
|
+
directed: Types.boolean(false, { animatable: false }),
|
|
33
|
+
arrangement: listed(GRAPH_LAYOUTS, "circular", { animatable: false }),
|
|
34
|
+
/** The vertex a tree hangs from; left empty, the first. */
|
|
35
|
+
root: Types.text("", { animatable: false }),
|
|
36
|
+
/** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */
|
|
37
|
+
positions: Types.custom([], { resolve: readPositions, animatable: false, kind: "vector" }),
|
|
38
|
+
vertexRadius: Types.number(18, { min: 0, unit: "px" }),
|
|
39
|
+
vertexStroke: Types.stroke([]),
|
|
40
|
+
labels: Types.boolean(true, { animatable: false }),
|
|
41
|
+
labelSize: Types.number(18, { min: 1, unit: "px" }),
|
|
42
|
+
labelColor: Types.color("#111827"),
|
|
43
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
44
|
+
/** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */
|
|
45
|
+
partFills: Types.custom([], { resolve: readPartFills, lerp: lerpPartFills, kind: "vector" }),
|
|
46
|
+
/** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */
|
|
47
|
+
layoutFrom: Types.text("", { private: true }),
|
|
48
|
+
layoutMix: Types.number(1, { private: true }),
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Vertices and the edges between them, arranged by a rule: in a circle, by
|
|
52
|
+
* springs, as a tree from `root`, or in a grid. Its `fill` is the vertices and
|
|
53
|
+
* its `stroke` the edges, with an arrowhead each when `directed`. `arrangeTo`
|
|
54
|
+
* moves every vertex to where another rule places it; `partFillTo` paints a
|
|
55
|
+
* vertex, or an edge written `a-b`. (`layout` is every node's own box.)
|
|
56
|
+
*/
|
|
57
|
+
export const NetworkGraph = component2d({
|
|
58
|
+
key: "networkGraph",
|
|
59
|
+
state,
|
|
60
|
+
defaults: {
|
|
61
|
+
fill: "#e5e7eb",
|
|
62
|
+
stroke: { weight: 3, fill: "#9ca3af", align: "center", cap: "round" },
|
|
63
|
+
},
|
|
64
|
+
load: (loader, s) => {
|
|
65
|
+
if (s.fontFamily !== "")
|
|
66
|
+
loader.font(s.fontFamily);
|
|
67
|
+
if (s.labels)
|
|
68
|
+
loadFormulas(loader, names(s));
|
|
69
|
+
},
|
|
70
|
+
commands: {
|
|
71
|
+
...PAINT_COMMANDS,
|
|
72
|
+
/** Move every vertex to where another arrangement places it. */
|
|
73
|
+
arrangeTo: {
|
|
74
|
+
// No default: one left out keeps the arrangement the graph has.
|
|
75
|
+
args: { arrangement: listed(GRAPH_LAYOUTS, undefined) },
|
|
76
|
+
run: (timeline, s) => {
|
|
77
|
+
const from = s.arrangement;
|
|
78
|
+
const to = timeline.args.arrangement ?? from;
|
|
79
|
+
return timeline.animate((t) => ({ arrangement: to, layoutFrom: from, layoutMix: t }));
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
/** Paint one part of the graph: a vertex by its name, or an edge written `a-b`. */
|
|
83
|
+
partFillTo: {
|
|
84
|
+
args: { part: Types.text(""), fill: Types.custom("#facc15", { kind: "fills" }) },
|
|
85
|
+
run: (timeline, s) => {
|
|
86
|
+
const { part, fill } = timeline.args;
|
|
87
|
+
if (!part || fill == null)
|
|
88
|
+
return timeline.tween({});
|
|
89
|
+
return timeline.tween({ partFills: withPartFill(s.partFills, { part, fill }) });
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
render: (ctx, s) => painted(ctx, () => drawGraph(ctx, s)),
|
|
94
|
+
});
|
|
95
|
+
/** Where each vertex is drawn in a graph of `size`, in pixels from its centre, y up. */
|
|
96
|
+
export function vertexPoints(graph, size) {
|
|
97
|
+
const room = graph.vertexRadius + Math.max(2, graph.labelSize * 0.2);
|
|
98
|
+
const halfX = Math.max(0, size.width / 2 - room);
|
|
99
|
+
const halfY = Math.max(0, size.height / 2 - room);
|
|
100
|
+
const to = placed(graph, graph.arrangement);
|
|
101
|
+
const from = graph.layoutMix < 1 && graph.layoutFrom !== "" ? placed(graph, graph.layoutFrom) : null;
|
|
102
|
+
const t = graph.layoutMix;
|
|
103
|
+
const out = new Map();
|
|
104
|
+
for (const [name, p] of to) {
|
|
105
|
+
const q = from?.get(name) ?? p;
|
|
106
|
+
out.set(name, { x: (q.x + (p.x - q.x) * t) * halfX, y: (q.y + (p.y - q.y) * t) * halfY });
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function drawGraph(ctx, graph) {
|
|
111
|
+
const points = vertexPoints(graph, ctx.size);
|
|
112
|
+
if (points.size === 0)
|
|
113
|
+
return;
|
|
114
|
+
const parts = new Map(graph.partFills.map((entry) => [entry.part, entry]));
|
|
115
|
+
drawEdges(ctx, graph, points, parts);
|
|
116
|
+
drawVertices(ctx, graph, points, parts);
|
|
117
|
+
}
|
|
118
|
+
// Two layouts are held at once while one becomes the other, and a scene may hold several graphs.
|
|
119
|
+
const layouts = createBoundedCache(32);
|
|
120
|
+
/** Each vertex's place under `layout`, from -1 to 1, a hand-placed one where it is. */
|
|
121
|
+
function placed(graph, layout) {
|
|
122
|
+
const vertices = names(graph);
|
|
123
|
+
const edges = links(graph);
|
|
124
|
+
const key = [layout, graph.root, vertices.join(NUL), JSON.stringify(edges), JSON.stringify(graph.positions)].join("|");
|
|
125
|
+
let at = layouts.get(key);
|
|
126
|
+
if (!at) {
|
|
127
|
+
at = layOut(layout, vertices, edges, graph.root.trim());
|
|
128
|
+
for (const { vertex, x, y } of graph.positions) {
|
|
129
|
+
const name = vertex.trim();
|
|
130
|
+
if (at.has(name))
|
|
131
|
+
at.set(name, { x, y });
|
|
132
|
+
}
|
|
133
|
+
layouts.set(key, at);
|
|
134
|
+
}
|
|
135
|
+
return at;
|
|
136
|
+
}
|
|
137
|
+
function drawEdges(ctx, graph, points, parts) {
|
|
138
|
+
const stroke = graph.stroke;
|
|
139
|
+
if (stroke.length === 0)
|
|
140
|
+
return;
|
|
141
|
+
const r = graph.vertexRadius;
|
|
142
|
+
const all = links(graph);
|
|
143
|
+
const pairs = new Set(all.map(({ from, to }) => `${from}${NUL}${to}`));
|
|
144
|
+
const plain = new Graphics2D();
|
|
145
|
+
let drawnPlain = false;
|
|
146
|
+
for (const { from, to } of all) {
|
|
147
|
+
const a = points.get(from);
|
|
148
|
+
const b = points.get(to);
|
|
149
|
+
if (!a || !b)
|
|
150
|
+
continue;
|
|
151
|
+
const run = from === to ? loop(a, r) : edge(a, b, r, graph.directed && pairs.has(`${to}${NUL}${from}`) ? BOW : 0);
|
|
152
|
+
if (run.length < 2)
|
|
153
|
+
continue;
|
|
154
|
+
const paint = parts.get(`${from}-${to}`) ?? (graph.directed ? undefined : parts.get(`${to}-${from}`));
|
|
155
|
+
const own = graph.directed || paint !== undefined;
|
|
156
|
+
const g = own ? new Graphics2D() : plain;
|
|
157
|
+
g.line({ points: run, radius: 0, start: graph.start, end: graph.end });
|
|
158
|
+
if (!own) {
|
|
159
|
+
drawnPlain = true;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
let layers = stroke;
|
|
163
|
+
if (paint)
|
|
164
|
+
layers = layers.map((layer) => ({ ...layer, fill: partPaint(layer.fill, paint) }));
|
|
165
|
+
if (graph.directed && from !== to)
|
|
166
|
+
layers = layers.map((layer) => ({ ...layer, endCap: layer.endCap ?? "triangle" }));
|
|
167
|
+
ctx.draw(g.stroke(layers));
|
|
168
|
+
}
|
|
169
|
+
if (drawnPlain)
|
|
170
|
+
ctx.draw(plain.stroke(stroke));
|
|
171
|
+
}
|
|
172
|
+
function drawVertices(ctx, graph, points, parts) {
|
|
173
|
+
const r = graph.vertexRadius;
|
|
174
|
+
const fill = graph.fill;
|
|
175
|
+
const outline = graph.vertexStroke;
|
|
176
|
+
const labels = [];
|
|
177
|
+
for (const [name, p] of points) {
|
|
178
|
+
if (r > 0) {
|
|
179
|
+
const paint = partPaint(fill, parts.get(name));
|
|
180
|
+
const disc = new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 });
|
|
181
|
+
ctx.draw(disc.shadow(graph.shadow).fill(paint));
|
|
182
|
+
if (outline.length > 0)
|
|
183
|
+
ctx.draw(new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 }).stroke(outline));
|
|
184
|
+
}
|
|
185
|
+
if (graph.labels)
|
|
186
|
+
labels.push({ text: name, at: { x: p.x, y: p.y }, align: "center" });
|
|
187
|
+
}
|
|
188
|
+
for (const part of drawLabels(labels, { fontSize: graph.labelSize, fontFamily: graph.fontFamily, color: graph.labelColor })) {
|
|
189
|
+
ctx.draw(part);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** The vertices drawn: each name once, trimmed, the blank ones left out. */
|
|
193
|
+
function names(graph) {
|
|
194
|
+
return [...new Set(graph.vertices.map((name) => name.trim()).filter((name) => name !== ""))];
|
|
195
|
+
}
|
|
196
|
+
/** The edges drawn: both ends named. */
|
|
197
|
+
function links(graph) {
|
|
198
|
+
return graph.edges.flatMap(({ from, to }) => {
|
|
199
|
+
const a = from.trim();
|
|
200
|
+
const b = to.trim();
|
|
201
|
+
return a === "" || b === "" ? [] : [{ from: a, to: b }];
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** An edge from one vertex's rim to the other's, straight or bowed to its left. */
|
|
205
|
+
function edge(a, b, r, bow) {
|
|
206
|
+
const dx = b.x - a.x;
|
|
207
|
+
const dy = b.y - a.y;
|
|
208
|
+
const length = Math.hypot(dx, dy);
|
|
209
|
+
if (!(length > 2 * r))
|
|
210
|
+
return [];
|
|
211
|
+
if (bow === 0) {
|
|
212
|
+
const ux = dx / length;
|
|
213
|
+
const uy = dy / length;
|
|
214
|
+
return [{ x: a.x + ux * r, y: a.y + uy * r }, { x: b.x - ux * r, y: b.y - uy * r }];
|
|
215
|
+
}
|
|
216
|
+
const mid = { x: (a.x + b.x) / 2 - (dy / length) * bow * length, y: (a.y + b.y) / 2 + (dx / length) * bow * length };
|
|
217
|
+
const run = [];
|
|
218
|
+
for (let i = 0; i <= 16; i++) {
|
|
219
|
+
const t = i / 16;
|
|
220
|
+
const u = 1 - t;
|
|
221
|
+
run.push({ x: u * u * a.x + 2 * u * t * mid.x + t * t * b.x, y: u * u * a.y + 2 * u * t * mid.y + t * t * b.y });
|
|
222
|
+
}
|
|
223
|
+
// Trimmed back to the rims along the curve.
|
|
224
|
+
const outside = (p, c) => Math.hypot(p.x - c.x, p.y - c.y) >= r;
|
|
225
|
+
return run.filter((p) => outside(p, a) && outside(p, b));
|
|
226
|
+
}
|
|
227
|
+
/** An edge from a vertex to itself: a small loop above it. */
|
|
228
|
+
function loop(c, r) {
|
|
229
|
+
const run = [];
|
|
230
|
+
const radius = Math.max(r * 0.8, 6);
|
|
231
|
+
const cy = c.y + r + radius * 0.6;
|
|
232
|
+
for (let i = 0; i <= 24; i++) {
|
|
233
|
+
const angle = -Math.PI / 2 + (2 * Math.PI * i) / 24;
|
|
234
|
+
const p = { x: c.x + Math.cos(angle) * radius, y: cy + Math.sin(angle) * radius };
|
|
235
|
+
if (Math.hypot(p.x - c.x, p.y - c.y) >= r)
|
|
236
|
+
run.push(p);
|
|
237
|
+
}
|
|
238
|
+
return run;
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=network-graph.js.map
|