@d3plus/core 3.0.9 → 3.0.11

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v3.0.9
2
+ @d3plus/core v3.0.11
3
3
  Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
4
4
  Copyright (c) 2025 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -2713,6 +2713,10 @@ function(){var t=this._history.length,i=Pt.elem("g.d3plus-viz-back",{parent:this
2713
2713
  * @param {Array} data The data to process.
2714
2714
  * @private
2715
2715
  */_thresholdFunction(t){return t}
2716
+ /**
2717
+ * Detects width and height and sets SVG properties
2718
+ * @private
2719
+ */_setSVGSize(){var t=this._select.style("display"),[i,e]=(this._select.style("display","none"),Pt.getSize(this._select.node().parentNode)),i=(i-=parseFloat(this._select.style("border-left-width"),10))-parseFloat(this._select.style("border-right-width"),10),e=(e-=parseFloat(this._select.style("border-top-width"),10))-parseFloat(this._select.style("border-bottom-width"),10);this._select.style("display",t),this._autoWidth&&(this.width(i),this._select.style("width",this._width+"px").attr("width",this._width+"px")),this._autoHeight&&(this.height(e),this._select.style("height",this._height+"px").attr("height",this._height+"px"))}
2716
2720
  /**
2717
2721
  @memberof Viz
2718
2722
  @desc Draws the visualization given the specified configuration.
@@ -2720,21 +2724,20 @@ function(){var t=this._history.length,i=Pt.elem("g.d3plus-viz-back",{parent:this
2720
2724
  @chainable
2721
2725
  */render(s){
2722
2726
  // Appends a fullscreen SVG to the BODY if a container has not been provided through .select().
2723
- if(
2727
+ if(this._callback=s,
2724
2728
  // Resets margins and padding
2725
2729
  this._margin={bottom:0,left:0,right:0,top:0},this._padding={bottom:0,left:0,right:0,top:0},void 0===this._select||"svg"!==this._select.node().tagName.toLowerCase()){let t=void 0===this._select?j.select("body").append("div"):this._select;var i=t.select(".d3plus-viz").size()?t.select(".d3plus-viz"):t.append("svg");this.select(i.node())}
2726
- /** detects width and height and sets SVG properties */function h(){var t=this._select.style("display"),[i,e]=(this._select.style("display","none"),Pt.getSize(this._select.node().parentNode)),i=(i-=parseFloat(this._select.style("border-left-width"),10))-parseFloat(this._select.style("border-right-width"),10),e=(e-=parseFloat(this._select.style("border-top-width"),10))-parseFloat(this._select.style("border-bottom-width"),10);this._select.style("display",t),this._autoWidth&&(this.width(i),this._select.style("width",this._width+"px").attr("width",this._width+"px")),this._autoHeight&&(this.height(e),this._select.style("height",this._height+"px").attr("height",this._height+"px"))}
2727
2730
  // Calculates the width and/or height of the Viz based on the this._select, if either has not been defined.
2728
- this._width&&this._height||this._detectVisible&&!Pt.inViewport(this._select.node())||(this._autoWidth=void 0===this._width,this._autoHeight=void 0===this._height,h.bind(this)()),this._select.attr("class","d3plus-viz").attr("aria-hidden",this._ariaHidden).attr("aria-labelledby",`${this._uuid}-title ${this._uuid}-desc`).attr("role","img").attr("xmlns","http://www.w3.org/2000/svg").attr("xmlns:xlink","http://www.w3.org/1999/xlink").transition().duration(this._duration).style("width",void 0!==this._width?this._width+"px":void 0).style("height",void 0!==this._height?this._height+"px":void 0).attr("width",void 0!==this._width?this._width+"px":void 0).attr("height",void 0!==this._height?this._height+"px":void 0);
2731
+ this._width&&this._height||this._detectVisible&&!Pt.inViewport(this._select.node())||(this._autoWidth=void 0===this._width,this._autoHeight=void 0===this._height,this._setSVGSize()),this._select.attr("class","d3plus-viz").attr("aria-hidden",this._ariaHidden).attr("aria-labelledby",`${this._uuid}-title ${this._uuid}-desc`).attr("role","img").attr("xmlns","http://www.w3.org/2000/svg").attr("xmlns:xlink","http://www.w3.org/1999/xlink").transition().duration(this._duration).style("width",void 0!==this._width?this._width+"px":void 0).style("height",void 0!==this._height?this._height+"px":void 0).attr("width",void 0!==this._width?this._width+"px":void 0).attr("height",void 0!==this._height?this._height+"px":void 0);
2729
2732
  // sets "position: relative" on the SVG parent if currently undefined
2730
2733
  let t=j.select(this._select.node().parentNode);"static"===t.style("position")&&t.style("position","relative"),t.style("font-family",H.fontFamilyStringify(this._fontFamily)),
2731
2734
  // sets initial opacity to 1, if it has not already been set
2732
- null===this._select.attr("opacity")&&this._select.attr("opacity",1);var i=this._select.selectAll("title").data([0]),e=i.enter().append("title").attr("id",this._uuid+"-title"),i=(i.merge(e).text(this._svgTitle),this._select.selectAll("desc").data([0])),e=i.enter().append("desc").attr("id",this._uuid+"-desc");if(i.merge(e).text(this._svgDesc),this._visiblePoll=clearInterval(this._visiblePoll),this._resizePoll=clearTimeout(this._resizePoll),this._scrollPoll=clearTimeout(this._scrollPoll),j.select(this._scrollContainer).on("scroll."+this._uuid,null),j.select(this._resizeContainer).on("resize."+this._uuid,null),this._detectVisible&&"hidden"===this._select.style("visibility"))this._visiblePoll=setInterval(()=>{"hidden"!==this._select.style("visibility")&&(this._visiblePoll=clearInterval(this._visiblePoll),this.render(s))},this._detectVisibleInterval);else if(this._detectVisible&&"none"===this._select.style("display"))this._visiblePoll=setInterval(()=>{"none"!==this._select.style("display")&&(this._visiblePoll=clearInterval(this._visiblePoll),this.render(s))},this._detectVisibleInterval);else if(this._detectVisible&&!Pt.inViewport(this._select.node()))j.select(this._scrollContainer).on("scroll."+this._uuid,()=>{this._scrollPoll||(this._scrollPoll=setTimeout(()=>{Pt.inViewport(this._select.node())&&(j.select(this._scrollContainer).on("scroll."+this._uuid,null),this.render(s)),this._scrollPoll=clearTimeout(this._scrollPoll)},this._detectVisibleInterval))});else{let e=b.queue();this._queue.forEach(t=>{var i=this._cache?this._lrucache.get(t[3]+"_"+t[1]):void 0;i?this["_"+t[3]]=t[2]?t[2](i):i:e.defer(...t)}),this._queue=[],this._loadingMessage&&e._tasks.length&&this._messageClass.render({container:this._select.node().parentNode,html:this._loadingHTML(this),mask:!!this._filteredData&&this._messageMask,style:this._messageStyle}),e.awaitAll(()=>{
2735
+ null===this._select.attr("opacity")&&this._select.attr("opacity",1);var i=this._select.selectAll("title").data([0]),e=i.enter().append("title").attr("id",this._uuid+"-title"),i=(i.merge(e).text(this._svgTitle),this._select.selectAll("desc").data([0])),e=i.enter().append("desc").attr("id",this._uuid+"-desc");if(i.merge(e).text(this._svgDesc),this._visiblePoll=clearInterval(this._visiblePoll),this._resizePoll=clearTimeout(this._resizePoll),this._scrollPoll=clearTimeout(this._scrollPoll),j.select(this._scrollContainer).on("scroll."+this._uuid,null),this._detectVisible&&"hidden"===this._select.style("visibility"))this._visiblePoll=setInterval(()=>{"hidden"!==this._select.style("visibility")&&(this._visiblePoll=clearInterval(this._visiblePoll),this.render(s))},this._detectVisibleInterval);else if(this._detectVisible&&"none"===this._select.style("display"))this._visiblePoll=setInterval(()=>{"none"!==this._select.style("display")&&(this._visiblePoll=clearInterval(this._visiblePoll),this.render(s))},this._detectVisibleInterval);else if(this._detectVisible&&!Pt.inViewport(this._select.node()))j.select(this._scrollContainer).on("scroll."+this._uuid,()=>{this._scrollPoll||(this._scrollPoll=setTimeout(()=>{Pt.inViewport(this._select.node())&&(j.select(this._scrollContainer).on("scroll."+this._uuid,null),this.render(s)),this._scrollPoll=clearTimeout(this._scrollPoll)},this._detectVisibleInterval))});else{let e=b.queue();this._queue.forEach(t=>{var i=this._cache?this._lrucache.get(t[3]+"_"+t[1]):void 0;i?this["_"+t[3]]=t[2]?t[2](i):i:e.defer(...t)}),this._queue=[],this._loadingMessage&&e._tasks.length&&this._messageClass.render({container:this._select.node().parentNode,html:this._loadingHTML(this),mask:!!this._filteredData&&this._messageMask,style:this._messageStyle}),e.awaitAll(()=>{
2733
2736
  // creates a data table as DOM elements inside of the SVG for accessibility
2734
2737
  // only if this._ariaHidden is set to true
2735
2738
  let e=this._data instanceof Array&&0<this._data.length?Object.keys(this._data[0]):[];var t=this._select.selectAll("g.data-table").data(!this._ariaHidden&&this._data instanceof Array&&this._data.length?[0]:[]),i=t.enter().append("g").attr("class","data-table").attr("role","table"),t=(t.exit().remove(),t.merge(i).selectAll("text").data(this._data instanceof Array?Dt.range(0,this._data.length+1):[])),i=(t.exit().remove(),t.merge(t.enter().append("text").attr("role","row")).selectAll("tspan").data((t,i)=>e.map(t=>({role:i?"cell":"columnheader",text:i?this._data[i-1][t]:t}))));i.exit().remove(),i.merge(i.enter().append("tspan")).attr("role",t=>t.role).attr("dy","-1000px").html(t=>t.text),
2736
2739
  // finishes the draw cycle
2737
- this._preDraw(),this._draw(s),bt.bind(this)(),function(){let t=j.select(this._select.node().parentNode).selectAll("div.d3plus-attribution").data(this._attribution?[0]:[]);var i=t.enter().append("div").attr("class","d3plus-attribution");t.exit().remove(),t=t.merge(i).style("position","absolute").html(this._attribution).style("right",this._margin.right+"px").style("bottom",this._margin.bottom+"px").call(Pt.stylize,this._attributionStyle)}.bind(this)(),!this._messageClass._isVisible||this._noDataMessage&&!this._filteredData.length||(this._messageClass.hide(),"0"===this._select.attr("opacity")&&this._select.transition().duration(this._duration).attr("opacity",1)),this._detectResize&&(this._autoWidth||this._autoHeight)&&j.select(this._resizeContainer).on("resize."+this._uuid,()=>{this._resizePoll=clearTimeout(this._resizePoll),this._resizePoll=setTimeout(()=>{this._resizePoll=clearTimeout(this._resizePoll),h.bind(this)(),this.render(s)},this._detectResizeDelay)}),s&&setTimeout(s,this._duration+100)})}
2740
+ this._preDraw(),this._draw(s),bt.bind(this)(),function(){let t=j.select(this._select.node().parentNode).selectAll("div.d3plus-attribution").data(this._attribution?[0]:[]);var i=t.enter().append("div").attr("class","d3plus-attribution");t.exit().remove(),t=t.merge(i).style("position","absolute").html(this._attribution).style("right",this._margin.right+"px").style("bottom",this._margin.bottom+"px").call(Pt.stylize,this._attributionStyle)}.bind(this)(),!this._messageClass._isVisible||this._noDataMessage&&!this._filteredData.length||(this._messageClass.hide(),"0"===this._select.attr("opacity")&&this._select.transition().duration(this._duration).attr("opacity",1)),this._detectResize&&(this._autoWidth||this._autoHeight)?this._resizeObserver.observe(this._select.node().parentNode):this._resizeObserver.unobserve(this._select.node().parentNode),s&&setTimeout(s,this._duration+100)})}
2738
2741
  // Attaches touchstart event listener to the BODY to hide the tooltip when the user touches any element without data
2739
2742
  return j.select("body").on("touchstart."+this._uuid,
2740
2743
  /**
@@ -3027,12 +3030,6 @@ return j.select("body").on("touchstart."+this._uuid,
3027
3030
  @param {Boolean} [*value* = true]
3028
3031
  @chainable
3029
3032
  */noDataMessage(t){return arguments.length?(this._noDataMessage=t,this):this._noDataMessage}
3030
- /**
3031
- @memberof Viz
3032
- @desc If using resize detection, this method allow a custom override of the element to which the resize detection function gets attached.
3033
- @param {String|HTMLElement} *selector*
3034
- @chainable
3035
- */resizeContainer(t){return arguments.length?(this._resizeContainer=t,this):this._resizeContainer}
3036
3033
  /**
3037
3034
  @memberof Viz
3038
3035
  @desc If using scroll or visibility detection, this method allow a custom override of the element to which the scroll detection function gets attached.
@@ -3327,7 +3324,7 @@ this._on[t].toString()!==i),o=this._on["click.legend"]&&this._on["click.legend"]
3327
3324
  this._select.style("cursor",r||o&&l?"pointer":"auto"),this._legendFilterInvert.bind(this)()),l=this._solo.includes(t),_=this._hidden.includes(t);
3328
3325
  // does the legend still have our default "click.legend" event?
3329
3326
  // (if the user only sets "click", both functions will fire)
3330
- this._tooltipClass.data([h||e]).footer(!!o&&(r?this._solo.length&&!l||_?s("Click to Highlight"):1===this._solo.length&&l||this._hidden.length===a-1?s("Click to Show All"):s("Click to Highlight")+"<br />"+s("Shift+Click to Hide"):this._solo.length&&!l||_?s("Click to Show")+"<br />"+s("Shift+Click to Highlight"):1===this._solo.length&&l||this._hidden.length===a-1?s("Click to Show All"):s("Click to Hide")+"<br />"+s("Shift+Click to Highlight"))).title(this._legendConfig.label?this._legendClass.label():ft.bind(this)).position(n).config(jt.bind(this)(this._tooltipConfig)).config(jt.bind(this)(this._legendTooltip)).render()}}.bind(this)},this._queue=[],this._resizeContainer="undefined"==typeof window?"":window,this._scrollContainer="undefined"==typeof window?"":window,this._shape=Ht("Rect"),this._shapes=[],this._shapeConfig={ariaLabel:(t,i)=>this._drawLabel(t,i),fill:(i,e)=>{for(;i.__d3plus__&&i.data;)e=(i=i.data).i;if(this._colorScale){let t=this._colorScale(i,e);var s,h;if(null!=t)return s=this._colorScaleClass._colorScale,h=this._colorScaleClass.color(),s?s.domain().length?s(t):s.range()[s.range().length-1]:h instanceof Array?h[h.length-1]:h}let t=this._color(i,e);return n.color(t)?t:A.colorAssign("string"==typeof t?t:JSON.stringify(t),this._colorDefaults)},labelConfig:{fontColor:(t,i)=>{t="function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,i):this._shapeConfig.fill;return A.colorContrast(t)}},opacity:Ht(1),stroke:(t,i)=>{t="function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,i):this._shapeConfig.fill;return n.color(t).darker(.25)},role:"presentation",strokeWidth:Ht(0)},this._solo=[],this._subtitleClass=new l,this._subtitleConfig={ariaHidden:!0,fontSize:12,padding:5,resize:!1,textAnchor:"middle"},this._subtitlePadding=At,this._svgDesc="",this._svgTitle="",this._timeline=!0,this._timelineClass=(new dt).align("end"),this._timelineConfig={padding:5},this._timelinePadding=At,this._threshold=Ht(1e-4),this._thresholdKey=void 0,this._thresholdName=()=>this._translate("Values"),this._titleClass=new l,this._titleConfig={ariaHidden:!0,fontSize:16,padding:5,resize:!1,textAnchor:"middle"},this._titlePadding=At,this._tooltip=Ht(!0),this._tooltipClass=new ct,this._tooltipConfig={pointerEvents:"none",titleStyle:{"max-width":"200px"}},this._totalClass=new l,this._totalConfig={fontSize:10,padding:5,resize:!1,textAnchor:"middle"},this._totalFormat=t=>this._translate("Total")+": "+Tt.formatAbbreviate(t,this._locale),this._totalPadding=At,this._zoom=!1,this._zoomBehavior=d.zoom(),this._zoomBrush=y.brush(),this._zoomBrushHandleSize=1,this._zoomBrushHandleStyle={fill:"#444"},this._zoomBrushSelectionStyle={fill:"#777","stroke-width":0},this._zoomControlStyle={background:"rgba(255, 255, 255, 0.75)",border:"1px solid rgba(0, 0, 0, 0.75)",color:"rgba(0, 0, 0, 0.75)",display:"block",font:"900 15px/21px "+H.fontFamilyStringify(H.fontFamily),height:"20px",margin:"5px",opacity:.75,padding:0,"text-align":"center",width:"20px"},this._zoomControlStyleActive={background:"rgba(0, 0, 0, 0.75)",color:"rgba(255, 255, 255, 0.75)",opacity:1},this._zoomControlStyleHover={cursor:"pointer",opacity:1},this._zoomFactor=2,this._zoomMax=16,this._zoomPadding=20,this._zoomPan=!0,this._zoomScroll=!0}}
3327
+ this._tooltipClass.data([h||e]).footer(!!o&&(r?this._solo.length&&!l||_?s("Click to Highlight"):1===this._solo.length&&l||this._hidden.length===a-1?s("Click to Show All"):s("Click to Highlight")+"<br />"+s("Shift+Click to Hide"):this._solo.length&&!l||_?s("Click to Show")+"<br />"+s("Shift+Click to Highlight"):1===this._solo.length&&l||this._hidden.length===a-1?s("Click to Show All"):s("Click to Hide")+"<br />"+s("Shift+Click to Highlight"))).title(this._legendConfig.label?this._legendClass.label():ft.bind(this)).position(n).config(jt.bind(this)(this._tooltipConfig)).config(jt.bind(this)(this._legendTooltip)).render()}}.bind(this)},this._queue=[],this._resizeObserver=new ResizeObserver(((e,s)=>{let h;return function(...t){let i=this;clearTimeout(h),h=setTimeout(()=>e.apply(i,t),s)}})(()=>{this._setSVGSize(),this.render(this._callback)},this._detectResizeDelay)),this._scrollContainer="undefined"==typeof window?"":window,this._shape=Ht("Rect"),this._shapes=[],this._shapeConfig={ariaLabel:(t,i)=>this._drawLabel(t,i),fill:(i,e)=>{for(;i.__d3plus__&&i.data;)e=(i=i.data).i;if(this._colorScale){let t=this._colorScale(i,e);var s,h;if(null!=t)return s=this._colorScaleClass._colorScale,h=this._colorScaleClass.color(),s?s.domain().length?s(t):s.range()[s.range().length-1]:h instanceof Array?h[h.length-1]:h}let t=this._color(i,e);return n.color(t)?t:A.colorAssign("string"==typeof t?t:JSON.stringify(t),this._colorDefaults)},labelConfig:{fontColor:(t,i)=>{t="function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,i):this._shapeConfig.fill;return A.colorContrast(t)}},opacity:Ht(1),stroke:(t,i)=>{t="function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,i):this._shapeConfig.fill;return n.color(t).darker(.25)},role:"presentation",strokeWidth:Ht(0)},this._solo=[],this._subtitleClass=new l,this._subtitleConfig={ariaHidden:!0,fontSize:12,padding:5,resize:!1,textAnchor:"middle"},this._subtitlePadding=At,this._svgDesc="",this._svgTitle="",this._timeline=!0,this._timelineClass=(new dt).align("end"),this._timelineConfig={padding:5},this._timelinePadding=At,this._threshold=Ht(1e-4),this._thresholdKey=void 0,this._thresholdName=()=>this._translate("Values"),this._titleClass=new l,this._titleConfig={ariaHidden:!0,fontSize:16,padding:5,resize:!1,textAnchor:"middle"},this._titlePadding=At,this._tooltip=Ht(!0),this._tooltipClass=new ct,this._tooltipConfig={pointerEvents:"none",titleStyle:{"max-width":"200px"}},this._totalClass=new l,this._totalConfig={fontSize:10,padding:5,resize:!1,textAnchor:"middle"},this._totalFormat=t=>this._translate("Total")+": "+Tt.formatAbbreviate(t,this._locale),this._totalPadding=At,this._zoom=!1,this._zoomBehavior=d.zoom(),this._zoomBrush=y.brush(),this._zoomBrushHandleSize=1,this._zoomBrushHandleStyle={fill:"#444"},this._zoomBrushSelectionStyle={fill:"#777","stroke-width":0},this._zoomControlStyle={background:"rgba(255, 255, 255, 0.75)",border:"1px solid rgba(0, 0, 0, 0.75)",color:"rgba(0, 0, 0, 0.75)",display:"block",font:"900 15px/21px "+H.fontFamilyStringify(H.fontFamily),height:"20px",margin:"5px",opacity:.75,padding:0,"text-align":"center",width:"20px"},this._zoomControlStyleActive={background:"rgba(0, 0, 0, 0.75)",color:"rgba(255, 255, 255, 0.75)",opacity:1},this._zoomControlStyleHover={cursor:"pointer",opacity:1},this._zoomFactor=2,this._zoomMax=16,this._zoomPadding=20,this._zoomPan=!0,this._zoomScroll=!0}}
3331
3328
  /**
3332
3329
  @module discreteBuffer
3333
3330
  @desc Adds left/right padding to a point or time scale.