fastplotpy 0.3.0a1__py3-none-win_amd64.whl

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 (78) hide show
  1. fastplotpy/README.md +70 -0
  2. fastplotpy/__init__.py +33 -0
  3. fastplotpy/assets/dist/assets/scene.worker-CcnexaKr.js +1 -0
  4. fastplotpy/assets/dist/index.js +15071 -0
  5. fastplotpy/assets/native/NotoSans-OFL.txt +96 -0
  6. fastplotpy/assets/native/THIRD_PARTY_NOTICES.md +24 -0
  7. fastplotpy/assets/native/fastplot_python_abi.dll +0 -0
  8. fastplotpy/assets/package.json +1 -0
  9. fastplotpy/axes_validation.py +102 -0
  10. fastplotpy/camera3d.py +104 -0
  11. fastplotpy/color_scale.py +88 -0
  12. fastplotpy/defaults/area-fill.json +5 -0
  13. fastplotpy/defaults/bar.json +22 -0
  14. fastplotpy/defaults/camera3d.json +22 -0
  15. fastplotpy/defaults/cartesian-references.json +10 -0
  16. fastplotpy/defaults/control.json +3 -0
  17. fastplotpy/defaults/crosshair.json +19 -0
  18. fastplotpy/defaults/error-bars.json +7 -0
  19. fastplotpy/defaults/heatmap.json +70 -0
  20. fastplotpy/defaults/interaction.json +3 -0
  21. fastplotpy/defaults/layout.json +32 -0
  22. fastplotpy/defaults/legend.json +24 -0
  23. fastplotpy/defaults/line-axes.json +28 -0
  24. fastplotpy/defaults/line3d.json +13 -0
  25. fastplotpy/defaults/markers.json +6 -0
  26. fastplotpy/defaults/mesh3d.json +13 -0
  27. fastplotpy/defaults/pan.json +7 -0
  28. fastplotpy/defaults/pie.json +27 -0
  29. fastplotpy/defaults/pie3d.json +7 -0
  30. fastplotpy/defaults/point-labels.json +13 -0
  31. fastplotpy/defaults/pointClick.json +6 -0
  32. fastplotpy/defaults/pointSelection.json +13 -0
  33. fastplotpy/defaults/polar.json +71 -0
  34. fastplotpy/defaults/polarRotate.json +5 -0
  35. fastplotpy/defaults/scatter3d.json +39 -0
  36. fastplotpy/defaults/scene3d.json +61 -0
  37. fastplotpy/defaults/surface.json +35 -0
  38. fastplotpy/defaults/tooltip.json +18 -0
  39. fastplotpy/defaults/trace-colors.json +10 -0
  40. fastplotpy/defaults/trace-options.json +24 -0
  41. fastplotpy/defaults/wonderplot.json +58 -0
  42. fastplotpy/defaults/zoom.json +12 -0
  43. fastplotpy/defaults.py +15 -0
  44. fastplotpy/error_bars.py +118 -0
  45. fastplotpy/exports.py +153 -0
  46. fastplotpy/families2d.py +896 -0
  47. fastplotpy/heatmap_labels.py +146 -0
  48. fastplotpy/interactions.py +243 -0
  49. fastplotpy/interactive.py +1922 -0
  50. fastplotpy/js_serialize.py +47 -0
  51. fastplotpy/lighting3d.py +113 -0
  52. fastplotpy/line3d_lod.py +138 -0
  53. fastplotpy/lod3d.py +105 -0
  54. fastplotpy/mesh3d_lod.py +107 -0
  55. fastplotpy/native.py +163 -0
  56. fastplotpy/overlays.py +561 -0
  57. fastplotpy/point_labels.py +86 -0
  58. fastplotpy/polar.py +445 -0
  59. fastplotpy/polygon_clip3d.py +148 -0
  60. fastplotpy/references.py +72 -0
  61. fastplotpy/rendering.py +65 -0
  62. fastplotpy/rust_scenes.py +314 -0
  63. fastplotpy/scene.py +1185 -0
  64. fastplotpy/scene3d.py +1215 -0
  65. fastplotpy/scene3d_accessibility.py +183 -0
  66. fastplotpy/scene3d_collection.py +158 -0
  67. fastplotpy/subplots.py +115 -0
  68. fastplotpy/surface_contours.py +122 -0
  69. fastplotpy/surface_lod.py +109 -0
  70. fastplotpy/svg3d.py +235 -0
  71. fastplotpy/trendline.py +236 -0
  72. fastplotpy/triangle_wireframe.py +51 -0
  73. fastplotpy/types.py +3027 -0
  74. fastplotpy-0.3.0a1.dist-info/METADATA +86 -0
  75. fastplotpy-0.3.0a1.dist-info/RECORD +78 -0
  76. fastplotpy-0.3.0a1.dist-info/WHEEL +5 -0
  77. fastplotpy-0.3.0a1.dist-info/licenses/LICENSE +21 -0
  78. fastplotpy-0.3.0a1.dist-info/top_level.txt +1 -0
fastplotpy/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # FastPlotPy
2
+
3
+ FastPlotPy is the Python port of FastPlotJs for renderer-neutral scene generation and browser/Jupyter charts. After its first PyPI publication, install with:
4
+
5
+ ```sh
6
+ python -m pip install fastplotpy
7
+ ```
8
+
9
+ In Python or Jupyter:
10
+
11
+ ```python
12
+ from fastplotpy import createChart
13
+
14
+ chart = createChart({
15
+ "type": "line",
16
+ "width": 800,
17
+ "height": 400,
18
+ "engine": "auto",
19
+ "data": [{"x": 0, "y": 12}, {"x": 1, "y": 18}],
20
+ "axes": {"show": True},
21
+ })
22
+ chart # Jupyter displays the interactive browser view.
23
+ ```
24
+
25
+ The local chart view uses the pinned FastPlotJs browser frontend for Canvas,
26
+ pointer, and WebGL behavior. Its loopback bridge binds to `127.0.0.1` for the
27
+ chart session. Python owns scene and state APIs; source frontend callbacks can
28
+ invoke Python formatters. Browser WebAssembly is separate from the optional
29
+ Python-host Rust core and is not initialized by `initWasmPlotEngine()` in CPython.
30
+ The source-named `hasNodePlotEngine()` and `initNodePlotEngine()` are Python
31
+ compatibility aliases for `hasRustPlotEngine()` and `initRustPlotEngine()`;
32
+ they do not start or require Node.js. `getRustPlotEngineStatus()` reports host
33
+ native capabilities. `getWasmPlotEngineStatus()` reports CPython availability,
34
+ not the state of the separate browser frontend.
35
+
36
+ Without a browser, `plot()` produces a renderer-neutral scene:
37
+
38
+ ```python
39
+ from fastplotpy import plot
40
+
41
+ scene = plot({
42
+ "type": "line",
43
+ "width": 800,
44
+ "height": 400,
45
+ "engine": "ts", # Source spelling selects the Python fallback geometry.
46
+ "data": [{"x": 0, "y": 12}, {"x": 1, "y": 18}],
47
+ })
48
+ ```
49
+
50
+ Current Python geometry covers all eleven source chart families, including
51
+ source-documented 3D LOD, encodings, lighting, accessibility, and multiple
52
+ subplots. No chart calculation invokes Node.js at package runtime. Strict
53
+ `engine="rust"` uses the optional pinned Rust core
54
+ for supported 2D families and fails explicitly when unavailable. Pie3D reuses
55
+ `pie` datum and presentation options, accepts `pie3d.extrusionDepth` in
56
+ `(0, 1]`, and uses the shared `scene3d.camera`. The native 3D PNG path has
57
+ Windows validation only. `renderToPNG()` retains the source placeholder behavior.
58
+
59
+ The source project is [FastPlotJs](https://fastplotjs.com). The first Python
60
+ alpha candidate is `0.3.0a1`; check PyPI separately for publication status.
61
+ Python 3.11 or newer is required. Its Windows wheel includes Python code,
62
+ the pinned frontend,
63
+ the built Rust ABI library, and the MIT License. The source
64
+ distribution includes the pinned Rust sources and lockfile for optional
65
+ native builds. Bundled font attribution is in the packaged
66
+ `assets/native/THIRD_PARTY_NOTICES.md` file.
67
+
68
+ ## Canvas quality
69
+
70
+ The pinned browser frontend accepts `canvas: { pixelRatio: "auto", resolutionScale: 2 }` through `createChart`. Omitted ratios default to `1`; logical sizes, text, and pointer coordinates remain unchanged while the backing bitmap scales. Experimental Pie3D also accepts `pie3d: { curveTolerance: 0.1 }` (default `1` logical pixel; smaller means more faces, within `scene3d.maxPoints`). Higher settings use more memory and rendering work. The source browser comparison remains in FastPlotJs. The Python source distribution includes the local Python-backed gallery under `examples/gallery/`; the installed wheel bundles the interactive frontend but does not install the standalone gallery server.
fastplotpy/__init__.py ADDED
@@ -0,0 +1,33 @@
1
+ """Public fastPlotPy API, retaining fastPlotJs names where Python permits."""
2
+
3
+ from .defaults import DEFAULT_TRACE_COLORS, get_defaults
4
+ from .scene import plot
5
+ from .interactive import Chart, createChart
6
+ from .exports import renderToPNG, renderScene3dToPNG, Scene3dNodePngExportError
7
+ from .svg3d import renderScene3dToSVG
8
+ from .rendering import (renderToCanvas, getLastLineAxisLayoutDiagnostics,
9
+ Scene3dWebgl2CapabilityError)
10
+ from .native import (getLastRustInitError, getLastWasmInitError, getRustPlotEngineStatus,
11
+ getWasmPlotEngineStatus, hasNodePlotEngine, hasRustPlotEngine,
12
+ hasWasmPlotEngine, initNodePlotEngine, initRustPlotEngine,
13
+ initWasmPlotEngine)
14
+ from .interactions import (applyAxisViewportState, mergeAxisViewportState,
15
+ resolveAxisBoxZoomInteractionPatch, resolveAxisPanInteractionPatch,
16
+ resolveAxisZoomInteractionPatch, resolveInteractionBindingsFromPlotOptions,
17
+ resolveSharedAxisInteractionPatch, viewportStateToAxesOptions)
18
+ from . import types as _public_types
19
+ from .types import *
20
+
21
+ ChartInstance = Chart
22
+
23
+ __all__ = ["plot", "createChart", "Chart", "renderToCanvas", "renderToPNG", "renderScene3dToSVG",
24
+ "renderScene3dToPNG", "Scene3dNodePngExportError", "DEFAULT_TRACE_COLORS",
25
+ "getLastLineAxisLayoutDiagnostics", "Scene3dWebgl2CapabilityError",
26
+ "get_defaults", "hasNodePlotEngine", "initNodePlotEngine", "hasRustPlotEngine",
27
+ "initRustPlotEngine", "getLastRustInitError", "getRustPlotEngineStatus",
28
+ "hasWasmPlotEngine", "initWasmPlotEngine", "getLastWasmInitError",
29
+ "getWasmPlotEngineStatus", "applyAxisViewportState", "mergeAxisViewportState",
30
+ "resolveInteractionBindingsFromPlotOptions", "resolveSharedAxisInteractionPatch",
31
+ "viewportStateToAxesOptions", "resolveAxisZoomInteractionPatch",
32
+ "resolveAxisBoxZoomInteractionPatch", "resolveAxisPanInteractionPatch",
33
+ "ChartInstance", *_public_types.__all__]
@@ -0,0 +1 @@
1
+ (function(){let e={show:!1,size:3,shape:`circle`,minSize:1},t={connectGaps:!1,lineWidth:1.5,opacity:1,interpolation:`linear`,smoothInterpolationSamplesPerSegment:12,pattern:`solid`,patternSegments:{solid:[],dashed:[8,4],dotted:[1,4],"dash-dot":[8,4,1,4]},trendline:{show:!1,method:`linear`,degree:2,samples:120,minDegree:1,maxDegree:6,minSamples:2,maxSamples:512}},n=[`#2563eb`,`#dc2626`,`#16a34a`,`#d97706`,`#7c3aed`,`#0891b2`,`#db2777`,`#4b5563`],r={renderer:`canvas`,webgl2BatchVertexCount:65532,webgl2MaxBufferBytes:8388608,nodePngMaxPixels:16777216,projection:`perspective`,eye:[1.8,1.4,1.8],target:[0,0,0],up:[0,1,0],fieldOfViewDegrees:45,orthographicScale:2.5,near:.1,far:100,lightingShow:!1,lightingDirection:[1,1,1],lightingAmbient:.35,lightingDiffuse:.65,lightingSpecular:0,lightingShininess:32,lightingTwoSided:!0,axisPadding:.08,showAxes:!0,showGrid:!0,gridSteps:4,axisColor:`#52606d`,gridColor:`#d9e2ec`,axisLineWidth:1.5,gridLineWidth:1,axisLabelFont:`600 12px system-ui, sans-serif`,axisLabelOffset:8,axisTickCount:5,axisTickMinCount:2,axisTickMaxCount:12,axisTickWorldLength:.03,axisTickLabelFont:`11px system-ui, sans-serif`,axisTickLabelOffset:7,axisTickLabelMinGap:4,axisTickLabelGlyphWidth:6.5,axisTickLabelMinWidth:7,axisTickLabelLineHeight:12,axisTickLabelBoundsInset:1,axisTickMaxDecimals:12,axisTickAutoMaxDecimals:10,axisTickScientificLowerMagnitude:1e-4,axisTickScientificUpperMagnitude:1e7,axisTickScientificDecimals:3,axisTickZeroToleranceFloor:1e-15,axisTickStepFloor:1e-12,axisTickLineWidthScale:.75,axisTickMinLineWidth:1,maxPoints:1e5,accessibilityMaxRows:50,accessibilityIncludeTable:!0,accessibilityScatter3dLabel:`Scatter3D chart`,accessibilityLine3dLabel:`Line3D chart`,accessibilitySurfaceLabel:`Surface chart`,accessibilityMesh3dLabel:`Mesh3D chart`,accessibilityCollectionLabel:`3D chart data summary`,staticFallbackDescription:`Static three-dimensional chart fallback generated from the renderer-neutral scene.`,staticFallbackDecimals:6},i={mode:`grouped`,orientation:`vertical`,barWidthRatio:.72,minBarWidth:1,borderWidth:0,borderColor:`rgba(15, 23, 42, 0.35)`,cornerRadius:0,valueLabels:{show:!1,color:`#0f172a`,font:`11px Inter, system-ui, sans-serif`,position:`center`,offset:4,decimals:0,prefix:``,suffix:``,minBarWidth:18,minBarHeight:12,formatter:null}};function a(e){return e?.scale??`linear`}function o(e){return Array.isArray(e?.categories)?e.categories.filter(e=>typeof e==`string`&&e.length>0):[]}function s(e,t){let n=o(t);if(n.length===0)return null;let r=n.indexOf(e);if(r<0)throw Error(`Unknown categorical axis value: ${e}`);return r+1}function c(e,t){if(a(t)===`datetime`){if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid datetime numeric value`);return e}if(e instanceof Date){let t=e.getTime();if(!Number.isFinite(t))throw Error(`Invalid Date value`);return t}let t=Date.parse(e);if(!Number.isFinite(t))throw Error(`Invalid datetime string value: ${e}`);return t}if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid numeric value`);return e}if(typeof e==`string`){let n=s(e,t);if(n!==null)return n}if(e instanceof Date){let t=e.getTime();if(!Number.isFinite(t))throw Error(`Invalid Date value`);return t}let n=Number(e);if(!Number.isFinite(n))throw Error(`Invalid numeric string value: ${e}`);return n}function l(e,t){if(t===`logarithmic`){if(e<=0)throw Error(`Logarithmic scale requires values > 0`);return Math.log10(e)}return e}function u(e,t,n){if(a(t)!==`datetime`)return d(n(e,t?.decimals),t);let r=new Date(e),i=t?.dateTime?.timeZone===`browser`?void 0:t?.dateTime?.timeZone===`utc`?`UTC`:t?.dateTime?.timeZone,o=t?.dateTime?.format??{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};return d(new Intl.DateTimeFormat(void 0,{...o,timeZone:i}).format(r),t)}function d(e,t){return`${t?.labelPrefix??``}${e}${t?.labelSuffix??``}`}let f={show:!0,x:!0,y:!0,lineWidth:1,capSize:6};function p(e){return e&&typeof e==`object`?e:void 0}function m(e,t){return typeof e==`boolean`?e:e&&typeof e==`object`?e.show??f.show:t}function h(e,t,n){return n?.[e]??t?.[e]??f[e]}function g(e,t,n){if(e===void 0)return t;if(!Number.isFinite(e)||e<0)throw Error(`${n} must be a finite number >= 0`);return e}function _(e,t,n){let r=p(e),i=p(t),a=m(t,m(e,!1)),o=g(r?.lineWidth,f.lineWidth,`errorBars.lineWidth`),s=g(r?.capSize,f.capSize,`errorBars.capSize`);return{show:a,x:h(`x`,r,i),y:h(`y`,r,i),style:{color:typeof i?.color==`string`&&i.color.trim().length>0?i.color:typeof r?.color==`string`&&r.color.trim().length>0?r.color:n,lineWidth:g(i?.lineWidth,o,`trace.errorBars.lineWidth`),capSize:g(i?.capSize,s,`trace.errorBars.capSize`)}}}function v(e){if((e.errorBars!==void 0||e.traces?.some(e=>e.errorBars!==void 0))&&e.type!==`line`&&e.type!==`wonderplot`&&e.type!==`bar`)throw Error(`errorBars are supported only for 'line', 'bar', and 'wonderplot' charts`)}function y(e,t){if(e==null)return null;if(typeof e==`number`){if(!Number.isFinite(e)||e<0)throw Error(`${t} must be a finite number >= 0`);return{minus:e,plus:e}}if(!e||typeof e!=`object`||Array.isArray(e)||!Number.isFinite(e.minus)||e.minus<0||!Number.isFinite(e.plus)||e.plus<0)throw Error(`${t} must contain finite minus/plus values >= 0`);return{minus:e.minus,plus:e.plus}}function b(e,t,n,r){let i=t===`x`?e.x:e.y,s=y(t===`x`?e.xError:e.yError,`data[${r}].${t}Error`);if(i===null||!s)return null;if(o(n).length>0)throw Error(`${t}Error is not supported on categorical axes`);let u=c(i,n),d={minus:u-s.minus,plus:u+s.plus};return l(d.minus,a(n)),l(d.plus,a(n)),d}function x(e,t,n,r,i,a,o){if(!(!n.show||e.x===null||e.y===null)){if(n.x&&e.xError!==void 0&&e.xError!==null){let n=b(e,`x`,r,t);n&&a.push(n.minus,n.plus)}if(n.y&&e.yError!==void 0&&e.yError!==null){let n=b(e,`y`,i,t);n&&o.push(n.minus,n.plus)}}}function S(e,t,n,r,i=!1){let o=l(e,a(n)),s=Math.max(t.max-t.min,2**-52),c=(o-t.min)/s*r;return i?r-c:c}function C(e,t){return e>=0&&e<=t}function w(e,t,n,r,i,a,o,s,l){if(!t.show||!t.x&&!t.y||t.style.lineWidth===0)return;let u=[];return e.data.forEach((e,d)=>{if(e.x===null||e.y===null)return;let f=l?.get(d);if(l&&!f)return;let p=f?.x??S(c(e.x,n),i,n,o),m=f?.y??S(c(e.y,r),a,r,s,!0);if(!(!C(p,o)||!C(m,s))){if(t.x&&e.xError!==void 0&&e.xError!==null){let t=b(e,`x`,n,d);if(t){let e=S(t.minus,i,n,o),r=S(t.plus,i,n,o);r<0||e>o||u.push({axis:`x`,sourceIndex:d,x1:Math.max(0,e),y1:m,x2:Math.min(o,r),y2:m,startCap:C(e,o),endCap:C(r,o)})}}if(t.y&&e.yError!==void 0&&e.yError!==null){let t=b(e,`y`,r,d);if(t){let e=S(t.minus,a,r,s,!0),n=S(t.plus,a,r,s,!0),i=Math.min(e,n),o=Math.max(e,n);o<0||i>s||u.push({axis:`y`,sourceIndex:d,x1:p,y1:Math.max(0,i),x2:p,y2:Math.min(s,o),startCap:C(i,s),endCap:C(o,s)})}}}}),u.length>0?u:void 0}let T={margin:{l:0,r:0,t:0,b:0},axisPaddingPercent:{start:0,end:0},axisSide:{x:`bottom`,y:`left`},subplots:{rowGap:16,columnGap:20},decorations:{titleFont:`600 18px system-ui, sans-serif`,subtitleFont:`13px system-ui, sans-serif`,titleColor:`#0f172a`,subtitleColor:`#475569`,plotAreaBackgroundColor:null,topPadding:8,titleLineHeight:22,subtitleLineHeight:18,subtitleGap:4,bottomGap:8}};function E(e,t){return e===void 0||!Number.isFinite(e)?t:Math.max(0,e)}function D(e){if(typeof e==`number`){let t=E(e,T.axisPaddingPercent.start);return{start:t,end:t}}return{start:E(e?.start,T.axisPaddingPercent.start),end:E(e?.end,T.axisPaddingPercent.end)}}function O(e,t,n){let r=Math.max(t-e,2**-52);return{min:e-r*n.start/100,max:t+r*n.end/100}}function k(e){return e?.range!==void 0}function A(e,t){if(t?.range){let e=c(t.range.min,t),n=c(t.range.max,t),r=a(t),i=l(e,r),o=l(n,r);if(!(i<o))throw Error(`Axis range requires min < max`);return{min:i,max:o}}let n=a(t),r=1/0,i=-1/0,o=!1;for(let t of e){o=!0;let e=l(t,n);e<r&&(r=e),e>i&&(i=e)}if(!o)return null;let s=D(t?.padding);return O(r,i,s)}let j=null,M=null,N=null,P=null,ee=null,F=null,I=null,L=!1;function te(){return typeof globalThis.process?.versions?.node==`string`}function R(){if(!(!te()||j||L)){L=!0;try{let e=globalThis.process,t=(e?.getBuiltinModule?.(`node:module`)??e?.getBuiltinModule?.(`module`))?.createRequire;if(typeof t!=`function`)return;let n=t(self.location.href)(`../native/fastplot_node.cjs`);typeof n.build_line_scene_node==`function`?j=n.build_line_scene_node:typeof n.buildLineSceneNode==`function`&&(j=n.buildLineSceneNode),typeof n.build_line_scene_with_domain_node==`function`?M=n.build_line_scene_with_domain_node:typeof n.buildLineSceneWithDomainNode==`function`&&(M=n.buildLineSceneWithDomainNode),typeof n.build_line_axis_layout_node==`function`?n.build_line_axis_layout_node:typeof n.buildLineAxisLayoutNode==`function`&&n.buildLineAxisLayoutNode,typeof n.build_bar_scene_node==`function`?P=n.build_bar_scene_node:typeof n.buildBarSceneNode==`function`&&(P=n.buildBarSceneNode),typeof n.build_heatmap_scene_node==`function`?ee=n.build_heatmap_scene_node:typeof n.buildHeatmapSceneNode==`function`&&(ee=n.buildHeatmapSceneNode),typeof n.build_wonderplot_scene_node==`function`?F=n.build_wonderplot_scene_node:typeof n.buildWonderplotSceneNode==`function`&&(F=n.buildWonderplotSceneNode),typeof n.build_polar_scene_node==`function`?I=n.build_polar_scene_node:typeof n.buildPolarSceneNode==`function`&&(I=n.buildPolarSceneNode),typeof n.build_subplot_layout_node==`function`?N=n.build_subplot_layout_node:typeof n.buildSubplotLayoutNode==`function`&&(N=n.buildSubplotLayoutNode),typeof n.build_subplot_axis_label_visibility_node==`function`?n.build_subplot_axis_label_visibility_node:typeof n.buildSubplotAxisLabelVisibilityNode==`function`&&n.buildSubplotAxisLabelVisibilityNode,typeof n.render_scene3d_svg_to_png_node==`function`?n.render_scene3d_svg_to_png_node:typeof n.renderScene3dSvgToPngNode==`function`?n.renderScene3dSvgToPngNode:typeof n.renderScene3DSvgToPngNode==`function`&&n.renderScene3DSvgToPngNode}catch{}}}function z(e){return R(),N?JSON.parse(N(JSON.stringify(e))):null}function ne(e){return R(),P?JSON.parse(P(JSON.stringify(e))):null}function B(e){return R(),ee?JSON.parse(ee(JSON.stringify(e))):null}function V(e){return R(),F?JSON.parse(F(JSON.stringify(e))):null}function re(e){return R(),I?JSON.parse(I(JSON.stringify(e))):null}function ie(e,t,n,r,i,a,o,s,c){return R(),M?JSON.parse(M(e,t,n,r,i,a,o,s,c)):null}function ae(e,t,n,r,i,a,o,s,c){return R(),j?JSON.parse(j(e,t,n,r,i,a,o,s,c)):null}function oe(e){return null}function se(e){return null}function ce(e){return null}function le(e){return null}function ue(e){return null}function de(e,t,n,r,i,a,o,s,c){return null}function fe(e,t,n,r,i,a,o,s,c){return null}function pe(e){return e.traces&&e.traces.length>0?e.traces:e.data?[{data:e.data}]:[]}function me(e){return Number.isInteger(e)&&e>0}function he(e,t){if(Array.isArray(e)){if(e.length===0)throw Error(`Subplot track arrays must not be empty`);return e.map(e=>({weight:Number.isFinite(e.weight)&&e.weight>0?e.weight:1}))}let n=e??t;if(!me(n))throw Error(`Subplot layout rows and columns must be positive integers`);return Array.from({length:n},()=>({weight:1}))}function ge(e,t){return Number.isFinite(e)?Math.max(0,e):t}function _e(e,t,n,r){let i=r*Math.max(0,n.length-1),a=Math.max(1,t-e-i),o=n.reduce((e,t)=>e+t.weight,0),s=[],c=e;for(let e=0;e<n.length;e+=1){let i=e===n.length-1?t-c:a*(n[e].weight/o);s.push({start:c,end:Math.max(c+1,c+i)}),c+=i+r}return s}function ve(e,t,n){return e[t+n-1].end}function ye(e){if(Array.isArray(e))return e.map(e=>({weight:e.weight}));if(typeof e==`number`)return Array.from({length:e},()=>({weight:1}))}function be(e,t){return{bounds:t??{left:0,top:0,right:e.width,bottom:e.height},rows:ye(e.subplots?.layout?.rows),columns:ye(e.subplots?.layout?.columns),row_gap:Number.isFinite(e.subplots?.layout?.rowGap)?Math.max(0,e.subplots?.layout?.rowGap):T.subplots.rowGap,column_gap:Number.isFinite(e.subplots?.layout?.columnGap)?Math.max(0,e.subplots?.layout?.columnGap):T.subplots.columnGap,items:Object.entries(e.subplots?.items??{}).map(([e,t])=>({id:e,row:t.row,column:t.column,row_span:t.rowSpan,column_span:t.columnSpan,x_axis_id:t.xAxis,y_axis_id:t.yAxis}))}}function xe(e){return Array.isArray(e)?e.map(e=>{let t=e;return{id:t.id,row:t.row,column:t.column,rowSpan:t.row_span??t.rowSpan??1,columnSpan:t.column_span??t.columnSpan??1,xAxisId:t.x_axis_id??t.xAxisId??`x`,yAxisId:t.y_axis_id??t.yAxisId??`y`,bounds:t.bounds}}):null}function Se(e,t){let n=be(e,t);return xe(z(n))||xe(oe(n))||null}function Ce(e,t){let n=t??{left:0,top:0,right:e.width,bottom:e.height},r=e.subplots?.items;if(!r||Object.keys(r).length===0)return[{id:`main`,row:0,column:0,rowSpan:1,columnSpan:1,xAxisId:`x`,yAxisId:`y`,bounds:n}];let i=Object.values(r),a=Math.max(...i.map(e=>e.row+(e.rowSpan??1))),o=Math.max(...i.map(e=>e.column+(e.columnSpan??1))),s=he(e.subplots?.layout?.rows,a),c=he(e.subplots?.layout?.columns,o),l=ge(e.subplots?.layout?.rowGap,T.subplots.rowGap),u=ge(e.subplots?.layout?.columnGap,T.subplots.columnGap),d=_e(n.top,n.bottom,s,l),f=_e(n.left,n.right,c,u);return Object.entries(r).map(([e,t])=>{let n=t.rowSpan??1,r=t.columnSpan??1;if(!me(t.row)&&t.row!==0||!me(t.column)&&t.column!==0)throw Error(`Invalid position for subplot '${e}'`);if(!me(n)||!me(r))throw Error(`Invalid span for subplot '${e}'`);if(t.row<0||t.column<0||t.row+n>s.length||t.column+r>c.length)throw Error(`Subplot '${e}' is outside the configured layout`);return{id:e,row:t.row,column:t.column,rowSpan:n,columnSpan:r,xAxisId:t.xAxis??`x`,yAxisId:t.yAxis??`y`,bounds:{left:f[t.column].start,top:d[t.row].start,right:ve(f,t.column,r),bottom:ve(d,t.row,n)}}})}function we(e,t){return Se(e,t)??Ce(e,t)}function Te(e){let t=pe(e),n=we(e),r=new Map(n.map(e=>[e.id,e])),i=r.has(`main`)?`main`:n.length===1?n[0].id:`main`;return t.map(e=>{let t=e.subplot??i,n=r.get(t);if(!n)throw Error(`Unknown subplot id '${t}' for trace`);return{trace:e,subplotId:t,xAxisId:e.xAxis??n.xAxisId,yAxisId:e.yAxis??n.yAxisId}})}function Ee(e){let t=new Map,n=e.axes?.xAxes??{};for(let e of Object.keys(n))t.set(e,n[e]);return t.has(`x`)||t.set(`x`,{}),t}function De(e){let t=new Map,n=e.axes?.yAxes??{};for(let e of Object.keys(n))t.set(e,n[e]);return t.has(`y`)||t.set(`y`,{}),t}function Oe(e){let t=Ee(e),n=De(e);return Te(e).map(({trace:e,subplotId:r,xAxisId:i,yAxisId:a})=>{if(!t.has(i))throw Error(`Unknown x-axis id '${i}' for trace`);if(!n.has(a))throw Error(`Unknown y-axis id '${a}' for trace`);return{trace:e,subplotId:r,xAxisId:i,yAxisId:a}})}function ke(e){if(!(e.axes?.show??!1))return;let t=Ee(e),n=De(e),r=Oe(e),i=new Map,a=new Map;for(let e of r){let r=t.get(e.xAxisId)??{};if(r.show!==!1){let t=r.side??`bottom`,n=`${e.subplotId}:${t}`,a=i.get(n)??{side:t,axisIds:new Set};a.axisIds.add(e.xAxisId),i.set(n,a)}let o=n.get(e.yAxisId)??{};if(o.show!==!1){let t=o.side??`left`,n=`${e.subplotId}:${t}`,r=a.get(n)??{side:t,axisIds:new Set};r.axisIds.add(e.yAxisId),a.set(n,r)}}for(let{side:e,axisIds:t}of i.values())if(t.size>1)throw Error(`Multiple visible x-axes on side '${e}' are not supported`);for(let{side:e,axisIds:t}of a.values())if(t.size>1)throw Error(`Multiple visible y-axes on side '${e}' are not supported`)}function Ae(e,t,n){return`${e}\u0000${t}\u0000${n}`}function je(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function Me(e,t){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(1,Math.max(.05,e))}function Ne(e,t){return typeof t==`string`&&t.trim().length>0?t:e}function Pe(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,Math.round(e)))}function Fe(e,t){if(e===void 0)return t;if(e===`center`||e===`inside-end`||e===`outside-end`)return e;throw Error(`bar.valueLabels.position must be 'center', 'inside-end', or 'outside-end'`)}function Ie(e){return typeof e==`object`&&e?e:void 0}function Le(e){return Me(e?.barWidthRatio,i.barWidthRatio)}function Re(e){if(e?.mode===void 0)return i.mode;if(e.mode===`stacked`||e.mode===`grouped`||e.mode===`normalized`)return e.mode;throw Error(`bar.mode must be 'grouped', 'stacked', or 'normalized'`)}function ze(e){return e===`stacked`||e===`normalized`}function Be(e,t,n){return e>0?t>0?e/t*100:0:e<0&&n<0?e/Math.abs(n)*100:0}function Ve(e){return e?.orientation===`horizontal`||e?.orientation===`vertical`?e.orientation:i.orientation}function He(e){let t=Re(e.bar),n=Ve(e.bar),r=n===`horizontal`?`x`:`y`,i=n===`horizontal`?`y`:`x`;Oe(e).forEach(a=>{if(a.trace.visible===!1)return;let o=_(e.errorBars,a.trace.errorBars,``);o.show&&a.trace.data.forEach(e=>{let a=r===`x`?e.xError:e.yError,s=i===`x`?e.xError:e.yError;if(o[i]&&s!=null)throw Error(`${i}Error is not supported on the slot axis of ${n} bar charts`);if(o[r]&&a!=null&&t!==`grouped`)throw Error(`errorBars are supported only for grouped bar charts`)})})}function Ue(){return i.minBarWidth}function We(e,t){let n=je(e?.borderWidth,i.borderWidth);return je(t?.borderWidth,n)}function Ge(e,t){return Ne(Ne(i.borderColor,e?.borderColor),t?.borderColor)}function Ke(e,t){let n=je(e?.cornerRadius,i.cornerRadius);return je(t?.cornerRadius,n)}function qe(e,t){if(t===void 0)return e;let n=Ie(t);return{show:typeof t==`boolean`?t:n?n.show??!0:e.show,color:Ne(e.color,n?.color),font:Ne(e.font,n?.font),position:Fe(n?.position,e.position),offset:je(n?.offset,e.offset),decimals:Pe(n?.decimals,e.decimals,0,12),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,minBarWidth:je(n?.minBarWidth,e.minBarWidth),minBarHeight:je(n?.minBarHeight,e.minBarHeight)}}function Je(e,t){return qe(qe({...i.valueLabels},e),t)}function Ye(e,t,n,r,i){let o=new Map;for(let s of e){let e=t.get(s.xAxisId)??{},u=n.get(s.yAxisId)??{},d=r===`horizontal`?e:u,f=a(d);if(i!==`grouped`&&f!==`linear`)throw Error(`Bar mode '${i}' requires a linear value axis`);let p=[];for(let t of s.trace.data){if(t.x===null||t.y===null)continue;let n=t.base!==void 0&&t.base!==null;if(i!==`grouped`&&n)throw Error(`Bar point base is only supported in grouped mode`);if(f!==`linear`&&!n)throw Error(`Grouped bars on a ${f} value axis require an explicit point base`);let a=c(t.x,e),o=c(t.y,u),s=n?c(t.base,d):0;f===`logarithmic`&&(l(r===`horizontal`?a:o,f),l(s,f)),p.push({x:a,y:o,base:s})}o.set(s,p)}return o}function Xe(e,t){if(k(t)||e.length===0)return 0;let n=a(t),r=[...new Set(e.map(e=>l(e,n)))].sort((e,t)=>e-t);if(r.length<=1)return .5;let i=1/0;for(let e=1;e<r.length;e+=1){let t=r[e]-r[e-1];t>0&&t<i&&(i=t)}return Number.isFinite(i)?i/2:.5}function Ze(e){let t=Ee(e),n=De(e),r=Oe(e).filter(e=>e.trace.visible!==!1),i=Re(e.bar),a=Ve(e.bar),s=Ye(r,t,n,a,i),c=new Map,l=new Map,u=new Map;for(let o of r){for(let e of s.get(o)??[]){let t=a===`horizontal`?e.y:e.x,n=a===`horizontal`?e.x:e.y,r=a===`horizontal`?o.yAxisId:o.xAxisId,s=a===`horizontal`?o.xAxisId:o.yAxisId,d=a===`horizontal`?l:c,f=a===`horizontal`?c:l;if(d.has(r)||d.set(r,[]),f.has(s)||f.set(s,[]),d.get(r)?.push(t),i===`normalized`)f.get(s)?.push(0),n>0&&f.get(s)?.push(100),n<0&&f.get(s)?.push(-100);else if(i===`stacked`){f.get(s)?.push(0);let e=`${Ae(o.subplotId,o.xAxisId,o.yAxisId)}\u0000${t}`,r=u.get(e)??{positive:0,negative:0};n>=0?(r.positive+=n,f.get(s)?.push(r.positive)):(r.negative+=n,f.get(s)?.push(r.negative)),u.set(e,r)}else f.get(s)?.push(e.base,n)}if(i===`grouped`){let r=_(e.errorBars,o.trace.errorBars,``),i={...r,x:a===`horizontal`&&r.x,y:a===`vertical`&&r.y},s=t.get(o.xAxisId)??{},u=n.get(o.yAxisId)??{},d=c.get(o.xAxisId)??[],f=l.get(o.yAxisId)??[];c.set(o.xAxisId,d),l.set(o.yAxisId,f),o.trace.data.forEach((e,t)=>{x(e,t,i,s,u,d,f)})}}let d=new Map,f=new Map;for(let[e,n]of t.entries()){let t=c.get(e)??[],r=o(n);if(a===`vertical`&&r.length>0)for(let e=0;e<r.length;e+=1)t.push(e+1);let i=A(t,n);if(!i)continue;let s=a===`vertical`?Xe(t,n):0;d.set(e,{min:i.min-s,max:i.max+s})}for(let[e,t]of n.entries()){let n=l.get(e)??[],r=o(t);if(a===`horizontal`&&r.length>0)for(let e=0;e<r.length;e+=1)n.push(e+1);let i=A(n,t);if(!i)continue;let s=a===`horizontal`?Xe(n,t):0;f.set(e,{min:i.min-s,max:i.max+s})}return{x:d,y:f}}function Qe(e){let t=new Map;return e.forEach((e,n)=>{if(e.trace.visible===!1)return;let r=Ae(e.subplotId,e.xAxisId,e.yAxisId),i=t.get(r)??[];i.push(n),t.set(r,i)}),t}function $e(e,t,n,r){let i=Math.max(n.max-n.min,2**-52),s=a(t),c=o(t);if(s===`linear`&&c.length>1)return 1/i*r;let u=[...new Set(e.map(e=>l(e,s)))].sort((e,t)=>e-t);if(u.length<=1)return r;let d=1/0;for(let e=1;e<u.length;e+=1){let t=u[e]-u[e-1];t>0&&t<d&&(d=t)}return Number.isFinite(d)?d/i*r:r}function et(e){let n=e??t.pattern;if(n!==`solid`&&n!==`dashed`&&n!==`dotted`&&n!==`dash-dot`)throw Error(`lineStyle.pattern must be 'solid', 'dashed', 'dotted', or 'dash-dot'`);return n}function tt(e,t,n=`reference`){if(t.axis!==`x`&&t.axis!==`y`)throw Error(`${n}.axis must be 'x' or 'y'`);let r=we(e),i=t.subplot===void 0?void 0:r.find(e=>e.id===t.subplot);if(t.subplot!==void 0&&!i)throw Error(`${n}.subplot references unknown subplot '${t.subplot}'`);let a=t.axis===`x`?Ee(e):De(e);if(t.axisId!==void 0&&!a.has(t.axisId))throw Error(`${n}.axisId references unknown ${t.axis}-axis '${t.axisId}'`);let o=Oe(e),s=(i?[i]:r).flatMap(e=>{let n=o.filter(t=>t.subplotId===e.id),r=t.axis===`x`?e.xAxisId:e.yAxisId,i=t.axisId??r,s=new Set(n.map(e=>t.axis===`x`?e.xAxisId:e.yAxisId));if(n.length===0&&s.add(r),!s.has(i))return[];let c=a.get(i);return c?[{subplotId:e.id,axisId:i,axis:c}]:[]});if(s.length===0){let e=t.axisId??(t.axis===`x`?i?.xAxisId??`x`:i?.yAxisId??`y`),r=i?`subplot '${i.id}'`:`any subplot`;throw Error(`${n}.axisId '${e}' is not used by ${r}`)}return s}function nt(e,t,n){if(e==null)throw Error(`${n} is required`);l(c(e,t),a(t))}function rt(e){if(e.references){if(e.type!==`line`&&e.type!==`bar`&&e.type!==`wonderplot`)throw Error(`references are supported only for 'line', 'bar', and 'wonderplot' charts`);if(e.references.lines!==void 0&&!Array.isArray(e.references.lines))throw Error(`references.lines must be an array`);if(e.references.bands!==void 0&&!Array.isArray(e.references.bands))throw Error(`references.bands must be an array`);(e.references.lines??[]).forEach((t,n)=>{let r=`references.lines[${n}]`,i=tt(e,t,r);for(let e of i)nt(t.value,e.axis,`${r}.value`);if(t.lineWidth!==void 0&&(!Number.isFinite(t.lineWidth)||t.lineWidth<0))throw Error(`${r}.lineWidth must be finite and >= 0`);et(t.pattern)}),(e.references.bands??[]).forEach((t,n)=>{let r=`references.bands[${n}]`,i=tt(e,t,r);for(let e of i)nt(t.from,e.axis,`${r}.from`),nt(t.to,e.axis,`${r}.to`)})}}function it(e){if(!(!e||typeof e!=`object`))return typeof e.formatter==`function`?e.formatter:void 0}function at(e,t){return it(t)??it(e)}function ot(e,t){if(e===null||e===``)return null;if(typeof e!=`string`)throw Error(`${t} must return a string or null`);return e}function st(e,t){let n=pe(t);return(t.type===`line`?it(t.pointLabels)!==void 0||n.some(e=>it(e.pointLabels)!==void 0):t.type===`bar`?it(t.bar?.valueLabels)!==void 0||n.some(e=>it(e.bar?.valueLabels)!==void 0):t.type===`heatmap`?it(t.heatmap?.cellLabels)!==void 0||n.some(e=>it(e.heatmap?.cellLabels)!==void 0):t.type===`wonderplot`&&(it(t.wonderplot?.markerLabels)!==void 0||n.some(e=>it(e.wonderplot?.markerLabels)!==void 0)))?{...e,primitives:e.primitives.map(e=>{let r=e.traceIndex??0,i=n[r];if(!i)return e;if(e.type===`line`&&e.linePointLabels?.length){let n=at(t.pointLabels,i.pointLabels);if(!n)return e;let a=e.linePointLabels.flatMap(e=>{let t=i.data[e.sourceIndex];if(!t||t.x===null||t.y===null)return[e];let a=ot(n({value:e.value,defaultLabel:e.text,x:t.x,y:t.y,traceIndex:r,sourceIndex:e.sourceIndex}),`pointLabels.formatter`);return a===null?[]:[{...e,text:a}]});return{...e,linePointLabels:a.length>0?a:void 0}}if(e.type===`bar`&&e.barValueLabels?.length){let n=at(t.bar?.valueLabels,i.bar?.valueLabels);if(!n)return e;let a=new Map(e.bars?.filter(e=>e.sourceIndex!==void 0).map(e=>[e.sourceIndex,e])??[]),o=e.barValueLabels.flatMap(e=>{let i=e.sourceIndex,o=i===void 0?void 0:a.get(i);if(i===void 0||!o)return[e];let s=ot(n({value:e.value,defaultLabel:e.text,baseline:o.baseline,...o.normalizedValue===void 0?{}:{normalizedValue:o.normalizedValue},orientation:t.bar?.orientation===`horizontal`?`horizontal`:`vertical`,mode:t.bar?.mode===`stacked`||t.bar?.mode===`normalized`?t.bar.mode:`grouped`,traceIndex:r,sourceIndex:i}),`bar.valueLabels.formatter`);return s===null?[]:[{...e,text:s}]});return{...e,barValueLabels:o.length>0?o:void 0}}if(e.type===`heatmap`&&e.heatmapCellLabels?.length){let n=at(t.heatmap?.cellLabels,i.heatmap?.cellLabels);if(!n)return e;let a=new Map(e.heatmapCells?.map(e=>[`${e.row}\u0000${e.column}`,e])??[]),o=e.heatmapCellLabels.flatMap(e=>{let t=a.get(`${e.row}\u0000${e.column}`),i=t?.sourceIndex;if(!t||i===void 0)return[e];let o=ot(n({value:e.value,defaultLabel:e.text,xValue:e.xValue,yValue:e.yValue,...t.xCategory===void 0?{}:{xCategory:t.xCategory},...t.yCategory===void 0?{}:{yCategory:t.yCategory},row:e.row,column:e.column,traceIndex:r,sourceIndex:i}),`heatmap.cellLabels.formatter`);return o===null?[]:[{...e,text:o,fullText:o,compactText:o===e.text?e.compactText:void 0}]});return{...e,heatmapCellLabels:o.length>0?o:void 0}}if(e.type===`wonderplot`&&e.wonderplotMarkerLabels?.length){let n=at(t.wonderplot?.markerLabels,i.wonderplot?.markerLabels);if(!n)return e;let a=e.wonderplotMarkerLabels.flatMap(e=>{let t=i.data[e.sourceIndex];if(!t||t.x===null||t.y===null)return[e];let a=ot(n({value:e.value,defaultLabel:e.text,x:t.x,y:t.y,traceIndex:r,sourceIndex:e.sourceIndex}),`wonderplot.markerLabels.formatter`);return a===null?[]:[{...e,text:a}]});return{...e,wonderplotMarkerLabels:a.length>0?a:void 0}}return e})}:e}let ct={show:!1,opacity:.18,baseline:`axis-min`};function lt(e,t){if(!(e===void 0||typeof e==`boolean`)){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be a boolean or object`);if(e.show!==void 0&&typeof e.show!=`boolean`)throw Error(`${t}.show must be a boolean`);if(e.color!==void 0&&typeof e.color!=`string`)throw Error(`${t}.color must be a string`);if(e.opacity!==void 0&&(!Number.isFinite(e.opacity)||e.opacity<0||e.opacity>1))throw Error(`${t}.opacity must be finite and between 0 and 1`)}}function ut(e,t){if(t===void 0)return e;if(typeof t==`boolean`)return{...e,show:t};let n=typeof t.color==`string`&&t.color.trim().length>0?t.color:e.color;return{...e,show:t.show??!0,color:n,opacity:t.opacity??e.opacity,baseline:`baseline`in t&&t.baseline!==void 0?t.baseline:e.baseline}}function dt(e,t){return ut(ut(ut({show:ct.show,opacity:ct.opacity,baseline:ct.baseline},e.style?.trace?.area),e.areaFill),t.areaFill)}function ft(e,t){return e===`axis-min`||e===`axis-max`?e:l(e===`zero`?0:c(e,t),a(t))}function pt(e){let t=e.areaFill!==void 0||e.style?.trace?.area!==void 0,n=e.traces?.some(e=>e.areaFill!==void 0)??!1;if(!t&&!n)return;if(e.type!==`line`)throw Error(`areaFill is supported only for 'line' charts`);lt(e.style?.trace?.area,`style.trace.area`),lt(e.areaFill,`areaFill`);for(let[t,n]of(e.traces??[]).entries())lt(n.areaFill,`traces[${t}].areaFill`);let r=De(e);for(let t of Oe(e)){let n=dt(e,t.trace);if(!n.show)continue;let i=r.get(t.yAxisId)??{};ft(n.baseline,i)}}function mt(e,t,n,r,i){let a=dt(e,t);if(!a.show)return;let o=ft(a.baseline,n),s=o===`axis-min`?i:o===`axis-max`?0:Math.max(0,Math.min(i,(1-(o-r.min)/(r.max-r.min))*i));return{color:a.color,opacity:a.opacity,baselineY:s}}function ht(e,t){if(e.labelPrefix!==void 0&&typeof e.labelPrefix!=`string`)throw Error(`${t}.labelPrefix must be a string`);if(e.labelSuffix!==void 0&&typeof e.labelSuffix!=`string`)throw Error(`${t}.labelSuffix must be a string`);if(e.tickValues!==void 0){if(!Array.isArray(e.tickValues))throw Error(`${t}.tickValues must be an array`);if(e.tickValues.length===0)throw Error(`${t}.tickValues must contain at least one value`);for(let t of e.tickValues)l(c(t,e),a(e))}}function gt(e){for(let[t,n]of Object.entries(e.axes?.xAxes??{}))ht(n,`axes.xAxes.${t}`);for(let[t,n]of Object.entries(e.axes?.yAxes??{}))ht(n,`axes.yAxes.${t}`)}function _t(e){let n=e??t.interpolation;if(n!==`linear`&&n!==`smooth`&&n!==`step-before`&&n!==`step-after`&&n!==`step-center`)throw Error(`lineStyle.interpolation must be 'linear', 'smooth', 'step-before', 'step-after', or 'step-center'`);return n}function vt(e,t){if(t===`linear`||e.length<2)return e;if(t===`smooth`)return xt(e);let n=[e[0]];for(let r=1;r<e.length;r+=1){let i=e[r-1],a=e[r];if(t===`step-before`)n.push({x:i.x,y:a.y});else if(t===`step-after`)n.push({x:a.x,y:i.y});else{let e=i.x+(a.x-i.x)/2;n.push({x:e,y:i.y},{x:e,y:a.y})}n.push(a)}return n}function yt(e,t,n){return Math.min(Math.max(e,Math.min(t,n)),Math.max(t,n))}function bt(e,t,n,r,i){let a=i*i,o=a*i;return .5*(2*t+(-e+n)*i+(2*e-5*t+4*n-r)*a+(-e+3*t-3*n+r)*o)}function xt(e){let n=t.smoothInterpolationSamplesPerSegment,r=[e[0]];for(let t=0;t<e.length-1;t+=1){let i=e[Math.max(0,t-1)],a=e[t],o=e[t+1],s=e[Math.min(e.length-1,t+2)];for(let e=1;e<=n;e+=1){if(e===n){r.push(o);continue}let t=e/n;r.push({x:yt(bt(i.x,a.x,o.x,s.x,t),a.x,o.x),y:yt(bt(i.y,a.y,o.y,s.y,t),a.y,o.y)})}}return r}let St={show:!1,color:`#0f172a`,font:`11px Inter, system-ui, sans-serif`,lineHeight:14,position:`auto`,offset:6,decimals:0,prefix:``,suffix:``,collisionPadding:2,formatter:null};function Ct(e,t){return typeof t==`string`&&t.trim().length>0?t:e}function wt(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function Tt(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<=0?t:e}function Et(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,Math.round(e)))}function Dt(e,t){if(e===void 0)return t;if(e===`above`||e===`below`||e===`auto`)return e;throw Error(`pointLabels.position must be 'above', 'below', or 'auto'`)}function Ot(e,t){if(t===void 0)return e;let n=typeof t==`object`&&t?t:void 0;return{show:typeof t==`boolean`?t:n?.show??!0,color:Ct(e.color,n?.color),font:Ct(e.font,n?.font),lineHeight:Tt(n?.lineHeight,e.lineHeight),position:Dt(n?.position,e.position),offset:wt(n?.offset,e.offset),decimals:Et(n?.decimals,e.decimals,0,12),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,collisionPadding:wt(n?.collisionPadding,e.collisionPadding)}}function kt(e,t){return Ot(Ot({...St},e),t)}function At(e){if(e.type!==`line`&&(e.pointLabels!==void 0||e.traces?.some(e=>e.pointLabels!==void 0)))throw Error(`pointLabels are supported only for 'line' charts`)}function jt(e,t,n){let r=e??t;if(r!==`circle`&&r!==`square`&&r!==`diamond`&&r!==`triangle`&&r!==`pentagon`&&r!==`hexagon`)throw Error(`${n} must be 'circle', 'square', 'diamond', 'triangle', 'pentagon', or 'hexagon'`);return r}let H={valueScale:`linear`,lowColor:`#e0f2fe`,highColor:`#0369a1`,colorStops:[],xCategories:[],yCategories:[],cellGap:0,cornerRadius:0,borderWidth:0,borderColor:`rgba(15, 23, 42, 0.22)`,labels:{show:!1,font:`11px system-ui, sans-serif`,color:`#475569`,lineHeight:14,offset:10},guides:{show:!1,color:`rgba(100, 116, 139, 0.32)`,lineWidth:1},missingCells:{show:!1,fillColor:`rgba(148, 163, 184, 0.18)`,borderColor:`rgba(100, 116, 139, 0.35)`,borderWidth:1},cellLabels:{show:!1,font:`11px system-ui, sans-serif`,color:`#0f172a`,autoContrast:!0,lightTextColor:`#f8fafc`,darkTextColor:`#0f172a`,minimumContrastRatio:4.5,lineHeight:14,padding:3,compactDecimals:1,ellipsis:`…`,decimals:0,prefix:``,suffix:``,minCellWidth:24,minCellHeight:18,formatter:null},colorScaleLegend:{show:!1,position:`right`,title:``,width:12,height:128,offset:16,tickCount:3,tickValues:[],tickSize:6,labelGap:6,labelPrefix:``,labelSuffix:``,decimals:0,font:`11px system-ui, sans-serif`,color:`#475569`,lineHeight:14,titleGap:4,borderColor:`rgba(15, 23, 42, 0.28)`,borderWidth:1}};function Mt(e,t,n){let r=e??t;if(r!==`linear`&&r!==`logarithmic`)throw Error(`${n} must be 'linear' or 'logarithmic'`);return r}function Nt(e,t,n,r){if(r===`logarithmic`){if(e<=0||t<=0||n<=0)throw Error(`Logarithmic color scales require values and bounds > 0`);if(t===n)return 1;let r=Math.log10(t),i=Math.log10(n);return Math.min(1,Math.max(0,(Math.log10(e)-r)/(i-r)))}return t===n?1:Math.min(1,Math.max(0,(e-t)/(n-t)))}function Pt(e,t,n,r,i){let a=r.filter(n=>n>=e&&n<=t);return a.length>0?a:Array.from({length:n},(r,a)=>{let o=n===1?0:a/(n-1);if(e===t)return e;if(i===`logarithmic`){let n=Math.log10(e);return 10**(n+o*(Math.log10(t)-n))}return e+(t-e)*o})}function Ft(e,t,n,r,i,a){return t===n?i===1?0:r/(i-1):Nt(e,t,n,a)}function It(e){let t=e.trim();return/^#[0-9a-fA-F]{3}$/.test(t)?{r:Number.parseInt(t[1]+t[1],16),g:Number.parseInt(t[2]+t[2],16),b:Number.parseInt(t[3]+t[3],16)}:/^#[0-9a-fA-F]{6}$/.test(t)?{r:Number.parseInt(t.slice(1,3),16),g:Number.parseInt(t.slice(3,5),16),b:Number.parseInt(t.slice(5,7),16)}:null}function Lt(e,t,n,r,i){let a=It(r),o=It(i);if(!a||!o)return e>=n?i:r;let s=n>t?Math.min(1,Math.max(0,(e-t)/(n-t))):1;return`rgb(${Math.round(a.r+(o.r-a.r)*s)}, ${Math.round(a.g+(o.g-a.g)*s)}, ${Math.round(a.b+(o.b-a.b)*s)})`}function Rt(e,t,n,r){if(!e||e.length===0)return[{offset:0,color:t},{offset:1,color:n}];if(e.length<2)throw Error(`${r} must contain at least two stops`);let i=e.map((e,t)=>{if(!e||typeof e!=`object`)throw Error(`${r}[${t}] must be a color stop`);if(typeof e.offset!=`number`||!Number.isFinite(e.offset)||e.offset<0||e.offset>1)throw Error(`${r}[${t}].offset must be a finite number between 0 and 1`);if(typeof e.color!=`string`||e.color.trim().length===0)throw Error(`${r}[${t}].color must be a non-empty string`);let n=e.color.trim();if(!It(n))throw Error(`${r}[${t}].color must use #RGB or #RRGGBB format`);return{offset:e.offset,color:n}});if(i[0].offset!==0||i[i.length-1].offset!==1)throw Error(`${r} must start at offset 0 and end at offset 1`);for(let e=1;e<i.length;e+=1)if(i[e].offset<=i[e-1].offset)throw Error(`${r} offsets must be strictly increasing`);return i}function zt(e,t,n,r,i=`linear`){let a=Nt(e,t,n,i),o=r.findIndex(e=>a<=e.offset);if(o<=0)return Lt(a,r[0].offset,r[1].offset,r[0].color,r[1].color);if(o===-1){let e=r[r.length-2],t=r[r.length-1];return Lt(a,e.offset,t.offset,e.color,t.color)}let s=r[o-1],c=r[o];return Lt(a,s.offset,c.offset,s.color,c.color)}function U(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function Bt(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<=0?t:e}function Vt(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,Math.round(e)))}function Ht(e,t,n){let r=Array.isArray(e)?e:t;if(n===`logarithmic`&&r.some(e=>typeof e!=`number`||!Number.isFinite(e)||e<=0))throw Error(`heatmap.colorScaleLegend.tickValues must contain only finite values > 0 for logarithmic scales`);return[...new Set(r.filter(e=>typeof e==`number`&&Number.isFinite(e)))].sort((e,t)=>e-t)}function Ut(...e){return[...e].reverse().find(e=>typeof e==`string`&&e.trim().length>0)}function Wt(e){return typeof e==`string`&&e.trim().length>0?e.trim():void 0}function Gt(e,t,r){let i=Mt(e.heatmap?.valueScale,H.valueScale,`heatmap.valueScale`),a=Ut(H.lowColor,e.heatmap?.lowColor)??H.lowColor,o=Ut(H.highColor,n[r%n.length],e.style?.trace?.line?.color,e.lineStyle?.color,e.heatmap?.highColor,t.color,t.lineStyle?.color)??H.highColor,s=Rt(e.heatmap?.colorStops??H.colorStops,a,o,`heatmap.colorStops`),c=U(e.heatmap?.cellGap,H.cellGap),l=U(e.heatmap?.cornerRadius,H.cornerRadius),u=U(e.heatmap?.borderWidth,H.borderWidth),d=Ut(H.borderColor,e.heatmap?.borderColor)??H.borderColor;return{valueScale:i,lowColor:a,highColor:o,colorStops:s,cellGap:U(t.heatmap?.cellGap,c),cornerRadius:U(t.heatmap?.cornerRadius,l),borderWidth:U(t.heatmap?.borderWidth,u),borderColor:Ut(d,t.heatmap?.borderColor)??d,missingCells:$t(e.heatmap?.missingCells,t.heatmap?.missingCells),cellLabels:nn(e.heatmap?.cellLabels,t.heatmap?.cellLabels),colorScaleLegend:an(e.heatmap?.colorScaleLegend,i)}}function Kt(e){if(Array.isArray(e))return e.filter(e=>typeof e==`string`)}function qt(e){return Array.isArray(e)?{labels:e}:typeof e==`object`&&e?e:void 0}function Jt(e){let t=qt(e);return{show:typeof e==`boolean`?e:t?t.show??!0:H.labels.show,labels:Kt(t?.labels),color:Ut(H.labels.color,t?.color)??H.labels.color,font:Ut(H.labels.font,t?.font)??H.labels.font,lineHeight:U(t?.lineHeight,H.labels.lineHeight),offset:U(t?.offset,H.labels.offset)}}function Yt(e){return typeof e==`object`&&e?e:void 0}function Xt(e){let t=Yt(e);return{show:typeof e==`boolean`?e:t?t.show??!0:H.guides.show,color:Ut(H.guides.color,t?.color)??H.guides.color,lineWidth:U(t?.lineWidth,H.guides.lineWidth)}}function Zt(e){return typeof e==`object`&&e?e:void 0}function Qt(e,t){if(t===void 0)return e;let n=Zt(t);return{show:typeof t==`boolean`?t:n?n.show??!0:e.show,fillColor:Ut(e.fillColor,n?.fillColor)??e.fillColor,borderColor:Ut(e.borderColor,n?.borderColor)??e.borderColor,borderWidth:U(n?.borderWidth,e.borderWidth)}}function $t(e,t){return Qt(Qt({...H.missingCells},e),t)}function en(e){return typeof e==`object`&&e?e:void 0}function tn(e,t){if(t===void 0)return e;let n=en(t),r=typeof t==`boolean`?t:n?n.show??!0:e.show,i=typeof n?.color==`string`&&n.color.trim().length>0?n.color:void 0;return{show:r,color:i??e.color,autoContrast:i===void 0?e.autoContrast:!1,font:Ut(e.font,n?.font)??e.font,lineHeight:Bt(n?.lineHeight,e.lineHeight),padding:U(n?.padding,e.padding),decimals:Vt(n?.decimals,e.decimals,0,6),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,minCellWidth:U(n?.minCellWidth,e.minCellWidth),minCellHeight:U(n?.minCellHeight,e.minCellHeight)}}function nn(e,t){return tn(tn({...H.cellLabels},e),t)}function rn(e){return typeof e==`object`&&e?e:void 0}function an(e,t){let n=rn(e),r=typeof e==`boolean`?e:n?n.show??!0:H.colorScaleLegend.show,i=n?.position===`left`||n?.position===`right`||n?.position===`top`||n?.position===`bottom`?n.position:H.colorScaleLegend.position,a=i===`top`||i===`bottom`;return{show:r,position:i,title:Wt(n?.title??H.colorScaleLegend.title),width:Bt(n?.width,a?H.colorScaleLegend.height:H.colorScaleLegend.width),height:Bt(n?.height,a?H.colorScaleLegend.width:H.colorScaleLegend.height),offset:U(n?.offset,H.colorScaleLegend.offset),tickCount:Vt(n?.tickCount,H.colorScaleLegend.tickCount,2,8),tickValues:Ht(n?.tickValues,H.colorScaleLegend.tickValues,t),tickSize:U(n?.tickSize,H.colorScaleLegend.tickSize),labelGap:U(n?.labelGap,H.colorScaleLegend.labelGap),labelPrefix:typeof n?.labelPrefix==`string`?n.labelPrefix:H.colorScaleLegend.labelPrefix,labelSuffix:typeof n?.labelSuffix==`string`?n.labelSuffix:H.colorScaleLegend.labelSuffix,decimals:Vt(n?.decimals,H.colorScaleLegend.decimals,0,6),color:Ut(H.colorScaleLegend.color,n?.color)??H.colorScaleLegend.color,font:Ut(H.colorScaleLegend.font,n?.font)??H.colorScaleLegend.font,lineHeight:Bt(n?.lineHeight,H.colorScaleLegend.lineHeight),titleGap:U(n?.titleGap,H.colorScaleLegend.titleGap),borderColor:Ut(H.colorScaleLegend.borderColor,n?.borderColor)??H.colorScaleLegend.borderColor,borderWidth:U(n?.borderWidth,H.colorScaleLegend.borderWidth)}}function on(e){let t=e.value??e.z;return t==null?null:c(t,{scale:`linear`})}function sn(e,t,n){let r=e??t;if(e!==void 0&&r.length===0)throw Error(`${n} must contain at least one category when provided`);if(r.length===0)return;let i=new Map;return r.forEach((e,t)=>{if(typeof e!=`string`||e.trim().length===0)throw Error(`${n} must contain only non-empty strings`);if(i.has(e))throw Error(`${n} must not contain duplicate categories`);i.set(e,t)}),{values:[...r],indexes:i}}function cn(e,t,n){if(!t)return c(e,{scale:`linear`});if(typeof e!=`string`)throw Error(`${n} requires string data coordinates`);let r=t.indexes.get(e);if(r===void 0)throw Error(`${n} does not contain data category '${e}'`);return r}function ln(e){return new Map(we(e).map(e=>[e.id,e.bounds]))}function un(e,t){let n=Mt(t.heatmap?.valueScale,H.valueScale,`heatmap.valueScale`),r=sn(t.heatmap?.xCategories,H.xCategories,`heatmap.xCategories`),i=sn(t.heatmap?.yCategories,H.yCategories,`heatmap.yCategories`),a=new Map;for(let t of e){if(t.visible===!1)continue;let e=t.subplot??`main`,o=a.get(e)??{x:new Set(r?.values.map((e,t)=>t)),y:new Set(i?.values.map((e,t)=>t)),values:[]};for(let e of t.data){if(e.x===null||e.y===null)continue;let t=on(e);if(t===null)throw Error(`Heatmap points require a numeric 'value' or 'z' field`);if(n===`logarithmic`&&t<=0)throw Error(`Heatmap logarithmic valueScale requires value/z > 0`);o.x.add(cn(e.x,r,`heatmap.xCategories`)),o.y.add(cn(e.y,i,`heatmap.yCategories`)),o.values.push(t)}a.set(e,o)}let o=new Map;for(let[e,s]of a.entries()){if(s.x.size===0||s.y.size===0||s.values.length===0)continue;if(n===`logarithmic`&&t.heatmap?.minValue!==void 0&&(typeof t.heatmap.minValue!=`number`||!Number.isFinite(t.heatmap.minValue)||t.heatmap.minValue<=0))throw Error(`Heatmap logarithmic minValue must be finite and > 0`);if(n===`logarithmic`&&t.heatmap?.maxValue!==void 0&&(typeof t.heatmap.maxValue!=`number`||!Number.isFinite(t.heatmap.maxValue)||t.heatmap.maxValue<=0))throw Error(`Heatmap logarithmic maxValue must be finite and > 0`);let a=typeof t.heatmap?.minValue==`number`&&Number.isFinite(t.heatmap.minValue)?t.heatmap.minValue:void 0,c=typeof t.heatmap?.maxValue==`number`&&Number.isFinite(t.heatmap.maxValue)?t.heatmap.maxValue:void 0,l=a??Math.min(...s.values),u=c??Math.max(...s.values);if(!(l<=u))throw Error(`Heatmap minValue must be <= maxValue`);o.set(e,{xValues:[...s.x].sort((e,t)=>e-t),yValues:[...s.y].sort((e,t)=>e-t),...r?{xCategories:r.values}:{},...i?{yCategories:i.values}:{},minValue:l,maxValue:u,valueScale:n})}return o}function dn(e){return String(Number.isInteger(e)?e:Number(e.toFixed(6)))}function fn(e,t,n,r){return e&&r<e.length?e[r]:t&&r<t.length?t[r]:dn(n)}function pn(e,t,n,r){let i=Jt(r.heatmap?.xLabels),a=Jt(r.heatmap?.yLabels),o=Xt(r.heatmap?.guides),s=i.show&&e.xValues.length>0,c=a.show&&e.yValues.length>0,l=o.show&&o.lineWidth>0;if(!s&&!c&&!l)return;let u=t/e.xValues.length,d=n/e.yValues.length,f={xLabels:[],yLabels:[],guides:[],guideColor:o.color,guideLineWidth:o.lineWidth};if(l){for(let t=0;t<=e.xValues.length;t+=1){let e=t*u;f.guides.push({axis:`x`,x1:e,y1:0,x2:e,y2:n,index:t})}for(let n=0;n<=e.yValues.length;n+=1){let e=n*d;f.guides.push({axis:`y`,x1:0,y1:e,x2:t,y2:e,index:n})}}return s&&e.xValues.forEach((t,r)=>{f.xLabels.push({axis:`x`,x:(r+.5)*u,y:n+i.offset,value:t,index:r,text:fn(i.labels,e.xCategories,t,r),color:i.color,font:i.font})}),c&&e.yValues.forEach((t,r)=>{f.yLabels.push({axis:`y`,x:-a.offset,y:n-(r+.5)*d,value:t,index:r,text:fn(a.labels,e.yCategories,t,r),color:a.color,font:a.font})}),f}function mn(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function hn(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function gn(e,t){return e.toFixed(t).replace(/\.0+$|(\.\d*?)0+$/,`$1`)}function _n(e,t,n){let r=Math.abs(e),i=[{threshold:0xe8d4a51000,divisor:0xe8d4a51000,symbol:`T`},{threshold:1e9,divisor:1e9,symbol:`B`},{threshold:1e6,divisor:1e6,symbol:`M`},{threshold:1e3,divisor:1e3,symbol:`k`}].find(e=>r>=e.threshold);return i?`${t}${gn(e/i.divisor,H.cellLabels.compactDecimals)}${i.symbol}${n}`:r>0&&r<.001?`${t}${e.toExponential(H.cellLabels.compactDecimals)}${n}`:hn(e,H.cellLabels.compactDecimals,t,n)}function vn(e){let t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)?.[1];if(n){let e=n.length===3?n.split(``).map(e=>`${e}${e}`).join(``):n;return{r:Number.parseInt(e.slice(0,2),16),g:Number.parseInt(e.slice(2,4),16),b:Number.parseInt(e.slice(4,6),16)}}let r=/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*[\d.]+)?\s*\)$/i.exec(t);if(r)return{r:Math.min(255,Math.max(0,Number(r[1]))),g:Math.min(255,Math.max(0,Number(r[2]))),b:Math.min(255,Math.max(0,Number(r[3])))}}function yn(e){let t=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function bn(e,t){let n=vn(e),r=vn(t);if(!n||!r)return;let i=yn(n),a=yn(r),o=Math.max(i,a),s=Math.min(i,a);return(o+.05)/(s+.05)}function xn(e,t,n){if(!n)return e;let r=bn(e,t);if(r===void 0||r>=H.cellLabels.minimumContrastRatio)return e;let i=[H.cellLabels.lightTextColor,H.cellLabels.darkTextColor].reduce((e,n)=>(bn(n,t)??0)>(bn(e,t)??0)?n:e,e);return(bn(i,t)??0)>=H.cellLabels.minimumContrastRatio?i:[`#ffffff`,`#000000`].reduce((e,n)=>(bn(n,t)??0)>(bn(e,t)??0)?n:e,i)}function Sn(e,t){let n=t.cellLabels;if(!n.show)return;let r=e.filter(e=>!e.missing).map(e=>{let r=hn(e.value,n.decimals,n.prefix,n.suffix),i=_n(e.value,n.prefix,n.suffix),a=e.borderWidth??t.borderWidth;return{x:e.x+e.width/2,y:e.y+e.height/2,value:e.value,xValue:e.xValue,yValue:e.yValue,row:e.row,column:e.column,text:r,fullText:r,...i.length<r.length?{compactText:i}:{},...e.sourceIndex===void 0?{}:{sourceIndex:e.sourceIndex},...e.xCategory===void 0?{}:{xCategory:e.xCategory},...e.yCategory===void 0?{}:{yCategory:e.yCategory},cellX:e.x,cellY:e.y,cellWidth:e.width,cellHeight:e.height,...e.cornerRadius===void 0?{}:{cellCornerRadius:e.cornerRadius},...a>0?{cellBorderWidth:a}:{},lineHeight:n.lineHeight,padding:n.padding,minCellWidth:n.minCellWidth,minCellHeight:n.minCellHeight,color:xn(n.color,e.fillColor,n.autoContrast),font:n.font}});return r.length>0?r:void 0}function Cn(e,t,n,r){let i=r.colorScaleLegend;if(!i.show)return;let a=i.position===`top`||i.position===`bottom`,o=i.title?i.lineHeight+i.titleGap:0;if(a){let a=Math.min(i.width,Math.max(1,t)),s=Math.max(0,(t-a)/2),c=o+i.height+i.tickSize+i.labelGap+i.lineHeight,l=(i.position===`top`?-(i.offset+c):n+i.offset)+o,u=Pt(e.minValue,e.maxValue,i.tickCount,i.tickValues,e.valueScale),d=u.map((t,n)=>{let r=Ft(t,e.minValue,e.maxValue,n,u.length,e.valueScale);return{value:t,text:mn(t,i.decimals,i.labelPrefix,i.labelSuffix),x:s+r*a,y:l+i.height}});return{valueScale:e.valueScale,position:i.position,x:s,y:l,width:a,height:i.height,minValue:e.minValue,maxValue:e.maxValue,lowColor:r.colorStops[0].color,highColor:r.colorStops[r.colorStops.length-1].color,colorStops:r.colorStops,title:i.title,ticks:d,tickSize:i.tickSize,labelGap:i.labelGap,labelPrefix:i.labelPrefix,labelSuffix:i.labelSuffix,color:i.color,font:i.font,lineHeight:i.lineHeight,titleGap:i.titleGap,borderColor:i.borderColor,borderWidth:i.borderWidth}}let s=Math.max(1,n-o),c=Math.min(i.height,s),l=c+o,u=Math.max(0,(n-l)/2)+o,d=Pt(e.minValue,e.maxValue,i.tickCount,i.tickValues,e.valueScale),f=d.map((t,n)=>{let r=Ft(t,e.minValue,e.maxValue,n,d.length,e.valueScale);return{value:t,text:mn(t,i.decimals,i.labelPrefix,i.labelSuffix),y:u+c-r*c}});return{valueScale:e.valueScale,position:i.position,x:i.position===`left`?-(i.offset+i.width):t+i.offset,y:u,width:i.width,height:c,minValue:e.minValue,maxValue:e.maxValue,lowColor:r.colorStops[0].color,highColor:r.colorStops[r.colorStops.length-1].color,colorStops:r.colorStops,title:i.title,ticks:f,tickSize:i.tickSize,labelGap:i.labelGap,labelPrefix:i.labelPrefix,labelSuffix:i.labelSuffix,color:i.color,font:i.font,lineHeight:i.lineHeight,titleGap:i.titleGap,borderColor:i.borderColor,borderWidth:i.borderWidth}}function wn(e,t){return`${e}:${t}`}function Tn(e,t,n,r,i,a){let o=r*t/e.xValues.length,s=r*(t+1)/e.xValues.length,c=e.yValues.length-n-1,l=i*c/e.yValues.length,u=i*(c+1)/e.yValues.length;return{x:o+a/2,y:l+a/2,width:Math.max(0,s-o-a),height:Math.max(0,u-l-a),row:n,column:t}}function En(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.width!=`number`||typeof t.height!=`number`||!Array.isArray(t.primitives))return null;for(let e of t.primitives)e.heatmapCells?.forEach(e=>{let t=e;t.missing&&(t.value===null||t.value===void 0)&&(t.value=NaN)});return t}function Dn(e){return En(B(e))||En(ce(e))||null}function On(e){let t=pe(e),n=ln(e),r=un(t,e),i=sn(e.heatmap?.xCategories,H.xCategories,`heatmap.xCategories`),a=sn(e.heatmap?.yCategories,H.yCategories,`heatmap.yCategories`),o=new Set,s=new Set,c=t.flatMap((t,c)=>{if(t.visible===!1)return[];let l=t.subplot??`main`,u=n.get(l);if(!u)throw Error(`Unknown subplot id '${l}' for trace`);let d=r.get(l);if(!d)return[];let f=Gt(e,t,c),p=Math.max(1,u.right-u.left),m=Math.max(1,u.bottom-u.top),h=p/d.xValues.length,g=m/d.yValues.length,_=Math.min(f.cellGap,h,g),v=new Map(d.xValues.map((e,t)=>[e,t])),y=new Map(d.yValues.map((e,t)=>[e,t])),b=[],x=new Set,S=0;for(let[e,n]of t.data.entries()){if(n.x===null||n.y===null)continue;let t=on(n);if(t===null)throw Error(`Heatmap points require a numeric 'value' or 'z' field`);let r=cn(n.x,i,`heatmap.xCategories`),o=cn(n.y,a,`heatmap.yCategories`),s=v.get(r),c=y.get(o);if(s===void 0||c===void 0)continue;let l=Tn(d,s,c,p,m,_),u=Math.min(f.cornerRadius,l.width/2,l.height/2);b.push({...l,...u>0?{cornerRadius:u}:{},value:t,xValue:r,yValue:o,...i?{xCategory:i.values[r]}:{},...a?{yCategory:a.values[o]}:{},sourceIndex:e,fillColor:zt(t,d.minValue,d.maxValue,f.colorStops,d.valueScale)}),x.add(wn(r,o)),S+=1}if(S>0&&f.missingCells.show&&d.yValues.forEach((e,t)=>{d.xValues.forEach((n,r)=>{if(x.has(wn(n,e)))return;let i=Tn(d,r,t,p,m,_),a=Math.min(f.cornerRadius,i.width/2,i.height/2);b.push({...i,...a>0?{cornerRadius:a}:{},value:NaN,xValue:n,yValue:e,...d.xCategories?{xCategory:d.xCategories[r]}:{},...d.yCategories?{yCategory:d.yCategories[t]}:{},fillColor:f.missingCells.fillColor,missing:!0,borderColor:f.missingCells.borderColor,borderWidth:f.missingCells.borderWidth})})}),b.length===0)return[];let C=o.has(l)?void 0:pn(d,p,m,e);o.add(l);let w=s.has(l)?void 0:Cn(d,p,m,f);s.add(l);let T=Sn(b,f);if(e.engine===`rust`){let t=Dn({width:e.width,height:e.height,traces:[{cells:b.map(e=>({value:e.missing?null:e.value,xValue:e.xValue,yValue:e.yValue,row:e.row,column:e.column,fillColor:e.fillColor,missing:e.missing===!0,...e.borderColor===void 0?{}:{borderColor:e.borderColor},...e.borderWidth===void 0?{}:{borderWidth:e.borderWidth}})),xCount:d.xValues.length,yCount:d.yValues.length,subplotWidth:p,subplotHeight:m,cellGap:_,color:f.highColor,lineWidth:f.borderWidth,borderColor:f.borderColor,borderWidth:f.borderWidth,subplot:l,bounds:u}]});if(!t)throw Error(`Rust heatmap scene engine is not available in current runtime`);let n=t.primitives[0];return n?[{...n,heatmapCells:n.heatmapCells?.map((e,t)=>({...e,sourceIndex:b[t]?.sourceIndex,xCategory:b[t]?.xCategory,yCategory:b[t]?.yCategory,...b[t]?.cornerRadius===void 0?{}:{cornerRadius:b[t].cornerRadius}})),heatmapCellLabels:T,heatmapGrid:C,heatmapColorScaleLegend:w,traceIndex:c}]:[]}return[{type:`heatmap`,points:b.map(e=>({x:e.x+e.width/2,y:e.y+e.height/2})),heatmapCells:b,heatmapCellLabels:T,heatmapGrid:C,heatmapColorScaleLegend:w,color:f.highColor,lineWidth:f.borderWidth,borderColor:f.borderColor,borderWidth:f.borderWidth,subplot:l,bounds:u,traceIndex:c}]});return{width:e.width,height:e.height,primitives:c}}function kn(e,t){let n=new Map;for(let[r,i]of e){if(i.viewportGroup===void 0)continue;if(typeof i.viewportGroup!=`string`||i.viewportGroup.trim().length===0)throw Error(`${t}-axis '${r}' viewportGroup must be a non-empty string`);let e=i.viewportGroup.trim(),a=n.get(e)??[];a.push({axisId:r,axis:i}),n.set(e,a)}for(let[e,r]of n){if(new Set(r.map(({axis:e})=>a(e))).size>1)throw Error(`${t}-axis viewportGroup '${e}' requires matching scale types`);let n=r.map(({axis:e})=>e.categories),i=n[0];if(!n.every(e=>!i&&!e?!0:!i||!e||i.length!==e.length?!1:i.every((t,n)=>t===e[n])))throw Error(`${t}-axis viewportGroup '${e}' requires matching categories`)}return n}function An(e,t,n,r){return c(e.min,t)===c(n.min,r)&&c(e.max,t)===c(n.max,r)}function jn(e,t,n){let r={...e},i=new Set(t??[]);for(let[e,t]of n){let n=t.filter(({axisId:e})=>r[e]!==void 0).map(({axisId:e,axis:t})=>({range:r[e],axis:t}));if(n.length>0){let[a,...o]=n;if(o.some(e=>!An(a.range,a.axis,e.range,e.axis)))throw Error(`viewportGroup '${e}' received conflicting ranges`);for(let{axisId:e}of t)r[e]=a.range,i.delete(e);continue}if(t.some(({axisId:e})=>i.has(e)))for(let{axisId:e}of t)i.add(e)}return{axes:r,resets:[...i]}}function Mn(e,t){let n=kn(Ee(e),`x`),r=kn(De(e),`y`),i=jn(t.xAxes,t.resetXAxes,n),a=jn(t.yAxes,t.resetYAxes,r);return{xAxes:i.axes,yAxes:a.axes,...i.resets.length>0?{resetXAxes:i.resets}:{},...a.resets.length>0?{resetYAxes:a.resets}:{}}}function Nn(e){return Pn(void 0,Mn(e,{xAxes:{...e.viewport?.xAxes??{}},yAxes:{...e.viewport?.yAxes??{}}}))}function Pn(e,t){let n={...e?.xAxes??{}},r={...e?.yAxes??{}};for(let e of t.resetXAxes??[])delete n[e];for(let e of t.resetYAxes??[])delete r[e];Object.assign(n,t.xAxes),Object.assign(r,t.yAxes);let i={};return Object.keys(n).length>0&&(i.xAxes=n),Object.keys(r).length>0&&(i.yAxes=r),i.xAxes||i.yAxes?i:void 0}function Fn(e,t){return!t?.xAxes&&!t?.yAxes?e:{...e??{},xAxes:{...e?.xAxes??{},...Object.fromEntries(Object.entries(t.xAxes??{}).map(([t,n])=>[t,{...e?.xAxes?.[t]??{},range:n}]))},yAxes:{...e?.yAxes??{},...Object.fromEntries(Object.entries(t.yAxes??{}).map(([t,n])=>[t,{...e?.yAxes?.[t]??{},range:n}]))}}}let In={startAngleDegrees:-90,clockwise:!0,sectorGapDegrees:0,sectorOpacity:1,borderColor:`rgba(15, 23, 42, 0.28)`,borderWidth:1,innerRadiusRatio:0,outerRadiusRatio:1,colors:[],labels:{show:!1,position:`inside`,content:`label`,color:`#ffffff`,font:`12px system-ui, sans-serif`,lineHeight:15,decimals:1,prefix:``,suffix:``,minSectorAngleDegrees:12,radiusRatio:.66,offset:14,collisionPadding:2,formatter:null}},Ln=Math.PI*2;function Rn(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function zn(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function Bn(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,e))}function Vn(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,Math.round(e)))}function Hn(e,t){return typeof t==`string`&&t.trim().length>0?t:e}function Un(e,t){if(e===void 0)return t;if(e===`inside`||e===`outside`)return e;throw Error(`pie.labels.position must be 'inside' or 'outside'`)}function Wn(e,t){if(e===void 0)return t;if(e===`label`||e===`value`||e===`fraction`||e===`label-value`||e===`label-fraction`)return e;throw Error(`pie.labels.content must be 'label', 'value', 'fraction', 'label-value', or 'label-fraction'`)}function Gn(e){return typeof e==`object`&&e?e:void 0}function Kn(e,t){if(t===void 0)return e;let n=Gn(t);return{show:typeof t==`boolean`?t:n?n.show??!0:e.show,position:Un(n?.position,e.position),content:Wn(n?.content,e.content),color:Hn(e.color,n?.color),font:Hn(e.font,n?.font),lineHeight:zn(n?.lineHeight,e.lineHeight),decimals:Vn(n?.decimals,e.decimals,0,12),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,minSectorAngleDegrees:zn(n?.minSectorAngleDegrees,e.minSectorAngleDegrees),radiusRatio:Bn(n?.radiusRatio,e.radiusRatio,0,1),offset:zn(n?.offset,e.offset),collisionPadding:zn(n?.collisionPadding,e.collisionPadding),formatter:typeof n?.formatter==`function`?n.formatter:e.formatter}}function qn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0):[...In.colors]}function Jn(e){let t={...In.labels},n=e?.labels;return{startAngleDegrees:Rn(e?.startAngleDegrees,In.startAngleDegrees),clockwise:e?.clockwise??In.clockwise,sectorGapDegrees:zn(e?.sectorGapDegrees,In.sectorGapDegrees),sectorOpacity:Bn(e?.sectorOpacity,In.sectorOpacity,0,1),borderColor:Hn(In.borderColor,e?.borderColor),borderWidth:zn(e?.borderWidth,In.borderWidth),innerRadiusRatio:Bn(e?.innerRadiusRatio,In.innerRadiusRatio,0,.95),outerRadiusRatio:Bn(e?.outerRadiusRatio,In.outerRadiusRatio,.05,1),colors:qn(e?.colors),labels:Kn(t,n)}}function Yn(e,t){return typeof e.label==`string`&&e.label.trim().length>0?e.label:typeof e.name==`string`&&e.name.trim().length>0?e.name:typeof e.x==`string`&&e.x.trim().length>0?e.x:`#${t+1}`}function Xn(e,t){let n=e.value!==void 0&&e.value!==null?e.value:e.y;if(n==null)return 0;if(typeof n==`number`&&Number.isFinite(n)){if(n<0)throw Error(`pie datum ${t} value must be non-negative`);return n}throw Error(`pie datum ${t} value must be a finite number`)}function Zn(e){let t=e.pie,r=[];if(t?.traces!==void 0&&t.traces.length>0)for(let e of t.traces){let t=e.pie?.data,n=Array.isArray(t)?t:e.data??[];r.push({visible:e.visible,color:e.color,hiddenDataIndexes:e.pie?.hiddenDataIndexes,data:n})}else if(t?.data!==void 0)r.push({hiddenDataIndexes:t.hiddenDataIndexes,data:t.data});else{let n=!!(e.traces&&e.traces.length>0),i=n?e.traces:e.data?[{data:e.data}]:[];for(let e of i){let i=e.pie?.data,a=Array.isArray(i)&&i.length>0?i:e.data??[];r.push({visible:e.visible,color:e.color,hiddenDataIndexes:e.pie?.hiddenDataIndexes??(n?void 0:t?.hiddenDataIndexes),data:a})}}let i=[],a=[],o=0;r.forEach((e,t)=>{if(a[t]=e.data.length,e.visible===!1)return;let r=t,s=new Set((e.hiddenDataIndexes??[]).filter(e=>Number.isInteger(e)&&e>=0));e.data.forEach((t,a)=>{if(s.has(a))return;let c=Xn(t,a);if(c<=0)return;let l=typeof e.color==`string`&&e.color.trim().length>0?e.color:void 0;i.push({label:Yn(t,a),value:c,sourceIndex:a,traceIndex:r,color:l??n[r%n.length]}),o+=c})});for(let e=0;e<a.length;e+=1)a[e]===void 0&&(a[e]=0);if(!Number.isFinite(o))throw Error(`pie total value must remain finite`);return{datum:i,total:o,datumCountsByTrace:a}}function Qn(e,t,n,r){let i=r>0?r:1,a=0,o=Number.isFinite(n)&&n>0?Math.floor(n):0;for(let e=0;e<o;e+=1)a+=Number.isFinite(t[e])?t[e]:0;return(a+(Number.isFinite(e)&&e>0?Math.floor(e):0))%i}function $n(e,t,r){let i=t.length>0?t:n;e.forEach(e=>{let t=e.color;e.color=n.includes(t)?i[Qn(e.sourceIndex,r,e.traceIndex,i.length)]:t})}function er(e,t){return e.toFixed(t)}function tr(e,t){return`${(e*100).toFixed(t)}%`}function nr(e,t,n){let{label:r,value:i}=e,{content:a,decimals:o,prefix:s,suffix:c}=n.labels,l=er(i,o),u=tr(t,o),d;switch(a){case`value`:d=l;break;case`fraction`:d=u;break;case`label-value`:d=`${r} ${l}`;break;case`label-fraction`:d=`${r} ${u}`;break;default:d=r;break}return`${s}${d}${c}`}function rr(e,t,n){let r=nr(e,t,n),i=n.labels.formatter;if(typeof i!=`function`)return r;let a=i({value:e.value,fraction:t,percentage:t*100,label:e.label,defaultLabel:r,color:e.color,traceIndex:e.traceIndex,sourceIndex:e.sourceIndex});if(a===null||a===``)return null;if(typeof a!=`string`)throw Error(`pie.labels.formatter must return a string, null, or an empty string`);return a}function ir(e){let t=e%Ln;return t<0?t+Ln:t}function ar(e,t){let n=e.startAngleDegrees*Math.PI/180,r=e.clockwise?1:-1,i=e.sectorGapDegrees*Math.PI/180,a=t.length>1&&i>0?Math.min(i,t.reduce((e,t)=>Math.min(e,t*Ln*.95),1/0)):0,o=[],s=n;return t.forEach(e=>{let t=e*Ln*r,n=s,i=t;if(a>0){let e=r>=0?1:-1;s=n+a/2*e,i=t-a*e}let c=ir(s),l=s+i;s=n+t;let u=c+i/2;o.push({start:c,end:l,sweep:i,angle:u})}),o}function or(e){if(e.engine===`rust`)throw Error(`Rust pie scene engine is not available in current runtime`);let t=Jn(e.pie),{datum:r,total:i,datumCountsByTrace:a}=Zn(e);if(r.length===0||i<=0)return{width:e.width,height:e.height,primitives:[]};$n(r,t.colors,a);let o=r.map(e=>e.value/i),s=ar(t,o),c=[...new Map(we(e).map(e=>[e.id,e.bounds])).entries()].map(([e,i])=>{let a=[],c=[],l=(i.right-i.left)/2,u=(i.bottom-i.top)/2,d=Math.max(0,Math.min(l,u,(i.bottom-i.top)/2,(i.right-i.left)/2)),f=d*t.innerRadiusRatio,p=Math.max(f,d*t.outerRadiusRatio);return r.forEach((e,n)=>{let r=s[n],i=o[n],d={centerX:l,centerY:u,innerRadius:f,outerRadius:p,startAngle:r.start,endAngle:r.start+r.sweep,sweep:r.sweep,clockwise:t.clockwise,angle:ir(r.angle),value:e.value,fraction:i,color:e.color,label:e.label,opacity:t.sectorOpacity,sourceIndex:e.sourceIndex,traceIndex:e.traceIndex};if(a.push(d),!t.labels.show||Math.abs(r.sweep*180/Math.PI)<t.labels.minSectorAngleDegrees)return;let m=rr(e,i,t);if(m===null)return;let h=t.labels.position===`inside`?f+(p-f)*t.labels.radiusRatio:p+t.labels.offset;c.push({x:l+Math.cos(r.angle)*h,y:u+Math.sin(r.angle)*h,angle:ir(r.angle),value:e.value,fraction:i,text:m,color:t.labels.color,font:t.labels.font,lineHeight:t.labels.lineHeight,position:t.labels.position,sectorIndex:n,collisionPadding:t.labels.collisionPadding})}),{type:`pie`,points:[],color:a[0]?.color??n[0],lineWidth:t.borderWidth,pieSectors:a,pieSectorLabels:c.length>0?c:void 0,borderColor:t.borderColor,borderWidth:t.borderWidth,subplot:e,bounds:{left:0,top:0,right:i.right-i.left,bottom:i.bottom-i.top}}});return{width:e.width,height:e.height,primitives:c}}let W={mode:`windrose`,radialScale:`linear`,sectorMode:`grouped`,angleCategories:[],sectorWidthDegrees:24,sectorGapDegrees:0,sectorOpacity:1,startAngleDegrees:-90,clockwise:!0,innerRadiusRatio:0,outerRadiusRatio:.92,minRadius:0,maxRadius:null,borderWidth:1,borderColor:`rgba(15, 23, 42, 0.28)`,sectorLabels:{show:!1,color:`#ffffff`,font:`11px Inter, system-ui, sans-serif`,lineHeight:14,decimals:0,prefix:``,suffix:``,minSectorRadius:14,minSectorAngleDegrees:6,radiusRatio:.62,collisionPadding:2,formatter:null},grid:{show:!1,rings:4,ringValues:[],spokes:12,ringColor:`rgba(100, 116, 139, 0.34)`,spokeColor:`rgba(100, 116, 139, 0.28)`,ringLineWidth:1,spokeLineWidth:1,labels:{show:!1,color:`#475569`,font:`11px system-ui, sans-serif`,decimals:0,angleDegrees:90,offset:6,prefix:``,suffix:``,formatter:null},angleLabels:{show:!1,color:`#475569`,font:`11px system-ui, sans-serif`,decimals:0,offset:14,labels:[],prefix:``,suffix:`°`,formatter:null}},vectors:{show:!1,directions:[],color:``,lineWidth:2,headSize:8,headAngleDegrees:28}};function sr(e,t){return typeof e!=`number`||!Number.isFinite(e)?t:e}function cr(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<=0?t:e}function G(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function lr(e,t,n,r){return Math.min(r,Math.max(n,typeof e==`number`&&Number.isInteger(e)?e:t))}function ur(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,e))}function dr(e,t){return typeof t==`string`&&t.trim().length>0?t:e}function fr(...e){return[...e].reverse().find(e=>typeof e==`string`&&e.trim().length>0)}function pr(e,t){if(t===void 0)return e;let n=typeof t==`object`?t:void 0;return{show:typeof t==`boolean`?t:n?.show??!0,color:dr(e.color,n?.color),font:dr(e.font,n?.font),lineHeight:G(n?.lineHeight,e.lineHeight),decimals:lr(n?.decimals,e.decimals,0,12),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,minSectorRadius:G(n?.minSectorRadius,e.minSectorRadius),minSectorAngleDegrees:G(n?.minSectorAngleDegrees,e.minSectorAngleDegrees),radiusRatio:ur(n?.radiusRatio,e.radiusRatio,0,1),collisionPadding:G(n?.collisionPadding,e.collisionPadding),formatter:typeof n?.formatter==`function`?n.formatter:e.formatter}}function mr(e,t){return pr(pr({...W.sectorLabels},e),t)}function hr(e){let t=typeof e==`object`?e:void 0;return{show:typeof e==`boolean`?e:t?.show??(e===void 0?W.grid.labels.show:!0),color:fr(W.grid.labels.color,t?.color),font:dr(W.grid.labels.font,t?.font),decimals:lr(t?.decimals,W.grid.labels.decimals,0,12),angleDegrees:sr(t?.angleDegrees,W.grid.labels.angleDegrees),offset:G(t?.offset,W.grid.labels.offset),prefix:typeof t?.prefix==`string`?t.prefix:W.grid.labels.prefix,suffix:typeof t?.suffix==`string`?t.suffix:W.grid.labels.suffix,formatter:typeof t?.formatter==`function`?t.formatter:W.grid.labels.formatter}}function gr(e,t){let n=typeof e==`object`?e:void 0;return{show:typeof e==`boolean`?e:n?.show??(e===void 0?W.grid.angleLabels.show:!0),color:fr(W.grid.angleLabels.color,n?.color),font:dr(W.grid.angleLabels.font,n?.font),decimals:lr(n?.decimals,W.grid.angleLabels.decimals,0,12),offset:G(n?.offset,W.grid.angleLabels.offset),labels:Array.isArray(n?.labels)?n.labels.map(e=>typeof e==`string`?e:``):t.length>0?t:W.grid.angleLabels.labels,prefix:typeof n?.prefix==`string`?n.prefix:W.grid.angleLabels.prefix,suffix:typeof n?.suffix==`string`?n.suffix:W.grid.angleLabels.suffix,formatter:typeof n?.formatter==`function`?n.formatter:W.grid.angleLabels.formatter}}function _r(e){if(e===void 0)return[...W.angleCategories];if(!Array.isArray(e)||e.length===0)throw Error(`Polar angleCategories must be a non-empty array when provided`);if(e.length>360)throw Error(`Polar angleCategories must contain at most 360 entries`);let t=e.map(e=>{if(typeof e!=`string`||e.trim().length===0)throw Error(`Polar angleCategories must contain only non-empty strings`);return e});if(new Set(t).size!==t.length)throw Error(`Polar angleCategories must contain unique strings`);return t}function vr(e,t){let n=Array.isArray(e)?e:W.grid.ringValues;if(t===`logarithmic`&&n.some(e=>typeof e!=`number`||!Number.isFinite(e)||e<=0))throw Error(`Polar logarithmic ringValues must contain only finite values > 0`);let r=[...new Set(n.filter(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0))].sort((e,t)=>e-t);return r.length>0?r:void 0}function yr(e,t){return e?.length?e.flatMap(e=>{let n=typeof e==`number`?e:e.directionDegrees??e.direction;if(typeof n!=`number`||!Number.isFinite(n))return[];let r=typeof e==`object`?e:void 0;return[{angle:Tr(n),color:fr(t.color,r?.color),lineWidth:G(r?.lineWidth,t.lineWidth),headSize:G(r?.headSize,t.headSize),headAngleDegrees:Math.min(85,Math.max(5,cr(r?.headAngleDegrees,t.headAngleDegrees)))}]}):[]}function br(e){let t={show:e?.show??(e===void 0?W.vectors.show:!0),color:fr(W.vectors.color,e?.color),lineWidth:G(e?.lineWidth,W.vectors.lineWidth),headSize:G(e?.headSize,W.vectors.headSize),headAngleDegrees:Math.min(85,Math.max(5,cr(e?.headAngleDegrees,W.vectors.headAngleDegrees)))};return{...t,directions:yr(e?.directions,t)}}function xr(e,t){if(t===void 0)return e;if(typeof t==`boolean`)return{...e,show:t,directions:[]};let n={show:t.show??!0,color:fr(e.color,t.color),lineWidth:G(t.lineWidth,e.lineWidth),headSize:G(t.headSize,e.headSize),headAngleDegrees:Math.min(85,Math.max(5,cr(t.headAngleDegrees,e.headAngleDegrees)))};return{...n,directions:yr(t.directions,n)}}function Sr(e){if((e?.mode??W.mode)!==`windrose`)throw Error(`Only polar mode 'windrose' is supported`);let t=e?.radialScale??W.radialScale;if(t!==`linear`&&t!==`logarithmic`)throw Error(`Polar radialScale must be 'linear' or 'logarithmic'`);let n=e?.sectorMode??W.sectorMode;if(n!==`grouped`&&n!==`stacked`)throw Error(`Polar sectorMode must be 'grouped' or 'stacked'`);if(n===`stacked`&&t===`logarithmic`)throw Error(`Polar stacked sectors require a linear radialScale`);let r=t===`logarithmic`;if(r&&e?.minRadius!==void 0&&(typeof e.minRadius!=`number`||!Number.isFinite(e.minRadius)||e.minRadius<=0))throw Error(`Polar logarithmic minRadius must be finite and > 0`);if(r&&e?.maxRadius!==void 0&&(typeof e.maxRadius!=`number`||!Number.isFinite(e.maxRadius)||e.maxRadius<=0))throw Error(`Polar logarithmic maxRadius must be finite and > 0`);if(r&&e?.minRadius!==void 0&&e?.maxRadius!==void 0&&e.maxRadius<=e.minRadius)throw Error(`Polar logarithmic maxRadius must be greater than minRadius`);let i=r?e?.minRadius:G(e?.minRadius,W.minRadius),a=r?e?.maxRadius:typeof e?.maxRadius==`number`&&Number.isFinite(e.maxRadius)?e.maxRadius:W.maxRadius,o=_r(e?.angleCategories);return{radialScale:t,sectorMode:n,angleCategories:o,sectorWidthDegrees:Math.min(360,Math.max(1,cr(e?.sectorWidthDegrees,W.sectorWidthDegrees))),sectorGapDegrees:Math.min(360,G(e?.sectorGapDegrees,W.sectorGapDegrees)),sectorOpacity:ur(e?.sectorOpacity,W.sectorOpacity,0,1),startAngleDegrees:sr(e?.startAngleDegrees,W.startAngleDegrees),clockwise:e?.clockwise??W.clockwise,innerRadiusRatio:ur(e?.innerRadiusRatio,W.innerRadiusRatio,0,.95),outerRadiusRatio:ur(e?.outerRadiusRatio,W.outerRadiusRatio,.05,1),minRadius:i,borderWidth:G(e?.borderWidth,W.borderWidth),borderColor:dr(W.borderColor,e?.borderColor),maxRadius:typeof a==`number`&&(i===void 0||a>i)?a:void 0,sectorLabels:mr(e?.sectorLabels),grid:{show:e?.grid?.show??(e?.grid===void 0?W.grid.show:!0),rings:lr(e?.grid?.rings,W.grid.rings,0,64),ringValues:vr(e?.grid?.ringValues,t),spokes:lr(e?.grid?.spokes,o.length>0?o.length:W.grid.spokes,0,360),ringColor:dr(W.grid.ringColor,e?.grid?.ringColor),spokeColor:dr(W.grid.spokeColor,e?.grid?.spokeColor),ringLineWidth:G(e?.grid?.ringLineWidth,W.grid.ringLineWidth),spokeLineWidth:G(e?.grid?.spokeLineWidth,W.grid.spokeLineWidth),labels:hr(e?.grid?.labels),angleLabels:gr(e?.grid?.angleLabels,o)},vectors:br(e?.vectors)}}function Cr(e,t){return{...e,sectorGapDegrees:Math.min(360,G(t?.sectorGapDegrees,e.sectorGapDegrees)),sectorOpacity:ur(t?.sectorOpacity,e.sectorOpacity,0,1),borderWidth:G(t?.borderWidth,e.borderWidth),borderColor:dr(e.borderColor,t?.borderColor),sectorLabels:pr(e.sectorLabels,t?.sectorLabels)}}function wr(e,t,r){return t.lineStyle?.color??t.color??e.lineStyle?.color??e.style?.trace?.line?.color??n[r%n.length]}function Tr(e){let t=e%360;return t<0?t+360:t}function Er(e,t){if(e===null)throw Error(`Polar angles must not be null`);if(t.angleCategories.length===0)return Tr(c(e,{scale:`linear`}));if(typeof e!=`string`)throw Error(`Categorical polar angles must be configured category strings`);let n=t.angleCategories.indexOf(e);if(n<0)throw Error(`Unknown polar angle category '${e}'`);return n*360/t.angleCategories.length}function Dr(e,t){if(t.angleCategories.length!==0){for(let n of e)if(n.visible!==!1)for(let e of n.data)e.x!==null&&e.y!==null&&Er(e.x,t)}}function Or(e){return new Map(we(e).map(e=>[e.id,e.bounds]))}function kr(e,t,n){let r=new Map;for(let[i,a]of e.entries()){if(a.visible===!1)continue;let e=a.subplot??`main`;for(let[o,s]of a.data.entries()){if(s.x===null||s.y===null)continue;let a=c(s.y,{scale:`linear`});if(t.radialScale===`logarithmic`&&a<=0)throw Error(`Polar logarithmic radial scale requires y > 0`);if(a<0)throw Error(`Polar windrose values require y >= 0`);let l=n.get(i)?.get(o)?.totalValue??a,u=r.get(e);r.set(e,{minRadius:Math.min(u?.minRadius??l,l),maxRadius:Math.max(u?.maxRadius??l,l)})}}r.size===0&&t.minRadius!==void 0&&t.maxRadius!==void 0&&r.set(`main`,{minRadius:t.minRadius,maxRadius:t.maxRadius});let i=new Map;for(let[e,n]of r){let r=t.radialScale===`logarithmic`?t.minRadius??n.minRadius:t.minRadius??W.minRadius,a=t.maxRadius??n.maxRadius;if(t.radialScale===`logarithmic`&&t.maxRadius!==void 0&&a<r)throw Error(`Polar logarithmic maxRadius must not be below the inferred radial minimum`);let o=t.radialScale===`linear`?Pr(a,r):Math.max(a,r);i.set(e,{minRadius:r,maxRadius:o})}return i}function Ar(e,t){let n=new Map;if(t.sectorMode!==`stacked`)return n;let r=new Map;return e.forEach((e,i)=>{if(e.visible===!1)return;let a=e.subplot??`main`,o=r.get(a)??new Map;r.set(a,o);let s=new Map;e.data.forEach((e,n)=>{if(e.x===null||e.y===null)return;let r=Er(e.x,t),i=c(e.y,{scale:`linear`});if(i<0)throw Error(`Polar windrose values require y >= 0`);if(i===0)return;let a=o.get(r)??0,l=a+i;o.set(r,l),s.set(n,{baseValue:a,totalValue:l})}),s.size>0&&n.set(i,s)}),n}function jr(e){let t=new Map;return e.forEach((e,n)=>{if(e.visible===!1)return;let r=e.subplot??`main`,i=t.get(r)??[];i.push(n),t.set(r,i)}),t}function Mr(e){return e*Math.PI/180}function Nr(e,t){let n=Math.max(1,e.right-e.left),r=Math.max(1,e.bottom-e.top),i=n/2,a=r/2,o=Math.min(n,r)/2*t.outerRadiusRatio,s=o*t.innerRadiusRatio;return{width:n,height:r,centerX:i,centerY:a,outerLimit:o,innerRadius:s,availableRadius:Math.max(0,o-s)}}function Pr(e,t){return e>t?e:t+1}function Fr(e,t,n,r){if(t.maxRadius===t.minRadius)return e>=t.maxRadius?r.outerLimit:r.innerRadius;let i=n===`logarithmic`?Math.log10(e):e,a=n===`logarithmic`?Math.log10(t.minRadius):t.minRadius,o=n===`logarithmic`?Math.log10(t.maxRadius):t.maxRadius,s=Math.max(2**-52,o-a),c=Math.min(1,Math.max(0,(i-a)/s));return r.innerRadius+c*r.availableRadius}function Ir(e,t){return Mr(t.startAngleDegrees+(t.clockwise?e:-e))}function Lr(e,t,n,r){return`${n}${t===0?e.toFixed(0):e.toFixed(t).replace(/\.?0+$/,``)}${r}`}function Rr(e,t,n,r){return`${n}${t===0?e.toFixed(0):e.toFixed(t).replace(/\.?0+$/,``)}${r}`}function zr(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function Br(e,t,n){let r=n.labels[t];return typeof r==`string`&&r.trim().length>0?r:Rr(e,n.decimals,n.prefix,n.suffix)}function Vr(e,t){if(e===null||e===``)return null;if(typeof e!=`string`)throw Error(`${t} must return a string or null`);return e}function Hr(e,t,n){let r=t.sectorLabels.formatter!==null||n.some(e=>typeof e.polar?.sectorLabels==`object`&&typeof e.polar.sectorLabels.formatter==`function`),i=t.grid.labels.formatter!==null,a=t.grid.angleLabels.formatter!==null;return!r&&!i&&!a?e:{...e,primitives:e.primitives.map(e=>{let r=e;if(e.polarSectorLabels?.length){let i=e.traceIndex??0,a=Cr(t,n[i]?.polar).sectorLabels.formatter;if(a){let t=e.polarSectorLabels.flatMap((t,n)=>{let r=e.polarSectors?.[t.sectorIndex??n],o=Vr(a({value:t.value,defaultLabel:t.text,angle:t.angle,traceIndex:i,sourceIndex:r?.sourceIndex??t.sectorIndex??n}),`polar.sectorLabels.formatter`);return o===null?[]:[{...t,text:o}]});r={...r,polarSectorLabels:t.length>0?t:void 0}}}if(e.polarGrid){let n=t.grid.labels.formatter?e.polarGrid.labels.flatMap((e,n)=>{let r=t.grid.labels.formatter?.({value:e.value,defaultLabel:e.text,index:n,scale:t.radialScale}),i=Vr(r,`polar.grid.labels.formatter`);return i===null?[]:[{...e,text:i}]}):e.polarGrid.labels,i=t.grid.angleLabels.formatter?e.polarGrid.angleLabels.flatMap((e,n)=>{let r=t.grid.angleLabels.formatter?.({angle:e.angle,defaultLabel:e.text,index:n,category:t.angleCategories[n]}),i=Vr(r,`polar.grid.angleLabels.formatter`);return i===null?[]:[{...e,text:i}]}):e.polarGrid.angleLabels;(n!==e.polarGrid.labels||i!==e.polarGrid.angleLabels)&&(r={...r,polarGrid:{...e.polarGrid,labels:n,angleLabels:i}})}return r})}}function Ur(e,t){if(!t.show)return;let n=e.map((e,t)=>({sector:e,sectorIndex:t})).filter(({sector:e})=>{let n=e.outerRadius-e.innerRadius,r=Math.abs(e.endAngle-e.startAngle)*(180/Math.PI);return n>=t.minSectorRadius&&r>=t.minSectorAngleDegrees}).map(({sector:e,sectorIndex:n})=>{let r=(e.startAngle+e.endAngle)/2,i=e.innerRadius+(e.outerRadius-e.innerRadius)*t.radiusRatio;return{x:e.centerX+Math.cos(r)*i,y:e.centerY+Math.sin(r)*i,angle:e.angle,value:e.value,text:zr(e.value,t.decimals,t.prefix,t.suffix),color:t.color,font:t.font,lineHeight:t.lineHeight,sectorIndex:n,collisionPadding:t.collisionPadding}});return n.length>0?n:void 0}function Wr(e,t){if(e.type!==`polar`||!e.polarSectors?.length)return e;let n=Ur(e.polarSectors,t.sectorLabels);return n?{...e,polarSectorLabels:n}:e}function Gr(e,t){return e.grid.ringValues?.length?e.grid.ringValues.filter(e=>e>=t.minRadius&&e<=t.maxRadius):e.grid.rings<=0?[]:t.minRadius===t.maxRadius?[t.maxRadius]:Array.from({length:e.grid.rings},(n,r)=>{let i=(r+1)/e.grid.rings;if(e.radialScale===`logarithmic`){let e=Math.log10(t.minRadius);return 10**(e+i*(Math.log10(t.maxRadius)-e))}return t.minRadius+i*(t.maxRadius-t.minRadius)})}function Kr(e){if(!e.polar.grid.show)return null;let t=[],n=[],r=[],i=[];for(let n of Gr(e.polar,e.domain)){let i=Fr(n,e.domain,e.polar.radialScale,e.geometry);if(t.push({centerX:e.geometry.centerX,centerY:e.geometry.centerY,radius:i,value:n}),e.polar.grid.labels.show){let t=Tr(e.polar.grid.labels.angleDegrees),a=Ir(t,e.polar),o=i+e.polar.grid.labels.offset;r.push({x:e.geometry.centerX+Math.cos(a)*o,y:e.geometry.centerY+Math.sin(a)*o,radius:i,value:n,text:Lr(n,e.polar.grid.labels.decimals,e.polar.grid.labels.prefix,e.polar.grid.labels.suffix),angle:t})}}for(let t=0;t<e.polar.grid.spokes;t+=1){let r=t*360/e.polar.grid.spokes,a=Ir(r,e.polar),o=e.geometry.centerX+Math.cos(a)*e.geometry.outerLimit,s=e.geometry.centerY+Math.sin(a)*e.geometry.outerLimit;if(n.push({centerX:e.geometry.centerX,centerY:e.geometry.centerY,endX:o,endY:s,angle:r}),e.polar.grid.angleLabels.show){let n=e.geometry.outerLimit+e.polar.grid.angleLabels.offset;i.push({x:e.geometry.centerX+Math.cos(a)*n,y:e.geometry.centerY+Math.sin(a)*n,angle:r,text:Br(r,t,e.polar.grid.angleLabels)})}}return t.length===0&&n.length===0?null:{type:`polar`,points:[...t.map(e=>({x:e.centerX+e.radius,y:e.centerY})),...n.map(e=>({x:e.endX,y:e.endY})),...r.map(e=>({x:e.x,y:e.y})),...i.map(e=>({x:e.x,y:e.y}))],color:e.polar.grid.ringColor,lineWidth:e.polar.grid.ringLineWidth,polarGrid:{rings:t,angleGuides:n,labels:r,angleLabels:i,ringColor:e.polar.grid.ringColor,spokeColor:e.polar.grid.spokeColor,labelColor:e.polar.grid.labels.color??W.grid.labels.color,labelFont:e.polar.grid.labels.font,angleLabelColor:e.polar.grid.angleLabels.color??W.grid.angleLabels.color,angleLabelFont:e.polar.grid.angleLabels.font,ringLineWidth:e.polar.grid.ringLineWidth,spokeLineWidth:e.polar.grid.spokeLineWidth},subplot:e.subplot,bounds:e.bounds}}function qr(e){let t=Ir(e.angle,e.polar);return{centerX:e.geometry.centerX,centerY:e.geometry.centerY,endX:e.geometry.centerX+Math.cos(t)*e.geometry.outerLimit,endY:e.geometry.centerY+Math.sin(t)*e.geometry.outerLimit,angle:e.angle,value:e.value,color:e.style.color??e.fallbackColor,lineWidth:e.style.lineWidth,headSize:e.style.headSize,headAngle:Mr(e.style.headAngleDegrees)}}function Jr(e){if(!e.polar.vectors.show||e.polar.vectors.directions.length===0)return null;let t=e.polar.vectors.color??n[0],r=e.polar.vectors.directions.map(n=>qr({angle:n.angle,value:e.maxRadius,style:n,fallbackColor:t,polar:e.polar,geometry:e.geometry}));return{type:`polar`,points:r.map(e=>({x:e.endX,y:e.endY})),color:t,lineWidth:e.polar.vectors.lineWidth,polarVectors:r,subplot:e.subplot,bounds:e.bounds}}function Yr(e){let t=wr(e.options,e.trace,e.traceIndex),n=xr(e.polar.vectors,e.trace.polarVector);if(!n.show)return null;let r=n.color??t;if(e.trace.polarVector===void 0&&e.polar.vectors.directions.length>0)return null;if(n.directions.length>0){let t=n.directions.map(t=>qr({angle:t.angle,value:e.maxRadius,style:t,fallbackColor:r,polar:e.polar,geometry:e.geometry}));return{type:`polar`,points:t.map(e=>({x:e.endX,y:e.endY})),color:r,lineWidth:n.lineWidth,polarVectors:t,subplot:e.subplot,bounds:e.bounds}}let i=[];for(let t of e.trace.data){if(t.x===null||t.y===null)continue;let a=Er(t.x,e.polar),o=c(t.y,{scale:`linear`});if(o<0)throw Error(`Polar windrose values require y >= 0`);o!==0&&i.push(qr({angle:a,value:o,style:n,fallbackColor:r,polar:e.polar,geometry:e.geometry}))}return i.length===0?null:{type:`polar`,points:i.map(e=>({x:e.endX,y:e.endY})),color:r,lineWidth:n.lineWidth,polarVectors:i,subplot:e.subplot,bounds:e.bounds}}function Xr(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||!Array.isArray(t.primitives)?null:t}function Zr(e){return Xr(re(e))||Xr(ue(e))||null}function Qr(e){let t=Sr(e.polar),n=pe(e);Dr(n,t);let r=Or(e),i=Ar(n,t),a=kr(n,t,i),o=jr(n),s=[...a.entries()].flatMap(([e,n])=>{let i=r.get(e);if(!i)throw Error(`Unknown subplot id '${e}' for trace`);let a=Kr({polar:t,subplot:e,bounds:i,geometry:Nr(i,t),domain:n});return a?[a]:[]}),l=n.flatMap((n,s)=>{if(n.visible===!1)return[];let l=n.subplot??`main`,u=r.get(l);if(!u)throw Error(`Unknown subplot id '${l}' for trace`);let d=a.get(l);if(!d)return[];let f=Nr(u,t),p=o.get(l)??[s],m=t.sectorMode===`stacked`?0:Math.max(0,p.indexOf(s)),h=t.sectorMode===`stacked`?1:Math.max(1,p.length),g=t.sectorWidthDegrees/h,_=wr(e,n,s),v=Cr(t,n.polar),y=i.get(s);if(e.engine===`rust`){let r=[],i=[],a=[];n.data.forEach((e,n)=>{if(e.x===null||e.y===null)return;let o=t.angleCategories.length>0?Er(e.x,t):c(e.x,{scale:`linear`}),s=c(e.y,{scale:`linear`});if(s<=0)return;let l=y?.get(n);r.push({x:o,y:l?.totalValue??s}),l&&(i.push(l.baseValue),a.push(s))});let o=Zr({width:e.width,height:e.height,traces:[{points:r,innerValues:y?i:void 0,values:y?a:void 0,centerX:f.centerX,centerY:f.centerY,innerRadius:f.innerRadius,availableRadius:f.availableRadius,sectorWidthDegrees:t.sectorWidthDegrees,sectorGapDegrees:v.sectorGapDegrees,startAngleDegrees:t.startAngleDegrees,clockwise:t.clockwise,radialScale:t.radialScale,minRadius:d.minRadius,maxRadius:d.maxRadius,groupIndex:m,groupCount:h,color:_,lineWidth:v.borderWidth,borderColor:v.borderColor,borderWidth:v.borderWidth,subplot:l,bounds:u}]});if(!o)throw Error(`Rust polar scene engine is not available in current runtime`);let p=o.primitives[0];if(!p)return[];let g=n.data.flatMap((e,t)=>e.x===null||e.y===null?[]:c(e.y,{scale:`linear`})>0?[t]:[]);return[{...Wr({...p,polarSectors:p.polarSectors?.map((e,t)=>({...e,opacity:v.sectorOpacity,sourceIndex:g[t]??t}))},v),traceIndex:s}]}let b=[];for(let[e,r]of n.data.entries()){if(r.x===null||r.y===null)continue;let n=Er(r.x,t),i=c(r.y,{scale:`linear`});if(t.radialScale===`logarithmic`&&i<=0)throw Error(`Polar logarithmic radial scale requires y > 0`);if(i<0)throw Error(`Polar windrose values require y >= 0`);if(i===0)continue;let a=t.startAngleDegrees+(t.clockwise?n:-n),o=Math.min(v.sectorGapDegrees,g*.95),s=a-t.sectorWidthDegrees/2+m*g+o/2,l=s+g-o,u=y?.get(e),p=u?Fr(u.baseValue,d,t.radialScale,f):f.innerRadius,h=Fr(u?.totalValue??i,d,t.radialScale,f);b.push({centerX:f.centerX,centerY:f.centerY,innerRadius:p,outerRadius:h,startAngle:Mr(s),endAngle:Mr(l),angle:n,value:i,opacity:v.sectorOpacity,sourceIndex:e})}return b.length===0?[]:[Wr({type:`polar`,points:b.map(e=>({x:e.centerX+Math.cos((e.startAngle+e.endAngle)/2)*e.outerRadius,y:e.centerY+Math.sin((e.startAngle+e.endAngle)/2)*e.outerRadius})),polarSectors:b,color:_,lineWidth:v.borderWidth,borderColor:v.borderColor,borderWidth:v.borderWidth,traceIndex:s,subplot:l,bounds:u},v)]}),u=[...a.entries()].flatMap(([e,n])=>{let i=r.get(e);if(!i)throw Error(`Unknown subplot id '${e}' for trace`);let a=Jr({polar:t,subplot:e,bounds:i,geometry:Nr(i,t),maxRadius:n.maxRadius});return a?[a]:[]}),d=n.flatMap((n,i)=>{if(n.visible===!1)return[];let o=n.subplot??`main`,s=r.get(o);if(!s)throw Error(`Unknown subplot id '${o}' for trace`);let c=a.get(o);if(!c)return[];let l=Yr({polar:t,options:e,trace:n,traceIndex:i,subplot:o,bounds:s,geometry:Nr(s,t),maxRadius:c.maxRadius});return l?[l]:[]});return Hr({width:e.width,height:e.height,primitives:[...s,...l,...u,...d]},t,n)}let K={valueScale:`linear`,markerSize:5,markerOpacity:1,markerShape:`circle`,lowColor:`#e0f2fe`,highColor:`#7c3aed`,colorStops:[],sizeScale:{enabled:!1,minSize:3,maxSize:14,minValue:null,maxValue:null},opacityScale:{enabled:!1,minOpacity:.2,maxOpacity:1,minValue:null,maxValue:null},borderWidth:0,borderColor:`rgba(15, 23, 42, 0.28)`,markerLabels:{show:!1,color:`#0f172a`,font:`11px system-ui, sans-serif`,lineHeight:14,decimals:0,prefix:``,suffix:``,offsetY:6,collisionPadding:2,formatter:null},colorScaleLegend:{show:!1,position:`right`,title:``,width:12,height:128,offset:16,tickCount:3,tickValues:[],tickSize:6,labelGap:6,labelPrefix:``,labelSuffix:``,decimals:0,font:`11px system-ui, sans-serif`,color:`#475569`,lineHeight:14,titleGap:4,borderColor:`rgba(15, 23, 42, 0.28)`,borderWidth:1}};function $r(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<0?t:e}function ei(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<=0?t:e}function ti(e,t,n,r){return typeof e!=`number`||!Number.isFinite(e)?t:Math.min(r,Math.max(n,Math.round(e)))}function ni(e,t,n){let r=Array.isArray(e)?e:t;if(n===`logarithmic`&&r.some(e=>typeof e!=`number`||!Number.isFinite(e)||e<=0))throw Error(`wonderplot.colorScaleLegend.tickValues must contain only finite values > 0 for logarithmic scales`);return[...new Set(r.filter(e=>typeof e==`number`&&Number.isFinite(e)))].sort((e,t)=>e-t)}function ri(t,n=K.markerSize){return typeof t!=`number`||!Number.isFinite(t)?n:Math.max(e.minSize,t)}function ii(e){return Math.min(1,Math.max(0,e))}function ai(e,t=K.markerOpacity,n=`wonderplot.markerOpacity`){if(e===void 0)return t;if(typeof e!=`number`||!Number.isFinite(e))throw Error(`${n} must be finite`);return ii(e)}function oi(e){return typeof e==`object`&&e?e:void 0}function si(e,t){if(e!==void 0){if(Number.isFinite(e))return e;throw Error(`${t} must be finite`)}}function ci(e){if(e.size===null||e.size===void 0)return null;if(typeof e.size!=`number`||!Number.isFinite(e.size))throw Error(`Wonderplot sizeScale points require a finite numeric 'size' field`);return e.size}function li(t){let n=t.wonderplot?.sizeScale,r=oi(n);if(!(typeof n==`boolean`?n:r?r.enabled??!0:K.sizeScale.enabled))return null;let i=r?.minSize??K.sizeScale.minSize,a=r?.maxSize??K.sizeScale.maxSize;if(!Number.isFinite(i)||i<e.minSize)throw Error(`wonderplot.sizeScale.minSize must be >= ${e.minSize}`);if(!Number.isFinite(a)||a<i)throw Error(`wonderplot.sizeScale.maxSize must be >= minSize`);let o=[];for(let e of Oe(t))if(e.trace.visible!==!1)for(let t of e.trace.data){if(t.x===null||t.y===null)continue;let e=ci(t);if(e===null)throw Error(`Wonderplot sizeScale points require a finite numeric 'size' field`);o.push(e)}if(o.length===0)return null;let s=si(r?.minValue,`wonderplot.sizeScale.minValue`),c=si(r?.maxValue,`wonderplot.sizeScale.maxValue`),l=s??Math.min(...o),u=c??Math.max(...o);if(l>u)throw Error(`wonderplot.sizeScale.minValue must be <= maxValue`);return{minSize:i,maxSize:a,minValue:l,maxValue:u}}function ui(e,t){if(t.minValue===t.maxValue)return(t.minSize+t.maxSize)/2;let n=Math.min(1,Math.max(0,(e-t.minValue)/(t.maxValue-t.minValue)));return t.minSize+(t.maxSize-t.minSize)*n}function di(e){return typeof e==`object`&&e?e:void 0}function fi(e){if(e.opacity===null||e.opacity===void 0)return null;if(typeof e.opacity!=`number`||!Number.isFinite(e.opacity))throw Error(`Wonderplot opacityScale points require a finite numeric 'opacity' field`);return e.opacity}function pi(e){let t=e.wonderplot?.opacityScale,n=di(t);if(!(typeof t==`boolean`?t:n?n.enabled??!0:K.opacityScale.enabled))return null;let r=n?.minOpacity??K.opacityScale.minOpacity,i=n?.maxOpacity??K.opacityScale.maxOpacity;if(!Number.isFinite(r))throw Error(`wonderplot.opacityScale.minOpacity must be finite`);if(!Number.isFinite(i))throw Error(`wonderplot.opacityScale.maxOpacity must be finite`);let a=ii(r),o=ii(i);if(o<a)throw Error(`wonderplot.opacityScale.maxOpacity must be >= minOpacity`);let s=[];for(let t of Oe(e))if(t.trace.visible!==!1)for(let e of t.trace.data){if(e.x===null||e.y===null)continue;let t=fi(e);if(t===null)throw Error(`Wonderplot opacityScale points require a finite numeric 'opacity' field`);s.push(t)}if(s.length===0)return null;let c=si(n?.minValue,`wonderplot.opacityScale.minValue`),l=si(n?.maxValue,`wonderplot.opacityScale.maxValue`),u=c??Math.min(...s),d=l??Math.max(...s);if(u>d)throw Error(`wonderplot.opacityScale.minValue must be <= maxValue`);return{minOpacity:a,maxOpacity:o,minValue:u,maxValue:d}}function mi(e,t){if(t.minValue===t.maxValue)return(t.minOpacity+t.maxOpacity)/2;let n=Math.min(1,Math.max(0,(e-t.minValue)/(t.maxValue-t.minValue)));return t.minOpacity+(t.maxOpacity-t.minOpacity)*n}function hi(...e){return[...e].reverse().find(e=>typeof e==`string`&&e.trim().length>0)}function gi(e){return typeof e==`string`&&e.trim().length>0?e.trim():void 0}function _i(e){return typeof e==`object`&&e?e:void 0}function vi(e){return typeof e==`object`&&e?e:void 0}function yi(e,t){if(t===void 0)return e;let n=vi(t);return{show:typeof t==`boolean`?t:n?n.show??!0:e.show,color:hi(e.color,n?.color)??e.color,font:hi(e.font,n?.font)??e.font,lineHeight:$r(n?.lineHeight,e.lineHeight),decimals:ti(n?.decimals,e.decimals,0,6),prefix:typeof n?.prefix==`string`?n.prefix:e.prefix,suffix:typeof n?.suffix==`string`?n.suffix:e.suffix,offsetY:$r(n?.offsetY,e.offsetY),collisionPadding:$r(n?.collisionPadding,e.collisionPadding)}}function bi(e,t){return yi(yi({...K.markerLabels},e),t)}function xi(e,t){let n=_i(e),r=typeof e==`boolean`?e:n?n.show??!0:K.colorScaleLegend.show,i=n?.position===`left`||n?.position===`right`||n?.position===`top`||n?.position===`bottom`?n.position:K.colorScaleLegend.position,a=i===`top`||i===`bottom`;return{show:r,position:i,title:gi(n?.title??K.colorScaleLegend.title),width:ei(n?.width,a?K.colorScaleLegend.height:K.colorScaleLegend.width),height:ei(n?.height,a?K.colorScaleLegend.width:K.colorScaleLegend.height),offset:$r(n?.offset,K.colorScaleLegend.offset),tickCount:ti(n?.tickCount,K.colorScaleLegend.tickCount,2,8),tickValues:ni(n?.tickValues,K.colorScaleLegend.tickValues,t),tickSize:$r(n?.tickSize,K.colorScaleLegend.tickSize),labelGap:$r(n?.labelGap,K.colorScaleLegend.labelGap),labelPrefix:typeof n?.labelPrefix==`string`?n.labelPrefix:K.colorScaleLegend.labelPrefix,labelSuffix:typeof n?.labelSuffix==`string`?n.labelSuffix:K.colorScaleLegend.labelSuffix,decimals:ti(n?.decimals,K.colorScaleLegend.decimals,0,6),color:hi(K.colorScaleLegend.color,n?.color)??K.colorScaleLegend.color,font:hi(K.colorScaleLegend.font,n?.font)??K.colorScaleLegend.font,lineHeight:ei(n?.lineHeight,K.colorScaleLegend.lineHeight),titleGap:$r(n?.titleGap,K.colorScaleLegend.titleGap),borderColor:hi(K.colorScaleLegend.borderColor,n?.borderColor)??K.colorScaleLegend.borderColor,borderWidth:$r(n?.borderWidth,K.colorScaleLegend.borderWidth)}}function Si(e,t,r){let i=Mt(e.wonderplot?.colorScale?.valueScale,K.valueScale,`wonderplot.colorScale.valueScale`),a=n[r%n.length],o=hi(K.lowColor,e.wonderplot?.colorScale?.lowColor)??K.lowColor,s=hi(K.highColor,a,e.style?.trace?.line?.color,e.lineStyle?.color,e.wonderplot?.colorScale?.highColor,t.color,t.lineStyle?.color)??K.highColor,c=Rt(e.wonderplot?.colorScale?.colorStops??K.colorStops,o,s,`wonderplot.colorScale.colorStops`);return{valueScale:i,markerSize:ri(t.wonderplot?.markerSize,ri(e.wonderplot?.markerSize)),markerOpacity:ai(t.wonderplot?.markerOpacity,ai(e.wonderplot?.markerOpacity),`trace.wonderplot.markerOpacity`),markerShape:jt(t.wonderplot?.markerShape,jt(e.wonderplot?.markerShape,K.markerShape,`wonderplot.markerShape`),`trace.wonderplot.markerShape`),lowColor:o,highColor:s,colorStops:c,borderWidth:$r(t.wonderplot?.borderWidth,$r(e.wonderplot?.borderWidth,K.borderWidth)),borderColor:hi(K.borderColor,e.wonderplot?.borderColor,t.wonderplot?.borderColor)??K.borderColor,markerLabels:bi(e.wonderplot?.markerLabels,t.wonderplot?.markerLabels),colorScaleLegend:xi(e.wonderplot?.colorScaleLegend,i)}}function Ci(e){let t=e.value??e.z;return t==null?null:c(t,{scale:`linear`})}function wi(e){let t=Ee(e),n=De(e),r=new Map,i=new Map;for(let a of Oe(e)){if(a.trace.visible===!1)continue;let o=t.get(a.xAxisId)??{},s=n.get(a.yAxisId)??{},l=_(e.errorBars,a.trace.errorBars,``);for(let[e,t]of a.trace.data.entries())t.x===null||t.y===null||(r.has(a.xAxisId)||r.set(a.xAxisId,[]),i.has(a.yAxisId)||i.set(a.yAxisId,[]),r.get(a.xAxisId)?.push(c(t.x,o)),i.get(a.yAxisId)?.push(c(t.y,s)),x(t,e,l,o,s,r.get(a.xAxisId),i.get(a.yAxisId)))}let a=new Map,o=new Map;for(let[e,n]of t.entries()){let t=A(r.get(e)??[],n);t&&a.set(e,t)}for(let[e,t]of n.entries()){let n=A(i.get(e)??[],t);n&&o.set(e,n)}return{x:a,y:o}}function Ti(e){let t=Mt(e.wonderplot?.colorScale?.valueScale,K.valueScale,`wonderplot.colorScale.valueScale`),n=[];for(let r of Oe(e))if(r.trace.visible!==!1)for(let e of r.trace.data){if(e.x===null||e.y===null)continue;let r=Ci(e);if(r===null)throw Error(`Wonderplot points require a numeric 'value' or 'z' field for color-scale markers`);if(t===`logarithmic`&&r<=0)throw Error(`Wonderplot logarithmic colorScale requires value/z > 0`);n.push(r)}if(n.length===0)return null;if(t===`logarithmic`&&e.wonderplot?.colorScale?.minValue!==void 0&&(typeof e.wonderplot.colorScale.minValue!=`number`||!Number.isFinite(e.wonderplot.colorScale.minValue)||e.wonderplot.colorScale.minValue<=0))throw Error(`Wonderplot logarithmic colorScale.minValue must be finite and > 0`);if(t===`logarithmic`&&e.wonderplot?.colorScale?.maxValue!==void 0&&(typeof e.wonderplot.colorScale.maxValue!=`number`||!Number.isFinite(e.wonderplot.colorScale.maxValue)||e.wonderplot.colorScale.maxValue<=0))throw Error(`Wonderplot logarithmic colorScale.maxValue must be finite and > 0`);let r=typeof e.wonderplot?.colorScale?.minValue==`number`&&Number.isFinite(e.wonderplot.colorScale.minValue)?e.wonderplot.colorScale.minValue:void 0,i=typeof e.wonderplot?.colorScale?.maxValue==`number`&&Number.isFinite(e.wonderplot.colorScale.maxValue)?e.wonderplot.colorScale.maxValue:void 0,a=r??Math.min(...n),o=i??Math.max(...n);if(!(a<=o))throw Error(`Wonderplot colorScale minValue must be <= maxValue`);return{minValue:a,maxValue:o,valueScale:t}}function Ei(e,t,n,r,i=!1){let o=l(e,a(n)),s=Math.max(t.max-t.min,2**-52),c=(o-t.min)/s*r;return i?r-c:c}function Di(e,t,n){return e.x>=0&&e.x<=t&&e.y>=0&&e.y<=n}function Oi(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function ki(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function Ai(e,t){let n=t.markerLabels;if(!n.show)return;let r=e.map(e=>({x:e.x,y:e.y-e.size-n.offsetY,value:e.value,sourceIndex:e.sourceIndex,text:ki(e.value,n.decimals,n.prefix,n.suffix),color:n.color,font:n.font,lineHeight:n.lineHeight,collisionPadding:n.collisionPadding}));return r.length>0?r:void 0}function ji(e,t,n,r){let i=r.colorScaleLegend;if(!i.show)return;let a=i.position===`top`||i.position===`bottom`,o=i.title?i.lineHeight+i.titleGap:0;if(a){let a=Math.min(i.width,Math.max(1,t)),s=Math.max(0,(t-a)/2),c=o+i.height+i.tickSize+i.labelGap+i.lineHeight,l=(i.position===`top`?-(i.offset+c):n+i.offset)+o,u=Pt(e.minValue,e.maxValue,i.tickCount,i.tickValues,e.valueScale),d=u.map((t,n)=>{let r=Ft(t,e.minValue,e.maxValue,n,u.length,e.valueScale);return{value:t,text:Oi(t,i.decimals,i.labelPrefix,i.labelSuffix),x:s+r*a,y:l+i.height}});return{valueScale:e.valueScale,position:i.position,x:s,y:l,width:a,height:i.height,minValue:e.minValue,maxValue:e.maxValue,lowColor:r.colorStops[0].color,highColor:r.colorStops[r.colorStops.length-1].color,colorStops:r.colorStops,title:i.title,ticks:d,tickSize:i.tickSize,labelGap:i.labelGap,labelPrefix:i.labelPrefix,labelSuffix:i.labelSuffix,color:i.color,font:i.font,lineHeight:i.lineHeight,titleGap:i.titleGap,borderColor:i.borderColor,borderWidth:i.borderWidth}}let s=Math.max(1,n-o),c=Math.min(i.height,s),l=c+o,u=Math.max(0,(n-l)/2)+o,d=Pt(e.minValue,e.maxValue,i.tickCount,i.tickValues,e.valueScale),f=d.map((t,n)=>{let r=Ft(t,e.minValue,e.maxValue,n,d.length,e.valueScale);return{value:t,text:Oi(t,i.decimals,i.labelPrefix,i.labelSuffix),y:u+c-r*c}});return{valueScale:e.valueScale,position:i.position,x:i.position===`left`?-(i.offset+i.width):t+i.offset,y:u,width:i.width,height:c,minValue:e.minValue,maxValue:e.maxValue,lowColor:r.colorStops[0].color,highColor:r.colorStops[r.colorStops.length-1].color,colorStops:r.colorStops,title:i.title,ticks:f,tickSize:i.tickSize,labelGap:i.labelGap,labelPrefix:i.labelPrefix,labelSuffix:i.labelSuffix,color:i.color,font:i.font,lineHeight:i.lineHeight,titleGap:i.titleGap,borderColor:i.borderColor,borderWidth:i.borderWidth}}function Mi(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||!Array.isArray(t.primitives)?null:t}function Ni(e){return Mi(V(e))||Mi(le(e))||null}function Pi(e){ke(e);let t={...e,axes:Fn(e.axes,e.viewport)},n=Ee(t),r=De(t),i=we(t),o=new Map(i.map(e=>[e.id,e])),s=Oe(t),l=wi(t),u=Ti(t);if(!u)return{width:e.width,height:e.height,primitives:[]};let d=li(t),f=pi(t),p=new Set,m=s.flatMap((t,i)=>{let{trace:s,subplotId:m,xAxisId:h,yAxisId:g}=t;if(s.visible===!1)return[];let v=o.get(m);if(!v)throw Error(`Unknown subplot id '${m}' for trace`);let y=n.get(h)??{},b=r.get(g)??{},x=l.x.get(h),S=l.y.get(g);if(!x||!S)return[];let C=Math.max(1,v.bounds.right-v.bounds.left),T=Math.max(1,v.bounds.bottom-v.bounds.top),E=Si(e,s,i),D=_(e.errorBars,s.errorBars,E.highColor),O=[],k=[];if(s.data.forEach((e,t)=>{if(e.x===null||e.y===null)return;let n=Ci(e);if(n===null)throw Error(`Wonderplot points require a numeric 'value' or 'z' field for color-scale markers`);let r=c(e.x,y),i=c(e.y,b),a={x:Ei(r,x,y,C),y:Ei(i,S,b,T,!0)};if(!Di(a,C,T))return;let o=zt(n,u.minValue,u.maxValue,E.colorStops,u.valueScale),s=d?ci(e):null;if(d&&s===null)throw Error(`Wonderplot sizeScale points require a finite numeric 'size' field`);let l=d&&s!==null?ui(s,d):E.markerSize,p=f?fi(e):null;if(f&&p===null)throw Error(`Wonderplot opacityScale points require a finite numeric 'opacity' field`);let m=f&&p!==null?mi(p,f):E.markerOpacity;O.push({...a,value:n,sourceIndex:t,size:l,...s===null?{}:{sizeValue:s},opacity:m,...p===null?{}:{opacityValue:p},fillColor:o}),k.push({x:r,y:i,value:n,sourceIndex:t,size:l,...s===null?{}:{sizeValue:s},opacity:m,...p===null?{}:{opacityValue:p},fillColor:o})}),O.length===0)return[];let A=p.has(m)?void 0:ji(u,C,T,E);p.add(m);let j=Ai(O,E),M=w(s,D,y,b,x,S,C,T);if(e.engine===`rust`){let t=Ni({width:e.width,height:e.height,traces:[{points:k,subplotWidth:C,subplotHeight:T,xDomain:x,yDomain:S,xScale:a(y),yScale:a(b),color:E.highColor,lineWidth:E.borderWidth,borderColor:E.borderColor,borderWidth:E.borderWidth,subplot:m,bounds:v.bounds}]});if(!t)throw Error(`Rust wonderplot scene engine is not available in current runtime`);let n=t.primitives[0];return n?[{...n,traceIndex:i,markerShape:E.markerShape,wonderplotMarkerLabels:j,wonderplotColorScaleLegend:A,...M?{errorBars:M,errorBarStyle:D.style}:{}}]:[]}return[{type:`wonderplot`,points:O.map(e=>({x:e.x,y:e.y})),wonderPoints:O,wonderplotMarkerLabels:j,wonderplotColorScaleLegend:A,...M?{errorBars:M,errorBarStyle:D.style}:{},traceIndex:i,markerShape:E.markerShape,color:E.highColor,lineWidth:E.borderWidth,borderColor:E.borderColor,borderWidth:E.borderWidth,subplot:m,bounds:v.bounds}]});return{width:e.width,height:e.height,primitives:m}}let Fi={lineWidth:2,lineOpacity:1,minimumHitRadius:1,interpolation:`linear`,smoothSamplesPerSegment:12,lod:{enabled:!1,strategy:`largest-triangle-3d`,maxSourceSegments:250},maxSegments:1e6},Ii={opacity:.82,maxFaces:5e5,lod:{strategy:`largest-area-stratified`,maxFaces:1e3},backfaceCulling:!1,wireframeShow:!1,wireframeColor:`#0f172a`,wireframeWidth:1,wireframeOpacity:.65},Li={extrusionDepth:.15,curveTolerance:1,seamStrokeWidth:1,seamLineJoin:`round`,maxCurveStepDegrees:90},q={markerSize:6,markerOpacity:.9,markerShape:`circle`,lod:{enabled:!1,strategy:`spatial-grid`,maxPoints:5e3},valueScale:`linear`,lowColor:`#e0f2fe`,highColor:`#7c3aed`,colorStops:[],sizeScale:{enabled:!1,minSize:3,maxSize:14,minValue:null,maxValue:null},opacityScale:{enabled:!1,minOpacity:.2,maxOpacity:1,minValue:null,maxValue:null},colorScaleLegend:!0,legendWidth:12,legendHeight:120,legendOffset:12,legendTitle:`value`,legendTickCount:3,legendFont:`11px system-ui, sans-serif`,legendColor:`#475569`,legendLabelGap:4,legendGlyphWidth:7,legendMinimumLabelHeight:32},J={lowColor:`#0ea5e9`,highColor:`#f97316`,colorStops:[],opacity:1,wireframeShow:!1,wireframeColor:`#0f172a`,wireframeWidth:1,wireframeOpacity:.65,contourShow:!1,contourCount:5,contourColor:`#0f172a`,contourWidth:1.25,contourOpacity:.8,maxContourLevels:32,lod:{enabled:!1,strategy:`grid-stride`,maxCells:1e4},missingCells:`gap`,maxTriangles:2e5,maxContourSegments:5e5,colorScaleLegend:!0,legendWidth:12,legendHeight:120,legendOffset:12,legendTitle:`z`,legendTickCount:3,legendFont:`11px system-ui, sans-serif`,legendColor:`#475569`,legendLabelGap:4,legendGlyphWidth:7,legendMinimumLabelHeight:32};function Ri(e,t){return Math.min(e.right,t.right)-Math.max(e.left,t.left)>1e-12&&Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)>1e-12}function zi(e){if(e.subplots===void 0){if(pe(e).some(e=>e.subplot!==void 0))throw Error(`experimental ${e.type} subplot bindings require a subplots layout`);return{subplotId:`scene3d`,bounds:{left:0,top:0,right:e.width,bottom:e.height},width:e.width,height:e.height}}let t=we(e),n=Te(e),r=new Set(n.map(e=>e.subplotId));if(r.size===0&&t.length===1&&r.add(t[0].id),r.size!==1)throw Error(`experimental ${e.type} requires every trace to bind to exactly one shared 3D subplot`);let i=[...r][0],a=t.find(e=>e.id===i);if(!a)throw Error(`Unknown subplot id '${i}' for experimental ${e.type}`);let o=t.find(e=>e.id!==i&&Ri(a.bounds,e.bounds));if(o)throw Error(`experimental ${e.type} subplot '${i}' overlaps subplot '${o.id}'`);let s=Math.max(1,a.bounds.right-a.bounds.left),c=Math.max(1,a.bounds.bottom-a.bounds.top);return{subplotId:i,bounds:{...a.bounds},width:s,height:c}}function Y(e,t){if(typeof e!=`number`||!Number.isFinite(e))throw Error(`scene3d requires finite numeric ${t}`);return e}function Bi(e,t,n){let r=e??t;if(!Array.isArray(r)||r.length!==3)throw Error(`scene3d.camera.${n} must contain exactly three finite numbers`);return[Y(r[0],`scene3d.camera.${n}[0]`),Y(r[1],`scene3d.camera.${n}[1]`),Y(r[2],`scene3d.camera.${n}[2]`)]}function X(e){return{x:e[0],y:e[1],z:e[2]}}function Z(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function Vi(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function Hi(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function Ui(e){return Math.hypot(e.x,e.y,e.z)}function Wi(e,t){let n=Ui(e);if(!(n>1e-12))throw Error(`${t} must not be degenerate`);return{x:e.x/n,y:e.y/n,z:e.z/n}}function Gi(e){let t=e?.projection??r.projection;if(t!==`perspective`&&t!==`orthographic`)throw Error(`scene3d.camera.projection must be 'perspective' or 'orthographic'`);let n=Bi(e?.eye,r.eye,`eye`),i=Bi(e?.target,r.target,`target`),a=Bi(e?.up,r.up,`up`),o=e?.fieldOfViewDegrees??r.fieldOfViewDegrees,s=e?.orthographicScale??r.orthographicScale,c=e?.near??r.near,l=e?.far??r.far;if(!Number.isFinite(o)||o<=1||o>=179)throw Error(`scene3d.camera.fieldOfViewDegrees must be finite and between 1 and 179`);if(!Number.isFinite(s)||s<=0)throw Error(`scene3d.camera.orthographicScale must be a positive finite number`);if(!Number.isFinite(c)||!Number.isFinite(l)||c<=0||l<=c)throw Error(`scene3d.camera clipping requires 0 < near < far`);return Wi(Hi(Wi(Z(X(i),X(n)),`scene3d camera eye/target direction`),Wi(X(a),`scene3d.camera.up`)),`scene3d camera up direction`),{projection:t,eye:n,target:i,up:a,fieldOfViewDegrees:o,orthographicScale:s,near:c,far:l}}function Ki(e,t){return e.x===null||e.x===void 0||e.y===null||e.y===void 0||e.z===null||e.z===void 0?null:{x:Y(e.x,`traces[].data[${t}].x`),y:Y(e.y,`traces[].data[${t}].y`),z:Y(e.z,`traces[].data[${t}].z`)}}function qi(e){let t=e?.padding??r.axisPadding;if(!Number.isFinite(t)||t<0||t>.45)throw Error(`scene3d axis padding must be finite and between 0 and 0.45`);return t}function Ji(e,t){if(!Number.isFinite(e.min)||!Number.isFinite(e.max))throw Error(`scene3d.${t}Axis domain endpoints must remain finite`);let n=e.max-e.min;if(!Number.isFinite(n)||n===0)throw Error(`scene3d.${t}Axis domain span must be finite and non-zero`);return e}function Yi(e,t,n,r){if(n?.range!==void 0){let e=Y(n.range.min,`scene3d.${r}Axis.range.min`),t=Y(n.range.max,`scene3d.${r}Axis.range.max`);if(e===t)throw Error(`scene3d.${r}Axis.range must have distinct endpoints`);return Ji({min:e,max:t},r)}if(e===void 0||t===void 0)return{min:-1,max:1};let i=e,a=t;if(i===a){let e=Math.max(.5,Math.abs(i)*.05);i-=e,a+=e}else{let e=a-i;if(!Number.isFinite(e))throw Error(`scene3d.${r}Axis inferred domain span must remain finite`);let t=e*qi(n);i-=t,a+=t}return Ji({min:i,max:a},r)}function Xi(e,t,n){let r,i;for(let t of e)r=r===void 0?t:Math.min(r,t),i=i===void 0?t:Math.max(i,t);return Yi(r,i,t,n)}function Zi(e,t,n){let r=pe(e),i=t??r.map((e,t)=>t),a=n?e.scene3d?.subplots?.[n]:void 0,o={x:a?.xAxis??e.scene3d?.xAxis,y:a?.yAxis??e.scene3d?.yAxis,z:a?.zAxis??e.scene3d?.zAxis},s={x:{},y:{},z:{}},c=(e,t)=>{let n=s[e];n.min=n.min===void 0?t:Math.min(n.min,t),n.max=n.max===void 0?t:Math.max(n.max,t)},l=e.surface?.missingCells??J.missingCells;for(let t of i){let n=r[t];!n||n.visible===!1||n.data.forEach((t,n)=>{if(e.type===`surface`){if(t.x===null||t.y===null)return;let e=t.z===null||t.z===void 0?l===`zero`?0:null:Y(t.z,`traces[].data[${n}].z`);if(e===null)return;c(`x`,Y(t.x,`traces[].data[${n}].x`)),c(`y`,Y(t.y,`traces[].data[${n}].y`)),c(`z`,e);return}let r=Ki(t,n);r&&(c(`x`,r.x),c(`y`,r.y),c(`z`,r.z))})}return{x:Yi(s.x.min,s.x.max,o.x,`x`),y:Yi(s.y.min,s.y.max,o.y,`y`),z:Yi(s.z.min,s.z.max,o.z,`z`)}}function Q(e,t){return(e-t.min)/(t.max-t.min)-.5}function Qi(e,t){let n=Math.min(t.min,t.max),r=Math.max(t.min,t.max);return e>=n&&e<=r}function $i(e){if(e===void 0||e===!1)return null;if(e===null||e!==!0&&(typeof e!=`object`||Array.isArray(e)))throw Error(`scatter3d.lod must be a boolean or an options object`);let t=e===!0?{}:e,n=t.enabled??!0;if(typeof n!=`boolean`)throw Error(`scatter3d.lod.enabled must be a boolean`);let r=t.strategy??q.lod.strategy;if(r!==`spatial-grid`)throw Error(`scatter3d.lod.strategy must be 'spatial-grid'`);let i=t.maxPoints??q.lod.maxPoints;if(!Number.isInteger(i)||i<1||i>1e6)throw Error(`scatter3d.lod.maxPoints must be an integer between 1 and 1000000`);return n?{strategy:r,maxPoints:i}:null}function ea(e,t){return Math.min(1,Math.max(0,Q(e,t)+.5))}function ta(e,t,n){let r=e=>Math.round(e*1023),i=r(e),a=r(t),o=r(n),s=0;for(let e=0;e<10;e+=1)s|=(i>>e&1)<<e*3,s|=(a>>e&1)<<e*3+1,s|=(o>>e&1)<<e*3+2;return s>>>0}function na(e,t){return e.mortonCode-t.mortonCode||e.traceIndex-t.traceIndex||e.parsed.sourceIndex-t.parsed.sourceIndex}function ra(e,t){return t<=0||e.length===0?[]:t>=e.length?[...e]:t===1?[e[Math.floor((e.length-1)/2)]]:Array.from({length:t},(n,r)=>e[Math.floor(r*(e.length-1)/(t-1))])}function ia(e,t,n){let r=[];if(e.forEach((e,n)=>{e.forEach(e=>{if(!Qi(e.point.x,t.x)||!Qi(e.point.y,t.y)||!Qi(e.point.z,t.z))return;let i=ea(e.point.x,t.x),a=ea(e.point.y,t.y),o=ea(e.point.z,t.z);r.push({traceIndex:n,parsed:e,xRatio:i,yRatio:a,zRatio:o,mortonCode:ta(i,a,o)})})}),r.length<=n)return{selected:new Set(r.map(e=>e.parsed)),candidatePointCount:r.length};let i=new Map;for(let e of r){let t=i.get(e.traceIndex),n=(e.xRatio-.5)**2+(e.yRatio-.5)**2+(e.zRatio-.5)**2,r=t?(t.xRatio-.5)**2+(t.yRatio-.5)**2+(t.zRatio-.5)**2:1/0;(n<r||n===r&&e.parsed.sourceIndex<(t?.parsed.sourceIndex??1/0))&&i.set(e.traceIndex,e)}let a=new Set,o=[...i.values()].sort((e,t)=>e.traceIndex-t.traceIndex);for(let e of ra(o,Math.min(n,o.length)))a.add(e);if(a.size<n){let e=Math.max(1,Math.floor(Math.cbrt(n))),t=new Map;for(let n of r){let r=Math.min(e-1,Math.floor(n.xRatio*e)),i=Math.min(e-1,Math.floor(n.yRatio*e)),a=Math.min(e-1,Math.floor(n.zRatio*e)),o=(r+.5)/e,s=(i+.5)/e,c=(a+.5)/e,l=(n.xRatio-o)**2+(n.yRatio-s)**2+(n.zRatio-c)**2,u=`${r}:${i}:${a}`,d=t.get(u);(!d||l<d.distance||l===d.distance&&na(n,d.candidate)<0)&&t.set(u,{candidate:n,distance:l})}let i=[...t.values()].map(({candidate:e})=>e).filter(e=>!a.has(e)).sort(na);for(let e of ra(i,Math.min(n-a.size,i.length)))a.add(e)}if(a.size<n){let e=r.filter(e=>!a.has(e)).sort(na);for(let t of ra(e,Math.min(n-a.size,e.length)))a.add(t)}return{selected:new Set([...a].map(e=>e.parsed)),candidatePointCount:r.length}}function aa(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}}function oa(e){let t=e===void 0?Fi.interpolation:e;if(t!==`linear`&&t!==`smooth`)throw Error(`line3d.interpolation must be 'linear' or 'smooth'`);return t}function sa(e){if(e===void 0||e===!1)return null;if(e===null||e!==!0&&(typeof e!=`object`||Array.isArray(e)))throw Error(`line3d.lod must be a boolean or an options object`);let t=e===!0?{}:e,n=t.enabled??!0;if(typeof n!=`boolean`)throw Error(`line3d.lod.enabled must be a boolean`);let r=t.strategy??Fi.lod.strategy;if(r!==`largest-triangle-3d`)throw Error(`line3d.lod.strategy must be 'largest-triangle-3d'`);let i=t.maxSourceSegments??Fi.lod.maxSourceSegments;if(!Number.isInteger(i)||i<1||i>1e6)throw Error(`line3d.lod.maxSourceSegments must be an integer between 1 and 1000000`);return n?{strategy:r,maxSourceSegments:i}:null}function ca(e){return e.map((e,t)=>{let n=[],r=[],i=()=>{r.length>=2&&n.push({traceIndex:t,runIndex:n.length,points:r}),r=[]};for(let t of e)t?r.push(t):i();return i(),n})}function la(e,t){return{x:Q(e.x,t.x),y:Q(e.y,t.y),z:Q(e.z,t.z)}}function ua(e,t,n){let r={x:t.x-e.x,y:t.y-e.y,z:t.z-e.z},i={x:n.x-e.x,y:n.y-e.y,z:n.z-e.z},a={x:r.y*i.z-r.z*i.y,y:r.z*i.x-r.x*i.z,z:r.x*i.y-r.y*i.x};return a.x*a.x+a.y*a.y+a.z*a.z}function da(e,t,n){if(t>=e.length)return[...e];if(t<=2)return[e[0],e[e.length-1]];let r=e.map(({point:e})=>la(e,n)),i=(e.length-2)/(t-2),a=[e[0]],o=0;for(let n=0;n<t-2;n+=1){let t=Math.floor(n*i)+1,s=Math.min(e.length-1,Math.floor((n+1)*i)+1),c=Math.floor((n+1)*i)+1,l=Math.min(e.length,Math.floor((n+2)*i)+1),u=Math.max(c+1,l),d={x:0,y:0,z:0},f=0;for(let t=Math.min(c,e.length-1);t<Math.min(u,e.length);t+=1)d.x+=r[t].x,d.y+=r[t].y,d.z+=r[t].z,f+=1;d={x:d.x/f,y:d.y/f,z:d.z/f};let p=t,m=-1;for(let n=t;n<s;n+=1){let t=ua(r[o],r[n],d);(t>m||t===m&&e[n].sourceIndex<e[p].sourceIndex)&&(m=t,p=n)}a.push(e[p]),o=p}return a.push(e[e.length-1]),a}function fa(e,t,n){let r=e.flat(),i=r.reduce((e,t)=>e+t.points.length-1,0);if(i<=n)return{runsByTrace:e.map(e=>e.map(e=>({...e,points:[...e.points]}))),candidateSourceSegmentCount:i,sampledSourceSegmentCount:i,sampledPointCount:r.reduce((e,t)=>e+t.points.length,0)};let a=e.map(e=>[...e].sort((e,t)=>t.points.length-e.points.length||e.runIndex-t.runIndex)[0]).filter(e=>e!==void 0),o=new Set(ra(a,Math.min(n,a.length)));if(o.size<n){let e=r.filter(e=>!o.has(e));for(let t of ra(e,Math.min(n-o.size,e.length)))o.add(t)}let s=new Map([...o].map(e=>[e,1])),c=n-s.size;if(c>0){let e=[...o].map(e=>({run:e,capacity:e.points.length-2})).filter(({capacity:e})=>e>0),t=e.reduce((e,t)=>e+t.capacity,0),r=e.map(e=>{let n=t===0?0:c*e.capacity/t,r=Math.floor(n);return s.set(e.run,(s.get(e.run)??0)+r),{...e,remainder:n-r}}),i=[...s.values()].reduce((e,t)=>e+t,0);r.sort((e,t)=>t.remainder-e.remainder||e.run.traceIndex-t.run.traceIndex||e.run.runIndex-t.run.runIndex);for(let e of r){if(i>=n)break;let t=s.get(e.run)??0;t<e.run.points.length-1&&(s.set(e.run,t+1),i+=1)}c=n-i}if(c!==0)throw Error(`line3d LOD could not allocate the configured source-segment budget`);let l=e.map(e=>e.flatMap(e=>{let n=s.get(e);return n===void 0?[]:[{...e,points:da(e.points,n+1,t)}]}));return{runsByTrace:l,candidateSourceSegmentCount:i,sampledSourceSegmentCount:n,sampledPointCount:l.flat().reduce((e,t)=>e+t.points.length,0)}}function pa(e,t,n){return Math.min(Math.max(e,Math.min(t,n)),Math.max(t,n))}function ma(e,t,n,r,i){let a=i*i,o=a*i;return .5*(2*t+(-e+n)*i+(2*e-5*t+4*n-r)*a+(-e+3*t-3*n+r)*o)}function ha(e,t,n,r,i){return i<=0?{...t}:i>=1?{...n}:{x:pa(ma(e.x,t.x,n.x,r.x,i),t.x,n.x),y:pa(ma(e.y,t.y,n.y,r.y,i),t.y,n.y),z:pa(ma(e.z,t.z,n.z,r.z,i),t.z,n.z)}}function ga(e,t,n){let r=n<.5?e.sourceIndex:n>.5?t.sourceIndex:Math.min(e.sourceIndex,t.sourceIndex);return{camera:aa(e.camera,t.camera,n),sourceIndex:r,sourceX:e.sourceX+(t.sourceX-e.sourceX)*n,sourceY:e.sourceY+(t.sourceY-e.sourceY)*n,sourceZ:e.sourceZ+(t.sourceZ-e.sourceZ)*n}}function _a(e,t,n){let r=n<.5?e.sourceIndex:n>.5?t.sourceIndex:Math.min(e.sourceIndex,t.sourceIndex);return{world:aa(e.world,t.world,n),sourceIndex:r,sourceX:e.sourceX+(t.sourceX-e.sourceX)*n,sourceY:e.sourceY+(t.sourceY-e.sourceY)*n,sourceZ:e.sourceZ+(t.sourceZ-e.sourceZ)*n}}function va(e,t){return Math.abs(e.world.x-t.world.x)<=1e-12&&Math.abs(e.world.y-t.world.y)<=1e-12&&Math.abs(e.world.z-t.world.z)<=1e-12}function ya(e){let t=[];for(let n of e)(t.length===0||!va(t[t.length-1],n))&&t.push(n);return t.length>1&&va(t[0],t[t.length-1])&&t.pop(),t}function ba(e,t){let n=[e=>e.world.x+.5,e=>.5-e.world.x,e=>e.world.y+.5,e=>.5-e.world.y,e=>e.world.z+.5,e=>.5-e.world.z],r=[...e];for(let e of n){if(r.length<3)return[];let t=[],n=r[r.length-1],i=e(n),a=i>=-1e-12;for(let o of r){let r=e(o),s=r>=-1e-12;if(a!==s){let e=i-r,a=Math.abs(e)<=1e-12?0:Math.max(0,Math.min(1,i/e));t.push(_a(n,o,a))}s&&t.push(o),n=o,i=r,a=s}r=ya(t)}if(r.length<3)return[];let i=(e,t,n)=>Math.abs(e+.5)<=1e-12?{world:-.5,source:n.min}:Math.abs(e-.5)<=1e-12?{world:.5,source:n.max}:{world:e,source:t};return r.map(e=>{let n=i(e.world.x,e.sourceX,t.x),r=i(e.world.y,e.sourceY,t.y),a=i(e.world.z,e.sourceZ,t.z);return{...e,world:{x:n.world,y:r.world,z:a.world},sourceX:n.source,sourceY:r.source,sourceZ:a.source}})}function xa(e,t){return Math.abs(e.camera.x-t.camera.x)<=1e-12&&Math.abs(e.camera.y-t.camera.y)<=1e-12&&Math.abs(e.camera.z-t.camera.z)<=1e-12}function Sa(e){let t=[];for(let n of e)(t.length===0||!xa(t[t.length-1],n))&&t.push(n);return t.length>1&&xa(t[0],t[t.length-1])&&t.pop(),t}function Ca(e,t){let n=0,r=1,i=Z(t,e),a=(e,t)=>{if(Math.abs(t)<1e-12)return e>=-.5&&e<=.5;let i=(-.5-e)/t,a=(.5-e)/t;return n=Math.max(n,Math.min(i,a)),r=Math.min(r,Math.max(i,a)),n<=r};return!a(e.x,i.x)||!a(e.y,i.y)||!a(e.z,i.z)?null:{from:aa(e,t,n),to:aa(e,t,r),startRatio:n,endRatio:r}}function wa(e,t,n){let r=X(e.eye),i=X(e.target),a=Wi(X(e.up),`scene3d.camera.up`),o=Wi(Z(i,r),`scene3d camera eye/target direction`),s=Wi(Hi(o,a),`scene3d camera up direction`),c=Hi(s,o),l=t/Math.max(1,n),u=Math.tan(e.fieldOfViewDegrees*Math.PI/360),d=e.orthographicScale/2,f=d*l,p=e=>{let t=Z(e,r);return{x:Vi(t,s),y:Vi(t,c),z:Vi(t,o)}},m=e.projection===`perspective`?[t=>t.z-e.near,t=>e.far-t.z,e=>e.x+e.z*u*l,e=>e.z*u*l-e.x,e=>e.y+e.z*u,e=>e.z*u-e.y]:[t=>t.z-e.near,t=>e.far-t.z,e=>e.x+f,e=>f-e.x,e=>e.y+d,e=>d-e.y],h=r=>{let i=e.projection===`perspective`?r.x/(r.z*u*l):r.x/f,a=e.projection===`perspective`?r.y/(r.z*u):r.y/d;return{x:(Math.max(-1,Math.min(1,i))+1)*t/2,y:(1-Math.max(-1,Math.min(1,a)))*n/2,depth:Math.max(0,Math.min(1,(r.z-e.near)/(e.far-e.near)))}};return{project:e=>{let t=p(e);return m.some(e=>e(t)<-1e-12)?null:h(t)},projectSegment:(e,t)=>{let n=p(e),r=p(t),i=0,a=1;for(let e of m){let t=e(n),o=e(r);if(t<0&&o<0)return null;if(t>=0&&o>=0)continue;let s=-t/(o-t);if(t<0?i=Math.max(i,s):a=Math.min(a,s),i>a)return null}return{from:h(aa(n,r,i)),to:h(aa(n,r,a)),startRatio:i,endRatio:a}},projectPolygon:e=>{let t=e.map(({world:e,...t})=>({camera:p(e),...t}));for(let e of m){if(t.length<3)return[];let n=[],r=t[t.length-1],i=e(r.camera),a=i>=-1e-12;for(let o of t){let t=e(o.camera),s=t>=-1e-12;if(a!==s){let e=i-t,a=Math.abs(e)<=1e-12?0:Math.max(0,Math.min(1,i/e));n.push(ga(r,o,a))}s&&n.push(o),r=o,i=t,a=s}t=Sa(n)}if(t.length<3)return[];let n=t.map(({camera:e,...t})=>({...h(e),...t})),r=[];for(let e=1;e<n.length-1;e+=1){let t=n[0],i=n[e],a=n[e+1],o=(i.x-t.x)*(a.y-t.y)-(i.y-t.y)*(a.x-t.x),s=Math.max(Math.abs(i.x-t.x),Math.abs(i.y-t.y),Math.abs(a.x-t.x),Math.abs(a.y-t.y)),c=2**-52*Math.max(1,s*s)*64;Math.abs(o)<=c||r.push({vertices:[t,i,a],boundaryEdges:[e===1,!0,e===n.length-2]})}if(r.length>13)throw Error(`scene3d triangle clipping exceeded its bounded fragment limit`);return r}}}function $(e,t,n){return{x:e,y:t,z:n}}function Ta(e,t,n,r,i){let a=e.projectSegment(n,r);if(!a)return null;let o=a.from,s=a.to;return{kind:t,...i?{axis:i}:{},x1:o.x,y1:o.y,depth1:o.depth,x2:s.x,y2:s.y,depth2:s.depth}}function Ea(e,t,n){if(e===void 0)return t;if(!Number.isFinite(e)||e<=0)throw Error(`${n} must be a positive finite number`);return e}function Da(e,t,n){if(e===void 0)return t;if(!Number.isFinite(e)||e<0||e>1)throw Error(`${n} must be finite and between 0 and 1`);return e}function Oa(e,t){if(e!==void 0){if(!Number.isFinite(e))throw Error(`${t} must be finite`);return e}}function ka(e,t,n,r){let i=e[0],a=e[0];for(let t=1;t<e.length;t+=1)i=Math.min(i,e[t]),a=Math.max(a,e[t]);let o=Oa(t,`${r}.minValue`)??i,s=Oa(n,`${r}.maxValue`)??a;if(o>s)throw Error(`${r}.minValue must be <= maxValue`);return{min:o,max:s}}function Aa(e,t,n){let r=e[t];if(typeof r!=`number`||!Number.isFinite(r))throw Error(`${n} points require a finite numeric '${t}' field`);return r}function ja(e,t){let n=t.scatter3d?.colorScale;if(n===void 0)return null;let r=Mt(n.valueScale,q.valueScale,`scatter3d.colorScale.valueScale`),i=n.lowColor??q.lowColor,a=n.highColor??q.highColor;if(typeof i!=`string`||i.trim().length===0)throw Error(`scatter3d.colorScale.lowColor must be a non-empty string`);if(typeof a!=`string`||a.trim().length===0)throw Error(`scatter3d.colorScale.highColor must be a non-empty string`);let o=Rt(n.colorStops,i.trim(),a.trim(),`scatter3d.colorScale.colorStops`),s=Oa(n.minValue,`scatter3d.colorScale.minValue`),c=Oa(n.maxValue,`scatter3d.colorScale.maxValue`);if(s!==void 0&&c!==void 0&&s>c)throw Error(`scatter3d.colorScale.minValue must be <= maxValue`);if(r===`logarithmic`&&(s!==void 0&&s<=0||c!==void 0&&c<=0))throw Error(`scatter3d.colorScale logarithmic values and bounds must be > 0`);let l=e.map(({input:e})=>Aa(e,`value`,`scatter3d.colorScale`));if(l.length===0)return null;let u=ka(l,s,c,`scatter3d.colorScale`);if(r===`logarithmic`&&(u.min<=0||u.max<=0||l.some(e=>e<=0)))throw Error(`scatter3d.colorScale logarithmic values and bounds must be > 0`);return{domain:u,valueScale:r,stops:o}}function Ma(e){return typeof e==`object`&&e?e:void 0}function Na(t,n){let r=n.scatter3d?.sizeScale,i=Ma(r);if(!(typeof r==`boolean`?r:i?i.enabled??!0:q.sizeScale.enabled))return null;let a=i?.minSize??q.sizeScale.minSize,o=i?.maxSize??q.sizeScale.maxSize;if(!Number.isFinite(a)||a<e.minSize)throw Error(`scatter3d.sizeScale.minSize must be >= ${e.minSize}`);if(!Number.isFinite(o)||o<a)throw Error(`scatter3d.sizeScale.maxSize must be >= minSize`);let s=Oa(i?.minValue,`scatter3d.sizeScale.minValue`),c=Oa(i?.maxValue,`scatter3d.sizeScale.maxValue`);if(s!==void 0&&c!==void 0&&s>c)throw Error(`scatter3d.sizeScale.minValue must be <= maxValue`);let l=t.map(({input:e})=>Aa(e,`size`,`scatter3d.sizeScale`));return l.length===0?null:{minSize:a,maxSize:o,domain:ka(l,s,c,`scatter3d.sizeScale`)}}function Pa(e,t){let n=t.scatter3d?.opacityScale,r=Ma(n);if(!(typeof n==`boolean`?n:r?r.enabled??!0:q.opacityScale.enabled))return null;let i=Da(r?.minOpacity,q.opacityScale.minOpacity,`scatter3d.opacityScale.minOpacity`),a=Da(r?.maxOpacity,q.opacityScale.maxOpacity,`scatter3d.opacityScale.maxOpacity`);if(a<i)throw Error(`scatter3d.opacityScale.maxOpacity must be >= minOpacity`);let o=Oa(r?.minValue,`scatter3d.opacityScale.minValue`),s=Oa(r?.maxValue,`scatter3d.opacityScale.maxValue`);if(o!==void 0&&s!==void 0&&o>s)throw Error(`scatter3d.opacityScale.minValue must be <= maxValue`);let c=e.map(({input:e})=>Aa(e,`opacity`,`scatter3d.opacityScale`));return c.length===0?null:{minOpacity:i,maxOpacity:a,domain:ka(c,o,s,`scatter3d.opacityScale`)}}function Fa(e,t,n,r){if(t.min===t.max)return(n+r)/2;let i=Math.min(1,Math.max(0,(e-t.min)/(t.max-t.min)));return n+(r-n)*i}function Ia(e,t){let n=[],i=[],a=t.scene3d?.showAxes??r.showAxes,o=t.scene3d?.showGrid??r.showGrid,s=t.scene3d?.gridSteps??r.gridSteps;if(!Number.isInteger(s)||s<1||s>20)throw Error(`scene3d.gridSteps must be an integer between 1 and 20`);if(o)for(let t=0;t<=s;t+=1){let r=-.5+t/s,i=Ta(e,`grid`,$(r,-.5,-.5),$(r,-.5,.5)),a=Ta(e,`grid`,$(-.5,-.5,r),$(.5,-.5,r));i&&n.push(i),a&&n.push(a)}if(a){let r=[{axis:`x`,from:$(-.5,-.5,-.5),to:$(.5,-.5,-.5)},{axis:`y`,from:$(-.5,-.5,-.5),to:$(-.5,.5,-.5)},{axis:`z`,from:$(-.5,-.5,-.5),to:$(-.5,-.5,.5)}];for(let a of r){let r=a.axis===`x`?t.scene3d?.xAxis:a.axis===`y`?t.scene3d?.yAxis:t.scene3d?.zAxis;if(r?.show===!1)continue;let o=Ta(e,`axis`,a.from,a.to,a.axis),s=e.project(a.to);o&&n.push(o),s&&i.push({axis:a.axis,text:r?.title?.trim()||a.axis.toUpperCase(),x:s.x,y:s.y,depth:s.depth})}}return{segments:n,labels:i}}function La(e,t,n){let i=Math.abs(e)<Math.max(r.axisTickZeroToleranceFloor,Math.abs(t)*r.axisTickStepFloor)?0:e;if(n!==void 0){if(!Number.isInteger(n)||n<0||n>r.axisTickMaxDecimals)throw Error(`scene3d axis tickDecimals must be an integer between 0 and ${r.axisTickMaxDecimals}`);return i.toFixed(n)}let a=Math.abs(i);if(a>=r.axisTickScientificUpperMagnitude||a>0&&a<r.axisTickScientificLowerMagnitude)return i.toExponential(r.axisTickScientificDecimals).replace(/\.?0+e/,`e`);let o=Math.max(0,Math.min(r.axisTickAutoMaxDecimals,Math.ceil(-Math.log10(Math.max(Math.abs(t),r.axisTickStepFloor)))+1));return i.toFixed(o).replace(/\.?0+$/,``)}function Ra(e,t,n){return e.left<t.right+n&&e.right+n>t.left&&e.top<t.bottom+n&&e.bottom+n>t.top}function za(e,t,n){let i=[],a=[];if(t.scene3d?.showAxes===!1)return{segments:i,tickLabels:[]};let o=r.axisTickWorldLength,s=[{axis:`x`,domain:n.x,options:t.scene3d?.xAxis},{axis:`y`,domain:n.y,options:t.scene3d?.yAxis},{axis:`z`,domain:n.z,options:t.scene3d?.zAxis}];for(let t of s){if(t.options?.show===!1)continue;let n=t.options?.showTickLabels!==!1,s=t.options?.tickCount??r.axisTickCount,c=t.options?.tickDecimals;if(c!==void 0&&(!Number.isInteger(c)||c<0||c>r.axisTickMaxDecimals))throw Error(`scene3d axis tickDecimals must be an integer between 0 and ${r.axisTickMaxDecimals}`);if(!Number.isInteger(s)||s<r.axisTickMinCount||s>r.axisTickMaxCount)throw Error(`scene3d axis tickCount must be an integer between ${r.axisTickMinCount} and ${r.axisTickMaxCount}`);let l=(t.domain.max-t.domain.min)/(s-1);for(let u=0;u<s;u+=1){let d=u/(s-1),f=-.5+d,p=t.domain.min+(t.domain.max-t.domain.min)*d,m=t.axis===`x`?$(f,-.5,-.5):t.axis===`y`?$(-.5,f,-.5):$(-.5,-.5,f),h=t.axis===`x`?$(f,-.5-o,-.5):t.axis===`y`?$(-.5-o,f,-.5):$(-.5-o,-.5,f),g=Ta(e,`tick`,m,h,t.axis),_=e.project(h);if(!g||!_||(i.push(g),!n))continue;let v=t.axis===`x`?{x:0,y:r.axisTickLabelOffset}:t.axis===`y`?{x:-r.axisTickLabelOffset,y:0}:{x:r.axisTickLabelOffset,y:r.axisTickLabelOffset/2};a.push({axis:t.axis,value:p,text:La(p,l,c),x:_.x+v.x,y:_.y+v.y,depth:_.depth})}}let c=[],l=[];for(let e of a){let n=Math.max(r.axisTickLabelMinWidth,e.text.length*r.axisTickLabelGlyphWidth),i=r.axisTickLabelLineHeight/2,a={left:e.x-n/2,right:e.x+n/2,top:e.y-i,bottom:e.y+i};a.left<r.axisTickLabelBoundsInset||a.right>t.width-r.axisTickLabelBoundsInset||a.top<r.axisTickLabelBoundsInset||a.bottom>t.height-r.axisTickLabelBoundsInset||l.some(e=>Ra(a,e,r.axisTickLabelMinGap))||(l.push(a),c.push(e))}return{segments:i,tickLabels:c}}function Ba(e){if(e.engine!==void 0&&e.engine!==`auto`&&e.engine!==`ts`&&e.engine!==`rust`)throw Error(`scatter3d engine must be 'auto', 'ts', or 'rust'`);if(e.engine===`rust`)throw Error(`scatter3d is experimental and currently supports engine 'auto' or 'ts'; Rust 3D scene capability is not available`);if(eo(e.scene3d?.lighting))throw Error(`scene3d.lighting is currently supported only for surface and mesh3d`);if(Object.keys(e.viewport?.xAxes??{}).length>0||Object.keys(e.viewport?.yAxes??{}).length>0)throw Error(`experimental scatter3d does not support Cartesian viewport state`);let t={width:e.width,height:e.height},i=zi(e);e={...e,width:i.width,height:i.height};let a=Gi(e.scene3d?.camera),o=pe(e),s=e.scene3d?.maxPoints??r.maxPoints;if(!Number.isInteger(s)||s<1||s>1e6)throw Error(`scene3d.maxPoints must be an integer between 1 and 1000000`);let c=$i(e.scatter3d?.lod),l=0,u=o.map(e=>{if(e.visible===!1)return[];let t=[];return e.data.forEach((e,n)=>{let r=Ki(e,n);if(r){if(l+=1,l>s)throw Error(`scatter3d visible point count ${l} exceeds scene3d.maxPoints ${s}`);t.push({sourceIndex:n,point:r,input:e})}}),t}),d=u.flatMap(e=>e.map(({point:e})=>e)),f={x:Xi(d.map(e=>e.x),e.scene3d?.xAxis,`x`),y:Xi(d.map(e=>e.y),e.scene3d?.yAxis,`y`),z:Xi(d.map(e=>e.z),e.scene3d?.zAxis,`z`)},p=c?ia(u,f,c.maxPoints):null,m=u.flat(),h=ja(m,e),g=Na(m,e),_=Pa(m,e),v=h?Pt(h.domain.min,h.domain.max,q.legendTickCount,[],h.valueScale).map((e,t,n)=>({value:e,text:Number.isInteger(e)?String(e):Number(e.toPrecision(4)).toString(),y:Ft(e,h.domain.min,h.domain.max,t,n.length,h.valueScale)})):[],y=Math.max(q.legendTitle.length,...v.map(e=>e.text.length))*q.legendGlyphWidth,b=e.width>=q.legendOffset*2+q.legendWidth+q.legendLabelGap+y&&e.height>=q.legendMinimumLabelHeight,x=Math.min(q.legendOffset,Math.max(0,e.width-q.legendWidth)),S=Math.min(q.legendOffset,Math.max(0,(e.height-1)/2)),C=b?e.width-q.legendOffset-q.legendWidth-q.legendLabelGap-y:Math.max(0,e.width-x-q.legendWidth),w=Math.min(q.legendHeight,Math.max(1,e.height-S*2)),T=wa(a,e.width,e.height),{segments:E,labels:D}=Ia(T,e),O=za(T,e,f);E.push(...O.segments);let k=!1,A=o.flatMap((t,r)=>{if(t.visible===!1)return[];let a=Ea(t.scatter3d?.markerSize??e.scatter3d?.markerSize,q.markerSize,`scatter3d.markerSize`),o=Da(t.scatter3d?.markerOpacity??e.scatter3d?.markerOpacity,q.markerOpacity,`scatter3d.markerOpacity`),s=jt(t.scatter3d?.markerShape??e.scatter3d?.markerShape,q.markerShape,`scatter3d.markerShape`),c=t.lineStyle?.color??t.color??e.lineStyle?.color??e.style?.trace?.line?.color??n[r%n.length],l=[];u[r].forEach(e=>{if(p&&!p.selected.has(e))return;let{point:t,sourceIndex:n,input:r}=e;if(!Qi(t.x,f.x)||!Qi(t.y,f.y)||!Qi(t.z,f.z))return;let i=T.project($(Q(t.x,f.x),Q(t.y,f.y),Q(t.z,f.z)));if(!i)return;let u=h?Aa(r,`value`,`scatter3d.colorScale`):void 0,d=g?Aa(r,`size`,`scatter3d.sizeScale`):void 0,m=_?Aa(r,`opacity`,`scatter3d.opacityScale`):void 0;l.push({...i,sourceIndex:n,sourceX:t.x,sourceY:t.y,sourceZ:t.z,radius:d===void 0?a:Fa(d,g.domain,g.minSize,g.maxSize),...d===void 0?{}:{sizeValue:d},opacity:m===void 0?o:Fa(m,_.domain,_.minOpacity,_.maxOpacity),...m===void 0?{}:{opacityValue:m},...u===void 0?{}:{colorValue:u},fillColor:u===void 0?c:zt(u,h.domain.min,h.domain.max,h.stops,h.valueScale),markerShape:s})}),l.sort((e,t)=>t.depth-e.depth||e.sourceIndex-t.sourceIndex);let d=h!==null&&(e.scatter3d?.colorScaleLegend??q.colorScaleLegend)&&!k;return d&&(k=!0),[{type:`scatter3d`,points:l.map(({x:e,y:t})=>({x:e,y:t})),scatter3dPoints:l,...d?{scene3dColorScaleLegend:{x:C,y:S,width:Math.min(q.legendWidth,e.width),height:w,minValue:h.domain.min,maxValue:h.domain.max,lowColor:h.stops[0].color,highColor:h.stops[h.stops.length-1].color,colorStops:h.stops,title:q.legendTitle,ticks:v,font:q.legendFont,color:q.legendColor,labelGap:q.legendLabelGap,labelWidth:y,labelsVisible:b}}:{},color:c,lineWidth:0,traceIndex:r,subplot:i.subplotId,bounds:{...i.bounds}}]}),j={experimental:!0,subplotId:i.subplotId,handedness:`right-handed`,depthOrder:`far-to-near`,sourcePointCount:l,...c&&p?{scatter3dLod:{strategy:c.strategy,maxPoints:c.maxPoints,candidatePointCount:p.candidatePointCount,sampledPointCount:p.selected.size}}:{},interactionItemCount:p?p.selected.size:l,projection:a.projection,camera:{projection:a.projection,eye:[...a.eye],target:[...a.target],up:[...a.up],fieldOfViewDegrees:a.fieldOfViewDegrees,orthographicScale:a.orthographicScale,near:a.near,far:a.far},domains:f,bounds:{...i.bounds},segments:E,labels:D,tickLabels:O.tickLabels,tickLabelFont:r.axisTickLabelFont,axisColor:e.scene3d?.axisColor??r.axisColor,gridColor:e.scene3d?.gridColor??r.gridColor,axisLineWidth:Ea(e.scene3d?.axisLineWidth,r.axisLineWidth,`scene3d.axisLineWidth`),gridLineWidth:Ea(e.scene3d?.gridLineWidth,r.gridLineWidth,`scene3d.gridLineWidth`)};return{...t,primitives:A,scene3d:j}}function Va(e){if(e.engine!==void 0&&e.engine!==`auto`&&e.engine!==`ts`&&e.engine!==`rust`)throw Error(`line3d engine must be 'auto', 'ts', or 'rust'`);if(e.engine===`rust`)throw Error(`line3d is experimental and currently supports engine 'auto' or 'ts'; Rust 3D scene capability is not available`);if(eo(e.scene3d?.lighting))throw Error(`scene3d.lighting is currently supported only for surface and mesh3d`);if(Object.keys(e.viewport?.xAxes??{}).length>0||Object.keys(e.viewport?.yAxes??{}).length>0)throw Error(`experimental line3d does not support Cartesian viewport state`);let t={width:e.width,height:e.height},i=zi(e);e={...e,width:i.width,height:i.height};let a=Gi(e.scene3d?.camera),o=pe(e),s=e.scene3d?.maxPoints??r.maxPoints;if(!Number.isInteger(s)||s<1||s>1e6)throw Error(`scene3d.maxPoints must be an integer between 1 and 1000000`);let c=e.line3d?.maxSegments??Fi.maxSegments;if(!Number.isInteger(c)||c<1||c>2e6)throw Error(`line3d.maxSegments must be an integer between 1 and 2000000`);let l=sa(e.line3d?.lod),u=o.map(t=>oa(t.line3d?.interpolation===void 0?e.line3d?.interpolation:t.line3d.interpolation)),d=0,f=o.map(e=>e.visible===!1?[]:e.data.map((e,t)=>{let n=Ki(e,t);if(!n)return null;if(d+=1,d>s)throw Error(`line3d visible point count ${d} exceeds scene3d.maxPoints ${s}`);return{sourceIndex:t,point:n}})),p=f.flatMap(e=>e.flatMap(e=>e?[e.point]:[])),m={x:Xi(p.map(e=>e.x),e.scene3d?.xAxis,`x`),y:Xi(p.map(e=>e.y),e.scene3d?.yAxis,`y`),z:Xi(p.map(e=>e.z),e.scene3d?.zAxis,`z`)},h=ca(f),g=l?fa(h,m,l.maxSourceSegments):null,_=g?.runsByTrace??h,v=0,y=!1;for(let e=0;e<_.length;e+=1){if(o[e].visible===!1)continue;let t=u[e]===`smooth`?Fi.smoothSamplesPerSegment:1;t>1&&(y=!0);for(let n of _[e])v+=(n.points.length-1)*t;if(v>c)throw Error(`line3d prepared segment count ${v} exceeds line3d.maxSegments ${c}`)}let b=wa(a,e.width,e.height),{segments:x,labels:S}=Ia(b,e),C=za(b,e,m);x.push(...C.segments);let w=o.flatMap((t,r)=>{if(t.visible===!1)return[];let a=Ea(t.line3d?.lineWidth??e.line3d?.lineWidth,Fi.lineWidth,`line3d.lineWidth`),o=Da(t.line3d?.lineOpacity??e.line3d?.lineOpacity,Fi.lineOpacity,`line3d.lineOpacity`),s=u[r],c=s===`smooth`?Fi.smoothSamplesPerSegment:1,l=[];for(let e of _[r]){let t=e.points;for(let e=1;e<t.length;e+=1){let n=t[e-1],r=t[e],i=t[e-2]??n,a=t[e+1]??r;for(let e=0;e<c;e+=1){let t=e/c,u=(e+1)/c,d=s===`smooth`?ha(i.point,n.point,r.point,a.point,t):n.point,f=s===`smooth`?ha(i.point,n.point,r.point,a.point,u):r.point,p=Ca($(Q(d.x,m.x),Q(d.y,m.y),Q(d.z,m.z)),$(Q(f.x,m.x),Q(f.y,m.y),Q(f.z,m.z)));if(!p)continue;let h=b.projectSegment(p.from,p.to);if(!h)continue;let g=p.startRatio+(p.endRatio-p.startRatio)*h.startRatio,_=p.startRatio+(p.endRatio-p.startRatio)*h.endRatio,v=t+(u-t)*g,y=t+(u-t)*_,x=aa(d,f,g),S=aa(d,f,_);l.push({x1:h.from.x,y1:h.from.y,depth1:h.from.depth,x2:h.to.x,y2:h.to.y,depth2:h.to.depth,sourceIndex1:n.sourceIndex,sourceIndex2:r.sourceIndex,...s===`smooth`?{sourceRatio1:v,sourceRatio2:y}:{},sourceX1:x.x,sourceY1:x.y,sourceZ1:x.z,sourceX2:S.x,sourceY2:S.y,sourceZ2:S.z,opacity:o})}}}l.sort((e,t)=>Math.max(t.depth1,t.depth2)-Math.max(e.depth1,e.depth2)||e.sourceIndex1-t.sourceIndex1||(e.sourceRatio1??0)-(t.sourceRatio1??0));let d=t.lineStyle?.color??t.color??e.lineStyle?.color??e.style?.trace?.line?.color??n[r%n.length];return[{type:`line3d`,points:l.flatMap(e=>[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}]),line3dSegments:l,color:d,lineWidth:a,lineOpacity:o,...s===`smooth`?{interpolation:s}:{},traceIndex:r,subplot:i.subplotId,bounds:{...i.bounds}}]}),T={experimental:!0,subplotId:i.subplotId,handedness:`right-handed`,depthOrder:`far-to-near`,sourcePointCount:d,...y?{preparedLineSegmentCount:v}:{},...l&&g?{line3dLod:{strategy:l.strategy,maxSourceSegments:l.maxSourceSegments,candidateSourceSegmentCount:g.candidateSourceSegmentCount,sampledSourceSegmentCount:g.sampledSourceSegmentCount,sampledPointCount:g.sampledPointCount,preparedSegmentCount:v}}:{},interactionItemCount:y?(g?.sampledPointCount??d)+v:g?.sampledPointCount??d,projection:a.projection,camera:{projection:a.projection,eye:[...a.eye],target:[...a.target],up:[...a.up],fieldOfViewDegrees:a.fieldOfViewDegrees,orthographicScale:a.orthographicScale,near:a.near,far:a.far},domains:m,bounds:{...i.bounds},segments:x,labels:S,tickLabels:C.tickLabels,tickLabelFont:r.axisTickLabelFont,axisColor:e.scene3d?.axisColor??r.axisColor,gridColor:e.scene3d?.gridColor??r.gridColor,axisLineWidth:Ea(e.scene3d?.axisLineWidth,r.axisLineWidth,`scene3d.axisLineWidth`),gridLineWidth:Ea(e.scene3d?.gridLineWidth,r.gridLineWidth,`scene3d.gridLineWidth`)};return{...t,primitives:w,scene3d:T}}function Ha(e){if(e===void 0||e===!1)return null;if(e===null||e!==!0&&(typeof e!=`object`||Array.isArray(e)))throw Error(`surface.lod must be a boolean or an options object`);let t=e===!0?{}:e,n=t.enabled??!0;if(t.enabled!==void 0&&typeof t.enabled!=`boolean`)throw Error(`surface.lod.enabled must be a boolean`);let r=t.strategy??J.lod.strategy;if(r!==`grid-stride`)throw Error(`surface.lod.strategy must be 'grid-stride'`);let i=t.maxCells??J.lod.maxCells;if(!Number.isInteger(i)||i<1||i>1e6)throw Error(`surface.lod.maxCells must be an integer between 1 and 1000000`);return n?{strategy:r,maxCells:i}:null}function Ua(e,t){let n=e.map(()=>0),r=e.filter(e=>e.candidateCellCount>0);if(r.reduce((e,t)=>e+t.candidateCellCount,0)<=t){for(let e of r)n[e.traceIndex]=e.candidateCellCount;return n}if(t<r.length){for(let e of r.slice(0,t))n[e.traceIndex]=1;return n}for(let e of r)n[e.traceIndex]=1;let i=t-r.length,a=r.reduce((e,t)=>e+t.candidateCellCount-1,0),o=r.map(e=>{let t=i*(e.candidateCellCount-1)/a,r=Math.floor(t);return n[e.traceIndex]+=r,{traceIndex:e.traceIndex,remainder:t-r}}),s=t-n.reduce((e,t)=>e+t,0);o.sort((e,t)=>t.remainder-e.remainder||e.traceIndex-t.traceIndex);for(let t of o){if(s===0)break;n[t.traceIndex]<e[t.traceIndex].candidateCellCount&&(n[t.traceIndex]+=1,--s)}return n}function Wa(e,t,n){let r=1,i=1,a=1,o=1/0,s=e/t;for(let c=1;c<=Math.min(e,n);c+=1){let e=Math.min(t,Math.floor(n/c));if(e<1)continue;let l=c*e,u=Math.abs(Math.log(c/e/s));(l>a||l===a&&(u<o||u===o&&c<r))&&(r=c,i=e,a=l,o=u)}return{xCellCount:r,yCellCount:i}}function Ga(e,t){return Array.from({length:t+1},(n,r)=>Math.round(r*e/t))}function Ka(e,t,n){if(n===0||e.candidateCellCount===0)return{xIndexes:[],yIndexes:[],renderableCellKeys:new Set};let r=Wa(e.xValues.length-1,e.yValues.length-1,n),i=Ga(e.xValues.length-1,r.xCellCount),a=Ga(e.yValues.length-1,r.yCellCount),o=new Map(t.map(e=>[`${e.x}\u0000${e.y}`,e])),s=new Set;for(let t=0;t<a.length-1;t+=1)for(let n=0;n<i.length-1;n+=1){let r=!1;for(let s=a[t];s<=a[t+1];s+=1){for(let t=i[n];t<=i[n+1];t+=1)if(o.get(`${e.xValues[t]}\u0000${e.yValues[s]}`).z===null){r=!0;break}if(r)break}r||s.add(`${t}\u0000${n}`)}return{xIndexes:i,yIndexes:a,renderableCellKeys:s}}function qa(e,t){if(e.candidateCellCount===0)return!1;if(t.every(e=>e.z!==null))return!0;let n=new Map(t.map(e=>[`${e.x}\u0000${e.y}`,e]));for(let t=0;t<e.yValues.length-1;t+=1)for(let r=0;r<e.xValues.length-1;r+=1)if([n.get(`${e.xValues[r]}\u0000${e.yValues[t]}`),n.get(`${e.xValues[r+1]}\u0000${e.yValues[t]}`),n.get(`${e.xValues[r]}\u0000${e.yValues[t+1]}`),n.get(`${e.xValues[r+1]}\u0000${e.yValues[t+1]}`)].every(e=>e.z!==null))return!0;return!1}function Ja(e,t){let n=e.map((e,t)=>{let n=[...new Set(e.map(e=>e.x))].sort((e,t)=>e-t),r=[...new Set(e.map(e=>e.y))].sort((e,t)=>e-t);return{traceIndex:t,xValues:n,yValues:r,candidateCellCount:Math.max(0,n.length-1)*Math.max(0,r.length-1)}}),r=Ua(n.map(t=>({...t,candidateCellCount:qa(t,e[t.traceIndex])?t.candidateCellCount:0})),t);return{byTrace:n.map(t=>Ka(t,e[t.traceIndex],r[t.traceIndex])),candidateCellCount:n.reduce((e,t)=>e+t.candidateCellCount,0)}}function Ya(e,t){let n=e.length>0?e[0]:0,r=e.length>0?e[0]:1;for(let t=1;t<e.length;t+=1)n=Math.min(n,e[t]),r=Math.max(r,e[t]);let i=t.surface?.minValue===void 0?n:Y(t.surface.minValue,`surface.minValue`),a=t.surface?.maxValue===void 0?r:Y(t.surface.maxValue,`surface.maxValue`);if(i>a)throw Error(`surface color scale requires minValue <= maxValue`);return{min:i,max:a}}function Xa(e,t,n){let r=(e,t)=>{if(!(e===void 0||typeof e==`boolean`)){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be boolean or an object`);if(e.show!==void 0&&typeof e.show!=`boolean`)throw Error(`${t}.show must be boolean`);if(e.color!==void 0&&so(e.color,`${t}.color`),e.width!==void 0&&(!Number.isFinite(e.width)||e.width<=0))throw Error(`${t}.width must be a positive finite number`);if(e.opacity!==void 0&&(!Number.isFinite(e.opacity)||e.opacity<0||e.opacity>1))throw Error(`${t}.opacity must be a finite number between 0 and 1`);if(e.count!==void 0&&(!Number.isInteger(e.count)||e.count<1||e.count>J.maxContourLevels))throw Error(`${t}.count must be an integer between 1 and ${J.maxContourLevels}`);if(e.values!==void 0){if(!Array.isArray(e.values)||e.values.length<1||e.values.length>J.maxContourLevels)throw Error(`${t}.values must contain between 1 and ${J.maxContourLevels} values`);for(let n=0;n<e.values.length;n+=1)if(!(n in e.values)||!Number.isFinite(e.values[n]))throw Error(`${t}.values must be a dense array of finite numbers`)}if(e.values!==void 0&&e.count!==void 0)throw Error(`${t} cannot configure both values and count`);return e}},i=r(e,`surface.contours`),a=r(t,`trace.surface.contours`),o=t??e;if(!(o===void 0?J.contourShow:typeof o==`boolean`?o:o.show??!0))return;let s=a?.values!==void 0||a?.count!==void 0?a:i,c;if(s?.values!==void 0)c=[...new Set(s.values)].sort((e,t)=>e-t);else if(n.min===n.max)c=[];else{let e=s?.count??J.contourCount;c=Array.from({length:e},(t,r)=>n.min+(n.max-n.min)*((r+1)/(e+1)))}let l=a?.color??i?.color??J.contourColor;return so(l,`surface.contours.color`),{levels:c,style:{color:l.trim(),width:a?.width??i?.width??J.contourWidth,opacity:a?.opacity??i?.opacity??J.contourOpacity}}}function Za(e,t){let n=[],r=e=>{n.some(t=>va(t,e))||n.push(e)};for(let n=0;n<e.length;n+=1){let i=e[n],a=e[(n+1)%e.length],o=i.sourceZ-t,s=a.sourceZ-t;o===0&&s===0?(r(i),r(a)):o===0?r(i):s===0?r(a):(o<0&&s>0||o>0&&s<0)&&r(_a(i,a,-o/(s-o)))}return n.length===2?[n[0],n[1]]:null}function Qa(e,t){let n=e=>`${e.sourceX}\u0000${e.sourceY}\u0000${e.sourceZ}`,r=n(t[0]),i=n(t[1]);return r<i?`${e}\u0000${r}\u0000${i}`:`${e}\u0000${i}\u0000${r}`}function $a(e,t){let[n,r]=e,i=Ca(n.world,r.world);if(!i)return null;let a=t.projectSegment(i.from,i.to);if(!a)return null;let o=i.startRatio+(i.endRatio-i.startRatio)*a.startRatio,s=i.startRatio+(i.endRatio-i.startRatio)*a.endRatio,c=aa({x:n.sourceX,y:n.sourceY,z:n.sourceZ},{x:r.sourceX,y:r.sourceY,z:r.sourceZ},o),l=aa({x:n.sourceX,y:n.sourceY,z:n.sourceZ},{x:r.sourceX,y:r.sourceY,z:r.sourceZ},s);return{x1:a.from.x,y1:a.from.y,depth1:a.from.depth,x2:a.to.x,y2:a.to.y,depth2:a.to.depth,sourceX1:c.x,sourceY1:c.y,sourceZ1:c.z,sourceX2:l.x,sourceY2:l.y,sourceZ2:l.z}}function eo(e){if(e===void 0){if(!r.lightingShow)return;e=!0}if(typeof e!=`boolean`&&(typeof e!=`object`||!e||Array.isArray(e)))throw Error(`scene3d.lighting must be boolean or an object`);let t=typeof e==`boolean`?void 0:e;if(t?.show!==void 0&&typeof t.show!=`boolean`)throw Error(`scene3d.lighting.show must be boolean`);let n=t?.direction??r.lightingDirection;if(!Array.isArray(n)||n.length!==3)throw Error(`scene3d.lighting.direction must contain exactly three finite numbers`);let i=n.map((e,t)=>{if(!(t in n)||!Number.isFinite(e))throw Error(`scene3d.lighting.direction must be a dense tuple of three finite numbers`);return e}),a=Wi({x:i[0],y:i[1],z:i[2]},`scene3d.lighting.direction`),o=t?.ambient??r.lightingAmbient,s=t?.diffuse??r.lightingDiffuse,c=t?.specular??r.lightingSpecular,l=t?.shininess??r.lightingShininess;if(!Number.isFinite(o)||o<0||o>1)throw Error(`scene3d.lighting.ambient must be a finite number between 0 and 1`);if(!Number.isFinite(s)||s<0||s>1)throw Error(`scene3d.lighting.diffuse must be a finite number between 0 and 1`);if(!Number.isFinite(c)||c<0||c>1)throw Error(`scene3d.lighting.specular must be a finite number between 0 and 1`);if(!Number.isInteger(l)||l<1||l>256)throw Error(`scene3d.lighting.shininess must be an integer between 1 and 256`);let u=t?.twoSided??r.lightingTwoSided;if(typeof u!=`boolean`)throw Error(`scene3d.lighting.twoSided must be boolean`);if(typeof e==`boolean`?e:e.show??!0)return{direction:[a.x,a.y,a.z],ambient:o,diffuse:s,specular:c,shininess:l,twoSided:u}}function to(e,t,n=0){let r=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e.trim()),i=r?r.slice(1).map(Number):so(e,`3D lighting base color`);if(i.some(e=>e<0||e>255))throw Error(`3D lighting base color RGB channels must be between 0 and 255`);let a=e=>{let r=e*t,i=r+(255-r)*n;return Math.round(Math.min(255,Math.max(0,i))).toString(16).padStart(2,`0`)};return`#${a(i[0])}${a(i[1])}${a(i[2])}`}function no(e,t,n,r,i){if(!n)return{fillColor:e};let a={x:t[0],y:t[1],z:t[2]},o={x:n.direction[0],y:n.direction[1],z:n.direction[2]},s=Vi(a,o),c=n.twoSided?Math.abs(s):Math.max(0,s),l=Math.min(1,Math.max(0,n.ambient+n.diffuse*c));if(n.specular===0)return{fillColor:to(e,l),lighting:{baseColor:e,normalDot:c,intensity:l,specularDot:0,specularIntensity:0}};let u={x:(r[0].x+r[1].x+r[2].x)/3,y:(r[0].y+r[1].y+r[2].y)/3,z:(r[0].z+r[1].z+r[2].z)/3},d=i.projection===`orthographic`?Z(X(i.eye),X(i.target)):Z(X(i.eye),u),f=Ui(d),p=f>1e-12?{x:d.x/f,y:d.y/f,z:d.z/f}:null,m=0;if(p){let e=Vi(a,p),t=n.twoSided&&e<0?{x:-a.x,y:-a.y,z:-a.z}:a,r=Vi(t,o),i=Vi(t,p),s={x:o.x+p.x,y:o.y+p.y,z:o.z+p.z},c=Ui(s);r>0&&i>0&&c>1e-12&&(m=Math.min(1,Math.max(0,Vi(t,{x:s.x/c,y:s.y/c,z:s.z/c}))))}let h=n.specular*m**n.shininess;return{fillColor:to(e,l,h),lighting:{baseColor:e,normalDot:c,intensity:l,specularDot:m,specularIntensity:h}}}function ro(e,t,n,r){let i=[e,t,n].map(e=>({x:Q(e.x,r.x),y:Q(e.y,r.y),z:Q(e.z??0,r.z)})),a=Wi(Hi(Z(i[1],i[0]),Z(i[2],i[0])),`surface triangle normal`);return[a.x,a.y,a.z]}function io(e){return{x:e.x,y:e.y,depth:e.depth,sourceIndex:e.sourceIndex,sourceX:e.sourceX,sourceY:e.sourceY,sourceZ:e.sourceZ}}function ao(e){if(e.engine!==void 0&&e.engine!==`auto`&&e.engine!==`ts`&&e.engine!==`rust`)throw Error(`surface engine must be 'auto', 'ts', or 'rust'`);if(e.engine===`rust`)throw Error(`surface is experimental and currently supports engine 'auto' or 'ts'; Rust 3D scene capability is not available`);if(Object.keys(e.viewport?.xAxes??{}).length>0||Object.keys(e.viewport?.yAxes??{}).length>0)throw Error(`experimental surface does not support Cartesian viewport state`);let t={width:e.width,height:e.height},i=zi(e);e={...e,width:i.width,height:i.height};let a=Gi(e.scene3d?.camera),o=eo(e.scene3d?.lighting),s=pe(e),c=Ha(e.surface?.lod),l=e.scene3d?.maxPoints??r.maxPoints;if(!Number.isInteger(l)||l<1||l>1e6)throw Error(`scene3d.maxPoints must be an integer between 1 and 1000000`);let u=e.surface?.maxTriangles??J.maxTriangles;if(!Number.isInteger(u)||u<1||u>2e6)throw Error(`surface.maxTriangles must be an integer between 1 and 2000000`);let d=e.surface?.maxContourSegments??J.maxContourSegments;if(!Number.isInteger(d)||d<1||d>2e6)throw Error(`surface.maxContourSegments must be an integer between 1 and 2000000`);let f=e.surface?.missingCells??J.missingCells;if(f!==`gap`&&f!==`zero`)throw Error(`surface.missingCells must be 'gap' or 'zero'`);let p=Rt(e.surface?.colorStops,e.surface?.lowColor??J.lowColor,e.surface?.highColor??J.highColor,`surface.colorStops`),m=0,h=0,g=s.map(e=>{if(e.visible===!1)return[];let t=e.data.map((e,t)=>{if(h+=1,h>l)throw Error(`surface grid point count ${h} exceeds scene3d.maxPoints ${l}`);if(e.x===null||e.y===null)throw Error(`surface regular grid requires x and y at traces[].data[${t}]`);let n=Y(e.x,`traces[].data[${t}].x`),r=Y(e.y,`traces[].data[${t}].y`),i=e.z===null||e.z===void 0?f===`zero`?0:null:Y(e.z,`traces[].data[${t}].z`);if(i!==null&&(m+=1,m>l))throw Error(`surface visible point count ${m} exceeds scene3d.maxPoints ${l}`);return{sourceIndex:t,x:n,y:r,z:i}}),n=[...new Set(t.map(e=>e.x))].sort((e,t)=>e-t),r=[...new Set(t.map(e=>e.y))].sort((e,t)=>e-t);if(t.length!==n.length*r.length)throw Error(`surface data must provide exactly one point for every regular x/y grid coordinate`);let i=new Set;for(let e of t){let t=`${e.x}\u0000${e.y}`;if(i.has(t))throw Error(`surface data must not contain duplicate x/y grid coordinates`);i.add(t)}return t}),_=g.flatMap(e=>e.filter(e=>e.z!==null)),v=c?Ja(g,c.maxCells):null,y={x:Xi(_.map(e=>e.x),e.scene3d?.xAxis,`x`),y:Xi(_.map(e=>e.y),e.scene3d?.yAxis,`y`),z:Xi(_.map(e=>e.z??0),e.scene3d?.zAxis,`z`)},b=Ya(_.map(e=>e.z??0),e),x=Pt(b.min,b.max,J.legendTickCount,[],`linear`).map((e,t,n)=>({value:e,text:Number.isInteger(e)?String(e):Number(e.toPrecision(4)).toString(),y:n.length===1?0:t/(n.length-1)})),S=Math.max(J.legendTitle.length,...x.map(e=>e.text.length))*J.legendGlyphWidth,C=e.width>=J.legendOffset*2+J.legendWidth+J.legendLabelGap+S&&e.height>=J.legendMinimumLabelHeight,w=Math.min(J.legendOffset,Math.max(0,e.width-J.legendWidth)),T=Math.min(J.legendOffset,Math.max(0,(e.height-1)/2)),E=C?e.width-J.legendOffset-J.legendWidth-J.legendLabelGap-S:Math.max(0,e.width-w-J.legendWidth),D=Math.min(J.legendHeight,Math.max(1,e.height-T*2)),O=wa(a,e.width,e.height),{segments:k,labels:A}=Ia(O,e),j=za(O,e,y);k.push(...j.segments);let M=0,N=0,P=new Set,ee=0,F=!1,I=s.map(t=>Xa(e.surface?.contours,t.surface?.contours,b)),L=s.flatMap((t,r)=>{if(t.visible===!1)return[];let s=g[r],c=[...new Set(s.map(e=>e.x))].sort((e,t)=>e-t),l=[...new Set(s.map(e=>e.y))].sort((e,t)=>e-t),f=v?.byTrace[r],m=f?.xIndexes??c.map((e,t)=>t),h=f?.yIndexes??l.map((e,t)=>t),_=m.map(e=>c[e]),w=h.map(e=>l[e]),k=new Map(s.map(e=>[`${e.x}\u0000${e.y}`,e])),A=Da(t.surface?.opacity??e.surface?.opacity,J.opacity,`surface.opacity`),j=co(e.surface?.wireframe,t.surface?.wireframe,J,`surface.wireframe`),L=I[r],te=[],R=[],z=new Set,ne=(e,t,n,r)=>{if(e.some(e=>e.z===null))return;if(M+=1,M>u)throw Error(`surface triangle count ${M} exceeds surface.maxTriangles ${u}`);let i=e.reduce((e,t)=>e+(t.z??0),0)/3,s=ro(e[0],e[1],e[2],y),l=zt(i,b.min,b.max,p),f=e.map(e=>({world:$(Q(e.x,y.x),Q(e.y,y.y),Q(e.z??0,y.z)),sourceIndex:e.sourceIndex,sourceX:e.x,sourceY:e.y,sourceZ:e.z??0})),m=no(l,s,o,f.map(e=>e.world),a),h={index:(t*Math.max(0,c.length-1)+n)*2+r,row:t,column:n,triangle:r};if(L)for(let e of L.levels){let t=Za(f,e);if(!t)continue;let n=Qa(e,t);if(z.has(n))continue;if(z.add(n),ee+=1,ee>d)throw Error(`surface contour segment count ${ee} exceeds surface.maxContourSegments ${d}`);let r=$a(t,O);r&&R.push({...r,level:e,sourceCell:h,style:L.style})}let g=O.projectPolygon(ba(f,y));for(let e of g){let t=e.vertices.map(io);te.push({vertices:t,sourceCell:h,normal:s,fillColor:m.fillColor,...m.lighting?{lighting:m.lighting}:{},opacity:A,...j?{wireframe:j,wireframeEdges:e.boundaryEdges}:{},depth:t.reduce((e,t)=>e+t.depth,0)/3})}};for(let e=0;e<w.length-1;e+=1)for(let t=0;t<_.length-1;t+=1){let n=h[e],i=m[t],a=k.get(`${_[t]}\u0000${w[e]}`),o=k.get(`${_[t+1]}\u0000${w[e]}`),s=k.get(`${_[t]}\u0000${w[e+1]}`),c=k.get(`${_[t+1]}\u0000${w[e+1]}`);if(!(f?!f.renderableCellKeys.has(`${e}\u0000${t}`):[a,o,s,c].some(e=>e.z===null))){if(v){N+=1;for(let e of[a,o,s,c])P.add(`${r}\u0000${e.sourceIndex}`)}ne([a,o,s],n,i,0),ne([o,c,s],n,i,1)}}te.sort((e,t)=>t.depth-e.depth||e.sourceCell.row-t.sourceCell.row||e.sourceCell.column-t.sourceCell.column||e.sourceCell.triangle-t.sourceCell.triangle),R.sort((e,t)=>Math.max(t.depth1,t.depth2)-Math.max(e.depth1,e.depth2)||e.level-t.level||e.sourceCell.index-t.sourceCell.index);let B=t.color??n[r%n.length],V=(e.surface?.colorScaleLegend??J.colorScaleLegend)&&!F;return V&&(F=!0),[{type:`surface`,points:te.flatMap(e=>e.vertices.map(({x:e,y:t})=>({x:e,y:t}))),surface3dTriangles:te,...L?{surface3dContourSegments:R,surface3dContourLevels:[...L.levels]}:{},...V?{surface3dColorScaleLegend:{x:E,y:T,width:Math.min(J.legendWidth,e.width),height:D,minValue:b.min,maxValue:b.max,lowColor:p[0].color,highColor:p[p.length-1].color,colorStops:p,title:J.legendTitle,ticks:x,font:J.legendFont,color:J.legendColor,labelGap:J.legendLabelGap,labelWidth:S,labelsVisible:C}}:{},color:B,lineWidth:0,traceIndex:r,subplot:i.subplotId,bounds:{...i.bounds}}]}),te={experimental:!0,subplotId:i.subplotId,handedness:`right-handed`,depthOrder:`far-to-near`,sourcePointCount:m,...c&&v?{surface3dLod:{strategy:c.strategy,maxCells:c.maxCells,candidateCellCount:v.candidateCellCount,sampledCellCount:N,sampledPointCount:P.size,preparedTriangleCount:M}}:{},interactionItemCount:v?P.size+M:m,projection:a.projection,camera:{...a,eye:[...a.eye],target:[...a.target],up:[...a.up]},...o?{lighting:o}:{},domains:y,bounds:{...i.bounds},segments:k,labels:A,tickLabels:j.tickLabels,tickLabelFont:r.axisTickLabelFont,axisColor:e.scene3d?.axisColor??r.axisColor,gridColor:e.scene3d?.gridColor??r.gridColor,axisLineWidth:Ea(e.scene3d?.axisLineWidth,r.axisLineWidth,`scene3d.axisLineWidth`),gridLineWidth:Ea(e.scene3d?.gridLineWidth,r.gridLineWidth,`scene3d.gridLineWidth`)};return{...t,primitives:L,scene3d:te}}function oo(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);for(let n=0;n<e.length;n+=1)if(!(n in e))throw Error(`${t} must not contain sparse entries`)}function so(e,t){if(typeof e!=`string`)throw Error(`${t} must be a hexadecimal color string`);let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n)throw Error(`${t} must use #rgb or #rrggbb hexadecimal syntax`);let r=n[1].length===3?n[1].split(``).map(e=>`${e}${e}`).join(``):n[1];return[Number.parseInt(r.slice(0,2),16),Number.parseInt(r.slice(2,4),16),Number.parseInt(r.slice(4,6),16)]}function co(e,t,n,r){let i=(e,t)=>{if(!(e===void 0||typeof e==`boolean`)){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be boolean or an object`);if(e.show!==void 0&&typeof e.show!=`boolean`)throw Error(`${t}.show must be boolean`);if(e.color!==void 0&&so(e.color,`${t}.color`),e.width!==void 0&&(!Number.isFinite(e.width)||e.width<=0))throw Error(`${t}.width must be a positive finite number`);if(e.opacity!==void 0&&(!Number.isFinite(e.opacity)||e.opacity<0||e.opacity>1))throw Error(`${t}.opacity must be a finite number between 0 and 1`);return e}},a=i(e,r),o=i(t,`trace.${r}`),s=t??e;if(!(s===void 0?n.wireframeShow:typeof s==`boolean`?s:s.show??!0))return;let c=o?.color??a?.color??n.wireframeColor,l=o?.width??a?.width??n.wireframeWidth,u=o?.opacity??a?.opacity??n.wireframeOpacity;return so(c,`${r}.color`),{color:c.trim(),width:l,opacity:u}}function lo(e,t){let n=t.map(t=>e[t]),r=e=>Math.round(n.reduce((t,n)=>t+n[e],0)/n.length).toString(16).padStart(2,`0`);return`#${r(0)}${r(1)}${r(2)}`}function uo(e,t,n){let r=e.map(({point:e})=>$(Q(e.x,t.x),Q(e.y,t.y),Q(e.z,t.z))),i=Wi(Hi(Z(r[1],r[0]),Z(r[2],r[0])),`mesh3d face ${n}`);return{normal:[i.x,i.y,i.z],world:r}}function fo(e){if(e===void 0||e===!1)return null;if(e===null||e!==!0&&(typeof e!=`object`||Array.isArray(e)))throw Error(`mesh3d.lod must be a boolean or an options object`);let t=e===!0?{}:e,n=t.enabled??!0;if(t.enabled!==void 0&&typeof t.enabled!=`boolean`)throw Error(`mesh3d.lod.enabled must be a boolean`);let r=t.strategy??Ii.lod.strategy;if(r!==`largest-area-stratified`)throw Error(`mesh3d.lod.strategy must be 'largest-area-stratified'`);let i=t.maxFaces??Ii.lod.maxFaces;if(!Number.isInteger(i)||i<1||i>2e6)throw Error(`mesh3d.lod.maxFaces must be an integer between 1 and 2000000`);return n?{strategy:r,maxFaces:i}:null}function po(e,t,n){return ba(e.map((e,n)=>({world:t[n],sourceIndex:e.sourceIndex,sourceX:e.point.x,sourceY:e.point.y,sourceZ:e.point.z})),n).length>=3}function mo(e,t){let n=e.map(()=>0),r=e.map((e,t)=>({traceIndex:t,faceCount:e.length})).filter(({faceCount:e})=>e>0);if(r.reduce((e,t)=>e+t.faceCount,0)<=t){for(let e of r)n[e.traceIndex]=e.faceCount;return n}if(t<r.length){for(let e of r.slice(0,t))n[e.traceIndex]=1;return n}for(let e of r)n[e.traceIndex]=1;let i=t-r.length,a=r.reduce((e,t)=>e+t.faceCount-1,0),o=r.map(e=>{let t=i*(e.faceCount-1)/a,r=Math.floor(t);return n[e.traceIndex]+=r,{traceIndex:e.traceIndex,remainder:t-r}}),s=t-n.reduce((e,t)=>e+t,0);o.sort((e,t)=>t.remainder-e.remainder||e.traceIndex-t.traceIndex);for(let t of o){if(s===0)break;n[t.traceIndex]<e[t.traceIndex].length&&(n[t.traceIndex]+=1,--s)}return n}function ho(e,t,n){let r=e.map((e,n)=>e.faces.flatMap((r,i)=>{let a=r.map(t=>e.vertices[t]),{world:o}=uo(a,t,i);if(!po(a,o,t))return[];let s=Hi(Z(o[1],o[0]),Z(o[2],o[0]));return[{traceIndex:n,faceIndex:i,indexes:r,areaSquared:Vi(s,s)}]})),i=mo(r,n),a=r.map(()=>new Set),o=new Set;return r.forEach((e,t)=>{let n=i[t];if(n!==0){if(n>=e.length){for(let n of e){a[t].add(n.faceIndex);for(let e of n.indexes)o.add(`${t}\u0000${e}`)}return}for(let r=0;r<n;r+=1){let i=Math.floor(r*e.length/n),s=Math.floor((r+1)*e.length/n),c=e[i];for(let t=i+1;t<s;t+=1){let n=e[t];(n.areaSquared>c.areaSquared||n.areaSquared===c.areaSquared&&n.faceIndex<c.faceIndex)&&(c=n)}a[t].add(c.faceIndex);for(let e of c.indexes)o.add(`${t}\u0000${e}`)}}}),{selectedFaceIndexesByTrace:a,candidateFaceCount:r.reduce((e,t)=>e+t.length,0),sampledFaceCount:a.reduce((e,t)=>e+t.size,0),sampledVertexCount:o.size}}function go(e,t,n){let r=t.reduce((e,t)=>({x:e.x+t.x/3,y:e.y+t.y/3,z:e.z+t.z/3}),{x:0,y:0,z:0}),i=n.projection===`orthographic`?Z(X(n.eye),X(n.target)):Z(X(n.eye),r);return Vi({x:e[0],y:e[1],z:e[2]},i)>1e-12}function _o(e){return{x:e.x,y:e.y,depth:e.depth,sourceIndex:e.sourceIndex,sourceX:e.sourceX,sourceY:e.sourceY,sourceZ:e.sourceZ}}function vo(e){if(!Number.isFinite(e.width)||!Number.isFinite(e.height)||e.width<=0||e.height<=0)throw Error(`pie3d width and height must be positive finite numbers`);if(e.engine!==void 0&&e.engine!==`auto`&&e.engine!==`ts`&&e.engine!==`rust`)throw Error(`pie3d engine must be 'auto', 'ts', or 'rust'`);if(e.engine===`rust`)throw Error(`pie3d is experimental and currently supports engine 'auto' or 'ts'; Rust 3D scene capability is not available`);if(e.viewport&&(Object.keys(e.viewport.xAxes??{}).length>0||Object.keys(e.viewport.yAxes??{}).length>0))throw Error(`experimental pie3d does not support Cartesian viewport state`);if(e.subplots!==void 0||e.scene3d?.subplots&&Object.keys(e.scene3d.subplots).length>0)throw Error(`experimental pie3d currently requires one full-chart 3D scene`);if(e.pie?.borderColor!==void 0||e.pie?.borderWidth!==void 0)throw Error(`pie3d does not support 2D pie.borderColor or pie.borderWidth; 3D face boundaries use projected geometry`);if(e.scene3d?.xAxis||e.scene3d?.yAxis||e.scene3d?.zAxis)throw Error(`pie3d does not support Cartesian scene3d axis options`);let t=e.pie3d?.curveTolerance??Li.curveTolerance;if(!Number.isFinite(t)||t<=0)throw Error(`pie3d.curveTolerance must be a positive finite number`);let n=e.pie3d?.extrusionDepth??Li.extrusionDepth;if(!Number.isFinite(n)||n<=0||n>1)throw Error(`pie3d.extrusionDepth must be finite and in (0, 1]`);let i=e.scene3d?.maxPoints??r.maxPoints;if(!Number.isInteger(i)||i<1||i>1e6)throw Error(`scene3d.maxPoints must be an integer between 1 and 1000000`);let a=Gi(e.scene3d?.camera),o=eo(e.scene3d?.lighting),s=wa(a,e.width,e.height),c=Jn(e.pie),{datum:l,total:u,datumCountsByTrace:d}=Zn(e);$n(l,c.colors,d);let f=l.map(e=>e.value/u),p=ar(c,f),m=c.outerRadiusRatio/2,h=m*c.innerRadiusRatio,g=n/2,_=-g,v=[],y=0,b=(e,t)=>{try{return to(e,t)}catch{return e}};for(let n=0;n<l.length;n+=1){let r=l[n],u=p[n],d=f[n],x=[],S=(e,t,n)=>({x:Math.cos(e)*t,y:n,z:Math.sin(e)*t}),C=(e,t,n)=>{if(y+=1,y>i)throw Error(`pie3d triangle count exceeds scene3d.maxPoints ${i}`);let l=t,f=Hi(Z(l[1],l[0]),Z(l[2],l[0])),p=e===`start`?u.start:u.start+u.sweep,m=Math.sign(u.sweep),h=e===`top`?$(0,1,0):e===`bottom`?$(0,-1,0):e===`outer`||e===`inner`?$((l[0].x+l[1].x+l[2].x)*(e===`outer`?1:-1),0,(l[0].z+l[1].z+l[2].z)*(e===`outer`?1:-1)):e===`start`?$(Math.sin(p)*m,0,-Math.cos(p)*m):$(-Math.sin(p)*m,0,Math.cos(p)*m);Vi(f,h)<0&&(l=[l[0],l[2],l[1]],f=Hi(Z(l[1],l[0]),Z(l[2],l[0])));let g=Ui(f);if(g<=2**-52)return;let _=l.map(e=>({world:e,sourceIndex:r.sourceIndex,sourceX:e.x,sourceY:e.y,sourceZ:e.z})),v=[f.x/g,f.y/g,f.z/g],S=$((l[0].x+l[1].x+l[2].x)/3,(l[0].y+l[1].y+l[2].y)/3,(l[0].z+l[1].z+l[2].z)/3),C=a.projection===`orthographic`?Z(X(a.eye),X(a.target)):Z(X(a.eye),S),w=Vi(f,C)>0,T=no(e===`top`?r.color:b(r.color,n),v,o,l,a);for(let t of s.projectPolygon(_)){let n=t.vertices.map(_o);x.push({vertices:n,sourceFace:{index:r.sourceIndex,vertexIndexes:[0,1,2]},normal:v,frontFacing:w,fillColor:T.fillColor,...T.lighting?{lighting:T.lighting}:{},opacity:c.sectorOpacity,depth:n.reduce((e,t)=>e+t.depth,0)/3,pie3d:{label:r.label,value:r.value,fraction:d,color:r.color,face:e}})}},w=(e,t,n,r,i,a)=>{C(e,[t,n,r],a),C(e,[t,r,i],a)},T=Math.max(1,Math.min(e.width,e.height)*m/2),E=Math.min(Li.maxCurveStepDegrees*Math.PI/180,2*Math.acos(Math.max(-1,1-t/T))),D=Math.max(1,Math.ceil(Math.abs(u.sweep)/E));if(!Number.isSafeInteger(D)||y+D>i)throw Error(`pie3d triangle count exceeds scene3d.maxPoints ${i}`);for(let e=0;e<D;e+=1){let t=u.start+u.sweep*e/D,n=u.start+u.sweep*(e+1)/D,r=S(t,m,g),i=S(n,m,g),a=S(t,h,g),o=S(n,h,g),s=S(t,m,_),c=S(n,m,_),l=S(t,h,_),d=S(n,h,_);w(`top`,a,r,i,o,1),w(`bottom`,d,c,s,l,.62),w(`outer`,r,s,c,i,.76),h>0&&w(`inner`,o,d,l,a,.68)}if(Math.abs(u.sweep)<Math.PI*2-2**-52){w(`start`,S(u.start,h,g),S(u.start,h,_),S(u.start,m,_),S(u.start,m,g),.7);let e=u.start+u.sweep;w(`end`,S(e,m,g),S(e,m,_),S(e,h,_),S(e,h,g),.7)}let O=c.labels.show&&Math.abs(u.sweep*180/Math.PI)>=c.labels.minSectorAngleDegrees?rr(r,d,c):null,k=c.labels.position===`inside`?h+(m-h)*c.labels.radiusRatio:m+c.labels.offset/Math.max(1,Math.min(e.width,e.height)),A=O&&a.eye[1]>=a.target[1]?s.project(S(u.angle,k,g)):null;v.push({type:`pie3d`,points:[],color:r.color,lineWidth:0,traceIndex:r.traceIndex,subplot:`scene3d`,bounds:{left:0,top:0,right:e.width,bottom:e.height},mesh3dTriangles:x,...A&&O?{pie3dLabels:[{x:A.x,y:A.y,angle:u.angle,value:r.value,fraction:d,text:O,color:c.labels.color,font:c.labels.font,lineHeight:c.labels.lineHeight,position:c.labels.position,collisionPadding:c.labels.collisionPadding}]}:{}})}let x=Ia(s,{...e,scene3d:{...e.scene3d,showAxes:e.scene3d?.showAxes??!1,showGrid:e.scene3d?.showGrid??!1}}),S={x:{min:-.5,max:.5},y:{min:-.5,max:.5},z:{min:-.5,max:.5}},C={experimental:!0,subplotId:`scene3d`,handedness:`right-handed`,depthOrder:`far-to-near`,sourcePointCount:l.length,sourceFaceCount:y,interactionItemCount:l.length+y,projection:a.projection,camera:a,...o?{lighting:o}:{},domains:S,bounds:{left:0,top:0,right:e.width,bottom:e.height},segments:x.segments,labels:x.labels,tickLabels:[],tickLabelFont:r.axisTickLabelFont,axisColor:e.scene3d?.axisColor??r.axisColor,gridColor:e.scene3d?.gridColor??r.gridColor,axisLineWidth:Ea(e.scene3d?.axisLineWidth,r.axisLineWidth,`scene3d.axisLineWidth`),gridLineWidth:Ea(e.scene3d?.gridLineWidth,r.gridLineWidth,`scene3d.gridLineWidth`)};return{width:e.width,height:e.height,primitives:v,scene3d:C}}function yo(e){if(e.engine!==void 0&&e.engine!==`auto`&&e.engine!==`ts`&&e.engine!==`rust`)throw Error(`mesh3d engine must be 'auto', 'ts', or 'rust'`);if(e.engine===`rust`)throw Error(`mesh3d is experimental and currently supports engine 'auto' or 'ts'; Rust 3D scene capability is not available`);if(Object.keys(e.viewport?.xAxes??{}).length>0||Object.keys(e.viewport?.yAxes??{}).length>0)throw Error(`experimental mesh3d does not support Cartesian viewport state`);let t={width:e.width,height:e.height},i=zi(e);e={...e,width:i.width,height:i.height};let a=Gi(e.scene3d?.camera),o=eo(e.scene3d?.lighting),s=pe(e),c=e.scene3d?.maxPoints??r.maxPoints;if(!Number.isInteger(c)||c<1||c>1e6)throw Error(`scene3d.maxPoints must be an integer between 1 and 1000000`);let l=e.mesh3d?.maxFaces??Ii.maxFaces;if(!Number.isInteger(l)||l<1||l>2e6)throw Error(`mesh3d.maxFaces must be an integer between 1 and 2000000`);if(e.mesh3d?.faceColors!==void 0&&e.mesh3d.vertexColors!==void 0)throw Error(`mesh3d cannot configure both faceColors and vertexColors`);let u=fo(e.mesh3d?.lod),d=0,f=0,p=s.map((t,n)=>{if(t.visible===!1)return{vertices:[],faces:[]};oo(t.data,`mesh3d vertex data for trace ${n}`);let r=t.data.map((e,t)=>{if(d+=1,d>c)throw Error(`mesh3d vertex count ${d} exceeds scene3d.maxPoints ${c}`);if(e.x===null||e.y===null||e.z===null||e.z===void 0)throw Error(`mesh3d requires x, y, and z at traces[${n}].data[${t}]`);return{sourceIndex:t,point:{x:Y(e.x,`traces[${n}].data[${t}].x`),y:Y(e.y,`traces[${n}].data[${t}].y`),z:Y(e.z,`traces[${n}].data[${t}].z`)}}}),i=t.mesh3d?.faces??e.mesh3d?.faces??[];if(oo(i,`mesh3d faces for trace ${n}`),f+=i.length,f>l)throw Error(`mesh3d face count ${f} exceeds mesh3d.maxFaces ${l}`);let a=i.map((e,t)=>{if(!Array.isArray(e)||e.length!==3)throw Error(`mesh3d face ${t} for trace ${n} must contain exactly three vertex indexes`);oo(e,`mesh3d face ${t} for trace ${n}`);let i=e.map((e,i)=>{if(!Number.isInteger(e)||e<0||e>=r.length)throw Error(`mesh3d face ${t} index ${i} for trace ${n} must reference an existing vertex`);return e});if(new Set(i).size!==3)throw Error(`mesh3d face ${t} for trace ${n} must reference three distinct vertices`);return i}),o=t.mesh3d?.faceColors,s=t.mesh3d?.vertexColors;if(o!==void 0&&s!==void 0)throw Error(`mesh3d trace ${n} cannot configure both faceColors and vertexColors`);let u=o!==void 0||s!==void 0,p=u?o:e.mesh3d?.faceColors,m=u?s:e.mesh3d?.vertexColors;if(p!==void 0){if(!Array.isArray(p)||p.length!==a.length)throw Error(`mesh3d.faceColors for trace ${n} must match the face count`);oo(p,`mesh3d.faceColors for trace ${n}`),p.forEach((e,t)=>so(e,`mesh3d.faceColors[${t}] for trace ${n}`))}let h;if(m!==void 0){if(!Array.isArray(m)||m.length!==r.length)throw Error(`mesh3d.vertexColors for trace ${n} must match the vertex count`);oo(m,`mesh3d.vertexColors for trace ${n}`),h=m.map((e,t)=>so(e,`mesh3d.vertexColors[${t}] for trace ${n}`))}return{vertices:r,faces:a,...p?{faceColors:[...p]}:{},...h?{vertexColorChannels:h}:{}}}),m=p.flatMap(e=>e.vertices),h={x:Xi(m.map(({point:e})=>e.x),e.scene3d?.xAxis,`x`),y:Xi(m.map(({point:e})=>e.y),e.scene3d?.yAxis,`y`),z:Xi(m.map(({point:e})=>e.z),e.scene3d?.zAxis,`z`)},g=u?ho(p,h,u.maxFaces):null,_=wa(a,e.width,e.height),{segments:v,labels:y}=Ia(_,e),b=za(_,e,h);v.push(...b.segments);let x=s.flatMap((t,r)=>{if(t.visible===!1)return[];let s=p[r],c=t.color??n[r%n.length],l=Da(t.mesh3d?.opacity??e.mesh3d?.opacity,Ii.opacity,`mesh3d.opacity`),u=t.mesh3d?.backfaceCulling??e.mesh3d?.backfaceCulling??Ii.backfaceCulling;if(typeof u!=`boolean`)throw Error(`mesh3d.backfaceCulling must be boolean`);let d=co(e.mesh3d?.wireframe,t.mesh3d?.wireframe,Ii,`mesh3d.wireframe`),f=[];for(let e=0;e<s.faces.length;e+=1){if(g&&!g.selectedFaceIndexesByTrace[r].has(e))continue;let t=s.faces[e],n=t.map(e=>s.vertices[e]),{normal:i,world:p}=uo(n,h,e),m=go(i,p,a);if(u&&!m)continue;let v=no(s.faceColors?.[e]??(s.vertexColorChannels?lo(s.vertexColorChannels,t):c),i,o,p,a),y=n.map((e,t)=>({world:p[t],sourceIndex:e.sourceIndex,sourceX:e.point.x,sourceY:e.point.y,sourceZ:e.point.z})),b=_.projectPolygon(ba(y,h));for(let n of b){let r=n.vertices.map(_o);f.push({vertices:r,sourceFace:{index:e,vertexIndexes:[...t]},normal:i,frontFacing:m,fillColor:v.fillColor,...v.lighting?{lighting:v.lighting}:{},opacity:l,...d?{wireframe:d,wireframeEdges:n.boundaryEdges}:{},depth:r.reduce((e,t)=>e+t.depth,0)/3})}}return f.sort((e,t)=>t.depth-e.depth||e.sourceFace.index-t.sourceFace.index),[{type:`mesh3d`,points:f.flatMap(e=>e.vertices.map(({x:e,y:t})=>({x:e,y:t}))),mesh3dTriangles:f,color:c,lineWidth:0,traceIndex:r,subplot:i.subplotId,bounds:{...i.bounds}}]}),S={experimental:!0,subplotId:i.subplotId,handedness:`right-handed`,depthOrder:`far-to-near`,sourcePointCount:d,sourceFaceCount:f,...u&&g?{mesh3dLod:{strategy:u.strategy,maxFaces:u.maxFaces,candidateFaceCount:g.candidateFaceCount,sampledFaceCount:g.sampledFaceCount,sampledVertexCount:g.sampledVertexCount,preparedTriangleCount:x.reduce((e,t)=>e+(t.mesh3dTriangles?.length??0),0)}}:{},interactionItemCount:g?g.sampledVertexCount+g.sampledFaceCount:d+f,projection:a.projection,camera:{...a,eye:[...a.eye],target:[...a.target],up:[...a.up]},...o?{lighting:o}:{},domains:h,bounds:{...i.bounds},segments:v,labels:y,tickLabels:b.tickLabels,tickLabelFont:r.axisTickLabelFont,axisColor:e.scene3d?.axisColor??r.axisColor,gridColor:e.scene3d?.gridColor??r.gridColor,axisLineWidth:Ea(e.scene3d?.axisLineWidth,r.axisLineWidth,`scene3d.axisLineWidth`),gridLineWidth:Ea(e.scene3d?.gridLineWidth,r.gridLineWidth,`scene3d.gridLineWidth`)};return{...t,primitives:x,scene3d:S}}function bo(e){let t=e??r.renderer;if(t===`canvas`||t===`webgl2`||t===`auto`)return t;throw Error(`scene3d.renderer must be 'canvas', 'webgl2', or 'auto'`)}function xo(e,t){let n={requested:t,resolved:`renderer-neutral`},r=e.scenes3d?.length?e.scenes3d:e.scene3d?[e.scene3d]:[];for(let e of r)e.renderer={...n};return e}function So(e){return`${a(e.x)}|${a(e.y)}`}function Co(e,t,n){if(n){let r=n.get(e)?.get(t);if(r)return r}let r=Math.max(Math.floor(t*2),2);if(e.length<=r)return n&&(n.has(e)||n.set(e,new Map),n.get(e)?.set(t,e)),e;let i=[],a=r,o=e.length/a;for(let t=0;t<a;t+=1){let n=Math.floor(t*o),r=Math.min(Math.floor((t+1)*o),e.length);if(r<=n)continue;let a=n,s=n;for(let t=n+1;t<r;t+=1)e[t].y<e[a].y&&(a=t),e[t].y>e[s].y&&(s=t);let c=[n,a,s,r-1].filter((e,t,n)=>n.indexOf(e)===t).sort((e,t)=>e-t);for(let t of c)i.push(e[t])}return i[i.length-1]!==e[e.length-1]&&i.push(e[e.length-1]),n&&(n.has(e)||n.set(e,new Map),n.get(e)?.set(t,i)),i}function wo(e,t,n,r,i){if(!e.length)return[];let o=Co(e,t,i),s=a(r.x),c=a(r.y),u=o.map(e=>({x:l(e.x,s),y:l(e.y,c)})),d=1/0,f=-1/0,p=1/0,m=-1/0;for(let e of u)e.x<d&&(d=e.x),e.x>f&&(f=e.x),e.y<p&&(p=e.y),e.y>m&&(m=e.y);let h=Math.max(f-d,2**-52),g=Math.max(m-p,2**-52);return u.map(e=>({x:(e.x-d)/h*t,y:(1-(e.y-p)/g)*n}))}function To(e,t){return{x:c(e.x,t.x),y:c(e.y,t.y)}}function Eo(e){return e.x===null||e.y===null}function Do(e,n){return n??e??t.connectGaps}function Oo(e,t,n){let r=So(t);if(n){let t=n.get(e)?.get(r);if(t)return t}let i=[];for(let n of e.data){if(Eo(n)){i.push(null);continue}i.push(To(n,t))}return n&&(n.has(e)||n.set(e,new Map),n.get(e)?.set(r,i)),i}function ko(e){let t=[],n=[];for(let r of e){if(r===null){n.length>0&&t.push(n),n=[];continue}n.push(r)}return n.length>0&&t.push(n),t}function Ao(e,t,n,r){if(e.length===0)return[];let i=a(r.x),o=a(r.y),s=e.map(e=>({x:l(e.x,i),y:l(e.y,o)})),c=1/0,u=-1/0,d=1/0,f=-1/0;for(let e of s)e.x<c&&(c=e.x),e.x>u&&(u=e.x),e.y<d&&(d=e.y),e.y>f&&(f=e.y);let p=Math.max(u-c,2**-52),m=Math.max(f-d,2**-52);return s.map(e=>({x:(e.x-c)/p*t,y:(1-(e.y-d)/m)*n}))}function jo(e,t){let n=e.map(e=>e.x),r=e.map(e=>e.y),i=A(n,t.x),a=A(r,t.y);if(!i||!a)throw Error(`Cannot resolve domain for empty dataset`);return{minX:i.min,maxX:i.max,minY:a.min,maxY:a.max}}function Mo(e,t,n,r,i,o=!0,s){let c=o?Co(e,t,s):e,u=a(i.x),d=a(i.y),f=c.map(e=>({x:l(e.x,u),y:l(e.y,d)})),p=Math.max(r.maxX-r.minX,2**-52),m=Math.max(r.maxY-r.minY,2**-52);return f.map(e=>({x:(e.x-r.minX)/p*t,y:(1-(e.y-r.minY)/m)*n}))}function No(e,t){return{x:l(e.x,a(t.x)),y:l(e.y,a(t.y))}}function Po(e,t,n){let r=No(e,n);return r.x>=t.minX&&r.x<=t.maxX&&r.y>=t.minY&&r.y<=t.maxY}function Fo(e,t,n,r){let i=No(e,r),a=No(t,r),o=a.x-i.x,s=a.y-i.y,c=0,l=1,u=[[-o,i.x-n.minX],[o,n.maxX-i.x],[-s,i.y-n.minY],[s,n.maxY-i.y]];for(let[e,t]of u){if(e===0){if(t<0)return!1;continue}let n=t/e;if(e<0){if(n>l)return!1;n>c&&(c=n)}else{if(n<c)return!1;n<l&&(l=n)}}return!0}function Io(e,t,n){if(e.length<=2)return e;let r=[],i=new Set,a=t=>{t<0||t>=e.length||i.has(t)||(i.add(t),r.push(e[t]))};for(let r=0;r<e.length;r+=1){if(Po(e[r],t,n)){a(r-1),a(r),a(r+1);continue}r>0&&Fo(e[r-1],e[r],t,n)&&(a(r-1),a(r))}return r}function Lo(e){let t=D(e.x?.padding),n=D(e.y?.padding);return t.start>0||t.end>0||n.start>0||n.end>0}function Ro(e){return k(e.x)||k(e.y)}function zo(e,t,n,r){let i=n,a=r,o=t.x-e.x,s=t.y-e.y,c=0,l=1,u=[[-o,e.x-0],[o,i-e.x],[-s,e.y-0],[s,a-e.y]];for(let[e,t]of u){if(e===0){if(t<0)return null;continue}let n=t/e;if(e<0){if(n>l)return null;n>c&&(c=n)}else{if(n<c)return null;n<l&&(l=n)}}return[{x:e.x+c*o,y:e.y+c*s},{x:e.x+l*o,y:e.y+l*s}]}function Bo(e,t,n){if(e.length<2)return[];let r=[],i=[],a=(e,t)=>Math.abs(e.x-t.x)<1e-9&&Math.abs(e.y-t.y)<1e-9;for(let o=0;o<e.length-1;o+=1){let s=zo(e[o],e[o+1],t,n);if(!s){i.length>1&&r.push(i),i=[];continue}let[c,l]=s;if(i.length===0){i.push(c,l);continue}let u=i[i.length-1];a(u,c)?i.push(l):(i.length>1&&r.push(i),i=[c,l])}return i.length>1&&r.push(i),r}function Vo(e,t,n){return e.filter(e=>e.x>=0&&e.x<=t&&e.y>=0&&e.y<=n)}function Ho(e,t,n,r,i,a,o,s,c){let l=ae(e,t,n,r,i,a,o,s,c);if(l?.primitives?.[0]?.points)return l.primitives[0].points;let u=fe(e,t,n,r,i,a,o,s,c);return u?.primitives?.[0]?.points?u.primitives[0].points:null}function Uo(e,t,n,r,i,a){let o=ie(e,t,n,r,i,a.minX,a.maxX,a.minY,a.maxY);if(o?.primitives?.[0]?.points)return o.primitives[0].points;let s=de(e,t,n,r,i,a.minX,a.maxX,a.minY,a.maxY);return s?.primitives?.[0]?.points?s.primitives[0].points:null}function Wo(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||!Array.isArray(t.primitives)?null:t}function Go(e){return Wo(ne(e))||Wo(se(e))||null}function Ko(e){return e??`auto`}function qo(e,t,n,r,i){let a=new Map,o=new Map;for(let s of t){if(s.trace.visible===!1)continue;let t=n.get(s.xAxisId)??{},c=r.get(s.yAxisId)??{},l=Oo(s.trace,{x:t,y:c},i);for(let e of l)e!==null&&(a.has(s.xAxisId)||a.set(s.xAxisId,[]),o.has(s.yAxisId)||o.set(s.yAxisId,[]),a.get(s.xAxisId)?.push(e.x),o.get(s.yAxisId)?.push(e.y));let u=_(e.errorBars,s.trace.errorBars,``),d=a.get(s.xAxisId)??[],f=o.get(s.yAxisId)??[];s.trace.data.forEach((e,n)=>{x(e,n,u,t,c,d,f)}),d.length>0&&a.set(s.xAxisId,d),f.length>0&&o.set(s.yAxisId,f)}let s=new Map,c=new Map;for(let[e,t]of n){let n=A(a.get(e)??[],t);n&&s.set(e,n)}for(let[e,t]of r){let n=A(o.get(e)??[],t);n&&c.set(e,n)}return{x:s,y:c}}function Jo(...e){return[...e].reverse().find(e=>typeof e==`string`&&e.trim().length>0)}function Yo(e,...t){let n=[...t].reverse().find(e=>typeof e==`number`&&Number.isFinite(e));return n===void 0?e:Math.max(0,n)}function Xo(e,t,n,...r){let i=[...r].reverse().find(e=>typeof e==`number`&&Number.isFinite(e));return i===void 0?e:Math.min(n,Math.max(t,i))}function Zo(t,n){return typeof n!=`number`||!Number.isFinite(n)?t:Math.max(e.minSize,n)}function Qo(e,n,r,i){return{color:Jo(e,n?.color,r?.color,i.color,i.lineStyle?.color)??e,lineWidth:Yo(t.lineWidth,n?.lineWidth,r?.lineWidth,i.lineStyle?.lineWidth),opacity:Xo(t.opacity,0,1,n?.opacity,r?.opacity,i.lineStyle?.opacity),interpolation:_t(i.lineStyle?.interpolation??r?.interpolation??n?.interpolation),pattern:et(i.lineStyle?.pattern??r?.pattern??n?.pattern)}}function $o(e,t){return t===void 0?e:typeof t==`boolean`?{...e,show:t}:{show:t.show??!0,size:Zo(e.size,t.size),color:Jo(e.color,t.color),shape:jt(t.shape,e.shape,`markers.shape`)}}function es(t,n,r){if(!(t===void 0&&n===void 0&&r===void 0))return $o($o(t?{show:t.show??!0,size:Zo(e.size,t.size),color:Jo(t.color),shape:jt(t.shape,e.shape,`style.trace.marker.shape`)}:{show:e.show,size:e.size,shape:e.shape},n),r)}function ts(e){return e===`linear`||e===`polynomial`||e===`exponential`||e===`logarithmic`||e===`power`||e===`gaussian`||e===`cauchyLorentz`}function ns(e,t,n,r){return Math.min(r,Math.max(n,Number.isInteger(e)?e:t))}function rs(e,n){let r=n??e;if(r===void 0||typeof r==`boolean`)return{show:r??t.trendline.show,method:t.trendline.method,degree:t.trendline.degree,samples:t.trendline.samples};let i=r;return{show:i.show??!0,method:ts(i.method)?i.method:t.trendline.method,degree:ns(i.degree,t.trendline.degree,t.trendline.minDegree,t.trendline.maxDegree),samples:ns(i.samples,t.trendline.samples,t.trendline.minSamples,t.trendline.maxSamples),color:i.color}}function is(e){return e.filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}function as(e){if(e.length===0)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)a.x<t&&(t=a.x),a.x>n&&(n=a.x),a.y<r&&(r=a.y),a.y>i&&(i=a.y);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:{minX:t,maxX:n,minY:r,maxY:i}}function os(e){let t=e.maxX-e.minX,n=(e.minX+e.maxX)/2;return e=>(e-n)/t*2}function ss(e,t){let n=[],r=1;for(let i=0;i<=t;i+=1)n.push(r),r*=e;return n}function cs(e,t){let n=t.length,r=e.map((e,n)=>[...e,t[n]]);for(let e=0;e<n;e+=1){let t=e,i=Math.abs(r[e][e]);for(let a=e+1;a<n;a+=1){let n=Math.abs(r[a][e]);n>i&&(i=n,t=a)}if(i<=1e-12)return null;t!==e&&([r[e],r[t]]=[r[t],r[e]]);let a=r[e][e];for(let t=e;t<=n;t+=1)r[e][t]/=a;for(let t=0;t<n;t+=1){if(t===e)continue;let i=r[t][e];if(i!==0)for(let a=e;a<=n;a+=1)r[t][a]-=i*r[e][a]}}return r.map(e=>e[n])}function ls(e,t){let n=e[0]?.length??0;if(e.length===0||t.length!==e.length||n===0)return null;let r=Array.from({length:n},()=>Array.from({length:n},()=>0)),i=Array.from({length:n},()=>0);for(let a=0;a<e.length;a+=1){let o=e[a],s=t[a];for(let e=0;e<n;e+=1){i[e]+=o[e]*s;for(let t=0;t<n;t+=1)r[e][t]+=o[e]*o[t]}}return cs(r,i)}function us(e,t){let n=0;for(let r=e.length-1;r>=0;--r)n=n*t+e[r];return n}function ds(e,t){let n=as(e);if(!n||!(n.minX<n.maxX)||e.length<2)return null;let r=Math.min(t,e.length-1);if(r<1)return null;let i=os(n),a=ls(e.map(e=>ss(i(e.x),r)),e.map(e=>e.y));return a?{degree:r,evaluate(e){let t=us(a,i(e));return Number.isFinite(t)?t:null}}:null}function fs(e,t,n,r){let i=[],a=[];for(let r of e){let e=t(r.x),o=n(r.y);e===null||o===null||!Number.isFinite(e)||!Number.isFinite(o)||(i.push([1,e]),a.push(o))}if(i.length<2)return null;let o=ls(i,a);return o?{evaluate(e){let n=t(e);if(n===null||!Number.isFinite(n))return null;let i=r(o[0]+o[1]*n);return Number.isFinite(i)?i:null}}:null}function ps(e){let t=e[0],n=e[0];for(let r of e)r.y<t.y&&(t=r),r.y>n.y&&(n=r);return{minPoint:t,maxPoint:n}}function ms(e,t,n,r,i){let a=0,o=0;for(let r of e){let e=Math.max(0,(r.y-t)/n);!Number.isFinite(e)||e<=0||(a+=e,o+=r.x*e)}let s=a>0?o/a:r,c=0;for(let r of e){let e=Math.max(0,(r.y-t)/n);if(!Number.isFinite(e)||e<=0)continue;let i=r.x-s;c+=i*i*e}let l=a>0?Math.sqrt(c/a):i;return{center:Number.isFinite(s)?s:r,width:Number.isFinite(l)&&l>0?l:i}}function hs(e,t,n,r){let i=[...e].sort((e,t)=>e.x-t.x),a=[];for(let e=0;e<i.length-1;e+=1){let t=i[e],o=i[e+1],s=(t.y-n)/r-.5,c=(o.y-n)/r-.5;if(!Number.isFinite(s)||!Number.isFinite(c))continue;if(s===0){a.push(t.x);continue}if(s*c>0)continue;let l=s-c;if(l===0)continue;let u=s/l;a.push(t.x+(o.x-t.x)*u)}let o=a.filter(e=>e<t).map(e=>t-e).sort((e,t)=>e-t)[0],s=a.filter(e=>e>t).map(e=>e-t).sort((e,t)=>e-t)[0];return Number.isFinite(o)&&Number.isFinite(s)?(o+s)/2:Number.isFinite(o)?o:Number.isFinite(s)?s:null}function gs(e,t){let n=as(e);if(!n||!(n.minX<n.maxX)||!(n.minY<n.maxY)||e.length<3)return null;let r=e.reduce((e,t)=>e+t.y,0)/e.length,{minPoint:i,maxPoint:a}=ps(e),o=n.maxY-r>=r-n.minY,s=o?n.minY:n.maxY,c=o?a:i,l=c.y-s,u=n.maxX-n.minX;if(!Number.isFinite(l)||Math.abs(l)<=2**-52)return null;let d=ms(e,s,l,c.x,u/6),f=t===`cauchyLorentz`?hs(e,d.center,s,l)??d.width:d.width,p=Math.max(2**-52,u/1e6),m=Math.max(p,f);return{evaluate(e){let n=(e-d.center)/m,r=t===`gaussian`?s+l*Math.exp(-.5*n*n):s+l/(1+n*n);return Number.isFinite(r)?r:null}}}function _s(e,t){let n=as(e);if(!n||!(n.minX<n.maxX))return null;if(t.method===`linear`)return ds(e,1);if(t.method===`polynomial`)return ds(e,t.degree);if(t.method===`exponential`){let t=os(n);return fs(e,e=>t(e),e=>e>0?Math.log(e):null,e=>Math.exp(e))}return t.method===`logarithmic`?fs(e,e=>e>0?Math.log(e):null,e=>e,e=>e):t.method===`power`?fs(e,e=>e>0?Math.log(e):null,e=>e>0?Math.log(e):null,e=>Math.exp(e)):t.method===`gaussian`||t.method===`cauchyLorentz`?gs(e,t.method):null}function vs(e,t,n,r){let i=[],a=n-t;if(!(a>0))return i;for(let n=0;n<r;n+=1){let o=t+a*(r<=1?0:n/(r-1)),s=e.evaluate(o);s===null||!Number.isFinite(s)||i.push({x:o,y:s})}return i}function ys(e,n){let r=is(e);if(r.length<2)return null;let i=as(r);if(!i||!(i.minX<i.maxX))return null;let a=_s(r,n);if(!a)return null;let o=n.method===`linear`?t.trendline.minSamples:n.samples,s=vs(a,i.minX,i.maxX,o);return s.length<2?null:{points:s,degree:n.method===`polynomial`?a.degree:void 0}}function bs(e){if(!e.trendline.show||e.sourcePoints.length<2||!e.domain)return[];let n=ys(e.sourcePoints,e.trendline);if(!n)return[];try{let r=Mo(n.points,e.width,e.height,e.domain,e.axisOptions,!1),i={sourceTraceIndex:e.traceIndex,method:e.trendline.method,...n.degree===void 0?{}:{degree:n.degree}};return Bo(r,e.width,e.height).map(n=>({type:`line`,points:n,color:e.trendline.color??e.color,lineWidth:e.lineWidth,...e.opacity===t.opacity?{}:{lineOpacity:e.opacity},subplot:e.subplotId,bounds:e.bounds,trendline:i}))}catch{return[]}}function xs(e,t,n,r,i=!1){let o=l(e,a(n)),s=Math.max(t.max-t.min,2**-52),c=(o-t.min)/s*r;return i?r-c:c}function Ss(e,t,n){let r=u(e,t?{...t,labelPrefix:void 0,labelSuffix:void 0}:void 0,e=>n.decimals<=0?String(Math.round(e)):e.toFixed(n.decimals));return`${n.prefix}${r}${n.suffix}`}function Cs(e,t,n,r,i,a,o){if(!t.show)return;let s=n?.show?n.size:0,l=[];return e.data.forEach((e,n)=>{if(e.x===null||e.y===null)return;let u=c(e.x,i.x),d=c(e.y,i.y),f=xs(u,{min:r.minX,max:r.maxX},i.x,a),p=xs(d,{min:r.minY,max:r.maxY},i.y,o,!0);if(f<0||f>a||p<0||p>o)return;let m=t.position===`auto`?p-s-t.offset-t.lineHeight>=0?`above`:`below`:t.position,h=s+t.offset;l.push({x:f,y:m===`above`?p-h:p+h,value:d,text:Ss(d,i.y,t),color:t.color,font:t.font,lineHeight:t.lineHeight,position:m,textBaseline:m===`above`?`bottom`:`top`,sourceIndex:n,collisionPadding:t.collisionPadding})}),l.length>0?l:void 0}function ws(e,t,n){let r=Math.max(0,e.x),i=Math.min(t,e.x+e.width),a=Math.max(0,e.y),o=Math.min(n,e.y+e.height);return!(i>r)||!(o>a)?null:{...e,x:r,y:a,width:i-r,height:o-a}}function Ts(e,t){let{cornerRadius:n,...r}=e,i=Math.min(t,e.width/2,e.height/2);return i>0?{...r,cornerRadius:i}:r}function Es(e,t,n,r){return`${n}${t<=0?String(Math.round(e)):e.toFixed(t)}${r}`}function Ds(e,t,n,r){if(t.position===`center`)return{x:e.x+e.width/2,y:e.y+e.height/2,position:t.position,textAlign:`center`,textBaseline:`middle`};let i=r===`grouped`?e.value>=e.baseline:(e.normalizedValue??e.value)>=0,a=t.position===`inside-end`;if(n===`horizontal`){let n=a?Math.min(t.offset,e.width/2):t.offset;return{x:i?e.x+e.width+(a?-n:n):e.x+(a?n:-n),y:e.y+e.height/2,position:t.position,textAlign:i===a?`right`:`left`,textBaseline:`middle`}}let o=a?Math.min(t.offset,e.height/2):t.offset;return{x:e.x+e.width/2,y:i?e.y+(a?o:-o):e.y+e.height+(a?-o:o),position:t.position,textAlign:`center`,textBaseline:i===a?`top`:`bottom`}}function Os(e,t,n,r){if(!t.show)return;let i=e.filter(e=>e.width>=t.minBarWidth&&e.height>=t.minBarHeight).map(e=>({...Ds(e,t,n,r),value:e.value,text:Es(e.value,t.decimals,t.prefix,t.suffix),color:t.color,font:t.font,sourceIndex:e.sourceIndex}));return i.length>0?i:void 0}function ks(e,t,n,r,i,a,o){return{...e,primitives:e.primitives.map(e=>{if(e.type!==`bar`||!e.bars?.length)return e;let s=e.traceIndex===void 0?n:t.get(e.traceIndex)??n,c=e.traceIndex===void 0?i:r.get(e.traceIndex)??i,l=e.bars.map(e=>Ts(e,c));return{...e,bars:l,barValueLabels:Os(l,s,a,o)}})}}function As(e,t,n,r,i,a,o,s,l,u,d,f,p){return d===`grouped`?{...e,primitives:e.primitives.map(e=>{if(e.type!==`bar`||e.traceIndex===void 0)return e;let d=n[e.traceIndex];if(!d||d.trace.visible===!1)return e;let{trace:m,subplotId:h,xAxisId:g,yAxisId:v}=d,y=l.get(h),b=r.get(g)??{},x=i.get(v)??{},S=a.x.get(g),C=a.y.get(v);if(!y||!S||!C)return e;let T=_(t.errorBars,m.errorBars,e.color),E={...T,x:u===`horizontal`&&T.x,y:u===`vertical`&&T.y};if(!E.show||!E.x&&!E.y)return e;let D=Math.max(1,y.bounds.right-y.bounds.left),O=Math.max(1,y.bounds.bottom-y.bounds.top),k=Ae(h,g,v),A=o.get(k)??[e.traceIndex],j=Math.max(0,A.indexOf(e.traceIndex)),M=Math.max(1,A.length),N=u===`horizontal`?x:b,P=u===`horizontal`?C:S,ee=u===`horizontal`?O:D,F=$e(s.get(k)??[],N,P,ee),I=Math.max(p,F*f/M),L=(j-(M-1)/2)*I,te=new Map;m.data.forEach((e,t)=>{if(e.x===null||e.y===null)return;let n=c(e.x,b),r=c(e.y,x);te.set(t,{x:xs(n,S,b,D)+(u===`vertical`?L:0),y:xs(r,C,x,O,!0)+(u===`horizontal`?L:0)})});let R=w(m,E,b,x,S,C,D,O,te);return R?{...e,errorBars:R,errorBarStyle:T.style}:e})}:e}function js(e){ke(e);let t=Ko(e.engine),r={...e,axes:Fn(e.axes,e.viewport)};He(r);let i=Ee(r),o=De(r),s=we(r),l=new Map(s.map(e=>[e.id,e])),u=Oe(r),d=Ze(r),f=Qe(u),p=Re(e.bar),m=Ve(e.bar),h=Le(e.bar),g=Ue(),_=We(e.bar),v=Ge(e.bar),y=Ke(e.bar),b=Je(e.bar?.valueLabels),x=new Map(u.map((t,n)=>[n,Je(e.bar?.valueLabels,t.trace.bar?.valueLabels)])),S=new Map(u.map((t,n)=>[n,Ke(e.bar,t.trace.bar)])),C=new Map,w=new Map,T=new Map;if(u.forEach(e=>{if(e.trace.visible===!1)return;let t=i.get(e.xAxisId)??{},n=o.get(e.yAxisId)??{},r=Ae(e.subplotId,e.xAxisId,e.yAxisId),a=C.get(r)??[];for(let i of e.trace.data){if(i.x===null||i.y===null)continue;let e=c(i.x,t),o=c(i.y,n),s=m===`horizontal`?o:e;if(a.push(s),p===`normalized`){let t=m===`horizontal`?e:o,n=`${r}\u0000${s}`,i=T.get(n)??{positive:0,negative:0};t>=0?i.positive+=t:i.negative+=t,T.set(n,i)}}C.set(r,a)}),t===`rust`){let t=Go({width:e.width,height:e.height,mode:p,orientation:m,barWidthRatio:h,minBarWidth:g,borderColor:v,borderWidth:_,traces:u.flatMap((t,r)=>{let{trace:s,subplotId:u,xAxisId:h,yAxisId:g}=t;if(s.visible===!1)return[];let _=l.get(u);if(!_)throw Error(`Unknown subplot id '${u}' for trace`);let v=i.get(h)??{},y=o.get(g)??{},b=d.x.get(h),x=d.y.get(g);if(!b||!x)return[];let S=Math.max(1,_.bounds.right-_.bounds.left),w=Math.max(1,_.bounds.bottom-_.bounds.top),T=Ae(u,h,g),E=f.get(T)??[r],D=ze(p)?0:Math.max(0,E.indexOf(r)),O=ze(p)?1:Math.max(1,E.length),k=m===`horizontal`?y:v,A=m===`horizontal`?x:b,j=m===`horizontal`?w:S,M=$e(C.get(T)??[],k,A,j),N=Qo(n[r%n.length],e.style?.trace?.line,e.lineStyle,s),P=Ge(e.bar,s.bar),ee=We(e.bar,s.bar),F=[],I=[],L=[],te=!1;return s.data.forEach((e,t)=>{if(e.x===null||e.y===null)return;F.push({x:c(e.x,v),y:c(e.y,y)}),L.push(t);let n=m===`horizontal`?v:y,r=e.base!==void 0&&e.base!==null;te||=r,I.push(e.base===void 0||e.base===null?0:c(e.base,n))}),F.length===0?[]:[{points:F,baselines:te?I:void 0,sourceIndexes:L,groupKey:T,groupIndex:D,groupCount:O,slotWidth:M,subplotWidth:S,subplotHeight:w,xDomain:b,yDomain:x,xScale:a(v),yScale:a(y),color:N.color,lineWidth:N.lineWidth,borderColor:P,borderWidth:ee,traceIndex:r,subplot:u,bounds:_.bounds}]})});if(!t)throw Error(`Rust bar scene engine is not available in current runtime`);return As(ks(t,x,b,S,y,m,p),r,u,i,o,d,f,C,l,m,p,h,g)}let E=u.flatMap((t,r)=>{let{trace:a,subplotId:s,xAxisId:u,yAxisId:_}=t;if(a.visible===!1)return[];let v=l.get(s);if(!v)throw Error(`Unknown subplot id '${s}' for trace`);let y=i.get(u)??{},S=o.get(_)??{},E=d.x.get(u),D=d.y.get(_);if(!E||!D)return[];let O=Math.max(1,v.bounds.right-v.bounds.left),k=Math.max(1,v.bounds.bottom-v.bounds.top),A=Ae(s,u,_),j=f.get(A)??[r],M=ze(p)?0:Math.max(0,j.indexOf(r)),N=ze(p)?1:Math.max(1,j.length),P=m===`horizontal`?S:y,ee=m===`horizontal`?D:E,F=m===`horizontal`?k:O,I=$e(C.get(A)??[],P,ee,F),L=Math.max(g,I*h/N),te=(M-(N-1)/2)*L,R=Qo(n[r%n.length],e.style?.trace?.line,e.lineStyle,a),z=Ge(e.bar,a.bar),ne=We(e.bar,a.bar),B=Ke(e.bar,a.bar),V=x.get(r)??b,re=[],ie=[];return a.data.forEach((e,t)=>{if(e.x===null||e.y===null)return;let n=c(e.x,y),r=c(e.y,S),i=m===`horizontal`?r:n,a=m===`horizontal`?n:r,o=`${A}\u0000${i}`,s=w.get(o)??{positive:0,negative:0},l=p===`normalized`?Be(a,T.get(o)?.positive??0,T.get(o)?.negative??0):void 0,u=l??a,d=e.base===void 0||e.base===null?0:c(e.base,m===`horizontal`?y:S),f=u;ze(p)&&(u>=0?(d=s.positive,s.positive+=u,f=s.positive):(d=s.negative,s.negative+=u,f=s.negative),w.set(o,s));let h=ws(m===`horizontal`?(()=>{let e=xs(r,D,S,k,!0),i=xs(d,E,y,O),a=xs(f,E,y,O);return{x:Math.min(a,i),y:e+te-L/2,width:Math.abs(i-a),height:L,value:n,baseline:d,...l===void 0?{}:{normalizedValue:l},sourceIndex:t}})():(()=>{let e=xs(n,E,y,O),i=xs(d,D,S,k,!0),a=xs(f,D,S,k,!0);return{x:e+te-L/2,y:Math.min(a,i),width:L,height:Math.abs(i-a),value:r,baseline:d,...l===void 0?{}:{normalizedValue:l},sourceIndex:t}})(),O,k);if(!h)return;let g=Ts(h,B);re.push(g),m===`horizontal`?ie.push({x:f>=d?g.x+g.width:g.x,y:g.y+g.height/2}):ie.push({x:g.x+g.width/2,y:f>=d?g.y:g.y+g.height})}),re.length===0?[]:[{type:`bar`,points:ie,bars:re,barValueLabels:Os(re,V,m,p),color:R.color,lineWidth:R.lineWidth,borderColor:z,borderWidth:ne,subplot:s,bounds:v.bounds,traceIndex:r}]}).filter(e=>e.points.length>0);return As({width:e.width,height:e.height,primitives:E},r,u,i,o,d,f,C,l,m,p,h,g)}function Ms(e,t){return t===void 0?e:typeof e==`object`&&e&&!Array.isArray(e)&&typeof t==`object`&&t&&!Array.isArray(t)?{...e,...t}:t}function Ns(e,t){if(!(e===void 0||typeof e==`boolean`)){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be a boolean or an object`);if(e.enabled!==void 0&&typeof e.enabled!=`boolean`)throw Error(`${t}.enabled must be a boolean`);if(e.includeTable!==void 0&&typeof e.includeTable!=`boolean`)throw Error(`${t}.includeTable must be a boolean`);for(let n of[`label`,`description`]){let r=e[n];if(r!==void 0&&(typeof r!=`string`||r.trim().length===0))throw Error(`${t}.${n} must be a non-empty string`)}if(e.maxRows!==void 0&&(!Number.isInteger(e.maxRows)||e.maxRows<1||e.maxRows>1e3))throw Error(`${t}.maxRows must be an integer between 1 and 1000`)}}function Ps(e){Ns(e.scene3d?.accessibility,`scene3d.accessibility`);for(let[t,n]of Object.entries(e.scene3d?.subplots??{}))Ns(n.accessibility,`scene3d.subplots.${t}.accessibility`)}function Fs(e,t){return t===void 0?e:typeof e==`object`&&e&&!Array.isArray(e)&&typeof t==`object`&&t&&!Array.isArray(t)?{...e,...t}:t}function Is(e){if(!(e===void 0||e===!1)){if(e===!0)return{maxRows:r.accessibilityMaxRows,includeTable:r.accessibilityIncludeTable};if(e.enabled!==!1)return{label:e.label?.trim(),description:e.description?.trim(),maxRows:e.maxRows??r.accessibilityMaxRows,includeTable:e.includeTable??r.accessibilityIncludeTable}}}function Ls(e){return e==null?null:e instanceof Date?e.toISOString():e}function Rs(e){return e.title?.trim()||(e.type===`scatter3d`?r.accessibilityScatter3dLabel:e.type===`line3d`?r.accessibilityLine3dLabel:e.type===`surface`?r.accessibilitySurfaceLabel:e.type===`pie3d`?`Pie3D chart`:r.accessibilityMesh3dLabel)}function zs(e){let t=e=>Number.isInteger(e)?String(e):Number(e.toPrecision(6)).toString();return[`x ${t(e.x.min)} to ${t(e.x.max)}`,`y ${t(e.y.min)} to ${t(e.y.max)}`,`z ${t(e.z.min)} to ${t(e.z.max)}`].join(`, `)}function Bs(e,t,n,r,i){let a=Zi(t,r,e.subplotId),o=r.filter(e=>n[e]?.visible!==!1),s=o.map(e=>{let r=n[e],i=t.type===`mesh3d`?(r.mesh3d?.faces??t.mesh3d?.faces??[]).length:void 0;return{traceIndex:e,...r.name?{name:r.name}:{},rowCount:r.data.length,...i===void 0?{}:{faceCount:i}}}),c=s.reduce((e,t)=>e+t.rowCount,0),l=[];for(let e of o){let t=n[e];for(let n=0;n<t.data.length&&!(l.length>=i.maxRows);n+=1){let r=t.data[n];l.push({traceIndex:e,...t.name?{traceName:t.name}:{},sourceIndex:n,x:Ls(r.x),y:Ls(r.y),z:Ls(r.z)})}if(l.length>=i.maxRows)break}let u=i.label??Rs(t),d=s.reduce((e,t)=>e+(t.faceCount??0),0),f=c>l.length;return{label:u,description:i.description??[`${u}.`,`Experimental ${t.type} scene ${e.subplotId} with ${s.length} visible ${s.length===1?`trace`:`traces`} and ${c} source ${c===1?`row`:`rows`}.`,...t.type===`mesh3d`?[`${d} source ${d===1?`face`:`faces`}.`]:[],`Camera-independent domains: ${zs(a)}.`,...f?[`The data table shows the first ${l.length} rows.`]:[]].join(` `),domains:a,maxRows:i.maxRows,totalRowCount:c,rows:l,truncated:f,includeTable:i.includeTable,traces:s}}function Vs(e,t){Ps(t);let n=e.scenes3d?.length?e.scenes3d:e.scene3d?[e.scene3d]:[];if(n.length===0)return e;let r=pe(t),i=t.subplots===void 0?void 0:Te(t);for(let e of n){let n=t.scene3d?.subplots?.[e.subplotId]?.accessibility,a=Is(Fs(t.scene3d?.accessibility,n));if(!a){delete e.accessibility;continue}if(t.type===`pie3d`){let{datum:n}=Zn(t),r=t.pie?.traces??t.traces??[],i=[...new Set(n.map(e=>e.traceIndex))],o=a.label??Rs(t),s=n.slice(0,a.maxRows).map(e=>({traceIndex:e.traceIndex,...r[e.traceIndex]?.name?{traceName:r[e.traceIndex].name}:{},sourceIndex:e.sourceIndex,x:e.label,y:e.value,z:null}));e.accessibility={label:o,description:a.description??`${o}. Experimental pie3d scene with ${n.length} visible sectors.`,domains:e.domains,maxRows:a.maxRows,totalRowCount:n.length,rows:s,truncated:n.length>s.length,includeTable:a.includeTable,traces:i.map(e=>({traceIndex:e,...r[e]?.name?{name:r[e].name}:{},rowCount:n.filter(t=>t.traceIndex===e).length}))};continue}e.accessibility=Bs(e,t,r,i?i.flatMap((t,n)=>t.subplotId===e.subplotId?[n]:[]):r.map((e,t)=>t),a)}return e}function Hs(e,t){let r=bo(e.scene3d?.renderer);if(Ps(e),e.subplots===void 0)return xo(Vs(t(e),e),r);let i=pe(e),a=Te(e),o=new Set(a.map(e=>e.subplotId)),s=we(e).map(e=>e.id).filter(e=>o.has(e));if(s.length<=1){let n=s[0],i=n?e.scene3d?.subplots?.[n]:void 0,a=Ms(e.scene3d?.lighting,i?.lighting);return xo(Vs(t({...e,scene3d:{...e.scene3d??{},...i??{},lighting:a,subplots:e.scene3d?.subplots}}),e),r)}let c=s.map(r=>{let o=a.flatMap((e,t)=>e.subplotId===r?[t]:[]),s=e.scene3d?.subplots?.[r],c=Ms(e.scene3d?.lighting,s?.lighting),l=t({...e,data:void 0,traces:o.map(e=>i[e]),scene3d:{...e.scene3d??{},...s??{},lighting:c,subplots:e.scene3d?.subplots}});return l.primitives.forEach(t=>{let r=o[t.traceIndex??0];t.traceIndex=r;let a=i[r];if(e.type===`scatter3d`||e.type===`line3d`?a.lineStyle?.color===void 0&&a.color===void 0&&e.lineStyle?.color===void 0&&e.style?.trace?.line?.color===void 0:a.color===void 0){let i=n[r%n.length];t.color=i;let o=a.mesh3d?.faceColors!==void 0||a.mesh3d?.vertexColors!==void 0||a.mesh3d?.faceColors===void 0&&a.mesh3d?.vertexColors===void 0&&(e.mesh3d?.faceColors!==void 0||e.mesh3d?.vertexColors!==void 0);if(t.type===`mesh3d`&&!o)for(let e of t.mesh3dTriangles??[])e.lighting?(e.lighting.baseColor=i,e.fillColor=to(i,e.lighting.intensity,e.lighting.specularIntensity)):e.fillColor=i;if(t.type===`scatter3d`&&e.scatter3d?.colorScale===void 0)for(let e of t.scatter3dPoints??[])e.fillColor=i}}),l}),l=c.flatMap(e=>e.scene3d?[e.scene3d]:[]);return xo(Vs({width:e.width,height:e.height,primitives:c.flatMap(e=>e.primitives),scene3d:l[0],scenes3d:l},e),r)}function Us(e){if(e={...e,viewport:Nn(e)},rt(e),v(e),pt(e),At(e),gt(e),e.type===`bar`)return st(js(e),e);if(e.type===`polar`)return Qr(e);if(e.type===`pie`)return or(e);if(e.type===`heatmap`)return st(On(e),e);if(e.type===`wonderplot`)return st(Pi(e),e);if(e.type===`scatter3d`)return Hs(e,Ba);if(e.type===`line3d`)return Hs(e,Va);if(e.type===`surface`)return Hs(e,ao);if(e.type===`mesh3d`)return Hs(e,yo);if(e.type===`pie3d`)return Hs(e,vo);if(e.type!==`line`)throw Error(`Only 'line', 'bar', 'polar', 'pie', 'heatmap', 'wonderplot', and experimental 'scatter3d', 'line3d', 'surface', 'mesh3d', and 'pie3d' are supported`);ke(e);let r={...e,axes:Fn(e.axes,e.viewport)},i=Ko(e.engine),o=Ee(r),s=De(r),c=we(r),l=new Map,u=new WeakMap,d=new Map(c.map(e=>[e.id,e])),f=Oe(r),p=qo(r,f,o,s,l),m=f.flatMap(({trace:r,subplotId:c,xAxisId:f,yAxisId:m},h)=>{if(r.visible===!1)return[];let g=d.get(c);if(!g)throw Error(`Unknown subplot id '${c}' for trace`);let v=Math.max(1,g.bounds.right-g.bounds.left),y=Math.max(1,g.bounds.bottom-g.bounds.top),b={x:o.get(f)??{},y:s.get(m)??{}},x=Do(e.connectGaps,r.connectGaps),S=Oo(r,b,l),C=S.filter(e=>e!==null),T=a(b.x),E=a(b.y),O=C.length!==S.length,k=D(b.x?.padding),A=D(b.y?.padding),j=Ro(b),M=Lo(b),N=(p.x.has(f)&&p.y.has(m)?{minX:p.x.get(f)?.min,maxX:p.x.get(f)?.max,minY:p.y.get(m)?.min,maxY:p.y.get(m)?.max}:null)??((M||j)&&C.length>0?jo(C,b):null),P=N&&j?Io(C,N,b):C;if(j&&P.length===0)return[];let ee=i===`ts`||O&&!x?null:N?Uo(P,v,y,T,E,N):Ho(P,v,y,T,E,k.start,k.end,A.start,A.end);if(i===`rust`&&!ee&&!(O&&!x))throw Error(`Rust engine is not available in current runtime`);let F=rs(e.trendline,r.trendline),I=Qo(n[h%n.length],e.style?.trace?.line,e.lineStyle,r),L=es(e.style?.trace?.marker,e.markers,r.markers),te=kt(e.pointLabels,r.pointLabels),R=I.color,z=N??(C.length>0?jo(C,b):null),ne=_(e.errorBars,r.errorBars,R),B=z?w(r,ne,b.x,b.y,{min:z.minX,max:z.maxX},{min:z.minY,max:z.maxY},v,y):void 0,V=z?Cs(r,te,L,z,b,v,y):void 0,re=z?mt(e,r,b.y,{min:z.minY,max:z.maxY},y):void 0,ie=F.show?bs({trendline:F,sourcePoints:C,width:v,height:y,domain:N??(C.length>0?jo(C,b):null),axisOptions:b,color:R,lineWidth:I.lineWidth,opacity:I.opacity,traceIndex:h,subplotId:c,bounds:g.bounds}):[];if(O&&!x){let e=ko(S),n=N?Mo(C,v,y,N,b,!1):Ao(C,v,y,b),r=0,i=e.map(e=>{let i=[];for(let t=0;t<e.length;t+=1){let a=e[t],o=C.findIndex((e,t)=>t>=r&&e.x===a.x&&e.y===a.y);o<0||(r=o+1,i.push(n[o]))}return{type:`line`,points:vt(i,I.interpolation),color:R,lineWidth:I.lineWidth,...I.opacity===t.opacity?{}:{lineOpacity:I.opacity},...I.interpolation===`linear`?{}:{interpolation:I.interpolation,markerPoints:i},...I.pattern===`solid`?{}:{linePattern:I.pattern},...re?{areaFill:re}:{},subplot:c,traceIndex:h,bounds:g.bounds,markers:L}}).filter(e=>e.points.length>0);if(!j)return V&&i[0]&&(i[0].linePointLabels=V),B&&i[0]&&(i[0].errorBars=B,i[0].errorBarStyle=ne.style),[...i,...ie];let a=i.flatMap((e,t)=>Bo(e.points,v,y).map((n,r)=>({...e,points:n,...t===0&&r===0&&V?{linePointLabels:V}:{},...e.markerPoints?{markerPoints:r===0?Vo(e.markerPoints,v,y):[]}:{}})));return a.length===0&&B&&i[0]&&a.push({...i[0],points:Vo(n,v,y)}),B&&a[0]&&(a[0].errorBars=B,a[0].errorBarStyle=ne.style),[...a,...ie]}let ae=ee??(N?Mo(P,v,y,N,b,!0,u):wo(P,v,y,b,u)),oe=vt(ae,I.interpolation);if(!j)return[{type:`line`,points:oe,color:R,lineWidth:I.lineWidth,...I.opacity===t.opacity?{}:{lineOpacity:I.opacity},...I.interpolation===`linear`?{}:{interpolation:I.interpolation,markerPoints:ae},...I.pattern===`solid`?{}:{linePattern:I.pattern},...re?{areaFill:re}:{},subplot:c,traceIndex:h,bounds:g.bounds,markers:L,...V?{linePointLabels:V}:{},...B?{errorBars:B,errorBarStyle:ne.style}:{}},...ie];let se=Bo(oe,v,y).map((e,n)=>({type:`line`,points:e,color:R,lineWidth:I.lineWidth,...I.opacity===t.opacity?{}:{lineOpacity:I.opacity},...I.interpolation===`linear`?{}:{interpolation:I.interpolation,markerPoints:n===0?Vo(ae,v,y):[]},...I.pattern===`solid`?{}:{linePattern:I.pattern},...re?{areaFill:re}:{},subplot:c,traceIndex:h,bounds:g.bounds,markers:L,...n===0&&V?{linePointLabels:V}:{},...n===0&&B?{errorBars:B,errorBarStyle:ne.style}:{}}));return se.length===0&&B&&se.push({type:`line`,points:Vo(ae,v,y),color:R,lineWidth:I.lineWidth,...I.opacity===t.opacity?{}:{lineOpacity:I.opacity},...I.pattern===`solid`?{}:{linePattern:I.pattern},subplot:c,traceIndex:h,bounds:g.bounds,markers:L,errorBars:B,errorBarStyle:ne.style,...V?{linePointLabels:V}:{}}),[...se,...ie]}).filter(e=>e.points.length>0);return st({width:e.width,height:e.height,primitives:m},e)}self.onmessage=e=>{let t=e.data?.options;if(!t){self.postMessage({error:`Missing plot options`});return}try{let e=Us(t);self.postMessage({scene:e})}catch(e){let t=e instanceof Error?e.message:`Unknown worker error`;self.postMessage({error:t})}}})();