semiotic 3.7.4 → 3.7.5

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 (135) hide show
  1. package/CLAUDE.md +10 -7
  2. package/README.md +36 -19
  3. package/ai/schema.json +221 -1
  4. package/ai/system-prompt.md +2 -1
  5. package/dist/components/Annotation.d.ts +4 -0
  6. package/dist/components/DataSummaryContext.d.ts +1 -0
  7. package/dist/components/ai/chartCapabilityTypes.d.ts +16 -0
  8. package/dist/components/ai/dataPitfallsBridge.d.ts +101 -0
  9. package/dist/components/ai/dataQualityBridge.d.ts +201 -0
  10. package/dist/components/ai/describeChart.d.ts +2 -0
  11. package/dist/components/ai/generativeChart.d.ts +145 -0
  12. package/dist/components/charts/custom/NetworkCustomChart.d.ts +14 -1
  13. package/dist/components/charts/ordinal/SwarmPlot.d.ts +7 -0
  14. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +21 -0
  15. package/dist/components/charts/realtime/aggregate.d.ts +51 -0
  16. package/dist/components/charts/realtime/eventTime.d.ts +26 -0
  17. package/dist/components/charts/shared/colorPalettes.d.ts +2 -0
  18. package/dist/components/charts/shared/colorUtils.d.ts +1 -12
  19. package/dist/components/charts/shared/minMax.d.ts +3 -0
  20. package/dist/components/charts/shared/radialGeometry.d.ts +0 -18
  21. package/dist/components/charts/shared/smartTooltip.d.ts +27 -0
  22. package/dist/components/charts/shared/statisticalOverlays.d.ts +35 -0
  23. package/dist/components/charts/shared/tooltipUtils.d.ts +2 -0
  24. package/dist/components/charts/shared/useChartSetup.d.ts +1 -1
  25. package/dist/components/charts/shared/useCustomChartSetup.d.ts +1 -1
  26. package/dist/components/charts/shared/validateChartData.d.ts +1 -1
  27. package/dist/components/charts/xy/Scatterplot.d.ts +9 -0
  28. package/dist/components/data/fromArrow.d.ts +54 -0
  29. package/dist/components/data/fromMermaid.d.ts +47 -0
  30. package/dist/components/data/fromObservablePlot.d.ts +69 -0
  31. package/dist/components/data/portability/index.d.ts +14 -0
  32. package/dist/components/data/portability/spec.d.ts +129 -0
  33. package/dist/components/data/portability/vegaLite.d.ts +62 -0
  34. package/dist/components/realtime/ReorderBuffer.d.ts +54 -0
  35. package/dist/components/realtime/RunningStats.d.ts +66 -0
  36. package/dist/components/realtime/WindowAccumulator.d.ts +105 -0
  37. package/dist/components/realtime/parseWindowDuration.d.ts +12 -0
  38. package/dist/components/recipes/customTooltip.d.ts +31 -0
  39. package/dist/components/recipes/gofish.d.ts +207 -0
  40. package/dist/components/recipes/gofishBoba.d.ts +23 -0
  41. package/dist/components/recipes/gofishIR.d.ts +169 -0
  42. package/dist/components/recipes/gofishIRExamples.d.ts +89 -0
  43. package/dist/components/recipes/gofishInterpreter.d.ts +52 -0
  44. package/dist/components/recipes/gofishLambdas.d.ts +145 -0
  45. package/dist/components/recipes/mermaidDag.d.ts +44 -0
  46. package/dist/components/recipes/packedClusterMatrix.d.ts +166 -0
  47. package/dist/components/recipes/recipeChrome.d.ts +100 -0
  48. package/dist/components/recipes/recipeLegend.d.ts +57 -0
  49. package/dist/components/recipes/recipeUtils.d.ts +105 -0
  50. package/dist/components/semiotic-ai.d.ts +6 -0
  51. package/dist/components/semiotic-data.d.ts +2 -0
  52. package/dist/components/semiotic-experimental.d.ts +20 -0
  53. package/dist/components/semiotic-network.d.ts +3 -1
  54. package/dist/components/semiotic-ordinal.d.ts +2 -0
  55. package/dist/components/semiotic-realtime.d.ts +9 -1
  56. package/dist/components/semiotic-recipes.d.ts +18 -1
  57. package/dist/components/semiotic-themes.d.ts +2 -0
  58. package/dist/components/semiotic-xy.d.ts +2 -0
  59. package/dist/components/semiotic.d.ts +4 -0
  60. package/dist/components/store/ObservationStore.d.ts +21 -2
  61. package/dist/components/store/SelectionStore.d.ts +1 -1
  62. package/dist/components/store/ThemeStore.d.ts +1 -1
  63. package/dist/components/store/TooltipStore.d.ts +1 -1
  64. package/dist/components/store/createStore.d.ts +1 -1
  65. package/dist/components/store/designTokens.d.ts +15 -0
  66. package/dist/components/stream/NetworkHtmlMarksLayer.d.ts +44 -0
  67. package/dist/components/stream/NetworkPipelineStore.d.ts +32 -0
  68. package/dist/components/stream/NetworkSVGOverlay.d.ts +12 -0
  69. package/dist/components/stream/OrdinalPipelineStore.d.ts +18 -0
  70. package/dist/components/stream/PipelineStore.d.ts +27 -0
  71. package/dist/components/stream/SceneGraph.d.ts +5 -1
  72. package/dist/components/stream/customLayout.d.ts +20 -0
  73. package/dist/components/stream/customLayoutDiagnostics.d.ts +11 -0
  74. package/dist/components/stream/customLayoutSelection.d.ts +52 -0
  75. package/dist/components/stream/networkCustomLayout.d.ts +66 -1
  76. package/dist/components/stream/networkTypes.d.ts +29 -1
  77. package/dist/components/stream/ordinalCustomLayout.d.ts +17 -1
  78. package/dist/components/stream/ordinalSceneBuilders/types.d.ts +2 -0
  79. package/dist/components/stream/ordinalTypes.d.ts +19 -3
  80. package/dist/components/stream/renderers/networkSymbolRenderer.d.ts +2 -0
  81. package/dist/components/stream/renderers/symbolCanvasRenderer.d.ts +2 -0
  82. package/dist/components/stream/stalenessBands.d.ts +28 -0
  83. package/dist/components/stream/symbolPath.d.ts +24 -0
  84. package/dist/components/stream/types.d.ts +72 -3
  85. package/dist/components/stream/useStalenessCheck.d.ts +6 -1
  86. package/dist/components/stream/xySceneBuilders/pointScene.d.ts +2 -2
  87. package/dist/components/stream/xySceneBuilders/types.d.ts +5 -0
  88. package/dist/geo.min.js +1 -1
  89. package/dist/geo.module.min.js +1 -1
  90. package/dist/network.min.js +1 -1
  91. package/dist/network.module.min.js +1 -1
  92. package/dist/ordinal.min.js +1 -1
  93. package/dist/ordinal.module.min.js +1 -1
  94. package/dist/realtime.min.js +1 -1
  95. package/dist/realtime.module.min.js +1 -1
  96. package/dist/semiotic-ai-semiotic-ai-u954ylUn.js +2 -0
  97. package/dist/semiotic-ai-statisticalOverlays-CU7jW05Q.js +1 -0
  98. package/dist/semiotic-ai.d.ts +6 -0
  99. package/dist/semiotic-ai.min.js +1 -1
  100. package/dist/semiotic-ai.module.min.js +1 -1
  101. package/dist/semiotic-data.d.ts +2 -0
  102. package/dist/semiotic-data.min.js +1 -1
  103. package/dist/semiotic-data.module.min.js +1 -1
  104. package/dist/semiotic-experimental.d.ts +20 -0
  105. package/dist/semiotic-experimental.min.js +1 -0
  106. package/dist/semiotic-experimental.module.min.js +1 -0
  107. package/dist/semiotic-network.d.ts +3 -1
  108. package/dist/semiotic-ordinal.d.ts +2 -0
  109. package/dist/semiotic-realtime.d.ts +9 -1
  110. package/dist/semiotic-recipes.d.ts +18 -1
  111. package/dist/semiotic-recipes.min.js +1 -1
  112. package/dist/semiotic-recipes.module.min.js +1 -1
  113. package/dist/semiotic-semiotic-BmrYbi99.js +2 -0
  114. package/dist/semiotic-statisticalOverlays-IjZw8Lsu.js +1 -0
  115. package/dist/semiotic-themes.d.ts +2 -0
  116. package/dist/semiotic-themes.min.js +1 -1
  117. package/dist/semiotic-themes.module.min.js +1 -1
  118. package/dist/semiotic-utils.min.js +1 -1
  119. package/dist/semiotic-utils.module.min.js +1 -1
  120. package/dist/semiotic-value.min.js +1 -1
  121. package/dist/semiotic-value.module.min.js +1 -1
  122. package/dist/semiotic-xy.d.ts +2 -0
  123. package/dist/semiotic.d.ts +4 -0
  124. package/dist/semiotic.min.js +1 -1
  125. package/dist/semiotic.module.min.js +1 -1
  126. package/dist/server.min.js +1 -1
  127. package/dist/server.module.min.js +1 -1
  128. package/dist/xy-semiotic-xy-Dufu3D0-.js +2 -0
  129. package/dist/xy-statisticalOverlays-3Ni9bRph.js +1 -0
  130. package/dist/xy.min.js +1 -1
  131. package/dist/xy.module.min.js +1 -1
  132. package/package.json +11 -3
  133. package/dist/semiotic-ai-statisticalOverlays-C2PPlmXv.js +0 -1
  134. package/dist/semiotic-statisticalOverlays-C3DsOgr_.js +0 -1
  135. package/dist/xy-statisticalOverlays-C2PPlmXv.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semiotic",
3
- "version": "3.7.4",
3
+ "version": "3.7.5",
4
4
  "mcpName": "io.github.nteract/semiotic",
5
5
  "description": "React data visualization library with built-in MCP server for AI-assisted chart generation",
6
6
  "main": "dist/semiotic.min.js",
@@ -84,6 +84,12 @@
84
84
  "require": "./dist/semiotic-recipes.min.js",
85
85
  "default": "./dist/semiotic-recipes.module.min.js"
86
86
  },
87
+ "./experimental": {
88
+ "types": "./dist/semiotic-experimental.d.ts",
89
+ "import": "./dist/semiotic-experimental.module.min.js",
90
+ "require": "./dist/semiotic-experimental.min.js",
91
+ "default": "./dist/semiotic-experimental.module.min.js"
92
+ },
87
93
  "./value": {
88
94
  "types": "./dist/semiotic-value.d.ts",
89
95
  "import": "./dist/semiotic-value.module.min.js",
@@ -94,6 +100,7 @@
94
100
  },
95
101
  "files": [
96
102
  "dist/*.min.js",
103
+ "dist/*-semiotic-*.js",
97
104
  "dist/*-statisticalOverlays-*.js",
98
105
  "dist/**/*.d.ts",
99
106
  "ai/schema.json",
@@ -123,8 +130,8 @@
123
130
  "bench:baseline": "node scripts/save-bench-baseline.mjs",
124
131
  "bench:compare": "node scripts/compare-bench-baseline.mjs",
125
132
  "bench:pr-vs-main": "node scripts/bench-pr-vs-main.mjs",
126
- "serve-examples": "npm run dist && parcel serve integration-tests/index.html integration-tests/xy-examples/index.html integration-tests/ordinal-examples/index.html integration-tests/network-examples/index.html integration-tests/hoc-legend-examples/index.html integration-tests/coordinated-examples/index.html integration-tests/accessibility-examples/index.html integration-tests/geo-examples/index.html integration-tests/realtime-examples/index.html integration-tests/streaming-regression-examples/index.html integration-tests/themed-examples/index.html integration-tests/background-graphics-examples/index.html integration-tests/histogram-theme-stroke-examples/index.html integration-tests/primitive-theme-matrix-examples/index.html integration-tests/status-scale-theme-examples/index.html integration-tests/primitive-props-examples/index.html integration-tests/chart-modes-examples/index.html integration-tests/ssr-parity-examples/index.html integration-tests/process-sankey-examples/index.html --dist-dir .parcel-cache/integration-tests",
127
- "serve-examples:ci": "parcel serve integration-tests/index.html integration-tests/xy-examples/index.html integration-tests/ordinal-examples/index.html integration-tests/network-examples/index.html integration-tests/hoc-legend-examples/index.html integration-tests/coordinated-examples/index.html integration-tests/accessibility-examples/index.html integration-tests/geo-examples/index.html integration-tests/realtime-examples/index.html integration-tests/streaming-regression-examples/index.html integration-tests/themed-examples/index.html integration-tests/background-graphics-examples/index.html integration-tests/histogram-theme-stroke-examples/index.html integration-tests/primitive-theme-matrix-examples/index.html integration-tests/status-scale-theme-examples/index.html integration-tests/primitive-props-examples/index.html integration-tests/chart-modes-examples/index.html integration-tests/ssr-parity-examples/index.html integration-tests/process-sankey-examples/index.html --dist-dir .parcel-cache/integration-tests",
133
+ "serve-examples": "npm run dist && parcel serve integration-tests/index.html integration-tests/xy-examples/index.html integration-tests/ordinal-examples/index.html integration-tests/network-examples/index.html integration-tests/hoc-legend-examples/index.html integration-tests/coordinated-examples/index.html integration-tests/accessibility-examples/index.html integration-tests/geo-examples/index.html integration-tests/realtime-examples/index.html integration-tests/streaming-regression-examples/index.html integration-tests/themed-examples/index.html integration-tests/background-graphics-examples/index.html integration-tests/histogram-theme-stroke-examples/index.html integration-tests/primitive-theme-matrix-examples/index.html integration-tests/status-scale-theme-examples/index.html integration-tests/primitive-props-examples/index.html integration-tests/chart-modes-examples/index.html integration-tests/ssr-parity-examples/index.html integration-tests/process-sankey-examples/index.html integration-tests/custom-layout-examples/index.html --dist-dir .parcel-cache/integration-tests",
134
+ "serve-examples:ci": "parcel serve integration-tests/index.html integration-tests/xy-examples/index.html integration-tests/ordinal-examples/index.html integration-tests/network-examples/index.html integration-tests/hoc-legend-examples/index.html integration-tests/coordinated-examples/index.html integration-tests/accessibility-examples/index.html integration-tests/geo-examples/index.html integration-tests/realtime-examples/index.html integration-tests/streaming-regression-examples/index.html integration-tests/themed-examples/index.html integration-tests/background-graphics-examples/index.html integration-tests/histogram-theme-stroke-examples/index.html integration-tests/primitive-theme-matrix-examples/index.html integration-tests/status-scale-theme-examples/index.html integration-tests/primitive-props-examples/index.html integration-tests/chart-modes-examples/index.html integration-tests/ssr-parity-examples/index.html integration-tests/process-sankey-examples/index.html integration-tests/custom-layout-examples/index.html --dist-dir .parcel-cache/integration-tests",
128
135
  "dist": "node --max-old-space-size=8192 scripts/build.mjs",
129
136
  "dist:prod": "node --max-old-space-size=8192 scripts/build.mjs --production",
130
137
  "lint": "eslint src",
@@ -197,6 +204,7 @@
197
204
  "semiotic": "./src/components/semiotic.ts",
198
205
  "semiotic/ai": "./src/components/semiotic-ai.ts",
199
206
  "semiotic/data": "./src/components/semiotic-data.ts",
207
+ "semiotic/experimental": "./src/components/semiotic-experimental.ts",
200
208
  "semiotic/geo": "./src/components/semiotic-geo.ts",
201
209
  "semiotic/network": "./src/components/semiotic-network.ts",
202
210
  "semiotic/ordinal": "./src/components/semiotic-ordinal.ts",
@@ -1 +0,0 @@
1
- function t(t,n=.5){const a=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!a)return t;const s=Math.round(parseInt(a[1],16)*(1-n)),e=Math.round(parseInt(a[2],16)*(1-n)),o=Math.round(parseInt(a[3],16)*(1-n));return`#${s.toString(16).padStart(2,"0")}${e.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function n(t,n=.5){const a=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!a)return t;const s=Math.round(parseInt(a[1],16)+(255-parseInt(a[1],16))*n),e=Math.round(parseInt(a[2],16)+(255-parseInt(a[2],16))*n),o=Math.round(parseInt(a[3],16)+(255-parseInt(a[3],16))*n);return`#${s.toString(16).padStart(2,"0")}${e.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const a="__forecastSegment";function s(t,n){return"function"==typeof n?n(t):!!t[n]}function e(t){var n,a,s;return[{type:"anomaly-band",threshold:null!==(n=t.threshold)&&void 0!==n?n:2,showBand:!1!==t.showBand,fill:t.bandColor||"#6366f1",fillOpacity:null!==(a=t.bandOpacity)&&void 0!==a?a:.1,anomalyColor:t.anomalyColor||"#ef4444",anomalyRadius:null!==(s=t.anomalyRadius)&&void 0!==s?s:6,label:t.label}]}function o(t,n,e,o,r){return(i=o).isTraining||i.isForecast||i.isAnomaly||i.upperBounds||i.lowerBounds?function(t,n,e,o,r){var i,l,c,p;const{isTraining:f,isForecast:u,isAnomaly:h,upperBounds:d,lowerBounds:g,color:y="#6366f1",bandOpacity:b=.15,anomalyColor:O="#ef4444",anomalyRadius:j=6,label:m}=o,v=t.map(t=>{let n="observed";return u&&s(t,u)?n="forecast":f&&s(t,f)&&(n="training"),Object.assign(Object.assign({},t),{[a]:n})}),k=o._groupBy,_=[];if(k){const t=new Map;for(const n of v){const a=null!==(i=n[k])&&void 0!==i?i:"__default";t.has(a)||t.set(a,[]),t.get(a).push(n)}const n=[];for(const[,s]of t)for(let t=0;s.length-1>t;t++)s[t][a]!==s[t+1][a]&&(n.push(Object.assign(Object.assign({},s[t+1]),{[a]:s[t][a]})),n.push(Object.assign(Object.assign({},s[t]),{[a]:s[t+1][a]})));_.push(...v,...n)}else for(let t=0;v.length>t;t++)_.push(v[t]),v.length-1>t&&v[t][a]!==v[t+1][a]&&(_.push(Object.assign(Object.assign({},v[t+1]),{[a]:v[t][a]})),_.push(Object.assign(Object.assign({},v[t]),{[a]:v[t+1][a]})));if(o.trainUnderline){const t=[];for(const n of _)"training"===n[a]&&t.push(Object.assign(Object.assign({},n),{[a]:"training-base"}));_.unshift(...t)}const w=[];if(d&&g){const t="string"==typeof d?d:"__envUpper",n="string"==typeof g?g:"__envLower";if("function"==typeof d||"function"==typeof g)for(const a of _)"function"==typeof d&&(a[t]=d(a)),"function"==typeof g&&(a[n]=g(a));w.push({type:"envelope",upperAccessor:t,lowerAccessor:n,fill:y,fillOpacity:b,label:m})}if(h){const t=o.anomalyStyle,n={type:"highlight",filter:t=>s(t,h)};t?(n.style=t,n.r=j):"function"==typeof O?(n.style=t=>{const n=O(t);return{stroke:n,strokeWidth:1.5,fill:n,fillOpacity:.7}},n.r=j):(n.color=O,n.r=j,n.style={stroke:O,strokeWidth:1.5,fill:O,fillOpacity:.7}),w.push(n)}return r&&w.push({type:"anomaly-band",threshold:null!==(l=r.threshold)&&void 0!==l?l:2,showBand:!1!==r.showBand,fill:r.bandColor||"#6366f1",fillOpacity:null!==(c=r.bandOpacity)&&void 0!==c?c:.1,anomalyColor:r.anomalyColor||"#ef4444",anomalyRadius:null!==(p=r.anomalyRadius)&&void 0!==p?p:6,label:r.label}),{processedData:_,annotations:w}}(t,0,0,o,r):function(t,n,s,e,o){var r,i,l;const{trainEnd:c,steps:p=10,confidence:f=.95,color:u="#6366f1",bandOpacity:h=.15,label:d}=e;if(null==c)return{processedData:t,annotations:[]};const g=[],y=[];for(const s of t)s[n]>c?y.push(Object.assign(Object.assign({},s),{[a]:"observed"})):g.push(Object.assign(Object.assign({},s),{[a]:"training"}));const b=g.map(t=>[t[n],t[s]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,n)=>t[0]-n[0]),O=[],j=[];if(b.length>=3){const e=b.length;let o=0,r=0,i=0,l=0;for(const[t,n]of b)o+=t,r+=n,i+=t*t,l+=t*n;const c=e*i-o*o;if(Math.abs(c)>1e-12){const i=(e*l-o*r)/c,g=(r-i*o)/e,y=t=>g+i*t,m=b.map(([t,n])=>n-y(t)).reduce((t,n)=>t+n*n,0),v=Math.sqrt(m/Math.max(e-2,1)),k=b.reduce((t,n)=>t+n[0],0)/e,_=b.reduce((t,n)=>t+Math.pow(n[0]-k,2),0),w=.99>f?.95>f?.9>f?1:1.645:1.96:2.576,S=t.map(t=>t[n]).filter(t=>null!=t&&isFinite(t)),M=Math.max(...S),B=b.length>1?(b[e-1][0]-b[0][0])/(e-1):1;for(let t=1;p>=t;t++){const o=M+t*B,r=y(o),i=v*Math.sqrt(1+1/e+(_>0?Math.pow(o-k,2)/_:0))*w;j.push({[n]:o,[s]:r,[a]:"forecast",__forecastUpper:r+i,__forecastLower:r-i})}O.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:u,fillOpacity:h,label:d})}}O.push({type:"x-threshold",x:c,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),o&&O.push({type:"anomaly-band",threshold:null!==(r=o.threshold)&&void 0!==r?r:2,showBand:!1!==o.showBand,fill:o.bandColor||"#6366f1",fillOpacity:null!==(i=o.bandOpacity)&&void 0!==i?i:.1,anomalyColor:o.anomalyColor||"#ef4444",anomalyRadius:null!==(l=o.anomalyRadius)&&void 0!==l?l:6,label:o.label});const m=[];if(m.push(...g),g.length>0&&y.length>0&&m.push(Object.assign(Object.assign({},g[g.length-1]),{[a]:"observed"})),m.push(...y),j.length>0){const t=y.length>0?y[y.length-1]:g[g.length-1];t&&m.push(Object.assign(Object.assign({},t),{[a]:"forecast"})),m.push(...j)}return{processedData:m,annotations:O}}(t,n,e,o,r);var i}function r(s,e){var o,r;const i=null!==(o=e.trainDasharray)&&void 0!==o?o:"8,4",l=null!==(r=e.forecastDasharray)&&void 0!==r?r:"4,4",c=e.color||"#6366f1",p=e.trainOpacity,f=e.forecastOpacity,u=e.trainStroke,h=e.trainLinecap,d=e.trainUnderline;return e=>{const o=s(e),r=e[a];if("training"===r){let n=o.stroke;return"darken"===u?n=t(o.stroke||"#666",.5):u&&(n=u),Object.assign(Object.assign(Object.assign(Object.assign({},o),{stroke:n,strokeDasharray:i}),h&&{strokeLinecap:h}),null!=p&&{strokeOpacity:p})}if("training-base"===r){let t=o.stroke||"#666";return"lighten"===d&&(t=n(t,.4)),Object.assign(Object.assign({},o),{stroke:t,strokeDasharray:void 0})}return"forecast"===r?Object.assign(Object.assign(Object.assign({},o),{stroke:c,strokeDasharray:l}),null!=f&&{strokeOpacity:f}):o}}export{a as SEGMENT_FIELD,e as buildAnomalyAnnotations,o as buildForecast,r as createSegmentLineStyle,t as darkenColor,n as lightenColor};
@@ -1 +0,0 @@
1
- import{darkenColor as t,lightenColor as o}from"./semiotic.module.min.js";import"react/jsx-runtime";import"react";import"d3-selection";import"d3-brush";import"d3-scale";import"d3-quadtree";import"d3-shape";import"d3-array";import"d3-hierarchy";import"regression";import"d3-interpolate";import"d3-force";import"d3-chord";const e="__forecastSegment";function n(t,o){return"function"==typeof o?o(t):!!t[o]}function s(t){var o,e,n;return[{type:"anomaly-band",threshold:null!==(o=t.threshold)&&void 0!==o?o:2,showBand:!1!==t.showBand,fill:t.bandColor||"#6366f1",fillOpacity:null!==(e=t.bandOpacity)&&void 0!==e?e:.1,anomalyColor:t.anomalyColor||"#ef4444",anomalyRadius:null!==(n=t.anomalyRadius)&&void 0!==n?n:6,label:t.label}]}function a(t,o,s,a,r){return(i=a).isTraining||i.isForecast||i.isAnomaly||i.upperBounds||i.lowerBounds?function(t,o,s,a,r){var i,l,c,p;const{isTraining:f,isForecast:u,isAnomaly:h,upperBounds:d,lowerBounds:y,color:b="#6366f1",bandOpacity:g=.15,anomalyColor:m="#ef4444",anomalyRadius:O=6,label:j}=a,v=t.map(t=>{let o="observed";return u&&n(t,u)?o="forecast":f&&n(t,f)&&(o="training"),Object.assign(Object.assign({},t),{[e]:o})}),k=a._groupBy,_=[];if(k){const t=new Map;for(const o of v){const e=null!==(i=o[k])&&void 0!==i?i:"__default";t.has(e)||t.set(e,[]),t.get(e).push(o)}const o=[];for(const[,n]of t)for(let t=0;n.length-1>t;t++)n[t][e]!==n[t+1][e]&&(o.push(Object.assign(Object.assign({},n[t+1]),{[e]:n[t][e]})),o.push(Object.assign(Object.assign({},n[t]),{[e]:n[t+1][e]})));_.push(...v,...o)}else for(let t=0;v.length>t;t++)_.push(v[t]),v.length-1>t&&v[t][e]!==v[t+1][e]&&(_.push(Object.assign(Object.assign({},v[t+1]),{[e]:v[t][e]})),_.push(Object.assign(Object.assign({},v[t]),{[e]:v[t+1][e]})));if(a.trainUnderline){const t=[];for(const o of _)"training"===o[e]&&t.push(Object.assign(Object.assign({},o),{[e]:"training-base"}));_.unshift(...t)}const w=[];if(d&&y){const t="string"==typeof d?d:"__envUpper",o="string"==typeof y?y:"__envLower";if("function"==typeof d||"function"==typeof y)for(const e of _)"function"==typeof d&&(e[t]=d(e)),"function"==typeof y&&(e[o]=y(e));w.push({type:"envelope",upperAccessor:t,lowerAccessor:o,fill:b,fillOpacity:g,label:j})}if(h){const t=a.anomalyStyle,o={type:"highlight",filter:t=>n(t,h)};t?(o.style=t,o.r=O):"function"==typeof m?(o.style=t=>{const o=m(t);return{stroke:o,strokeWidth:1.5,fill:o,fillOpacity:.7}},o.r=O):(o.color=m,o.r=O,o.style={stroke:m,strokeWidth:1.5,fill:m,fillOpacity:.7}),w.push(o)}return r&&w.push({type:"anomaly-band",threshold:null!==(l=r.threshold)&&void 0!==l?l:2,showBand:!1!==r.showBand,fill:r.bandColor||"#6366f1",fillOpacity:null!==(c=r.bandOpacity)&&void 0!==c?c:.1,anomalyColor:r.anomalyColor||"#ef4444",anomalyRadius:null!==(p=r.anomalyRadius)&&void 0!==p?p:6,label:r.label}),{processedData:_,annotations:w}}(t,0,0,a,r):function(t,o,n,s,a){var r,i,l;const{trainEnd:c,steps:p=10,confidence:f=.95,color:u="#6366f1",bandOpacity:h=.15,label:d}=s;if(null==c)return{processedData:t,annotations:[]};const y=[],b=[];for(const n of t)n[o]>c?b.push(Object.assign(Object.assign({},n),{[e]:"observed"})):y.push(Object.assign(Object.assign({},n),{[e]:"training"}));const g=y.map(t=>[t[o],t[n]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,o)=>t[0]-o[0]),m=[],O=[];if(g.length>=3){const s=g.length;let a=0,r=0,i=0,l=0;for(const[t,o]of g)a+=t,r+=o,i+=t*t,l+=t*o;const c=s*i-a*a;if(Math.abs(c)>1e-12){const i=(s*l-a*r)/c,y=(r-i*a)/s,b=t=>y+i*t,j=g.map(([t,o])=>o-b(t)).reduce((t,o)=>t+o*o,0),v=Math.sqrt(j/Math.max(s-2,1)),k=g.reduce((t,o)=>t+o[0],0)/s,_=g.reduce((t,o)=>t+Math.pow(o[0]-k,2),0),w=.99>f?.95>f?.9>f?1:1.645:1.96:2.576,B=t.map(t=>t[o]).filter(t=>null!=t&&isFinite(t)),C=Math.max(...B),D=g.length>1?(g[s-1][0]-g[0][0])/(s-1):1;for(let t=1;p>=t;t++){const a=C+t*D,r=b(a),i=v*Math.sqrt(1+1/s+(_>0?Math.pow(a-k,2)/_:0))*w;O.push({[o]:a,[n]:r,[e]:"forecast",__forecastUpper:r+i,__forecastLower:r-i})}m.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:u,fillOpacity:h,label:d})}}m.push({type:"x-threshold",x:c,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),a&&m.push({type:"anomaly-band",threshold:null!==(r=a.threshold)&&void 0!==r?r:2,showBand:!1!==a.showBand,fill:a.bandColor||"#6366f1",fillOpacity:null!==(i=a.bandOpacity)&&void 0!==i?i:.1,anomalyColor:a.anomalyColor||"#ef4444",anomalyRadius:null!==(l=a.anomalyRadius)&&void 0!==l?l:6,label:a.label});const j=[];if(j.push(...y),y.length>0&&b.length>0&&j.push(Object.assign(Object.assign({},y[y.length-1]),{[e]:"observed"})),j.push(...b),O.length>0){const t=b.length>0?b[b.length-1]:y[y.length-1];t&&j.push(Object.assign(Object.assign({},t),{[e]:"forecast"})),j.push(...O)}return{processedData:j,annotations:m}}(t,o,s,a,r);var i}function r(n,s){var a,r;const i=null!==(a=s.trainDasharray)&&void 0!==a?a:"8,4",l=null!==(r=s.forecastDasharray)&&void 0!==r?r:"4,4",c=s.color||"#6366f1",p=s.trainOpacity,f=s.forecastOpacity,u=s.trainStroke,h=s.trainLinecap,d=s.trainUnderline;return s=>{const a=n(s),r=s[e];if("training"===r){let o=a.stroke;return"darken"===u?o=t(a.stroke||"#666",.5):u&&(o=u),Object.assign(Object.assign(Object.assign(Object.assign({},a),{stroke:o,strokeDasharray:i}),h&&{strokeLinecap:h}),null!=p&&{strokeOpacity:p})}if("training-base"===r){let t=a.stroke||"#666";return"lighten"===d&&(t=o(t,.4)),Object.assign(Object.assign({},a),{stroke:t,strokeDasharray:void 0})}return"forecast"===r?Object.assign(Object.assign(Object.assign({},a),{stroke:c,strokeDasharray:l}),null!=f&&{strokeOpacity:f}):a}}export{e as SEGMENT_FIELD,s as buildAnomalyAnnotations,a as buildForecast,r as createSegmentLineStyle,t as darkenColor,o as lightenColor};
@@ -1 +0,0 @@
1
- function t(t,n=.5){const a=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!a)return t;const s=Math.round(parseInt(a[1],16)*(1-n)),e=Math.round(parseInt(a[2],16)*(1-n)),o=Math.round(parseInt(a[3],16)*(1-n));return`#${s.toString(16).padStart(2,"0")}${e.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function n(t,n=.5){const a=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!a)return t;const s=Math.round(parseInt(a[1],16)+(255-parseInt(a[1],16))*n),e=Math.round(parseInt(a[2],16)+(255-parseInt(a[2],16))*n),o=Math.round(parseInt(a[3],16)+(255-parseInt(a[3],16))*n);return`#${s.toString(16).padStart(2,"0")}${e.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const a="__forecastSegment";function s(t,n){return"function"==typeof n?n(t):!!t[n]}function e(t){var n,a,s;return[{type:"anomaly-band",threshold:null!==(n=t.threshold)&&void 0!==n?n:2,showBand:!1!==t.showBand,fill:t.bandColor||"#6366f1",fillOpacity:null!==(a=t.bandOpacity)&&void 0!==a?a:.1,anomalyColor:t.anomalyColor||"#ef4444",anomalyRadius:null!==(s=t.anomalyRadius)&&void 0!==s?s:6,label:t.label}]}function o(t,n,e,o,r){return(i=o).isTraining||i.isForecast||i.isAnomaly||i.upperBounds||i.lowerBounds?function(t,n,e,o,r){var i,l,c,p;const{isTraining:f,isForecast:u,isAnomaly:h,upperBounds:d,lowerBounds:g,color:y="#6366f1",bandOpacity:b=.15,anomalyColor:O="#ef4444",anomalyRadius:j=6,label:m}=o,v=t.map(t=>{let n="observed";return u&&s(t,u)?n="forecast":f&&s(t,f)&&(n="training"),Object.assign(Object.assign({},t),{[a]:n})}),k=o._groupBy,_=[];if(k){const t=new Map;for(const n of v){const a=null!==(i=n[k])&&void 0!==i?i:"__default";t.has(a)||t.set(a,[]),t.get(a).push(n)}const n=[];for(const[,s]of t)for(let t=0;s.length-1>t;t++)s[t][a]!==s[t+1][a]&&(n.push(Object.assign(Object.assign({},s[t+1]),{[a]:s[t][a]})),n.push(Object.assign(Object.assign({},s[t]),{[a]:s[t+1][a]})));_.push(...v,...n)}else for(let t=0;v.length>t;t++)_.push(v[t]),v.length-1>t&&v[t][a]!==v[t+1][a]&&(_.push(Object.assign(Object.assign({},v[t+1]),{[a]:v[t][a]})),_.push(Object.assign(Object.assign({},v[t]),{[a]:v[t+1][a]})));if(o.trainUnderline){const t=[];for(const n of _)"training"===n[a]&&t.push(Object.assign(Object.assign({},n),{[a]:"training-base"}));_.unshift(...t)}const w=[];if(d&&g){const t="string"==typeof d?d:"__envUpper",n="string"==typeof g?g:"__envLower";if("function"==typeof d||"function"==typeof g)for(const a of _)"function"==typeof d&&(a[t]=d(a)),"function"==typeof g&&(a[n]=g(a));w.push({type:"envelope",upperAccessor:t,lowerAccessor:n,fill:y,fillOpacity:b,label:m})}if(h){const t=o.anomalyStyle,n={type:"highlight",filter:t=>s(t,h)};t?(n.style=t,n.r=j):"function"==typeof O?(n.style=t=>{const n=O(t);return{stroke:n,strokeWidth:1.5,fill:n,fillOpacity:.7}},n.r=j):(n.color=O,n.r=j,n.style={stroke:O,strokeWidth:1.5,fill:O,fillOpacity:.7}),w.push(n)}return r&&w.push({type:"anomaly-band",threshold:null!==(l=r.threshold)&&void 0!==l?l:2,showBand:!1!==r.showBand,fill:r.bandColor||"#6366f1",fillOpacity:null!==(c=r.bandOpacity)&&void 0!==c?c:.1,anomalyColor:r.anomalyColor||"#ef4444",anomalyRadius:null!==(p=r.anomalyRadius)&&void 0!==p?p:6,label:r.label}),{processedData:_,annotations:w}}(t,0,0,o,r):function(t,n,s,e,o){var r,i,l;const{trainEnd:c,steps:p=10,confidence:f=.95,color:u="#6366f1",bandOpacity:h=.15,label:d}=e;if(null==c)return{processedData:t,annotations:[]};const g=[],y=[];for(const s of t)s[n]>c?y.push(Object.assign(Object.assign({},s),{[a]:"observed"})):g.push(Object.assign(Object.assign({},s),{[a]:"training"}));const b=g.map(t=>[t[n],t[s]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,n)=>t[0]-n[0]),O=[],j=[];if(b.length>=3){const e=b.length;let o=0,r=0,i=0,l=0;for(const[t,n]of b)o+=t,r+=n,i+=t*t,l+=t*n;const c=e*i-o*o;if(Math.abs(c)>1e-12){const i=(e*l-o*r)/c,g=(r-i*o)/e,y=t=>g+i*t,m=b.map(([t,n])=>n-y(t)).reduce((t,n)=>t+n*n,0),v=Math.sqrt(m/Math.max(e-2,1)),k=b.reduce((t,n)=>t+n[0],0)/e,_=b.reduce((t,n)=>t+Math.pow(n[0]-k,2),0),w=.99>f?.95>f?.9>f?1:1.645:1.96:2.576,S=t.map(t=>t[n]).filter(t=>null!=t&&isFinite(t)),M=Math.max(...S),B=b.length>1?(b[e-1][0]-b[0][0])/(e-1):1;for(let t=1;p>=t;t++){const o=M+t*B,r=y(o),i=v*Math.sqrt(1+1/e+(_>0?Math.pow(o-k,2)/_:0))*w;j.push({[n]:o,[s]:r,[a]:"forecast",__forecastUpper:r+i,__forecastLower:r-i})}O.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:u,fillOpacity:h,label:d})}}O.push({type:"x-threshold",x:c,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),o&&O.push({type:"anomaly-band",threshold:null!==(r=o.threshold)&&void 0!==r?r:2,showBand:!1!==o.showBand,fill:o.bandColor||"#6366f1",fillOpacity:null!==(i=o.bandOpacity)&&void 0!==i?i:.1,anomalyColor:o.anomalyColor||"#ef4444",anomalyRadius:null!==(l=o.anomalyRadius)&&void 0!==l?l:6,label:o.label});const m=[];if(m.push(...g),g.length>0&&y.length>0&&m.push(Object.assign(Object.assign({},g[g.length-1]),{[a]:"observed"})),m.push(...y),j.length>0){const t=y.length>0?y[y.length-1]:g[g.length-1];t&&m.push(Object.assign(Object.assign({},t),{[a]:"forecast"})),m.push(...j)}return{processedData:m,annotations:O}}(t,n,e,o,r);var i}function r(s,e){var o,r;const i=null!==(o=e.trainDasharray)&&void 0!==o?o:"8,4",l=null!==(r=e.forecastDasharray)&&void 0!==r?r:"4,4",c=e.color||"#6366f1",p=e.trainOpacity,f=e.forecastOpacity,u=e.trainStroke,h=e.trainLinecap,d=e.trainUnderline;return e=>{const o=s(e),r=e[a];if("training"===r){let n=o.stroke;return"darken"===u?n=t(o.stroke||"#666",.5):u&&(n=u),Object.assign(Object.assign(Object.assign(Object.assign({},o),{stroke:n,strokeDasharray:i}),h&&{strokeLinecap:h}),null!=p&&{strokeOpacity:p})}if("training-base"===r){let t=o.stroke||"#666";return"lighten"===d&&(t=n(t,.4)),Object.assign(Object.assign({},o),{stroke:t,strokeDasharray:void 0})}return"forecast"===r?Object.assign(Object.assign(Object.assign({},o),{stroke:c,strokeDasharray:l}),null!=f&&{strokeOpacity:f}):o}}export{a as SEGMENT_FIELD,e as buildAnomalyAnnotations,o as buildForecast,r as createSegmentLineStyle,t as darkenColor,n as lightenColor};