@kanzo-tech/graph 0.14.0 → 0.15.1

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.
Files changed (113) hide show
  1. package/README.md +20 -16
  2. package/dist/core/categories.d.ts +18 -6
  3. package/dist/core/categories.d.ts.map +1 -1
  4. package/dist/core/categories.js +41 -10
  5. package/dist/core/categories.js.map +1 -1
  6. package/dist/core/channels.d.ts +10 -5
  7. package/dist/core/channels.d.ts.map +1 -1
  8. package/dist/core/channels.js +11 -13
  9. package/dist/core/channels.js.map +1 -1
  10. package/dist/core/detail.d.ts +14 -8
  11. package/dist/core/detail.d.ts.map +1 -1
  12. package/dist/core/detail.js +33 -15
  13. package/dist/core/detail.js.map +1 -1
  14. package/dist/core/filter.d.ts +3 -1
  15. package/dist/core/filter.d.ts.map +1 -1
  16. package/dist/core/filter.js +54 -50
  17. package/dist/core/filter.js.map +1 -1
  18. package/dist/core/load.d.ts +58 -0
  19. package/dist/core/load.d.ts.map +1 -0
  20. package/dist/core/load.js +115 -0
  21. package/dist/core/load.js.map +1 -0
  22. package/dist/core/state.d.ts +27 -55
  23. package/dist/core/state.d.ts.map +1 -1
  24. package/dist/core/store.d.ts +1 -3
  25. package/dist/core/store.d.ts.map +1 -1
  26. package/dist/core/store.js +159 -174
  27. package/dist/core/store.js.map +1 -1
  28. package/dist/core/types.d.ts +21 -17
  29. package/dist/core/types.d.ts.map +1 -1
  30. package/dist/index.d.ts +5 -7
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +19 -25
  33. package/dist/index.js.map +1 -1
  34. package/dist/parts/gesture.d.ts +1 -10
  35. package/dist/parts/gesture.d.ts.map +1 -1
  36. package/dist/parts/gesture.js +28 -28
  37. package/dist/parts/gesture.js.map +1 -1
  38. package/dist/parts/graph-canvas.d.ts.map +1 -1
  39. package/dist/parts/graph-canvas.js +119 -108
  40. package/dist/parts/graph-canvas.js.map +1 -1
  41. package/dist/parts/graph-inspector.d.ts +4 -4
  42. package/dist/parts/graph-inspector.d.ts.map +1 -1
  43. package/dist/parts/graph-inspector.js +55 -57
  44. package/dist/parts/graph-inspector.js.map +1 -1
  45. package/dist/parts/graph-legend.d.ts +4 -4
  46. package/dist/parts/graph-legend.d.ts.map +1 -1
  47. package/dist/parts/graph-legend.js +21 -21
  48. package/dist/parts/graph-legend.js.map +1 -1
  49. package/dist/parts/overlays.d.ts +2 -4
  50. package/dist/parts/overlays.d.ts.map +1 -1
  51. package/dist/parts/overlays.js +45 -45
  52. package/dist/parts/overlays.js.map +1 -1
  53. package/dist/react/use-graph-state.d.ts +4 -2
  54. package/dist/react/use-graph-state.d.ts.map +1 -1
  55. package/dist/react/use-graph-state.js +10 -6
  56. package/dist/react/use-graph-state.js.map +1 -1
  57. package/dist/react/use-graph.d.ts +1 -4
  58. package/dist/react/use-graph.d.ts.map +1 -1
  59. package/dist/react/use-graph.js +38 -49
  60. package/dist/react/use-graph.js.map +1 -1
  61. package/dist/render/graph-looks.d.ts.map +1 -1
  62. package/dist/render/graph-looks.js.map +1 -1
  63. package/dist/render/graph-model.d.ts +6 -8
  64. package/dist/render/graph-model.d.ts.map +1 -1
  65. package/dist/render/graph-model.js +51 -57
  66. package/dist/render/graph-model.js.map +1 -1
  67. package/dist/render/graph-sim.d.ts +2 -3
  68. package/dist/render/graph-sim.d.ts.map +1 -1
  69. package/dist/render/graph-sim.js.map +1 -1
  70. package/dist/render/renderer.d.ts +6 -11
  71. package/dist/render/renderer.d.ts.map +1 -1
  72. package/dist/render/renderer.js +120 -173
  73. package/dist/render/renderer.js.map +1 -1
  74. package/dist/section.d.ts.map +1 -1
  75. package/dist/section.js +3 -7
  76. package/dist/section.js.map +1 -1
  77. package/package.json +11 -11
  78. package/dist/core/refine.d.ts +0 -14
  79. package/dist/core/refine.d.ts.map +0 -1
  80. package/dist/core/refine.js +0 -20
  81. package/dist/core/refine.js.map +0 -1
  82. package/dist/core/resident.d.ts +0 -79
  83. package/dist/core/resident.d.ts.map +0 -1
  84. package/dist/core/resident.js +0 -44
  85. package/dist/core/resident.js.map +0 -1
  86. package/dist/core/scheduler.d.ts +0 -42
  87. package/dist/core/scheduler.d.ts.map +0 -1
  88. package/dist/core/scheduler.js +0 -77
  89. package/dist/core/scheduler.js.map +0 -1
  90. package/dist/core/tile-matrix.d.ts +0 -37
  91. package/dist/core/tile-matrix.d.ts.map +0 -1
  92. package/dist/core/tile-matrix.js +0 -49
  93. package/dist/core/tile-matrix.js.map +0 -1
  94. package/dist/core/tile.d.ts +0 -54
  95. package/dist/core/tile.d.ts.map +0 -1
  96. package/dist/core/tile.js +0 -76
  97. package/dist/core/tile.js.map +0 -1
  98. package/dist/core/tileset.d.ts +0 -59
  99. package/dist/core/tileset.d.ts.map +0 -1
  100. package/dist/core/tileset.js +0 -177
  101. package/dist/core/tileset.js.map +0 -1
  102. package/dist/render/adaptive.d.ts +0 -27
  103. package/dist/render/adaptive.d.ts.map +0 -1
  104. package/dist/render/adaptive.js +0 -25
  105. package/dist/render/adaptive.js.map +0 -1
  106. package/dist/render/compose.d.ts +0 -51
  107. package/dist/render/compose.d.ts.map +0 -1
  108. package/dist/render/compose.js +0 -107
  109. package/dist/render/compose.js.map +0 -1
  110. package/dist/render/encode.d.ts +0 -42
  111. package/dist/render/encode.d.ts.map +0 -1
  112. package/dist/render/encode.js +0 -68
  113. package/dist/render/encode.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"graph-model.js","sources":["../../src/render/graph-model.ts"],"sourcesContent":["import type { GraphConfig } from \"@cosmos.gl/graph\";\nimport { CHART_SLOTS, categoricalCapacity, categoricalColor } from \"@kanzo-tech/ui\";\nimport { isColour, type Channels } from \"../core/channels\";\nimport type { Composition } from \"./compose\";\nimport { resolveToken, toHex, type Rgba } from \"./css-color\";\nimport { SHAPE_INDEX, SHAPE_ORDER, SHAPE_OTHER, type Look, type Shape } from \"./graph-looks\";\nimport type { Sim } from \"./graph-sim\";\n\n/**\n * The categorical scale the bindings imply — what colour and what shape a category rank wears.\n *\n * One answer for the GPU buffers, the hover card and the legend, because three answers is how a\n * legend ends up disagreeing with the canvas it explains. Values are CSS strings: the DOM resolves\n * them itself, and the buffer path resolves them once on its way to the GPU.\n *\n * `capacity` is where Other begins, and it is the document's number rather than the token\n * vocabulary's: a set derived from a client's brand names 6 to 8 real categories, not always 8.\n */\nexport function scaleOf(channels: Channels, capacity = CHART_SLOTS) {\n const constant = isColour(channels.fill) ? channels.fill : undefined;\n const shaped = channels.symbol !== undefined;\n return {\n color: (ordinal: number): string => {\n if (constant) return constant;\n return ordinal >= capacity ? \"var(--muted-foreground)\" : categoricalColor(ordinal, undefined, capacity);\n },\n shape: (ordinal: number): Shape => (shaped ? (SHAPE_ORDER[ordinal] ?? SHAPE_OTHER) : \"circle\"),\n };\n}\n\nexport interface Paint {\n colors: Float32Array;\n sizes: Float32Array;\n shapes: Float32Array;\n linkColors: Float32Array;\n linkWidths: Float32Array;\n}\n\n/**\n * Every per-point and per-link attribute, from one composition and the live theme — what a look or a\n * theme change re-uploads, and all it re-uploads.\n *\n * `host` is the element the tokens are read against, so `var(--primary)` resolves for the tree the\n * canvas sits in. The ramp is `√value` over **this composition** — the biggest node here is what a\n * reader is looking at. A far end past `marks` is drawn at radius zero and alpha zero: it is in the\n * buffers only so an edge has somewhere to end.\n */\nexport function paint(composition: Composition, look: Look, host: Element, channels: Channels = {}): Paint {\n const scale = scaleOf(channels, categoricalCapacity(host));\n const rgba = new Map<number, Rgba>();\n const colourOf = (ordinal: number): Rgba => {\n let resolved = rgba.get(ordinal);\n if (!resolved) rgba.set(ordinal, (resolved = resolveToken(host, scale.color(ordinal))));\n return resolved;\n };\n const n = composition.positions.length / 2;\n const colors = new Float32Array(n * 4);\n const sizes = new Float32Array(n);\n const shapes = new Float32Array(n);\n const ramp = composition.sizes;\n let lo = 0;\n let span = 1;\n if (ramp && composition.marks > 0) {\n let min = Number.POSITIVE_INFINITY;\n let max = 0;\n for (let i = 0; i < composition.marks; i++) {\n const value = ramp[i] as number;\n if (value < min) min = value;\n if (value > max) max = value;\n }\n lo = Math.sqrt(Number.isFinite(min) ? min : 0);\n span = Math.sqrt(max) - lo || 1;\n }\n for (let i = 0; i < composition.marks; i++) {\n const ordinal = composition.categories[i] ?? 0;\n colors.set(colourOf(ordinal), i * 4);\n const t = ramp ? (Math.sqrt(ramp[i] as number) - lo) / span : 0;\n sizes[i] = look.size[0] + t * (look.size[1] - look.size[0]);\n shapes[i] = SHAPE_INDEX[scale.shape(ordinal)] as number;\n }\n\n const count = composition.links.length / 2;\n const linkColors = new Float32Array(count * 4);\n const linkWidths = new Float32Array(count);\n const neutral = channels.stroke ? resolveToken(host, channels.stroke) : null;\n for (let e = 0; e < count; e++) {\n const src = composition.links[e * 2] ?? 0;\n // Link alpha stays 1: `linkOpacity` and the distance fade multiply into it, and a second\n // opacity here would compound with both.\n linkColors.set(\n neutral ? [neutral[0], neutral[1], neutral[2], 1] : [colors[src * 4] ?? 0.7, colors[src * 4 + 1] ?? 0.7, colors[src * 4 + 2] ?? 0.7, 1],\n e * 4,\n );\n const weight = composition.weights?.[e] ?? 1;\n linkWidths[e] = look.link.width * (1 + Math.log2(Math.max(1, weight)) / 2);\n }\n return { colors, sizes, shapes, linkColors, linkWidths };\n}\n\n/** The simulation coefficients, in cosmos.gl's spelling. Shared by construction and every change. */\nexport function forces(sim: Sim): GraphConfig {\n return {\n simulationGravity: sim.gravity,\n simulationRepulsion: sim.repulsion,\n simulationLinkSpring: sim.linkSpring,\n simulationLinkDistance: sim.linkDistance,\n simulationFriction: sim.friction,\n simulationCluster: sim.cluster,\n };\n}\n\n/**\n * Everything the picture needs that is *one number for the whole canvas* — cosmos.gl's uniforms, read\n * fresh on every draw, so a look change costs a `setConfigPartial` and no upload at all.\n */\nexport function appearance(look: Look, host: Element): GraphConfig {\n return {\n backgroundColor: toHex(resolveToken(host, \"var(--background)\")),\n scalePointsOnZoom: false,\n renderLinks: look.link.render,\n linkOpacity: look.link.opacity,\n linkDefaultWidth: look.link.width,\n linkBlending: look.link.blend,\n curvedLinks: look.link.curve > 0,\n curvedLinkControlPointDistance: look.link.curve,\n linkVisibilityDistanceRange: look.link.fade,\n linkVisibilityMinTransparency: 0.12,\n renderHoveredPointRing: true,\n hoveredPointRingColor: toHex(resolveToken(host, \"var(--primary)\")),\n focusedPointRingColor: toHex(resolveToken(host, \"var(--primary)\")),\n pointGreyoutOpacity: 0.1,\n linkGreyoutOpacity: 0.025,\n };\n}\n"],"names":["scaleOf","channels","capacity","CHART_SLOTS","constant","isColour","shaped","ordinal","categoricalColor","SHAPE_ORDER","SHAPE_OTHER","paint","composition","look","host","scale","categoricalCapacity","rgba","colourOf","resolved","resolveToken","n","colors","sizes","shapes","ramp","lo","span","min","max","i","value","t","SHAPE_INDEX","count","linkColors","linkWidths","neutral","e","src","weight","_a","forces","sim","appearance","toHex"],"mappings":";;;;AAkBO,SAASA,EAAQC,GAAoBC,IAAWC,GAAa;AAClE,QAAMC,IAAWC,EAASJ,EAAS,IAAI,IAAIA,EAAS,OAAO,QACrDK,IAASL,EAAS,WAAW;AACnC,SAAO;AAAA,IACL,OAAO,CAACM,MACFH,MACGG,KAAWL,IAAW,4BAA4BM,EAAiBD,GAAS,QAAWL,CAAQ;AAAA,IAExG,OAAO,CAACK,MAA4BD,IAAUG,EAAYF,CAAO,KAAKG,IAAe;AAAA,EAAA;AAEzF;AAmBO,SAASC,EAAMC,GAA0BC,GAAYC,GAAeb,IAAqB,CAAA,GAAW;;AACzG,QAAMc,IAAQf,EAAQC,GAAUe,EAAoBF,CAAI,CAAC,GACnDG,wBAAW,IAAA,GACXC,IAAW,CAACX,MAA0B;AAC1C,QAAIY,IAAWF,EAAK,IAAIV,CAAO;AAC/B,WAAKY,KAAUF,EAAK,IAAIV,GAAUY,IAAWC,EAAaN,GAAMC,EAAM,MAAMR,CAAO,CAAC,CAAE,GAC/EY;AAAA,EACT,GACME,IAAIT,EAAY,UAAU,SAAS,GACnCU,IAAS,IAAI,aAAaD,IA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jE,uBAAuB+B,EAAMzB,EAAaN,GAAM,gBAAgB,CAAC;AAAA,IACjE,qBAAqB;AAAA,IACrB,oBAAoB;AAAA,EAAA;AAExB;"}
1
+ {"version":3,"file":"graph-model.js","sources":["../../src/render/graph-model.ts"],"sourcesContent":["import type { GraphConfig } from \"@cosmos.gl/graph\";\nimport { CHART_SLOTS, categoricalCapacity, categoricalColor } from \"@kanzo-tech/ui\";\nimport { isColour, type Channels } from \"../core/channels\";\nimport type { Encoding, Geometry } from \"../core/load\";\nimport { resolveToken, toHex, type Rgba } from \"./css-color\";\nimport { SHAPE_INDEX, SHAPE_ORDER, SHAPE_OTHER, type Look, type Shape } from \"./graph-looks\";\nimport type { Sim } from \"./graph-sim\";\n\n/**\n * The categorical scale the bindings imply — what colour and what shape a category rank wears.\n *\n * One answer for the GPU buffers, the hover card and the legend, because three answers is how a\n * legend ends up disagreeing with the canvas it explains. Values are CSS strings: the DOM resolves\n * them itself, and the buffer path resolves them once on its way to the GPU.\n *\n * `capacity` is where Other begins, and it is the document's number rather than the token\n * vocabulary's: a set derived from a client's brand names 6 to 8 real categories, not always 8.\n */\nexport function scaleOf(channels: Channels, capacity = CHART_SLOTS) {\n const constant = isColour(channels.fill) ? channels.fill : undefined;\n const shaped = channels.symbol !== undefined;\n return {\n color: (ordinal: number): string => {\n if (constant) return constant;\n return ordinal >= capacity ? \"var(--muted-foreground)\" : categoricalColor(ordinal, undefined, capacity);\n },\n shape: (ordinal: number): Shape => (shaped ? (SHAPE_ORDER[ordinal] ?? SHAPE_OTHER) : \"circle\"),\n };\n}\n\nexport interface Paint {\n colors: Float32Array;\n sizes: Float32Array;\n shapes: Float32Array;\n linkColors: Float32Array;\n}\n\n/**\n * Every per-point and per-link attribute, from the loaded graph and the live theme — what a binding,\n * a look or a theme change re-uploads, and all it re-uploads.\n *\n * `host` is the element the tokens are read against, so `var(--primary)` resolves for the tree the\n * canvas sits in. The ramp is `√value` over the whole graph, and a vertex with no value takes the\n * smallest radius.\n */\nexport function paint(geometry: Geometry, encoding: Encoding, look: Look, host: Element, channels: Channels = {}): Paint {\n const scale = scaleOf(channels, categoricalCapacity(host));\n const rgba = new Map<number, Rgba>();\n const colourOf = (ordinal: number): Rgba => {\n let resolved = rgba.get(ordinal);\n if (!resolved) rgba.set(ordinal, (resolved = resolveToken(host, scale.color(ordinal))));\n return resolved;\n };\n const n = geometry.size;\n const colors = new Float32Array(n * 4);\n const sizes = new Float32Array(n);\n const shapes = new Float32Array(n);\n const ramp = encoding.sizes;\n let lo = 0;\n let span = 1;\n if (ramp) {\n let min = Number.POSITIVE_INFINITY;\n let max = 0;\n for (let i = 0; i < n; i++) {\n const value = ramp[i] as number;\n if (value < min) min = value;\n if (value > max) max = value;\n }\n lo = Math.sqrt(Number.isFinite(min) ? min : 0);\n span = Math.sqrt(max) - lo || 1;\n }\n for (let i = 0; i < n; i++) {\n const ordinal = encoding.ranks[i] ?? 0;\n colors.set(colourOf(ordinal), i * 4);\n const value = ramp ? (ramp[i] as number) : Number.NaN;\n const t = Number.isNaN(value) ? 0 : (Math.sqrt(value) - lo) / span;\n sizes[i] = look.size[0] + t * (look.size[1] - look.size[0]);\n shapes[i] = SHAPE_INDEX[scale.shape(ordinal)] as number;\n }\n\n const count = geometry.links.length / 2;\n const linkColors = new Float32Array(count * 4);\n const neutral = channels.stroke ? resolveToken(host, channels.stroke) : null;\n for (let e = 0; e < count; e++) {\n const src = geometry.links[e * 2] ?? 0;\n // Link alpha stays 1: `linkOpacity` and the distance fade multiply into it, and a second\n // opacity here would compound with both.\n linkColors[e * 4] = neutral ? neutral[0] : (colors[src * 4] ?? 0.7);\n linkColors[e * 4 + 1] = neutral ? neutral[1] : (colors[src * 4 + 1] ?? 0.7);\n linkColors[e * 4 + 2] = neutral ? neutral[2] : (colors[src * 4 + 2] ?? 0.7);\n linkColors[e * 4 + 3] = 1;\n }\n return { colors, sizes, shapes, linkColors };\n}\n\n/** The simulation coefficients, in cosmos.gl's spelling. Shared by construction and every change. */\nexport function forces(sim: Sim): GraphConfig {\n return {\n simulationGravity: sim.gravity,\n simulationRepulsion: sim.repulsion,\n simulationLinkSpring: sim.linkSpring,\n simulationLinkDistance: sim.linkDistance,\n simulationFriction: sim.friction,\n simulationCluster: sim.cluster,\n };\n}\n\n/**\n * Everything the picture needs that is *one number for the whole canvas* — cosmos.gl's uniforms, read\n * fresh on every draw, so a look change costs a `setConfigPartial` and no upload at all.\n */\nexport function appearance(look: Look, host: Element): GraphConfig {\n return {\n backgroundColor: toHex(resolveToken(host, \"var(--background)\")),\n scalePointsOnZoom: false,\n renderLinks: look.link.render,\n linkOpacity: look.link.opacity,\n linkDefaultWidth: look.link.width,\n linkBlending: look.link.blend,\n curvedLinks: look.link.curve > 0,\n curvedLinkControlPointDistance: look.link.curve,\n linkVisibilityDistanceRange: look.link.fade,\n linkVisibilityMinTransparency: 0.12,\n renderHoveredPointRing: true,\n hoveredPointRingColor: toHex(resolveToken(host, \"var(--primary)\")),\n focusedPointRingColor: toHex(resolveToken(host, \"var(--primary)\")),\n pointGreyoutOpacity: 0.1,\n linkGreyoutOpacity: 0.025,\n };\n}\n"],"names":["scaleOf","channels","capacity","CHART_SLOTS","constant","isColour","shaped","ordinal","categoricalColor","SHAPE_ORDER","SHAPE_OTHER","paint","geometry","encoding","look","host","scale","categoricalCapacity","rgba","colourOf","resolved","resolveToken","n","colors","sizes","shapes","ramp","lo","span","min","max","i","value","t","SHAPE_INDEX","count","linkColors","neutral","e","src","forces","sim","appearance","toHex"],"mappings":";;;;AAkBO,SAASA,EAAQC,GAAoBC,IAAWC,GAAa;AAClE,QAAMC,IAAWC,EAASJ,EAAS,IAAI,IAAIA,EAAS,OAAO,QACrDK,IAASL,EAAS,WAAW;AACnC,SAAO;AAAA,IACL,OAAO,CAACM,MACFH,MACGG,KAAWL,IAAW,4BAA4BM,EAAiBD,GAAS,QAAWL,CAAQ;AAAA,IAExG,OAAO,CAACK,MAA4BD,IAAUG,EAAYF,CAAO,KAAKG,IAAe;AAA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K;AAAA,IACxB,aAAaA,EAAK,KAAK,QAAQ;AAAA,IAC/B,gCAAgCA,EAAK,KAAK;AAAA,IAC1C,6BAA6BA,EAAK,KAAK;AAAA,IACvC,+BAA+B;AAAA,IAC/B,wBAAwB;AAAA,IACxB,uBAAuB6B,EAAMtB,EAAaN,GAAM,gBAAgB,CAAC;AAAA,IACjE,uBAAuB4B,EAAMtB,EAAaN,GAAM,gBAAgB,CAAC;AAAA,IACjE,qBAAqB;AAAA,IACrB,oBAAoB;AAAA,EAAA;AAExB;"}
@@ -25,9 +25,8 @@ export interface Sim {
25
25
  *
26
26
  * Chosen against a corpus of that size, and they are a starting point rather than a law: a graph
27
27
  * two orders of magnitude larger wants less repulsion and more friction, and the measurements in
28
- * `/docs/graph/benchmarks` say a live simulation is finished by around 200,000 points regardless. What a
29
- * corpus of a given size wants is computed rather than chosen — see `adaptive` — and a host that
30
- * knows its corpus should start its users at that answer through the tenant policy.
28
+ * `/docs/graph/benchmarks` say a live simulation is finished by around 200,000 points regardless. A
29
+ * host that knows its corpus starts its users elsewhere through the tenant policy.
31
30
  *
32
31
  * The values are strings for the reason `lookFrom`'s are: a contributed preference is a string in
33
32
  * all three kinds, so an unrecognised namespace rides through a write untouched. A key that is
@@ -1 +1 @@
1
- {"version":3,"file":"graph-sim.d.ts","sourceRoot":"","sources":["../../src/render/graph-sim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iEAAiE;AACjE,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAM,GAAG,GAAG,CAatF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,GAAe,CAAC;AAE1C;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAGpD"}
1
+ {"version":3,"file":"graph-sim.d.ts","sourceRoot":"","sources":["../../src/render/graph-sim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iEAAiE;AACjE,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAM,GAAG,GAAG,CAatF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,GAAe,CAAC;AAE1C;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAGpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"graph-sim.js","sources":["../../src/render/graph-sim.ts"],"sourcesContent":["/**\n * The force coefficients, and the one function that builds them from the axes a person chose.\n *\n * `graph-looks.ts`'s sibling, and deliberately its twin: a type the renderer consumes, one builder\n * that reads declared string values, and a default that is the builder called with nothing. What was\n * here before is what was there before — an interface, a `DEFAULT_SIM` table beside it, and a dock\n * that held six of them in React state and drew six sliders by hand.\n *\n * **A coefficient is not appearance, and it is still a preference.** `section.ts` says why it shares\n * the manifest: `tokens` are the colours a document may move, `prefs` are what the person on the\n * screen decides, and somebody tuning a layout until it settles is deciding.\n */\n\n/** Force coefficients, handed straight to the GPU simulation. */\nexport interface Sim {\n gravity: number;\n repulsion: number;\n linkSpring: number;\n linkDistance: number;\n friction: number;\n /** Pull toward the node's group position on the cluster ring. Zero lets the links decide alone. */\n cluster: number;\n}\n\n/**\n * Coefficients that settle a few-hundred-node graph into something readable.\n *\n * Chosen against a corpus of that size, and they are a starting point rather than a law: a graph\n * two orders of magnitude larger wants less repulsion and more friction, and the measurements in\n * `/docs/graph/benchmarks` say a live simulation is finished by around 200,000 points regardless. What a\n * corpus of a given size wants is computed rather than chosen — see `adaptive` — and a host that\n * knows its corpus should start its users at that answer through the tenant policy.\n *\n * The values are strings for the reason `lookFrom`'s are: a contributed preference is a string in\n * all three kinds, so an unrecognised namespace rides through a write untouched. A key that is\n * missing, or that carries a value the section never offered, takes the default below — which is\n * what a graph simulated before any of this existed.\n */\nexport function simFrom(values: Readonly<Record<string, string | undefined>> = {}): Sim {\n const num = (key: string, fallback: number) => {\n const value = Number.parseFloat(values[key] ?? \"\");\n return Number.isFinite(value) ? value : fallback;\n };\n return {\n gravity: num(\"gravity\", 0.14),\n repulsion: num(\"repulsion\", 1.1),\n linkSpring: num(\"link-spring\", 0.6),\n linkDistance: num(\"link-distance\", 18),\n friction: num(\"friction\", 0.86),\n cluster: num(\"cluster\", 0.1),\n };\n}\n\n/**\n * What a canvas simulates with when nobody has chosen anything.\n *\n * **Not on the barrel, and it used to be** — for the reason its twin was: it is `simFrom()`, a\n * second public name for a value already available on request, exported only because `sim` took a\n * whole `Sim` and a host changing `gravity` had to supply the other five.\n */\nexport const DEFAULT_SIM: Sim = simFrom();\n\n/**\n * The coefficients a caller wants different, over the ones this package chose.\n *\n * Flat, so a spread is the whole merge. `undefined` returns the shared constant rather than a copy:\n * the renderer re-heats when the forces change, so a fresh object\n * per render would put energy back into a settled layout on every render.\n */\nexport function resolveSim(patch?: Partial<Sim>): Sim {\n if (!patch) return DEFAULT_SIM;\n return { ...DEFAULT_SIM, ...patch };\n}\n"],"names":["simFrom","values","num","key","fallback","value","DEFAULT_SIM","resolveSim","patch"],"mappings":"AAsCO,SAASA,EAAQC,IAAuD,IAAS;AACtF,QAAMC,IAAM,CAACC,GAAaC,MAAqB;AAC7C,UAAMC,IAAQ,OAAO,WAAWJ,EAAOE,CAAG,KAAK,EAAE;AACjD,WAAO,OAAO,SAASE,CAAK,IAAIA,IAAQD;AAAA,EAC1C;AACA,SAAO;AAAA,IACL,SAASF,EAAI,WAAW,IAAI;AAAA,IAC5B,WAAWA,EAAI,aAAa,GAAG;AAAA,IAC/B,YAAYA,EAAI,eAAe,GAAG;AAAA,IAClC,cAAcA,EAAI,iBAAiB,EAAE;AAAA,IACrC,UAAUA,EAAI,YAAY,IAAI;AAAA,IAC9B,SAASA,EAAI,WAAW,GAAG;AAAA,EAAA;AAE/B;AASO,MAAMI,IAAmBN,EAAA;AASzB,SAASO,EAAWC,GAA2B;AACpD,SAAKA,IACE,EAAE,GAAGF,GAAa,GAAGE,EAAA,IADTF;AAErB;"}
1
+ {"version":3,"file":"graph-sim.js","sources":["../../src/render/graph-sim.ts"],"sourcesContent":["/**\n * The force coefficients, and the one function that builds them from the axes a person chose.\n *\n * `graph-looks.ts`'s sibling, and deliberately its twin: a type the renderer consumes, one builder\n * that reads declared string values, and a default that is the builder called with nothing. What was\n * here before is what was there before — an interface, a `DEFAULT_SIM` table beside it, and a dock\n * that held six of them in React state and drew six sliders by hand.\n *\n * **A coefficient is not appearance, and it is still a preference.** `section.ts` says why it shares\n * the manifest: `tokens` are the colours a document may move, `prefs` are what the person on the\n * screen decides, and somebody tuning a layout until it settles is deciding.\n */\n\n/** Force coefficients, handed straight to the GPU simulation. */\nexport interface Sim {\n gravity: number;\n repulsion: number;\n linkSpring: number;\n linkDistance: number;\n friction: number;\n /** Pull toward the node's group position on the cluster ring. Zero lets the links decide alone. */\n cluster: number;\n}\n\n/**\n * Coefficients that settle a few-hundred-node graph into something readable.\n *\n * Chosen against a corpus of that size, and they are a starting point rather than a law: a graph\n * two orders of magnitude larger wants less repulsion and more friction, and the measurements in\n * `/docs/graph/benchmarks` say a live simulation is finished by around 200,000 points regardless. A\n * host that knows its corpus starts its users elsewhere through the tenant policy.\n *\n * The values are strings for the reason `lookFrom`'s are: a contributed preference is a string in\n * all three kinds, so an unrecognised namespace rides through a write untouched. A key that is\n * missing, or that carries a value the section never offered, takes the default below — which is\n * what a graph simulated before any of this existed.\n */\nexport function simFrom(values: Readonly<Record<string, string | undefined>> = {}): Sim {\n const num = (key: string, fallback: number) => {\n const value = Number.parseFloat(values[key] ?? \"\");\n return Number.isFinite(value) ? value : fallback;\n };\n return {\n gravity: num(\"gravity\", 0.14),\n repulsion: num(\"repulsion\", 1.1),\n linkSpring: num(\"link-spring\", 0.6),\n linkDistance: num(\"link-distance\", 18),\n friction: num(\"friction\", 0.86),\n cluster: num(\"cluster\", 0.1),\n };\n}\n\n/**\n * What a canvas simulates with when nobody has chosen anything.\n *\n * **Not on the barrel, and it used to be** — for the reason its twin was: it is `simFrom()`, a\n * second public name for a value already available on request, exported only because `sim` took a\n * whole `Sim` and a host changing `gravity` had to supply the other five.\n */\nexport const DEFAULT_SIM: Sim = simFrom();\n\n/**\n * The coefficients a caller wants different, over the ones this package chose.\n *\n * Flat, so a spread is the whole merge. `undefined` returns the shared constant rather than a copy:\n * the renderer re-heats when the forces change, so a fresh object\n * per render would put energy back into a settled layout on every render.\n */\nexport function resolveSim(patch?: Partial<Sim>): Sim {\n if (!patch) return DEFAULT_SIM;\n return { ...DEFAULT_SIM, ...patch };\n}\n"],"names":["simFrom","values","num","key","fallback","value","DEFAULT_SIM","resolveSim","patch"],"mappings":"AAqCO,SAASA,EAAQC,IAAuD,IAAS;AACtF,QAAMC,IAAM,CAACC,GAAaC,MAAqB;AAC7C,UAAMC,IAAQ,OAAO,WAAWJ,EAAOE,CAAG,KAAK,EAAE;AACjD,WAAO,OAAO,SAASE,CAAK,IAAIA,IAAQD;AAAA,EAC1C;AACA,SAAO;AAAA,IACL,SAASF,EAAI,WAAW,IAAI;AAAA,IAC5B,WAAWA,EAAI,aAAa,GAAG;AAAA,IAC/B,YAAYA,EAAI,eAAe,GAAG;AAAA,IAClC,cAAcA,EAAI,iBAAiB,EAAE;AAAA,IACrC,UAAUA,EAAI,YAAY,IAAI;AAAA,IAC9B,SAASA,EAAI,WAAW,GAAG;AAAA,EAAA;AAE/B;AASO,MAAMI,IAAmBN,EAAA;AASzB,SAASO,EAAWC,GAA2B;AACpD,SAAKA,IACE,EAAE,GAAGF,GAAa,GAAGE,EAAA,IADTF;AAErB;"}
@@ -1,20 +1,14 @@
1
1
  import { Graph } from '@cosmos.gl/graph';
2
- import { Resident } from '../core/resident';
3
2
  import { GraphStore } from '../core/store';
4
3
  import { GraphCommands } from '../core/types';
5
- import { Composition } from './compose';
6
4
  export interface RendererEvents {
7
5
  /** After every frame and every camera move — where the overlays repaint. */
8
6
  onFrame?: () => void;
9
- /** A new composition was uploaded. */
10
- onComposed?: (composition: Composition) => void;
11
7
  /** Where the hovered point is in space, as cosmos.gl reports it: no GPU readback per hover. */
12
8
  onHover?: (position: [number, number] | null) => void;
13
9
  }
14
10
  export interface Renderer extends GraphCommands {
15
11
  readonly graph: Graph;
16
- resident(): Resident;
17
- composition(): Composition | null;
18
12
  /** The theme moved under the canvas: colours are resolved again, nothing else. */
19
13
  repaint(): void;
20
14
  /** The drawn points inside a screen rectangle or polygon, once the device is ready. */
@@ -29,15 +23,16 @@ export interface Renderer extends GraphCommands {
29
23
  * **cosmos.gl's lifetime, and the frame that renders once.** Built once per element; it subscribes to
30
24
  * the store and discharges what changed in one `requestAnimationFrame`:
31
25
  *
32
- * - a change of visible tiles recomposes, and dirties positions, links and the per-point arrays;
33
- * - a look or a theme change dirties colours, sizes and shapes and nothing else;
26
+ * - a new graph uploads positions and links, once per corpus; a filter uploads positions alone;
27
+ * - a binding, a look or a theme change uploads colours, sizes and shapes and nothing else;
34
28
  * - a selection, a focus or a pin sets config and uploads nothing, and never calls `render()`:
35
29
  * `render()` walks every point and link in JS, and `setConfigPartial` asks for its own frame;
36
- * - a snapshot that changed none of those schedules nothing.
30
+ * - the camera reaches nothing: cosmos.gl moves it, and the overlays follow.
37
31
  *
32
+ * A vertex's id is its index here, so nothing is resolved between the store and the buffers.
38
33
  * `transitionDuration` is 0: the default animates every upload for 800 ms and keeps the loop awake.
39
- * The live layout is off unless `simulate` or the toolbar asks, and runs from the current positions;
40
- * a drag needs none, since cosmos.gl moves the dragged point itself. Every callback reads the store's latest options, so a host's inline `onFailure` never rebuilds it.
34
+ * The live layout is off unless `simulate` or the toolbar asks, and runs from the current positions.
35
+ * Every callback reads the store's latest options, so a host's inline `onFailure` never rebuilds it.
41
36
  */
42
37
  export declare function createRenderer(host: HTMLDivElement, store: GraphStore, events?: RendererEvents): Renderer | null;
43
38
  //# sourceMappingURL=renderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,kBAAkB,CAAC;AAE3D,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7D,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sCAAsC;IACtC,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,+FAA+F;IAC/F,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,QAAS,SAAQ,aAAa;IAC7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AC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAAE,GAAG,MAAM,EAAE,CAAC;IACvG,OAAO,IAAI,IAAI,CAAC;CACjB;AAqBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAE,cAAmB,GAAG,QAAQ,GAAG,IAAI,CA8QpH"}
@@ -1,43 +1,41 @@
1
- import { Graph as v } from "@cosmos.gl/graph";
2
- import { denseOf as ii } from "../core/resident.js";
3
- import { tileOfDense as ni } from "../core/tile-matrix.js";
4
- import { createComposer as ti } from "./compose.js";
5
- import { resolveLook as _ } from "./graph-looks.js";
6
- import { forces as R, appearance as U, paint as ei } from "./graph-model.js";
7
- import { resolveSim as Z } from "./graph-sim.js";
8
- import { hasWebGL as oi, releaseContext as ri } from "./webgl.js";
9
- const S = 420, y = 0.18, O = 0.35, j = 20, C = (c) => [c.x, c.y, c.x + c.w, c.y + c.h];
10
- function gi(c, e, o = {}) {
11
- const M = (i) => e.getOptions().onFailure(i);
12
- if (!oi())
13
- return M("This canvas renders on the GPU, and this browser offers no WebGL context."), null;
14
- let b = Z(e.getOptions().sim), g = e.getOptions().simulate ?? !1, T = null, k = null, F = -1;
15
- const B = (i) => {
16
- const n = Math.round(i * j);
17
- n !== F && (F = n, e.reportProgress(n / j));
18
- }, Y = ti();
19
- let d = null, w = _(e.getOptions().look), E = e.getOptions().look;
20
- const s = { compose: !0, paint: !0, state: !0, pinned: !0 };
21
- let P = 0, I = !1, A = null, x = null, f = e.getSnapshot(), h = e.getOptions();
22
- const m = () => (d == null ? void 0 : d.resident) ?? ai, z = () => {
23
- const { height: i, width: n } = c.getBoundingClientRect();
24
- if (!t.isReady || n === 0 || i === 0) return null;
25
- const [a, l] = t.screenToSpacePosition([0, 0]), [u, p] = t.screenToSpacePosition([n, i]), r = { xMin: Math.min(a, u), yMin: Math.min(l, p), xMax: Math.max(a, u), yMax: Math.max(l, p) };
26
- return { view: r, perPixel: (r.xMax - r.xMin) / n };
27
- }, G = () => {
28
- const i = z();
29
- i && e.setViewport(i.view);
1
+ import { Graph as j } from "@cosmos.gl/graph";
2
+ import { resolveLook as B } from "./graph-looks.js";
3
+ import { forces as x, appearance as H, paint as $ } from "./graph-model.js";
4
+ import { resolveSim as M } from "./graph-sim.js";
5
+ import { hasWebGL as J, releaseContext as K } from "./webgl.js";
6
+ const C = 420, z = 0.18, S = 0.35, V = 20, _ = (s) => [s.x, s.y, s.x + s.w, s.y + s.h];
7
+ function Q(s, i) {
8
+ if (!i) return s.positions;
9
+ const e = s.positions.slice();
10
+ for (let l = 0; l < s.size; l++)
11
+ i[l] || (e[l * 2] = e[l * 2 + 1] = Number.NaN);
12
+ return e;
13
+ }
14
+ function on(s, i, e = {}) {
15
+ const l = (n) => i.getOptions().onFailure(n);
16
+ if (!J())
17
+ return l("This canvas renders on the GPU, and this browser offers no WebGL context."), null;
18
+ let h = M(i.getOptions().sim), f = i.getOptions().simulate ?? !1, k = null, y = null, D = -1;
19
+ const F = (n) => {
20
+ const t = Math.round(n * V);
21
+ t !== D && (D = t, i.reportProgress(t / V));
22
+ };
23
+ let P = B(i.getOptions().look), I = i.getOptions().look;
24
+ const r = { positions: !0, paint: !0, state: !0, pinned: !0 };
25
+ let g = 0, L = !1, T = null, b = null, u = i.getSnapshot(), p = i.getOptions();
26
+ const E = () => {
27
+ var n;
28
+ return ((n = i.getSnapshot().geometry) == null ? void 0 : n.size) ?? 0;
30
29
  };
31
- let t;
30
+ let o;
32
31
  try {
33
- t = new v(c, {
34
- // No `spaceSize` here: the box is the corpus's extent, set when the matrix arrives.
35
- // `rescalePositions: false` because the corpus's coordinates are the camera's — a rescale
36
- // between them means the cull and the viewport describe different places.
32
+ o = new j(s, {
33
+ // No `spaceSize` here: the box is the corpus's extent, set when the graph has loaded.
34
+ // `rescalePositions: false` because the corpus's coordinates are the camera's.
37
35
  rescalePositions: !1,
38
36
  transitionDuration: 0,
39
- enableSimulation: g,
40
- ...R(b),
37
+ enableSimulation: f,
38
+ ...x(h),
41
39
  // Frames to convergence: alpha reaches its floor after exactly this many rendered frames.
42
40
  simulationDecay: 400,
43
41
  randomSeed: "kanzo-discovery",
@@ -45,188 +43,137 @@ function gi(c, e, o = {}) {
45
43
  enableDrag: !0,
46
44
  hoveredPointCursor: "pointer",
47
45
  attribution: "",
48
- onSimulationStart: () => e.report("running"),
46
+ onSimulationStart: () => i.report("running"),
49
47
  onSimulationEnd: () => {
50
- var i;
51
- e.report("settled"), B(1), (i = o.onFrame) == null || i.call(o);
48
+ var n;
49
+ i.report("settled"), F(1), (n = e.onFrame) == null || n.call(e);
52
50
  },
53
- onSimulationPause: () => e.report("paused"),
54
- onSimulationUnpause: () => e.report("running"),
55
- onSimulationTick: (i, n, a) => {
56
- var l, u;
57
- B(t.progress), n !== void 0 && a && ((l = o.onHover) == null || l.call(o, a)), (u = o.onFrame) == null || u.call(o);
51
+ onSimulationPause: () => i.report("paused"),
52
+ onSimulationUnpause: () => i.report("running"),
53
+ onSimulationTick: (n, t, a) => {
54
+ var c, d;
55
+ F(o.progress), t !== void 0 && a && ((c = e.onHover) == null || c.call(e, a)), (d = e.onFrame) == null || d.call(e);
58
56
  },
59
57
  onZoom: () => {
60
- var i;
61
- G(), (i = o.onFrame) == null || i.call(o);
58
+ var n;
59
+ return (n = e.onFrame) == null ? void 0 : n.call(e);
62
60
  },
63
- onPointMouseOver: (i, n) => {
61
+ onPointMouseOver: (n, t) => {
64
62
  var a;
65
- T = i, (a = o.onHover) == null || a.call(o, n), e.hover(m().at(i) ?? null);
63
+ k = n, (a = e.onHover) == null || a.call(e, t), i.hover(n);
66
64
  },
67
65
  onPointMouseOut: () => {
68
- var i;
69
- T = null, (i = o.onHover) == null || i.call(o, null), e.hover(null);
66
+ var n;
67
+ k = null, (n = e.onHover) == null || n.call(e, null), i.hover(null);
70
68
  },
71
69
  onDragStart: () => {
72
- k = T;
70
+ y = k;
73
71
  },
74
- onDrag: (i) => {
75
- var n, a;
76
- (n = o.onHover) == null || n.call(o, t.screenToSpacePosition([i.x, i.y])), (a = o.onFrame) == null || a.call(o);
72
+ onDrag: (n) => {
73
+ var t, a;
74
+ (t = e.onHover) == null || t.call(e, o.screenToSpacePosition([n.x, n.y])), (a = e.onFrame) == null || a.call(e);
77
75
  },
78
76
  onDragEnd: () => {
79
- const i = k === null ? void 0 : m().at(k);
80
- k = null, i !== void 0 && e.pin([...e.getSnapshot().pinned, i]);
81
- },
82
- onPointClick: (i) => {
83
- const n = m().at(i);
84
- n !== void 0 && H(n, i);
77
+ const n = y;
78
+ y = null, n !== null && i.pin([...i.getSnapshot().pinned, n]);
85
79
  },
86
- onBackgroundClick: () => W()
80
+ onPointClick: (n) => R(n),
81
+ onBackgroundClick: () => A()
87
82
  });
88
- } catch (i) {
89
- return M(`The renderer failed to start. (${String(i)})`), null;
83
+ } catch (n) {
84
+ return l(`The renderer failed to start. (${String(n)})`), null;
90
85
  }
91
- const D = () => {
92
- P || (P = requestAnimationFrame(() => {
93
- P = 0, $();
86
+ const w = () => {
87
+ g || (g = requestAnimationFrame(() => {
88
+ g = 0, q();
94
89
  }));
95
90
  };
96
- function $() {
97
- var l, u, p;
98
- const i = e.getSnapshot(), n = e.getOptions();
99
- let a = !1;
100
- if (s.compose && i.matrix) {
101
- s.compose = !1;
102
- const r = Y({
103
- matrix: i.matrix,
104
- typeIndex: i.typeIndex,
105
- binding: i.binding,
106
- modeColumn: i.modeColumn,
107
- domain: i.domain,
108
- visible: i.visible,
109
- cached: i.cached,
110
- perPixel: ((l = z()) == null ? void 0 : l.perPixel) ?? 0
111
- });
112
- if (r && (d = r, t.setPointPositions(r.positions, !0), t.setLinks(r.links), s.paint = !0, s.state = !0, s.pinned = !0, a = !0, (u = o.onComposed) == null || u.call(o, r), x !== null && r.resident.indexOf(x) !== void 0)) {
113
- const X = x;
114
- x = null, queueMicrotask(() => q(X));
115
- }
116
- const Q = r && { marks: r.marks, represented: r.represented, domain: r.domain, tally: r.tally };
117
- e.reportDrawn(i.visible, Q);
118
- }
119
- if (s.paint && d) {
120
- s.paint = !1;
121
- const r = ei(d, w, c, n);
122
- t.setPointColors(r.colors), t.setPointSizes(r.sizes), t.setPointShapes(r.shapes), t.setLinkColors(r.linkColors), t.setLinkWidths(r.linkWidths), t.setConfigPartial(U(w, c)), a = !0;
123
- }
124
- if (s.state && d) {
125
- s.state = !1;
126
- const r = d.resident;
127
- t.setConfigPartial({
128
- highlightedPointIndices: i.selection ? r.indicesOf(i.selection.vertices) : void 0,
129
- focusedPointIndex: i.focus === null ? void 0 : r.indexOf(i.focus)
130
- });
91
+ function q() {
92
+ var N;
93
+ const n = i.getSnapshot(), { geometry: t, encoding: a } = n, c = i.getOptions();
94
+ let d = !1;
95
+ if (r.positions && t && (r.positions = !1, U(t), o.setPointPositions(Q(t, n.mask), !0), t.links !== b && (b = t.links, o.setLinks(b), r.paint = r.state = r.pinned = !0), d = !0), r.paint && t && a) {
96
+ r.paint = !1;
97
+ const m = $(t, a, P, s, c);
98
+ o.setPointColors(m.colors), o.setPointSizes(m.sizes), o.setPointShapes(m.shapes), o.setLinkColors(m.linkColors), o.setConfigPartial(H(P, s)), d = !0;
131
99
  }
132
- if (s.pinned && d) {
133
- s.pinned = !1;
134
- const r = d.resident.indicesOf(i.pinned);
135
- t.setPinnedPoints(r.length > 0 ? r : null);
136
- }
137
- a && t.render(), (p = o.onFrame) == null || p.call(o);
100
+ r.state && t && (r.state = !1, o.setConfigPartial({
101
+ highlightedPointIndices: n.selection ? n.selection.vertices.filter((m) => m < t.size) : void 0,
102
+ focusedPointIndex: n.focus === null || n.focus >= t.size ? void 0 : n.focus
103
+ })), r.pinned && t && (r.pinned = !1, o.setPinnedPoints(n.pinned.length > 0 ? [...n.pinned] : null)), d && o.render(), t && a && !r.paint && i.reportDrawn(n), (N = e.onFrame) == null || N.call(e);
138
104
  }
139
- const V = (i) => {
140
- var a;
141
- const n = (a = i.matrix) == null ? void 0 : a.extent;
142
- !n || i.matrix === A || (A = i.matrix, t.setConfigPartial({ spaceSize: Math.max(n.w, n.h) }), t.fitViewByPointPositions(C(n), 0, y), t.ready.then(() => {
143
- I || G();
144
- }));
145
- }, J = e.subscribe(() => {
146
- const i = e.getSnapshot(), n = e.getOptions();
147
- V(i), (i.visible !== f.visible || i.binding !== f.binding || i.domain !== f.domain) && (s.compose = !0), n.look !== E && (E = n.look, w = _(n.look), s.paint = !0), (n.fill !== h.fill || n.symbol !== h.symbol || n.stroke !== h.stroke) && (s.paint = !0), (i.selection !== f.selection || i.focus !== f.focus) && (s.state = !0), i.pinned !== f.pinned && (s.pinned = !0), n.sim !== h.sim && K(n.sim), (n.simulate ?? !1) !== (h.simulate ?? !1) && (n.simulate ? L(O) : t.pause()), f = i, h = n, (s.compose || s.paint || s.state || s.pinned) && D();
148
- });
149
- function K(i) {
150
- const n = Z(i), a = Object.keys(n).some((l) => n[l] !== b[l]);
151
- b = n, g && (t.setConfigPartial(R(n)), a && e.getSnapshot().motion !== "paused" && t.start(O));
105
+ function U(n) {
106
+ n === T || !n.extent || (T = n, o.setConfigPartial({ spaceSize: Math.max(n.extent.w, n.extent.h) }), o.fitViewByPointPositions(_(n.extent), 0, z));
152
107
  }
153
- function L(i) {
154
- g || (g = !0, t.setConfigPartial({ enableSimulation: !0, ...R(b) })), t.start(i);
108
+ const W = i.subscribe(() => {
109
+ const n = i.getSnapshot(), t = i.getOptions();
110
+ (n.geometry !== u.geometry || n.mask !== u.mask) && (r.positions = !0), n.encoding !== u.encoding && (r.paint = !0), t.look !== I && (I = t.look, P = B(t.look), r.paint = !0), (t.fill !== p.fill || t.symbol !== p.symbol || t.stroke !== p.stroke) && (r.paint = !0), (n.selection !== u.selection || n.focus !== u.focus) && (r.state = !0), n.pinned !== u.pinned && (r.pinned = !0), t.sim !== p.sim && Z(t.sim), (t.simulate ?? !1) !== (p.simulate ?? !1) && (t.simulate ? O(S) : o.pause()), u = n, p = t, (r.positions || r.paint || r.state || r.pinned) && w();
111
+ });
112
+ function Z(n) {
113
+ const t = M(n), a = Object.keys(t).some((c) => t[c] !== h[c]);
114
+ h = t, f && (o.setConfigPartial(x(t)), a && i.getSnapshot().motion !== "paused" && o.start(S));
155
115
  }
156
- function H(i, n) {
157
- const l = m().verticesAt(t.getNeighboringPointIndices(n));
158
- e.select([i, ...l], "node", "Node"), e.focus(i);
116
+ function O(n) {
117
+ f || (f = !0, o.setConfigPartial({ enableSimulation: !0, ...x(h) })), o.start(n);
159
118
  }
160
- function W() {
161
- e.select(null), e.focus(null);
119
+ function R(n) {
120
+ const t = o.getNeighboringPointIndices(n) ?? [];
121
+ i.select([n, ...t], "node", "Node"), i.focus(n);
162
122
  }
163
- function q(i) {
164
- var p, r;
165
- const n = m().indexOf(i);
166
- if (n !== void 0) {
167
- H(i, n), t.zoomToPointByIndex(n, 500, 5, !0);
168
- return;
169
- }
170
- const a = e.getSnapshot().matrix, l = a ? ni(a, ii(i)) : null, u = l && ((r = (p = a == null ? void 0 : a.tileMatrices[l.z]) == null ? void 0 : p.tiles[l.tile]) == null ? void 0 : r.bbox);
171
- u && (x = i, t.fitViewByPointPositions(C(u), S, y));
123
+ function A() {
124
+ i.select(null), i.focus(null);
172
125
  }
173
- t.setConfigPartial(U(w, c)), t.render();
174
- const N = (i) => {
175
- i.preventDefault(), M("The graph's WebGL context was lost. A browser keeps a limited number of them and drops the oldest; reload the page to get one back.");
126
+ o.setConfigPartial(H(P, s)), o.render();
127
+ const G = (n) => {
128
+ n.preventDefault(), l("The graph's WebGL context was lost. A browser keeps a limited number of them and drops the oldest; reload the page to get one back.");
176
129
  };
177
- return t.ready.then(() => {
178
- var i;
179
- I || (i = c.querySelector("canvas")) == null || i.addEventListener("webglcontextlost", N);
180
- }), e.report(g && t.isSimulationRunning ? "running" : "settled"), V(f), D(), {
181
- graph: t,
182
- resident: m,
183
- composition: () => d,
130
+ return o.ready.then(() => {
131
+ var n;
132
+ L || (n = s.querySelector("canvas")) == null || n.addEventListener("webglcontextlost", G);
133
+ }), i.report(f && o.isSimulationRunning ? "running" : "settled"), w(), {
134
+ graph: o,
184
135
  repaint() {
185
- s.paint = !0, D();
136
+ r.paint = !0, w();
186
137
  },
187
- hit(i) {
188
- const n = "rect" in i ? t.findPointsInRect(i.rect) : t.findPointsInPolygon(i.polygon);
189
- return Array.from(n);
138
+ hit(n) {
139
+ const t = "rect" in n ? o.findPointsInRect(n.rect) : o.findPointsInPolygon(n.polygon);
140
+ return Array.from(t);
190
141
  },
191
- zoomBy(i) {
192
- t.setZoomLevel(t.getZoomLevel() * i, 220);
142
+ zoomBy(n) {
143
+ o.setZoomLevel(o.getZoomLevel() * n, 220);
193
144
  },
194
145
  fit() {
195
- var n;
196
- const i = (n = e.getSnapshot().matrix) == null ? void 0 : n.extent;
197
- i ? t.fitViewByPointPositions(C(i), S, y) : t.fitView(S, y);
146
+ var t;
147
+ const n = (t = i.getSnapshot().geometry) == null ? void 0 : t.extent;
148
+ n ? o.fitViewByPointPositions(_(n), C, z) : o.fitView(C, z);
198
149
  },
199
- pause: () => t.pause(),
150
+ pause: () => o.pause(),
200
151
  resume() {
201
- e.getSnapshot().motion === "settled" || !g ? L(O) : t.unpause();
152
+ i.getSnapshot().motion === "settled" || !f ? O(S) : o.unpause();
202
153
  },
203
154
  restart() {
204
- e.pin([]), L(1);
155
+ i.pin([]), O(1);
205
156
  },
206
157
  unpin() {
207
- e.getSnapshot().pinned.length !== 0 && (e.pin([]), e.getSnapshot().motion === "running" && t.start(O));
158
+ i.getSnapshot().pinned.length !== 0 && (i.pin([]), i.getSnapshot().motion === "running" && o.start(S));
208
159
  },
209
- reveal: q,
210
- frameBox(i, { duration: n = S, padding: a = y } = {}) {
211
- t.fitViewByPointPositions(C(i), n, a);
160
+ reveal(n) {
161
+ n >= E() || (R(n), o.zoomToPointByIndex(n, 500, 5, !0));
212
162
  },
213
163
  frameSelection() {
214
- var n;
215
- const i = m().indicesOf(((n = e.getSnapshot().selection) == null ? void 0 : n.vertices) ?? []);
216
- i.length > 0 && t.fitViewByPointIndices(i, S, 0.25);
164
+ var t;
165
+ const n = (((t = i.getSnapshot().selection) == null ? void 0 : t.vertices) ?? []).filter((a) => a < E());
166
+ n.length > 0 && o.fitViewByPointIndices(n, C, 0.25);
217
167
  },
218
- clear: W,
168
+ clear: A,
219
169
  destroy() {
220
- J(), P && cancelAnimationFrame(P), I = !0;
221
- const i = c.querySelector("canvas");
222
- i == null || i.removeEventListener("webglcontextlost", N), t.destroy(), ri(i);
170
+ W(), g && cancelAnimationFrame(g), L = !0;
171
+ const n = s.querySelector("canvas");
172
+ n == null || n.removeEventListener("webglcontextlost", G), o.destroy(), K(n);
223
173
  }
224
174
  };
225
175
  }
226
- const ai = { size: 0, indexOf: () => {
227
- }, at: () => {
228
- }, indicesOf: () => [], verticesAt: () => [] };
229
176
  export {
230
- gi as createRenderer
177
+ on as createRenderer
231
178
  };
232
179
  //# sourceMappingURL=renderer.js.map