semiotic 3.0.0-beta.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/xy.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("react"),t=require("d3-brush"),n=require("d3-selection"),o=require("d3-scale"),s=require("d3-array"),i=require("d3-hierarchy"),r=require("d3-scale-chromatic");function l(e){if(e&&e.__esModule)return e;const t=Object.create(null);if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}return t.default=e,Object.freeze(t)}const a=l(e),c=5e3;class u{constructor(e){this.lastBoundedData=null,this.chunkTimer=0,this.callback=e}clearLastData(){this.lastBoundedData=null,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0)}setBoundedData(e){if(e===this.lastBoundedData)return;if(this.lastBoundedData=e,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),5e3>=e.length)return void this.callback({inserts:e,bounded:!0});this.callback({inserts:e.slice(0,c),bounded:!0,totalSize:e.length});let t=c;const n=()=>{if(t>=e.length)return;if(e!==this.lastBoundedData)return;const o=Math.min(t+c,e.length);this.callback({inserts:e.slice(t,o),bounded:!1}),t=o,this.chunkTimer=e.length>t?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}push(e){this.callback({inserts:[e],bounded:!1})}pushMany(e){0!==e.length&&this.callback({inserts:e,bounded:!1})}clear(){this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.lastBoundedData=null}}class h{constructor(e){if(this._capacity=e,this.head=0,this._size=0,1>e)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){const t=[];for(const n of e){const e=this.push(n);void 0!==e&&t.push(e)}return t}get(e){if(e>=0&&this._size>e)return this.buffer[(this.head-this._size+e+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let e=0;const t=this;return{next:()=>t._size>e?{done:!1,value:t.get(e++)}:{done:!0,value:void 0}}}toArray(){const e=[];for(const t of this)e.push(t);return e}resize(e){if(1>e)throw Error("RingBuffer capacity must be at least 1");const t=this.toArray(),n=[];for(;t.length>e;)n.push(t.shift());this._capacity=e,this.buffer=Array(e),this.head=0,this._size=0;for(const e of t)this.push(e);return n}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}}class d{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isNaN(e)||(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}evict(e){e!==this._min&&e!==this._max||(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(const n of e){const e=t?t(n):n;Number.isNaN(e)||(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}}function f(e,t,n,o,s){const i=new Map;for(const r of e){const e=t(r),l=n(r);if(null==e||null==l||Number.isNaN(e)||Number.isNaN(l))continue;const a=Math.floor(e/o)*o;let c=i.get(a);if(c||(c={start:a,end:a+o,total:0,categories:new Map},i.set(a,c)),c.total+=l,s){const e=s(r);c.categories.set(e,(c.categories.get(e)||0)+l)}}return i}function p(e,t,n,o,s,i){const r=[],l=[];for(const s of e){const e=n(s),i=o(s);null==e||null==i||Number.isNaN(e)||Number.isNaN(i)||(r.push([t.x(e),t.y(i)]),l.push(i))}return{type:"line",path:r,rawValues:l,style:s,datum:e,group:i}}function m(e,t,n,o,s,i,r,l){const a=[],c=[];for(const i of e){const e=n(i),r=o(i);if(null==e||null==r||Number.isNaN(e)||Number.isNaN(r))continue;const u=t.x(e);a.push([u,t.y(r)]);const h=l?l(i):s;c.push([u,t.y(h)])}return{type:"area",topPath:a,bottomPath:c,style:i,datum:e,group:r}}function y(e,t,n,o,s,i,r){const l=n(e),a=o(e);if(null==l||null==a||Number.isNaN(l)||Number.isNaN(a))return null;const c={type:"point",x:t.x(l),y:t.y(a),r:s,style:i,datum:e};return void 0!==r&&(c.pointId=r),c}function g(e,t,n,o,s,i,r){return{type:"rect",x:e,y:t,w:n,h:o,style:s,datum:i,group:r}}function b(e,t,n,o,s,i){return{type:"heatcell",x:e,y:t,w:n,h:o,fill:s,datum:i}}function v(e,t){if("function"==typeof e)return t=>+e(t);const n=e||t;return e=>+e[n]}function x(e,t){return"function"==typeof e?e:e?t=>t[e]+"":void 0}class w{constructor(e){this.xExtent=new d,this.yExtent=new d,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.lastIngestTime=0,this.scales=null,this.scene=[],this.version=0,this.config=e,this.buffer=new h(e.windowSize),this.growingCap=e.windowSize,["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode?(this.getX=v(e.timeAccessor||e.xAccessor,"time"),this.getY=v(e.valueAccessor||e.yAccessor,"value")):(this.getX=v(e.xAccessor,"x"),this.getY=v(e.yAccessor,"y")),this.getGroup=x(e.groupAccessor),this.getCategory=x(e.categoryAccessor),this.getSize=e.sizeAccessor?v(e.sizeAccessor,"size"):void 0,this.getColor=x(e.colorAccessor),this.getBounds=e.boundsAccessor?v(e.boundsAccessor,"bounds"):void 0,this.getY0=e.y0Accessor?v(e.y0Accessor,"y0"):void 0,this.getPointId=x(e.pointIdAccessor),"candlestick"===e.chartType&&(this.getOpen=v(e.openAccessor,"open"),this.getHigh=v(e.highAccessor,"high"),this.getLow=v(e.lowAccessor,"low"),this.getClose=v(e.closeAccessor,"close")),e.pulse&&(this.timestampBuffer=new h(e.windowSize))}ingest(e){const t="undefined"!=typeof performance?performance.now():Date.now();if(this.lastIngestTime=t,e.bounded){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const n=e.totalSize||e.inserts.length;n>this.buffer.capacity&&(this.buffer.resize(n),this.timestampBuffer&&n>this.timestampBuffer.capacity&&this.timestampBuffer.resize(n));for(const n of e.inserts)this.buffer.push(n),this.timestampBuffer&&this.timestampBuffer.push(t),this.xExtent.push(this.getX(n)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.push(this.getHigh(n)),this.yExtent.push(this.getLow(n))):(this.yExtent.push(this.getY(n)),this.getY0&&this.yExtent.push(this.getY0(n)))}else for(const n of e.inserts){"growing"===this.config.windowMode&&this.buffer.full&&(this.growingCap*=2,this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap));const e=this.buffer.push(n);this.timestampBuffer&&this.timestampBuffer.push(t),this.xExtent.push(this.getX(n)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.push(this.getHigh(n)),this.yExtent.push(this.getLow(n))):(this.yExtent.push(this.getY(n)),this.getY0&&this.yExtent.push(this.getY0(n))),null!=e&&(this.xExtent.evict(this.getX(e)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.evict(this.getHigh(e)),this.yExtent.evict(this.getLow(e))):this.yExtent.evict(this.getY(e)))}return!0}computeScene(e){var t,n,s,i,r,l;const{config:a,buffer:c}=this;if(this.xExtent.dirty&&this.xExtent.recalculate(c,this.getX),this.yExtent.dirty)if("candlestick"===a.chartType&&this.getHigh&&this.getLow){this.yExtent.clear();for(const e of c)this.yExtent.push(this.getHigh(e)),this.yExtent.push(this.getLow(e))}else this.yExtent.recalculate(c,this.getY);const u=this.xExtent.extent,h=this.yExtent.extent;let d=a.xExtent?[null!==(t=a.xExtent[0])&&void 0!==t?t:u[0],null!==(n=a.xExtent[1])&&void 0!==n?n:u[1]]:u,p=a.yExtent?[null!==(s=a.yExtent[0])&&void 0!==s?s:h[0],null!==(i=a.yExtent[1])&&void 0!==i?i:h[1]]:h;const m=a.yExtent&&null!=a.yExtent[0]&&null!=a.yExtent[1];if("stackedarea"===a.chartType&&!m&&c.size>0)if(a.normalize)p=[0,1+a.extentPadding];else{const e=c.toArray(),t=this.groupData(e),n=new Map;for(const e of t)for(const t of e.data){const e=this.getX(t),o=this.getY(t);null==e||null==o||Number.isNaN(e)||Number.isNaN(o)||n.set(e,(n.get(e)||0)+o)}let o=0;for(const e of n.values())e>o&&(o=e);p=[0,o+(o>0?o*a.extentPadding:1)]}else if("bar"===a.chartType&&a.binSize&&!m&&c.size>0){const[,e]=function(e,t,n,o,s){const i=f(e,t,n,o,s);if(0===i.size)return[0,0];let r=0;for(const e of i.values())e.total>r&&(r=e.total);return[0,r]}(c,this.getX,this.getY,a.binSize,this.getCategory);p=[0,e+e*a.extentPadding]}else if("waterfall"===a.chartType&&!m&&c.size>0){const[e,t]=function(e,t){let n=0,o=0,s=0;for(const i of e){const e=t(i);null==e||Number.isNaN(e)||(s+=e,n>s&&(n=s),s>o&&(o=s))}return[n,o]}(c,this.getY),n=t-e,o=n>0?n*a.extentPadding:1;p=[Math.min(0,e-Math.abs(o)),Math.max(0,t+Math.abs(o))]}else if(!m&&p[0]!==1/0){if(this.getBounds){const e=c.toArray();for(const t of e){const e=this.getY(t),n=this.getBounds(t);null!=e&&!Number.isNaN(e)&&n&&(e+n>p[1]&&(p[1]=e+n),p[0]>e-n&&(p[0]=e-n))}}const e=p[1]-p[0],t=e>0?e*a.extentPadding:1,n=null===(r=a.yExtent)||void 0===r?void 0:r[0],o=null===(l=a.yExtent)||void 0===l?void 0:l[1];p=[null!=n?p[0]:p[0]-t,null!=o?p[1]:p[1]+t]}if(d[0]!==1/0&&d[1]!==-1/0||(d=[0,1]),p[0]!==1/0&&p[1]!==-1/0||(p=[0,1]),void 0!==a.arrowOfTime)if("x"==("up"===(y=a.arrowOfTime)||"down"===y?"y":"x")){const t="right"===a.arrowOfTime?[0,e.width]:[e.width,0];this.scales={x:o.scaleLinear().domain(d).range(t),y:o.scaleLinear().domain(p).range([e.height,0])}}else{const t="down"===a.arrowOfTime?[0,e.height]:[e.height,0];this.scales={x:o.scaleLinear().domain(p).range([0,e.width]),y:o.scaleLinear().domain(d).range(t)}}else this.scales={x:o.scaleLinear().domain(d).range([0,e.width]),y:o.scaleLinear().domain(p).range([e.height,0])};var y;this.config.transition&&this.scene.length>0&&this.snapshotPositions();const g=c.toArray();this.scene=this.buildSceneNodes(e),this.config.decay&&this.applyDecay(this.scene,g),this.config.pulse&&this.applyPulse(this.scene,g),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++}buildSceneNodes(e){const{config:t,buffer:n,scales:o}=this;if(!o||0===n.size)return[];const s=n.toArray();switch(t.chartType){case"line":return this.buildLineScene(s);case"area":return this.buildAreaScene(s);case"stackedarea":return this.buildStackedAreaScene(s);case"scatter":case"bubble":return this.buildPointScene(s);case"heatmap":return this.buildHeatmapScene(s,e);case"bar":return this.buildBarScene(s);case"swarm":return this.buildSwarmScene(s);case"waterfall":return this.buildWaterfallScene(s,e);case"candlestick":return this.buildCandlestickScene(s,e);default:return[]}}buildLineScene(e){var t;const n=this.groupData(e),o=[],s=null===(t=this.config.annotations)||void 0===t?void 0:t.filter(e=>"threshold"===e.type&&e.color).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(this.getBounds)for(const e of n){const t=this.buildBoundsForGroup(e.data,e.key);t&&o.push(t)}for(const e of n){const t=this.resolveLineStyle(e.key,e.data[0]),n=p(e.data,this.scales,this.getX,this.getY,t,e.key);s&&s.length>0&&(n.colorThresholds=s),o.push(n)}return o}buildAreaScene(e){const t=this.groupData(e),n=[],o=this.scales.y.domain()[0];for(const e of t){const t=this.resolveAreaStyle(e.key,e.data[0]),s=m(e.data,this.scales,this.getX,this.getY,o,t,e.key,this.getY0);this.config.gradientFill&&(s.fillGradient=this.config.gradientFill),n.push(s)}return n}buildStackedAreaScene(e){const t=this.groupData(e);return t.sort((e,t)=>t.key>e.key?-1:e.key>t.key?1:0),function(e,t,n,o,s,i){var r;const l=new Set;for(const t of e)for(const e of t.data){const t=n(e);null==t||Number.isNaN(t)||l.add(t)}const a=Array.from(l).sort((e,t)=>e-t),c=new Map;for(const t of e){const e=new Map;for(const s of t.data){const t=n(s),i=o(s);null==t||null==i||Number.isNaN(t)||Number.isNaN(i)||e.set(t,(e.get(t)||0)+i)}c.set(t.key,e)}let u;if(i){u=new Map;for(const t of a){let n=0;for(const o of e)n+=(null===(r=c.get(o.key))||void 0===r?void 0:r.get(t))||0;u.set(t,n||1)}}const h=[],d=new Map;for(const e of a)d.set(e,0);for(const n of e){const e=c.get(n.key),o=[],r=[];for(const n of a){let s=e.get(n)||0;const l=d.get(n);i&&(s/=u.get(n));const a=t.x(n);r.push([a,t.y(l)]),o.push([a,t.y(l+s)]),d.set(n,l+s)}h.push({type:"area",topPath:o,bottomPath:r,style:s(n.key,n.data[0]),datum:n.data,group:n.key})}return h}(t,this.scales,this.getX,this.getY,(e,t)=>this.resolveAreaStyle(e,t),this.config.normalize)}buildPointScene(e){const t=[],n="bubble"===this.config.chartType?10:5,o=this.config.sizeRange||[3,15];let s=null;if(this.getSize&&!this.config.pointStyle){const t=e.map(e=>this.getSize(e)).filter(e=>null!=e&&!Number.isNaN(e));if(t.length>0){const e=Math.min(...t),n=Math.max(...t);s=t=>e===n?(o[0]+o[1])/2:o[0]+(t-e)/(n-e)*(o[1]-o[0])}}let i=null;if(this.getColor&&!this.config.pointStyle){const t=new Set;for(const n of e){const e=this.getColor(n);e&&t.add(e)}const n=Array.isArray(this.config.colorScheme)?this.config.colorScheme:["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"];i=new Map;let o=0;for(const e of t)i.set(e,n[o%n.length]),o++}for(const o of e){let e=this.config.pointStyle?this.config.pointStyle(o):{fill:"#4e79a7",opacity:.8},r=e.r||n;if(s&&this.getSize){const e=this.getSize(o);null==e||Number.isNaN(e)||(r=s(e))}if(i&&this.getColor){const t=this.getColor(o);t&&i.has(t)&&(e=Object.assign(Object.assign({},e),{fill:i.get(t)}))}const l=this.getPointId?this.getPointId(o)+"":void 0,a=y(o,this.scales,this.getX,this.getY,r,e,l);a&&t.push(a)}return t}buildHeatmapScene(e,t){const n=[];if(this.config.heatmapAggregation)return this.buildStreamingHeatmapScene(e,t);const o=v(this.config.valueAccessor,"value"),s=new Set,i=new Set;for(const t of e)s.add(this.getX(t)),i.add(this.getY(t));const r=Array.from(s).sort((e,t)=>e-t),l=Array.from(i).sort((e,t)=>e-t);if(0===r.length||0===l.length)return n;const a=t.width/r.length,c=t.height/l.length,u=new Map;for(const t of e){const e=`${this.getX(t)}_${this.getY(t)}`;u.set(e,{val:o(t),datum:t})}let h=1/0,d=-1/0;for(const{val:e}of u.values())h>e&&(h=e),e>d&&(d=e);const f=d-h||1;for(let e=0;r.length>e;e++)for(let t=0;l.length>t;t++){const o=u.get(`${r[e]}_${l[t]}`);if(!o)continue;const s=(o.val-h)/f;n.push(b(e*a,(l.length-1-t)*c,a,c,`rgb(${Math.round(220-180*s)},${Math.round(220-100*s)},${Math.round(255-50*s)})`,o.datum))}return n}buildStreamingHeatmapScene(e,t){var n,o,s;const i=[],r=null!==(n=this.config.heatmapXBins)&&void 0!==n?n:20,l=null!==(o=this.config.heatmapYBins)&&void 0!==o?o:20,a=null!==(s=this.config.heatmapAggregation)&&void 0!==s?s:"count",c=v(this.config.valueAccessor,"value");if(!this.scales||0===e.length)return i;const[u,h]=this.scales.x.domain(),[d,f]=this.scales.y.domain(),p=(h-u||1)/r,m=(f-d||1)/l,y=new Map;for(const t of e){const e=this.getX(t),n=this.getY(t),o=Math.min(Math.floor((e-u)/p),r-1),s=Math.min(Math.floor((n-d)/m),l-1);if(0>o||0>s)continue;const i=`${o}_${s}`;let a=y.get(i);a||(a={sum:0,count:0,data:[]},y.set(i,a)),a.count++,a.sum+=c(t),a.data.push(t)}let g=1/0,x=-1/0;const w=new Map;for(const[e,t]of y){let n;switch(a){case"sum":n=t.sum;break;case"mean":n=t.count>0?t.sum/t.count:0;break;default:n=t.count}w.set(e,n),g>n&&(g=n),n>x&&(x=n)}const k=x-g||1,A=t.width/r,E=t.height/l;for(const[e,t]of w){const[n,o]=e.split("_"),s=+n,r=+o,a=(t-g)/k,c=`rgb(${Math.round(220-180*a)},${Math.round(220-100*a)},${Math.round(255-50*a)})`,u=y.get(e);i.push(b(s*A,(l-1-r)*E,A,E,c,{xi:s,yi:r,value:t,count:u.count,sum:u.sum,data:u.data}))}return i}buildBarScene(e){var t;if(!this.config.binSize)return[];const n=f(e,this.getX,this.getY,this.config.binSize,this.getCategory);if(0===n.size)return[];let o=null;if(this.getCategory){const e=new Set;for(const t of n.values())for(const n of t.categories.keys())e.add(n);const t=this.config.barColors?Object.keys(this.config.barColors):[],s=new Set(t),i=Array.from(e).filter(e=>!s.has(e)).sort();o=[...t.filter(t=>e.has(t)),...i]}const s=[],i=this.scales,[r,l]=i.x.domain();for(const e of n.values()){const n=Math.max(e.start,r),a=Math.min(e.end,l);if(n>=a)continue;const c=i.x(n),u=i.x(a),h=Math.min(c,u)+.5,d=Math.max(c,u)-.5-h;if(d>0)if(o&&e.categories.size>0){let n=0;for(const r of o){const o=e.categories.get(r)||0;if(0===o)continue;const l=i.y(n),a=i.y(n+o);s.push(g(h,Math.min(l,a),d,Math.abs(l-a),{fill:(null===(t=this.config.barColors)||void 0===t?void 0:t[r])||"#4e79a7"},{binStart:e.start,binEnd:e.end,total:e.total,category:r,categoryValue:o},r)),n+=o}}else{const t=i.y(0),n=i.y(e.total);s.push(g(h,Math.min(t,n),d,Math.abs(t-n),{fill:"#007bff"},{binStart:e.start,binEnd:e.end,total:e.total}))}}return s}buildSwarmScene(e){var t,n,o,s;const i=[],r=this.config.swarmStyle||{},l=null!==(t=r.radius)&&void 0!==t?t:3,a=null!==(n=r.fill)&&void 0!==n?n:"#007bff",c=null!==(o=r.opacity)&&void 0!==o?o:.7,u=r.stroke,h=r.strokeWidth;for(const t of e){const e=this.getX(t),n=this.getY(t);if(null==n||Number.isNaN(n))continue;const o=this.scales.x(e),r=this.scales.y(n);let d=a;if(this.getCategory){const e=this.getCategory(t);d=(null===(s=this.config.barColors)||void 0===s?void 0:s[e])||d}const f={type:"point",x:o,y:r,r:l,style:{fill:d,opacity:c,stroke:u,strokeWidth:h},datum:t};this.getPointId&&(f.pointId=this.getPointId(t)+""),i.push(f)}return i}buildWaterfallScene(e,t){var n,o,s;const i=[],r=this.scales,l=this.config.waterfallStyle,a=e.filter(e=>{const t=this.getY(e);return null!=t&&!Number.isNaN(t)});if(0===a.length)return i;const c=null!==(n=null==l?void 0:l.positiveColor)&&void 0!==n?n:"#28a745",u=null!==(o=null==l?void 0:l.negativeColor)&&void 0!==o?o:"#dc3545",h=null!==(s=null==l?void 0:l.gap)&&void 0!==s?s:1,d=null==l?void 0:l.stroke,f=null==l?void 0:l.strokeWidth;let p=0;for(let e=0;a.length>e;e++){const n=a[e],o=this.getX(n),s=this.getY(n),m=p+s;let y;y=a.length-1>e?this.getX(a[e+1])-o:e>0?o-this.getX(a[e-1]):0;const b=r.x(o),v=0!==y?r.x(o+y):b+t.width/10,x=Math.min(b,v)+h/2,w=Math.max(b,v)-h/2-x;if(0>=w){p=m;continue}const k=r.y(p),A=r.y(m);i.push(g(x,Math.min(k,A),w,Math.abs(k-A),{fill:0>s?u:c,stroke:d,strokeWidth:f},Object.assign(Object.assign({},n),{baseline:p,cumEnd:m,delta:s,_connectorStroke:null==l?void 0:l.connectorStroke,_connectorWidth:null==l?void 0:l.connectorWidth}))),p=m}return i}buildCandlestickScene(e,t){if(!(this.getOpen&&this.getHigh&&this.getLow&&this.getClose&&this.scales))return[];const n=[],o=this.config.candlestickStyle||{},s=o.upColor||"#28a745",i=o.downColor||"#dc3545",r=o.wickColor||"#333",l=o.wickWidth||1,a=e.map(e=>this.getX(e)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);let c=o.bodyWidth||6;if(!o.bodyWidth&&a.length>1){let e=1/0;for(let t=1;a.length>t;t++){const n=Math.abs(this.scales.x(a[t])-this.scales.x(a[t-1]));n>0&&e>n&&(e=n)}e!==1/0&&(c=Math.max(2,Math.min(.6*e,20)))}for(const t of e){const e=this.getX(t);if(null==e||Number.isNaN(e))continue;const o=this.getOpen(t),a=this.getHigh(t),u=this.getLow(t),h=this.getClose(t);if([o,a,u,h].some(e=>null==e||Number.isNaN(e)))continue;const d=h>=o;n.push({type:"candlestick",x:this.scales.x(e),openY:this.scales.y(o),closeY:this.scales.y(h),highY:this.scales.y(a),lowY:this.scales.y(u),bodyWidth:c,upColor:s,downColor:i,wickColor:r,wickWidth:l,isUp:d,datum:t})}return n}buildBoundsForGroup(e,t){if(!this.getBounds||!this.scales)return null;const n=[],o=[];for(const t of e){const e=this.getX(t),s=this.getY(t);if(null==e||null==s||Number.isNaN(e)||Number.isNaN(s))continue;const i=this.getBounds(t),r=this.scales.x(e);if(i&&0!==i)n.push([r,this.scales.y(s+i)]),o.push([r,this.scales.y(s-i)]);else{const e=this.scales.y(s);n.push([r,e]),o.push([r,e])}}return 2>n.length?null:{type:"area",topPath:n,bottomPath:o,style:this.resolveBoundsStyle(t,e[0]),datum:e,group:t,interactive:!1}}resolveBoundsStyle(e,t){const n=this.config.boundsStyle;return"function"==typeof n?n(t||{},e):n&&"object"==typeof n?n:{fill:this.resolveLineStyle(e,t).stroke||"#4e79a7",fillOpacity:.2,stroke:"none"}}computeDecayOpacity(e,t){var n,o,s;const i=this.config.decay;if(!i||1>=t)return 1;const r=null!==(n=i.minOpacity)&&void 0!==n?n:.1,l=t-1-e;switch(i.type){case"linear":return r+(1-l/(t-1))*(1-r);case"exponential":{const e=null!==(o=i.halfLife)&&void 0!==o?o:t/2;return r+Math.pow(.5,l/e)*(1-r)}case"step":return(null!==(s=i.stepThreshold)&&void 0!==s?s:.5*t)>l?1:r;default:return 1}}applyDecay(e,t){var n,o;if(!this.config.decay)return;const s=t.length;if(1>=s)return;const i=new Map;for(let e=0;t.length>e;e++)i.set(t[e],e);for(const t of e){if("line"===t.type||"area"===t.type)continue;const e=i.get(t.datum);if(null==e)continue;const r=this.computeDecayOpacity(e,s);if("heatcell"===t.type)t.style={opacity:r};else if("candlestick"===t.type)t._decayOpacity=r;else{const e=null!==(o=null===(n=t.style)||void 0===n?void 0:n.opacity)&&void 0!==o?o:1;t.style=Object.assign(Object.assign({},t.style),{opacity:e*r})}}}computePulseIntensity(e,t){var n;const o=this.config.pulse;if(!o)return 0;const s=null!==(n=o.duration)&&void 0!==n?n:500,i=t-e;return s>i?1-i/s:0}applyPulse(e,t){var n,o;if(!this.config.pulse||!this.timestampBuffer)return;const s="undefined"!=typeof performance?performance.now():Date.now(),i=null!==(n=this.config.pulse.color)&&void 0!==n?n:"rgba(255,255,255,0.6)",r=null!==(o=this.config.pulse.glowRadius)&&void 0!==o?o:4,l=new Map;for(let e=0;t.length>e;e++)l.set(t[e],e);for(const t of e){if("line"===t.type||"area"===t.type)continue;const e=l.get(t.datum);if(null==e)continue;const n=this.timestampBuffer.get(e);if(null==n)continue;const o=this.computePulseIntensity(n,s);o>0&&(t._pulseIntensity=o,t._pulseColor=i,t._pulseGlowRadius=r)}}get hasActivePulses(){var e;if(!this.config.pulse||!this.timestampBuffer||0===this.timestampBuffer.size)return!1;const t="undefined"!=typeof performance?performance.now():Date.now(),n=null!==(e=this.config.pulse.duration)&&void 0!==e?e:500,o=this.timestampBuffer.peek();return null!=o&&n>t-o}snapshotPositions(){this.prevPositionMap.clear();for(let e=0;this.scene.length>e;e++){const t=this.scene[e],n=this.getNodeIdentity(t,e);n&&("point"===t.type?this.prevPositionMap.set(n,{x:t.x,y:t.y,r:t.r}):"rect"===t.type||"heatcell"===t.type?this.prevPositionMap.set(n,{x:t.x,y:t.y,w:t.w,h:t.h}):"candlestick"===t.type&&this.prevPositionMap.set(n,{x:t.x,y:t.openY}))}}getNodeIdentity(e,t){var n,o,s,i;switch(e.type){case"point":return`p:${void 0===e.datum?t:this.getX(e.datum)}_${this.getY(e.datum)}`;case"rect":return`r:${e.group||""}:${null!==(i=null!==(o=null===(n=e.datum)||void 0===n?void 0:n.binStart)&&void 0!==o?o:null===(s=e.datum)||void 0===s?void 0:s.category)&&void 0!==i?i:t}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return"c:"+this.getX(e.datum);default:return null}}startTransition(){var e,t,n,o,s,i;if(!this.config.transition||0===this.prevPositionMap.size)return;const r=null!==(e=this.config.transition.duration)&&void 0!==e?e:300;let l=!1;for(let e=0;this.scene.length>e;e++){const r=this.scene[e],a=this.getNodeIdentity(r,e);if(!a)continue;const c=this.prevPositionMap.get(a);if(c)if("point"===r.type){const e={x:r.x,y:r.y,r:r.r};c.x===e.x&&c.y===e.y||(r._targetX=e.x,r._targetY=e.y,r._targetR=e.r,r.x=c.x,r.y=c.y,r.r=null!==(t=c.r)&&void 0!==t?t:r.r,l=!0)}else if("rect"===r.type){const e={x:r.x,y:r.y,w:r.w,h:r.h};c.x===e.x&&c.y===e.y&&c.w===e.w&&c.h===e.h||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.h,r.x=c.x,r.y=c.y,r.w=null!==(n=c.w)&&void 0!==n?n:r.w,r.h=null!==(o=c.h)&&void 0!==o?o:r.h,l=!0)}else if("heatcell"===r.type){const e={x:r.x,y:r.y,w:r.w,h:r.h};c.x===e.x&&c.y===e.y||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.h,r.x=c.x,r.y=c.y,r.w=null!==(s=c.w)&&void 0!==s?s:r.w,r.h=null!==(i=c.h)&&void 0!==i?i:r.h,l=!0)}}l&&(this.activeTransition={startTime:"undefined"!=typeof performance?performance.now():Date.now(),duration:r})}advanceTransition(e){var t;if(!this.activeTransition)return!1;const n=Math.min((e-this.activeTransition.startTime)/this.activeTransition.duration,1),o="linear"===(null===(t=this.config.transition)||void 0===t?void 0:t.easing)?n:1-Math.pow(1-n,3);for(const e of this.scene)if("point"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==e._targetR&&void 0!==n.r&&(e.r=n.r+(e._targetR-n.r)*o)}else if("rect"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==n.w&&(e.w=n.w+(e._targetW-n.w)*o),void 0!==n.h&&(e.h=n.h+(e._targetH-n.h)*o)}else if("heatcell"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==n.w&&(e.w=n.w+(e._targetW-n.w)*o),void 0!==n.h&&(e.h=n.h+(e._targetH-n.h)*o)}if(n>=1){for(const e of this.scene)if("point"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("heatcell"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}return this.activeTransition=null,!1}return!0}groupData(e){if(!this.getGroup)return[{key:"_default",data:e}];const t=new Map;for(const n of e){const e=this.getGroup(n);t.has(e)||t.set(e,[]),t.get(e).push(n)}return Array.from(t.entries()).map(([e,t])=>({key:e,data:t}))}resolveLineStyle(e,t){const n=this.config.lineStyle;return"function"==typeof n?n(t||{},e):n&&"object"==typeof n?{stroke:n.stroke||"#007bff",strokeWidth:n.strokeWidth||2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity}:{stroke:"#007bff",strokeWidth:2}}resolveAreaStyle(e,t){var n;if(this.config.areaStyle)return this.config.areaStyle(t||{});const o=this.config.lineStyle;return"function"==typeof o?o(t||{},e):o&&"object"==typeof o?{fill:o.fill||o.stroke||"#4e79a7",fillOpacity:null!==(n=o.fillOpacity)&&void 0!==n?n:.7,stroke:o.stroke||"#4e79a7",strokeWidth:o.strokeWidth||2}:{fill:"#4e79a7",fillOpacity:.7,stroke:"#4e79a7",strokeWidth:2}}getData(){return this.buffer.toArray()}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.version++}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}updateConfig(e){Object.assign(this.config,e)}}function k(e,t,n){const o=t-e.x,s=n-e.y,i=Math.sqrt(o*o+s*s);return i>e.r+5?null:{node:e,datum:e.datum,x:e.x,y:e.y,distance:i}}function A(e,t,n){if(0===e.path.length)return null;const o=L(e.path,t);if(0>o)return null;const[s,i]=e.path[o],r=t-s,l=n-i,a=Math.sqrt(r*r+l*l);return{node:e,datum:Array.isArray(e.datum)&&e.datum[o]?e.datum[o]:e.datum,x:s,y:i,distance:a}}function E(e,t,n){return e.x>t||t>e.x+e.w||e.y>n||n>e.y+e.h?null:{node:e,datum:e.datum,x:e.x+e.w/2,y:e.y+e.h/2,distance:0}}function M(e,t,n){return e.x>t||t>e.x+e.w||e.y>n||n>e.y+e.h?null:{node:e,datum:e.datum,x:e.x+e.w/2,y:e.y+e.h/2,distance:0}}function S(e,t,n){const o=e.bodyWidth/2,s=Math.min(e.openY,e.closeY);if(!(e.x-o-3>t||t>e.x+o+3||e.highY-3>n||n>e.lowY+3)){const o=s+Math.max(Math.max(e.openY,e.closeY)-s,1)/2,i=t-e.x,r=n-o;return{node:e,datum:e.datum,x:e.x,y:o,distance:Math.sqrt(i*i+r*r)}}return null}function O(e,t,n){if(0===e.topPath.length)return null;const o=L(e.topPath,t);if(0>o)return null;const[s,i]=e.topPath[o],r=t-s,l=n-i;return{node:e,datum:e.datum,x:s,y:i,distance:Math.sqrt(r*r+l*l)}}function L(e,t){if(0===e.length)return-1;let n=0,o=e.length-1;for(;o>n;){const s=n+o>>1;t>e[s][0]?n=s+1:o=s}return n>0&&Math.abs(e[n][0]-t)>=Math.abs(e[n-1][0]-t)?n-1:n}const N={fill:e=>a.createElement("rect",{style:e,width:20,height:20}),line:e=>a.createElement("line",{style:e,x1:0,y1:0,x2:20,y2:20})};function j(e,t,n,o){let s;return s="function"==typeof n?n(e):(0,N[n])(o(e,t)),s}function C(e){const{legendGroups:t,customClickBehavior:n,title:o="Legend",width:s=100,height:i=20,orientation:r="vertical"}=e,l="vertical"===r?(({legendGroups:e,width:t,customClickBehavior:n})=>{let o=30;const s=[];return e.forEach((e,i)=>{o+=5,s.push(a.createElement("line",{key:"legend-top-line legend-symbol-"+i,stroke:"gray",x1:0,y1:o,x2:t,y2:o})),o+=10,e.label&&(o+=20,s.push(a.createElement("text",{key:"legend-text-"+i,y:o,className:"legend-group-label"},e.label)),o+=10),s.push(a.createElement("g",{key:"legend-group-"+i,className:"legend-item",transform:`translate(0,${o})`},((e,t)=>{const{type:n="fill",styleFn:o,items:s}=e,i=[];let r=0;return s.forEach((e,s)=>{const l=j(e,s,n,o);i.push(a.createElement("g",{key:"legend-item-"+s,transform:`translate(0,${r})`,onClick:t?()=>t(e):void 0,style:{cursor:t?"pointer":"default"}},l,a.createElement("text",{y:15,x:30},e.label))),r+=25}),i})(e,n))),o+=25*e.items.length+10}),s})({legendGroups:t,width:s,customClickBehavior:n}):(({legendGroups:e,title:t,height:n,customClickBehavior:o})=>{let s=0;const i=[],r=!1===t?10:40;return e.forEach((t,l)=>{t.label&&(i.push(a.createElement("text",{key:"legend-text-"+l,transform:`translate(${s},${r}) rotate(90)`,textAnchor:"start",className:"legend-group-label"},t.label)),s+=20);const c=((e,t)=>{const{type:n="fill",styleFn:o,items:s}=e,i=[];let r=0;return s.forEach((e,s)=>{const l=j(e,s,n,o);i.push(a.createElement("g",{key:"legend-item-"+s,transform:`translate(${r},0)`,onClick:t?()=>t(e):void 0,style:{cursor:t?"pointer":"default"}},l,a.createElement("text",{y:15,x:25},e.label))),r+=35,r+=8*e.label.length}),{items:i,offset:r}})(t,o);i.push(a.createElement("g",{key:"legend-group-"+l,className:"legend-item",transform:`translate(${s},${r})`},c.items)),s+=c.offset+5,e[l+1]&&i.push(a.createElement("line",{key:"legend-top-line legend-symbol-"+l,stroke:"gray",x1:s,y1:r-10,x2:s,y2:n+r+10})),s+=15}),a.createElement("g",null,!1!==t&&a.createElement("line",{x1:0,x2:s+10,y1:r-10,y2:r-10,stroke:"gray",className:"title-neatline"}),i)})({legendGroups:t,title:o,height:i,customClickBehavior:n});return a.createElement("g",null,void 0!==o&&a.createElement("text",{className:"legend-title",y:20,x:"horizontal"===r?0:s/2,textAnchor:"horizontal"===r?"start":"middle"},o),l)}function _(e){return"string"==typeof e?{type:e}:e}function B({orient:t,config:n,values:o,scale:i,size:r,length:l}){const c=function(e){var t,n,o,s,i;return{type:e.type,bins:null!==(t=e.bins)&&void 0!==t?t:20,fill:null!==(n=e.fill)&&void 0!==n?n:"#4e79a7",fillOpacity:null!==(o=e.fillOpacity)&&void 0!==o?o:.5,stroke:null!==(s=e.stroke)&&void 0!==s?s:"none",strokeWidth:null!==(i=e.strokeWidth)&&void 0!==i?i:1}}(n),u="top"===t||"bottom"===t,h=e.useMemo(()=>{if(0===o.length)return null;const e=i.domain(),n=r-8;if("boxplot"===c.type){const e=function(e){const t=[...e].sort((e,t)=>e-t),n=t.length;if(0===n)return null;const o=t[Math.floor(.25*n)],s=t[Math.floor(.5*n)],i=t[Math.floor(.75*n)],r=i-o;return{q1:o,median:s,q3:i,whiskerLow:Math.max(t[0],o-1.5*r),whiskerHigh:Math.min(t[n-1],i+1.5*r)}}(o);if(!e)return null;const{q1:s,median:r,q3:l,whiskerLow:h,whiskerHigh:d}=e,f=Math.min(.5*n,20),p=(n-f)/2+4;if(u){const e=i(s),n=i(l),o=i(r),u=i(h),m=i(d),y="top"===t?-1:1,g=0;return a.createElement("g",{"data-testid":"marginal-boxplot-"+t},a.createElement("line",{x1:u,y1:g+y*(p+f/2),x2:m,y2:g+y*(p+f/2),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:u,y1:g+y*p,x2:u,y2:g+y*(p+f),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:m,y1:g+y*p,x2:m,y2:g+y*(p+f),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("rect",{x:Math.min(e,n),y:"top"===t?g-p-f:g+p,width:Math.abs(n-e),height:f,fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:o,y1:"top"===t?g-p-f:g+p,x2:o,y2:"top"===t?g-p:g+p+f,stroke:c.fill,strokeWidth:2}))}{const e=i(s),n=i(l),o=i(r),u=i(h),m=i(d),y="left"===t?-1:1,g=0;return a.createElement("g",{"data-testid":"marginal-boxplot-"+t},a.createElement("line",{x1:g+y*(p+f/2),y1:u,x2:g+y*(p+f/2),y2:m,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:g+y*p,y1:u,x2:g+y*(p+f),y2:u,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:g+y*p,y1:m,x2:g+y*(p+f),y2:m,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("rect",{x:"left"===t?g-p-f:g+p,y:Math.min(e,n),width:f,height:Math.abs(n-e),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:"left"===t?g-p-f:g+p,y1:o,x2:"left"===t?g-p:g+p+f,y2:o,stroke:c.fill,strokeWidth:2}))}}const h=s.bin().domain(e).thresholds(c.bins)(o);if(0===h.length)return null;const d=Math.max(...h.map(e=>e.length));if(0===d)return null;if("histogram"===c.type)return a.createElement("g",{"data-testid":"marginal-histogram-"+t},h.map((e,o)=>{if(null==e.x0||null==e.x1)return null;const s=e.length/d*n;if(u){const n=i(e.x0),r=i(e.x1)-i(e.x0);return a.createElement("rect",{key:o,x:n,y:"top"===t?-4-s:4,width:Math.max(r,.5),height:s,fill:c.fill,fillOpacity:c.fillOpacity,stroke:c.stroke,strokeWidth:c.strokeWidth})}{const n=i(e.x0),r=i(e.x1)-i(e.x0);return a.createElement("rect",{key:o,x:"left"===t?-4-s:4,y:Math.min(n,n+r),width:s,height:Math.abs(r),fill:c.fill,fillOpacity:c.fillOpacity,stroke:c.stroke,strokeWidth:c.strokeWidth})}}));if("violin"===c.type){const e=n/2+4,o=[];for(const s of h){if(null==s.x0||null==s.x1)continue;const r=s.length/d*(n/2),l=i((s.x0+s.x1)/2);o.push(u?`${l},${"top"===t?-(e-r):e-r}`:`${"left"===t?-(e-r):e-r},${l}`)}for(let s=h.length-1;s>=0;s--){const r=h[s];if(null==r.x0||null==r.x1)continue;const l=r.length/d*(n/2),a=i((r.x0+r.x1)/2);o.push(u?`${a},${"top"===t?-(e+l):e+l}`:`${"left"===t?-(e+l):e+l},${a}`)}return a.createElement("g",{"data-testid":"marginal-violin-"+t},a.createElement("polygon",{points:o.join(" "),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}))}if("ridgeline"===c.type){const e=[];if(u){const o=0,s=null!=h[0].x0?i(h[0].x0):0;e.push(`M${s},${o}`);for(const o of h){if(null==o.x0||null==o.x1)continue;const s=o.length/d*n,r=i((o.x0+o.x1)/2);e.push(`L${r},${"top"===t?-s-4:s+4}`)}const r=null!=h[h.length-1].x1?i(h[h.length-1].x1):l;e.push(`L${r},${o}`),e.push("Z")}else{const o=0,s=null!=h[0].x0?i(h[0].x0):0;e.push(`M${o},${s}`);for(const o of h){if(null==o.x0||null==o.x1)continue;const s=o.length/d*n,r=i((o.x0+o.x1)/2);e.push(`L${"left"===t?-s-4:s+4},${r}`)}const r=null!=h[h.length-1].x1?i(h[h.length-1].x1):l;e.push(`L${o},${r}`),e.push("Z")}return a.createElement("g",{"data-testid":"marginal-ridgeline-"+t},a.createElement("path",{d:e.join(" "),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}))}return null},[o,i,c,r,l,t,u,4]);return h?a.createElement("g",{className:"marginal-"+t,"data-testid":"marginal-"+t},h):null}function W(e,t=120,n=8){if(!e)return[];const o=Math.max(1,Math.floor(t/n)),s=e.split(/\s+/),i=[];let r="";for(const e of s)r&&r.length+1+e.length>o?(i.push(r),r=e):r=r?`${r} ${e}`:e;return r&&i.push(r),i}function $(e,t,n,o){return"curly"===e?o?`M0,0 C${.6*n},0 ${.4*n},${t/2} ${n},${t/2} C${.4*n},${t/2} ${.6*n},${t} 0,${t}`:`M0,0 C0,${.6*n} ${t/2},${.4*n} ${t/2},${n} C${t/2},${.4*n} ${t},${.6*n} ${t},0`:o?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function H(e){const{x:t=0,y:n=0,dx:o,dy:s,nx:i,ny:r,note:l,connector:c,subject:u,type:h,color:d,className:f,disable:p,events:m={},"data-testid":y}=e,g=new Set(Array.isArray(p)?p:[]);let b=o||0,v=s||0;null!=i&&(b=i-t),null!=r&&(v=r-n);const x="string"==typeof h?h:"label";if("bracket"===x&&u&&0===b&&0===v)if(void 0!==u.width){b=u.width/2;const e=u.depth||30;v=e+(0>e?-5:5)}else if(void 0!==u.height){const e=u.depth||30;b=e+(0>e?-5:5),v=u.height/2}return a.createElement("g",Object.assign({className:("annotation "+(f||"")).trim(),transform:`translate(${t},${n})`,"data-testid":y},m),!g.has("connector")&&function(e,t,n,o,s,i){const r=[];let l=0,c=0;if("callout-circle"!==s&&"label"!==s||!(null==i?void 0:i.radius)){if("callout-rect"===s&&i){const n=i.width||0,o=i.height||0;if(n>0||o>0){const s=n/2,i=o/2,r=e-s,a=t-i;if(0!==r||0!==a){const e=Math.abs(r),t=Math.abs(a),u=n/2,h=o/2,d=e*h>t*u?u/e:h/t;l=s+r*d,c=i+a*d}}}else if("bracket"===s&&i){const e=i.width,t=i.height,n=i.depth||30;void 0!==e?(l=e/2,c=n):void 0!==t&&(l=n,c=t/2)}}else{const n=(i.radius||0)+(i.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const o=Math.atan2(t,e);l=Math.cos(o)*n,c=Math.sin(o)*n}}if(Math.sqrt(Math.pow(e-l,2)+Math.pow(t-c,2))>.5&&(r.push(a.createElement("line",{key:"connector-line",x1:l,y1:c,x2:e,y2:t,stroke:o||"currentColor"})),"arrow"===(null==n?void 0:n.end))){const n=10,s=16/180*Math.PI,i=Math.atan2(t-c,e-l);r.push(a.createElement("path",{key:"connector-arrow",d:`M${l},${c}L${l+n*Math.cos(i+s)},${c+n*Math.sin(i+s)}L${l+n*Math.cos(i-s)},${c+n*Math.sin(i-s)}Z`,fill:o||"currentColor",stroke:"none"}))}return a.createElement("g",{className:"annotation-connector"},r)}(b,v,c,d,x,u),!g.has("subject")&&function(e,t,n,o,s){var i;const r=[];switch(e){case"callout-circle":{const e=((null==t?void 0:t.radius)||0)+((null==t?void 0:t.radiusPadding)||0);e>0&&r.push(a.createElement("circle",{key:"subject-circle",r:e,fill:"none",stroke:n||"currentColor"}));break}case"callout-rect":{const e=(null==t?void 0:t.width)||0,o=(null==t?void 0:t.height)||0;(e>0||o>0)&&r.push(a.createElement("rect",{key:"subject-rect",width:e,height:o,fill:"none",stroke:n||"currentColor"}));break}case"callout-custom":(null==t?void 0:t.custom)&&r.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=o||0,i=s||0;if(void 0!==(null==t?void 0:t.x)){const o=(t.x||0)-e;r.push(a.createElement("line",{key:"threshold-line",x1:o,y1:(t.y1||0)-i,x2:o,y2:(t.y2||0)-i,stroke:n||"currentColor",strokeDasharray:"5,5"}))}else if(void 0!==(null==t?void 0:t.y)){const o=(t.y||0)-i;r.push(a.createElement("line",{key:"threshold-line",x1:(t.x1||0)-e,y1:o,x2:(t.x2||0)-e,y2:o,stroke:n||"currentColor",strokeDasharray:"5,5"}))}else void 0!==(null==t?void 0:t.x1)||void 0!==(null==t?void 0:t.x2)?r.push(a.createElement("line",{key:"threshold-line",x1:(t.x1||0)-e,y1:0,x2:(t.x2||0)-e,y2:0,stroke:n||"currentColor",strokeDasharray:"5,5"})):void 0===(null==t?void 0:t.y1)&&void 0===(null==t?void 0:t.y2)||r.push(a.createElement("line",{key:"threshold-line",x1:0,y1:(t.y1||0)-i,x2:0,y2:(t.y2||0)-i,stroke:n||"currentColor",strokeDasharray:"5,5"}));break}case"bracket":{const e=null!==(i=null==t?void 0:t.width)&&void 0!==i?i:null==t?void 0:t.height;void 0!==e&&r.push(a.createElement("path",{key:"bracket-path",d:$((null==t?void 0:t.type)||"curly",e,(null==t?void 0:t.depth)||30,void 0===(null==t?void 0:t.width)),fill:"none",stroke:n||"currentColor"}));break}}return a.createElement("g",{className:"annotation-subject"},r)}(x,u,d,t,n),!g.has("note")&&function(e,t,n,o){if(!e)return a.createElement("g",{className:"annotation-note"});const{label:s,title:i,orientation:r,align:l,wrap:c=120,noWrap:u}=e;if(!s&&!i)return a.createElement("g",{className:"annotation-note"});let h=r;h||(h=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let d=l;d&&"dynamic"!==d||(d="topBottom"===h?0>t?"right":"left":0>n?"bottom":"top");let f="start";"topBottom"===h?"right"===d?f="end":"middle"===d&&(f="middle"):f=0>t?"end":"start";const p=16,m=i?u?[i]:W(i,c):[],y=s?u?[s]:W(s,c):[],g="leftRight"===h?"end"===f?-4:4:0;let b=0;const v=[];m.length>0&&(v.push(a.createElement("text",{key:"annotation-note-title",className:"annotation-note-title",fill:o||void 0,textAnchor:f,fontWeight:"bold"},m.map((e,t)=>a.createElement("tspan",{key:t,x:g,dy:0===t?0:p},e)))),b=m.length*p),y.length>0&&v.push(a.createElement("text",{key:"annotation-note-label",className:"annotation-note-label",fill:o||void 0,textAnchor:f,y:b},y.map((e,t)=>a.createElement("tspan",{key:t,x:g,dy:0===t?0:p},e))));let x=null;if((i||s)&&(0!==t||0!==n))if("topBottom"===h){const e=Math.min(c,120);let t=0,n=e;"end"===f?(t=-e,n=0):"middle"===f&&(t=-e/2,n=e/2),x=a.createElement("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:o||"currentColor"})}else{const e=(m.length+y.length)*p+(y.length>0?p:0);let t=0,n=e;"bottom"===d?(t=-e,n=0):"middle"===d&&(t=-e/2,n=e/2),x=a.createElement("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:o||"currentColor"})}const w=Math.max(0,m.length+y.length-1)*p;let k=0;return"topBottom"===h?k=0>n?-(w+2):18:"leftRight"===h&&(k="middle"===d?-(w+p+(y.length>0&&m.length>0?2:0))/2+8:"bottom"===d||0>n?-(w+2):18),a.createElement("g",{className:"annotation-note",transform:`translate(${t},${n})`},a.createElement("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0},v),x)}(l,b,v,d))}function z(e){var t,n;const{noteData:o}=e,{screenCoordinates:s}=o,i="string"==typeof o.type?o.type:"label",r=o.eventListeners||o.events||{};if(o.coordinates&&s){const e=o.nx||s[0][0]+(null!==(t=o.dx)&&void 0!==t?t:0),r=o.ny||s[0][1]+(null!==(n=o.dy)&&void 0!==n?n:0),l=s.map((t,n)=>{const s=Object.assign({},o,{note:0===n?o.note:{label:""},x:t[0],y:t[1],nx:e,ny:r});return a.createElement(H,Object.assign({"data-testid":"semiotic-annotation",key:"multi-annotation-"+n},s,{type:i}))});return a.createElement("g",null,l)}const l=o.note||{title:"none",label:o.label};return a.createElement(H,Object.assign({"data-testid":"semiotic-annotation",key:`${l.label}-${l.title}-${o.i}`,events:r},o,{type:i}))}function T(e,t){var n,o,s;const i=null!==(o=null===(n=t.scales)||void 0===n?void 0:n.x)&&void 0!==o?o:null===(s=t.scales)||void 0===s?void 0:s.time;return i?null!=e.x?i(e.x):t.xAccessor&&null!=e[t.xAccessor]?i(e[t.xAccessor]):null:null}function F(e,t){var n,o,s;const i=null!==(o=null===(n=t.scales)||void 0===n?void 0:n.y)&&void 0!==o?o:null===(s=t.scales)||void 0===s?void 0:s.value;return i?null!=e.y?i(e.y):t.yAccessor&&null!=e[t.yAccessor]?i(e[t.yAccessor]):null:null}function P(e,t,n,o=50){return!(-o>e||e>(n.width||0)+o||-o>t||t>(n.height||0)+o)}function I(e,t,n){if("left"===e||"right"===e){const o="left"===e?n:0,s="left"===e?-1:1,i=Math.ceil(t/8);let r="M0,"+o;for(let e=0;i>e;e++){const n=8*(e+1);r+=`L${Math.min(8*e+4,t)},${o+4*s}`,r+=`L${Math.min(n,t)},${o}`}return r}{const o="bottom"===e?0:t,s="bottom"===e?1:-1,i=Math.ceil(n/8);let r=`M${o},0`;for(let e=0;i>e;e++){const t=8*(e+1);r+=`L${o+4*s},${Math.min(8*e+4,n)}`,r+=`L${o},${Math.min(t,n)}`}return r}}function D(e){return Math.round(100*e)/100+""}function R(t){const{width:n,height:o,totalWidth:s,totalHeight:r,margin:l,scales:c,showAxes:u,axes:h,xLabel:d,yLabel:f,xFormat:p,yFormat:m,showGrid:y,title:g,legend:b,foregroundGraphics:v,marginalGraphics:x,xValues:w,yValues:k,annotations:A,svgAnnotationRules:E,annotationFrame:M,xAccessor:S,yAccessor:O,annotationData:L,pointNodes:N,children:j}=t,W=e.useMemo(()=>u&&c?c.x.ticks(5).map(e=>({value:e,pixel:c.x(e),label:(p||D)(e)})):[],[u,c,p]),$=e.useMemo(()=>u&&c?c.y.ticks(5).map(e=>({value:e,pixel:c.y(e),label:(m||D)(e)})):[],[u,c,m]),H=e.useMemo(()=>{if(!A||0===A.length)return null;const e=function(e,t,n){var o,s,r,l,c,u,h,d,f,p,m,y,g,b,v,x,w,k,A,E,M,S,O,L,N,j,C,_,B,W,$,H,I,D,R,G,Y,X,q;switch(e.type){case"label":{let o=null,s=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);if(!t)return null;o=t.x,s=t.y}else o=T(e,n),s=F(e,n);return null==o||null==s?null:P(o,s,n)?a.createElement(z,{key:"ann-"+t,noteData:{x:o,y:s,dx:e.dx||30,dy:e.dy||-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"label",connector:e.connector||{end:"arrow"},color:e.color}}):null}case"callout":{let o=null,s=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);if(!t)return null;o=t.x,s=t.y}else o=T(e,n),s=F(e,n);return null==o||null==s?null:P(o,s,n)?a.createElement(z,{key:"ann-"+t,noteData:{x:o,y:s,dx:e.dx||30,dy:e.dy||-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"callout-circle",subject:{radius:e.radius||12},connector:e.connector||{end:"arrow"},color:e.color}}):null}case"x-threshold":{const o=T(e,n);if(null==o)return null;const s=e.color||"#f97316";return a.createElement("g",{key:"ann-"+t},a.createElement("line",{x1:o,y1:0,x2:o,y2:n.height||0,stroke:s,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:o+4,y:12,fill:s,fontSize:12,fontWeight:"bold"},e.label))}case"y-threshold":{const o=F(e,n);if(null==o)return null;const s=e.color||"#f97316";return a.createElement("g",{key:"ann-"+t},a.createElement("line",{x1:0,y1:o,x2:n.width||0,y2:o,stroke:s,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:o-4,textAnchor:"end",fill:s,fontSize:12,fontWeight:"bold"},e.label))}case"enclose":{const o=(e.coordinates||[]).map(e=>({x:T(Object.assign(Object.assign({},e),{type:"point"}),n),y:F(Object.assign(Object.assign({},e),{type:"point"}),n),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>o.length)return null;const s=i.packEnclose(o),r=e.padding||10;return a.createElement("g",{key:"ann-"+t},a.createElement("circle",{cx:s.x,cy:s.y,r:s.r+r,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"#666",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&a.createElement("text",{x:s.x,y:s.y-s.r-r-4,textAnchor:"middle",fill:e.color||"#666",fontSize:12},e.label))}case"rect-enclose":{const o=(e.coordinates||[]).map(e=>({x:T(Object.assign(Object.assign({},e),{type:"point"}),n),y:F(Object.assign(Object.assign({},e),{type:"point"}),n)})).filter(e=>null!=e.x&&null!=e.y);if(2>o.length)return null;const s=e.padding||10,i=o.map(e=>e.x),r=o.map(e=>e.y),l=Math.min(...i)-s,c=Math.max(...i)+s,u=Math.min(...r)-s,h=Math.max(...r)+s;return a.createElement("g",{key:"ann-"+t},a.createElement("rect",{x:l,y:u,width:c-l,height:h-u,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"#666",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&a.createElement("text",{x:(l+c)/2,y:u-4,textAnchor:"middle",fill:e.color||"#666",fontSize:12},e.label))}case"highlight":{const o=n.data||[],s="function"==typeof e.filter?o.filter(e.filter):e.field&&null!=e.value?o.filter(t=>t[e.field]===e.value):[],i=e.style||{stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return a.createElement("g",{key:"ann-"+t},s.map((t,o)=>{const s=T(t,n),r=F(t,n);return null==s||null==r?null:a.createElement("circle",Object.assign({key:o,cx:s,cy:r,r:e.r||6},i))}))}case"bracket":{const o=T(e,n),s=F(e,n);return a.createElement(z,{key:"ann-"+t,noteData:{x:null!=o?o:0,y:null!=s?s:0,dx:e.dx||0,dy:e.dy||0,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}})}case"trend":{const i=n.data||[];if(2>i.length)return null;const d=n.xAccessor||"x",f=n.yAccessor||"y",p=i.map(e=>[e[d],e[f]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>p.length)return null;const m=null!==(s=null===(o=n.scales)||void 0===o?void 0:o.x)&&void 0!==s?s:null===(r=n.scales)||void 0===r?void 0:r.time,y=null!==(c=null===(l=n.scales)||void 0===l?void 0:l.y)&&void 0!==c?c:null===(u=n.scales)||void 0===u?void 0:u.value;if(!m||!y)return null;const g=e.method||"linear";let b;if("loess"===g)b=function(e,t=.3){const n=e.length;if(2>n)return e.slice();const o=e.slice().sort((e,t)=>e[0]-t[0]),s=o.map(e=>e[0]),i=o.map(e=>e[1]),r=Math.max(2,Math.ceil(t*n)),l=[];for(let e=0;n>e;e++){const t=s[e],o=s.map(e=>Math.abs(e-t)),a=o.slice().sort((e,t)=>e-t)[Math.min(r-1,n-1)]||1,c=[];for(let e=0;n>e;e++){const t=0===a?0:o[e]/a;c[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let u=0,h=0,d=0,f=0,p=0;for(let e=0;n>e;e++){const t=c[e];0!==t&&(u+=t,h+=t*s[e],d+=t*i[e],f+=t*s[e]*s[e],p+=t*s[e]*i[e])}if(0===u){l.push([t,i[e]]);continue}const m=u*f-h*h;if(1e-12>Math.abs(m))l.push([t,d/u]);else{const e=(u*p-h*d)/m;l.push([t,(d-e*h)/u+e*t])}}return l}(p,null!==(h=e.bandwidth)&&void 0!==h?h:.3);else{let t;try{const n=require("regression");t="polynomial"===g?n.polynomial(p,{order:e.order||2}):n.linear(p)}catch(e){return null}b=t.points}const v=b.map(([e,t])=>`${m(e)},${y(t)}`).join(" "),x=e.color||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("polyline",{points:v,fill:"none",stroke:x,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:m(b[b.length-1][0])+4,y:y(b[b.length-1][1])-4,fill:x,fontSize:11},e.label))}case"band":{const o=null!==(f=null===(d=n.scales)||void 0===d?void 0:d.y)&&void 0!==f?f:null===(p=n.scales)||void 0===p?void 0:p.value,s=null!==(m=null==o?void 0:o(e.y0))&&void 0!==m?m:0,i=null!==(y=null==o?void 0:o(e.y1))&&void 0!==y?y:n.height||0;return a.createElement("g",{key:"ann-"+t},a.createElement("rect",{x:0,y:Math.min(s,i),width:n.width||0,height:Math.abs(i-s),fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity||.1}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:Math.min(s,i)-4,textAnchor:"end",fill:e.color||"#6366f1",fontSize:11},e.label))}case"envelope":{const o=n.data||[];if(2>o.length)return null;const s=n.xAccessor||"x",i=null!==(b=null===(g=n.scales)||void 0===g?void 0:g.x)&&void 0!==b?b:null===(v=n.scales)||void 0===v?void 0:v.time,r=null!==(w=null===(x=n.scales)||void 0===x?void 0:x.y)&&void 0!==w?w:null===(k=n.scales)||void 0===k?void 0:k.value;if(!i||!r)return null;const l=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",u=e.filter,h=o.filter(e=>null!=e[l]&&null!=e[c]&&!(u&&!u(e))).sort((e,t)=>e[s]-t[s]);if(2>h.length)return null;const d=h.map(e=>`${i(e[s])},${r(e[l])}`).join(" L"),f=h.slice().reverse().map(e=>`${i(e[s])},${r(e[c])}`).join(" L"),p=e.fill||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("path",{d:`M${d} L${f} Z`,fill:p,fillOpacity:null!==(A=e.fillOpacity)&&void 0!==A?A:.15,stroke:"none"}),e.label&&h.length>0&&a.createElement("text",{x:i(h[h.length-1][s])+4,y:r(h[h.length-1][l])-4,fill:p,fontSize:11},e.label))}case"anomaly-band":{const o=n.data||[];if(2>o.length)return null;const s=n.yAccessor||"y",i=null!==(M=null===(E=n.scales)||void 0===E?void 0:E.x)&&void 0!==M?M:null===(S=n.scales)||void 0===S?void 0:S.time,r=null!==(L=null===(O=n.scales)||void 0===O?void 0:O.y)&&void 0!==L?L:null===(N=n.scales)||void 0===N?void 0:N.value;if(!i||!r)return null;const l=o.map(e=>e[s]).filter(e=>null!=e&&isFinite(e));if(2>l.length)return null;const c=l.reduce((e,t)=>e+t,0)/l.length,u=l.reduce((e,t)=>e+Math.pow(t-c,2),0)/l.length,h=Math.sqrt(u),d=null!==(j=e.threshold)&&void 0!==j?j:2,f=c-d*h,p=!1!==e.showBand,m=e.fill||"#6366f1",y=null!==(C=e.fillOpacity)&&void 0!==C?C:.1,g=e.anomalyColor||"#ef4444",b=null!==(_=e.anomalyRadius)&&void 0!==_?_:6,v=r(c+d*h),x=r(f),w=o.filter(e=>{const t=e[s];return null!=t&&Math.abs(t-c)>d*h});return a.createElement("g",{key:"ann-"+t},p&&a.createElement("rect",{x:0,y:Math.min(v,x),width:n.width||0,height:Math.abs(x-v),fill:m,fillOpacity:y}),w.map((e,t)=>{const o=T(e,n),s=F(e,n);return null==o||null==s?null:a.createElement("circle",{key:t,cx:o,cy:s,r:b,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5})}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:Math.min(v,x)-4,textAnchor:"end",fill:m,fontSize:11},e.label))}case"forecast":{const o=n.data||[];if(3>o.length)return null;const s=n.xAccessor||"x",i=n.yAccessor||"y",r=null!==(W=null===(B=n.scales)||void 0===B?void 0:B.x)&&void 0!==W?W:null===($=n.scales)||void 0===$?void 0:$.time,l=null!==(I=null===(H=n.scales)||void 0===H?void 0:H.y)&&void 0!==I?I:null===(D=n.scales)||void 0===D?void 0:D.value;if(!r||!l)return null;const c=o.map(e=>[e[s],e[i]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>c.length)return null;let u;if("polynomial"===(e.method||"linear"))try{const t=require("regression").polynomial(c,{order:e.order||2}).equation;u=e=>t.reduce((t,n,o)=>t+n*Math.pow(e,o),0)}catch(e){return null}else{const e=c.length;let t=0,n=0,o=0,s=0;for(const[e,i]of c)t+=e,n+=i,o+=e*e,s+=e*i;const i=e*o-t*t;if(1e-12>Math.abs(i))return null;const r=(e*s-t*n)/i,l=(n-r*t)/e;u=e=>l+r*e}const h=c.length,d=c.map(([e,t])=>t-u(e)).reduce((e,t)=>e+t*t,0),f=Math.sqrt(d/Math.max(h-2,1)),p=c.reduce((e,t)=>e+t[0],0)/h,m=c.reduce((e,t)=>e+Math.pow(t[0]-p,2),0),y=null!==(R=e.confidence)&&void 0!==R?R:.95,g=.99>y?.95>y?.9>y?1:1.645:1.96:2.576,b=null!==(G=e.steps)&&void 0!==G?G:5,v=c[h-1][0],x=(v-c[0][0])/Math.max(h-1,1),w=[];for(let e=1;b>=e;e++)w.push(v+e*x);const k=[];for(const e of w){const t=u(e),n=f*Math.sqrt(1+1/h+(m>0?Math.pow(e-p,2)/m:0))*g;k.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const A=`M${k.map(e=>`${r(e.x)},${l(e.yUpper)}`).join(" L")} L${k.slice().reverse().map(e=>`${r(e.x)},${l(e.yLower)}`).join(" L")} Z`,E=k.map(e=>`${r(e.x)},${l(e.yCenter)}`).join(" "),M=`${r(v)},${l(u(v))}`,S=e.strokeColor||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("path",{d:A,fill:e.fill||"#6366f1",fillOpacity:null!==(Y=e.fillOpacity)&&void 0!==Y?Y:.15,stroke:"none"}),a.createElement("polyline",{points:`${M} ${E}`,fill:"none",stroke:S,strokeWidth:null!==(X=e.strokeWidth)&&void 0!==X?X:2,strokeDasharray:null!==(q=e.strokeDasharray)&&void 0!==q?q:"6,3"}),e.label&&k.length>0&&a.createElement("text",{x:r(k[k.length-1].x)+4,y:l(k[k.length-1].yCenter)-4,fill:S,fontSize:11},e.label))}default:return null}},t={scales:c?{x:c.x,y:c.y,time:c.x,value:c.y}:null,timeAxis:"x",xAccessor:S,yAccessor:O,width:n,height:o,data:L,frameType:"xy",pointNodes:N};return A.map((n,o)=>{if(E){const s=E(n,o,t);return null!=s?s:e(n,o,t)}return e(n,o,t)}).filter(Boolean)},[A,E,n,o,M,S,O,L]);return u||g||b||v||x||H&&H.length>0||y||j?a.createElement("svg",{width:s,height:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},a.createElement("g",{transform:`translate(${l.left},${l.top})`},y&&c&&a.createElement("g",{className:"stream-grid"},W.map((e,t)=>a.createElement("line",{key:"xgrid-"+t,x1:e.pixel,y1:0,x2:e.pixel,y2:o,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1})),$.map((e,t)=>a.createElement("line",{key:"ygrid-"+t,x1:0,y1:e.pixel,x2:n,y2:e.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1}))),u&&c&&(()=>{const e=null==h?void 0:h.find(e=>"left"===e.orient),t=null==h?void 0:h.find(e=>"bottom"===e.orient),s=!e||!1!==e.baseline,i=(null==e?void 0:e.jaggedBase)||!1,r=(null==t?void 0:t.jaggedBase)||!1,c="var(--semiotic-border, #ccc)",u="var(--semiotic-text-secondary, #666)",p="var(--semiotic-text, #333)";return a.createElement("g",{className:"stream-axes"},(!t||!1!==t.baseline)&&!r&&a.createElement("line",{x1:0,y1:o,x2:n,y2:o,stroke:c,strokeWidth:1}),r&&a.createElement("path",{d:I("bottom",n,o),fill:"none",stroke:c,strokeWidth:1}),W.map((e,t)=>a.createElement("g",{key:"xtick-"+t,transform:`translate(${e.pixel},${o})`},a.createElement("line",{y2:5,stroke:c,strokeWidth:1}),a.createElement("text",{y:18,textAnchor:"middle",fontSize:10,fill:u,style:{userSelect:"none"}},e.label))),d&&a.createElement("text",{x:n/2,y:o+40,textAnchor:"middle",fontSize:12,fill:p,style:{userSelect:"none"}},d),s&&!i&&a.createElement("line",{x1:0,y1:0,x2:0,y2:o,stroke:c,strokeWidth:1}),i&&a.createElement("path",{d:I("left",n,o),fill:"none",stroke:c,strokeWidth:1}),$.map((e,t)=>a.createElement("g",{key:"ytick-"+t,transform:`translate(0,${e.pixel})`},a.createElement("line",{x2:-5,stroke:c,strokeWidth:1}),a.createElement("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:u,style:{userSelect:"none"}},e.label))),f&&a.createElement("text",{x:15-l.left,y:o/2,textAnchor:"middle",fontSize:12,fill:p,transform:`rotate(-90, ${15-l.left}, ${o/2})`,style:{userSelect:"none"}},f))})(),H,x&&c&&w&&k&&a.createElement(a.Fragment,null,x.top&&a.createElement("g",{transform:"translate(0, 0)"},a.createElement(B,{orient:"top",config:_(x.top),values:w,scale:c.x,size:l.top,length:n})),x.bottom&&a.createElement("g",{transform:`translate(0, ${o})`},a.createElement(B,{orient:"bottom",config:_(x.bottom),values:w,scale:c.x,size:l.bottom,length:n})),x.left&&a.createElement("g",{transform:"translate(0, 0)"},a.createElement(B,{orient:"left",config:_(x.left),values:k,scale:c.y,size:l.left,length:o})),x.right&&a.createElement("g",{transform:`translate(${n}, 0)`},a.createElement(B,{orient:"right",config:_(x.right),values:k,scale:c.y,size:l.right,length:o}))),v,j),g&&a.createElement("text",{x:s/2,y:20,textAnchor:"middle",fontSize:14,fontWeight:"bold",fill:"var(--semiotic-text, #333)",style:{userSelect:"none"}},"string"==typeof g?g:null),b&&a.createElement("g",{transform:`translate(${s-l.right+10}, ${l.top})`},"object"==typeof(R=b)&&null!==R&&!a.isValidElement(R)&&"legendGroups"in R?a.createElement(C,{legendGroups:b.legendGroups,title:"",width:100}):b)):null;var R}function G(e,t,n){let o=n;for(const n of t)"lesser"===n.thresholdType?n.value>e&&(o=n.color):e>n.value&&(o=n.color);return o}function Y(e){if(e.startsWith("#")){const t=4===e.length?e[1]+e[1]+e[2]+e[2]+e[3]+e[3]:e.slice(1,7);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[78,121,167]}const X=(e,t,n,o)=>{var s;const i=t.filter(e=>"area"===e.type);for(const t of i){if(2>t.topPath.length)continue;e.beginPath();const[n,o]=t.topPath[0];e.moveTo(n,o);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1]);for(let n=t.bottomPath.length-1;n>=0;n--)e.lineTo(t.bottomPath[n][0],t.bottomPath[n][1]);e.closePath();const i=t.style.fill||"#4e79a7";if(t.fillGradient){const n=Math.min(...t.topPath.map(e=>e[1])),o=Math.max(...t.bottomPath.map(e=>e[1])),s=e.createLinearGradient(0,n,0,o);s.addColorStop(0,i),s.addColorStop(1,i),e.fillStyle=s;const r=Y(i),l=t.fillGradient.topOpacity,a=t.fillGradient.bottomOpacity,c=e.createLinearGradient(0,n,0,o);c.addColorStop(0,`rgba(${r[0]},${r[1]},${r[2]},${l})`),c.addColorStop(1,`rgba(${r[0]},${r[1]},${r[2]},${a})`),e.fillStyle=c,e.globalAlpha=1}else{const n=null!==(s=t.style.fillOpacity)&&void 0!==s?s:.7;e.globalAlpha=n,e.fillStyle=i}if(e.fill(),t.style.stroke&&"none"!==t.style.stroke){e.globalAlpha=1,e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||2,e.setLineDash([]),e.beginPath(),e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1]);e.stroke()}e.globalAlpha=1}},q=(e,t,n,o)=>{var s,i;const r=t.filter(e=>"point"===e.type);for(const t of r){e.beginPath(),e.arc(t.x,t.y,t.r,0,2*Math.PI);const n=null!==(s=t.style.opacity)&&void 0!==s?s:t.style.fillOpacity;if(null!=n&&(e.globalAlpha=n),e.fillStyle=t.style.fill||"#4e79a7",e.fill(),t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||1,e.stroke()),t._pulseIntensity&&t._pulseIntensity>0){const n=null!==(i=t._pulseGlowRadius)&&void 0!==i?i:4,o=t.r+n*t._pulseIntensity;e.beginPath(),e.arc(t.x,t.y,o,0,2*Math.PI),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=2*t._pulseIntensity,e.globalAlpha=.6*t._pulseIntensity,e.stroke()}e.globalAlpha=1}},V=(e,t,n,o)=>{const s=t.filter(e=>"rect"===e.type);for(const t of s)null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.icon?U(e,t):(e.fillStyle=t.style.fill||"#007bff",e.fillRect(t.x,t.y,t.w,t.h),t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||1,e.strokeRect(t.x,t.y,t.w,t.h))),t._pulseIntensity&&t._pulseIntensity>0&&(e.globalAlpha=.3*t._pulseIntensity,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h)),e.globalAlpha=1};function U(e,t){const n=t.style.icon,o=t.style.iconPadding||2,s=Math.min(t.w,t.w)-o;if(0>=s)return;const i=t.h>t.w;if(e.save(),e.beginPath(),e.rect(t.x,t.y,t.w,t.h),e.clip(),i){const i=s+o,r=t.x+(t.w-s)/2;for(let o=t.y+t.h-s;o>=t.y-s;o-=i)e.drawImage(n,r,o,s,s)}else{const i=s+o,r=t.y+(t.h-s)/2;for(let o=t.x;t.x+t.w>o;o+=i)e.drawImage(n,o,r,s,s)}e.restore()}const Z={line:[X,(e,t,n,o)=>{const s=t.filter(e=>"line"===e.type);for(const i of s){if(2>i.path.length)continue;const r=i.style.stroke||"#007bff",l=i.style.strokeWidth||2,a=i.colorThresholds,c=i.rawValues;if(e.setLineDash(i.style.strokeDasharray?i.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=i.style.opacity&&(e.globalAlpha=i.style.opacity),e.lineWidth=l,a&&0!==a.length&&c&&c.length===i.path.length){let u=null,h=null,d=null,f=null,p=!1;function m(t,n,o){e.beginPath(),e.strokeStyle=t,e.moveTo(n,o),p=!0}function y(){p&&(e.stroke(),p=!1)}for(let g=0;i.path.length>g;g++){const[b,v]=i.path[g],x=c[g],w=G(x,a,r);if(null!==u&&null!==f&&null!==d){if(w===f)e.lineTo(b,v);else{const k=[];for(const A of a){const E=A.value;(d>E||E>x)&&(E>d||x>E)||d===E||x===E||k.push({t:(E-d)/(x-d)})}k.sort((e,t)=>e.t-t.t);for(const M of k){const S=u+(b-u)*M.t,O=h+(v-h)*M.t,L=G(d+(x-d)*Math.min(M.t+1e-4,1),a,r);e.lineTo(S,O),y(),m(L,S,O)}e.lineTo(b,v)}u=b,h=v,d=x,f=w}else m(w,b,v),u=b,h=v,d=x,f=w}y()}else{e.beginPath(),e.strokeStyle=r;const[N,j]=i.path[0];e.moveTo(N,j);for(let C=1;i.path.length>C;C++)e.lineTo(i.path[C][0],i.path[C][1]);e.stroke()}if(i.style.fill&&i.style.fillOpacity&&i.style.fillOpacity>0){e.beginPath(),e.globalAlpha=i.style.fillOpacity,e.fillStyle=i.style.fill;const[_,B]=i.path[0];e.moveTo(_,B);for(let $=1;i.path.length>$;$++)e.lineTo(i.path[$][0],i.path[$][1]);const W=i.path[0][0];e.lineTo(i.path[i.path.length-1][0],o.height),e.lineTo(W,o.height),e.closePath(),e.fill()}e.globalAlpha=1,e.setLineDash([])}}],area:[X],stackedarea:[X],scatter:[q],bubble:[q],heatmap:[(e,t,n,o)=>{const s=t.filter(e=>"heatcell"===e.type);for(const t of s){const n=t.style;null!=(null==n?void 0:n.opacity)&&(e.globalAlpha=n.opacity),e.fillStyle=t.fill,e.fillRect(t.x,t.y,t.w,t.h),e.strokeStyle="#fff",e.lineWidth=1,e.strokeRect(t.x,t.y,t.w,t.h),t._pulseIntensity&&t._pulseIntensity>0&&(e.globalAlpha=.3*t._pulseIntensity,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h)),e.globalAlpha=1}}],bar:[V],swarm:[q],waterfall:[(e,t,n,o)=>{var s,i,r;V(e,t);const l=t.filter(e=>"rect"===e.type);if(2>l.length)return;const a=l[0].datum,c=null==a?void 0:a._connectorStroke;if(c){e.save(),e.strokeStyle=c,e.lineWidth=null!==(s=null==a?void 0:a._connectorWidth)&&void 0!==s?s:1,e.setLineDash([]);for(let t=0;l.length-1>t;t++){const o=l[t],s=l[t+1];if(!(null===(i=o.datum)||void 0===i?void 0:i.cumEnd)||!(null===(r=s.datum)||void 0===r?void 0:r.baseline))continue;const a=n.y(o.datum.cumEnd),c=o.x+o.w,u=s.x;e.beginPath(),e.moveTo(c,a),e.lineTo(u,a),e.stroke()}e.restore()}}],candlestick:[(e,t,n,o)=>{for(const n of t){if("candlestick"!==n.type)continue;const t=n;e.beginPath(),e.moveTo(t.x,t.highY),e.lineTo(t.x,t.lowY),e.strokeStyle=t.wickColor,e.lineWidth=t.wickWidth,e.stroke();const o=Math.min(t.openY,t.closeY),s=Math.abs(t.openY-t.closeY),i=t.isUp?t.upColor:t.downColor;e.fillStyle=i,e.fillRect(t.x-t.bodyWidth/2,o,t.bodyWidth,Math.max(s,1)),e.strokeStyle=i,e.lineWidth=1,e.strokeRect(t.x-t.bodyWidth/2,o,t.bodyWidth,Math.max(s,1))}}]},J={top:20,right:20,bottom:30,left:40},K={axisStroke:"#ccc",tickText:"#666",crosshair:"rgba(0, 0, 0, 0.25)",hoverFill:"rgba(255, 255, 255, 0.3)",hoverStroke:"rgba(0, 0, 0, 0.4)",pointRing:"white"},Q={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"6px 10px",borderRadius:4,fontSize:12,lineHeight:1.5,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",whiteSpace:"nowrap"};function ee({hover:e}){const t=e=>Number.isInteger(e)?e+"":e.toFixed(2);return a.createElement("div",{className:"semiotic-tooltip",style:Q},a.createElement("div",{style:{fontWeight:600,marginBottom:2}},t(e.value)),a.createElement("div",{style:{opacity:.7,fontSize:11}},t(e.time)))}function te({width:o,height:s,totalWidth:i,totalHeight:r,margin:l,dimension:c,scales:u,onBrush:h}){const d=e.useRef(null),f=e.useRef(null);return e.useEffect(()=>{if(!d.current)return;const e=n.select(d.current).select(".brush-g"),i="x"===c?t.brushX():"y"===c?t.brushY():t.brush();return i.extent([[0,0],[o,s]]),i.on("brush end",e=>{if(!u)return;if(!e.selection)return void h(null);let t,n;if("x"===c){const[o,i]=e.selection;t=[u.x.invert(o),u.x.invert(i)],n=[u.y.invert(s),u.y.invert(0)]}else if("y"===c){const[s,i]=e.selection;t=[u.x.invert(0),u.x.invert(o)],n=[u.y.invert(i),u.y.invert(s)]}else{const[[o,s],[i,r]]=e.selection;t=[u.x.invert(o),u.x.invert(i)],n=[u.y.invert(r),u.y.invert(s)]}h({x:t,y:n})}),e.call(i),f.current=i,e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.15).attr("stroke","steelblue").attr("stroke-width",1),()=>{i.on("brush end",null),f.current=null}},[o,s,c,u,h]),a.createElement("svg",{ref:d,width:i,height:r,style:{position:"absolute",top:0,left:0,pointerEvents:"all"}},a.createElement("g",{className:"brush-g",transform:`translate(${l.left},${l.top})`}))}const ne=e.forwardRef(function(t,n){var o,s,i;const{chartType:r,runtimeMode:l,data:c,xAccessor:h,yAccessor:d,colorAccessor:f,sizeAccessor:p,groupAccessor:m,lineDataAccessor:y,normalize:g,binSize:b,valueAccessor:v,arrowOfTime:x="right",windowMode:L="sliding",windowSize:N=200,timeAccessor:j,xExtent:C,yExtent:_,extentPadding:B=.1,sizeRange:W,size:$=[500,300],responsiveWidth:H,responsiveHeight:z,margin:T,className:F,background:P,lineStyle:I,pointStyle:D,areaStyle:G,waterfallStyle:Y,swarmStyle:X,barColors:q,colorScheme:V,boundsAccessor:U,boundsStyle:Q,y0Accessor:ne,gradientFill:oe,openAccessor:se,highAccessor:ie,lowAccessor:re,closeAccessor:le,candlestickStyle:ae,showAxes:ce=!0,axes:ue,xLabel:he,yLabel:de,xFormat:fe,yFormat:pe,tickFormatTime:me,tickFormatValue:ye,hoverAnnotation:ge,tooltipContent:be,customHoverBehavior:ve,enableHover:xe,annotations:we,svgAnnotationRules:ke,showGrid:Ae,legend:Ee,backgroundGraphics:Me,foregroundGraphics:Se,title:Oe,categoryAccessor:Le,brush:Ne,onBrush:je,decay:Ce,pulse:_e,transition:Be,staleness:We,heatmapAggregation:$e,heatmapXBins:He,heatmapYBins:ze,marginalGraphics:Te,pointIdAccessor:Fe}=t,[Pe,Ie]=function(t,n,o){const s=e.useRef(null),[i,r]=e.useState(null);return e.useEffect(()=>{if(!n&&!o)return;const e=s.current;if(!e)return;const t=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;r(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return t.observe(e),()=>t.disconnect()},[n,o]),[s,[n&&i?i.w:t[0],o&&i?i.h:t[1]]]}($,H,z),De=Object.assign(Object.assign({},J),T);if(Te){const e=60;Te.top&&e>De.top&&(De.top=e),Te.bottom&&e>De.bottom&&(De.bottom=e),Te.left&&e>De.left&&(De.left=e),Te.right&&e>De.right&&(De.right=e)}const Re=Ie[0]-De.left-De.right,Ge=Ie[1]-De.top-De.bottom,Ye=null!=ge?ge:xe,Xe=e.useRef(null),qe=e.useRef(0),Ve=e.useRef(!1),[Ue,Ze]=e.useState(0),[Je,Ke]=e.useState(null),Qe=e.useRef(null),et=e.useRef(null),[tt,nt]=e.useState(null),[ot,st]=e.useState(!1),[it,rt]=e.useState([]),[lt,at]=e.useState([]),ct=e.useRef(()=>{}),ut="streaming"===l||["bar","swarm","waterfall"].includes(r),ht=e.useMemo(()=>({chartType:r,runtimeMode:ut?"streaming":"bounded",windowSize:N,windowMode:L,arrowOfTime:ut?x:"right",extentPadding:B,xAccessor:ut?void 0:h,yAccessor:ut?void 0:d,timeAccessor:ut?j:void 0,valueAccessor:v,colorAccessor:f,sizeAccessor:p,groupAccessor:m,categoryAccessor:Le,lineDataAccessor:y,xExtent:C,yExtent:_,sizeRange:W,binSize:b,normalize:g,boundsAccessor:U,boundsStyle:Q,y0Accessor:ne,gradientFill:"boolean"==typeof oe?oe?{topOpacity:.8,bottomOpacity:.05}:void 0:oe,openAccessor:se,highAccessor:ie,lowAccessor:re,closeAccessor:le,candlestickStyle:ae,lineStyle:I,pointStyle:D,areaStyle:G,swarmStyle:X,waterfallStyle:Y,colorScheme:V,barColors:q,annotations:we,decay:Ce,pulse:_e,transition:Be,staleness:We,heatmapAggregation:$e,heatmapXBins:He,heatmapYBins:ze,pointIdAccessor:Fe}),[r,N,L,x,B,h,d,j,v,f,p,m,Le,y,C,_,W,b,g,U,Q,ne,oe,se,ie,re,le,ae,I,D,G,X,Y,V,q,we,Ce,_e,Be,We,$e,He,ze,ut,Fe]),dt=e.useRef(null);dt.current||(dt.current=new w(ht));const ft=e.useCallback(()=>{qe.current||(qe.current=requestAnimationFrame(()=>ct.current()))},[]);e.useEffect(()=>{var e;null===(e=dt.current)||void 0===e||e.updateConfig(ht),Ve.current=!0,ft()},[ht,ft]);const pt=e.useRef(null);pt.current||(pt.current=new u(e=>{const t=dt.current;t&&t.ingest(e)&&(Ve.current=!0,ft())}));const mt=e.useCallback(e=>{var t;null===(t=pt.current)||void 0===t||t.push(e)},[]),yt=e.useCallback(e=>{var t;null===(t=pt.current)||void 0===t||t.pushMany(e)},[]),gt=e.useCallback(()=>{var e,t;null===(e=pt.current)||void 0===e||e.clear(),null===(t=dt.current)||void 0===t||t.clear(),Ve.current=!0,ft()},[ft]);e.useImperativeHandle(n,()=>({push:mt,pushMany:yt,clear:gt,getData:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.getData())&&void 0!==t?t:[]},getScales:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.scales)&&void 0!==t?t:null},getExtents:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.getExtents())&&void 0!==t?t:null}}),[mt,yt,gt]),e.useEffect(()=>{var e;if(c)return null===(e=pt.current)||void 0===e||e.setBoundedData(c),()=>{var e;null===(e=pt.current)||void 0===e||e.clearLastData()}},[c]);const bt=e.useRef(()=>{}),vt=e.useRef(()=>{});bt.current=e=>{if(!Ye)return;const t=Xe.current;if(!t)return;const n=t.getBoundingClientRect(),o=e.clientX-n.left-De.left,s=e.clientY-n.top-De.top;if(0>o||o>Re||0>s||s>Ge)return void(Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&(ve(null),Ve.current=!0),ft()));const i=dt.current;if(!i||0===i.scene.length)return;const r=function(e,t,n,o=30){let s=null;for(const i of e){let e=null;switch(i.type){case"point":e=k(i,t,n);break;case"line":e=A(i,t,n);break;case"rect":e=E(i,t,n);break;case"heatcell":e=M(i,t,n);break;case"area":if(!1===i.interactive)break;e=O(i,t,n);break;case"candlestick":e=S(i,t,n)}e&&o>e.distance&&(s&&e.distance>=s.distance||(s=e))}return s}(i.scene,o,s);if(!r)return void(Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&ve(null),ft()));const l={data:r.datum,time:r.x,value:r.y,x:r.x,y:r.y};Qe.current=l,et.current=r.node,nt(l),ve&&(ve(l),Ve.current=!0),ft()},vt.current=()=>{Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&(ve(null),Ve.current=!0),ft())},e.useCallback(e=>bt.current(e),[]);const xt=e.useCallback(()=>vt.current(),[]),wt=e.useRef(-1),kt=e.useCallback(e=>{const t=dt.current;if(!t||0===t.scene.length)return;const n=function(e){const t=[];for(const n of e)switch(n.type){case"point":t.push({x:n.x,y:n.y,datum:n.datum});break;case"line":{const e=n,o=Array.isArray(e.datum)?e.datum:[];for(let n=0;e.path.length>n&&o.length>n;n++)t.push({x:e.path[n][0],y:e.path[n][1],datum:o[n]});break}case"area":{const e=n,o=Array.isArray(e.datum)?e.datum:[];for(let n=0;e.topPath.length>n&&o.length>n;n++)t.push({x:e.topPath[n][0],y:e.topPath[n][1],datum:o[n]});break}case"rect":case"heatcell":t.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum})}return t.sort((e,t)=>e.x-t.x||e.y-t.y),t}(t.scene);if(0===n.length)return;const o=0>wt.current?-1:wt.current,s=function(e,t,n){switch(e){case"ArrowRight":case"ArrowDown":return n-1>t?t+1:t;case"ArrowLeft":case"ArrowUp":return t>0?t-1:t;case"Home":return 0;case"End":return n-1;case"Escape":return-1;default:return null}}(e.key,0>o?-1:o,n.length);if(null===s)return;if(e.preventDefault(),0>s)return wt.current=-1,Qe.current=null,et.current=null,nt(null),ve&&ve(null),void ft();const i=0>o?0:s;wt.current=i;const r={data:(l=n[i]).datum,x:l.x,y:l.y,time:l.x,value:l.y};var l;Qe.current=r,nt(r),ve&&ve(r),ft()},[ve,ft]),At=e.useCallback(e=>{wt.current=-1,bt.current(e)},[]);ct.current=()=>{var e,t;qe.current=0;const n=Xe.current;if(!n)return;const o=n.getContext("2d");if(!o)return;const s=dt.current;if(!s)return;const i="undefined"!=typeof performance?performance.now():Date.now(),l=s.advanceTransition(i);l||s.computeScene({width:Re,height:Ge});const a="undefined"!=typeof window&&window.devicePixelRatio||1;n.width=Ie[0]*a,n.height=Ie[1]*a,n.style.width=Ie[0]+"px",n.style.height=Ie[1]+"px",o.scale(a,a),o.translate(De.left,De.top),o.clearRect(-De.left,-De.top,Ie[0],Ie[1]);const c=function(e){if(!e)return K;const t=getComputedStyle(e),n=t.getPropertyValue("--semiotic-border").trim(),o=t.getPropertyValue("--semiotic-text-secondary").trim(),s=t.getPropertyValue("--semiotic-bg").trim(),i=o||t.getPropertyValue("--text-secondary").trim(),r=t.getPropertyValue("--text-primary").trim(),l=n||t.getPropertyValue("--surface-3").trim(),a=s||t.getPropertyValue("--surface-0").trim();return i||r||n?{axisStroke:l||K.axisStroke,tickText:i||K.tickText,crosshair:i?i+"66":K.crosshair,hoverFill:a?a+"4D":K.hoverFill,hoverStroke:i?i+"99":K.hoverStroke,pointRing:a||K.pointRing}:K}(n),u=null!==(e=null==We?void 0:We.threshold)&&void 0!==e?e:5e3,f=We&&s.lastIngestTime>0&&i-s.lastIngestTime>u;f&&(o.globalAlpha=null!==(t=null==We?void 0:We.dimOpacity)&&void 0!==t?t:.5);const p=n?getComputedStyle(n).getPropertyValue("--semiotic-bg").trim():"",m=P||(p&&"transparent"!==p?p:null);m&&(o.fillStyle=m,o.fillRect(-De.left,-De.top,Ie[0],Ie[1])),o.save(),"function"==typeof o.rect&&(o.beginPath(),o.rect(0,0,Re,Ge),o.clip());const y=Z[r];if(y&&s.scales)for(const e of y)e(o,s.scene,s.scales,{width:Re,height:Ge});if(o.restore(),f&&(o.globalAlpha=1),Ye&&Qe.current&&s.scales&&function(e,t,n,o,s,i,r){if(!1===s.crosshair)return;e.save();const l="object"==typeof s.crosshair?s.crosshair:{};e.strokeStyle=l.stroke||r.crosshair,e.lineWidth=l.strokeWidth||1,e.setLineDash(l.strokeDasharray?l.strokeDasharray.split(/[\s,]+/).map(Number):[4,4]),e.beginPath(),e.moveTo(t.x,0),e.lineTo(t.x,o),e.stroke(),e.beginPath(),e.moveTo(0,t.y),e.lineTo(n,t.y),e.stroke(),e.restore(),e.beginPath(),e.arc(t.x,t.y,4,0,2*Math.PI),e.fillStyle="#007bff",e.fill(),e.strokeStyle=r.pointRing,e.lineWidth=2,e.stroke()}(o,Qe.current,Re,Ge,"object"==typeof Ye?Ye:{},0,c),et.current&&Array.isArray(ge)){const e=ge.find(e=>e&&"object"==typeof e&&"highlight"===e.type);e&&function(e,t,n,o){var s;if(!n)return;const i=n.group;if(void 0!==i)for(const n of t){if("line"!==n.type)continue;if(n.group!==i)continue;if(2>n.path.length)continue;const t="function"==typeof o.style?o.style(n.datum):o.style||{};e.save(),e.beginPath(),e.moveTo(n.path[0][0],n.path[0][1]);for(let t=1;n.path.length>t;t++)e.lineTo(n.path[t][0],n.path[t][1]);e.strokeStyle=t.stroke||n.style.stroke||"#007bff",e.lineWidth=t.strokeWidth||(n.style.strokeWidth||2)+2,e.globalAlpha=null!==(s=t.opacity)&&void 0!==s?s:1,e.stroke(),e.restore()}}(o,s.scene,et.current,e)}const g=Ve.current;if(Ve.current=!1,g&&s.scales&&(Ke(s.scales),Te)){const e=s.getData(),t="function"==typeof h?h:e=>e[h||"x"],n="function"==typeof d?d:e=>e[d||"y"];rt(e.map(e=>t(e)).filter(e=>"number"==typeof e&&isFinite(e))),at(e.map(e=>n(e)).filter(e=>"number"==typeof e&&isFinite(e)))}g&&we&&we.length>0&&Ze(e=>e+1),(null==We?void 0:We.showBadge)&&st(!!f),(l||s.hasActivePulses)&&(qe.current=requestAnimationFrame(()=>ct.current()))},e.useEffect(()=>(ft(),()=>{qe.current&&(cancelAnimationFrame(qe.current),qe.current=0)}),[ft]),e.useEffect(()=>{Ve.current=!0,ft()},[r,Re,Ge,ce,P,I,ft]),e.useEffect(()=>{if(!We)return;const e=setInterval(()=>{var e;const t=dt.current;if(!t||0===t.lastIngestTime)return;const n="undefined"!=typeof performance?performance.now():Date.now(),o=null!==(e=We.threshold)&&void 0!==e?e:5e3,s=n-t.lastIngestTime>o;s!==ot&&(st(s),Ve.current=!0,ft())},1e3);return()=>clearInterval(e)},[We,ot,ft]);const Et=Ye&&tt?be?be(tt):a.createElement(ee,{hover:tt}):null,Mt=Et?a.createElement("div",{className:"stream-frame-tooltip",style:{position:"absolute",left:De.left+tt.x,top:De.top+tt.y,transform:`translate(${tt.x>.7*Re?"calc(-100% - 12px)":"12px"}, ${.3*Ge>tt.y?"4px":"calc(-100% - 4px)"})`,pointerEvents:"none",zIndex:1}},Et):null,St=wt.current>=0&&tt?a.createElement("svg",{style:{position:"absolute",left:0,top:0,width:Ie[0],height:Ie[1],pointerEvents:"none",zIndex:2}},a.createElement("circle",{cx:tt.x+De.left,cy:tt.y+De.top,r:8,fill:"none",stroke:"var(--accent, #6366f1)",strokeWidth:2,strokeDasharray:"4,2"})):null;return a.createElement("div",{ref:Pe,className:"stream-xy-frame"+(F?" "+F:""),role:"img","aria-label":"string"==typeof Oe?Oe:"XY chart",tabIndex:0,style:{position:"relative",width:H?"100%":Ie[0],height:z?"100%":Ie[1]},onMouseMove:Ye?At:void 0,onMouseLeave:Ye?xt:void 0,onKeyDown:kt},Me&&a.createElement("svg",{style:{position:"absolute",left:0,top:0,width:Ie[0],height:Ie[1],pointerEvents:"none"}},Me),a.createElement("canvas",{ref:Xe,style:{position:"absolute",left:0,top:0}}),a.createElement(R,{width:Re,height:Ge,totalWidth:Ie[0],totalHeight:Ie[1],margin:De,scales:Je,showAxes:ce,axes:ue,xLabel:he,yLabel:de,xFormat:fe||me,yFormat:pe||ye,showGrid:Ae,title:Oe,legend:Ee,foregroundGraphics:Se,marginalGraphics:Te,xValues:it,yValues:lt,annotations:we,svgAnnotationRules:ke,annotationFrame:Ue,xAccessor:"string"==typeof h?h:"string"==typeof j?j:void 0,yAccessor:"string"==typeof d?d:"string"==typeof v?v:void 0,annotationData:null===(o=dt.current)||void 0===o?void 0:o.getData(),pointNodes:null===(s=dt.current)||void 0===s?void 0:s.scene.filter(e=>"point"===e.type)}),(Ne||je)&&a.createElement(te,{width:Re,height:Ge,totalWidth:Ie[0],totalHeight:Ie[1],margin:De,dimension:null!==(i=null==Ne?void 0:Ne.dimension)&&void 0!==i?i:"xy",scales:Je,onBrush:null!=je?je:()=>{}}),(null==We?void 0:We.showBadge)&&a.createElement("div",{className:"stream-staleness-badge",style:Object.assign(Object.assign({position:"absolute"},"top-left"===We.badgePosition?{top:4,left:4}:"bottom-left"===We.badgePosition?{bottom:4,left:4}:"bottom-right"===We.badgePosition?{bottom:4,right:4}:{top:4,right:4}),{padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",background:ot?"#dc3545":"#28a745",color:"white"})},ot?"STALE":"LIVE"),St,Mt)});ne.displayName="StreamXYFrame";const oe={category10:r.schemeCategory10,tableau10:r.schemeTableau10,set3:r.schemeSet3,blues:r.interpolateBlues,reds:r.interpolateReds,greens:r.interpolateGreens,oranges:r.interpolateOranges,purples:r.interpolatePurples,viridis:r.interpolateViridis,plasma:r.interpolatePlasma},se=r.schemeCategory10;function ie(e,t,n){if("function"==typeof t)return t(e);const o=e[t];return n?n(o):se[Math.abs(function(e){let t=0;for(let n=0;e.length>n;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return Math.abs(t)}(o+""))%se.length]}function re(e,t,n="category10"){const s=Array.from(new Set(e.map(e=>e[t]))),i=s.every(e=>"number"==typeof e||!isNaN(Number(e)));if(Array.isArray(n))return o.scaleOrdinal().domain(s).range(n).unknown("#999");const r=oe[n]||oe.category10;if(i&&"function"==typeof r)return e=>r(Number(e)/Math.max(...s.map(Number)));{const e=Array.isArray(r)?r:se;return o.scaleOrdinal().domain(s).range(e).unknown("#999")}}function le(e,t,n=[3,20],o){let s;if(s="function"==typeof t?t(e):e[t],!o)return s;const[i,r]=o,[l,a]=n;return r===i?(l+a)/2:l+(s-i)/(r-i)*(a-l)}const ae=e.createContext(null);function ce(e){return e?"string"==typeof e?{name:e}:e:null}function ue(e,t,n){return t?o=>{var s;const i=Object.assign({},e(o));if(t.isActive)if(t.predicate(o))(null==n?void 0:n.selectedStyle)&&Object.assign(i,n.selectedStyle);else{const e=null!==(s=null==n?void 0:n.unselectedOpacity)&&void 0!==s?s:.2;i.opacity=e,i.fillOpacity=e,i.strokeOpacity=e,(null==n?void 0:n.unselectedStyle)&&Object.assign(i,n.unselectedStyle)}return i}:e}function he(t){const n=e.createContext(null),o=de(t);return[function({children:o}){const s=e.useMemo(()=>de(t),[]);return a.createElement(n.Provider,{value:s,children:o})},t=>{var s;const i=null!==(s=e.useContext(n))&&void 0!==s?s:o;return function(t,n){const[o,s]=e.useState(n);return e.useLayoutEffect(()=>t(()=>s(n)),[t]),o}(i.subscribe,()=>t(i.getState()))}]}function de(e){const t=new EventTarget;let n=e(function(e){n=Object.assign(Object.assign({},n),e(n)),t.dispatchEvent(new CustomEvent("update"))});return{getState:()=>n,subscribe:function(e){return t.addEventListener("update",e),()=>t.removeEventListener("update",e)}}}function fe(e){const t=[];for(const[n,o]of Object.entries(e.fields))if("point"===o.type)t.push(e=>o.values.has(e[n]));else{const[e,s]=o.range;t.push(t=>{const o=t[n];return o>=e&&s>=o})}return e=>t.every(t=>t(e))}function pe(e,t){let n=e.get(t);return n||(n={name:t,resolution:"union",clauses:new Map},e.set(t,n)),n}const[me,ye]=he(e=>({selections:new Map,setClause(t,n){e(e=>{const o=new Map(e.selections),s=pe(o,t),i=new Map(s.clauses);return i.set(n.clientId,n),o.set(t,Object.assign(Object.assign({},s),{clauses:i})),{selections:o}})},clearClause(t,n){e(e=>{const o=e.selections.get(t);if(!o)return{};const s=new Map(e.selections),i=new Map(o.clauses);return i.delete(n),s.set(t,Object.assign(Object.assign({},o),{clauses:i})),{selections:s}})},setResolution(t,n){e(e=>{const o=new Map(e.selections),s=pe(o,t);return o.set(t,Object.assign(Object.assign({},s),{resolution:n})),{selections:o}})},clearSelection(t){e(e=>{const n=new Map(e.selections),o=n.get(t);return o&&n.set(t,Object.assign(Object.assign({},o),{clauses:new Map})),{selections:n}})}}));function ge(t){const n=e.useId(),o=t.clientId||n,{name:s}=t,i=ye(e=>e.selections.get(s)),r=ye(e=>e.setClause),l=ye(e=>e.clearClause),a=e.useMemo(()=>!!i&&i.clauses.size>0,[i]);return{predicate:e.useMemo(()=>i&&0!==i.clauses.size?function(e,t){const n=[];for(const[o,s]of e.clauses)"crossfilter"===e.resolution&&o===t||n.push(fe(s));return 0===n.length?()=>!0:"intersect"===e.resolution?e=>n.every(t=>t(e)):e=>n.some(t=>t(e))}(i,o):()=>!0,[i,o]),isActive:a,selectPoints:e.useCallback(e=>{const t={};for(const[n,o]of Object.entries(e))t[n]={type:"point",values:new Set(o)};r(s,{clientId:o,type:"point",fields:t})},[o,s,r]),selectInterval:e.useCallback(e=>{const t={};for(const[n,o]of Object.entries(e))t[n]={type:"interval",range:o};r(s,{clientId:o,type:"interval",fields:t})},[o,s,r]),clear:e.useCallback(()=>{l(s,o)},[l,s,o]),clientId:o}}function be(t){const{name:n,xField:o,yField:s}=t,{predicate:i,isActive:r,selectInterval:l,clear:a}=ge({name:n}),c=o&&s?"xyBrush":o?"xBrush":"yBrush",u=e.useCallback(e=>{if(!e)return void a();const t={};"xyBrush"===c&&Array.isArray(e)&&2===e.length?(o&&(t[o]=[Math.min(e[0][0],e[1][0]),Math.max(e[0][0],e[1][0])]),s&&(t[s]=[Math.min(e[0][1],e[1][1]),Math.max(e[0][1],e[1][1])])):"xBrush"===c&&Array.isArray(e)?o&&(t[o]=[Math.min(...e),Math.max(...e)]):"yBrush"===c&&Array.isArray(e)&&s&&(t[s]=[Math.min(...e),Math.max(...e)]),Object.keys(t).length>0&&l(t)},[c,o,s,l,a]);return{brushInteraction:e.useMemo(()=>({brush:c,during:u,end:u}),[c,u]),predicate:i,isActive:r,clear:a}}const[ve,xe]=he(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const n=e.observations;return n.push(t),n.length>e.maxObservations&&n.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}})),we="#007bff";function ke(e){return"function"==typeof e?e:t=>t[e]}function Ae(t,n,o="category10"){const s=e.useContext(ae);return e.useMemo(()=>{if(n&&"function"!=typeof n)return s&&Object.keys(s).length>0?e=>s[e]||re(t,n,o)(e):re(t,n,o)},[t,n,o,s])}function Ee({selection:t,linkedHover:n,fallbackFields:o=[],unwrapData:s=!1,onObservation:i,chartType:r,chartId:l}){const a=function(e,t){return e?!0===e?{name:"hover",fields:t||[]}:"string"==typeof e?{name:e,fields:t||[]}:{name:e.name||"hover",fields:e.fields}:null}(n,o),c=ge({name:(null==t?void 0:t.name)||"__unused__"}),u=function(t){const n=t.name||"hover",{fields:o}=t,{predicate:s,isActive:i,selectPoints:r,clear:l}=ge({name:n});return{onHover:e.useCallback(e=>{if(!e)return void l();const t={};for(const n of o){const o=e[n];void 0!==o&&(t[n]=[o])}Object.keys(t).length>0&&r(t)},[o,r,l,n]),predicate:s,isActive:i}}({name:(null==a?void 0:a.name)||"hover",fields:(null==a?void 0:a.fields)||o||[]}),h=xe(e=>e.pushObservation),d=t?{isActive:c.isActive,predicate:c.predicate}:null,f=e.useCallback(e=>{var t,o;if(n)if(e){let t=e.data||e.datum||e;Array.isArray(t)&&(t=t[0]),u.onHover(t)}else u.onHover(null);if(i||h){const n={timestamp:Date.now(),chartType:r||"unknown",chartId:l};if(e){let s=e.data||e.datum||e;Array.isArray(s)&&(s=s[0]);const r=Object.assign(Object.assign({},n),{type:"hover",datum:s||{},x:null!==(t=e.x)&&void 0!==t?t:0,y:null!==(o=e.y)&&void 0!==o?o:0});i&&i(r),h&&h(r)}else{const e=Object.assign(Object.assign({},n),{type:"hover-end"});i&&i(e),h&&h(e)}}},[n,u,i,r,l,h]),p=e.useCallback(e=>{var t,n;if(i||h){const o={timestamp:Date.now(),chartType:r||"unknown",chartId:l};if(e){let s=e.data||e.datum||e;Array.isArray(s)&&(s=s[0]);const r=Object.assign(Object.assign({},o),{type:"click",datum:s||{},x:null!==(t=e.x)&&void 0!==t?t:0,y:null!==(n=e.y)&&void 0!==n?n:0});i&&i(r),h&&h(r)}else{const e=Object.assign(Object.assign({},o),{type:"click-end"});i&&i(e),h&&h(e)}}},[i,h,r,l]);return{activeSelectionHook:d,customHoverBehavior:f,customClickBehavior:p}}function Me({data:t,colorBy:n,colorScale:o,showLegend:s,userMargin:i,defaults:r={top:50,bottom:60,left:70,right:40}}){const l=void 0!==s?s:!!n,a=e.useMemo(()=>{if(l&&n)return function({data:e,colorBy:t,colorScale:n,getColor:o,strokeColor:s,strokeWidth:i}){return{legendGroups:[{styleFn:e=>{const t={fill:e.color,stroke:e.color};return void 0!==s&&(t.stroke=s),void 0!==i&&(t.strokeWidth=i),t},type:"fill",items:Array.from(new Set(e.map(e=>"function"==typeof t?t(e):e[t]))).map(s=>{const i=e.find("function"==typeof t?e=>t(e)===s:e=>e[t]===s),r=i?o(i,t,n):n?n(s):"#000000";return{label:s+"",color:r}}),label:""}]}}({data:t,colorBy:n,colorScale:o,getColor:ie})},[l,n,t,o]),c=e.useMemo(()=>{const e=Object.assign(Object.assign({},r),i);return a&&120>e.right&&(e.right=120),e},[r,i,a]);return{legend:a,margin:c}}const Se={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}}};function Oe(e,t,n){var o,s,i,r,l,a;const c=Se[e||"primary"],u="context"===e||"sparkline"===e;return{width:null!==(o=t.width)&&void 0!==o?o:c.width,height:null!==(s=t.height)&&void 0!==s?s:c.height,showAxes:c.showAxes,showGrid:null!==(i=t.showGrid)&&void 0!==i?i:c.showGrid,enableHover:null!==(r=t.enableHover)&&void 0!==r?r:!!t.linkedHover||c.enableHover,showLegend:null!==(l=t.showLegend)&&void 0!==l?l:c.showLegend,showLabels:null!==(a=t.showLabels)&&void 0!==a?a:c.showLabels,title:u?void 0:t.title,xLabel:u?void 0:t.xLabel,yLabel:u?void 0:t.yLabel,categoryLabel:u?void 0:t.categoryLabel,valueLabel:u?void 0:t.valueLabel,marginDefaults:c.marginDefaults}}const Le={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"8px 12px",borderRadius:"4px",fontSize:"14px",lineHeight:"1.5",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Ne(e,t){return"function"==typeof t?t(e):e[t]}function je(e,t){return t?t(e):null==e?"":"number"==typeof e?e.toLocaleString():e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function Ce(e){return!0===e||("function"==typeof e?e:!1!==e&&void 0!==e&&("object"!=typeof e||null===e||!("fields"in e)&&!("title"in e)||function(e={}){const{fields:t,title:n,format:o,style:s={},className:i=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let r;const l=[];if(n){const t=Ne(e,n);r=je(t,o)}if(t&&t.length>0)t.forEach(t=>{let n,s,i;"string"==typeof t?(n=t,s=t,i=o):(n=t.label,s=t.accessor||t.key||"",i=t.format||o);const r=Ne(e,s);l.push({label:n,value:je(r,i)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){r=je(e[n],o);break}if(!r){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(r=je(e[t[0]],o))}}const c=Object.assign(Object.assign({},Le),s);return a.createElement("div",{className:("semiotic-tooltip "+i).trim(),style:c},r&&a.createElement("div",{style:{fontWeight:l.length>0?"bold":"normal"}},r),l.map((e,t)=>a.createElement("div",{key:t,style:{marginTop:0===t&&r?"4px":0}},e.label&&a.createElement("span",null,e.label,": "),e.value)))}}(e)))}function _e(e){return"string"==typeof e?e:"value"}function Be(e){return t=>{const n=t.data;return n?a.createElement("div",{className:"semiotic-tooltip",style:Le},e.map((e,t)=>{const o=function(e,t){return"function"==typeof t?t(e):e[t]}(n,e.accessor),s=null==(i=o)?"–":"number"==typeof i?Math.abs(i)>9999?i.toLocaleString():i+"":i instanceof Date?i.toLocaleDateString():i+"";var i;return a.createElement("div",{key:t,style:t>0?{marginTop:2}:void 0},a.createElement("span",{style:{opacity:.8}},e.label,": "),a.createElement("span",{style:{fontWeight:"color"===e.role||"group"===e.role?"bold":"normal"}},s))})):null}}function We({componentName:e,message:t,width:n,height:o}){return a.createElement("div",{role:"alert",style:{width:n,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"}},a.createElement("div",{style:{textAlign:"center",maxWidth:400}},a.createElement("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"}},e),a.createElement("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5}},t)))}class $e extends a.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){var n,o;null===(o=(n=this.props).onError)||void 0===o||o.call(n,e,t)}render(){if(this.state.error){const{fallback:e}=this.props,t=this.state.error;return"function"==typeof e?e(t):void 0!==e?e:a.createElement(We,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}}var He;const ze="undefined"!=typeof process&&"production"!==(null===(He=process.env)||void 0===He?void 0:He.NODE_ENV);function Te({componentName:e,width:t,height:n,children:o}){return a.createElement($e,{fallback:o=>a.createElement(We,{componentName:e,message:o.message,width:t,height:n})},o)}function Fe(e,t,n,o){if(!ze)return;if(!t||0===t.length)return;if("string"!=typeof o)return;const s=t[0];if(!s||"object"!=typeof s)return;if(o in s)return;const i=Object.keys(s).join(", ");console.warn(`[semiotic] ${e}: ${n} "${o}" not found in data. Available keys: ${i}`)}function Pe(e,t){if(0===t.length)return null;const n=e.toLowerCase();return t.find(e=>e.toLowerCase().includes(n)||n.includes(e.toLowerCase()))||t[0]}function Ie({componentName:e,data:t,accessors:n,requiredProps:o}){if(o)for(const[t,n]of Object.entries(o))if(null==n)return`${e}: ${t} is required. Provide a field name or function.`;if(!t||!Array.isArray(t)||0===t.length)return e+": No data provided. Pass a non-empty array to the data prop.";if(!Array.isArray(t)&&"object"==typeof t)return e+": data should be an array, but received an object. If this is hierarchical data, use TreeDiagram, Treemap, or CirclePack instead.";if(n){const o=function(e){return e.length>3?[e[0],e[Math.floor(e.length/2)],e[e.length-1]]:e}(t).find(e=>e&&"object"==typeof e);if(o){const t=Object.keys(o);for(const[s,i]of Object.entries(n))if(i&&"string"==typeof i&&!(i in o)){const n=Pe(i,t),o=n?` Try ${s}="${n}".`:"";return`${e}: ${s} "${i}" not found in data. Available fields: ${t.join(", ")}.${o}`}}}return null}const De="__forecastSegment";function Re(e,t){return"function"==typeof t?t(e):!!e[t]}function Ge(t){var n,o;const s=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:i,margin:r,className:l,xFormat:c,yFormat:u,xAccessor:h="x",yAccessor:d="y",lineBy:f,lineDataAccessor:p="coordinates",colorBy:m,colorScheme:y="category10",curve:g="linear",showPoints:b=!1,pointRadius:v=3,fillArea:x=!1,areaOpacity:w=.3,lineWidth:k=2,tooltip:A,pointIdAccessor:E,annotations:M,anomaly:S,forecast:O,frameProps:L={},selection:N,linkedHover:j,onObservation:C,chartId:_}=t,B=s.width,W=s.height,$=s.enableHover,H=s.showGrid,z=s.showLegend,T=s.title,F=s.xLabel,P=s.yLabel,I=i||[];Fe("LineChart",I,"xAccessor",h),Fe("LineChart",I,"yAccessor",d);const D="string"==typeof h?h:"x",R="string"==typeof d?d:"y",G=e.useMemo(()=>O?function(e,t,n,o,s){return(i=o).isTraining||i.isForecast||i.isAnomaly||i.upperBounds||i.lowerBounds?function(e,t,n,o,s){var i,r,l;const{isTraining:a,isForecast:c,isAnomaly:u,upperBounds:h,lowerBounds:d,color:f="#6366f1",bandOpacity:p=.15,anomalyColor:m="#ef4444",anomalyRadius:y=6,label:g}=o,b=e.map(e=>{let t="observed";return c&&Re(e,c)?t="forecast":a&&Re(e,a)&&(t="training"),Object.assign(Object.assign({},e),{[De]:t})}),v=[];if(h&&d){const e="string"==typeof h?h:"__envUpper",t="string"==typeof d?d:"__envLower";if("function"==typeof h||"function"==typeof d)for(const n of b)"function"==typeof h&&(n[e]=h(n)),"function"==typeof d&&(n[t]=d(n));v.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:f,fillOpacity:p,label:g})}return u&&v.push({type:"highlight",filter:e=>Re(e,u),color:m,r:y,style:{stroke:m,strokeWidth:1.5,fill:m,fillOpacity:.7}}),s&&v.push({type:"anomaly-band",threshold:null!==(i=s.threshold)&&void 0!==i?i:2,showBand:!1!==s.showBand,fill:s.bandColor||"#6366f1",fillOpacity:null!==(r=s.bandOpacity)&&void 0!==r?r:.1,anomalyColor:s.anomalyColor||"#ef4444",anomalyRadius:null!==(l=s.anomalyRadius)&&void 0!==l?l:6,label:s.label}),{processedData:b,annotations:v}}(e,0,0,o,s):function(e,t,n,o,s){var i,r,l;const{trainEnd:a,steps:c=10,confidence:u=.95,color:h="#6366f1",bandOpacity:d=.15,label:f}=o;if(null==a)return{processedData:e,annotations:[]};const p=[],m=[];for(const n of e)n[t]>a?m.push(Object.assign(Object.assign({},n),{[De]:"observed"})):p.push(Object.assign(Object.assign({},n),{[De]:"training"}));const y=p.map(e=>[e[t],e[n]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),g=[],b=[];if(y.length>=3){const o=y.length;let s=0,i=0,r=0,l=0;for(const[e,t]of y)s+=e,i+=t,r+=e*e,l+=e*t;const a=o*r-s*s;if(Math.abs(a)>1e-12){const r=(o*l-s*i)/a,p=(i-r*s)/o,m=e=>p+r*e,v=y.map(([e,t])=>t-m(e)).reduce((e,t)=>e+t*t,0),x=Math.sqrt(v/Math.max(o-2,1)),w=y.reduce((e,t)=>e+t[0],0)/o,k=y.reduce((e,t)=>e+Math.pow(t[0]-w,2),0),A=.99>u?.95>u?.9>u?1:1.645:1.96:2.576,E=e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e)),M=Math.max(...E),S=y.length>1?(y[o-1][0]-y[0][0])/(o-1):1;for(let e=1;c>=e;e++){const s=M+e*S,i=m(s),r=x*Math.sqrt(1+1/o+(k>0?Math.pow(s-w,2)/k:0))*A;b.push({[t]:s,[n]:i,[De]:"forecast",__forecastUpper:i+r,__forecastLower:i-r})}g.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:h,fillOpacity:d,label:f})}}return g.push({type:"x-threshold",x:a,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),s&&g.push({type:"anomaly-band",threshold:null!==(i=s.threshold)&&void 0!==i?i:2,showBand:!1!==s.showBand,fill:s.bandColor||"#6366f1",fillOpacity:null!==(r=s.bandOpacity)&&void 0!==r?r:.1,anomalyColor:s.anomalyColor||"#ef4444",anomalyRadius:null!==(l=s.anomalyRadius)&&void 0!==l?l:6,label:s.label}),{processedData:[...p,...m,...b],annotations:g}}(e,t,n,o,s);var i}(I,D,R,O,S):null,[I,O,S,D,R]),Y=e.useMemo(()=>G?G.annotations:S?function(e){var t,n,o;return[{type:"anomaly-band",threshold:null!==(t=e.threshold)&&void 0!==t?t:2,showBand:!1!==e.showBand,fill:e.bandColor||"#6366f1",fillOpacity:null!==(n=e.bandOpacity)&&void 0!==n?n:.1,anomalyColor:e.anomalyColor||"#ef4444",anomalyRadius:null!==(o=e.anomalyRadius)&&void 0!==o?o:6,label:e.label}]}(S):[],[G,S]),X=G?G.processedData:I,q=O&&!f?De:f,{activeSelectionHook:V,customHoverBehavior:U}=Ee({selection:N,linkedHover:j,fallbackFields:m?["string"==typeof m?m:""]:[],onObservation:C,chartType:"LineChart",chartId:_}),Z=void 0!==(null===(n=X[0])||void 0===n?void 0:n[p]),J=e.useMemo(()=>{if(Z)return X;if(q){const e=X.reduce((e,t)=>{const n="function"==typeof q?q(t):t[q];if(!e[n]){const t={[p]:[]};"string"==typeof q&&(t[q]=n),e[n]=t}return e[n][p].push(t),e},{});return Object.values(e)}return[{[p]:X}]},[X,q,p,Z]),K=Ae(X,m,y),Q=e.useMemo(()=>e=>{const t={strokeWidth:k};return t.stroke=m?ie(e,m,K):we,x&&(t.fill=t.stroke,t.fillOpacity=w),t},[m,K,k,x,w]),ee=e.useMemo(()=>O?function(e,t){var n,o;const s=null!==(n=t.trainDasharray)&&void 0!==n?n:"8,4",i=null!==(o=t.forecastDasharray)&&void 0!==o?o:"4,4",r=t.color||"#6366f1";return t=>{const n=e(t),o=t[De];return"training"===o?Object.assign(Object.assign({},n),{strokeDasharray:s}):"forecast"===o?Object.assign(Object.assign({},n),{stroke:r,strokeDasharray:i}):n}}(Q,O):Q,[Q,O]),te=e.useMemo(()=>ue(ee,V,N),[ee,V,N]),oe=e.useMemo(()=>{if(b)return e=>{const t={r:v,fillOpacity:1};return t.fill=m?ie(e.parentLine||e,m,K):we,t}},[b,v,m,K]),se=x?"area":"line",{legend:re,margin:le}=Me({data:J,colorBy:m,colorScale:K,showLegend:z,userMargin:r,defaults:s.marginDefaults}),ae=f||m,ce=e.useMemo(()=>Be([{label:F||_e(h),accessor:h,role:"x"},{label:P||_e(d),accessor:d,role:"y"},...ae?[{label:_e(ae),accessor:ae,role:"group"}]:[]]),[h,d,F,P,ae]),he=Ie({componentName:"LineChart",data:Z?(null===(o=X[0])||void 0===o?void 0:o[p])||[]:I,accessors:{xAccessor:h,yAccessor:d}});if(he)return a.createElement(We,{componentName:"LineChart",message:he,width:B,height:W});const de=e.useMemo(()=>Z||q?J.flatMap(e=>{const t=e[p]||[];return q&&"string"==typeof q?t.map(t=>Object.assign(Object.assign({},t),{[q]:e[q]})):t}):X,[J,p,Z,q,X]),fe=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:se,data:de,xAccessor:h,yAccessor:d,groupAccessor:q||void 0,curve:g,lineStyle:te},b&&{pointStyle:oe}),{size:[B,W],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:le,showAxes:s.showAxes,xLabel:F,yLabel:P,xFormat:c,yFormat:u,enableHover:$,showGrid:H}),re&&{legend:re}),T&&{title:T}),l&&{className:l}),{tooltipContent:A?Ce(A):ce}),(j||C)&&{customHoverBehavior:U}),E&&{pointIdAccessor:E}),((null==M?void 0:M.length)||Y.length)&&{annotations:[...M||[],...Y]}),L);return a.createElement(Te,{componentName:"LineChart",width:B,height:W},a.createElement(ne,Object.assign({},fe)))}function Ye(t){var n;const o=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:r,xFormat:l,yFormat:c,xAccessor:u="x",yAccessor:h="y",areaBy:d,y0Accessor:f,gradientFill:p=!1,lineDataAccessor:m="coordinates",colorBy:y,colorScheme:g="category10",curve:b="monotoneX",areaOpacity:v=.7,showLine:x=!0,lineWidth:w=2,tooltip:k,annotations:A,frameProps:E={},selection:M,linkedHover:S,onObservation:O,chartId:L}=t,N=o.width,j=o.height,C=o.enableHover,_=o.showGrid,B=o.showLegend,W=o.title,$=o.xLabel,H=o.yLabel,z=s||[];Fe("AreaChart",z,"xAccessor",u),Fe("AreaChart",z,"yAccessor",h);const{activeSelectionHook:T,customHoverBehavior:F}=Ee({selection:M,linkedHover:S,fallbackFields:y?["string"==typeof y?y:""]:[],onObservation:O,chartType:"AreaChart",chartId:L}),P=void 0!==(null===(n=z[0])||void 0===n?void 0:n[m]),I=e.useMemo(()=>{if(P)return z;if(d){const e=z.reduce((e,t)=>{const n="function"==typeof d?d(t):t[d];if(!e[n]){const t={[m]:[]};"string"==typeof d&&(t[d]=n),e[n]=t}return e[n][m].push(t),e},{});return Object.values(e)}return[{[m]:z}]},[z,d,m,P]),D=Ae(z,y,g),R=e.useMemo(()=>e=>{const t={},n=y?ie(e,y,D):we;return t.fill=n,t.fillOpacity=v,x?(t.stroke=n,t.strokeWidth=w):t.stroke="none",t},[y,D,v,x,w]),G=e.useMemo(()=>ue(R,T,M),[R,T,M]),{legend:Y,margin:X}=Me({data:I,colorBy:y,colorScale:D,showLegend:B,userMargin:i,defaults:o.marginDefaults}),q=d||y,V=e.useMemo(()=>Be([{label:$||_e(u),accessor:u,role:"x"},{label:H||_e(h),accessor:h,role:"y"},...q?[{label:_e(q),accessor:q,role:"group"}]:[]]),[u,h,$,H,q]),U=Ie({componentName:"AreaChart",data:z,accessors:{xAccessor:u,yAccessor:h}});if(U)return a.createElement(We,{componentName:"AreaChart",message:U,width:N,height:j});const Z=e.useMemo(()=>P||d?I.flatMap(e=>{const t=e[m]||[];return d&&"string"==typeof d?t.map(t=>Object.assign(Object.assign({},t),{[d]:e[d]})):t}):z,[I,m,P,d,z]),J=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"area",data:Z,xAccessor:u,yAccessor:h,groupAccessor:d||void 0},f&&{y0Accessor:f}),p&&{gradientFill:p}),{curve:b,lineStyle:G,size:[N,j],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:X,showAxes:o.showAxes,xLabel:$,yLabel:H,xFormat:l,yFormat:c,enableHover:C,showGrid:_}),Y&&{legend:Y}),W&&{title:W}),r&&{className:r}),{tooltipContent:k?Ce(k):V}),(S||O)&&{customHoverBehavior:F}),A&&A.length>0&&{annotations:A}),E);return a.createElement(Te,{componentName:"AreaChart",width:N,height:j},a.createElement(ne,Object.assign({},J)))}function Xe(t){var n;const o=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:r,xFormat:l,yFormat:c,xAccessor:u="x",yAccessor:h="y",areaBy:d,lineDataAccessor:f="coordinates",colorBy:p,colorScheme:m="category10",curve:y="monotoneX",areaOpacity:g=.7,showLine:b=!0,lineWidth:v=2,normalize:x=!1,tooltip:w,annotations:k,frameProps:A={},selection:E,linkedHover:M,onObservation:S,chartId:O}=t,L=o.width,N=o.height,j=o.enableHover,C=o.showGrid,_=o.showLegend,B=o.title,W=o.xLabel,$=o.yLabel,H=s||[],{activeSelectionHook:z,customHoverBehavior:T}=Ee({selection:E,linkedHover:M,fallbackFields:p?["string"==typeof p?p:""]:[],onObservation:S,chartType:"StackedAreaChart",chartId:O}),F=void 0!==(null===(n=H[0])||void 0===n?void 0:n[f]),P=e.useMemo(()=>{if(F)return H;if(d){const e=H.reduce((e,t)=>{const n="function"==typeof d?d(t):t[d];if(!e[n]){const t={[f]:[]};"string"==typeof d&&(t[d]=n),e[n]=t}return e[n][f].push(t),e},{});return Object.values(e)}return[{[f]:H}]},[H,d,f,F]),I=Ae(H,p,m),D=e.useMemo(()=>e=>{const t={},n=p?ie(e,p,I):we;return t.fill=n,t.fillOpacity=g,b?(t.stroke=n,t.strokeWidth=v):t.stroke="none",t},[p,I,g,b,v]),R=e.useMemo(()=>ue(D,z,E),[D,z,E]),{legend:G,margin:Y}=Me({data:P,colorBy:p,colorScale:I,showLegend:_,userMargin:i,defaults:o.marginDefaults}),X=d||p,q=e.useMemo(()=>Be([{label:W||_e(u),accessor:u,role:"x"},{label:$||_e(h),accessor:h,role:"y"},...X?[{label:_e(X),accessor:X,role:"group"}]:[]]),[u,h,W,$,X]),V=Ie({componentName:"StackedAreaChart",data:H,accessors:{xAccessor:u,yAccessor:h}});if(V)return a.createElement(We,{componentName:"StackedAreaChart",message:V,width:L,height:N});const U=e.useMemo(()=>F||d?P.flatMap(e=>{const t=e[f]||[];return d&&"string"==typeof d?t.map(t=>Object.assign(Object.assign({},t),{[d]:e[d]})):t}):H,[P,f,F,d,H]),Z=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"stackedarea",data:U,xAccessor:u,yAccessor:h,groupAccessor:d||void 0,curve:y,normalize:x,lineStyle:R,size:[L,N],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:Y,showAxes:o.showAxes,xLabel:W,yLabel:$,xFormat:l,yFormat:c,enableHover:j,showGrid:C},G&&{legend:G}),B&&{title:B}),r&&{className:r}),{tooltipContent:w?Ce(w):q}),(M||S)&&{customHoverBehavior:T}),k&&k.length>0&&{annotations:k}),A);return a.createElement(Te,{componentName:"StackedAreaChart",width:L,height:N},a.createElement(ne,Object.assign({},Z)))}function qe(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,margin:s,className:i,xFormat:r,yFormat:l,xAccessor:c="x",yAccessor:u="y",colorBy:h,colorScheme:d="category10",sizeBy:f,sizeRange:p=[3,15],pointRadius:m=5,pointOpacity:y=.8,tooltip:g,marginalGraphics:b,pointIdAccessor:v,annotations:x,frameProps:w={},selection:k,linkedHover:A,linkedBrush:E,onObservation:M,chartId:S}=t,O=n.width,L=n.height,N=n.enableHover,j=n.showGrid,C=n.showLegend,_=n.title,B=n.xLabel,W=n.yLabel,$=o||[];Fe("Scatterplot",$,"xAccessor",c),Fe("Scatterplot",$,"yAccessor",u);const{activeSelectionHook:H,customHoverBehavior:z}=Ee({selection:k,linkedHover:A,fallbackFields:h?["string"==typeof h?h:""]:[],onObservation:M,chartType:"Scatterplot",chartId:S}),T=ce(E);be({name:(null==T?void 0:T.name)||"__unused_brush__",xField:(null==T?void 0:T.xField)||("string"==typeof c?c:void 0),yField:(null==T?void 0:T.yField)||("string"==typeof u?u:void 0)});const F=Ae($,h,d),P=e.useMemo(()=>{if(!f||0===$.length)return;const e=$.map(e=>"function"==typeof f?f(e):e[f]);return[Math.min(...e),Math.max(...e)]},[$,f]),I=e.useMemo(()=>e=>{const t={fillOpacity:y};return t.fill=h?ie(e,h,F):we,t.r=f?le(e,f,p,P):m,t},[h,F,f,p,P,m,y]),D=e.useMemo(()=>ue(I,H,k),[I,H,k]),{legend:R,margin:G}=Me({data:$,colorBy:h,colorScale:F,showLegend:C,userMargin:s,defaults:n.marginDefaults}),Y=e.useMemo(()=>Be([{label:B||_e(c),accessor:c,role:"x"},{label:W||_e(u),accessor:u,role:"y"},...h?[{label:_e(h),accessor:h,role:"color"}]:[],...f?[{label:_e(f),accessor:f,role:"size"}]:[]]),[c,u,B,W,h,f]),X=Ie({componentName:"Scatterplot",data:$,accessors:{xAccessor:c,yAccessor:u}});if(X)return a.createElement(We,{componentName:"Scatterplot",message:X,width:O,height:L});const q=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"scatter",data:$,xAccessor:c,yAccessor:u,colorAccessor:h||void 0,sizeAccessor:f||void 0,sizeRange:p,pointStyle:D,colorScheme:d,size:[O,L],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:G,showAxes:n.showAxes,xLabel:B,yLabel:W,xFormat:r,yFormat:l,enableHover:N,showGrid:j},R&&{legend:R}),_&&{title:_}),i&&{className:i}),{tooltipContent:g?Ce(g):Y}),(A||M)&&{customHoverBehavior:z}),b&&{marginalGraphics:b}),v&&{pointIdAccessor:v}),x&&x.length>0&&{annotations:x}),w);return a.createElement(Te,{componentName:"Scatterplot",width:O,height:L},a.createElement(ne,Object.assign({},q)))}function Ve(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,className:s,xFormat:i,yFormat:l,xAccessor:c="x",yAccessor:u="y",orderAccessor:h,orderLabel:d,pointRadius:f=4,tooltip:p,pointIdAccessor:m,annotations:y,frameProps:g={},selection:b,linkedHover:v,onObservation:x,chartId:w}=t,k=n.width,A=n.height,E=n.enableHover,M=n.showGrid,S=n.title,O=n.xLabel,L=n.yLabel,N=o||[],j=e.useMemo(()=>{if(!h||0===N.length)return N;const e="function"==typeof h?h:e=>e[h];return[...N].sort((t,n)=>{const o=e(t),s=e(n);return(o instanceof Date?o.getTime():+o)-(s instanceof Date?s.getTime():+s)})},[N,h]);Fe("ConnectedScatterplot",j,"xAccessor",c),Fe("ConnectedScatterplot",j,"yAccessor",u);const{activeSelectionHook:C,customHoverBehavior:_}=Ee({selection:b,linkedHover:v,fallbackFields:[],onObservation:x,chartType:"ConnectedScatterplot",chartId:w}),B=j.length,W=B>0&&100>B,$=e.useMemo(()=>0===B?[]:j.map((e,t)=>r.interpolateViridis(1===B?.5:t/(B-1))),[j,B]);e.useMemo(()=>null,[B]);const H=e.useMemo(()=>{if(B>=2)return(e,t,n)=>{var o,s;if("connected-lines"!==e.type)return null;const i=n.scales;if(!i)return null;const r=null!==(o=i.x)&&void 0!==o?o:i.time,l=null!==(s=i.y)&&void 0!==s?s:i.value;if(!r||!l)return null;const h="string"==typeof c?e=>e[c]:c,d="string"==typeof u?e=>e[u]:u,p=[];for(let e=0;j.length-1>e;e++){const t=j[e],n=j[e+1],o=r(h(t)),s=l(d(t)),i=r(h(n)),c=l(d(n)),u=$[e];W&&p.push(a.createElement("line",{key:"halo-"+e,x1:o,y1:s,x2:i,y2:c,stroke:"white",strokeWidth:f+2,strokeOpacity:.5,strokeLinecap:"round"})),p.push(a.createElement("line",{key:"conn-"+e,x1:o,y1:s,x2:i,y2:c,stroke:u,strokeWidth:f,strokeLinecap:"round"}))}return a.createElement("g",{key:"ann-"+t},p)}},[j,$,f,W,c,u,B]),z=e.useMemo(()=>e=>{const t=j.indexOf(e);return{fill:t>=0&&$.length>t?$[t]:"#6366f1",stroke:"white",strokeWidth:1,r:f,fillOpacity:1}},[j,$,f]),T=e.useMemo(()=>ue(z,C,b),[z,C,b]),F=Object.assign({top:50,right:40,bottom:60,left:70},t.margin),P=d||("string"==typeof h?h:"Order"),I=e.useMemo(()=>Be([{label:O||_e(c),accessor:c,role:"x"},{label:L||_e(u),accessor:u,role:"y"},...h?[{label:P,accessor:h,role:"group"}]:[]]),[c,u,O,L,h,P]),D=Ie({componentName:"ConnectedScatterplot",data:j,accessors:{xAccessor:c,yAccessor:u}});if(D)return a.createElement(We,{componentName:"ConnectedScatterplot",message:D,width:k,height:A});const R=e.useMemo(()=>[{type:"connected-lines"},...y||[]],[y]),G=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"scatter",data:j,xAccessor:c,yAccessor:u,pointStyle:T,size:[k,A],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:F,showAxes:n.showAxes,xLabel:O,yLabel:L,xFormat:i,yFormat:l,enableHover:E,showGrid:M},S&&{title:S}),s&&{className:s}),{tooltipContent:p?Ce(p):I}),(v||x)&&{customHoverBehavior:_}),m&&{pointIdAccessor:m}),{annotations:R,svgAnnotationRules:H}),g);return a.createElement(Te,{componentName:"ConnectedScatterplot",width:k,height:A},a.createElement(ne,Object.assign({},G)))}function Ue(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,margin:s,className:i,xFormat:r,yFormat:l,xAccessor:c="x",yAccessor:u="y",sizeBy:h,sizeRange:d=[5,40],colorBy:f,colorScheme:p="category10",bubbleOpacity:m=.6,bubbleStrokeWidth:y=1,bubbleStrokeColor:g="white",tooltip:b,marginalGraphics:v,pointIdAccessor:x,annotations:w,frameProps:k={},selection:A,linkedHover:E,linkedBrush:M,onObservation:S,chartId:O}=t,L=n.width,N=n.height,j=n.enableHover,C=n.showGrid,_=n.showLegend,B=n.title,W=n.xLabel,$=n.yLabel,H=o||[],{activeSelectionHook:z,customHoverBehavior:T}=Ee({selection:A,linkedHover:E,fallbackFields:f?["string"==typeof f?f:""]:[],onObservation:S,chartType:"BubbleChart",chartId:O}),F=ce(M);be({name:(null==F?void 0:F.name)||"__unused_brush__",xField:(null==F?void 0:F.xField)||("string"==typeof c?c:void 0),yField:(null==F?void 0:F.yField)||("string"==typeof u?u:void 0)});const P=Ae(H,f,p),I=e.useMemo(()=>{const e=H.map(e=>"function"==typeof h?h(e):e[h]);return[Math.min(...e),Math.max(...e)]},[H,h]),D=e.useMemo(()=>e=>{const t={fillOpacity:m,strokeWidth:y,stroke:g};return t.fill=f?ie(e,f,P):we,t.r=le(e,h,d,I),t},[f,P,h,d,I,m,y,g]),R=e.useMemo(()=>ue(D,z,A),[D,z,A]),{legend:G,margin:Y}=Me({data:H,colorBy:f,colorScale:P,showLegend:_,userMargin:s,defaults:n.marginDefaults}),X=e.useMemo(()=>Be([{label:W||_e(c),accessor:c,role:"x"},{label:$||_e(u),accessor:u,role:"y"},{label:_e(h),accessor:h,role:"size"},...f?[{label:_e(f),accessor:f,role:"color"}]:[]]),[c,u,W,$,h,f]),q=Ie({componentName:"BubbleChart",data:H,accessors:{xAccessor:c,yAccessor:u},requiredProps:{sizeBy:h}});if(q)return a.createElement(We,{componentName:"BubbleChart",message:q,width:L,height:N});const V=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"bubble",data:H,xAccessor:c,yAccessor:u,colorAccessor:f||void 0,sizeAccessor:h,sizeRange:d,pointStyle:R,colorScheme:p,size:[L,N],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:Y,showAxes:n.showAxes,xLabel:W,yLabel:$,xFormat:r,yFormat:l,enableHover:j,showGrid:C},G&&{legend:G}),B&&{title:B}),i&&{className:i}),{tooltipContent:b?Ce(b):X}),(E||S)&&{customHoverBehavior:T}),v&&{marginalGraphics:v}),x&&{pointIdAccessor:x}),w&&w.length>0&&{annotations:w}),k);return a.createElement(Te,{componentName:"BubbleChart",width:L,height:N},a.createElement(ne,Object.assign({},V)))}function Ze(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:void 0,enableHover:t.enableHover,showLegend:void 0,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:l,xAccessor:c="x",yAccessor:u="y",valueAccessor:h="value",xFormat:d,yFormat:f,colorScheme:p="blues",customColorScale:m,showValues:y=!1,valueFormat:g,cellBorderColor:b="#fff",cellBorderWidth:v=1,tooltip:x,annotations:w,frameProps:k={},selection:A,linkedHover:E,onObservation:M,chartId:S}=t,O=n.width,L=n.height,N=n.enableHover,j=n.title,C=n.xLabel,_=n.yLabel,B=s||[],{margin:W}=Me({data:B,colorBy:void 0,colorScale:void 0,showLegend:!1,userMargin:i,defaults:n.marginDefaults}),{activeSelectionHook:$,customHoverBehavior:H}=Ee({selection:A,linkedHover:E,fallbackFields:[],onObservation:M,chartType:"Heatmap",chartId:S}),z=e.useMemo(()=>"function"==typeof h?e=>h(e):e=>e[h],[h]),T=e.useMemo(()=>{const e=B.map(z);return[Math.min(...e),Math.max(...e)]},[B,z]),F=e.useMemo(()=>"custom"===p&&m?m:o.scaleSequential({blues:r.interpolateBlues,reds:r.interpolateReds,greens:r.interpolateGreens,viridis:r.interpolateViridis}[p]||r.interpolateBlues).domain(T),[p,m,T]);e.useMemo(()=>{const e=ke(c),t=ke(u);return{xBinCount:new Set(B.map(e)).size,yBinCount:new Set(B.map(t)).size}},[B,c,u]),e.useMemo(()=>({coordinates:B}),[B]);const P=e.useMemo(()=>e=>{const t=z(e);return{fill:F(t),stroke:b,strokeWidth:v}},[z,F,b,v]);e.useMemo(()=>ue(P,$,A),[P,$,A]),e.useMemo(()=>{if(!y)return;const e=(T[0]+T[1])/2;return(t,n)=>{const o=z(t),s=g?g(o):o+"";return a.createElement("text",{textAnchor:"middle",dominantBaseline:"middle",fill:z(t)>e?"#fff":"#000",fontSize:"12px"},s)}},[y,z,g,T]);const I=e.useMemo(()=>Be([{label:C||_e(c),accessor:c,role:"x"},{label:_||_e(u),accessor:u,role:"y"},{label:_e(h),accessor:h,role:"value"}]),[c,u,C,_,h]),D=Ie({componentName:"Heatmap",data:B,accessors:{xAccessor:c,yAccessor:u,valueAccessor:h}});if(D)return a.createElement(We,{componentName:"Heatmap",message:D,width:O,height:L});const R=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"heatmap",data:B,xAccessor:c,yAccessor:u,valueAccessor:h,size:[O,L],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:W,showAxes:n.showAxes,xLabel:C,yLabel:_,xFormat:d,yFormat:f,enableHover:N},j&&{title:j}),l&&{className:l}),{tooltipContent:x?Ce(x):I}),(E||M)&&{customHoverBehavior:H}),w&&w.length>0&&{annotations:w}),k);return a.createElement(Te,{componentName:"Heatmap",width:O,height:L},a.createElement(ne,Object.assign({},R)))}function Je({selections:t}){const n=ye(e=>e.setResolution);return e.useEffect(()=>{for(const[e,o]of Object.entries(t))o.resolution&&n(e,o.resolution)},[t,n]),null}function Ke({children:e,selections:t}){return a.createElement(me,null,a.createElement(ve,null,t&&a.createElement(Je,{selections:t}),e))}Ge.displayName="LineChart",Ye.displayName="AreaChart",Xe.displayName="StackedAreaChart",qe.displayName="Scatterplot",Ve.displayName="ConnectedScatterplot",Ue.displayName="BubbleChart",Ze.displayName="Heatmap";const Qe="__splomIdx",et={top:4,bottom:4,left:4,right:4};function tt({frameRef:o,cellSize:s,onBrush:i}){const r=e.useRef(null),l=s-et.left-et.right,c=s-et.top-et.bottom;return e.useEffect(()=>{if(!r.current)return;const e=n.select(r.current).select(".brush-g"),s=t.brush().extent([[0,0],[l,c]]).on("brush end",e=>{var t;const n=null===(t=o.current)||void 0===t?void 0:t.getScales();if(!n)return;if(!e.selection)return void i(null);const[[s,r],[l,a]]=e.selection,c=[[n.x.invert(s),n.y.invert(r)],[n.x.invert(l),n.y.invert(a)]];i(c)});return e.call(s),e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.15).attr("stroke","steelblue").attr("stroke-width",1),()=>{s.on("brush end",null)}},[l,c,o,i]),a.createElement("svg",{ref:r,width:s,height:s,style:{position:"absolute",top:0,left:0}},a.createElement("g",{className:"brush-g",transform:`translate(${et.left},${et.top})`}))}function nt({data:t,xField:n,yField:o,cellSize:s,pointRadius:i,pointOpacity:r,colorBy:l,colorScale:c,brushSelectionName:u,hoverSelectionName:h,unselectedOpacity:d,mode:f,onPointHover:p}){const m=e.useRef(null),y=ge({name:u,clientId:`splom-${n}-${o}`}),g=be({name:u,xField:n,yField:o}),b=ge({name:h,clientId:"splom-hover-source"}),v=b.selectPoints,x=e.useCallback(e=>{e?g.brushInteraction.during(e):g.brushInteraction.end(null)},[g.brushInteraction]),w=e.useCallback(e=>{if(!e)return void(null==p||p(null));const t=e.data,n=null==t?void 0:t[Qe];void 0!==n&&(v({[Qe]:[n]}),null==p||p(t,e.x+et.left,e.y+et.top))},[v,p]),k=e.useCallback(e=>{const t={opacity:r,r:i};return t.fill=l?ie(e,l,c):we,"hover"===f?b.isActive&&b.predicate(e)?(t.opacity=1,t.r=2.5*i,t.stroke="#333",t.strokeWidth=1.5):b.isActive&&(t.opacity=.6*r):y.isActive&&!y.predicate(e)&&(t.opacity=d),t},[l,c,r,i,f,y.isActive,y.predicate,b.isActive,b.predicate,d]);return a.createElement("div",{style:{position:"relative",width:s,height:s}},a.createElement(ne,{ref:m,chartType:"scatter",data:t,size:[s,s],xAccessor:n,yAccessor:o,pointStyle:k,margin:et,showAxes:!1,enableHover:"hover"===f,customHoverBehavior:"hover"===f?w:void 0,tooltipContent:"hover"===f?()=>null:void 0}),"brush"===f&&a.createElement(tt,{frameRef:m,cellSize:s,xField:n,yField:o,onBrush:x}))}function ot({data:t,field:n,label:o,cellSize:s,bins:i,brushSelectionName:r,hoverSelectionName:l,mode:c}){const u=ge({name:r,clientId:"splom-diag-"+n}),h=ge({name:l,clientId:`splom-diag-${n}-hover`}),d="hover"===c?h:u,f=d.isActive,p=d.predicate,m=e.useMemo(()=>{const e=t.map(e=>e[n]).filter(e=>null!=e&&!isNaN(e));if(0===e.length)return{bars:[],selectedBars:[],max:0};const o=Math.min(...e),r=(Math.max(...e)-o)/i||1,l=Array(i).fill(0),a=Array(i).fill(0);for(const e of t){const t=e[n];if(null==t||isNaN(t))continue;const s=Math.min(Math.floor((t-o)/r),i-1);l[s]++,f&&!p(e)||a[s]++}const c=Math.max(...l,1);return{bars:l.map((e,t)=>({x:t/i*s,w:s/i-1,h:e/c*(s-24),count:e})),selectedBars:a.map((e,t)=>({x:t/i*s,w:s/i-1,h:e/c*(s-24),count:e})),max:c}},[t,n,i,s,f,p]);return a.createElement("svg",{width:s,height:s,style:{overflow:"hidden"}},a.createElement("text",{x:s/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333"},o),m.bars.map((e,t)=>a.createElement("rect",{key:"bg-"+t,x:e.x,y:s-e.h,width:Math.max(e.w,1),height:e.h,fill:"#ccc",opacity:f?.3:.6})),f&&m.selectedBars.map((e,t)=>a.createElement("rect",{key:"sel-"+t,x:e.x,y:s-e.h,width:Math.max(e.w,1),height:e.h,fill:we,opacity:.7})))}function st({label:e,cellSize:t}){return a.createElement("svg",{width:t,height:t},a.createElement("text",{x:t/2,y:t/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333"},e))}function it(t){const{data:n,fields:o,fieldLabels:s={},colorBy:i,colorScheme:r="category10",cellSize:l=150,cellGap:c=4,pointRadius:u=2,pointOpacity:h=.5,diagonal:d="histogram",histogramBins:f=20,brushMode:p="crossfilter",hoverMode:m=!0,unselectedOpacity:y=.1,showGrid:g=!1,tooltip:b,showLegend:v,idAccessor:x,className:w,onObservation:k,chartId:A}=t,E="splom",M="splom-hover",S=m?"hover":p?"brush":"hover",O=ye(e=>e.clearSelection),[L,N]=e.useState(null),j=e.useCallback(()=>{O(M),N(null)},[O,M]),C=e.useMemo(()=>(n||[]).map((e,t)=>void 0!==e[Qe]?e:Object.assign(Object.assign({},e),{[Qe]:t})),[n]),_=Ae(C,i,r),B=void 0!==v?v:!!i,W=e.useMemo(()=>{if(!B||!i)return null;const e="string"==typeof i?i:null;return e?[...new Set(C.map(t=>t[e]))].map(e=>({label:e+"",color:_?_(e+""):we})):null},[B,i,C,_]),$=e.useMemo(()=>({display:"grid",gridTemplateColumns:"40px "+o.map(()=>l+"px").join(" "),gridTemplateRows:o.map(()=>l+"px").join(" ")+" 40px",gap:c+"px",width:"fit-content"}),[o,l,c,40]);return a.createElement("div",{className:w,style:{position:"relative"}},W&&a.createElement("div",{style:{display:"flex",gap:12,marginBottom:8,flexWrap:"wrap"}},W.map(e=>a.createElement("div",{key:e.label,style:{display:"flex",alignItems:"center",gap:4}},a.createElement("span",{style:{display:"inline-block",width:10,height:10,borderRadius:"50%",backgroundColor:e.color}}),a.createElement("span",{style:{fontSize:11}},e.label)))),a.createElement("div",{style:$,onMouseLeave:"hover"===S?j:void 0},o.map((e,t)=>a.createElement(a.Fragment,{key:"row-"+e},a.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",writingMode:"vertical-rl",transform:"rotate(180deg)",fontSize:11,fontWeight:"bold",color:"#333"}},s[e]||e),o.map((n,o)=>t===o?"label"===d?a.createElement(st,{key:"diag-"+e,label:s[e]||e,cellSize:l}):a.createElement(ot,{key:"diag-"+e,data:C,field:e,label:s[e]||e,cellSize:l,bins:f,colorBy:i,colorScale:_,brushSelectionName:E,hoverSelectionName:M,unselectedOpacity:y,mode:S}):a.createElement(nt,{key:`cell-${e}-${n}`,data:C,xField:n,yField:e,fieldLabels:s,cellSize:l,pointRadius:u,pointOpacity:h,colorBy:i,colorScale:_,brushSelectionName:E,hoverSelectionName:M,unselectedOpacity:y,showGrid:g,tooltip:b,mode:S,onPointHover:"hover"===S?(s,i,r)=>{s?(N({datum:s,xField:n,yField:e,colIndex:o,rowIndex:t,px:null!=i?i:0,py:null!=r?r:0}),k&&k({type:"hover",datum:s,x:null!=i?i:0,y:null!=r?r:0,timestamp:Date.now(),chartType:"ScatterplotMatrix",chartId:A})):(N(null),k&&k({type:"hover-end",timestamp:Date.now(),chartType:"ScatterplotMatrix",chartId:A}))}:void 0})))),a.createElement("div",null)," ",o.map(e=>a.createElement("div",{key:"col-label-"+e,style:{display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,fontWeight:"bold",color:"#333"}},s[e]||e))),L&&"hover"===S&&(()=>{const e=L.datum,t=s[L.xField]||L.xField,n=s[L.yField]||L.yField,o=i?"function"==typeof i?i(e):e[i]:null,r=x?"function"==typeof x?x(e):e[x]:"Row "+e[Qe];return a.createElement("div",{style:{position:"absolute",left:40+L.colIndex*(l+c)+L.px,top:L.rowIndex*(l+c)+L.py-8,transform:"translate(-50%, -100%)",color:"#333",background:"rgba(255,255,255,0.95)",border:"1px solid #ddd",borderRadius:3,padding:"4px 8px",fontSize:11,lineHeight:1.4,whiteSpace:"nowrap",pointerEvents:"none",zIndex:10}},a.createElement("div",{style:{fontWeight:"bold",marginBottom:2}},r+""),a.createElement("div",null,t,": ",null!=e[L.xField]?Number(e[L.xField]).toFixed(1):"–"),a.createElement("div",null,n,": ",null!=e[L.yField]?Number(e[L.yField]).toFixed(1):"–"),null!=o&&a.createElement("div",{style:{opacity:.8}},"string"==typeof i?i:"group",": ",o+""))})())}function rt(e){const{brushMode:t="crossfilter",hoverMode:n=!0}=e,o={};return!n&&t&&(o.splom={resolution:t}),n&&(o["splom-hover"]={resolution:"union"}),a.createElement(Ke,{selections:o},a.createElement(it,Object.assign({},e)))}function lt({width:o,height:s,margin:i,scales:r,brushDirection:l,extent:c,onBrush:u}){const h=e.useRef(null),d=e.useRef(null),f=e.useRef(!1),p=o+i.left+i.right,m=s+i.top+i.bottom;return e.useEffect(()=>{if(!h.current||!r)return;const e=n.select(h.current).select(".brush-group"),i="x"===l?t.brushX().extent([[0,0],[o,s]]):t.brushY().extent([[0,0],[o,s]]);return i.on("brush end",e=>{if(f.current)return;if(!e.sourceEvent)return;const t=e.selection;if(!t)return void u(null);const n=("x"===l?r.x:r.y).invert;if(!n)return;const o=[n(t[0]),n(t[1])];u(o)}),e.call(i),d.current=i,e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.2).attr("stroke","steelblue").attr("stroke-width",1),()=>{i.on("brush end",null)}},[r,o,s,l,u]),e.useEffect(()=>{if(!d.current||!r||!h.current)return;const e=n.select(h.current).select(".brush-group"),t="x"===l?r.x:r.y;if(f.current=!0,c){const n=[t(c[0]),t(c[1])];e.call(d.current.move,n)}else e.call(d.current.move,null);f.current=!1},[c,r,l]),a.createElement("svg",{ref:h,width:p,height:m,style:{position:"absolute",top:0,left:0,pointerEvents:"all"}},a.createElement("g",{className:"brush-group",transform:`translate(${i.left},${i.top})`}))}function at(t){var n,o;const{data:s,width:i=600,height:r=400,margin:l,className:c,title:u,xLabel:h,yLabel:d,xFormat:f,yFormat:p,xAccessor:m="x",yAccessor:y="y",lineBy:g,lineDataAccessor:b="coordinates",colorBy:v,colorScheme:x="category10",curve:w="linear",lineWidth:k=2,fillArea:A=!1,areaOpacity:E=.3,showPoints:M=!1,pointRadius:S=3,enableHover:O=!0,showGrid:L=!1,showLegend:N,tooltip:j,minimap:C={},renderBefore:_=!1,onBrush:B,brushExtent:W,frameProps:$={}}=t,H=s||[],[z,T]=e.useState(null),F=null!=W?W:z,P=e.useCallback(e=>{W||T(e),null==B||B(e)},[W,B]),I=e.useRef(null),[D,R]=e.useState(null);e.useEffect(()=>{const e=()=>{var t,n;const o=null===(n=null===(t=I.current)||void 0===t?void 0:t.getScales)||void 0===n?void 0:n.call(t);o?R(o):requestAnimationFrame(e)};requestAnimationFrame(e)},[s]);const G=void 0!==(null===(n=H[0])||void 0===n?void 0:n[b]),Y=e.useMemo(()=>{if(G)return H;if(g){const e=H.reduce((e,t)=>{const n="function"==typeof g?g(t):t[g];if(!e[n]){const t={[b]:[]};"string"==typeof g&&(t[g]=n),e[n]=t}return e[n][b].push(t),e},{});return Object.values(e)}return[{[b]:H}]},[H,g,b,G]),X=e.useMemo(()=>G||g?Y.flatMap(e=>{const t=e[b]||[];return g&&"string"==typeof g?t.map(t=>Object.assign(Object.assign({},t),{[g]:e[g]})):t}):H,[Y,b,G,g,H]),q=Ae(H,v,x),V=e.useMemo(()=>e=>{const t={strokeWidth:k};return t.stroke=v?ie(e,v,q):we,A&&(t.fill=t.stroke,t.fillOpacity=E),t},[v,q,k,A,E]),U=e.useMemo(()=>C.lineStyle?C.lineStyle:e=>{const t={strokeWidth:1};return t.stroke=v?ie(e,v,q):we,t},[v,q,C.lineStyle]),Z=e.useMemo(()=>{if(M)return e=>{const t={r:S,fillOpacity:1};return t.fill=v?ie(e.parentLine||e,v,q):we,t}},[M,S,v,q]),{legend:J,margin:K}=Me({data:Y,colorBy:v,colorScale:q,showLegend:N,userMargin:l}),Q=C.height||60,ee=e.useMemo(()=>{var e,t,n,o,s,i,r,l;return{top:null!==(t=null===(e=C.margin)||void 0===e?void 0:e.top)&&void 0!==t?t:0,bottom:null!==(o=null===(n=C.margin)||void 0===n?void 0:n.bottom)&&void 0!==o?o:20,left:null!==(i=null===(s=C.margin)||void 0===s?void 0:s.left)&&void 0!==i?i:K.left,right:null!==(l=null===(r=C.margin)||void 0===r?void 0:r.right)&&void 0!==l?l:K.right}},[C.margin,K]),te=C.brushDirection||"x",oe=Ie({componentName:"MinimapChart",data:H,accessors:{xAccessor:m,yAccessor:y}});if(oe)return a.createElement(We,{componentName:"MinimapChart",message:oe,width:i,height:r});const se=A?"area":"line",re=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:se,data:X,xAccessor:m,yAccessor:y,groupAccessor:g||void 0,curve:w,lineStyle:V},M&&{pointStyle:Z}),{size:[i,r],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:K,showAxes:!0,xLabel:h,yLabel:d,xFormat:f,yFormat:p,enableHover:O,showGrid:L}),J&&{legend:J}),u&&{title:u}),j&&{tooltipContent:Ce(j)}),F&&{xExtent:F}),$),le={chartType:se,data:X,xAccessor:m,yAccessor:y,groupAccessor:g||void 0,curve:w,lineStyle:U,size:[i,Q+ee.top+ee.bottom],margin:ee,showAxes:null!==(o=C.showAxes)&&void 0!==o&&o,background:C.background,enableHover:!1},ae=a.createElement("div",{key:"minimap",style:{position:"relative",width:i,overflow:"hidden"}},a.createElement(ne,Object.assign({ref:I},le)),a.createElement(lt,{width:i-ee.left-ee.right,height:Q,margin:ee,scales:D,brushDirection:te,extent:F,onBrush:P})),ce=a.createElement("div",{key:"main",style:{overflow:"hidden"}},a.createElement(ne,Object.assign({},re)));return a.createElement("div",{className:"minimap-chart"+(c?" "+c:"")},_?ae:ce,_?ce:ae)}rt.displayName="ScatterplotMatrix",at.displayName="MinimapChart",exports.AreaChart=Ye,exports.BubbleChart=Ue,exports.ConnectedScatterplot=Ve,exports.Heatmap=Ze,exports.LineChart=Ge,exports.MinimapChart=at,exports.Scatterplot=qe,exports.ScatterplotMatrix=rt,exports.StackedAreaChart=Xe,exports.StreamXYFrame=ne;
1
+ "use strict";const e=require("react"),t=require("d3-brush"),n=require("d3-selection"),o=require("d3-scale"),s=require("d3-array"),i=require("d3-hierarchy"),r=require("d3-scale-chromatic");function l(e){if(e&&e.__esModule)return e;const t=Object.create(null);if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}return t.default=e,Object.freeze(t)}const a=l(e),c=5e3;class u{constructor(e){this.lastBoundedData=null,this.chunkTimer=0,this.callback=e}clearLastData(){this.lastBoundedData=null,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0)}setBoundedData(e){if(this.lastBoundedData=e,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),5e3>=e.length)return void this.callback({inserts:e,bounded:!0});this.callback({inserts:e.slice(0,c),bounded:!0,totalSize:e.length});let t=c;const n=()=>{if(t>=e.length)return;if(e!==this.lastBoundedData)return;const o=Math.min(t+c,e.length);this.callback({inserts:e.slice(t,o),bounded:!1}),t=o,this.chunkTimer=e.length>t?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}push(e){this.callback({inserts:[e],bounded:!1})}pushMany(e){0!==e.length&&this.callback({inserts:e,bounded:!1})}clear(){this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.lastBoundedData=null}}class h{constructor(e){if(this._capacity=e,this.head=0,this._size=0,1>e)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){const t=[];for(const n of e){const e=this.push(n);void 0!==e&&t.push(e)}return t}get(e){if(e>=0&&this._size>e)return this.buffer[(this.head-this._size+e+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let e=0;const t=this;return{next:()=>t._size>e?{done:!1,value:t.get(e++)}:{done:!0,value:void 0}}}toArray(){const e=[];for(const t of this)e.push(t);return e}resize(e){if(1>e)throw Error("RingBuffer capacity must be at least 1");const t=this.toArray(),n=[];for(;t.length>e;)n.push(t.shift());this._capacity=e,this.buffer=Array(e),this.head=0,this._size=0;for(const e of t)this.push(e);return n}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}}class d{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isNaN(e)||(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}evict(e){e!==this._min&&e!==this._max||(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(const n of e){const e=t?t(n):n;Number.isNaN(e)||(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}}function f(e,t,n,o,s){const i=new Map;for(const r of e){const e=t(r),l=n(r);if(null==e||null==l||Number.isNaN(e)||Number.isNaN(l))continue;const a=Math.floor(e/o)*o;let c=i.get(a);if(c||(c={start:a,end:a+o,total:0,categories:new Map},i.set(a,c)),c.total+=l,s){const e=s(r);c.categories.set(e,(c.categories.get(e)||0)+l)}}return i}function p(e,t,n,o,s,i){const r=[],l=[];for(const s of e){const e=n(s),i=o(s);null==e||null==i||Number.isNaN(e)||Number.isNaN(i)||(r.push([t.x(e),t.y(i)]),l.push(i))}return{type:"line",path:r,rawValues:l,style:s,datum:e,group:i}}function m(e,t,n,o,s,i,r,l){const a=[],c=[];for(const i of e){const e=n(i),r=o(i);if(null==e||null==r||Number.isNaN(e)||Number.isNaN(r))continue;const u=t.x(e);a.push([u,t.y(r)]);const h=l?l(i):s;c.push([u,t.y(h)])}return{type:"area",topPath:a,bottomPath:c,style:i,datum:e,group:r}}function y(e,t,n,o,s,i,r){const l=n(e),a=o(e);if(null==l||null==a||Number.isNaN(l)||Number.isNaN(a))return null;const c={type:"point",x:t.x(l),y:t.y(a),r:s,style:i,datum:e};return void 0!==r&&(c.pointId=r),c}function g(e,t,n,o,s,i,r){return{type:"rect",x:e,y:t,w:n,h:o,style:s,datum:i,group:r}}function b(e,t,n,o,s,i){return{type:"heatcell",x:e,y:t,w:n,h:o,fill:s,datum:i}}function v(e,t){if("function"==typeof e)return t=>+e(t);const n=e||t;return e=>+e[n]}function x(e,t){return"function"==typeof e?e:e?t=>t[e]+"":void 0}class w{constructor(e){this.xExtent=new d,this.yExtent=new d,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.lastIngestTime=0,this.scales=null,this.scene=[],this.version=0,this.config=e,this.buffer=new h(e.windowSize),this.growingCap=e.windowSize,["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode?(this.getX=v(e.timeAccessor||e.xAccessor,"time"),this.getY=v(e.valueAccessor||e.yAccessor,"value")):(this.getX=v(e.xAccessor,"x"),this.getY=v(e.yAccessor,"y")),this.getGroup=x(e.groupAccessor),this.getCategory=x(e.categoryAccessor),this.getSize=e.sizeAccessor?v(e.sizeAccessor,"size"):void 0,this.getColor=x(e.colorAccessor),this.getBounds=e.boundsAccessor?v(e.boundsAccessor,"bounds"):void 0,this.getY0=e.y0Accessor?v(e.y0Accessor,"y0"):void 0,this.getPointId=x(e.pointIdAccessor),"candlestick"===e.chartType&&(this.getOpen=v(e.openAccessor,"open"),this.getHigh=v(e.highAccessor,"high"),this.getLow=v(e.lowAccessor,"low"),this.getClose=v(e.closeAccessor,"close")),e.pulse&&(this.timestampBuffer=new h(e.windowSize))}ingest(e){const t="undefined"!=typeof performance?performance.now():Date.now();if(this.lastIngestTime=t,e.bounded){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const n=e.totalSize||e.inserts.length;n>this.buffer.capacity&&(this.buffer.resize(n),this.timestampBuffer&&n>this.timestampBuffer.capacity&&this.timestampBuffer.resize(n));for(const n of e.inserts)this.buffer.push(n),this.timestampBuffer&&this.timestampBuffer.push(t),this.xExtent.push(this.getX(n)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.push(this.getHigh(n)),this.yExtent.push(this.getLow(n))):(this.yExtent.push(this.getY(n)),this.getY0&&this.yExtent.push(this.getY0(n)))}else for(const n of e.inserts){"growing"===this.config.windowMode&&this.buffer.full&&(this.growingCap*=2,this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap));const e=this.buffer.push(n);this.timestampBuffer&&this.timestampBuffer.push(t),this.xExtent.push(this.getX(n)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.push(this.getHigh(n)),this.yExtent.push(this.getLow(n))):(this.yExtent.push(this.getY(n)),this.getY0&&this.yExtent.push(this.getY0(n))),null!=e&&(this.xExtent.evict(this.getX(e)),"candlestick"===this.config.chartType&&this.getHigh&&this.getLow?(this.yExtent.evict(this.getHigh(e)),this.yExtent.evict(this.getLow(e))):this.yExtent.evict(this.getY(e)))}return!0}computeScene(e){var t,n,s,i,r,l;const{config:a,buffer:c}=this;if(this.xExtent.dirty&&this.xExtent.recalculate(c,this.getX),this.yExtent.dirty)if("candlestick"===a.chartType&&this.getHigh&&this.getLow){this.yExtent.clear();for(const e of c)this.yExtent.push(this.getHigh(e)),this.yExtent.push(this.getLow(e))}else this.yExtent.recalculate(c,this.getY);const u=this.xExtent.extent,h=this.yExtent.extent;let d=a.xExtent?[null!==(t=a.xExtent[0])&&void 0!==t?t:u[0],null!==(n=a.xExtent[1])&&void 0!==n?n:u[1]]:u,p=a.yExtent?[null!==(s=a.yExtent[0])&&void 0!==s?s:h[0],null!==(i=a.yExtent[1])&&void 0!==i?i:h[1]]:h;const m=a.yExtent&&null!=a.yExtent[0]&&null!=a.yExtent[1];if("stackedarea"===a.chartType&&!m&&c.size>0)if(a.normalize)p=[0,1+a.extentPadding];else{const e=c.toArray(),t=this.groupData(e),n=new Map;for(const e of t)for(const t of e.data){const e=this.getX(t),o=this.getY(t);null==e||null==o||Number.isNaN(e)||Number.isNaN(o)||n.set(e,(n.get(e)||0)+o)}let o=0;for(const e of n.values())e>o&&(o=e);p=[0,o+(o>0?o*a.extentPadding:1)]}else if("bar"===a.chartType&&a.binSize&&!m&&c.size>0){const[,e]=function(e,t,n,o,s){const i=f(e,t,n,o,s);if(0===i.size)return[0,0];let r=0;for(const e of i.values())e.total>r&&(r=e.total);return[0,r]}(c,this.getX,this.getY,a.binSize,this.getCategory);p=[0,e+e*a.extentPadding]}else if("waterfall"===a.chartType&&!m&&c.size>0){const[e,t]=function(e,t){let n=0,o=0,s=0;for(const i of e){const e=t(i);null==e||Number.isNaN(e)||(s+=e,n>s&&(n=s),s>o&&(o=s))}return[n,o]}(c,this.getY),n=t-e,o=n>0?n*a.extentPadding:1;p=[Math.min(0,e-Math.abs(o)),Math.max(0,t+Math.abs(o))]}else if(!m&&p[0]!==1/0){if(this.getBounds){const e=c.toArray();for(const t of e){const e=this.getY(t),n=this.getBounds(t);null!=e&&!Number.isNaN(e)&&n&&(e+n>p[1]&&(p[1]=e+n),p[0]>e-n&&(p[0]=e-n))}}const e=p[1]-p[0],t=e>0?e*a.extentPadding:1,n=null===(r=a.yExtent)||void 0===r?void 0:r[0],o=null===(l=a.yExtent)||void 0===l?void 0:l[1];p=[null!=n?p[0]:p[0]-t,null!=o?p[1]:p[1]+t]}if(d[0]!==1/0&&d[1]!==-1/0||(d=[0,1]),p[0]!==1/0&&p[1]!==-1/0||(p=[0,1]),void 0!==a.arrowOfTime)if("x"==("up"===(y=a.arrowOfTime)||"down"===y?"y":"x")){const t="right"===a.arrowOfTime?[0,e.width]:[e.width,0];this.scales={x:o.scaleLinear().domain(d).range(t),y:o.scaleLinear().domain(p).range([e.height,0])}}else{const t="down"===a.arrowOfTime?[0,e.height]:[e.height,0];this.scales={x:o.scaleLinear().domain(p).range([0,e.width]),y:o.scaleLinear().domain(d).range(t)}}else this.scales={x:o.scaleLinear().domain(d).range([0,e.width]),y:o.scaleLinear().domain(p).range([e.height,0])};var y;this.config.transition&&this.scene.length>0&&this.snapshotPositions();const g=c.toArray();this.scene=this.buildSceneNodes(e),this.config.decay&&this.applyDecay(this.scene,g),this.config.pulse&&this.applyPulse(this.scene,g),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++}buildSceneNodes(e){const{config:t,buffer:n,scales:o}=this;if(!o||0===n.size)return[];const s=n.toArray();switch(t.chartType){case"line":return this.buildLineScene(s);case"area":return this.buildAreaScene(s);case"stackedarea":return this.buildStackedAreaScene(s);case"scatter":case"bubble":return this.buildPointScene(s);case"heatmap":return this.buildHeatmapScene(s,e);case"bar":return this.buildBarScene(s);case"swarm":return this.buildSwarmScene(s);case"waterfall":return this.buildWaterfallScene(s,e);case"candlestick":return this.buildCandlestickScene(s,e);default:return[]}}buildLineScene(e){var t;const n=this.groupData(e),o=[],s=null===(t=this.config.annotations)||void 0===t?void 0:t.filter(e=>"threshold"===e.type&&e.color).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(this.getBounds)for(const e of n){const t=this.buildBoundsForGroup(e.data,e.key);t&&o.push(t)}for(const e of n){const t=this.resolveLineStyle(e.key,e.data[0]),n=p(e.data,this.scales,this.getX,this.getY,t,e.key);s&&s.length>0&&(n.colorThresholds=s),o.push(n)}return o}buildAreaScene(e){const t=this.groupData(e),n=[],o=this.scales.y.domain()[0];for(const e of t){const t=this.resolveAreaStyle(e.key,e.data[0]),s=m(e.data,this.scales,this.getX,this.getY,o,t,e.key,this.getY0);this.config.gradientFill&&(s.fillGradient=this.config.gradientFill),n.push(s)}return n}buildStackedAreaScene(e){const t=this.groupData(e);return t.sort((e,t)=>t.key>e.key?-1:e.key>t.key?1:0),function(e,t,n,o,s,i){var r;const l=new Set;for(const t of e)for(const e of t.data){const t=n(e);null==t||Number.isNaN(t)||l.add(t)}const a=Array.from(l).sort((e,t)=>e-t),c=new Map;for(const t of e){const e=new Map;for(const s of t.data){const t=n(s),i=o(s);null==t||null==i||Number.isNaN(t)||Number.isNaN(i)||e.set(t,(e.get(t)||0)+i)}c.set(t.key,e)}let u;if(i){u=new Map;for(const t of a){let n=0;for(const o of e)n+=(null===(r=c.get(o.key))||void 0===r?void 0:r.get(t))||0;u.set(t,n||1)}}const h=[],d=new Map;for(const e of a)d.set(e,0);for(const n of e){const e=c.get(n.key),o=[],r=[];for(const n of a){let s=e.get(n)||0;const l=d.get(n);i&&(s/=u.get(n));const a=t.x(n);r.push([a,t.y(l)]),o.push([a,t.y(l+s)]),d.set(n,l+s)}h.push({type:"area",topPath:o,bottomPath:r,style:s(n.key,n.data[0]),datum:n.data,group:n.key})}return h}(t,this.scales,this.getX,this.getY,(e,t)=>this.resolveAreaStyle(e,t),this.config.normalize)}buildPointScene(e){const t=[],n="bubble"===this.config.chartType?10:5,o=this.config.sizeRange||[3,15];let s=null;if(this.getSize&&!this.config.pointStyle){const t=e.map(e=>this.getSize(e)).filter(e=>null!=e&&!Number.isNaN(e));if(t.length>0){const e=Math.min(...t),n=Math.max(...t);s=t=>e===n?(o[0]+o[1])/2:o[0]+(t-e)/(n-e)*(o[1]-o[0])}}let i=null;if(this.getColor&&!this.config.pointStyle){const t=new Set;for(const n of e){const e=this.getColor(n);e&&t.add(e)}const n=Array.isArray(this.config.colorScheme)?this.config.colorScheme:["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"];i=new Map;let o=0;for(const e of t)i.set(e,n[o%n.length]),o++}for(const o of e){let e=this.config.pointStyle?this.config.pointStyle(o):{fill:"#4e79a7",opacity:.8},r=e.r||n;if(s&&this.getSize){const e=this.getSize(o);null==e||Number.isNaN(e)||(r=s(e))}if(i&&this.getColor){const t=this.getColor(o);t&&i.has(t)&&(e=Object.assign(Object.assign({},e),{fill:i.get(t)}))}const l=this.getPointId?this.getPointId(o)+"":void 0,a=y(o,this.scales,this.getX,this.getY,r,e,l);a&&t.push(a)}return t}buildHeatmapScene(e,t){const n=[];if(this.config.heatmapAggregation)return this.buildStreamingHeatmapScene(e,t);const o=v(this.config.valueAccessor,"value"),s=new Set,i=new Set;for(const t of e)s.add(this.getX(t)),i.add(this.getY(t));const r=Array.from(s).sort((e,t)=>e-t),l=Array.from(i).sort((e,t)=>e-t);if(0===r.length||0===l.length)return n;const a=t.width/r.length,c=t.height/l.length,u=new Map;for(const t of e){const e=`${this.getX(t)}_${this.getY(t)}`;u.set(e,{val:o(t),datum:t})}let h=1/0,d=-1/0;for(const{val:e}of u.values())h>e&&(h=e),e>d&&(d=e);const f=d-h||1;for(let e=0;r.length>e;e++)for(let t=0;l.length>t;t++){const o=u.get(`${r[e]}_${l[t]}`);if(!o)continue;const s=(o.val-h)/f;n.push(b(e*a,(l.length-1-t)*c,a,c,`rgb(${Math.round(220-180*s)},${Math.round(220-100*s)},${Math.round(255-50*s)})`,o.datum))}return n}buildStreamingHeatmapScene(e,t){var n,o,s;const i=[],r=null!==(n=this.config.heatmapXBins)&&void 0!==n?n:20,l=null!==(o=this.config.heatmapYBins)&&void 0!==o?o:20,a=null!==(s=this.config.heatmapAggregation)&&void 0!==s?s:"count",c=v(this.config.valueAccessor,"value");if(!this.scales||0===e.length)return i;const[u,h]=this.scales.x.domain(),[d,f]=this.scales.y.domain(),p=(h-u||1)/r,m=(f-d||1)/l,y=new Map;for(const t of e){const e=this.getX(t),n=this.getY(t),o=Math.min(Math.floor((e-u)/p),r-1),s=Math.min(Math.floor((n-d)/m),l-1);if(0>o||0>s)continue;const i=`${o}_${s}`;let a=y.get(i);a||(a={sum:0,count:0,data:[]},y.set(i,a)),a.count++,a.sum+=c(t),a.data.push(t)}let g=1/0,x=-1/0;const w=new Map;for(const[e,t]of y){let n;switch(a){case"sum":n=t.sum;break;case"mean":n=t.count>0?t.sum/t.count:0;break;default:n=t.count}w.set(e,n),g>n&&(g=n),n>x&&(x=n)}const k=x-g||1,A=t.width/r,E=t.height/l;for(const[e,t]of w){const[n,o]=e.split("_"),s=+n,r=+o,a=(t-g)/k,c=`rgb(${Math.round(220-180*a)},${Math.round(220-100*a)},${Math.round(255-50*a)})`,u=y.get(e);i.push(b(s*A,(l-1-r)*E,A,E,c,{xi:s,yi:r,value:t,count:u.count,sum:u.sum,data:u.data}))}return i}buildBarScene(e){var t;if(!this.config.binSize)return[];const n=f(e,this.getX,this.getY,this.config.binSize,this.getCategory);if(0===n.size)return[];let o=null;if(this.getCategory){const e=new Set;for(const t of n.values())for(const n of t.categories.keys())e.add(n);const t=this.config.barColors?Object.keys(this.config.barColors):[],s=new Set(t),i=Array.from(e).filter(e=>!s.has(e)).sort();o=[...t.filter(t=>e.has(t)),...i]}const s=[],i=this.scales,[r,l]=i.x.domain();for(const e of n.values()){const n=Math.max(e.start,r),a=Math.min(e.end,l);if(n>=a)continue;const c=i.x(n),u=i.x(a),h=Math.min(c,u)+.5,d=Math.max(c,u)-.5-h;if(d>0)if(o&&e.categories.size>0){let n=0;for(const r of o){const o=e.categories.get(r)||0;if(0===o)continue;const l=i.y(n),a=i.y(n+o);s.push(g(h,Math.min(l,a),d,Math.abs(l-a),{fill:(null===(t=this.config.barColors)||void 0===t?void 0:t[r])||"#4e79a7"},{binStart:e.start,binEnd:e.end,total:e.total,category:r,categoryValue:o},r)),n+=o}}else{const t=i.y(0),n=i.y(e.total);s.push(g(h,Math.min(t,n),d,Math.abs(t-n),{fill:"#007bff"},{binStart:e.start,binEnd:e.end,total:e.total}))}}return s}buildSwarmScene(e){var t,n,o,s;const i=[],r=this.config.swarmStyle||{},l=null!==(t=r.radius)&&void 0!==t?t:3,a=null!==(n=r.fill)&&void 0!==n?n:"#007bff",c=null!==(o=r.opacity)&&void 0!==o?o:.7,u=r.stroke,h=r.strokeWidth;for(const t of e){const e=this.getX(t),n=this.getY(t);if(null==n||Number.isNaN(n))continue;const o=this.scales.x(e),r=this.scales.y(n);let d=a;if(this.getCategory){const e=this.getCategory(t);d=(null===(s=this.config.barColors)||void 0===s?void 0:s[e])||d}const f={type:"point",x:o,y:r,r:l,style:{fill:d,opacity:c,stroke:u,strokeWidth:h},datum:t};this.getPointId&&(f.pointId=this.getPointId(t)+""),i.push(f)}return i}buildWaterfallScene(e,t){var n,o,s;const i=[],r=this.scales,l=this.config.waterfallStyle,a=e.filter(e=>{const t=this.getY(e);return null!=t&&!Number.isNaN(t)});if(0===a.length)return i;const c=null!==(n=null==l?void 0:l.positiveColor)&&void 0!==n?n:"#28a745",u=null!==(o=null==l?void 0:l.negativeColor)&&void 0!==o?o:"#dc3545",h=null!==(s=null==l?void 0:l.gap)&&void 0!==s?s:1,d=null==l?void 0:l.stroke,f=null==l?void 0:l.strokeWidth;let p=0;for(let e=0;a.length>e;e++){const n=a[e],o=this.getX(n),s=this.getY(n),m=p+s;let y;y=a.length-1>e?this.getX(a[e+1])-o:e>0?o-this.getX(a[e-1]):0;const b=r.x(o),v=0!==y?r.x(o+y):b+t.width/10,x=Math.min(b,v)+h/2,w=Math.max(b,v)-h/2-x;if(0>=w){p=m;continue}const k=r.y(p),A=r.y(m);i.push(g(x,Math.min(k,A),w,Math.abs(k-A),{fill:0>s?u:c,stroke:d,strokeWidth:f},Object.assign(Object.assign({},n),{baseline:p,cumEnd:m,delta:s,_connectorStroke:null==l?void 0:l.connectorStroke,_connectorWidth:null==l?void 0:l.connectorWidth}))),p=m}return i}buildCandlestickScene(e,t){if(!(this.getOpen&&this.getHigh&&this.getLow&&this.getClose&&this.scales))return[];const n=[],o=this.config.candlestickStyle||{},s=o.upColor||"#28a745",i=o.downColor||"#dc3545",r=o.wickColor||"#333",l=o.wickWidth||1,a=e.map(e=>this.getX(e)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);let c=o.bodyWidth||6;if(!o.bodyWidth&&a.length>1){let e=1/0;for(let t=1;a.length>t;t++){const n=Math.abs(this.scales.x(a[t])-this.scales.x(a[t-1]));n>0&&e>n&&(e=n)}e!==1/0&&(c=Math.max(2,Math.min(.6*e,20)))}for(const t of e){const e=this.getX(t);if(null==e||Number.isNaN(e))continue;const o=this.getOpen(t),a=this.getHigh(t),u=this.getLow(t),h=this.getClose(t);if([o,a,u,h].some(e=>null==e||Number.isNaN(e)))continue;const d=h>=o;n.push({type:"candlestick",x:this.scales.x(e),openY:this.scales.y(o),closeY:this.scales.y(h),highY:this.scales.y(a),lowY:this.scales.y(u),bodyWidth:c,upColor:s,downColor:i,wickColor:r,wickWidth:l,isUp:d,datum:t})}return n}buildBoundsForGroup(e,t){if(!this.getBounds||!this.scales)return null;const n=[],o=[];for(const t of e){const e=this.getX(t),s=this.getY(t);if(null==e||null==s||Number.isNaN(e)||Number.isNaN(s))continue;const i=this.getBounds(t),r=this.scales.x(e);if(i&&0!==i)n.push([r,this.scales.y(s+i)]),o.push([r,this.scales.y(s-i)]);else{const e=this.scales.y(s);n.push([r,e]),o.push([r,e])}}return 2>n.length?null:{type:"area",topPath:n,bottomPath:o,style:this.resolveBoundsStyle(t,e[0]),datum:e,group:t,interactive:!1}}resolveBoundsStyle(e,t){const n=this.config.boundsStyle;return"function"==typeof n?n(t||{},e):n&&"object"==typeof n?n:{fill:this.resolveLineStyle(e,t).stroke||"#4e79a7",fillOpacity:.2,stroke:"none"}}computeDecayOpacity(e,t){var n,o,s;const i=this.config.decay;if(!i||1>=t)return 1;const r=null!==(n=i.minOpacity)&&void 0!==n?n:.1,l=t-1-e;switch(i.type){case"linear":return r+(1-l/(t-1))*(1-r);case"exponential":{const e=null!==(o=i.halfLife)&&void 0!==o?o:t/2;return r+Math.pow(.5,l/e)*(1-r)}case"step":return(null!==(s=i.stepThreshold)&&void 0!==s?s:.5*t)>l?1:r;default:return 1}}applyDecay(e,t){var n,o;if(!this.config.decay)return;const s=t.length;if(1>=s)return;const i=new Map;for(let e=0;t.length>e;e++)i.set(t[e],e);for(const t of e){if("line"===t.type||"area"===t.type)continue;const e=i.get(t.datum);if(null==e)continue;const r=this.computeDecayOpacity(e,s);if("heatcell"===t.type)t.style={opacity:r};else if("candlestick"===t.type)t._decayOpacity=r;else{const e=null!==(o=null===(n=t.style)||void 0===n?void 0:n.opacity)&&void 0!==o?o:1;t.style=Object.assign(Object.assign({},t.style),{opacity:e*r})}}}computePulseIntensity(e,t){var n;const o=this.config.pulse;if(!o)return 0;const s=null!==(n=o.duration)&&void 0!==n?n:500,i=t-e;return s>i?1-i/s:0}applyPulse(e,t){var n,o;if(!this.config.pulse||!this.timestampBuffer)return;const s="undefined"!=typeof performance?performance.now():Date.now(),i=null!==(n=this.config.pulse.color)&&void 0!==n?n:"rgba(255,255,255,0.6)",r=null!==(o=this.config.pulse.glowRadius)&&void 0!==o?o:4,l=new Map;for(let e=0;t.length>e;e++)l.set(t[e],e);for(const t of e){if("line"===t.type||"area"===t.type)continue;const e=l.get(t.datum);if(null==e)continue;const n=this.timestampBuffer.get(e);if(null==n)continue;const o=this.computePulseIntensity(n,s);o>0&&(t._pulseIntensity=o,t._pulseColor=i,t._pulseGlowRadius=r)}}get hasActivePulses(){var e;if(!this.config.pulse||!this.timestampBuffer||0===this.timestampBuffer.size)return!1;const t="undefined"!=typeof performance?performance.now():Date.now(),n=null!==(e=this.config.pulse.duration)&&void 0!==e?e:500,o=this.timestampBuffer.peek();return null!=o&&n>t-o}snapshotPositions(){this.prevPositionMap.clear();for(let e=0;this.scene.length>e;e++){const t=this.scene[e],n=this.getNodeIdentity(t,e);n&&("point"===t.type?this.prevPositionMap.set(n,{x:t.x,y:t.y,r:t.r}):"rect"===t.type||"heatcell"===t.type?this.prevPositionMap.set(n,{x:t.x,y:t.y,w:t.w,h:t.h}):"candlestick"===t.type&&this.prevPositionMap.set(n,{x:t.x,y:t.openY}))}}getNodeIdentity(e,t){var n,o,s,i;switch(e.type){case"point":return`p:${void 0===e.datum?t:this.getX(e.datum)}_${this.getY(e.datum)}`;case"rect":return`r:${e.group||""}:${null!==(i=null!==(o=null===(n=e.datum)||void 0===n?void 0:n.binStart)&&void 0!==o?o:null===(s=e.datum)||void 0===s?void 0:s.category)&&void 0!==i?i:t}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return"c:"+this.getX(e.datum);default:return null}}startTransition(){var e,t,n,o,s,i;if(!this.config.transition||0===this.prevPositionMap.size)return;const r=null!==(e=this.config.transition.duration)&&void 0!==e?e:300;let l=!1;for(let e=0;this.scene.length>e;e++){const r=this.scene[e],a=this.getNodeIdentity(r,e);if(!a)continue;const c=this.prevPositionMap.get(a);if(c)if("point"===r.type){const e={x:r.x,y:r.y,r:r.r};c.x===e.x&&c.y===e.y||(r._targetX=e.x,r._targetY=e.y,r._targetR=e.r,r.x=c.x,r.y=c.y,r.r=null!==(t=c.r)&&void 0!==t?t:r.r,l=!0)}else if("rect"===r.type){const e={x:r.x,y:r.y,w:r.w,h:r.h};c.x===e.x&&c.y===e.y&&c.w===e.w&&c.h===e.h||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.h,r.x=c.x,r.y=c.y,r.w=null!==(n=c.w)&&void 0!==n?n:r.w,r.h=null!==(o=c.h)&&void 0!==o?o:r.h,l=!0)}else if("heatcell"===r.type){const e={x:r.x,y:r.y,w:r.w,h:r.h};c.x===e.x&&c.y===e.y||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.h,r.x=c.x,r.y=c.y,r.w=null!==(s=c.w)&&void 0!==s?s:r.w,r.h=null!==(i=c.h)&&void 0!==i?i:r.h,l=!0)}}l&&(this.activeTransition={startTime:"undefined"!=typeof performance?performance.now():Date.now(),duration:r})}advanceTransition(e){var t;if(!this.activeTransition)return!1;const n=Math.min((e-this.activeTransition.startTime)/this.activeTransition.duration,1),o="linear"===(null===(t=this.config.transition)||void 0===t?void 0:t.easing)?n:1-Math.pow(1-n,3);for(const e of this.scene)if("point"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==e._targetR&&void 0!==n.r&&(e.r=n.r+(e._targetR-n.r)*o)}else if("rect"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==n.w&&(e.w=n.w+(e._targetW-n.w)*o),void 0!==n.h&&(e.h=n.h+(e._targetH-n.h)*o)}else if("heatcell"===e.type){if(void 0===e._targetX)continue;const t=this.getNodeIdentity(e,0);if(!t)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=n.x+(e._targetX-n.x)*o,e.y=n.y+(e._targetY-n.y)*o,void 0!==n.w&&(e.w=n.w+(e._targetW-n.w)*o),void 0!==n.h&&(e.h=n.h+(e._targetH-n.h)*o)}if(n>=1){for(const e of this.scene)if("point"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("heatcell"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}return this.activeTransition=null,!1}return!0}groupData(e){if(!this.getGroup)return[{key:"_default",data:e}];const t=new Map;for(const n of e){const e=this.getGroup(n);t.has(e)||t.set(e,[]),t.get(e).push(n)}return Array.from(t.entries()).map(([e,t])=>({key:e,data:t}))}resolveLineStyle(e,t){const n=this.config.lineStyle;return"function"==typeof n?n(t||{},e):n&&"object"==typeof n?{stroke:n.stroke||"#007bff",strokeWidth:n.strokeWidth||2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity}:{stroke:"#007bff",strokeWidth:2}}resolveAreaStyle(e,t){var n;if(this.config.areaStyle)return this.config.areaStyle(t||{});const o=this.config.lineStyle;return"function"==typeof o?o(t||{},e):o&&"object"==typeof o?{fill:o.fill||o.stroke||"#4e79a7",fillOpacity:null!==(n=o.fillOpacity)&&void 0!==n?n:.7,stroke:o.stroke||"#4e79a7",strokeWidth:o.strokeWidth||2}:{fill:"#4e79a7",fillOpacity:.7,stroke:"#4e79a7",strokeWidth:2}}getData(){return this.buffer.toArray()}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.version++}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}updateConfig(e){Object.assign(this.config,e)}}function k(e,t,n){const o=t-e.x,s=n-e.y,i=Math.sqrt(o*o+s*s);return i>e.r+5?null:{node:e,datum:e.datum,x:e.x,y:e.y,distance:i}}function A(e,t,n){if(0===e.path.length)return null;const o=N(e.path,t);if(0>o)return null;const[s,i]=e.path[o],r=t-s,l=n-i,a=Math.sqrt(r*r+l*l);return{node:e,datum:Array.isArray(e.datum)&&e.datum[o]?e.datum[o]:e.datum,x:s,y:i,distance:a}}function E(e,t,n){return e.x>t||t>e.x+e.w||e.y>n||n>e.y+e.h?null:{node:e,datum:e.datum,x:e.x+e.w/2,y:e.y+e.h/2,distance:0}}function M(e,t,n){return e.x>t||t>e.x+e.w||e.y>n||n>e.y+e.h?null:{node:e,datum:e.datum,x:e.x+e.w/2,y:e.y+e.h/2,distance:0}}function S(e,t,n){const o=e.bodyWidth/2,s=Math.min(e.openY,e.closeY);if(!(e.x-o-3>t||t>e.x+o+3||e.highY-3>n||n>e.lowY+3)){const o=s+Math.max(Math.max(e.openY,e.closeY)-s,1)/2,i=t-e.x,r=n-o;return{node:e,datum:e.datum,x:e.x,y:o,distance:Math.sqrt(i*i+r*r)}}return null}function O(e,t,n){if(0===e.topPath.length)return null;const o=N(e.topPath,t);if(0>o)return null;const[s,i]=e.topPath[o],r=t-s,l=n-i;return{node:e,datum:e.datum,x:s,y:i,distance:Math.sqrt(r*r+l*l)}}function N(e,t){if(0===e.length)return-1;let n=0,o=e.length-1;for(;o>n;){const s=n+o>>1;t>e[s][0]?n=s+1:o=s}return n>0&&Math.abs(e[n][0]-t)>=Math.abs(e[n-1][0]-t)?n-1:n}const L={fill:e=>a.createElement("rect",{style:e,width:20,height:20}),line:e=>a.createElement("line",{style:e,x1:0,y1:0,x2:20,y2:20})};function j(e,t,n,o){let s;return s="function"==typeof n?n(e):(0,L[n])(o(e,t)),s}function C(e){const{legendGroups:t,customClickBehavior:n,title:o="Legend",width:s=100,height:i=20,orientation:r="vertical"}=e,l="vertical"===r?(({legendGroups:e,width:t,customClickBehavior:n})=>{let o=30;const s=[];return e.forEach((e,i)=>{o+=5,s.push(a.createElement("line",{key:"legend-top-line legend-symbol-"+i,stroke:"gray",x1:0,y1:o,x2:t,y2:o})),o+=10,e.label&&(o+=20,s.push(a.createElement("text",{key:"legend-text-"+i,y:o,className:"legend-group-label"},e.label)),o+=10),s.push(a.createElement("g",{key:"legend-group-"+i,className:"legend-item",transform:`translate(0,${o})`},((e,t)=>{const{type:n="fill",styleFn:o,items:s}=e,i=[];let r=0;return s.forEach((e,s)=>{const l=j(e,s,n,o);i.push(a.createElement("g",{key:"legend-item-"+s,transform:`translate(0,${r})`,onClick:t?()=>t(e):void 0,style:{cursor:t?"pointer":"default"}},l,a.createElement("text",{y:15,x:30},e.label))),r+=25}),i})(e,n))),o+=25*e.items.length+10}),s})({legendGroups:t,width:s,customClickBehavior:n}):(({legendGroups:e,title:t,height:n,customClickBehavior:o})=>{let s=0;const i=[],r=!1===t?10:40;return e.forEach((t,l)=>{t.label&&(i.push(a.createElement("text",{key:"legend-text-"+l,transform:`translate(${s},${r}) rotate(90)`,textAnchor:"start",className:"legend-group-label"},t.label)),s+=20);const c=((e,t)=>{const{type:n="fill",styleFn:o,items:s}=e,i=[];let r=0;return s.forEach((e,s)=>{const l=j(e,s,n,o);i.push(a.createElement("g",{key:"legend-item-"+s,transform:`translate(${r},0)`,onClick:t?()=>t(e):void 0,style:{cursor:t?"pointer":"default"}},l,a.createElement("text",{y:15,x:25},e.label))),r+=35,r+=8*e.label.length}),{items:i,offset:r}})(t,o);i.push(a.createElement("g",{key:"legend-group-"+l,className:"legend-item",transform:`translate(${s},${r})`},c.items)),s+=c.offset+5,e[l+1]&&i.push(a.createElement("line",{key:"legend-top-line legend-symbol-"+l,stroke:"gray",x1:s,y1:r-10,x2:s,y2:n+r+10})),s+=15}),a.createElement("g",null,!1!==t&&a.createElement("line",{x1:0,x2:s+10,y1:r-10,y2:r-10,stroke:"gray",className:"title-neatline"}),i)})({legendGroups:t,title:o,height:i,customClickBehavior:n});return a.createElement("g",null,void 0!==o&&a.createElement("text",{className:"legend-title",y:20,x:"horizontal"===r?0:s/2,textAnchor:"horizontal"===r?"start":"middle"},o),l)}function _(e){return"string"==typeof e?{type:e}:e}function W({orient:t,config:n,values:o,scale:i,size:r,length:l}){const c=function(e){var t,n,o,s,i;return{type:e.type,bins:null!==(t=e.bins)&&void 0!==t?t:20,fill:null!==(n=e.fill)&&void 0!==n?n:"#4e79a7",fillOpacity:null!==(o=e.fillOpacity)&&void 0!==o?o:.5,stroke:null!==(s=e.stroke)&&void 0!==s?s:"none",strokeWidth:null!==(i=e.strokeWidth)&&void 0!==i?i:1}}(n),u="top"===t||"bottom"===t,h=e.useMemo(()=>{if(0===o.length)return null;const e=i.domain(),n=r-8;if("boxplot"===c.type){const e=function(e){const t=[...e].sort((e,t)=>e-t),n=t.length;if(0===n)return null;const o=t[Math.floor(.25*n)],s=t[Math.floor(.5*n)],i=t[Math.floor(.75*n)],r=i-o;return{q1:o,median:s,q3:i,whiskerLow:Math.max(t[0],o-1.5*r),whiskerHigh:Math.min(t[n-1],i+1.5*r)}}(o);if(!e)return null;const{q1:s,median:r,q3:l,whiskerLow:h,whiskerHigh:d}=e,f=Math.min(.5*n,20),p=(n-f)/2+4;if(u){const e=i(s),n=i(l),o=i(r),u=i(h),m=i(d),y="top"===t?-1:1,g=0;return a.createElement("g",{"data-testid":"marginal-boxplot-"+t},a.createElement("line",{x1:u,y1:g+y*(p+f/2),x2:m,y2:g+y*(p+f/2),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:u,y1:g+y*p,x2:u,y2:g+y*(p+f),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:m,y1:g+y*p,x2:m,y2:g+y*(p+f),stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("rect",{x:Math.min(e,n),y:"top"===t?g-p-f:g+p,width:Math.abs(n-e),height:f,fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:o,y1:"top"===t?g-p-f:g+p,x2:o,y2:"top"===t?g-p:g+p+f,stroke:c.fill,strokeWidth:2}))}{const e=i(s),n=i(l),o=i(r),u=i(h),m=i(d),y="left"===t?-1:1,g=0;return a.createElement("g",{"data-testid":"marginal-boxplot-"+t},a.createElement("line",{x1:g+y*(p+f/2),y1:u,x2:g+y*(p+f/2),y2:m,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:g+y*p,y1:u,x2:g+y*(p+f),y2:u,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:g+y*p,y1:m,x2:g+y*(p+f),y2:m,stroke:c.fill,strokeWidth:c.strokeWidth}),a.createElement("rect",{x:"left"===t?g-p-f:g+p,y:Math.min(e,n),width:f,height:Math.abs(n-e),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}),a.createElement("line",{x1:"left"===t?g-p-f:g+p,y1:o,x2:"left"===t?g-p:g+p+f,y2:o,stroke:c.fill,strokeWidth:2}))}}const h=s.bin().domain(e).thresholds(c.bins)(o);if(0===h.length)return null;const d=Math.max(...h.map(e=>e.length));if(0===d)return null;if("histogram"===c.type)return a.createElement("g",{"data-testid":"marginal-histogram-"+t},h.map((e,o)=>{if(null==e.x0||null==e.x1)return null;const s=e.length/d*n;if(u){const n=i(e.x0),r=i(e.x1)-i(e.x0);return a.createElement("rect",{key:o,x:n,y:"top"===t?-4-s:4,width:Math.max(r,.5),height:s,fill:c.fill,fillOpacity:c.fillOpacity,stroke:c.stroke,strokeWidth:c.strokeWidth})}{const n=i(e.x0),r=i(e.x1)-i(e.x0);return a.createElement("rect",{key:o,x:"left"===t?-4-s:4,y:Math.min(n,n+r),width:s,height:Math.abs(r),fill:c.fill,fillOpacity:c.fillOpacity,stroke:c.stroke,strokeWidth:c.strokeWidth})}}));if("violin"===c.type){const e=n/2+4,o=[];for(const s of h){if(null==s.x0||null==s.x1)continue;const r=s.length/d*(n/2),l=i((s.x0+s.x1)/2);o.push(u?`${l},${"top"===t?-(e-r):e-r}`:`${"left"===t?-(e-r):e-r},${l}`)}for(let s=h.length-1;s>=0;s--){const r=h[s];if(null==r.x0||null==r.x1)continue;const l=r.length/d*(n/2),a=i((r.x0+r.x1)/2);o.push(u?`${a},${"top"===t?-(e+l):e+l}`:`${"left"===t?-(e+l):e+l},${a}`)}return a.createElement("g",{"data-testid":"marginal-violin-"+t},a.createElement("polygon",{points:o.join(" "),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}))}if("ridgeline"===c.type){const e=[];if(u){const o=0,s=null!=h[0].x0?i(h[0].x0):0;e.push(`M${s},${o}`);for(const o of h){if(null==o.x0||null==o.x1)continue;const s=o.length/d*n,r=i((o.x0+o.x1)/2);e.push(`L${r},${"top"===t?-s-4:s+4}`)}const r=null!=h[h.length-1].x1?i(h[h.length-1].x1):l;e.push(`L${r},${o}`),e.push("Z")}else{const o=0,s=null!=h[0].x0?i(h[0].x0):0;e.push(`M${o},${s}`);for(const o of h){if(null==o.x0||null==o.x1)continue;const s=o.length/d*n,r=i((o.x0+o.x1)/2);e.push(`L${"left"===t?-s-4:s+4},${r}`)}const r=null!=h[h.length-1].x1?i(h[h.length-1].x1):l;e.push(`L${o},${r}`),e.push("Z")}return a.createElement("g",{"data-testid":"marginal-ridgeline-"+t},a.createElement("path",{d:e.join(" "),fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none"===c.stroke?c.fill:c.stroke,strokeWidth:c.strokeWidth}))}return null},[o,i,c,r,l,t,u,4]);return h?a.createElement("g",{className:"marginal-"+t,"data-testid":"marginal-"+t},h):null}function B(e,t=120,n=8){if(!e)return[];const o=Math.max(1,Math.floor(t/n)),s=e.split(/\s+/),i=[];let r="";for(const e of s)r&&r.length+1+e.length>o?(i.push(r),r=e):r=r?`${r} ${e}`:e;return r&&i.push(r),i}function $(e,t,n,o){return"curly"===e?o?`M0,0 C${.6*n},0 ${.4*n},${t/2} ${n},${t/2} C${.4*n},${t/2} ${.6*n},${t} 0,${t}`:`M0,0 C0,${.6*n} ${t/2},${.4*n} ${t/2},${n} C${t/2},${.4*n} ${t},${.6*n} ${t},0`:o?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function H(e){const{x:t=0,y:n=0,dx:o,dy:s,nx:i,ny:r,note:l,connector:c,subject:u,type:h,color:d,className:f,disable:p,events:m={},"data-testid":y}=e,g=new Set(Array.isArray(p)?p:[]);let b=o||0,v=s||0;null!=i&&(b=i-t),null!=r&&(v=r-n);const x="string"==typeof h?h:"label";if("bracket"===x&&u&&0===b&&0===v)if(void 0!==u.width){b=u.width/2;const e=u.depth||30;v=e+(0>e?-5:5)}else if(void 0!==u.height){const e=u.depth||30;b=e+(0>e?-5:5),v=u.height/2}return a.createElement("g",Object.assign({className:("annotation "+(f||"")).trim(),transform:`translate(${t},${n})`,"data-testid":y},m),!g.has("connector")&&function(e,t,n,o,s,i){const r=[];let l=0,c=0;if("callout-circle"!==s&&"label"!==s||!(null==i?void 0:i.radius)){if("callout-rect"===s&&i){const n=i.width||0,o=i.height||0;if(n>0||o>0){const s=n/2,i=o/2,r=e-s,a=t-i;if(0!==r||0!==a){const e=Math.abs(r),t=Math.abs(a),u=n/2,h=o/2,d=e*h>t*u?u/e:h/t;l=s+r*d,c=i+a*d}}}else if("bracket"===s&&i){const e=i.width,t=i.height,n=i.depth||30;void 0!==e?(l=e/2,c=n):void 0!==t&&(l=n,c=t/2)}}else{const n=(i.radius||0)+(i.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const o=Math.atan2(t,e);l=Math.cos(o)*n,c=Math.sin(o)*n}}if(Math.sqrt(Math.pow(e-l,2)+Math.pow(t-c,2))>.5&&(r.push(a.createElement("line",{key:"connector-line",x1:l,y1:c,x2:e,y2:t,stroke:o||"currentColor"})),"arrow"===(null==n?void 0:n.end))){const n=10,s=16/180*Math.PI,i=Math.atan2(t-c,e-l);r.push(a.createElement("path",{key:"connector-arrow",d:`M${l},${c}L${l+n*Math.cos(i+s)},${c+n*Math.sin(i+s)}L${l+n*Math.cos(i-s)},${c+n*Math.sin(i-s)}Z`,fill:o||"currentColor",stroke:"none"}))}return a.createElement("g",{className:"annotation-connector"},r)}(b,v,c,d,x,u),!g.has("subject")&&function(e,t,n,o,s){var i;const r=[];switch(e){case"callout-circle":{const e=((null==t?void 0:t.radius)||0)+((null==t?void 0:t.radiusPadding)||0);e>0&&r.push(a.createElement("circle",{key:"subject-circle",r:e,fill:"none",stroke:n||"currentColor"}));break}case"callout-rect":{const e=(null==t?void 0:t.width)||0,o=(null==t?void 0:t.height)||0;(e>0||o>0)&&r.push(a.createElement("rect",{key:"subject-rect",width:e,height:o,fill:"none",stroke:n||"currentColor"}));break}case"callout-custom":(null==t?void 0:t.custom)&&r.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=o||0,i=s||0;if(void 0!==(null==t?void 0:t.x)){const o=(t.x||0)-e;r.push(a.createElement("line",{key:"threshold-line",x1:o,y1:(t.y1||0)-i,x2:o,y2:(t.y2||0)-i,stroke:n||"currentColor",strokeDasharray:"5,5"}))}else if(void 0!==(null==t?void 0:t.y)){const o=(t.y||0)-i;r.push(a.createElement("line",{key:"threshold-line",x1:(t.x1||0)-e,y1:o,x2:(t.x2||0)-e,y2:o,stroke:n||"currentColor",strokeDasharray:"5,5"}))}else void 0!==(null==t?void 0:t.x1)||void 0!==(null==t?void 0:t.x2)?r.push(a.createElement("line",{key:"threshold-line",x1:(t.x1||0)-e,y1:0,x2:(t.x2||0)-e,y2:0,stroke:n||"currentColor",strokeDasharray:"5,5"})):void 0===(null==t?void 0:t.y1)&&void 0===(null==t?void 0:t.y2)||r.push(a.createElement("line",{key:"threshold-line",x1:0,y1:(t.y1||0)-i,x2:0,y2:(t.y2||0)-i,stroke:n||"currentColor",strokeDasharray:"5,5"}));break}case"bracket":{const e=null!==(i=null==t?void 0:t.width)&&void 0!==i?i:null==t?void 0:t.height;void 0!==e&&r.push(a.createElement("path",{key:"bracket-path",d:$((null==t?void 0:t.type)||"curly",e,(null==t?void 0:t.depth)||30,void 0===(null==t?void 0:t.width)),fill:"none",stroke:n||"currentColor"}));break}}return a.createElement("g",{className:"annotation-subject"},r)}(x,u,d,t,n),!g.has("note")&&function(e,t,n,o){if(!e)return a.createElement("g",{className:"annotation-note"});const{label:s,title:i,orientation:r,align:l,wrap:c=120,noWrap:u}=e;if(!s&&!i)return a.createElement("g",{className:"annotation-note"});let h=r;h||(h=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let d=l;d&&"dynamic"!==d||(d="topBottom"===h?0>t?"right":"left":0>n?"bottom":"top");let f="start";"topBottom"===h?"right"===d?f="end":"middle"===d&&(f="middle"):f=0>t?"end":"start";const p=16,m=i?u?[i]:B(i,c):[],y=s?u?[s]:B(s,c):[],g="leftRight"===h?"end"===f?-4:4:0;let b=0;const v=[];m.length>0&&(v.push(a.createElement("text",{key:"annotation-note-title",className:"annotation-note-title",fill:o||void 0,textAnchor:f,fontWeight:"bold"},m.map((e,t)=>a.createElement("tspan",{key:t,x:g,dy:0===t?0:p},e)))),b=m.length*p),y.length>0&&v.push(a.createElement("text",{key:"annotation-note-label",className:"annotation-note-label",fill:o||void 0,textAnchor:f,y:b},y.map((e,t)=>a.createElement("tspan",{key:t,x:g,dy:0===t?0:p},e))));let x=null;if((i||s)&&(0!==t||0!==n))if("topBottom"===h){const e=Math.min(c,120);let t=0,n=e;"end"===f?(t=-e,n=0):"middle"===f&&(t=-e/2,n=e/2),x=a.createElement("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:o||"currentColor"})}else{const e=(m.length+y.length)*p+(y.length>0?p:0);let t=0,n=e;"bottom"===d?(t=-e,n=0):"middle"===d&&(t=-e/2,n=e/2),x=a.createElement("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:o||"currentColor"})}const w=Math.max(0,m.length+y.length-1)*p;let k=0;return"topBottom"===h?k=0>n?-(w+2):18:"leftRight"===h&&(k="middle"===d?-(w+p+(y.length>0&&m.length>0?2:0))/2+8:"bottom"===d||0>n?-(w+2):18),a.createElement("g",{className:"annotation-note",transform:`translate(${t},${n})`},a.createElement("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0},v),x)}(l,b,v,d))}function z(e){var t,n;const{noteData:o}=e,{screenCoordinates:s}=o,i="string"==typeof o.type?o.type:"label",r=o.eventListeners||o.events||{};if(o.coordinates&&s){const e=o.nx||s[0][0]+(null!==(t=o.dx)&&void 0!==t?t:0),r=o.ny||s[0][1]+(null!==(n=o.dy)&&void 0!==n?n:0),l=s.map((t,n)=>{const s=Object.assign({},o,{note:0===n?o.note:{label:""},x:t[0],y:t[1],nx:e,ny:r});return a.createElement(H,Object.assign({"data-testid":"semiotic-annotation",key:"multi-annotation-"+n},s,{type:i}))});return a.createElement("g",null,l)}const l=o.note||{title:"none",label:o.label};return a.createElement(H,Object.assign({"data-testid":"semiotic-annotation",key:`${l.label}-${l.title}-${o.i}`,events:r},o,{type:i}))}function T(e,t){var n,o,s;const i=null!==(o=null===(n=t.scales)||void 0===n?void 0:n.x)&&void 0!==o?o:null===(s=t.scales)||void 0===s?void 0:s.time;return i?null!=e.x?i(e.x):t.xAccessor&&null!=e[t.xAccessor]?i(e[t.xAccessor]):null:null}function F(e,t){var n,o,s;const i=null!==(o=null===(n=t.scales)||void 0===n?void 0:n.y)&&void 0!==o?o:null===(s=t.scales)||void 0===s?void 0:s.value;return i?null!=e.y?i(e.y):t.yAccessor&&null!=e[t.yAccessor]?i(e[t.yAccessor]):null:null}function P(e,t,n,o=50){return!(-o>e||e>(n.width||0)+o||-o>t||t>(n.height||0)+o)}function I(e,t,n){if("left"===e||"right"===e){const o="left"===e?n:0,s="left"===e?-1:1,i=Math.ceil(t/8);let r="M0,"+o;for(let e=0;i>e;e++){const n=8*(e+1);r+=`L${Math.min(8*e+4,t)},${o+4*s}`,r+=`L${Math.min(n,t)},${o}`}return r}{const o="bottom"===e?0:t,s="bottom"===e?1:-1,i=Math.ceil(n/8);let r=`M${o},0`;for(let e=0;i>e;e++){const t=8*(e+1);r+=`L${o+4*s},${Math.min(8*e+4,n)}`,r+=`L${o},${Math.min(t,n)}`}return r}}function D(e){return Math.round(100*e)/100+""}function R(t){const{width:n,height:o,totalWidth:s,totalHeight:r,margin:l,scales:c,showAxes:u,axes:h,xLabel:d,yLabel:f,xFormat:p,yFormat:m,showGrid:y,title:g,legend:b,foregroundGraphics:v,marginalGraphics:x,xValues:w,yValues:k,annotations:A,svgAnnotationRules:E,annotationFrame:M,xAccessor:S,yAccessor:O,annotationData:N,pointNodes:L,children:j}=t,B=e.useMemo(()=>u&&c?c.x.ticks(5).map(e=>({value:e,pixel:c.x(e),label:(p||D)(e)})):[],[u,c,p]),$=e.useMemo(()=>u&&c?c.y.ticks(5).map(e=>({value:e,pixel:c.y(e),label:(m||D)(e)})):[],[u,c,m]),H=e.useMemo(()=>{if(!A||0===A.length)return null;const e=function(e,t,n){var o,s,r,l,c,u,h,d,f,p,m,y,g,b,v,x,w,k,A,E,M,S,O,N,L,j,C,_,W,B,$,H,I,D,R,G,Y,X,q;switch(e.type){case"label":{let o=null,s=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);if(!t)return null;o=t.x,s=t.y}else o=T(e,n),s=F(e,n);return null==o||null==s?null:P(o,s,n)?a.createElement(z,{key:"ann-"+t,noteData:{x:o,y:s,dx:e.dx||30,dy:e.dy||-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"label",connector:e.connector||{end:"arrow"},color:e.color}}):null}case"callout":{let o=null,s=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);if(!t)return null;o=t.x,s=t.y}else o=T(e,n),s=F(e,n);return null==o||null==s?null:P(o,s,n)?a.createElement(z,{key:"ann-"+t,noteData:{x:o,y:s,dx:e.dx||30,dy:e.dy||-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"callout-circle",subject:{radius:e.radius||12},connector:e.connector||{end:"arrow"},color:e.color}}):null}case"x-threshold":{const o=T(e,n);if(null==o)return null;const s=e.color||"#f97316";return a.createElement("g",{key:"ann-"+t},a.createElement("line",{x1:o,y1:0,x2:o,y2:n.height||0,stroke:s,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:o+4,y:12,fill:s,fontSize:12,fontWeight:"bold"},e.label))}case"y-threshold":{const o=F(e,n);if(null==o)return null;const s=e.color||"#f97316";return a.createElement("g",{key:"ann-"+t},a.createElement("line",{x1:0,y1:o,x2:n.width||0,y2:o,stroke:s,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:o-4,textAnchor:"end",fill:s,fontSize:12,fontWeight:"bold"},e.label))}case"enclose":{const o=(e.coordinates||[]).map(e=>({x:T(Object.assign(Object.assign({},e),{type:"point"}),n),y:F(Object.assign(Object.assign({},e),{type:"point"}),n),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>o.length)return null;const s=i.packEnclose(o),r=e.padding||10;return a.createElement("g",{key:"ann-"+t},a.createElement("circle",{cx:s.x,cy:s.y,r:s.r+r,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"#666",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&a.createElement("text",{x:s.x,y:s.y-s.r-r-4,textAnchor:"middle",fill:e.color||"#666",fontSize:12},e.label))}case"rect-enclose":{const o=(e.coordinates||[]).map(e=>({x:T(Object.assign(Object.assign({},e),{type:"point"}),n),y:F(Object.assign(Object.assign({},e),{type:"point"}),n)})).filter(e=>null!=e.x&&null!=e.y);if(2>o.length)return null;const s=e.padding||10,i=o.map(e=>e.x),r=o.map(e=>e.y),l=Math.min(...i)-s,c=Math.max(...i)+s,u=Math.min(...r)-s,h=Math.max(...r)+s;return a.createElement("g",{key:"ann-"+t},a.createElement("rect",{x:l,y:u,width:c-l,height:h-u,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"#666",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&a.createElement("text",{x:(l+c)/2,y:u-4,textAnchor:"middle",fill:e.color||"#666",fontSize:12},e.label))}case"highlight":{const o=n.data||[],s="function"==typeof e.filter?o.filter(e.filter):e.field&&null!=e.value?o.filter(t=>t[e.field]===e.value):[],i=e.style||{stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return a.createElement("g",{key:"ann-"+t},s.map((t,o)=>{const s=T(t,n),r=F(t,n);return null==s||null==r?null:a.createElement("circle",Object.assign({key:o,cx:s,cy:r,r:e.r||6},i))}))}case"bracket":{const o=T(e,n),s=F(e,n);return a.createElement(z,{key:"ann-"+t,noteData:{x:null!=o?o:0,y:null!=s?s:0,dx:e.dx||0,dy:e.dy||0,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}})}case"trend":{const i=n.data||[];if(2>i.length)return null;const d=n.xAccessor||"x",f=n.yAccessor||"y",p=i.map(e=>[e[d],e[f]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>p.length)return null;const m=null!==(s=null===(o=n.scales)||void 0===o?void 0:o.x)&&void 0!==s?s:null===(r=n.scales)||void 0===r?void 0:r.time,y=null!==(c=null===(l=n.scales)||void 0===l?void 0:l.y)&&void 0!==c?c:null===(u=n.scales)||void 0===u?void 0:u.value;if(!m||!y)return null;const g=e.method||"linear";let b;if("loess"===g)b=function(e,t=.3){const n=e.length;if(2>n)return e.slice();const o=e.slice().sort((e,t)=>e[0]-t[0]),s=o.map(e=>e[0]),i=o.map(e=>e[1]),r=Math.max(2,Math.ceil(t*n)),l=[];for(let e=0;n>e;e++){const t=s[e],o=s.map(e=>Math.abs(e-t)),a=o.slice().sort((e,t)=>e-t)[Math.min(r-1,n-1)]||1,c=[];for(let e=0;n>e;e++){const t=0===a?0:o[e]/a;c[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let u=0,h=0,d=0,f=0,p=0;for(let e=0;n>e;e++){const t=c[e];0!==t&&(u+=t,h+=t*s[e],d+=t*i[e],f+=t*s[e]*s[e],p+=t*s[e]*i[e])}if(0===u){l.push([t,i[e]]);continue}const m=u*f-h*h;if(1e-12>Math.abs(m))l.push([t,d/u]);else{const e=(u*p-h*d)/m;l.push([t,(d-e*h)/u+e*t])}}return l}(p,null!==(h=e.bandwidth)&&void 0!==h?h:.3);else{let t;try{const n=require("regression");t="polynomial"===g?n.polynomial(p,{order:e.order||2}):n.linear(p)}catch(e){return null}b=t.points}const v=b.map(([e,t])=>`${m(e)},${y(t)}`).join(" "),x=e.color||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("polyline",{points:v,fill:"none",stroke:x,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&a.createElement("text",{x:m(b[b.length-1][0])+4,y:y(b[b.length-1][1])-4,fill:x,fontSize:11},e.label))}case"band":{const o=null!==(f=null===(d=n.scales)||void 0===d?void 0:d.y)&&void 0!==f?f:null===(p=n.scales)||void 0===p?void 0:p.value,s=null!==(m=null==o?void 0:o(e.y0))&&void 0!==m?m:0,i=null!==(y=null==o?void 0:o(e.y1))&&void 0!==y?y:n.height||0;return a.createElement("g",{key:"ann-"+t},a.createElement("rect",{x:0,y:Math.min(s,i),width:n.width||0,height:Math.abs(i-s),fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity||.1}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:Math.min(s,i)-4,textAnchor:"end",fill:e.color||"#6366f1",fontSize:11},e.label))}case"envelope":{const o=n.data||[];if(2>o.length)return null;const s=n.xAccessor||"x",i=null!==(b=null===(g=n.scales)||void 0===g?void 0:g.x)&&void 0!==b?b:null===(v=n.scales)||void 0===v?void 0:v.time,r=null!==(w=null===(x=n.scales)||void 0===x?void 0:x.y)&&void 0!==w?w:null===(k=n.scales)||void 0===k?void 0:k.value;if(!i||!r)return null;const l=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",u=e.filter,h=o.filter(e=>null!=e[l]&&null!=e[c]&&!(u&&!u(e))).sort((e,t)=>e[s]-t[s]);if(2>h.length)return null;const d=h.map(e=>`${i(e[s])},${r(e[l])}`).join(" L"),f=h.slice().reverse().map(e=>`${i(e[s])},${r(e[c])}`).join(" L"),p=e.fill||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("path",{d:`M${d} L${f} Z`,fill:p,fillOpacity:null!==(A=e.fillOpacity)&&void 0!==A?A:.15,stroke:"none"}),e.label&&h.length>0&&a.createElement("text",{x:i(h[h.length-1][s])+4,y:r(h[h.length-1][l])-4,fill:p,fontSize:11},e.label))}case"anomaly-band":{const o=n.data||[];if(2>o.length)return null;const s=n.yAccessor||"y",i=null!==(M=null===(E=n.scales)||void 0===E?void 0:E.x)&&void 0!==M?M:null===(S=n.scales)||void 0===S?void 0:S.time,r=null!==(N=null===(O=n.scales)||void 0===O?void 0:O.y)&&void 0!==N?N:null===(L=n.scales)||void 0===L?void 0:L.value;if(!i||!r)return null;const l=o.map(e=>e[s]).filter(e=>null!=e&&isFinite(e));if(2>l.length)return null;const c=l.reduce((e,t)=>e+t,0)/l.length,u=l.reduce((e,t)=>e+Math.pow(t-c,2),0)/l.length,h=Math.sqrt(u),d=null!==(j=e.threshold)&&void 0!==j?j:2,f=c-d*h,p=!1!==e.showBand,m=e.fill||"#6366f1",y=null!==(C=e.fillOpacity)&&void 0!==C?C:.1,g=e.anomalyColor||"#ef4444",b=null!==(_=e.anomalyRadius)&&void 0!==_?_:6,v=r(c+d*h),x=r(f),w=o.filter(e=>{const t=e[s];return null!=t&&Math.abs(t-c)>d*h});return a.createElement("g",{key:"ann-"+t},p&&a.createElement("rect",{x:0,y:Math.min(v,x),width:n.width||0,height:Math.abs(x-v),fill:m,fillOpacity:y}),w.map((e,t)=>{const o=T(e,n),s=F(e,n);return null==o||null==s?null:a.createElement("circle",{key:t,cx:o,cy:s,r:b,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5})}),e.label&&a.createElement("text",{x:(n.width||0)-4,y:Math.min(v,x)-4,textAnchor:"end",fill:m,fontSize:11},e.label))}case"forecast":{const o=n.data||[];if(3>o.length)return null;const s=n.xAccessor||"x",i=n.yAccessor||"y",r=null!==(B=null===(W=n.scales)||void 0===W?void 0:W.x)&&void 0!==B?B:null===($=n.scales)||void 0===$?void 0:$.time,l=null!==(I=null===(H=n.scales)||void 0===H?void 0:H.y)&&void 0!==I?I:null===(D=n.scales)||void 0===D?void 0:D.value;if(!r||!l)return null;const c=o.map(e=>[e[s],e[i]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>c.length)return null;let u;if("polynomial"===(e.method||"linear"))try{const t=require("regression").polynomial(c,{order:e.order||2}).equation;u=e=>t.reduce((t,n,o)=>t+n*Math.pow(e,o),0)}catch(e){return null}else{const e=c.length;let t=0,n=0,o=0,s=0;for(const[e,i]of c)t+=e,n+=i,o+=e*e,s+=e*i;const i=e*o-t*t;if(1e-12>Math.abs(i))return null;const r=(e*s-t*n)/i,l=(n-r*t)/e;u=e=>l+r*e}const h=c.length,d=c.map(([e,t])=>t-u(e)).reduce((e,t)=>e+t*t,0),f=Math.sqrt(d/Math.max(h-2,1)),p=c.reduce((e,t)=>e+t[0],0)/h,m=c.reduce((e,t)=>e+Math.pow(t[0]-p,2),0),y=null!==(R=e.confidence)&&void 0!==R?R:.95,g=.99>y?.95>y?.9>y?1:1.645:1.96:2.576,b=null!==(G=e.steps)&&void 0!==G?G:5,v=c[h-1][0],x=(v-c[0][0])/Math.max(h-1,1),w=[];for(let e=1;b>=e;e++)w.push(v+e*x);const k=[];for(const e of w){const t=u(e),n=f*Math.sqrt(1+1/h+(m>0?Math.pow(e-p,2)/m:0))*g;k.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const A=`M${k.map(e=>`${r(e.x)},${l(e.yUpper)}`).join(" L")} L${k.slice().reverse().map(e=>`${r(e.x)},${l(e.yLower)}`).join(" L")} Z`,E=k.map(e=>`${r(e.x)},${l(e.yCenter)}`).join(" "),M=`${r(v)},${l(u(v))}`,S=e.strokeColor||"#6366f1";return a.createElement("g",{key:"ann-"+t},a.createElement("path",{d:A,fill:e.fill||"#6366f1",fillOpacity:null!==(Y=e.fillOpacity)&&void 0!==Y?Y:.15,stroke:"none"}),a.createElement("polyline",{points:`${M} ${E}`,fill:"none",stroke:S,strokeWidth:null!==(X=e.strokeWidth)&&void 0!==X?X:2,strokeDasharray:null!==(q=e.strokeDasharray)&&void 0!==q?q:"6,3"}),e.label&&k.length>0&&a.createElement("text",{x:r(k[k.length-1].x)+4,y:l(k[k.length-1].yCenter)-4,fill:S,fontSize:11},e.label))}default:return null}},t={scales:c?{x:c.x,y:c.y,time:c.x,value:c.y}:null,timeAxis:"x",xAccessor:S,yAccessor:O,width:n,height:o,data:N,frameType:"xy",pointNodes:L};return A.map((n,o)=>{if(E){const s=E(n,o,t);return null!=s?s:e(n,o,t)}return e(n,o,t)}).filter(Boolean)},[A,E,n,o,M,S,O,N]);return u||g||b||v||x||H&&H.length>0||y||j?a.createElement("svg",{width:s,height:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},a.createElement("g",{transform:`translate(${l.left},${l.top})`},y&&c&&a.createElement("g",{className:"stream-grid"},B.map((e,t)=>a.createElement("line",{key:"xgrid-"+t,x1:e.pixel,y1:0,x2:e.pixel,y2:o,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1})),$.map((e,t)=>a.createElement("line",{key:"ygrid-"+t,x1:0,y1:e.pixel,x2:n,y2:e.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1}))),u&&c&&(()=>{const e=null==h?void 0:h.find(e=>"left"===e.orient),t=null==h?void 0:h.find(e=>"bottom"===e.orient),s=!e||!1!==e.baseline,i=(null==e?void 0:e.jaggedBase)||!1,r=(null==t?void 0:t.jaggedBase)||!1,c="var(--semiotic-border, #ccc)",u="var(--semiotic-text-secondary, #666)",p="var(--semiotic-text, #333)";return a.createElement("g",{className:"stream-axes"},(!t||!1!==t.baseline)&&!r&&a.createElement("line",{x1:0,y1:o,x2:n,y2:o,stroke:c,strokeWidth:1}),r&&a.createElement("path",{d:I("bottom",n,o),fill:"none",stroke:c,strokeWidth:1}),B.map((e,t)=>a.createElement("g",{key:"xtick-"+t,transform:`translate(${e.pixel},${o})`},a.createElement("line",{y2:5,stroke:c,strokeWidth:1}),a.createElement("text",{y:18,textAnchor:"middle",fontSize:10,fill:u,style:{userSelect:"none"}},e.label))),d&&a.createElement("text",{x:n/2,y:o+40,textAnchor:"middle",fontSize:12,fill:p,style:{userSelect:"none"}},d),s&&!i&&a.createElement("line",{x1:0,y1:0,x2:0,y2:o,stroke:c,strokeWidth:1}),i&&a.createElement("path",{d:I("left",n,o),fill:"none",stroke:c,strokeWidth:1}),$.map((e,t)=>a.createElement("g",{key:"ytick-"+t,transform:`translate(0,${e.pixel})`},a.createElement("line",{x2:-5,stroke:c,strokeWidth:1}),a.createElement("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:u,style:{userSelect:"none"}},e.label))),f&&a.createElement("text",{x:15-l.left,y:o/2,textAnchor:"middle",fontSize:12,fill:p,transform:`rotate(-90, ${15-l.left}, ${o/2})`,style:{userSelect:"none"}},f))})(),H,x&&c&&w&&k&&a.createElement(a.Fragment,null,x.top&&a.createElement("g",{transform:"translate(0, 0)"},a.createElement(W,{orient:"top",config:_(x.top),values:w,scale:c.x,size:l.top,length:n})),x.bottom&&a.createElement("g",{transform:`translate(0, ${o})`},a.createElement(W,{orient:"bottom",config:_(x.bottom),values:w,scale:c.x,size:l.bottom,length:n})),x.left&&a.createElement("g",{transform:"translate(0, 0)"},a.createElement(W,{orient:"left",config:_(x.left),values:k,scale:c.y,size:l.left,length:o})),x.right&&a.createElement("g",{transform:`translate(${n}, 0)`},a.createElement(W,{orient:"right",config:_(x.right),values:k,scale:c.y,size:l.right,length:o}))),v,j),g&&a.createElement("text",{x:s/2,y:20,textAnchor:"middle",fontSize:14,fontWeight:"bold",fill:"var(--semiotic-text, #333)",style:{userSelect:"none"}},"string"==typeof g?g:null),b&&a.createElement("g",{transform:`translate(${s-l.right+10}, ${l.top})`},"object"==typeof(R=b)&&null!==R&&!a.isValidElement(R)&&"legendGroups"in R?a.createElement(C,{legendGroups:b.legendGroups,title:"",width:100}):b)):null;var R}function G(e,t,n){let o=n;for(const n of t)"lesser"===n.thresholdType?n.value>e&&(o=n.color):e>n.value&&(o=n.color);return o}function Y(e){if(e.startsWith("#")){const t=4===e.length?e[1]+e[1]+e[2]+e[2]+e[3]+e[3]:e.slice(1,7);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[78,121,167]}const X=(e,t,n,o)=>{var s;const i=t.filter(e=>"area"===e.type);for(const t of i){if(2>t.topPath.length)continue;e.beginPath();const[n,o]=t.topPath[0];e.moveTo(n,o);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1]);for(let n=t.bottomPath.length-1;n>=0;n--)e.lineTo(t.bottomPath[n][0],t.bottomPath[n][1]);e.closePath();const i=t.style.fill||"#4e79a7";if(t.fillGradient){const n=Math.min(...t.topPath.map(e=>e[1])),o=Math.max(...t.bottomPath.map(e=>e[1])),s=e.createLinearGradient(0,n,0,o);s.addColorStop(0,i),s.addColorStop(1,i),e.fillStyle=s;const r=Y(i),l=t.fillGradient.topOpacity,a=t.fillGradient.bottomOpacity,c=e.createLinearGradient(0,n,0,o);c.addColorStop(0,`rgba(${r[0]},${r[1]},${r[2]},${l})`),c.addColorStop(1,`rgba(${r[0]},${r[1]},${r[2]},${a})`),e.fillStyle=c,e.globalAlpha=1}else{const n=null!==(s=t.style.fillOpacity)&&void 0!==s?s:.7;e.globalAlpha=n,e.fillStyle=i}if(e.fill(),t.style.stroke&&"none"!==t.style.stroke){e.globalAlpha=1,e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||2,e.setLineDash([]),e.beginPath(),e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1]);e.stroke()}e.globalAlpha=1}},q=(e,t,n,o)=>{var s,i;const r=t.filter(e=>"point"===e.type);for(const t of r){e.beginPath(),e.arc(t.x,t.y,t.r,0,2*Math.PI);const n=null!==(s=t.style.opacity)&&void 0!==s?s:t.style.fillOpacity;if(null!=n&&(e.globalAlpha=n),e.fillStyle=t.style.fill||"#4e79a7",e.fill(),t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||1,e.stroke()),t._pulseIntensity&&t._pulseIntensity>0){const n=null!==(i=t._pulseGlowRadius)&&void 0!==i?i:4,o=t.r+n*t._pulseIntensity;e.beginPath(),e.arc(t.x,t.y,o,0,2*Math.PI),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=2*t._pulseIntensity,e.globalAlpha=.6*t._pulseIntensity,e.stroke()}e.globalAlpha=1}},V=(e,t,n,o)=>{const s=t.filter(e=>"rect"===e.type);for(const t of s)null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.icon?U(e,t):(e.fillStyle=t.style.fill||"#007bff",e.fillRect(t.x,t.y,t.w,t.h),t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=t.style.strokeWidth||1,e.strokeRect(t.x,t.y,t.w,t.h))),t._pulseIntensity&&t._pulseIntensity>0&&(e.globalAlpha=.3*t._pulseIntensity,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h)),e.globalAlpha=1};function U(e,t){const n=t.style.icon,o=t.style.iconPadding||2,s=Math.min(t.w,t.w)-o;if(0>=s)return;const i=t.h>t.w;if(e.save(),e.beginPath(),e.rect(t.x,t.y,t.w,t.h),e.clip(),i){const i=s+o,r=t.x+(t.w-s)/2;for(let o=t.y+t.h-s;o>=t.y-s;o-=i)e.drawImage(n,r,o,s,s)}else{const i=s+o,r=t.y+(t.h-s)/2;for(let o=t.x;t.x+t.w>o;o+=i)e.drawImage(n,o,r,s,s)}e.restore()}const Z={line:[X,(e,t,n,o)=>{const s=t.filter(e=>"line"===e.type);for(const i of s){if(2>i.path.length)continue;const r=i.style.stroke||"#007bff",l=i.style.strokeWidth||2,a=i.colorThresholds,c=i.rawValues;if(e.setLineDash(i.style.strokeDasharray?i.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=i.style.opacity&&(e.globalAlpha=i.style.opacity),e.lineWidth=l,a&&0!==a.length&&c&&c.length===i.path.length){let u=null,h=null,d=null,f=null,p=!1;function m(t,n,o){e.beginPath(),e.strokeStyle=t,e.moveTo(n,o),p=!0}function y(){p&&(e.stroke(),p=!1)}for(let g=0;i.path.length>g;g++){const[b,v]=i.path[g],x=c[g],w=G(x,a,r);if(null!==u&&null!==f&&null!==d){if(w===f)e.lineTo(b,v);else{const k=[];for(const A of a){const E=A.value;(d>E||E>x)&&(E>d||x>E)||d===E||x===E||k.push({t:(E-d)/(x-d)})}k.sort((e,t)=>e.t-t.t);for(const M of k){const S=u+(b-u)*M.t,O=h+(v-h)*M.t,N=G(d+(x-d)*Math.min(M.t+1e-4,1),a,r);e.lineTo(S,O),y(),m(N,S,O)}e.lineTo(b,v)}u=b,h=v,d=x,f=w}else m(w,b,v),u=b,h=v,d=x,f=w}y()}else{e.beginPath(),e.strokeStyle=r;const[L,j]=i.path[0];e.moveTo(L,j);for(let C=1;i.path.length>C;C++)e.lineTo(i.path[C][0],i.path[C][1]);e.stroke()}if(i.style.fill&&i.style.fillOpacity&&i.style.fillOpacity>0){e.beginPath(),e.globalAlpha=i.style.fillOpacity,e.fillStyle=i.style.fill;const[_,W]=i.path[0];e.moveTo(_,W);for(let $=1;i.path.length>$;$++)e.lineTo(i.path[$][0],i.path[$][1]);const B=i.path[0][0];e.lineTo(i.path[i.path.length-1][0],o.height),e.lineTo(B,o.height),e.closePath(),e.fill()}e.globalAlpha=1,e.setLineDash([])}}],area:[X],stackedarea:[X],scatter:[q],bubble:[q],heatmap:[(e,t,n,o)=>{const s=t.filter(e=>"heatcell"===e.type);for(const t of s){const n=t.style;null!=(null==n?void 0:n.opacity)&&(e.globalAlpha=n.opacity),e.fillStyle=t.fill,e.fillRect(t.x,t.y,t.w,t.h),e.strokeStyle="#fff",e.lineWidth=1,e.strokeRect(t.x,t.y,t.w,t.h),t._pulseIntensity&&t._pulseIntensity>0&&(e.globalAlpha=.3*t._pulseIntensity,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h)),e.globalAlpha=1}}],bar:[V],swarm:[q],waterfall:[(e,t,n,o)=>{var s,i,r;V(e,t);const l=t.filter(e=>"rect"===e.type);if(2>l.length)return;const a=l[0].datum,c=null==a?void 0:a._connectorStroke;if(c){e.save(),e.strokeStyle=c,e.lineWidth=null!==(s=null==a?void 0:a._connectorWidth)&&void 0!==s?s:1,e.setLineDash([]);for(let t=0;l.length-1>t;t++){const o=l[t],s=l[t+1];if(!(null===(i=o.datum)||void 0===i?void 0:i.cumEnd)||!(null===(r=s.datum)||void 0===r?void 0:r.baseline))continue;const a=n.y(o.datum.cumEnd),c=o.x+o.w,u=s.x;e.beginPath(),e.moveTo(c,a),e.lineTo(u,a),e.stroke()}e.restore()}}],candlestick:[(e,t,n,o)=>{for(const n of t){if("candlestick"!==n.type)continue;const t=n;e.beginPath(),e.moveTo(t.x,t.highY),e.lineTo(t.x,t.lowY),e.strokeStyle=t.wickColor,e.lineWidth=t.wickWidth,e.stroke();const o=Math.min(t.openY,t.closeY),s=Math.abs(t.openY-t.closeY),i=t.isUp?t.upColor:t.downColor;e.fillStyle=i,e.fillRect(t.x-t.bodyWidth/2,o,t.bodyWidth,Math.max(s,1)),e.strokeStyle=i,e.lineWidth=1,e.strokeRect(t.x-t.bodyWidth/2,o,t.bodyWidth,Math.max(s,1))}}]},J={top:20,right:20,bottom:30,left:40},K={axisStroke:"#ccc",tickText:"#666",crosshair:"rgba(0, 0, 0, 0.25)",hoverFill:"rgba(255, 255, 255, 0.3)",hoverStroke:"rgba(0, 0, 0, 0.4)",pointRing:"white"},Q={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"6px 10px",borderRadius:4,fontSize:12,lineHeight:1.5,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",whiteSpace:"nowrap"};function ee({hover:e}){const t=e=>Number.isInteger(e)?e+"":e.toFixed(2);return a.createElement("div",{className:"semiotic-tooltip",style:Q},a.createElement("div",{style:{fontWeight:600,marginBottom:2}},t(e.value)),a.createElement("div",{style:{opacity:.7,fontSize:11}},t(e.time)))}function te({width:o,height:s,totalWidth:i,totalHeight:r,margin:l,dimension:c,scales:u,onBrush:h}){const d=e.useRef(null),f=e.useRef(null);return e.useEffect(()=>{if(!d.current)return;const e=n.select(d.current).select(".brush-g"),i="x"===c?t.brushX():"y"===c?t.brushY():t.brush();return i.extent([[0,0],[o,s]]),i.on("brush end",e=>{if(!u)return;if(!e.selection)return void h(null);let t,n;if("x"===c){const[o,i]=e.selection;t=[u.x.invert(o),u.x.invert(i)],n=[u.y.invert(s),u.y.invert(0)]}else if("y"===c){const[s,i]=e.selection;t=[u.x.invert(0),u.x.invert(o)],n=[u.y.invert(i),u.y.invert(s)]}else{const[[o,s],[i,r]]=e.selection;t=[u.x.invert(o),u.x.invert(i)],n=[u.y.invert(r),u.y.invert(s)]}h({x:t,y:n})}),e.call(i),f.current=i,e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.15).attr("stroke","steelblue").attr("stroke-width",1),()=>{i.on("brush end",null),f.current=null}},[o,s,c,u,h]),a.createElement("svg",{ref:d,width:i,height:r,style:{position:"absolute",top:0,left:0,pointerEvents:"all"}},a.createElement("g",{className:"brush-g",transform:`translate(${l.left},${l.top})`}))}const ne=e.forwardRef(function(t,n){var o,s,i;const{chartType:r,runtimeMode:l,data:c,xAccessor:h,yAccessor:d,colorAccessor:f,sizeAccessor:p,groupAccessor:m,lineDataAccessor:y,normalize:g,binSize:b,valueAccessor:v,arrowOfTime:x="right",windowMode:N="sliding",windowSize:L=200,timeAccessor:j,xExtent:C,yExtent:_,extentPadding:W=.1,sizeRange:B,size:$=[500,300],responsiveWidth:H,responsiveHeight:z,margin:T,className:F,background:P,lineStyle:I,pointStyle:D,areaStyle:G,waterfallStyle:Y,swarmStyle:X,barColors:q,colorScheme:V,boundsAccessor:U,boundsStyle:Q,y0Accessor:ne,gradientFill:oe,openAccessor:se,highAccessor:ie,lowAccessor:re,closeAccessor:le,candlestickStyle:ae,showAxes:ce=!0,axes:ue,xLabel:he,yLabel:de,xFormat:fe,yFormat:pe,tickFormatTime:me,tickFormatValue:ye,hoverAnnotation:ge,tooltipContent:be,customHoverBehavior:ve,enableHover:xe,annotations:we,svgAnnotationRules:ke,showGrid:Ae,legend:Ee,backgroundGraphics:Me,foregroundGraphics:Se,title:Oe,categoryAccessor:Ne,brush:Le,onBrush:je,decay:Ce,pulse:_e,transition:We,staleness:Be,heatmapAggregation:$e,heatmapXBins:He,heatmapYBins:ze,marginalGraphics:Te,pointIdAccessor:Fe}=t,[Pe,Ie]=function(t,n,o){const s=e.useRef(null),[i,r]=e.useState(null);return e.useEffect(()=>{if(!n&&!o)return;const e=s.current;if(!e)return;const t=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;r(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return t.observe(e),()=>t.disconnect()},[n,o]),[s,[n&&i?i.w:t[0],o&&i?i.h:t[1]]]}($,H,z),De=Object.assign(Object.assign({},J),T);if(Te){const e=60;Te.top&&e>De.top&&(De.top=e),Te.bottom&&e>De.bottom&&(De.bottom=e),Te.left&&e>De.left&&(De.left=e),Te.right&&e>De.right&&(De.right=e)}const Re=Ie[0]-De.left-De.right,Ge=Ie[1]-De.top-De.bottom,Ye=null!=ge?ge:xe,Xe=e.useRef(null),qe=e.useRef(0),Ve=e.useRef(!1),[Ue,Ze]=e.useState(0),[Je,Ke]=e.useState(null),Qe=e.useRef(null),et=e.useRef(null),[tt,nt]=e.useState(null),[ot,st]=e.useState(!1),[it,rt]=e.useState([]),[lt,at]=e.useState([]),ct=e.useRef(()=>{}),ut="streaming"===l||["bar","swarm","waterfall"].includes(r),ht=e.useMemo(()=>({chartType:r,runtimeMode:ut?"streaming":"bounded",windowSize:L,windowMode:N,arrowOfTime:ut?x:"right",extentPadding:W,xAccessor:ut?void 0:h,yAccessor:ut?void 0:d,timeAccessor:ut?j:void 0,valueAccessor:v,colorAccessor:f,sizeAccessor:p,groupAccessor:m,categoryAccessor:Ne,lineDataAccessor:y,xExtent:C,yExtent:_,sizeRange:B,binSize:b,normalize:g,boundsAccessor:U,boundsStyle:Q,y0Accessor:ne,gradientFill:"boolean"==typeof oe?oe?{topOpacity:.8,bottomOpacity:.05}:void 0:oe,openAccessor:se,highAccessor:ie,lowAccessor:re,closeAccessor:le,candlestickStyle:ae,lineStyle:I,pointStyle:D,areaStyle:G,swarmStyle:X,waterfallStyle:Y,colorScheme:V,barColors:q,annotations:we,decay:Ce,pulse:_e,transition:We,staleness:Be,heatmapAggregation:$e,heatmapXBins:He,heatmapYBins:ze,pointIdAccessor:Fe}),[r,L,N,x,W,h,d,j,v,f,p,m,Ne,y,C,_,B,b,g,U,Q,ne,oe,se,ie,re,le,ae,I,D,G,X,Y,V,q,we,Ce,_e,We,Be,$e,He,ze,ut,Fe]),dt=e.useRef(null);dt.current||(dt.current=new w(ht));const ft=e.useCallback(()=>{qe.current||(qe.current=requestAnimationFrame(()=>ct.current()))},[]);e.useEffect(()=>{var e;null===(e=dt.current)||void 0===e||e.updateConfig(ht),Ve.current=!0,ft()},[ht,ft]);const pt=e.useRef(null);pt.current||(pt.current=new u(e=>{const t=dt.current;t&&t.ingest(e)&&(Ve.current=!0,ft())}));const mt=e.useCallback(e=>{var t;null===(t=pt.current)||void 0===t||t.push(e)},[]),yt=e.useCallback(e=>{var t;null===(t=pt.current)||void 0===t||t.pushMany(e)},[]),gt=e.useCallback(()=>{var e,t;null===(e=pt.current)||void 0===e||e.clear(),null===(t=dt.current)||void 0===t||t.clear(),Ve.current=!0,ft()},[ft]);e.useImperativeHandle(n,()=>({push:mt,pushMany:yt,clear:gt,getData:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.getData())&&void 0!==t?t:[]},getScales:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.scales)&&void 0!==t?t:null},getExtents:()=>{var e,t;return null!==(t=null===(e=dt.current)||void 0===e?void 0:e.getExtents())&&void 0!==t?t:null}}),[mt,yt,gt]),e.useEffect(()=>{var e;c&&(null===(e=pt.current)||void 0===e||e.setBoundedData(c))},[c]);const bt=e.useRef(()=>{}),vt=e.useRef(()=>{});bt.current=e=>{if(!Ye)return;const t=Xe.current;if(!t)return;const n=t.getBoundingClientRect(),o=e.clientX-n.left-De.left,s=e.clientY-n.top-De.top;if(0>o||o>Re||0>s||s>Ge)return void(Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&(ve(null),Ve.current=!0),ft()));const i=dt.current;if(!i||0===i.scene.length)return;const r=function(e,t,n,o=30){let s=null;for(const i of e){let e=null;switch(i.type){case"point":e=k(i,t,n);break;case"line":e=A(i,t,n);break;case"rect":e=E(i,t,n);break;case"heatcell":e=M(i,t,n);break;case"area":if(!1===i.interactive)break;e=O(i,t,n);break;case"candlestick":e=S(i,t,n)}e&&o>e.distance&&(s&&e.distance>=s.distance||(s=e))}return s}(i.scene,o,s);if(!r)return void(Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&ve(null),ft()));const l={data:r.datum,time:r.x,value:r.y,x:r.x,y:r.y};Qe.current=l,et.current=r.node,nt(l),ve&&(ve(l),Ve.current=!0),ft()},vt.current=()=>{Qe.current&&(Qe.current=null,et.current=null,nt(null),ve&&(ve(null),Ve.current=!0),ft())},e.useCallback(e=>bt.current(e),[]);const xt=e.useCallback(()=>vt.current(),[]),wt=e.useRef(-1),kt=e.useCallback(e=>{const t=dt.current;if(!t||0===t.scene.length)return;const n=function(e){const t=[];for(const n of e)switch(n.type){case"point":t.push({x:n.x,y:n.y,datum:n.datum});break;case"line":{const e=n,o=Array.isArray(e.datum)?e.datum:[];for(let n=0;e.path.length>n&&o.length>n;n++)t.push({x:e.path[n][0],y:e.path[n][1],datum:o[n]});break}case"area":{const e=n,o=Array.isArray(e.datum)?e.datum:[];for(let n=0;e.topPath.length>n&&o.length>n;n++)t.push({x:e.topPath[n][0],y:e.topPath[n][1],datum:o[n]});break}case"rect":case"heatcell":t.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum})}return t.sort((e,t)=>e.x-t.x||e.y-t.y),t}(t.scene);if(0===n.length)return;const o=0>wt.current?-1:wt.current,s=function(e,t,n){switch(e){case"ArrowRight":case"ArrowDown":return n-1>t?t+1:t;case"ArrowLeft":case"ArrowUp":return t>0?t-1:t;case"Home":return 0;case"End":return n-1;case"Escape":return-1;default:return null}}(e.key,0>o?-1:o,n.length);if(null===s)return;if(e.preventDefault(),0>s)return wt.current=-1,Qe.current=null,et.current=null,nt(null),ve&&ve(null),void ft();const i=0>o?0:s;wt.current=i;const r={data:(l=n[i]).datum,x:l.x,y:l.y,time:l.x,value:l.y};var l;Qe.current=r,nt(r),ve&&ve(r),ft()},[ve,ft]),At=e.useCallback(e=>{wt.current=-1,bt.current(e)},[]);ct.current=()=>{var e,t;qe.current=0;const n=Xe.current;if(!n)return;const o=n.getContext("2d");if(!o)return;const s=dt.current;if(!s)return;const i="undefined"!=typeof performance?performance.now():Date.now(),l=s.advanceTransition(i);l||s.computeScene({width:Re,height:Ge});const a="undefined"!=typeof window&&window.devicePixelRatio||1;n.width=Ie[0]*a,n.height=Ie[1]*a,n.style.width=Ie[0]+"px",n.style.height=Ie[1]+"px",o.scale(a,a),o.translate(De.left,De.top),o.clearRect(-De.left,-De.top,Ie[0],Ie[1]);const c=function(e){if(!e)return K;const t=getComputedStyle(e),n=t.getPropertyValue("--semiotic-border").trim(),o=t.getPropertyValue("--semiotic-text-secondary").trim(),s=t.getPropertyValue("--semiotic-bg").trim(),i=o||t.getPropertyValue("--text-secondary").trim(),r=t.getPropertyValue("--text-primary").trim(),l=n||t.getPropertyValue("--surface-3").trim(),a=s||t.getPropertyValue("--surface-0").trim();return i||r||n?{axisStroke:l||K.axisStroke,tickText:i||K.tickText,crosshair:i?i+"66":K.crosshair,hoverFill:a?a+"4D":K.hoverFill,hoverStroke:i?i+"99":K.hoverStroke,pointRing:a||K.pointRing}:K}(n),u=null!==(e=null==Be?void 0:Be.threshold)&&void 0!==e?e:5e3,f=Be&&s.lastIngestTime>0&&i-s.lastIngestTime>u;f&&(o.globalAlpha=null!==(t=null==Be?void 0:Be.dimOpacity)&&void 0!==t?t:.5);const p=n?getComputedStyle(n).getPropertyValue("--semiotic-bg").trim():"",m=P||(p&&"transparent"!==p?p:null);m&&(o.fillStyle=m,o.fillRect(-De.left,-De.top,Ie[0],Ie[1])),o.save(),"function"==typeof o.rect&&(o.beginPath(),o.rect(0,0,Re,Ge),o.clip());const y=Z[r];if(y&&s.scales)for(const e of y)e(o,s.scene,s.scales,{width:Re,height:Ge});if(o.restore(),f&&(o.globalAlpha=1),Ye&&Qe.current&&s.scales&&function(e,t,n,o,s,i,r){if(!1===s.crosshair)return;e.save();const l="object"==typeof s.crosshair?s.crosshair:{};e.strokeStyle=l.stroke||r.crosshair,e.lineWidth=l.strokeWidth||1,e.setLineDash(l.strokeDasharray?l.strokeDasharray.split(/[\s,]+/).map(Number):[4,4]),e.beginPath(),e.moveTo(t.x,0),e.lineTo(t.x,o),e.stroke(),e.beginPath(),e.moveTo(0,t.y),e.lineTo(n,t.y),e.stroke(),e.restore(),e.beginPath(),e.arc(t.x,t.y,4,0,2*Math.PI),e.fillStyle="#007bff",e.fill(),e.strokeStyle=r.pointRing,e.lineWidth=2,e.stroke()}(o,Qe.current,Re,Ge,"object"==typeof Ye?Ye:{},0,c),et.current&&Array.isArray(ge)){const e=ge.find(e=>e&&"object"==typeof e&&"highlight"===e.type);e&&function(e,t,n,o){var s;if(!n)return;const i=n.group;if(void 0!==i)for(const n of t){if("line"!==n.type)continue;if(n.group!==i)continue;if(2>n.path.length)continue;const t="function"==typeof o.style?o.style(n.datum):o.style||{};e.save(),e.beginPath(),e.moveTo(n.path[0][0],n.path[0][1]);for(let t=1;n.path.length>t;t++)e.lineTo(n.path[t][0],n.path[t][1]);e.strokeStyle=t.stroke||n.style.stroke||"#007bff",e.lineWidth=t.strokeWidth||(n.style.strokeWidth||2)+2,e.globalAlpha=null!==(s=t.opacity)&&void 0!==s?s:1,e.stroke(),e.restore()}}(o,s.scene,et.current,e)}const g=Ve.current;if(Ve.current=!1,g&&s.scales&&(Ke(s.scales),Te)){const e=s.getData(),t="function"==typeof h?h:e=>e[h||"x"],n="function"==typeof d?d:e=>e[d||"y"];rt(e.map(e=>t(e)).filter(e=>"number"==typeof e&&isFinite(e))),at(e.map(e=>n(e)).filter(e=>"number"==typeof e&&isFinite(e)))}g&&we&&we.length>0&&Ze(e=>e+1),(null==Be?void 0:Be.showBadge)&&st(!!f),(l||s.hasActivePulses)&&(qe.current=requestAnimationFrame(()=>ct.current()))},e.useEffect(()=>(ft(),()=>{qe.current&&(cancelAnimationFrame(qe.current),qe.current=0)}),[ft]),e.useEffect(()=>{Ve.current=!0,ft()},[r,Re,Ge,ce,P,I,ft]),e.useEffect(()=>{if(!Be)return;const e=setInterval(()=>{var e;const t=dt.current;if(!t||0===t.lastIngestTime)return;const n="undefined"!=typeof performance?performance.now():Date.now(),o=null!==(e=Be.threshold)&&void 0!==e?e:5e3,s=n-t.lastIngestTime>o;s!==ot&&(st(s),Ve.current=!0,ft())},1e3);return()=>clearInterval(e)},[Be,ot,ft]);const Et=Ye&&tt?be?be(tt):a.createElement(ee,{hover:tt}):null,Mt=Et?a.createElement("div",{className:"stream-frame-tooltip",style:{position:"absolute",left:De.left+tt.x,top:De.top+tt.y,transform:`translate(${tt.x>.7*Re?"calc(-100% - 12px)":"12px"}, ${.3*Ge>tt.y?"4px":"calc(-100% - 4px)"})`,pointerEvents:"none",zIndex:1}},Et):null,St=wt.current>=0&&tt?a.createElement("svg",{style:{position:"absolute",left:0,top:0,width:Ie[0],height:Ie[1],pointerEvents:"none",zIndex:2}},a.createElement("circle",{cx:tt.x+De.left,cy:tt.y+De.top,r:8,fill:"none",stroke:"var(--accent, #6366f1)",strokeWidth:2,strokeDasharray:"4,2"})):null;return a.createElement("div",{ref:Pe,className:"stream-xy-frame"+(F?" "+F:""),role:"img","aria-label":"string"==typeof Oe?Oe:"XY chart",tabIndex:0,style:{position:"relative",width:H?"100%":Ie[0],height:z?"100%":Ie[1]},onMouseMove:Ye?At:void 0,onMouseLeave:Ye?xt:void 0,onKeyDown:kt},Me&&a.createElement("svg",{style:{position:"absolute",left:0,top:0,width:Ie[0],height:Ie[1],pointerEvents:"none"}},Me),a.createElement("canvas",{ref:Xe,style:{position:"absolute",left:0,top:0}}),a.createElement(R,{width:Re,height:Ge,totalWidth:Ie[0],totalHeight:Ie[1],margin:De,scales:Je,showAxes:ce,axes:ue,xLabel:he,yLabel:de,xFormat:fe||me,yFormat:pe||ye,showGrid:Ae,title:Oe,legend:Ee,foregroundGraphics:Se,marginalGraphics:Te,xValues:it,yValues:lt,annotations:we,svgAnnotationRules:ke,annotationFrame:Ue,xAccessor:"string"==typeof h?h:"string"==typeof j?j:void 0,yAccessor:"string"==typeof d?d:"string"==typeof v?v:void 0,annotationData:null===(o=dt.current)||void 0===o?void 0:o.getData(),pointNodes:null===(s=dt.current)||void 0===s?void 0:s.scene.filter(e=>"point"===e.type)}),(Le||je)&&a.createElement(te,{width:Re,height:Ge,totalWidth:Ie[0],totalHeight:Ie[1],margin:De,dimension:null!==(i=null==Le?void 0:Le.dimension)&&void 0!==i?i:"xy",scales:Je,onBrush:null!=je?je:()=>{}}),(null==Be?void 0:Be.showBadge)&&a.createElement("div",{className:"stream-staleness-badge",style:Object.assign(Object.assign({position:"absolute"},"top-left"===Be.badgePosition?{top:4,left:4}:"bottom-left"===Be.badgePosition?{bottom:4,left:4}:"bottom-right"===Be.badgePosition?{bottom:4,right:4}:{top:4,right:4}),{padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",background:ot?"#dc3545":"#28a745",color:"white"})},ot?"STALE":"LIVE"),St,Mt)});ne.displayName="StreamXYFrame";const oe={category10:r.schemeCategory10,tableau10:r.schemeTableau10,set3:r.schemeSet3,blues:r.interpolateBlues,reds:r.interpolateReds,greens:r.interpolateGreens,oranges:r.interpolateOranges,purples:r.interpolatePurples,viridis:r.interpolateViridis,plasma:r.interpolatePlasma},se=r.schemeCategory10;function ie(e,t,n){if("function"==typeof t)return t(e);const o=e[t];return n?n(o):se[Math.abs(function(e){let t=0;for(let n=0;e.length>n;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return Math.abs(t)}(o+""))%se.length]}function re(e,t,n="category10"){const s=Array.from(new Set(e.map(e=>e[t]))),i=s.every(e=>"number"==typeof e||!isNaN(Number(e)));if(Array.isArray(n))return o.scaleOrdinal().domain(s).range(n).unknown("#999");const r=oe[n]||oe.category10;if(i&&"function"==typeof r)return e=>r(Number(e)/Math.max(...s.map(Number)));{const e=Array.isArray(r)?r:se;return o.scaleOrdinal().domain(s).range(e).unknown("#999")}}function le(e,t,n=[3,20],o){let s;if(s="function"==typeof t?t(e):e[t],!o)return s;const[i,r]=o,[l,a]=n;return r===i?(l+a)/2:l+(s-i)/(r-i)*(a-l)}const ae=e.createContext(null);function ce(e){return e?"string"==typeof e?{name:e}:e:null}function ue(e,t,n){return t?o=>{var s;const i=Object.assign({},e(o));if(t.isActive)if(t.predicate(o))(null==n?void 0:n.selectedStyle)&&Object.assign(i,n.selectedStyle);else{const e=null!==(s=null==n?void 0:n.unselectedOpacity)&&void 0!==s?s:.2;i.opacity=e,i.fillOpacity=e,i.strokeOpacity=e,(null==n?void 0:n.unselectedStyle)&&Object.assign(i,n.unselectedStyle)}return i}:e}function he(t){const n=e.createContext(null),o=de(t);return[function({children:o}){const s=e.useMemo(()=>de(t),[]);return a.createElement(n.Provider,{value:s,children:o})},t=>{var s;const i=null!==(s=e.useContext(n))&&void 0!==s?s:o;return function(t,n){const[o,s]=e.useState(n);return e.useLayoutEffect(()=>t(()=>s(n)),[t]),o}(i.subscribe,()=>t(i.getState()))}]}function de(e){const t=new EventTarget;let n=e(function(e){n=Object.assign(Object.assign({},n),e(n)),t.dispatchEvent(new CustomEvent("update"))});return{getState:()=>n,subscribe:function(e){return t.addEventListener("update",e),()=>t.removeEventListener("update",e)}}}function fe(e){const t=[];for(const[n,o]of Object.entries(e.fields))if("point"===o.type)t.push(e=>o.values.has(e[n]));else{const[e,s]=o.range;t.push(t=>{const o=t[n];return o>=e&&s>=o})}return e=>t.every(t=>t(e))}function pe(e,t){let n=e.get(t);return n||(n={name:t,resolution:"union",clauses:new Map},e.set(t,n)),n}const[me,ye]=he(e=>({selections:new Map,setClause(t,n){e(e=>{const o=new Map(e.selections),s=pe(o,t),i=new Map(s.clauses);return i.set(n.clientId,n),o.set(t,Object.assign(Object.assign({},s),{clauses:i})),{selections:o}})},clearClause(t,n){e(e=>{const o=e.selections.get(t);if(!o)return{};const s=new Map(e.selections),i=new Map(o.clauses);return i.delete(n),s.set(t,Object.assign(Object.assign({},o),{clauses:i})),{selections:s}})},setResolution(t,n){e(e=>{const o=new Map(e.selections),s=pe(o,t);return o.set(t,Object.assign(Object.assign({},s),{resolution:n})),{selections:o}})},clearSelection(t){e(e=>{const n=new Map(e.selections),o=n.get(t);return o&&n.set(t,Object.assign(Object.assign({},o),{clauses:new Map})),{selections:n}})}}));function ge(t){const n=e.useId(),o=t.clientId||n,{name:s}=t,i=ye(e=>e.selections.get(s)),r=ye(e=>e.setClause),l=ye(e=>e.clearClause),a=e.useMemo(()=>!!i&&i.clauses.size>0,[i]);return{predicate:e.useMemo(()=>i&&0!==i.clauses.size?function(e,t){const n=[];for(const[o,s]of e.clauses)"crossfilter"===e.resolution&&o===t||n.push(fe(s));return 0===n.length?()=>!0:"intersect"===e.resolution?e=>n.every(t=>t(e)):e=>n.some(t=>t(e))}(i,o):()=>!0,[i,o]),isActive:a,selectPoints:e.useCallback(e=>{const t={};for(const[n,o]of Object.entries(e))t[n]={type:"point",values:new Set(o)};r(s,{clientId:o,type:"point",fields:t})},[o,s,r]),selectInterval:e.useCallback(e=>{const t={};for(const[n,o]of Object.entries(e))t[n]={type:"interval",range:o};r(s,{clientId:o,type:"interval",fields:t})},[o,s,r]),clear:e.useCallback(()=>{l(s,o)},[l,s,o]),clientId:o}}function be(t){const{name:n,xField:o,yField:s}=t,{predicate:i,isActive:r,selectInterval:l,clear:a}=ge({name:n}),c=o&&s?"xyBrush":o?"xBrush":"yBrush",u=e.useCallback(e=>{if(!e)return void a();const t={};"xyBrush"===c&&Array.isArray(e)&&2===e.length?(o&&(t[o]=[Math.min(e[0][0],e[1][0]),Math.max(e[0][0],e[1][0])]),s&&(t[s]=[Math.min(e[0][1],e[1][1]),Math.max(e[0][1],e[1][1])])):"xBrush"===c&&Array.isArray(e)?o&&(t[o]=[Math.min(...e),Math.max(...e)]):"yBrush"===c&&Array.isArray(e)&&s&&(t[s]=[Math.min(...e),Math.max(...e)]),Object.keys(t).length>0&&l(t)},[c,o,s,l,a]);return{brushInteraction:e.useMemo(()=>({brush:c,during:u,end:u}),[c,u]),predicate:i,isActive:r,clear:a}}const[ve,xe]=he(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const n=e.observations;return n.push(t),n.length>e.maxObservations&&n.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}})),we="#007bff";function ke(e){return"function"==typeof e?e:t=>t[e]}function Ae(t,n,o="category10"){const s=e.useContext(ae);return e.useMemo(()=>{if(n&&"function"!=typeof n)return s&&Object.keys(s).length>0?e=>s[e]||re(t,n,o)(e):re(t,n,o)},[t,n,o,s])}function Ee({selection:t,linkedHover:n,fallbackFields:o=[],unwrapData:s=!1,onObservation:i,chartType:r,chartId:l}){const a=function(e,t){return e?!0===e?{name:"hover",fields:t||[]}:"string"==typeof e?{name:e,fields:t||[]}:{name:e.name||"hover",fields:e.fields}:null}(n,o),c=ge({name:(null==t?void 0:t.name)||"__unused__"}),u=function(t){const n=t.name||"hover",{fields:o}=t,{predicate:s,isActive:i,selectPoints:r,clear:l}=ge({name:n});return{onHover:e.useCallback(e=>{if(!e)return void l();const t={};for(const n of o){const o=e[n];void 0!==o&&(t[n]=[o])}Object.keys(t).length>0&&r(t)},[o,r,l,n]),predicate:s,isActive:i}}({name:(null==a?void 0:a.name)||"hover",fields:(null==a?void 0:a.fields)||o||[]}),h=xe(e=>e.pushObservation),d=t?{isActive:c.isActive,predicate:c.predicate}:null,f=e.useCallback(e=>{var t,o;if(n)if(e){let t=e.data||e.datum||e;Array.isArray(t)&&(t=t[0]),u.onHover(t)}else u.onHover(null);if(i||h){const n={timestamp:Date.now(),chartType:r||"unknown",chartId:l};if(e){let s=e.data||e.datum||e;Array.isArray(s)&&(s=s[0]);const r=Object.assign(Object.assign({},n),{type:"hover",datum:s||{},x:null!==(t=e.x)&&void 0!==t?t:0,y:null!==(o=e.y)&&void 0!==o?o:0});i&&i(r),h&&h(r)}else{const e=Object.assign(Object.assign({},n),{type:"hover-end"});i&&i(e),h&&h(e)}}},[n,u,i,r,l,h]),p=e.useCallback(e=>{var t,n;if(i||h){const o={timestamp:Date.now(),chartType:r||"unknown",chartId:l};if(e){let s=e.data||e.datum||e;Array.isArray(s)&&(s=s[0]);const r=Object.assign(Object.assign({},o),{type:"click",datum:s||{},x:null!==(t=e.x)&&void 0!==t?t:0,y:null!==(n=e.y)&&void 0!==n?n:0});i&&i(r),h&&h(r)}else{const e=Object.assign(Object.assign({},o),{type:"click-end"});i&&i(e),h&&h(e)}}},[i,h,r,l]);return{activeSelectionHook:d,customHoverBehavior:f,customClickBehavior:p}}function Me({data:t,colorBy:n,colorScale:o,showLegend:s,userMargin:i,defaults:r={top:50,bottom:60,left:70,right:40}}){const l=void 0!==s?s:!!n,a=e.useMemo(()=>{if(l&&n)return function({data:e,colorBy:t,colorScale:n,getColor:o,strokeColor:s,strokeWidth:i}){return{legendGroups:[{styleFn:e=>{const t={fill:e.color,stroke:e.color};return void 0!==s&&(t.stroke=s),void 0!==i&&(t.strokeWidth=i),t},type:"fill",items:Array.from(new Set(e.map(e=>"function"==typeof t?t(e):e[t]))).map(s=>{const i=e.find("function"==typeof t?e=>t(e)===s:e=>e[t]===s),r=i?o(i,t,n):n?n(s):"#000000";return{label:s+"",color:r}}),label:""}]}}({data:t,colorBy:n,colorScale:o,getColor:ie})},[l,n,t,o]),c=e.useMemo(()=>{const e=Object.assign(Object.assign({},r),i);return a&&120>e.right&&(e.right=120),e},[r,i,a]);return{legend:a,margin:c}}const Se={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}}};function Oe(e,t,n){var o,s,i,r,l,a;const c=Se[e||"primary"],u="context"===e||"sparkline"===e;return{width:null!==(o=t.width)&&void 0!==o?o:c.width,height:null!==(s=t.height)&&void 0!==s?s:c.height,showAxes:c.showAxes,showGrid:null!==(i=t.showGrid)&&void 0!==i?i:c.showGrid,enableHover:null!==(r=t.enableHover)&&void 0!==r?r:!!t.linkedHover||c.enableHover,showLegend:null!==(l=t.showLegend)&&void 0!==l?l:c.showLegend,showLabels:null!==(a=t.showLabels)&&void 0!==a?a:c.showLabels,title:u?void 0:t.title,xLabel:u?void 0:t.xLabel,yLabel:u?void 0:t.yLabel,categoryLabel:u?void 0:t.categoryLabel,valueLabel:u?void 0:t.valueLabel,marginDefaults:c.marginDefaults}}const Ne={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"8px 12px",borderRadius:"4px",fontSize:"14px",lineHeight:"1.5",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Le(e,t){return"function"==typeof t?t(e):e[t]}function je(e,t){return t?t(e):null==e?"":"number"==typeof e?e.toLocaleString():e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function Ce(e){return!0===e||("function"==typeof e?e:!1!==e&&void 0!==e&&("object"!=typeof e||null===e||!("fields"in e)&&!("title"in e)||function(e={}){const{fields:t,title:n,format:o,style:s={},className:i=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let r;const l=[];if(n){const t=Le(e,n);r=je(t,o)}if(t&&t.length>0)t.forEach(t=>{let n,s,i;"string"==typeof t?(n=t,s=t,i=o):(n=t.label,s=t.accessor||t.key||"",i=t.format||o);const r=Le(e,s);l.push({label:n,value:je(r,i)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){r=je(e[n],o);break}if(!r){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(r=je(e[t[0]],o))}}const c=Object.assign(Object.assign({},Ne),s);return a.createElement("div",{className:("semiotic-tooltip "+i).trim(),style:c},r&&a.createElement("div",{style:{fontWeight:l.length>0?"bold":"normal"}},r),l.map((e,t)=>a.createElement("div",{key:t,style:{marginTop:0===t&&r?"4px":0}},e.label&&a.createElement("span",null,e.label,": "),e.value)))}}(e)))}function _e(e){return"string"==typeof e?e:"value"}function We(e){return t=>{const n=t.data;return n?a.createElement("div",{className:"semiotic-tooltip",style:Ne},e.map((e,t)=>{const o=function(e,t){return"function"==typeof t?t(e):e[t]}(n,e.accessor),s=null==(i=o)?"–":"number"==typeof i?Math.abs(i)>9999?i.toLocaleString():i+"":i instanceof Date?i.toLocaleDateString():i+"";var i;return a.createElement("div",{key:t,style:t>0?{marginTop:2}:void 0},a.createElement("span",{style:{opacity:.8}},e.label,": "),a.createElement("span",{style:{fontWeight:"color"===e.role||"group"===e.role?"bold":"normal"}},s))})):null}}function Be({componentName:e,message:t,width:n,height:o}){return a.createElement("div",{role:"alert",style:{width:n,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"}},a.createElement("div",{style:{textAlign:"center",maxWidth:400}},a.createElement("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"}},e),a.createElement("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5}},t)))}class $e extends a.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){var n,o;null===(o=(n=this.props).onError)||void 0===o||o.call(n,e,t)}render(){if(this.state.error){const{fallback:e}=this.props,t=this.state.error;return"function"==typeof e?e(t):void 0!==e?e:a.createElement(Be,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}}var He;const ze="undefined"!=typeof process&&"production"!==(null===(He=process.env)||void 0===He?void 0:He.NODE_ENV);function Te({componentName:e,width:t,height:n,children:o}){return a.createElement($e,{fallback:o=>a.createElement(Be,{componentName:e,message:o.message,width:t,height:n})},o)}function Fe(e,t,n,o){if(!ze)return;if(!t||0===t.length)return;if("string"!=typeof o)return;const s=t[0];if(!s||"object"!=typeof s)return;if(o in s)return;const i=Object.keys(s).join(", ");console.warn(`[semiotic] ${e}: ${n} "${o}" not found in data. Available keys: ${i}`)}function Pe(e,t){if(0===t.length)return null;const n=e.toLowerCase();return t.find(e=>e.toLowerCase().includes(n)||n.includes(e.toLowerCase()))||t[0]}function Ie({componentName:e,data:t,accessors:n,requiredProps:o}){if(o)for(const[t,n]of Object.entries(o))if(null==n)return`${e}: ${t} is required. Provide a field name or function.`;if(!t||!Array.isArray(t)||0===t.length)return e+": No data provided. Pass a non-empty array to the data prop.";if(!Array.isArray(t)&&"object"==typeof t)return e+": data should be an array, but received an object. If this is hierarchical data, use TreeDiagram, Treemap, or CirclePack instead.";if(n){const o=function(e){return e.length>3?[e[0],e[Math.floor(e.length/2)],e[e.length-1]]:e}(t).find(e=>e&&"object"==typeof e);if(o){const t=Object.keys(o);for(const[s,i]of Object.entries(n))if(i&&"string"==typeof i&&!(i in o)){const n=Pe(i,t),o=n?` Try ${s}="${n}".`:"";return`${e}: ${s} "${i}" not found in data. Available fields: ${t.join(", ")}.${o}`}}}return null}const De="__forecastSegment";function Re(e,t){return"function"==typeof t?t(e):!!e[t]}function Ge(t){var n,o;const s=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:i,margin:r,className:l,xFormat:c,yFormat:u,xAccessor:h="x",yAccessor:d="y",lineBy:f,lineDataAccessor:p="coordinates",colorBy:m,colorScheme:y="category10",curve:g="linear",showPoints:b=!1,pointRadius:v=3,fillArea:x=!1,areaOpacity:w=.3,lineWidth:k=2,tooltip:A,pointIdAccessor:E,annotations:M,anomaly:S,forecast:O,frameProps:N={},selection:L,linkedHover:j,onObservation:C,chartId:_}=t,W=s.width,B=s.height,$=s.enableHover,H=s.showGrid,z=s.showLegend,T=s.title,F=s.xLabel,P=s.yLabel,I=i||[];Fe("LineChart",I,"xAccessor",h),Fe("LineChart",I,"yAccessor",d);const D="string"==typeof h?h:"x",R="string"==typeof d?d:"y",G=e.useMemo(()=>O?function(e,t,n,o,s){return(i=o).isTraining||i.isForecast||i.isAnomaly||i.upperBounds||i.lowerBounds?function(e,t,n,o,s){var i,r,l;const{isTraining:a,isForecast:c,isAnomaly:u,upperBounds:h,lowerBounds:d,color:f="#6366f1",bandOpacity:p=.15,anomalyColor:m="#ef4444",anomalyRadius:y=6,label:g}=o,b=e.map(e=>{let t="observed";return c&&Re(e,c)?t="forecast":a&&Re(e,a)&&(t="training"),Object.assign(Object.assign({},e),{[De]:t})}),v=[];if(h&&d){const e="string"==typeof h?h:"__envUpper",t="string"==typeof d?d:"__envLower";if("function"==typeof h||"function"==typeof d)for(const n of b)"function"==typeof h&&(n[e]=h(n)),"function"==typeof d&&(n[t]=d(n));v.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:f,fillOpacity:p,label:g})}return u&&v.push({type:"highlight",filter:e=>Re(e,u),color:m,r:y,style:{stroke:m,strokeWidth:1.5,fill:m,fillOpacity:.7}}),s&&v.push({type:"anomaly-band",threshold:null!==(i=s.threshold)&&void 0!==i?i:2,showBand:!1!==s.showBand,fill:s.bandColor||"#6366f1",fillOpacity:null!==(r=s.bandOpacity)&&void 0!==r?r:.1,anomalyColor:s.anomalyColor||"#ef4444",anomalyRadius:null!==(l=s.anomalyRadius)&&void 0!==l?l:6,label:s.label}),{processedData:b,annotations:v}}(e,0,0,o,s):function(e,t,n,o,s){var i,r,l;const{trainEnd:a,steps:c=10,confidence:u=.95,color:h="#6366f1",bandOpacity:d=.15,label:f}=o;if(null==a)return{processedData:e,annotations:[]};const p=[],m=[];for(const n of e)n[t]>a?m.push(Object.assign(Object.assign({},n),{[De]:"observed"})):p.push(Object.assign(Object.assign({},n),{[De]:"training"}));const y=p.map(e=>[e[t],e[n]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),g=[],b=[];if(y.length>=3){const o=y.length;let s=0,i=0,r=0,l=0;for(const[e,t]of y)s+=e,i+=t,r+=e*e,l+=e*t;const a=o*r-s*s;if(Math.abs(a)>1e-12){const r=(o*l-s*i)/a,p=(i-r*s)/o,m=e=>p+r*e,v=y.map(([e,t])=>t-m(e)).reduce((e,t)=>e+t*t,0),x=Math.sqrt(v/Math.max(o-2,1)),w=y.reduce((e,t)=>e+t[0],0)/o,k=y.reduce((e,t)=>e+Math.pow(t[0]-w,2),0),A=.99>u?.95>u?.9>u?1:1.645:1.96:2.576,E=e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e)),M=Math.max(...E),S=y.length>1?(y[o-1][0]-y[0][0])/(o-1):1;for(let e=1;c>=e;e++){const s=M+e*S,i=m(s),r=x*Math.sqrt(1+1/o+(k>0?Math.pow(s-w,2)/k:0))*A;b.push({[t]:s,[n]:i,[De]:"forecast",__forecastUpper:i+r,__forecastLower:i-r})}g.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:h,fillOpacity:d,label:f})}}return g.push({type:"x-threshold",x:a,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),s&&g.push({type:"anomaly-band",threshold:null!==(i=s.threshold)&&void 0!==i?i:2,showBand:!1!==s.showBand,fill:s.bandColor||"#6366f1",fillOpacity:null!==(r=s.bandOpacity)&&void 0!==r?r:.1,anomalyColor:s.anomalyColor||"#ef4444",anomalyRadius:null!==(l=s.anomalyRadius)&&void 0!==l?l:6,label:s.label}),{processedData:[...p,...m,...b],annotations:g}}(e,t,n,o,s);var i}(I,D,R,O,S):null,[I,O,S,D,R]),Y=e.useMemo(()=>G?G.annotations:S?function(e){var t,n,o;return[{type:"anomaly-band",threshold:null!==(t=e.threshold)&&void 0!==t?t:2,showBand:!1!==e.showBand,fill:e.bandColor||"#6366f1",fillOpacity:null!==(n=e.bandOpacity)&&void 0!==n?n:.1,anomalyColor:e.anomalyColor||"#ef4444",anomalyRadius:null!==(o=e.anomalyRadius)&&void 0!==o?o:6,label:e.label}]}(S):[],[G,S]),X=G?G.processedData:I,q=O&&!f?De:f,{activeSelectionHook:V,customHoverBehavior:U}=Ee({selection:L,linkedHover:j,fallbackFields:m?["string"==typeof m?m:""]:[],onObservation:C,chartType:"LineChart",chartId:_}),Z=void 0!==(null===(n=X[0])||void 0===n?void 0:n[p]),J=e.useMemo(()=>{if(Z)return X;if(q){const e=X.reduce((e,t)=>{const n="function"==typeof q?q(t):t[q];if(!e[n]){const t={[p]:[]};"string"==typeof q&&(t[q]=n),e[n]=t}return e[n][p].push(t),e},{});return Object.values(e)}return[{[p]:X}]},[X,q,p,Z]),K=Ae(X,m,y),Q=e.useMemo(()=>e=>{const t={strokeWidth:k};return t.stroke=m?ie(e,m,K):we,x&&(t.fill=t.stroke,t.fillOpacity=w),t},[m,K,k,x,w]),ee=e.useMemo(()=>O?function(e,t){var n,o;const s=null!==(n=t.trainDasharray)&&void 0!==n?n:"8,4",i=null!==(o=t.forecastDasharray)&&void 0!==o?o:"4,4",r=t.color||"#6366f1";return t=>{const n=e(t),o=t[De];return"training"===o?Object.assign(Object.assign({},n),{strokeDasharray:s}):"forecast"===o?Object.assign(Object.assign({},n),{stroke:r,strokeDasharray:i}):n}}(Q,O):Q,[Q,O]),te=e.useMemo(()=>ue(ee,V,L),[ee,V,L]),oe=e.useMemo(()=>{if(b)return e=>{const t={r:v,fillOpacity:1};return t.fill=m?ie(e.parentLine||e,m,K):we,t}},[b,v,m,K]),se=x?"area":"line",{legend:re,margin:le}=Me({data:J,colorBy:m,colorScale:K,showLegend:z,userMargin:r,defaults:s.marginDefaults}),ae=f||m,ce=e.useMemo(()=>We([{label:F||_e(h),accessor:h,role:"x"},{label:P||_e(d),accessor:d,role:"y"},...ae?[{label:_e(ae),accessor:ae,role:"group"}]:[]]),[h,d,F,P,ae]),he=Ie({componentName:"LineChart",data:Z?(null===(o=X[0])||void 0===o?void 0:o[p])||[]:I,accessors:{xAccessor:h,yAccessor:d}});if(he)return a.createElement(Be,{componentName:"LineChart",message:he,width:W,height:B});const de=e.useMemo(()=>Z||q?J.flatMap(e=>{const t=e[p]||[];return q&&"string"==typeof q?t.map(t=>Object.assign(Object.assign({},t),{[q]:e[q]})):t}):X,[J,p,Z,q,X]),fe=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:se,data:de,xAccessor:h,yAccessor:d,groupAccessor:q||void 0,curve:g,lineStyle:te},b&&{pointStyle:oe}),{size:[W,B],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:le,showAxes:s.showAxes,xLabel:F,yLabel:P,xFormat:c,yFormat:u,enableHover:$,showGrid:H}),re&&{legend:re}),T&&{title:T}),l&&{className:l}),{tooltipContent:A?Ce(A):ce}),(j||C)&&{customHoverBehavior:U}),E&&{pointIdAccessor:E}),((null==M?void 0:M.length)||Y.length)&&{annotations:[...M||[],...Y]}),N);return a.createElement(Te,{componentName:"LineChart",width:W,height:B},a.createElement(ne,Object.assign({},fe)))}function Ye(t){var n;const o=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:r,xFormat:l,yFormat:c,xAccessor:u="x",yAccessor:h="y",areaBy:d,y0Accessor:f,gradientFill:p=!1,lineDataAccessor:m="coordinates",colorBy:y,colorScheme:g="category10",curve:b="monotoneX",areaOpacity:v=.7,showLine:x=!0,lineWidth:w=2,tooltip:k,annotations:A,frameProps:E={},selection:M,linkedHover:S,onObservation:O,chartId:N}=t,L=o.width,j=o.height,C=o.enableHover,_=o.showGrid,W=o.showLegend,B=o.title,$=o.xLabel,H=o.yLabel,z=s||[];Fe("AreaChart",z,"xAccessor",u),Fe("AreaChart",z,"yAccessor",h);const{activeSelectionHook:T,customHoverBehavior:F}=Ee({selection:M,linkedHover:S,fallbackFields:y?["string"==typeof y?y:""]:[],onObservation:O,chartType:"AreaChart",chartId:N}),P=void 0!==(null===(n=z[0])||void 0===n?void 0:n[m]),I=e.useMemo(()=>{if(P)return z;if(d){const e=z.reduce((e,t)=>{const n="function"==typeof d?d(t):t[d];if(!e[n]){const t={[m]:[]};"string"==typeof d&&(t[d]=n),e[n]=t}return e[n][m].push(t),e},{});return Object.values(e)}return[{[m]:z}]},[z,d,m,P]),D=Ae(z,y,g),R=e.useMemo(()=>e=>{const t={},n=y?ie(e,y,D):we;return t.fill=n,t.fillOpacity=v,x?(t.stroke=n,t.strokeWidth=w):t.stroke="none",t},[y,D,v,x,w]),G=e.useMemo(()=>ue(R,T,M),[R,T,M]),{legend:Y,margin:X}=Me({data:I,colorBy:y,colorScale:D,showLegend:W,userMargin:i,defaults:o.marginDefaults}),q=d||y,V=e.useMemo(()=>We([{label:$||_e(u),accessor:u,role:"x"},{label:H||_e(h),accessor:h,role:"y"},...q?[{label:_e(q),accessor:q,role:"group"}]:[]]),[u,h,$,H,q]),U=Ie({componentName:"AreaChart",data:z,accessors:{xAccessor:u,yAccessor:h}});if(U)return a.createElement(Be,{componentName:"AreaChart",message:U,width:L,height:j});const Z=e.useMemo(()=>P||d?I.flatMap(e=>{const t=e[m]||[];return d&&"string"==typeof d?t.map(t=>Object.assign(Object.assign({},t),{[d]:e[d]})):t}):z,[I,m,P,d,z]),J=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"area",data:Z,xAccessor:u,yAccessor:h,groupAccessor:d||void 0},f&&{y0Accessor:f}),p&&{gradientFill:p}),{curve:b,lineStyle:G,size:[L,j],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:X,showAxes:o.showAxes,xLabel:$,yLabel:H,xFormat:l,yFormat:c,enableHover:C,showGrid:_}),Y&&{legend:Y}),B&&{title:B}),r&&{className:r}),{tooltipContent:k?Ce(k):V}),(S||O)&&{customHoverBehavior:F}),A&&A.length>0&&{annotations:A}),E);return a.createElement(Te,{componentName:"AreaChart",width:L,height:j},a.createElement(ne,Object.assign({},J)))}function Xe(t){var n;const o=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:r,xFormat:l,yFormat:c,xAccessor:u="x",yAccessor:h="y",areaBy:d,lineDataAccessor:f="coordinates",colorBy:p,colorScheme:m="category10",curve:y="monotoneX",areaOpacity:g=.7,showLine:b=!0,lineWidth:v=2,normalize:x=!1,tooltip:w,annotations:k,frameProps:A={},selection:E,linkedHover:M,onObservation:S,chartId:O}=t,N=o.width,L=o.height,j=o.enableHover,C=o.showGrid,_=o.showLegend,W=o.title,B=o.xLabel,$=o.yLabel,H=s||[],{activeSelectionHook:z,customHoverBehavior:T}=Ee({selection:E,linkedHover:M,fallbackFields:p?["string"==typeof p?p:""]:[],onObservation:S,chartType:"StackedAreaChart",chartId:O}),F=void 0!==(null===(n=H[0])||void 0===n?void 0:n[f]),P=e.useMemo(()=>{if(F)return H;if(d){const e=H.reduce((e,t)=>{const n="function"==typeof d?d(t):t[d];if(!e[n]){const t={[f]:[]};"string"==typeof d&&(t[d]=n),e[n]=t}return e[n][f].push(t),e},{});return Object.values(e)}return[{[f]:H}]},[H,d,f,F]),I=Ae(H,p,m),D=e.useMemo(()=>e=>{const t={},n=p?ie(e,p,I):we;return t.fill=n,t.fillOpacity=g,b?(t.stroke=n,t.strokeWidth=v):t.stroke="none",t},[p,I,g,b,v]),R=e.useMemo(()=>ue(D,z,E),[D,z,E]),{legend:G,margin:Y}=Me({data:P,colorBy:p,colorScale:I,showLegend:_,userMargin:i,defaults:o.marginDefaults}),X=d||p,q=e.useMemo(()=>We([{label:B||_e(u),accessor:u,role:"x"},{label:$||_e(h),accessor:h,role:"y"},...X?[{label:_e(X),accessor:X,role:"group"}]:[]]),[u,h,B,$,X]),V=Ie({componentName:"StackedAreaChart",data:H,accessors:{xAccessor:u,yAccessor:h}});if(V)return a.createElement(Be,{componentName:"StackedAreaChart",message:V,width:N,height:L});const U=e.useMemo(()=>F||d?P.flatMap(e=>{const t=e[f]||[];return d&&"string"==typeof d?t.map(t=>Object.assign(Object.assign({},t),{[d]:e[d]})):t}):H,[P,f,F,d,H]),Z=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"stackedarea",data:U,xAccessor:u,yAccessor:h,groupAccessor:d||void 0,curve:y,normalize:x,lineStyle:R,size:[N,L],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:Y,showAxes:o.showAxes,xLabel:B,yLabel:$,xFormat:l,yFormat:c,enableHover:j,showGrid:C},G&&{legend:G}),W&&{title:W}),r&&{className:r}),{tooltipContent:w?Ce(w):q}),(M||S)&&{customHoverBehavior:T}),k&&k.length>0&&{annotations:k}),A);return a.createElement(Te,{componentName:"StackedAreaChart",width:N,height:L},a.createElement(ne,Object.assign({},Z)))}function qe(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,margin:s,className:i,xFormat:r,yFormat:l,xAccessor:c="x",yAccessor:u="y",colorBy:h,colorScheme:d="category10",sizeBy:f,sizeRange:p=[3,15],pointRadius:m=5,pointOpacity:y=.8,tooltip:g,marginalGraphics:b,pointIdAccessor:v,annotations:x,frameProps:w={},selection:k,linkedHover:A,linkedBrush:E,onObservation:M,chartId:S}=t,O=n.width,N=n.height,L=n.enableHover,j=n.showGrid,C=n.showLegend,_=n.title,W=n.xLabel,B=n.yLabel,$=o||[];Fe("Scatterplot",$,"xAccessor",c),Fe("Scatterplot",$,"yAccessor",u);const{activeSelectionHook:H,customHoverBehavior:z}=Ee({selection:k,linkedHover:A,fallbackFields:h?["string"==typeof h?h:""]:[],onObservation:M,chartType:"Scatterplot",chartId:S}),T=ce(E);be({name:(null==T?void 0:T.name)||"__unused_brush__",xField:(null==T?void 0:T.xField)||("string"==typeof c?c:void 0),yField:(null==T?void 0:T.yField)||("string"==typeof u?u:void 0)});const F=Ae($,h,d),P=e.useMemo(()=>{if(!f||0===$.length)return;const e=$.map(e=>"function"==typeof f?f(e):e[f]);return[Math.min(...e),Math.max(...e)]},[$,f]),I=e.useMemo(()=>e=>{const t={fillOpacity:y};return t.fill=h?ie(e,h,F):we,t.r=f?le(e,f,p,P):m,t},[h,F,f,p,P,m,y]),D=e.useMemo(()=>ue(I,H,k),[I,H,k]),{legend:R,margin:G}=Me({data:$,colorBy:h,colorScale:F,showLegend:C,userMargin:s,defaults:n.marginDefaults}),Y=e.useMemo(()=>We([{label:W||_e(c),accessor:c,role:"x"},{label:B||_e(u),accessor:u,role:"y"},...h?[{label:_e(h),accessor:h,role:"color"}]:[],...f?[{label:_e(f),accessor:f,role:"size"}]:[]]),[c,u,W,B,h,f]),X=Ie({componentName:"Scatterplot",data:$,accessors:{xAccessor:c,yAccessor:u}});if(X)return a.createElement(Be,{componentName:"Scatterplot",message:X,width:O,height:N});const q=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"scatter",data:$,xAccessor:c,yAccessor:u,colorAccessor:h||void 0,sizeAccessor:f||void 0,sizeRange:p,pointStyle:D,colorScheme:d,size:[O,N],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:G,showAxes:n.showAxes,xLabel:W,yLabel:B,xFormat:r,yFormat:l,enableHover:L,showGrid:j},R&&{legend:R}),_&&{title:_}),i&&{className:i}),{tooltipContent:g?Ce(g):Y}),(A||M)&&{customHoverBehavior:z}),b&&{marginalGraphics:b}),v&&{pointIdAccessor:v}),x&&x.length>0&&{annotations:x}),w);return a.createElement(Te,{componentName:"Scatterplot",width:O,height:N},a.createElement(ne,Object.assign({},q)))}function Ve(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,className:s,xFormat:i,yFormat:l,xAccessor:c="x",yAccessor:u="y",orderAccessor:h,orderLabel:d,pointRadius:f=4,tooltip:p,pointIdAccessor:m,annotations:y,frameProps:g={},selection:b,linkedHover:v,onObservation:x,chartId:w}=t,k=n.width,A=n.height,E=n.enableHover,M=n.showGrid,S=n.title,O=n.xLabel,N=n.yLabel,L=o||[],j=e.useMemo(()=>{if(!h||0===L.length)return L;const e="function"==typeof h?h:e=>e[h];return[...L].sort((t,n)=>{const o=e(t),s=e(n);return(o instanceof Date?o.getTime():+o)-(s instanceof Date?s.getTime():+s)})},[L,h]);Fe("ConnectedScatterplot",j,"xAccessor",c),Fe("ConnectedScatterplot",j,"yAccessor",u);const{activeSelectionHook:C,customHoverBehavior:_}=Ee({selection:b,linkedHover:v,fallbackFields:[],onObservation:x,chartType:"ConnectedScatterplot",chartId:w}),W=j.length,B=W>0&&100>W,$=e.useMemo(()=>0===W?[]:j.map((e,t)=>r.interpolateViridis(1===W?.5:t/(W-1))),[j,W]);e.useMemo(()=>null,[W]);const H=e.useMemo(()=>{if(W>=2)return(e,t,n)=>{var o,s;if("connected-lines"!==e.type)return null;const i=n.scales;if(!i)return null;const r=null!==(o=i.x)&&void 0!==o?o:i.time,l=null!==(s=i.y)&&void 0!==s?s:i.value;if(!r||!l)return null;const h="string"==typeof c?e=>e[c]:c,d="string"==typeof u?e=>e[u]:u,p=[];for(let e=0;j.length-1>e;e++){const t=j[e],n=j[e+1],o=r(h(t)),s=l(d(t)),i=r(h(n)),c=l(d(n)),u=$[e];B&&p.push(a.createElement("line",{key:"halo-"+e,x1:o,y1:s,x2:i,y2:c,stroke:"white",strokeWidth:f+2,strokeOpacity:.5,strokeLinecap:"round"})),p.push(a.createElement("line",{key:"conn-"+e,x1:o,y1:s,x2:i,y2:c,stroke:u,strokeWidth:f,strokeLinecap:"round"}))}return a.createElement("g",{key:"ann-"+t},p)}},[j,$,f,B,c,u,W]),z=e.useMemo(()=>e=>{const t=j.indexOf(e);return{fill:t>=0&&$.length>t?$[t]:"#6366f1",stroke:"white",strokeWidth:1,r:f,fillOpacity:1}},[j,$,f]),T=e.useMemo(()=>ue(z,C,b),[z,C,b]),F=Object.assign({top:50,right:40,bottom:60,left:70},t.margin),P=d||("string"==typeof h?h:"Order"),I=e.useMemo(()=>We([{label:O||_e(c),accessor:c,role:"x"},{label:N||_e(u),accessor:u,role:"y"},...h?[{label:P,accessor:h,role:"group"}]:[]]),[c,u,O,N,h,P]),D=Ie({componentName:"ConnectedScatterplot",data:j,accessors:{xAccessor:c,yAccessor:u}});if(D)return a.createElement(Be,{componentName:"ConnectedScatterplot",message:D,width:k,height:A});const R=e.useMemo(()=>[{type:"connected-lines"},...y||[]],[y]),G=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"scatter",data:j,xAccessor:c,yAccessor:u,pointStyle:T,size:[k,A],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:F,showAxes:n.showAxes,xLabel:O,yLabel:N,xFormat:i,yFormat:l,enableHover:E,showGrid:M},S&&{title:S}),s&&{className:s}),{tooltipContent:p?Ce(p):I}),(v||x)&&{customHoverBehavior:_}),m&&{pointIdAccessor:m}),{annotations:R,svgAnnotationRules:H}),g);return a.createElement(Te,{componentName:"ConnectedScatterplot",width:k,height:A},a.createElement(ne,Object.assign({},G)))}function Ue(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:o,margin:s,className:i,xFormat:r,yFormat:l,xAccessor:c="x",yAccessor:u="y",sizeBy:h,sizeRange:d=[5,40],colorBy:f,colorScheme:p="category10",bubbleOpacity:m=.6,bubbleStrokeWidth:y=1,bubbleStrokeColor:g="white",tooltip:b,marginalGraphics:v,pointIdAccessor:x,annotations:w,frameProps:k={},selection:A,linkedHover:E,linkedBrush:M,onObservation:S,chartId:O}=t,N=n.width,L=n.height,j=n.enableHover,C=n.showGrid,_=n.showLegend,W=n.title,B=n.xLabel,$=n.yLabel,H=o||[],{activeSelectionHook:z,customHoverBehavior:T}=Ee({selection:A,linkedHover:E,fallbackFields:f?["string"==typeof f?f:""]:[],onObservation:S,chartType:"BubbleChart",chartId:O}),F=ce(M);be({name:(null==F?void 0:F.name)||"__unused_brush__",xField:(null==F?void 0:F.xField)||("string"==typeof c?c:void 0),yField:(null==F?void 0:F.yField)||("string"==typeof u?u:void 0)});const P=Ae(H,f,p),I=e.useMemo(()=>{const e=H.map(e=>"function"==typeof h?h(e):e[h]);return[Math.min(...e),Math.max(...e)]},[H,h]),D=e.useMemo(()=>e=>{const t={fillOpacity:m,strokeWidth:y,stroke:g};return t.fill=f?ie(e,f,P):we,t.r=le(e,h,d,I),t},[f,P,h,d,I,m,y,g]),R=e.useMemo(()=>ue(D,z,A),[D,z,A]),{legend:G,margin:Y}=Me({data:H,colorBy:f,colorScale:P,showLegend:_,userMargin:s,defaults:n.marginDefaults}),X=e.useMemo(()=>We([{label:B||_e(c),accessor:c,role:"x"},{label:$||_e(u),accessor:u,role:"y"},{label:_e(h),accessor:h,role:"size"},...f?[{label:_e(f),accessor:f,role:"color"}]:[]]),[c,u,B,$,h,f]),q=Ie({componentName:"BubbleChart",data:H,accessors:{xAccessor:c,yAccessor:u},requiredProps:{sizeBy:h}});if(q)return a.createElement(Be,{componentName:"BubbleChart",message:q,width:N,height:L});const V=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"bubble",data:H,xAccessor:c,yAccessor:u,colorAccessor:f||void 0,sizeAccessor:h,sizeRange:d,pointStyle:R,colorScheme:p,size:[N,L],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:Y,showAxes:n.showAxes,xLabel:B,yLabel:$,xFormat:r,yFormat:l,enableHover:j,showGrid:C},G&&{legend:G}),W&&{title:W}),i&&{className:i}),{tooltipContent:b?Ce(b):X}),(E||S)&&{customHoverBehavior:T}),v&&{marginalGraphics:v}),x&&{pointIdAccessor:x}),w&&w.length>0&&{annotations:w}),k);return a.createElement(Te,{componentName:"BubbleChart",width:N,height:L},a.createElement(ne,Object.assign({},V)))}function Ze(t){const n=Oe(t.mode,{width:t.width,height:t.height,showGrid:void 0,enableHover:t.enableHover,showLegend:void 0,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel}),{data:s,margin:i,className:l,xAccessor:c="x",yAccessor:u="y",valueAccessor:h="value",xFormat:d,yFormat:f,colorScheme:p="blues",customColorScale:m,showValues:y=!1,valueFormat:g,cellBorderColor:b="#fff",cellBorderWidth:v=1,tooltip:x,annotations:w,frameProps:k={},selection:A,linkedHover:E,onObservation:M,chartId:S}=t,O=n.width,N=n.height,L=n.enableHover,j=n.title,C=n.xLabel,_=n.yLabel,W=s||[],{margin:B}=Me({data:W,colorBy:void 0,colorScale:void 0,showLegend:!1,userMargin:i,defaults:n.marginDefaults}),{activeSelectionHook:$,customHoverBehavior:H}=Ee({selection:A,linkedHover:E,fallbackFields:[],onObservation:M,chartType:"Heatmap",chartId:S}),z=e.useMemo(()=>"function"==typeof h?e=>h(e):e=>e[h],[h]),T=e.useMemo(()=>{const e=W.map(z);return[Math.min(...e),Math.max(...e)]},[W,z]),F=e.useMemo(()=>"custom"===p&&m?m:o.scaleSequential({blues:r.interpolateBlues,reds:r.interpolateReds,greens:r.interpolateGreens,viridis:r.interpolateViridis}[p]||r.interpolateBlues).domain(T),[p,m,T]);e.useMemo(()=>{const e=ke(c),t=ke(u);return{xBinCount:new Set(W.map(e)).size,yBinCount:new Set(W.map(t)).size}},[W,c,u]),e.useMemo(()=>({coordinates:W}),[W]);const P=e.useMemo(()=>e=>{const t=z(e);return{fill:F(t),stroke:b,strokeWidth:v}},[z,F,b,v]);e.useMemo(()=>ue(P,$,A),[P,$,A]),e.useMemo(()=>{if(!y)return;const e=(T[0]+T[1])/2;return(t,n)=>{const o=z(t),s=g?g(o):o+"";return a.createElement("text",{textAnchor:"middle",dominantBaseline:"middle",fill:z(t)>e?"#fff":"#000",fontSize:"12px"},s)}},[y,z,g,T]);const I=e.useMemo(()=>We([{label:C||_e(c),accessor:c,role:"x"},{label:_||_e(u),accessor:u,role:"y"},{label:_e(h),accessor:h,role:"value"}]),[c,u,C,_,h]),D=Ie({componentName:"Heatmap",data:W,accessors:{xAccessor:c,yAccessor:u,valueAccessor:h}});if(D)return a.createElement(Be,{componentName:"Heatmap",message:D,width:O,height:N});const R=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:"heatmap",data:W,xAccessor:c,yAccessor:u,valueAccessor:h,size:[O,N],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:B,showAxes:n.showAxes,xLabel:C,yLabel:_,xFormat:d,yFormat:f,enableHover:L},j&&{title:j}),l&&{className:l}),{tooltipContent:x?Ce(x):I}),(E||M)&&{customHoverBehavior:H}),w&&w.length>0&&{annotations:w}),k);return a.createElement(Te,{componentName:"Heatmap",width:O,height:N},a.createElement(ne,Object.assign({},R)))}function Je({selections:t}){const n=ye(e=>e.setResolution);return e.useEffect(()=>{for(const[e,o]of Object.entries(t))o.resolution&&n(e,o.resolution)},[t,n]),null}function Ke({children:e,selections:t}){return a.createElement(me,null,a.createElement(ve,null,t&&a.createElement(Je,{selections:t}),e))}Ge.displayName="LineChart",Ye.displayName="AreaChart",Xe.displayName="StackedAreaChart",qe.displayName="Scatterplot",Ve.displayName="ConnectedScatterplot",Ue.displayName="BubbleChart",Ze.displayName="Heatmap";const Qe="__splomIdx",et={top:4,bottom:4,left:4,right:4};function tt({frameRef:o,cellSize:s,onBrush:i}){const r=e.useRef(null),l=s-et.left-et.right,c=s-et.top-et.bottom;return e.useEffect(()=>{if(!r.current)return;const e=n.select(r.current).select(".brush-g"),s=t.brush().extent([[0,0],[l,c]]).on("brush end",e=>{var t;const n=null===(t=o.current)||void 0===t?void 0:t.getScales();if(!n)return;if(!e.selection)return void i(null);const[[s,r],[l,a]]=e.selection,c=[[n.x.invert(s),n.y.invert(r)],[n.x.invert(l),n.y.invert(a)]];i(c)});return e.call(s),e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.15).attr("stroke","steelblue").attr("stroke-width",1),()=>{s.on("brush end",null)}},[l,c,o,i]),a.createElement("svg",{ref:r,width:s,height:s,style:{position:"absolute",top:0,left:0}},a.createElement("g",{className:"brush-g",transform:`translate(${et.left},${et.top})`}))}function nt({data:t,xField:n,yField:o,cellSize:s,pointRadius:i,pointOpacity:r,colorBy:l,colorScale:c,brushSelectionName:u,hoverSelectionName:h,unselectedOpacity:d,mode:f,onPointHover:p}){const m=e.useRef(null),y=ge({name:u,clientId:`splom-${n}-${o}`}),g=be({name:u,xField:n,yField:o}),b=ge({name:h,clientId:"splom-hover-source"}),v=b.selectPoints,x=e.useCallback(e=>{e?g.brushInteraction.during(e):g.brushInteraction.end(null)},[g.brushInteraction]),w=e.useCallback(e=>{if(!e)return void(null==p||p(null));const t=e.data,n=null==t?void 0:t[Qe];void 0!==n&&(v({[Qe]:[n]}),null==p||p(t,e.x+et.left,e.y+et.top))},[v,p]),k=e.useCallback(e=>{const t={opacity:r,r:i};return t.fill=l?ie(e,l,c):we,"hover"===f?b.isActive&&b.predicate(e)?(t.opacity=1,t.r=2.5*i,t.stroke="#333",t.strokeWidth=1.5):b.isActive&&(t.opacity=.6*r):y.isActive&&!y.predicate(e)&&(t.opacity=d),t},[l,c,r,i,f,y.isActive,y.predicate,b.isActive,b.predicate,d]);return a.createElement("div",{style:{position:"relative",width:s,height:s}},a.createElement(ne,{ref:m,chartType:"scatter",data:t,size:[s,s],xAccessor:n,yAccessor:o,pointStyle:k,margin:et,showAxes:!1,enableHover:"hover"===f,customHoverBehavior:"hover"===f?w:void 0,tooltipContent:"hover"===f?()=>null:void 0}),"brush"===f&&a.createElement(tt,{frameRef:m,cellSize:s,xField:n,yField:o,onBrush:x}))}function ot({data:t,field:n,label:o,cellSize:s,bins:i,brushSelectionName:r,hoverSelectionName:l,mode:c}){const u=ge({name:r,clientId:"splom-diag-"+n}),h=ge({name:l,clientId:`splom-diag-${n}-hover`}),d="hover"===c?h:u,f=d.isActive,p=d.predicate,m=e.useMemo(()=>{const e=t.map(e=>e[n]).filter(e=>null!=e&&!isNaN(e));if(0===e.length)return{bars:[],selectedBars:[],max:0};const o=Math.min(...e),r=(Math.max(...e)-o)/i||1,l=Array(i).fill(0),a=Array(i).fill(0);for(const e of t){const t=e[n];if(null==t||isNaN(t))continue;const s=Math.min(Math.floor((t-o)/r),i-1);l[s]++,f&&!p(e)||a[s]++}const c=Math.max(...l,1);return{bars:l.map((e,t)=>({x:t/i*s,w:s/i-1,h:e/c*(s-24),count:e})),selectedBars:a.map((e,t)=>({x:t/i*s,w:s/i-1,h:e/c*(s-24),count:e})),max:c}},[t,n,i,s,f,p]);return a.createElement("svg",{width:s,height:s,style:{overflow:"hidden"}},a.createElement("text",{x:s/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333"},o),m.bars.map((e,t)=>a.createElement("rect",{key:"bg-"+t,x:e.x,y:s-e.h,width:Math.max(e.w,1),height:e.h,fill:"#ccc",opacity:f?.3:.6})),f&&m.selectedBars.map((e,t)=>a.createElement("rect",{key:"sel-"+t,x:e.x,y:s-e.h,width:Math.max(e.w,1),height:e.h,fill:we,opacity:.7})))}function st({label:e,cellSize:t}){return a.createElement("svg",{width:t,height:t},a.createElement("text",{x:t/2,y:t/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333"},e))}function it(t){const{data:n,fields:o,fieldLabels:s={},colorBy:i,colorScheme:r="category10",cellSize:l=150,cellGap:c=4,pointRadius:u=2,pointOpacity:h=.5,diagonal:d="histogram",histogramBins:f=20,brushMode:p="crossfilter",hoverMode:m=!0,unselectedOpacity:y=.1,showGrid:g=!1,tooltip:b,showLegend:v,idAccessor:x,className:w,onObservation:k,chartId:A}=t,E="splom",M="splom-hover",S=m?"hover":p?"brush":"hover",O=ye(e=>e.clearSelection),[N,L]=e.useState(null),j=e.useCallback(()=>{O(M),L(null)},[O,M]),C=e.useMemo(()=>(n||[]).map((e,t)=>void 0!==e[Qe]?e:Object.assign(Object.assign({},e),{[Qe]:t})),[n]),_=Ae(C,i,r),W=void 0!==v?v:!!i,B=e.useMemo(()=>{if(!W||!i)return null;const e="string"==typeof i?i:null;return e?[...new Set(C.map(t=>t[e]))].map(e=>({label:e+"",color:_?_(e+""):we})):null},[W,i,C,_]),$=e.useMemo(()=>({display:"grid",gridTemplateColumns:"40px "+o.map(()=>l+"px").join(" "),gridTemplateRows:o.map(()=>l+"px").join(" ")+" 40px",gap:c+"px",width:"fit-content"}),[o,l,c,40]);return a.createElement("div",{className:w,style:{position:"relative"}},B&&a.createElement("div",{style:{display:"flex",gap:12,marginBottom:8,flexWrap:"wrap"}},B.map(e=>a.createElement("div",{key:e.label,style:{display:"flex",alignItems:"center",gap:4}},a.createElement("span",{style:{display:"inline-block",width:10,height:10,borderRadius:"50%",backgroundColor:e.color}}),a.createElement("span",{style:{fontSize:11}},e.label)))),a.createElement("div",{style:$,onMouseLeave:"hover"===S?j:void 0},o.map((e,t)=>a.createElement(a.Fragment,{key:"row-"+e},a.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",writingMode:"vertical-rl",transform:"rotate(180deg)",fontSize:11,fontWeight:"bold",color:"#333"}},s[e]||e),o.map((n,o)=>t===o?"label"===d?a.createElement(st,{key:"diag-"+e,label:s[e]||e,cellSize:l}):a.createElement(ot,{key:"diag-"+e,data:C,field:e,label:s[e]||e,cellSize:l,bins:f,colorBy:i,colorScale:_,brushSelectionName:E,hoverSelectionName:M,unselectedOpacity:y,mode:S}):a.createElement(nt,{key:`cell-${e}-${n}`,data:C,xField:n,yField:e,fieldLabels:s,cellSize:l,pointRadius:u,pointOpacity:h,colorBy:i,colorScale:_,brushSelectionName:E,hoverSelectionName:M,unselectedOpacity:y,showGrid:g,tooltip:b,mode:S,onPointHover:"hover"===S?(s,i,r)=>{s?(L({datum:s,xField:n,yField:e,colIndex:o,rowIndex:t,px:null!=i?i:0,py:null!=r?r:0}),k&&k({type:"hover",datum:s,x:null!=i?i:0,y:null!=r?r:0,timestamp:Date.now(),chartType:"ScatterplotMatrix",chartId:A})):(L(null),k&&k({type:"hover-end",timestamp:Date.now(),chartType:"ScatterplotMatrix",chartId:A}))}:void 0})))),a.createElement("div",null)," ",o.map(e=>a.createElement("div",{key:"col-label-"+e,style:{display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,fontWeight:"bold",color:"#333"}},s[e]||e))),N&&"hover"===S&&(()=>{const e=N.datum,t=s[N.xField]||N.xField,n=s[N.yField]||N.yField,o=i?"function"==typeof i?i(e):e[i]:null,r=x?"function"==typeof x?x(e):e[x]:"Row "+e[Qe];return a.createElement("div",{style:{position:"absolute",left:40+N.colIndex*(l+c)+N.px,top:N.rowIndex*(l+c)+N.py-8,transform:"translate(-50%, -100%)",color:"#333",background:"rgba(255,255,255,0.95)",border:"1px solid #ddd",borderRadius:3,padding:"4px 8px",fontSize:11,lineHeight:1.4,whiteSpace:"nowrap",pointerEvents:"none",zIndex:10}},a.createElement("div",{style:{fontWeight:"bold",marginBottom:2}},r+""),a.createElement("div",null,t,": ",null!=e[N.xField]?Number(e[N.xField]).toFixed(1):"–"),a.createElement("div",null,n,": ",null!=e[N.yField]?Number(e[N.yField]).toFixed(1):"–"),null!=o&&a.createElement("div",{style:{opacity:.8}},"string"==typeof i?i:"group",": ",o+""))})())}function rt(e){const{brushMode:t="crossfilter",hoverMode:n=!0}=e,o={};return!n&&t&&(o.splom={resolution:t}),n&&(o["splom-hover"]={resolution:"union"}),a.createElement(Ke,{selections:o},a.createElement(it,Object.assign({},e)))}function lt({width:o,height:s,margin:i,scales:r,brushDirection:l,extent:c,onBrush:u}){const h=e.useRef(null),d=e.useRef(null),f=e.useRef(!1),p=o+i.left+i.right,m=s+i.top+i.bottom;return e.useEffect(()=>{if(!h.current||!r)return;const e=n.select(h.current).select(".brush-group"),i="x"===l?t.brushX().extent([[0,0],[o,s]]):t.brushY().extent([[0,0],[o,s]]);return i.on("brush end",e=>{if(f.current)return;if(!e.sourceEvent)return;const t=e.selection;if(!t)return void u(null);const n=("x"===l?r.x:r.y).invert;if(!n)return;const o=[n(t[0]),n(t[1])];u(o)}),e.call(i),d.current=i,e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.2).attr("stroke","steelblue").attr("stroke-width",1),()=>{i.on("brush end",null)}},[r,o,s,l,u]),e.useEffect(()=>{if(!d.current||!r||!h.current)return;const e=n.select(h.current).select(".brush-group"),t="x"===l?r.x:r.y;if(f.current=!0,c){const n=[t(c[0]),t(c[1])];e.call(d.current.move,n)}else e.call(d.current.move,null);f.current=!1},[c,r,l]),a.createElement("svg",{ref:h,width:p,height:m,style:{position:"absolute",top:0,left:0,pointerEvents:"all"}},a.createElement("g",{className:"brush-group",transform:`translate(${i.left},${i.top})`}))}function at(t){var n,o;const{data:s,width:i=600,height:r=400,margin:l,className:c,title:u,xLabel:h,yLabel:d,xFormat:f,yFormat:p,xAccessor:m="x",yAccessor:y="y",lineBy:g,lineDataAccessor:b="coordinates",colorBy:v,colorScheme:x="category10",curve:w="linear",lineWidth:k=2,fillArea:A=!1,areaOpacity:E=.3,showPoints:M=!1,pointRadius:S=3,enableHover:O=!0,showGrid:N=!1,showLegend:L,tooltip:j,minimap:C={},renderBefore:_=!1,onBrush:W,brushExtent:B,frameProps:$={}}=t,H=s||[],[z,T]=e.useState(null),F=null!=B?B:z,P=e.useCallback(e=>{B||T(e),null==W||W(e)},[B,W]),I=e.useRef(null),[D,R]=e.useState(null);e.useEffect(()=>{const e=()=>{var t,n;const o=null===(n=null===(t=I.current)||void 0===t?void 0:t.getScales)||void 0===n?void 0:n.call(t);o?R(o):requestAnimationFrame(e)};requestAnimationFrame(e)},[s]);const G=void 0!==(null===(n=H[0])||void 0===n?void 0:n[b]),Y=e.useMemo(()=>{if(G)return H;if(g){const e=H.reduce((e,t)=>{const n="function"==typeof g?g(t):t[g];if(!e[n]){const t={[b]:[]};"string"==typeof g&&(t[g]=n),e[n]=t}return e[n][b].push(t),e},{});return Object.values(e)}return[{[b]:H}]},[H,g,b,G]),X=e.useMemo(()=>G||g?Y.flatMap(e=>{const t=e[b]||[];return g&&"string"==typeof g?t.map(t=>Object.assign(Object.assign({},t),{[g]:e[g]})):t}):H,[Y,b,G,g,H]),q=Ae(H,v,x),V=e.useMemo(()=>e=>{const t={strokeWidth:k};return t.stroke=v?ie(e,v,q):we,A&&(t.fill=t.stroke,t.fillOpacity=E),t},[v,q,k,A,E]),U=e.useMemo(()=>C.lineStyle?C.lineStyle:e=>{const t={strokeWidth:1};return t.stroke=v?ie(e,v,q):we,t},[v,q,C.lineStyle]),Z=e.useMemo(()=>{if(M)return e=>{const t={r:S,fillOpacity:1};return t.fill=v?ie(e.parentLine||e,v,q):we,t}},[M,S,v,q]),{legend:J,margin:K}=Me({data:Y,colorBy:v,colorScale:q,showLegend:L,userMargin:l}),Q=C.height||60,ee=e.useMemo(()=>{var e,t,n,o,s,i,r,l;return{top:null!==(t=null===(e=C.margin)||void 0===e?void 0:e.top)&&void 0!==t?t:0,bottom:null!==(o=null===(n=C.margin)||void 0===n?void 0:n.bottom)&&void 0!==o?o:20,left:null!==(i=null===(s=C.margin)||void 0===s?void 0:s.left)&&void 0!==i?i:K.left,right:null!==(l=null===(r=C.margin)||void 0===r?void 0:r.right)&&void 0!==l?l:K.right}},[C.margin,K]),te=C.brushDirection||"x",oe=Ie({componentName:"MinimapChart",data:H,accessors:{xAccessor:m,yAccessor:y}});if(oe)return a.createElement(Be,{componentName:"MinimapChart",message:oe,width:i,height:r});const se=A?"area":"line",re=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({chartType:se,data:X,xAccessor:m,yAccessor:y,groupAccessor:g||void 0,curve:w,lineStyle:V},M&&{pointStyle:Z}),{size:[i,r],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:K,showAxes:!0,xLabel:h,yLabel:d,xFormat:f,yFormat:p,enableHover:O,showGrid:N}),J&&{legend:J}),u&&{title:u}),j&&{tooltipContent:Ce(j)}),F&&{xExtent:F}),$),le={chartType:se,data:X,xAccessor:m,yAccessor:y,groupAccessor:g||void 0,curve:w,lineStyle:U,size:[i,Q+ee.top+ee.bottom],margin:ee,showAxes:null!==(o=C.showAxes)&&void 0!==o&&o,background:C.background,enableHover:!1},ae=a.createElement("div",{key:"minimap",style:{position:"relative",width:i,overflow:"hidden"}},a.createElement(ne,Object.assign({ref:I},le)),a.createElement(lt,{width:i-ee.left-ee.right,height:Q,margin:ee,scales:D,brushDirection:te,extent:F,onBrush:P})),ce=a.createElement("div",{key:"main",style:{overflow:"hidden"}},a.createElement(ne,Object.assign({},re)));return a.createElement("div",{className:"minimap-chart"+(c?" "+c:"")},_?ae:ce,_?ce:ae)}rt.displayName="ScatterplotMatrix",at.displayName="MinimapChart",exports.AreaChart=Ye,exports.BubbleChart=Ue,exports.ConnectedScatterplot=Ve,exports.Heatmap=Ze,exports.LineChart=Ge,exports.MinimapChart=at,exports.Scatterplot=qe,exports.ScatterplotMatrix=rt,exports.StackedAreaChart=Xe,exports.StreamXYFrame=ne;