@carbon/charts 1.11.2 → 1.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{_baseEach-477c04db.js → _baseEach-326db134.js} +2 -2
  3. package/dist/{_baseEach-477c04db.js.map → _baseEach-326db134.js.map} +1 -1
  4. package/dist/{_baseEach-05847c57.mjs → _baseEach-9b6a12fa.mjs} +2 -2
  5. package/dist/{_baseEach-05847c57.mjs.map → _baseEach-9b6a12fa.mjs.map} +1 -1
  6. package/dist/angle-utils-264ed176.mjs +840 -0
  7. package/dist/angle-utils-264ed176.mjs.map +1 -0
  8. package/dist/angle-utils-ccc0d890.js +3 -0
  9. package/dist/angle-utils-ccc0d890.js.map +1 -0
  10. package/dist/chart.d.ts +1 -1
  11. package/dist/{choropleth-9a359c3b.mjs → choropleth-141685a0.mjs} +280 -277
  12. package/dist/choropleth-141685a0.mjs.map +1 -0
  13. package/dist/{choropleth-2f8ec4a1.js → choropleth-b1a3729f.js} +9 -9
  14. package/dist/choropleth-b1a3729f.js.map +1 -0
  15. package/dist/color-scale-utils-2cd523be.js +2 -0
  16. package/dist/color-scale-utils-2cd523be.js.map +1 -0
  17. package/dist/color-scale-utils-b9604b2c.mjs +3335 -0
  18. package/dist/color-scale-utils-b9604b2c.mjs.map +1 -0
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/index.mjs +4 -4
  21. package/dist/demo/charts/index.d.ts +9 -6
  22. package/dist/demo/index.js +197 -193
  23. package/dist/demo/index.js.map +1 -1
  24. package/dist/demo/index.mjs +2119 -1592
  25. package/dist/demo/index.mjs.map +1 -1
  26. package/dist/demo/utils/index.d.ts +1 -1
  27. package/dist/demo/utils/package-versions.d.ts +20 -0
  28. package/dist/demo/utils/stackblitz/angular.d.ts +3 -0
  29. package/dist/demo/utils/stackblitz/index.d.ts +5 -0
  30. package/dist/demo/utils/stackblitz/react.d.ts +3 -0
  31. package/dist/demo/utils/stackblitz/svelte.d.ts +3 -0
  32. package/dist/demo/utils/stackblitz/vanilla-js.d.ts +3 -0
  33. package/dist/demo/utils/stackblitz/vue.d.ts +3 -0
  34. package/dist/{index-e425a7b5.mjs → index-4b5d1e49.mjs} +3 -3
  35. package/dist/{index-e425a7b5.mjs.map → index-4b5d1e49.mjs.map} +1 -1
  36. package/dist/{index-4203ca23.js → index-eace9da9.js} +2 -2
  37. package/dist/{index-4203ca23.js.map → index-eace9da9.js.map} +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +126 -125
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/model/index.js +1 -1
  43. package/dist/model/index.js.map +1 -1
  44. package/dist/model/index.mjs +34 -34
  45. package/dist/model/index.mjs.map +1 -1
  46. package/dist/services/index.js +1 -1
  47. package/dist/services/index.mjs +10 -10
  48. package/package.json +5 -5
  49. package/dist/angle-utils-512bc5cd.js +0 -2
  50. package/dist/angle-utils-512bc5cd.js.map +0 -1
  51. package/dist/angle-utils-7255d1d9.mjs +0 -387
  52. package/dist/angle-utils-7255d1d9.mjs.map +0 -1
  53. package/dist/choropleth-2f8ec4a1.js.map +0 -1
  54. package/dist/choropleth-9a359c3b.mjs.map +0 -1
  55. package/dist/color-scale-utils-222feda6.mjs +0 -3815
  56. package/dist/color-scale-utils-222feda6.mjs.map +0 -1
  57. package/dist/color-scale-utils-79786095.js +0 -3
  58. package/dist/color-scale-utils-79786095.js.map +0 -1
  59. package/dist/demo/utils/sandbox.d.ts +0 -36
@@ -1,2 +1,2 @@
1
- "use strict";const n=require("./color-scale-utils-79786095.js"),v=require("./angle-utils-512bc5cd.js"),a=require("./enums-aa2efd99.js"),m=require("d3");function z(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toInteger(e);return isNaN(s)?new Date(NaN):(s&&t.setDate(t.getDate()+s),t)}function B(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toInteger(e);if(isNaN(s))return new Date(NaN);if(!s)return t;var i=t.getDate(),r=new Date(t.getTime());r.setMonth(t.getMonth()+s+1,0);var l=r.getDate();return i>=l?r:(t.setFullYear(r.getFullYear(),r.getMonth(),i),t)}var _=36e5;function Y(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*_)}function Z(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return e.setHours(0,0,0,0),e}var $=864e5;function j(o,e){n.requiredArgs(2,arguments);var t=Z(o),s=Z(e),i=t.getTime()-n.getTimezoneOffsetInMilliseconds(t),r=s.getTime()-n.getTimezoneOffsetInMilliseconds(s);return Math.round((i-r)/$)}var K=6e4;function M(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*K)}function R(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*1e3)}function X(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return B(o,t*12)}function D(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=t.getTime()-s.getTime();return i<0?-1:i>0?1:i}var W=6e4,J=36e5;function Q(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=t.getFullYear()-s.getFullYear(),r=t.getMonth()-s.getMonth();return i*12+r}function ee(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e);return t.getFullYear()-s.getFullYear()}function w(o,e){var t=o.getFullYear()-e.getFullYear()||o.getMonth()-e.getMonth()||o.getDate()-e.getDate()||o.getHours()-e.getHours()||o.getMinutes()-e.getMinutes()||o.getSeconds()-e.getSeconds()||o.getMilliseconds()-e.getMilliseconds();return t<0?-1:t>0?1:t}function te(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=w(t,s),r=Math.abs(j(t,s));t.setDate(t.getDate()-i*r);var l=+(w(t,s)===-i),u=i*(r-l);return u===0?0:u}function I(o,e){return n.requiredArgs(2,arguments),n.toDate(o).getTime()-n.toDate(e).getTime()}var N={ceil:Math.ceil,round:Math.round,floor:Math.floor,trunc:function(e){return e<0?Math.ceil(e):Math.floor(e)}},se="trunc";function L(o){return o?N[o]:N[se]}function ne(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/J;return L(t==null?void 0:t.roundingMethod)(s)}function F(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/W;return L(t==null?void 0:t.roundingMethod)(s)}function ie(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return e.setHours(23,59,59,999),e}function oe(o){n.requiredArgs(1,arguments);var e=n.toDate(o),t=e.getMonth();return e.setFullYear(e.getFullYear(),t+1,0),e.setHours(23,59,59,999),e}function re(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return ie(e).getTime()===oe(e).getTime()}function ae(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=D(t,s),r=Math.abs(Q(t,s)),l;if(r<1)l=0;else{t.getMonth()===1&&t.getDate()>27&&t.setDate(30),t.setMonth(t.getMonth()-i*r);var u=D(t,s)===-i;re(n.toDate(o))&&r===1&&D(o,s)===1&&(u=!1),l=i*(r-Number(u))}return l===0?0:l}function q(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/1e3;return L(t==null?void 0:t.roundingMethod)(s)}function le(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=D(t,s),r=Math.abs(ee(t,s));t.setFullYear(1584),s.setFullYear(1584);var l=D(t,s)===-i,u=i*(r-Number(l));return u===0?0:u}function ue(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return z(o,-t)}function ce(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return B(o,-t)}function ge(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return Y(o,-t)}function V(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return M(o,-t)}function H(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return R(o,-t)}function me(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return X(o,-t)}function k(o){var e=o==null?0:o.length;return e?n.baseFlatten(o,1):[]}class de extends v.Service{zoomIn(e,t,s){let i,r,l;const u=s||n.canvasZoomSettings;e&&(i=e.x,r=e.y,l=2);const{width:c,height:d}=v.DOMUtils.getSVGElementSize(this.services.domUtils.getHolder(),{useClientDimensions:!0});t.transition().duration(u.duration).ease(u.ease).attr("transform",`translate(${c/2}, ${d/2}) scale(${l}) translate(${-i},${-r})`),this.services.events.dispatchEvent(a.Events.CanvasZoom.CANVAS_ZOOM_IN,{element:m.select(e)})}zoomOut(e,t){const s=t||n.canvasZoomSettings;e.transition().duration(s.duration).ease(s.ease).attr("transform",""),this.services.events.dispatchEvent(a.Events.CanvasZoom.CANVAS_ZOOM_OUT)}}class he extends v.Service{init(){this.documentFragment=document.createDocumentFragment()}addEventListener(e,t){this.documentFragment.addEventListener(e,t)}removeEventListener(e,t){this.documentFragment.removeEventListener(e,t)}dispatchEvent(e,t){let s;t?s=new CustomEvent(e,{detail:t}):(s=document.createEvent("Event"),s.initEvent(e,!1,!0)),this.documentFragment.dispatchEvent(s)}}class pe extends v.Service{constructor(e,t){super(e,t)}downloadCSV(e,t){const s=document.createElement("a"),i="text/csv;encoding:utf-8";if(navigator.msSaveBlob)navigator.msSaveBlob(new Blob([e],{type:i}),t);else if(URL&&"download"in s){const r=URL.createObjectURL(new Blob([e],{type:i}));s.href=r,s.setAttribute("download",t),document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)}else location.href=`data:application/octet-stream,${encodeURIComponent(e)}`}downloadImage(e,t){const s=document.createElement("a");s.download=t,s.href=e,document.body.appendChild(s),s.click(),document.body.removeChild(s)}}class fe extends v.Service{constructor(){super(...arguments),this.pendingTransitions={}}init(){var e;(e=this.services.events)==null||e.addEventListener(a.Events.Model.UPDATE,()=>{this.pendingTransitions={}})}setupTransition({transition:e,name:t,animate:s}){return this.pendingTransitions[e._id]=e,e.on("end interrupt cancel",()=>{delete this.pendingTransitions[e._id]}),this.model.getOptions().animations===!1||s===!1?e.duration(0):e.duration(n.getProperty(n.transitions,t,"duration")||n.transitions.default.duration)}getPendingTransitions(){return this.pendingTransitions}}class ve extends v.Service{constructor(){super(...arguments),this.scaleTypes={top:null,right:null,bottom:null,left:null},this.scales={top:null,right:null,bottom:null,left:null}}getDomainAxisPosition({datum:e=null}={}){if(this.dualAxes&&e){const t=this.model.getOptions(),{groupMapsTo:s}=t.data,i=n.getProperty(t,"axes",this.secondaryDomainAxisPosition),r=e[s];if(i!=null&&i.correspondingDatasets&&i.correspondingDatasets.includes(r))return this.secondaryDomainAxisPosition}return this.domainAxisPosition}getRangeAxisPosition({datum:e=null,groups:t=null}={}){if(this.dualAxes){const s=this.model.getOptions(),{groupMapsTo:i}=s.data,r=n.getProperty(s,"axes",this.secondaryRangeAxisPosition);let l;if(e!==null?l=e[i]:t&&t.length>0&&(l=t[0]),r!=null&&r.correspondingDatasets&&r.correspondingDatasets.includes(l))return this.secondaryRangeAxisPosition}return this.rangeAxisPosition}getAxisOptions(e){return n.getProperty(this.model.getOptions(),"axes",e)}getDomainAxisOptions(){const e=this.getDomainAxisPosition();return this.getAxisOptions(e)}getRangeAxisOptions(){const e=this.getRangeAxisPosition();return this.getAxisOptions(e)}getScaleLabel(e){const s=this.getAxisOptions(e).title;return s||(e===a.AxisPositions.BOTTOM||e===a.AxisPositions.TOP?"x-value":"y-value")}getDomainLabel(){return this.getScaleLabel(this.getDomainAxisPosition())}getRangeLabel(){return this.getScaleLabel(this.getRangeAxisPosition())}update(){this.determineAxisDuality(),this.findDomainAndRangeAxes(),this.determineOrientation(),Object.keys(a.AxisPositions).map(t=>a.AxisPositions[t]).forEach(t=>{this.scales[t]=this.createScale(t)})}findDomainAndRangeAxes(){const e=this.findVerticalAxesPositions(),t=this.findHorizontalAxesPositions(),s=this.findDomainAndRangeAxesPositions(e,t);this.domainAxisPosition=s.primaryDomainAxisPosition,this.rangeAxisPosition=s.primaryRangeAxisPosition,this.isDualAxes()&&(this.secondaryDomainAxisPosition=s.secondaryDomainAxisPosition,this.secondaryRangeAxisPosition=s.secondaryRangeAxisPosition)}determineOrientation(){(this.rangeAxisPosition===a.AxisPositions.LEFT||this.rangeAxisPosition===a.AxisPositions.RIGHT)&&(this.domainAxisPosition===a.AxisPositions.BOTTOM||this.domainAxisPosition===a.AxisPositions.TOP)?this.orientation=a.CartesianOrientations.VERTICAL:this.orientation=a.CartesianOrientations.HORIZONTAL}isDualAxes(){return this.dualAxes}determineAxisDuality(){var s,i,r,l;const e=this.model.getOptions(),t=n.getProperty(e,"axes");((s=t[a.AxisPositions.LEFT])!=null&&s.correspondingDatasets&&t[a.AxisPositions.RIGHT]||(i=t[a.AxisPositions.RIGHT])!=null&&i.correspondingDatasets&&t[a.AxisPositions.LEFT]||(r=t[a.AxisPositions.TOP])!=null&&r.correspondingDatasets&&t[a.AxisPositions.BOTTOM]||(l=t[a.AxisPositions.BOTTOM])!=null&&l.correspondingDatasets&&t[a.AxisPositions.TOP])&&(this.dualAxes=!0)}getCustomDomainValuesByposition(e){const t=n.getProperty(this.model.getOptions(),"axes",e,"domain");if(t&&!Array.isArray(t))throw new Error(`Domain in ${e} axis is not a valid array`);if(Array.isArray(t)&&(this.scaleTypes[e]===a.ScaleTypes.LINEAR||this.scaleTypes[e]===a.ScaleTypes.TIME)&&t.length!==2)throw new Error(`There can only be 2 elements in domain for scale type: ${this.scaleTypes[e]}`);return t}getOrientation(){return this.orientation}getScaleByPosition(e){return this.scales[e]}getScaleTypeByPosition(e){return this.scaleTypes[e]}getDomainAxisScaleType(){const e=this.getDomainAxisPosition();return this.getScaleTypeByPosition(e)}getRangeAxisScaleType(){const e=this.getRangeAxisPosition();return this.getScaleTypeByPosition(e)}getDomainScale(){return this.scales[this.domainAxisPosition]}getRangeScale(){return this.scales[this.rangeAxisPosition]}getMainXAxisPosition(){const e=[a.AxisPositions.BOTTOM,a.AxisPositions.TOP];return[this.domainAxisPosition,this.rangeAxisPosition].find(t=>e.indexOf(t)>-1)}getMainYAxisPosition(){const e=[a.AxisPositions.LEFT,a.AxisPositions.RIGHT];return[this.domainAxisPosition,this.rangeAxisPosition].find(t=>e.indexOf(t)>-1)}getMainXScale(){return this.scales[this.getMainXAxisPosition()]}getMainYScale(){return this.scales[this.getMainYAxisPosition()]}getValueFromScale(e,t,s,i){const r=this.model.getOptions(),u=n.getProperty(r,"axes")[s],{mapsTo:c}=u,d=n.getProperty(i,c)!==null?i[c]:i;let p;switch(t){case a.ScaleTypes.LABELS:p=e(d)+e.step()/2;break;case a.ScaleTypes.TIME:p=e(new Date(d));break;default:p=e(d)}return p}getBoundedScaledValues(e){const{bounds:t}=this.model.getOptions(),s=this.getRangeAxisPosition({datum:e}),i=this.scales[s],r=this.model.getOptions(),u=n.getProperty(r,"axes")[s],{mapsTo:c}=u,d=e[c]!==void 0?e[c]:e;return[i(n.getProperty(e,t.upperBoundMapsTo)!==null?e[t.upperBoundMapsTo]:d),i(n.getProperty(e,t.lowerBoundMapsTo)!==null?e[t.lowerBoundMapsTo]:d)]}getValueThroughAxisPosition(e,t){const s=this.scaleTypes[e],i=this.scales[e];return this.getValueFromScale(i,s,e,t)}getDomainValue(e){const t=this.getDomainAxisPosition({datum:e});return this.getValueThroughAxisPosition(t,e)}getRangeValue(e){const t=this.getRangeAxisPosition({datum:e});return this.getValueThroughAxisPosition(t,e)}getMainXScaleType(){return this.getScaleTypeByPosition(this.getMainXAxisPosition())}getMainYScaleType(){return this.getScaleTypeByPosition(this.getMainYAxisPosition())}getDomainIdentifier(e){const t=this.model.getOptions();return n.getProperty(t,"axes",this.getDomainAxisPosition({datum:e}),"mapsTo")}getRangeIdentifier(e){const t=this.model.getOptions();return n.getProperty(t,"axes",this.getRangeAxisPosition({datum:e}),"mapsTo")}extendsDomain(e,t){const s=this.model.getOptions(),i=n.getProperty(s,"axes",e);if(i.scaleType===a.ScaleTypes.TIME){const r=n.getProperty(s,"timeScale","addSpaceOnEdges");return ye(t,r)}else return Ae(t,n.axis.paddingRatio,i.scaleType)}findVerticalAxesPositions(){const e=this.model.getOptions(),t=n.getProperty(e,"axes"),s=this.isDualAxes();return n.getProperty(t,a.AxisPositions.LEFT)===null&&n.getProperty(t,a.AxisPositions.RIGHT)!==null||n.getProperty(t,a.AxisPositions.RIGHT,"main")===!0||s&&n.getProperty(t,a.AxisPositions.LEFT,"correspondingDatasets")?{primary:a.AxisPositions.RIGHT,secondary:a.AxisPositions.LEFT}:{primary:a.AxisPositions.LEFT,secondary:a.AxisPositions.RIGHT}}findHorizontalAxesPositions(){const e=this.model.getOptions(),t=n.getProperty(e,"axes"),s=this.isDualAxes();return n.getProperty(t,a.AxisPositions.BOTTOM)===null&&n.getProperty(t,a.AxisPositions.TOP)!==null||n.getProperty(t,a.AxisPositions.TOP,"main")===!0||s&&n.getProperty(t,a.AxisPositions.BOTTOM,"correspondingDatasets")?{primary:a.AxisPositions.TOP,secondary:a.AxisPositions.BOTTOM}:{primary:a.AxisPositions.BOTTOM,secondary:a.AxisPositions.TOP}}findDomainAndRangeAxesPositions(e,t){const s=this.model.getOptions(),i=n.getProperty(s,"axes",e.primary),r=n.getProperty(s,"axes",t.primary),l=i.scaleType||a.ScaleTypes.LINEAR,u=r.scaleType||a.ScaleTypes.LINEAR,c={primaryDomainAxisPosition:null,secondaryDomainAxisPosition:null,primaryRangeAxisPosition:null,secondaryRangeAxisPosition:null};return c.primaryDomainAxisPosition=t.primary,c.primaryRangeAxisPosition=e.primary,c.secondaryDomainAxisPosition=t.secondary,c.secondaryRangeAxisPosition=e.secondary,(!(u===a.ScaleTypes.LABELS||u===a.ScaleTypes.TIME)&&l===a.ScaleTypes.LABELS||l===a.ScaleTypes.TIME)&&(c.primaryDomainAxisPosition=e.primary,c.primaryRangeAxisPosition=t.primary,c.secondaryDomainAxisPosition=e.secondary,c.secondaryRangeAxisPosition=t.secondary),c}getScaleDomain(e){const t=this.model.getOptions(),s=n.getProperty(t,"axes",e),i=n.getProperty(t,"bounds"),{includeZero:r}=s,l=n.getProperty(s,"scaleType")||a.ScaleTypes.LINEAR;if(this.model.isDataEmpty())return[];if(s.binned){const{bins:g}=this.model.getBinConfigurations();return[0,m.max(g,h=>h.length)]}else if(s.limitDomainToBins){const{bins:g}=this.model.getBinConfigurations(),h=this.model.getStackKeys({bins:g});return[h[0].split("-")[0],h[h.length-1].split("-")[1]]}const u=this.model.getDisplayData(),{extendLinearDomainBy:c,mapsTo:d,percentage:p,thresholds:y}=s,{reference:A,compareTo:P}=n.axis.ratio;if(s.domain)return l===a.ScaleTypes.LABELS?s.domain:(l===a.ScaleTypes.TIME&&(s.domain=s.domain.map(g=>g.getTime===void 0?new Date(g):g)),this.extendsDomain(e,s.domain));if(p)return[0,100];if(s&&l===a.ScaleTypes.LABELS)return n.removeArrayDuplicates(u.map(g=>g[d]));let T,f;const S=this.model.getDataGroupNames();if(l===a.ScaleTypes.LABELS_RATIO)return u.map(g=>`${g[A]}/${g[P]}`);if(l===a.ScaleTypes.TIME)f=u.map(g=>+new Date(g[d]));else if(i&&t.axes)f=[],u.forEach(g=>{f.push(g[d]),g[i.upperBoundMapsTo]&&f.push(g[i.upperBoundMapsTo]),g[i.lowerBoundMapsTo]&&f.push(g[i.lowerBoundMapsTo])});else if(s.stacked===!0&&S&&e===this.getRangeAxisPosition()){const{groupMapsTo:g}=t.data,h=this.model.getDataValuesGroupedByKeys({groups:S}),G=u.filter(x=>!S.includes(x[g])),E=[];h.forEach(x=>{const{...U}=x;let C=0,b=0;Object.values(U).forEach(O=>{isNaN(O)||(O<0?b+=O:C+=O)}),E.push([b,C])}),f=[...k(E),...G.map(x=>x[d])]}else f=[],u.forEach(g=>{const h=g[d];Array.isArray(h)&&h.length===2?(f.push(h[0]),f.push(h[1])):(c&&f.push(Math.max(g[d],g[c])),f.push(h))});return l!==a.ScaleTypes.TIME&&l!==a.ScaleTypes.LOG&&r&&f.push(0),y&&y.length>0&&y.forEach(g=>{const h=n.getProperty(g,"value");h!==null&&f.push(h)}),T=m.extent(f),T=this.extendsDomain(e,T),T}createScale(e){const t=this.model.getOptions(),s=n.getProperty(t,"axes",e);if(!s)return null;const i=n.getProperty(s,"scaleType")||a.ScaleTypes.LINEAR;this.scaleTypes[e]=i;let r;return i===a.ScaleTypes.TIME?r=m.scaleTime():i===a.ScaleTypes.LOG?r=m.scaleLog().base(s.base||10):i===a.ScaleTypes.LABELS||i===a.ScaleTypes.LABELS_RATIO?r=m.scaleBand():r=m.scaleLinear(),r.domain(this.getScaleDomain(e)),r}getHighestDomainThreshold(){const e=n.getProperty(this.model.getOptions(),"axes"),t=this.getDomainAxisPosition(),{thresholds:s}=e[t];if(!Array.isArray(s)||Array.isArray(s)&&!s.length)return null;const i=this.getDomainScale(),r=s.sort((u,c)=>c.value-u.value)[0];return this.getScaleTypeByPosition(t)===a.ScaleTypes.TIME&&(typeof r.value=="string"||r.value.getTime===void 0)&&(r.value=new Date(r.value)),{threshold:r,scaleValue:i(r.value)}}getHighestRangeThreshold(){const e=n.getProperty(this.model.getOptions(),"axes"),t=this.getRangeAxisPosition(),{thresholds:s}=e[t];if(!Array.isArray(s)||Array.isArray(s)&&!s.length)return null;const i=this.getRangeScale(),r=s.sort((l,u)=>u.value-l.value)[0];return{threshold:r,scaleValue:i(r.value)}}}function ye(o,e){const t=new Date(o[0]),s=new Date(o[1]);return le(s,t)>1?[me(t,e),X(s,e)]:ae(s,t)>1?[ce(t,e),B(s,e)]:te(s,t)>1?[ue(t,e),z(s,e)]:ne(s,t)>1?[ge(t,e),Y(s,e)]:F(s,t)>30?[V(t,e*30),M(s,e*30)]:F(s,t)>1?[V(t,e),M(s,e)]:q(s,t)>15?[H(t,e*15),R(s,e*15)]:q(s,t)>1?[H(t,e),R(s,e)]:[t,s]}function Ae([o,e],t,s){const r=(e-o)*t,l=e<=0&&e+r>0?0:e+r;let u=o>=0&&o-r<0?0:o-r;if(s===a.ScaleTypes.LOG&&u<=0){if(o<=0)throw Error("Data must have values greater than 0 if log scale type is used.");u=o}return[u,l]}class xe extends v.Service{constructor(){super(...arguments),this.curveTypes={curveLinear:m.curveLinear,curveLinearClosed:m.curveLinearClosed,curveBasis:m.curveBasis,curveBasisClosed:m.curveBasisClosed,curveBasisOpen:m.curveBasisOpen,curveBundle:m.curveBundle,curveCardinal:m.curveCardinal,curveCardinalClosed:m.curveCardinalClosed,curveCardinalOpen:m.curveCardinalOpen,curveCatmullRom:m.curveCatmullRom,curveCatmullRomClosed:m.curveCatmullRomClosed,curveCatmullRomOpen:m.curveCatmullRomOpen,curveMonotoneX:m.curveMonotoneX,curveMonotoneY:m.curveMonotoneY,curveNatural:m.curveNatural,curveStep:m.curveStep,curveStepAfter:m.curveStepAfter,curveStepBefore:m.curveStepBefore}}getD3Curve(){let e="curveLinear";const t=this.model.getOptions().curve;if(t&&(typeof t=="string"?e=t:e=t.name),this.curveTypes[e]){let s=this.curveTypes[e];return t&&Object.keys(t).forEach(i=>{s[i]&&(s=s[i](t[i]))}),s}return console.warn(`The curve type '${e}' is invalid, using 'curveLinear' instead`),this.curveTypes.curveLinear}}class De extends v.Service{isZoomBarEnabled(){if(!this.services.cartesianScales||!n.getProperty(this.model.getOptions(),"zoomBar","top","enabled"))return!1;this.services.cartesianScales.findDomainAndRangeAxes();const e=this.services.cartesianScales.getMainXAxisPosition(),t=n.getProperty(this.model.getOptions(),"axes",e,"scaleType");return e===a.AxisPositions.BOTTOM&&t===a.ScaleTypes.TIME}getZoomBarData(){const e=this.model.getZoomBarData();return e&&e.length>1?e:this.model.getDisplayData()}getDefaultZoomBarDomain(e){if(!this.services.zoom)throw new Error("Services zoom not defined");const t=e||this.services.zoom.getZoomBarData(),{cartesianScales:s}=this.services;if(!s)throw new Error("Services cartesianScales undefined");const i=s.getMainXAxisPosition(),r=s.getDomainIdentifier(),l=n.getProperty(this.model.getOptions(),"axes",i,"domain");if(Array.isArray(l)&&l.length===2)return l;if(!i)throw new Error("Not defined: mainXAxisPosition");return s.extendsDomain(i,m.extent(t,u=>u[r]))}handleDomainChange(e,t={dispatchEvent:!0}){var s;this.model.set({zoomDomain:e},{animate:!1}),t.dispatchEvent&&((s=this.services.events)==null||s.dispatchEvent(a.Events.ZoomDomain.CHANGE,{newDomain:e}))}getZoomRatio(){return n.getProperty(this.model.getOptions(),"zoomBar","zoomRatio")}filterDataForRangeAxis(e,t){var l;const s=this.model.get("zoomDomain"),i=Object.assign({stacked:!1},t),r=n.getProperty(this.model.getOptions(),"zoomBar","updateRangeAxis");if(this.isZoomBarEnabled()&&r&&s){const u=i.stacked?"sharedStackKey":(l=this.services.cartesianScales)==null?void 0:l.getDomainIdentifier(),c=e.filter(d=>new Date(d[u])>=s[0]&&new Date(d[u])<=s[1]);if(c.length>0)return c}return e}zoomIn(e=this.getZoomRatio()){var P;const t=this.model.get("zoomDomain"),s=n.zoomBar.handleWidth,i=(P=this.services.cartesianScales)==null?void 0:P.getMainXScale().copy();i.domain(this.getDefaultZoomBarDomain());const r=i(t[0]),l=i(t[1]);if(l-r<s+1)return;const u=i.range(),c=l-r,d=Math.min((u[1]-u[0])/2*(e/2),c/2);let p=r+d,y=l-d;p>=y&&(p=r+c/2-s/2,y=l-c/2+s/2);const A=[i.invert(p),i.invert(y)];(t[0].valueOf()!==A[0].valueOf()||t[1].valueOf()!==A[1].valueOf())&&this.handleDomainChange(A)}zoomOut(e=this.getZoomRatio()){const t=this.model.get("zoomDomain");if(!this.services.cartesianScales)throw new Error("Services cartesianScales undefined");const s=this.services.cartesianScales.getMainXScale().copy();s.domain(this.getDefaultZoomBarDomain());const i=s(t[0]),r=s(t[1]),l=s.range(),u=(l[1]-l[0])/2*(e/2),c=Math.max(i-u,l[0]),d=Math.min(r+u,l[1]),p=[s.invert(c),s.invert(d)];(t[0].valueOf()!==p[0].valueOf()||t[1].valueOf()!==p[1].valueOf())&&this.handleDomainChange(p)}resetZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();(e[0].valueOf()!==t[0].valueOf()||e[1].valueOf()!==t[1].valueOf())&&this.handleDomainChange(t)}isMinZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();if(!e||!t)return!1;const s=e[1].valueOf()-e[0].valueOf(),i=t[1].valueOf()-t[0].valueOf(),r=n.getProperty(this.model.getOptions(),"zoomBar","minZoomRatio");return s/i<r}isMaxZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();return!!(e&&t&&e[0].valueOf()===t[0].valueOf()&&e[1].valueOf()===t[1].valueOf())}isEmptyState(){return this.getZoomBarData().length===0}isZoomBarLoading(e){return n.getProperty(this.model.getOptions(),"zoomBar",e,"loading")}isZoomBarLocked(e){return n.getProperty(this.model.getOptions(),"zoomBar",e,"locked")}}exports.CanvasZoom=de;exports.CartesianScales=ve;exports.Curves=xe;exports.Events=he;exports.Files=pe;exports.Transitions=fe;exports.Zoom=De;exports.flatten=k;
2
- //# sourceMappingURL=index-4203ca23.js.map
1
+ "use strict";const n=require("./color-scale-utils-2cd523be.js"),v=require("./angle-utils-ccc0d890.js"),a=require("./enums-aa2efd99.js"),m=require("d3");function z(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toInteger(e);return isNaN(s)?new Date(NaN):(s&&t.setDate(t.getDate()+s),t)}function B(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toInteger(e);if(isNaN(s))return new Date(NaN);if(!s)return t;var i=t.getDate(),r=new Date(t.getTime());r.setMonth(t.getMonth()+s+1,0);var l=r.getDate();return i>=l?r:(t.setFullYear(r.getFullYear(),r.getMonth(),i),t)}var _=36e5;function Y(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*_)}function Z(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return e.setHours(0,0,0,0),e}var $=864e5;function j(o,e){n.requiredArgs(2,arguments);var t=Z(o),s=Z(e),i=t.getTime()-n.getTimezoneOffsetInMilliseconds(t),r=s.getTime()-n.getTimezoneOffsetInMilliseconds(s);return Math.round((i-r)/$)}var K=6e4;function M(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*K)}function R(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return n.addMilliseconds(o,t*1e3)}function X(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return B(o,t*12)}function D(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=t.getTime()-s.getTime();return i<0?-1:i>0?1:i}var W=6e4,J=36e5;function Q(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=t.getFullYear()-s.getFullYear(),r=t.getMonth()-s.getMonth();return i*12+r}function ee(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e);return t.getFullYear()-s.getFullYear()}function w(o,e){var t=o.getFullYear()-e.getFullYear()||o.getMonth()-e.getMonth()||o.getDate()-e.getDate()||o.getHours()-e.getHours()||o.getMinutes()-e.getMinutes()||o.getSeconds()-e.getSeconds()||o.getMilliseconds()-e.getMilliseconds();return t<0?-1:t>0?1:t}function te(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=w(t,s),r=Math.abs(j(t,s));t.setDate(t.getDate()-i*r);var l=+(w(t,s)===-i),u=i*(r-l);return u===0?0:u}function I(o,e){return n.requiredArgs(2,arguments),n.toDate(o).getTime()-n.toDate(e).getTime()}var N={ceil:Math.ceil,round:Math.round,floor:Math.floor,trunc:function(e){return e<0?Math.ceil(e):Math.floor(e)}},se="trunc";function L(o){return o?N[o]:N[se]}function ne(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/J;return L(t==null?void 0:t.roundingMethod)(s)}function F(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/W;return L(t==null?void 0:t.roundingMethod)(s)}function ie(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return e.setHours(23,59,59,999),e}function oe(o){n.requiredArgs(1,arguments);var e=n.toDate(o),t=e.getMonth();return e.setFullYear(e.getFullYear(),t+1,0),e.setHours(23,59,59,999),e}function re(o){n.requiredArgs(1,arguments);var e=n.toDate(o);return ie(e).getTime()===oe(e).getTime()}function ae(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=D(t,s),r=Math.abs(Q(t,s)),l;if(r<1)l=0;else{t.getMonth()===1&&t.getDate()>27&&t.setDate(30),t.setMonth(t.getMonth()-i*r);var u=D(t,s)===-i;re(n.toDate(o))&&r===1&&D(o,s)===1&&(u=!1),l=i*(r-Number(u))}return l===0?0:l}function q(o,e,t){n.requiredArgs(2,arguments);var s=I(o,e)/1e3;return L(t==null?void 0:t.roundingMethod)(s)}function le(o,e){n.requiredArgs(2,arguments);var t=n.toDate(o),s=n.toDate(e),i=D(t,s),r=Math.abs(ee(t,s));t.setFullYear(1584),s.setFullYear(1584);var l=D(t,s)===-i,u=i*(r-Number(l));return u===0?0:u}function ue(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return z(o,-t)}function ce(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return B(o,-t)}function ge(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return Y(o,-t)}function V(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return M(o,-t)}function H(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return R(o,-t)}function me(o,e){n.requiredArgs(2,arguments);var t=n.toInteger(e);return X(o,-t)}function k(o){var e=o==null?0:o.length;return e?n.baseFlatten(o,1):[]}class de extends v.Service{zoomIn(e,t,s){let i,r,l;const u=s||n.canvasZoomSettings;e&&(i=e.x,r=e.y,l=2);const{width:c,height:d}=v.DOMUtils.getSVGElementSize(this.services.domUtils.getHolder(),{useClientDimensions:!0});t.transition().duration(u.duration).ease(u.ease).attr("transform",`translate(${c/2}, ${d/2}) scale(${l}) translate(${-i},${-r})`),this.services.events.dispatchEvent(a.Events.CanvasZoom.CANVAS_ZOOM_IN,{element:m.select(e)})}zoomOut(e,t){const s=t||n.canvasZoomSettings;e.transition().duration(s.duration).ease(s.ease).attr("transform",""),this.services.events.dispatchEvent(a.Events.CanvasZoom.CANVAS_ZOOM_OUT)}}class he extends v.Service{init(){this.documentFragment=document.createDocumentFragment()}addEventListener(e,t){this.documentFragment.addEventListener(e,t)}removeEventListener(e,t){this.documentFragment.removeEventListener(e,t)}dispatchEvent(e,t){let s;t?s=new CustomEvent(e,{detail:t}):(s=document.createEvent("Event"),s.initEvent(e,!1,!0)),this.documentFragment.dispatchEvent(s)}}class pe extends v.Service{constructor(e,t){super(e,t)}downloadCSV(e,t){const s=document.createElement("a"),i="text/csv;encoding:utf-8";if(navigator.msSaveBlob)navigator.msSaveBlob(new Blob([e],{type:i}),t);else if(URL&&"download"in s){const r=URL.createObjectURL(new Blob([e],{type:i}));s.href=r,s.setAttribute("download",t),document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)}else location.href=`data:application/octet-stream,${encodeURIComponent(e)}`}downloadImage(e,t){const s=document.createElement("a");s.download=t,s.href=e,document.body.appendChild(s),s.click(),document.body.removeChild(s)}}class fe extends v.Service{constructor(){super(...arguments),this.pendingTransitions={}}init(){var e;(e=this.services.events)==null||e.addEventListener(a.Events.Model.UPDATE,()=>{this.pendingTransitions={}})}setupTransition({transition:e,name:t,animate:s}){return this.pendingTransitions[e._id]=e,e.on("end interrupt cancel",()=>{delete this.pendingTransitions[e._id]}),this.model.getOptions().animations===!1||s===!1?e.duration(0):e.duration(n.getProperty(n.transitions,t,"duration")||n.transitions.default.duration)}getPendingTransitions(){return this.pendingTransitions}}class ve extends v.Service{constructor(){super(...arguments),this.scaleTypes={top:null,right:null,bottom:null,left:null},this.scales={top:null,right:null,bottom:null,left:null}}getDomainAxisPosition({datum:e=null}={}){if(this.dualAxes&&e){const t=this.model.getOptions(),{groupMapsTo:s}=t.data,i=n.getProperty(t,"axes",this.secondaryDomainAxisPosition),r=e[s];if(i!=null&&i.correspondingDatasets&&i.correspondingDatasets.includes(r))return this.secondaryDomainAxisPosition}return this.domainAxisPosition}getRangeAxisPosition({datum:e=null,groups:t=null}={}){if(this.dualAxes){const s=this.model.getOptions(),{groupMapsTo:i}=s.data,r=n.getProperty(s,"axes",this.secondaryRangeAxisPosition);let l;if(e!==null?l=e[i]:t&&t.length>0&&(l=t[0]),r!=null&&r.correspondingDatasets&&r.correspondingDatasets.includes(l))return this.secondaryRangeAxisPosition}return this.rangeAxisPosition}getAxisOptions(e){return n.getProperty(this.model.getOptions(),"axes",e)}getDomainAxisOptions(){const e=this.getDomainAxisPosition();return this.getAxisOptions(e)}getRangeAxisOptions(){const e=this.getRangeAxisPosition();return this.getAxisOptions(e)}getScaleLabel(e){const s=this.getAxisOptions(e).title;return s||(e===a.AxisPositions.BOTTOM||e===a.AxisPositions.TOP?"x-value":"y-value")}getDomainLabel(){return this.getScaleLabel(this.getDomainAxisPosition())}getRangeLabel(){return this.getScaleLabel(this.getRangeAxisPosition())}update(){this.determineAxisDuality(),this.findDomainAndRangeAxes(),this.determineOrientation(),Object.keys(a.AxisPositions).map(t=>a.AxisPositions[t]).forEach(t=>{this.scales[t]=this.createScale(t)})}findDomainAndRangeAxes(){const e=this.findVerticalAxesPositions(),t=this.findHorizontalAxesPositions(),s=this.findDomainAndRangeAxesPositions(e,t);this.domainAxisPosition=s.primaryDomainAxisPosition,this.rangeAxisPosition=s.primaryRangeAxisPosition,this.isDualAxes()&&(this.secondaryDomainAxisPosition=s.secondaryDomainAxisPosition,this.secondaryRangeAxisPosition=s.secondaryRangeAxisPosition)}determineOrientation(){(this.rangeAxisPosition===a.AxisPositions.LEFT||this.rangeAxisPosition===a.AxisPositions.RIGHT)&&(this.domainAxisPosition===a.AxisPositions.BOTTOM||this.domainAxisPosition===a.AxisPositions.TOP)?this.orientation=a.CartesianOrientations.VERTICAL:this.orientation=a.CartesianOrientations.HORIZONTAL}isDualAxes(){return this.dualAxes}determineAxisDuality(){var s,i,r,l;const e=this.model.getOptions(),t=n.getProperty(e,"axes");((s=t[a.AxisPositions.LEFT])!=null&&s.correspondingDatasets&&t[a.AxisPositions.RIGHT]||(i=t[a.AxisPositions.RIGHT])!=null&&i.correspondingDatasets&&t[a.AxisPositions.LEFT]||(r=t[a.AxisPositions.TOP])!=null&&r.correspondingDatasets&&t[a.AxisPositions.BOTTOM]||(l=t[a.AxisPositions.BOTTOM])!=null&&l.correspondingDatasets&&t[a.AxisPositions.TOP])&&(this.dualAxes=!0)}getCustomDomainValuesByposition(e){const t=n.getProperty(this.model.getOptions(),"axes",e,"domain");if(t&&!Array.isArray(t))throw new Error(`Domain in ${e} axis is not a valid array`);if(Array.isArray(t)&&(this.scaleTypes[e]===a.ScaleTypes.LINEAR||this.scaleTypes[e]===a.ScaleTypes.TIME)&&t.length!==2)throw new Error(`There can only be 2 elements in domain for scale type: ${this.scaleTypes[e]}`);return t}getOrientation(){return this.orientation}getScaleByPosition(e){return this.scales[e]}getScaleTypeByPosition(e){return this.scaleTypes[e]}getDomainAxisScaleType(){const e=this.getDomainAxisPosition();return this.getScaleTypeByPosition(e)}getRangeAxisScaleType(){const e=this.getRangeAxisPosition();return this.getScaleTypeByPosition(e)}getDomainScale(){return this.scales[this.domainAxisPosition]}getRangeScale(){return this.scales[this.rangeAxisPosition]}getMainXAxisPosition(){const e=[a.AxisPositions.BOTTOM,a.AxisPositions.TOP];return[this.domainAxisPosition,this.rangeAxisPosition].find(t=>e.indexOf(t)>-1)}getMainYAxisPosition(){const e=[a.AxisPositions.LEFT,a.AxisPositions.RIGHT];return[this.domainAxisPosition,this.rangeAxisPosition].find(t=>e.indexOf(t)>-1)}getMainXScale(){return this.scales[this.getMainXAxisPosition()]}getMainYScale(){return this.scales[this.getMainYAxisPosition()]}getValueFromScale(e,t,s,i){const r=this.model.getOptions(),u=n.getProperty(r,"axes")[s],{mapsTo:c}=u,d=n.getProperty(i,c)!==null?i[c]:i;let p;switch(t){case a.ScaleTypes.LABELS:p=e(d)+e.step()/2;break;case a.ScaleTypes.TIME:p=e(new Date(d));break;default:p=e(d)}return p}getBoundedScaledValues(e){const{bounds:t}=this.model.getOptions(),s=this.getRangeAxisPosition({datum:e}),i=this.scales[s],r=this.model.getOptions(),u=n.getProperty(r,"axes")[s],{mapsTo:c}=u,d=e[c]!==void 0?e[c]:e;return[i(n.getProperty(e,t.upperBoundMapsTo)!==null?e[t.upperBoundMapsTo]:d),i(n.getProperty(e,t.lowerBoundMapsTo)!==null?e[t.lowerBoundMapsTo]:d)]}getValueThroughAxisPosition(e,t){const s=this.scaleTypes[e],i=this.scales[e];return this.getValueFromScale(i,s,e,t)}getDomainValue(e){const t=this.getDomainAxisPosition({datum:e});return this.getValueThroughAxisPosition(t,e)}getRangeValue(e){const t=this.getRangeAxisPosition({datum:e});return this.getValueThroughAxisPosition(t,e)}getMainXScaleType(){return this.getScaleTypeByPosition(this.getMainXAxisPosition())}getMainYScaleType(){return this.getScaleTypeByPosition(this.getMainYAxisPosition())}getDomainIdentifier(e){const t=this.model.getOptions();return n.getProperty(t,"axes",this.getDomainAxisPosition({datum:e}),"mapsTo")}getRangeIdentifier(e){const t=this.model.getOptions();return n.getProperty(t,"axes",this.getRangeAxisPosition({datum:e}),"mapsTo")}extendsDomain(e,t){const s=this.model.getOptions(),i=n.getProperty(s,"axes",e);if(i.scaleType===a.ScaleTypes.TIME){const r=n.getProperty(s,"timeScale","addSpaceOnEdges");return ye(t,r)}else return Ae(t,n.axis.paddingRatio,i.scaleType)}findVerticalAxesPositions(){const e=this.model.getOptions(),t=n.getProperty(e,"axes"),s=this.isDualAxes();return n.getProperty(t,a.AxisPositions.LEFT)===null&&n.getProperty(t,a.AxisPositions.RIGHT)!==null||n.getProperty(t,a.AxisPositions.RIGHT,"main")===!0||s&&n.getProperty(t,a.AxisPositions.LEFT,"correspondingDatasets")?{primary:a.AxisPositions.RIGHT,secondary:a.AxisPositions.LEFT}:{primary:a.AxisPositions.LEFT,secondary:a.AxisPositions.RIGHT}}findHorizontalAxesPositions(){const e=this.model.getOptions(),t=n.getProperty(e,"axes"),s=this.isDualAxes();return n.getProperty(t,a.AxisPositions.BOTTOM)===null&&n.getProperty(t,a.AxisPositions.TOP)!==null||n.getProperty(t,a.AxisPositions.TOP,"main")===!0||s&&n.getProperty(t,a.AxisPositions.BOTTOM,"correspondingDatasets")?{primary:a.AxisPositions.TOP,secondary:a.AxisPositions.BOTTOM}:{primary:a.AxisPositions.BOTTOM,secondary:a.AxisPositions.TOP}}findDomainAndRangeAxesPositions(e,t){const s=this.model.getOptions(),i=n.getProperty(s,"axes",e.primary),r=n.getProperty(s,"axes",t.primary),l=i.scaleType||a.ScaleTypes.LINEAR,u=r.scaleType||a.ScaleTypes.LINEAR,c={primaryDomainAxisPosition:null,secondaryDomainAxisPosition:null,primaryRangeAxisPosition:null,secondaryRangeAxisPosition:null};return c.primaryDomainAxisPosition=t.primary,c.primaryRangeAxisPosition=e.primary,c.secondaryDomainAxisPosition=t.secondary,c.secondaryRangeAxisPosition=e.secondary,(!(u===a.ScaleTypes.LABELS||u===a.ScaleTypes.TIME)&&l===a.ScaleTypes.LABELS||l===a.ScaleTypes.TIME)&&(c.primaryDomainAxisPosition=e.primary,c.primaryRangeAxisPosition=t.primary,c.secondaryDomainAxisPosition=e.secondary,c.secondaryRangeAxisPosition=t.secondary),c}getScaleDomain(e){const t=this.model.getOptions(),s=n.getProperty(t,"axes",e),i=n.getProperty(t,"bounds"),{includeZero:r}=s,l=n.getProperty(s,"scaleType")||a.ScaleTypes.LINEAR;if(this.model.isDataEmpty())return[];if(s.binned){const{bins:g}=this.model.getBinConfigurations();return[0,m.max(g,h=>h.length)]}else if(s.limitDomainToBins){const{bins:g}=this.model.getBinConfigurations(),h=this.model.getStackKeys({bins:g});return[h[0].split("-")[0],h[h.length-1].split("-")[1]]}const u=this.model.getDisplayData(),{extendLinearDomainBy:c,mapsTo:d,percentage:p,thresholds:y}=s,{reference:A,compareTo:P}=n.axis.ratio;if(s.domain)return l===a.ScaleTypes.LABELS?s.domain:(l===a.ScaleTypes.TIME&&(s.domain=s.domain.map(g=>g.getTime===void 0?new Date(g):g)),this.extendsDomain(e,s.domain));if(p)return[0,100];if(s&&l===a.ScaleTypes.LABELS)return n.removeArrayDuplicates(u.map(g=>g[d]));let T,f;const S=this.model.getDataGroupNames();if(l===a.ScaleTypes.LABELS_RATIO)return u.map(g=>`${g[A]}/${g[P]}`);if(l===a.ScaleTypes.TIME)f=u.map(g=>+new Date(g[d]));else if(i&&t.axes)f=[],u.forEach(g=>{f.push(g[d]),g[i.upperBoundMapsTo]&&f.push(g[i.upperBoundMapsTo]),g[i.lowerBoundMapsTo]&&f.push(g[i.lowerBoundMapsTo])});else if(s.stacked===!0&&S&&e===this.getRangeAxisPosition()){const{groupMapsTo:g}=t.data,h=this.model.getDataValuesGroupedByKeys({groups:S}),G=u.filter(x=>!S.includes(x[g])),E=[];h.forEach(x=>{const{...U}=x;let C=0,b=0;Object.values(U).forEach(O=>{isNaN(O)||(O<0?b+=O:C+=O)}),E.push([b,C])}),f=[...k(E),...G.map(x=>x[d])]}else f=[],u.forEach(g=>{const h=g[d];Array.isArray(h)&&h.length===2?(f.push(h[0]),f.push(h[1])):(c&&f.push(Math.max(g[d],g[c])),f.push(h))});return l!==a.ScaleTypes.TIME&&l!==a.ScaleTypes.LOG&&r&&f.push(0),y&&y.length>0&&y.forEach(g=>{const h=n.getProperty(g,"value");h!==null&&f.push(h)}),T=m.extent(f),T=this.extendsDomain(e,T),T}createScale(e){const t=this.model.getOptions(),s=n.getProperty(t,"axes",e);if(!s)return null;const i=n.getProperty(s,"scaleType")||a.ScaleTypes.LINEAR;this.scaleTypes[e]=i;let r;return i===a.ScaleTypes.TIME?r=m.scaleTime():i===a.ScaleTypes.LOG?r=m.scaleLog().base(s.base||10):i===a.ScaleTypes.LABELS||i===a.ScaleTypes.LABELS_RATIO?r=m.scaleBand():r=m.scaleLinear(),r.domain(this.getScaleDomain(e)),r}getHighestDomainThreshold(){const e=n.getProperty(this.model.getOptions(),"axes"),t=this.getDomainAxisPosition(),{thresholds:s}=e[t];if(!Array.isArray(s)||Array.isArray(s)&&!s.length)return null;const i=this.getDomainScale(),r=s.sort((u,c)=>c.value-u.value)[0];return this.getScaleTypeByPosition(t)===a.ScaleTypes.TIME&&(typeof r.value=="string"||r.value.getTime===void 0)&&(r.value=new Date(r.value)),{threshold:r,scaleValue:i(r.value)}}getHighestRangeThreshold(){const e=n.getProperty(this.model.getOptions(),"axes"),t=this.getRangeAxisPosition(),{thresholds:s}=e[t];if(!Array.isArray(s)||Array.isArray(s)&&!s.length)return null;const i=this.getRangeScale(),r=s.sort((l,u)=>u.value-l.value)[0];return{threshold:r,scaleValue:i(r.value)}}}function ye(o,e){const t=new Date(o[0]),s=new Date(o[1]);return le(s,t)>1?[me(t,e),X(s,e)]:ae(s,t)>1?[ce(t,e),B(s,e)]:te(s,t)>1?[ue(t,e),z(s,e)]:ne(s,t)>1?[ge(t,e),Y(s,e)]:F(s,t)>30?[V(t,e*30),M(s,e*30)]:F(s,t)>1?[V(t,e),M(s,e)]:q(s,t)>15?[H(t,e*15),R(s,e*15)]:q(s,t)>1?[H(t,e),R(s,e)]:[t,s]}function Ae([o,e],t,s){const r=(e-o)*t,l=e<=0&&e+r>0?0:e+r;let u=o>=0&&o-r<0?0:o-r;if(s===a.ScaleTypes.LOG&&u<=0){if(o<=0)throw Error("Data must have values greater than 0 if log scale type is used.");u=o}return[u,l]}class xe extends v.Service{constructor(){super(...arguments),this.curveTypes={curveLinear:m.curveLinear,curveLinearClosed:m.curveLinearClosed,curveBasis:m.curveBasis,curveBasisClosed:m.curveBasisClosed,curveBasisOpen:m.curveBasisOpen,curveBundle:m.curveBundle,curveCardinal:m.curveCardinal,curveCardinalClosed:m.curveCardinalClosed,curveCardinalOpen:m.curveCardinalOpen,curveCatmullRom:m.curveCatmullRom,curveCatmullRomClosed:m.curveCatmullRomClosed,curveCatmullRomOpen:m.curveCatmullRomOpen,curveMonotoneX:m.curveMonotoneX,curveMonotoneY:m.curveMonotoneY,curveNatural:m.curveNatural,curveStep:m.curveStep,curveStepAfter:m.curveStepAfter,curveStepBefore:m.curveStepBefore}}getD3Curve(){let e="curveLinear";const t=this.model.getOptions().curve;if(t&&(typeof t=="string"?e=t:e=t.name),this.curveTypes[e]){let s=this.curveTypes[e];return t&&Object.keys(t).forEach(i=>{s[i]&&(s=s[i](t[i]))}),s}return console.warn(`The curve type '${e}' is invalid, using 'curveLinear' instead`),this.curveTypes.curveLinear}}class De extends v.Service{isZoomBarEnabled(){if(!this.services.cartesianScales||!n.getProperty(this.model.getOptions(),"zoomBar","top","enabled"))return!1;this.services.cartesianScales.findDomainAndRangeAxes();const e=this.services.cartesianScales.getMainXAxisPosition(),t=n.getProperty(this.model.getOptions(),"axes",e,"scaleType");return e===a.AxisPositions.BOTTOM&&t===a.ScaleTypes.TIME}getZoomBarData(){const e=this.model.getZoomBarData();return e&&e.length>1?e:this.model.getDisplayData()}getDefaultZoomBarDomain(e){if(!this.services.zoom)throw new Error("Services zoom not defined");const t=e||this.services.zoom.getZoomBarData(),{cartesianScales:s}=this.services;if(!s)throw new Error("Services cartesianScales undefined");const i=s.getMainXAxisPosition(),r=s.getDomainIdentifier(),l=n.getProperty(this.model.getOptions(),"axes",i,"domain");if(Array.isArray(l)&&l.length===2)return l;if(!i)throw new Error("Not defined: mainXAxisPosition");return s.extendsDomain(i,m.extent(t,u=>u[r]))}handleDomainChange(e,t={dispatchEvent:!0}){var s;this.model.set({zoomDomain:e},{animate:!1}),t.dispatchEvent&&((s=this.services.events)==null||s.dispatchEvent(a.Events.ZoomDomain.CHANGE,{newDomain:e}))}getZoomRatio(){return n.getProperty(this.model.getOptions(),"zoomBar","zoomRatio")}filterDataForRangeAxis(e,t){var l;const s=this.model.get("zoomDomain"),i=Object.assign({stacked:!1},t),r=n.getProperty(this.model.getOptions(),"zoomBar","updateRangeAxis");if(this.isZoomBarEnabled()&&r&&s){const u=i.stacked?"sharedStackKey":(l=this.services.cartesianScales)==null?void 0:l.getDomainIdentifier(),c=e.filter(d=>new Date(d[u])>=s[0]&&new Date(d[u])<=s[1]);if(c.length>0)return c}return e}zoomIn(e=this.getZoomRatio()){var P;const t=this.model.get("zoomDomain"),s=n.zoomBar.handleWidth,i=(P=this.services.cartesianScales)==null?void 0:P.getMainXScale().copy();i.domain(this.getDefaultZoomBarDomain());const r=i(t[0]),l=i(t[1]);if(l-r<s+1)return;const u=i.range(),c=l-r,d=Math.min((u[1]-u[0])/2*(e/2),c/2);let p=r+d,y=l-d;p>=y&&(p=r+c/2-s/2,y=l-c/2+s/2);const A=[i.invert(p),i.invert(y)];(t[0].valueOf()!==A[0].valueOf()||t[1].valueOf()!==A[1].valueOf())&&this.handleDomainChange(A)}zoomOut(e=this.getZoomRatio()){const t=this.model.get("zoomDomain");if(!this.services.cartesianScales)throw new Error("Services cartesianScales undefined");const s=this.services.cartesianScales.getMainXScale().copy();s.domain(this.getDefaultZoomBarDomain());const i=s(t[0]),r=s(t[1]),l=s.range(),u=(l[1]-l[0])/2*(e/2),c=Math.max(i-u,l[0]),d=Math.min(r+u,l[1]),p=[s.invert(c),s.invert(d)];(t[0].valueOf()!==p[0].valueOf()||t[1].valueOf()!==p[1].valueOf())&&this.handleDomainChange(p)}resetZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();(e[0].valueOf()!==t[0].valueOf()||e[1].valueOf()!==t[1].valueOf())&&this.handleDomainChange(t)}isMinZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();if(!e||!t)return!1;const s=e[1].valueOf()-e[0].valueOf(),i=t[1].valueOf()-t[0].valueOf(),r=n.getProperty(this.model.getOptions(),"zoomBar","minZoomRatio");return s/i<r}isMaxZoomDomain(){const e=this.model.get("zoomDomain"),t=this.getDefaultZoomBarDomain();return!!(e&&t&&e[0].valueOf()===t[0].valueOf()&&e[1].valueOf()===t[1].valueOf())}isEmptyState(){return this.getZoomBarData().length===0}isZoomBarLoading(e){return n.getProperty(this.model.getOptions(),"zoomBar",e,"loading")}isZoomBarLocked(e){return n.getProperty(this.model.getOptions(),"zoomBar",e,"locked")}}exports.CanvasZoom=de;exports.CartesianScales=ve;exports.Curves=xe;exports.Events=he;exports.Files=pe;exports.Transitions=fe;exports.Zoom=De;exports.flatten=k;
2
+ //# sourceMappingURL=index-eace9da9.js.map