d3plus-shape
Advanced tools
Comparing version 0.16.8 to 0.16.9
/* | ||
d3plus-shape v0.16.8 | ||
d3plus-shape v0.16.9 | ||
Fancy SVG shapes for visualizations | ||
@@ -7,2 +7,2 @@ Copyright (c) 2019 D3plus - https://d3plus.org | ||
*/ | ||
if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function t(e){"use strict";if(e===null){throw new TypeError("Cannot convert undefined or null to object")}var i=Object(e);for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r!==null){for(var s in r){if(Object.prototype.hasOwnProperty.call(r,s)){i[s]=r[s]}}}}return i},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function t(e,i){var n=Object(this);var r=n.length>>>0;if(r===0)return false;var s=i|0;var o=Math.max(s>=0?s:r-Math.abs(s),0);function a(t,e){return t===e||typeof t==="number"&&typeof e==="number"&&isNaN(t)&&isNaN(e)}while(o<r){if(a(n[o],e)){return true}o++}return false}})}if(!String.prototype.includes){Object.defineProperty(String.prototype,"includes",{value:function(t,e){if(typeof e!=="number"){e=0}if(e+t.length>this.length){return false}else{return this.indexOf(t,e)!==-1}}})}if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(t){if(this==null){throw new TypeError('"this" is null or not defined')}var e=Object(this);var i=e.length>>>0;if(typeof t!=="function"){throw new TypeError("predicate must be a function")}var n=arguments[1];var r=0;while(r<i){var s=e[r];if(t.call(n,s,r,e)){return s}r++}return undefined},configurable:true,writable:true})}if(!String.prototype.startsWith){Object.defineProperty(String.prototype,"startsWith",{value:function(t,e){e=!e||e<0?0:+e;return this.substring(e,e+t.length)===t}})}if(typeof window!=="undefined"){(function(){var n=function(t,e){var i=t.nodeType;if(i===3){e.push(t.textContent.replace(/&/,"&").replace(/</,"<").replace(">",">"))}else if(i===1){e.push("<",t.tagName);if(t.hasAttributes()){[].forEach.call(t.attributes,function(t){e.push(" ",t.item.name,"='",t.item.value,"'")})}if(t.hasChildNodes()){e.push(">");[].forEach.call(t.childNodes,function(t){n(t,e)});e.push("</",t.tagName,">")}else{e.push("/>")}}else if(i==8){e.push("\x3c!--",t.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t=[];var e=this.firstChild;while(e){n(e,t);e=e.nextSibling}return t.join("")},set:function(t){while(this.firstChild){this.removeChild(this.firstChild)}try{var e=new DOMParser;e.async=false;var i="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+t+"</svg>";var n=e.parseFromString(i,"text/xml").documentElement;var r=n.firstChild;while(r){this.appendChild(this.ownerDocument.importNode(r,true));r=r.nextSibling}}catch(t){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(t){this.innerHTML=t}})})()}(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("d3-selection"),require("d3-transition"),require("d3plus-common"),require("d3-array"),require("d3-color"),require("d3plus-color"),require("d3-shape"),require("d3plus-text"),require("d3-polygon"),require("d3-collection"),require("d3-interpolate-path")):typeof define==="function"&&define.amd?define("d3plus-shape",["exports","d3-selection","d3-transition","d3plus-common","d3-array","d3-color","d3plus-color","d3-shape","d3plus-text","d3-polygon","d3-collection","d3-interpolate-path"],e):e(t.d3plus={},t.d3Selection,t.d3Transition,t.d3plusCommon,t.d3Array,t.d3Color,t.d3plusColor,t.paths,t.d3plusText,t.d3Polygon,t.d3Collection,t.d3InterpolatePath)})(this,function(t,f,d,y,ut,r,i,v,g,pt,l,o){"use strict";var h=function t(){this._duration=600;this._height=y.accessor("height");this._id=y.accessor("id");this._pointerEvents=y.constant("auto");this._select;this._url=y.accessor("url");this._width=y.accessor("width");this._x=y.accessor("x",0);this._y=y.accessor("y",0)};h.prototype.render=function t(e){var i=this;if(this._select===void 0){this.select(f.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").style("display","block").node())}var n=this._select.selectAll(".d3plus-Image").data(this._data,this._id);var r=n.enter().append("image").attr("class","d3plus-Image").attr("opacity",0).attr("width",0).attr("height",0).attr("x",function(t,e){return i._x(t,e)+i._width(t,e)/2}).attr("y",function(t,e){return i._y(t,e)+i._height(t,e)/2});var s=d.transition().duration(this._duration),o=this,a=r.merge(n);a.attr("xlink:href",this._url).style("pointer-events",this._pointerEvents).transition(s).attr("opacity",1).attr("width",function(t,e){return i._width(t,e)}).attr("height",function(t,e){return i._height(t,e)}).attr("x",function(t,e){return i._x(t,e)}).attr("y",function(t,e){return i._y(t,e)}).each(function(t,e){var i=f.select(this),n=o._url(t,e);var r=n.indexOf("http://")===0||n.indexOf("https://")===0;if(!r||n.indexOf(window.location.hostname)===0){var s=new h;s.src=n;s.crossOrigin="Anonymous";s.onload=function(){var t=document.createElement("canvas");t.width=this.width;t.height=this.height;var e=t.getContext("2d");e.drawImage(this,0,0);i.attr("xlink:href",t.toDataURL("image/png"))}}});n.exit().transition(s).attr("width",function(t,e){return i._width(t,e)}).attr("height",function(t,e){return i._height(t,e)}).attr("x",function(t,e){return i._x(t,e)}).attr("y",function(t,e){return i._y(t,e)}).attr("opacity",0).remove();if(e){setTimeout(e,this._duration+100)}return this};h.prototype.data=function t(e){return arguments.length?(this._data=e,this):this._data};h.prototype.duration=function t(e){return arguments.length?(this._duration=e,this):this._duration};h.prototype.height=function t(e){return arguments.length?(this._height=typeof e==="function"?e:y.constant(e),this):this._height};h.prototype.id=function t(e){return arguments.length?(this._id=e,this):this._id};h.prototype.pointerEvents=function t(e){return arguments.length?(this._pointerEvents=typeof e==="function"?e:y.constant(e),this):this._pointerEvents};h.prototype.select=function t(e){return arguments.length?(this._select=f.select(e),this):this._select};h.prototype.url=function t(e){return arguments.length?(this._url=e,this):this._url};h.prototype.width=function t(e){return arguments.length?(this._width=typeof e==="function"?e:y.constant(e),this):this._width};h.prototype.x=function t(e){return arguments.length?(this._x=typeof e==="function"?e:y.constant(e),this):this._x};h.prototype.y=function t(e){return arguments.length?(this._y=typeof e==="function"?e:y.constant(e),this):this._y};function _t(t,e){var i=e[0]-t[0],n=e[1]-t[1];return i*i+n*n}function x(t,e){return Math.sqrt(_t(t,e))}var e=function(e){function t(t){var n=this;if(t===void 0)t="g";e.call(this);this._activeOpacity=.25;this._activeStyle={stroke:function(t,e){var i=n._fill(t,e);if(["transparent","none"].includes(i)){i=n._stroke(t,e)}return r.color(i).darker(1)},"stroke-width":function(t,e){var i=n._strokeWidth(t,e)||1;return i*3}};this._ariaLabel=y.constant("");this._backgroundImage=y.constant(false);this._backgroundImageClass=new h;this._data=[];this._duration=600;this._fill=y.constant("black");this._fillOpacity=y.constant(1);this._hoverOpacity=.5;this._hoverStyle={stroke:function(t,e){var i=n._fill(t,e);if(["transparent","none"].includes(i)){i=n._stroke(t,e)}return r.color(i).darker(.5)},"stroke-width":function(t,e){var i=n._strokeWidth(t,e)||1;return i*2}};this._id=function(t,e){return t.id!==void 0?t.id:e};this._label=y.constant(false);this._labelClass=new g.TextBox;this._labelConfig={fontColor:function(t,e){return i.colorContrast(n._fill(t,e))},fontSize:12,padding:5};this._name="Shape";this._opacity=y.constant(1);this._pointerEvents=y.constant("visiblePainted");this._role=y.constant("presentation");this._rotate=y.constant(0);this._rx=y.constant(0);this._ry=y.constant(0);this._scale=y.constant(1);this._shapeRendering=y.constant("geometricPrecision");this._stroke=function(t,e){return r.color(n._fill(t,e)).darker(1)};this._strokeDasharray=y.constant("0");this._strokeLinecap=y.constant("butt");this._strokeOpacity=y.constant(1);this._strokeWidth=y.constant(0);this._tagName=t;this._textAnchor=y.constant("start");this._vectorEffect=y.constant("non-scaling-stroke");this._verticalAlign=y.constant("top");this._x=y.accessor("x",0);this._y=y.accessor("y",0)}if(e)t.__proto__=e;t.prototype=Object.create(e&&e.prototype);t.prototype.constructor=t;t.prototype._aes=function t(){return{}};t.prototype._applyEvents=function t(e){var s=this;var o=Object.keys(this._on);var i=function(r){e.on(o[r],function(t,e){if(!s._on[o[r]]){return}if(t.i!==void 0){e=t.i}if(t.nested&&t.values){var i=f.mouse(s._select.node()),n=t.values.map(function(t){return x(i,[s._x(t,e),s._y(t,e)])});t=t.values[n.indexOf(ut.min(n))]}s._on[o[r]].bind(s)(t,e)})};for(var n=0;n<o.length;n++)i(n)};t.prototype._updateStyle=function t(e,i){var n=this;if(e.size()&&e.node().tagName==="g"){e=e.selectAll("*")}function r(t,e){return typeof this!=="function"?this:t.nested&&t.key&&t.values?this(t.values[0],n._data.indexOf(t.values[0])):this(t,e)}var s={};for(var o in i){if({}.hasOwnProperty.call(i,o)){s[o]=r.bind(i[o])}}e.transition().duration(0).call(y.attrize,s)};t.prototype._applyStyle=function t(e){var i=this;if(e.size()&&e.node().tagName==="g"){e=e.selectAll("*")}function n(t,e){return typeof this!=="function"?this:t.nested&&t.key&&t.values?this(t.values[0],i._data.indexOf(t.values[0])):this(t,e)}e.attr("fill",n.bind(this._fill)).attr("fill-opacity",n.bind(this._fillOpacity)).attr("rx",n.bind(this._rx)).attr("ry",n.bind(this._ry)).attr("stroke",n.bind(this._stroke)).attr("stroke-dasharray",n.bind(this._strokeDasharray)).attr("stroke-linecap",n.bind(this._strokeLinecap)).attr("stroke-opacity",n.bind(this._strokeOpacity)).attr("stroke-width",n.bind(this._strokeWidth)).attr("vector-effect",n.bind(this._vectorEffect))};t.prototype._applyTransform=function t(e){var i=this;e.attr("transform",function(t,e){return"\n translate("+(t.__d3plusShape__?t.translate?t.translate:i._x(t.data,t.i)+","+i._y(t.data,t.i):i._x(t,e)+","+i._y(t,e))+")\n scale("+(t.__d3plusShape__?t.scale||i._scale(t.data,t.i):i._scale(t,e))+")\n rotate("+(t.__d3plusShape__?t.rotate?t.rotate:i._rotate(t.data||t,t.i):i._rotate(t.data||t,t.i))+")"})};t.prototype._nestWrapper=function t(i){return function(t,e){return i(t.__d3plusShape__?t.data:t,t.__d3plusShape__?t.i:e)}};t.prototype._renderActive=function t(){var r=this;this._group.selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(t,e){if(!t){t={}}if(!t.parentNode){t.parentNode=this.parentNode}var i=t.parentNode;if(f.select(this).classed("d3plus-textBox")){t=t.data}if(t.__d3plusShape__||t.__d3plus__){while(t&&(t.__d3plusShape__||t.__d3plus__)){e=t.i;t=t.data}}else{e=r._data.indexOf(t)}var n=!r._active||typeof r._active!=="function"||!r._active(t,e)?i:r._activeGroup.node();if(n!==this.parentNode){n.appendChild(this);if(this.className.baseVal.includes("d3plus-Shape")){if(i===n){f.select(this).call(r._applyStyle.bind(r))}else{f.select(this).call(r._updateStyle.bind(r,f.select(this),r._activeStyle))}}}});this._group.selectAll("g.d3plus-"+this._name+"-shape, g.d3plus-"+this._name+"-image, g.d3plus-"+this._name+"-text").attr("opacity",this._hover?this._hoverOpacity:this._active?this._activeOpacity:1)};t.prototype._renderHover=function t(){var r=this;this._group.selectAll("g.d3plus-"+this._name+"-shape, g.d3plus-"+this._name+"-image, g.d3plus-"+this._name+"-text, g.d3plus-"+this._name+"-hover").selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(t,e){if(!t){t={}}if(!t.parentNode){t.parentNode=this.parentNode}var i=t.parentNode;if(f.select(this).classed("d3plus-textBox")){t=t.data}if(t.__d3plusShape__||t.__d3plus__){while(t&&(t.__d3plusShape__||t.__d3plus__)){e=t.i;t=t.data}}else{e=r._data.indexOf(t)}var n=!r._hover||typeof r._hover!=="function"||!r._hover(t,e)?i:r._hoverGroup.node();if(n!==this.parentNode){n.appendChild(this)}if(this.className.baseVal.includes("d3plus-Shape")){if(i===n){f.select(this).call(r._applyStyle.bind(r))}else{f.select(this).call(r._updateStyle.bind(r,f.select(this),r._hoverStyle))}}});this._group.selectAll("g.d3plus-"+this._name+"-shape, g.d3plus-"+this._name+"-image, g.d3plus-"+this._name+"-text").attr("opacity",this._hover?this._hoverOpacity:this._active?this._activeOpacity:1)};t.prototype._renderImage=function t(){var l=this;var c=[];this._update.merge(this._enter).data().forEach(function(t,e){var i=l._aes(t,e);if(i.r||i.width&&i.height){var n=t;if(t.nested&&t.key&&t.values){n=t.values[0];e=l._data.indexOf(n)}var r=i.r?i.r*2:i.height,s=l._backgroundImage(n,e),o=i.r?i.r*2:i.width;if(s){var a=n.__d3plusShape__?n.translate?n.translate[0]:l._x(n.data,n.i):l._x(n,e),h=n.__d3plusShape__?n.translate?n.translate[1]:l._y(n.data,n.i):l._y(n,e);if(i.x){a+=i.x}if(i.y){h+=i.y}if(n.__d3plusShape__){n=n.data;e=n.i}c.push({__d3plus__:true,data:n,height:r,i:e,id:l._id(n,e),url:s,width:o,x:a+-o/2,y:h+-r/2})}}});this._backgroundImageClass.data(c).duration(this._duration).pointerEvents("none").select(y.elem("g.d3plus-"+this._name+"-image",{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).node()).render()};t.prototype._renderLabels=function t(){var p=this;var _=[];this._update.merge(this._enter).data().forEach(function(t,e){var i=t;if(t.nested&&t.key&&t.values){i=t.values[0];e=p._data.indexOf(i)}var n=p._label(i,e);if(p._labelBounds&&n!==false&&n!==undefined&&n!==null){var r=p._labelBounds(i,e,p._aes(t,e));if(r){if(n.constructor!==Array){n=[n]}var s=i.__d3plusShape__?i.translate?i.translate[0]:p._x(i.data,i.i):p._x(i,e),o=i.__d3plusShape__?i.translate?i.translate[1]:p._y(i.data,i.i):p._y(i,e);if(i.__d3plusShape__){i=i.data;e=i.i}for(var a=0;a<n.length;a++){var h=r.constructor===Array?r[a]:Object.assign({},r);var l=p._rotate(i,e);var c=i.labelConfig&&i.labelConfig.rotate?i.labelConfig.rotate:r.angle!==undefined?r.angle:0;c+=l;var u=l!==0?[h.x*-1||0,h.y*-1||0]:[h.width/2,h.height/2];_.push({__d3plus__:true,data:i,height:h.height,l:a,id:p._id(i,e)+"_"+a,r:c,rotateAnchor:u,text:n[a],width:h.width,x:s+h.x,y:o+h.y})}}}});this._labelClass.data(_).duration(this._duration).pointerEvents("none").rotate(function(t){return t.__d3plus__?t.r:t.data.r}).rotateAnchor(function(t){return t.__d3plus__?t.rotateAnchor:t.data.rotateAnchor}).select(y.elem("g.d3plus-"+this._name+"-text",{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).node()).config(y.configPrep.bind(this)(this._labelConfig)).render()};t.prototype.render=function t(e){var i=this;if(this._select===void 0){this.select(f.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").style("display","block").node())}this._transition=d.transition().duration(this._duration);var n=this._data,r=this._id;if(this._dataFilter){n=this._dataFilter(n);if(n.key){r=n.key}}if(this._sort){n=n.sort(function(t,e){while(t.__d3plusShape__||t.__d3plus__){t=t.data}while(e.__d3plusShape__||e.__d3plus__){e=e.data}return i._sort(t,e)})}f.selectAll("g.d3plus-"+this._name+"-hover > *, g.d3plus-"+this._name+"-active > *").each(function(t){if(t&&t.parentNode){t.parentNode.appendChild(this)}else{this.parentNode.removeChild(this)}});this._group=y.elem("g.d3plus-"+this._name+"-group",{parent:this._select});var s=this._update=y.elem("g.d3plus-"+this._name+"-shape",{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).selectAll(".d3plus-"+this._name).data(n,r);s.order().transition(this._transition).call(this._applyTransform.bind(this));var o=this._enter=s.enter().append(this._tagName).attr("class",function(t,e){return"d3plus-Shape d3plus-"+i._name+" d3plus-id-"+g.strip(i._nestWrapper(i._id)(t,e))}).call(this._applyTransform.bind(this)).attr("aria-label",this._ariaLabel).attr("role",this._role).attr("opacity",this._nestWrapper(this._opacity));var a=o.merge(s);a.attr("shape-rendering",this._nestWrapper(this._shapeRendering)).attr("pointer-events","none").transition(this._transition).attr("opacity",this._nestWrapper(this._opacity)).attr("pointer-events",this._pointerEvents);var h=this._exit=s.exit();h.transition().delay(this._duration).remove();this._renderImage();this._renderLabels();this._hoverGroup=y.elem("g.d3plus-"+this._name+"-hover",{parent:this._group});this._activeGroup=y.elem("g.d3plus-"+this._name+"-active",{parent:this._group});var l=this._group.selectAll(".d3plus-HitArea").data(this._hitArea?n:[],r);l.order().call(this._applyTransform.bind(this));var c=this._name==="Line";c&&this._path.curve(v["curve"+this._curve.charAt(0).toUpperCase()+this._curve.slice(1)]).defined(this._defined).x(this._x).y(this._y);var u=l.enter().append(c?"path":"rect").attr("class",function(t,e){return"d3plus-HitArea d3plus-id-"+g.strip(i._nestWrapper(i._id)(t,e))}).attr("fill","black").attr("stroke","black").attr("pointer-events","painted").attr("opacity",0).call(this._applyTransform.bind(this));var p=this;var _=l.merge(u).each(function(t){var e=p._data.indexOf(t);var i=p._hitArea(t,e,p._aes(t,e));return i&&!(p._name==="Line"&&parseFloat(p._strokeWidth(t,e))>10)?f.select(this).call(y.attrize,i):f.select(this).remove()});l.exit().remove();this._applyEvents(this._hitArea?_:a);setTimeout(function(){if(i._active){i._renderActive()}else if(i._hover){i._renderHover()}if(e){e()}},this._duration+100);return this};t.prototype.active=function t(e){if(!arguments.length||e===undefined){return this._active}this._active=e;if(this._group){this._renderActive()}return this};t.prototype.activeOpacity=function t(e){return arguments.length?(this._activeOpacity=e,this):this._activeOpacity};t.prototype.activeStyle=function t(e){return arguments.length?(this._activeStyle=y.assign({},this._activeStyle,e),this):this._activeStyle};t.prototype.ariaLabel=function t(e){return e!==undefined?(this._ariaLabel=typeof e==="function"?e:y.constant(e),this):this._ariaLabel};t.prototype.backgroundImage=function t(e){return arguments.length?(this._backgroundImage=typeof e==="function"?e:y.constant(e),this):this._backgroundImage};t.prototype.data=function t(e){return arguments.length?(this._data=e,this):this._data};t.prototype.duration=function t(e){return arguments.length?(this._duration=e,this):this._duration};t.prototype.fill=function t(e){return arguments.length?(this._fill=typeof e==="function"?e:y.constant(e),this):this._fill};t.prototype.fillOpacity=function t(e){return arguments.length?(this._fillOpacity=typeof e==="function"?e:y.constant(e),this):this._fillOpacity};t.prototype.hover=function t(e){if(!arguments.length||e===void 0){return this._hover}this._hover=e;if(this._group){this._renderHover()}return this};t.prototype.hoverStyle=function t(e){return arguments.length?(this._hoverStyle=y.assign({},this._hoverStyle,e),this):this._hoverStyle};t.prototype.hoverOpacity=function t(e){return arguments.length?(this._hoverOpacity=e,this):this._hoverOpacity};t.prototype.hitArea=function t(e){return arguments.length?(this._hitArea=typeof e==="function"?e:y.constant(e),this):this._hitArea};t.prototype.id=function t(e){return arguments.length?(this._id=e,this):this._id};t.prototype.label=function t(e){return arguments.length?(this._label=typeof e==="function"?e:y.constant(e),this):this._label};t.prototype.labelBounds=function t(e){return arguments.length?(this._labelBounds=typeof e==="function"?e:y.constant(e),this):this._labelBounds};t.prototype.labelConfig=function t(e){return arguments.length?(this._labelConfig=y.assign(this._labelConfig,e),this):this._labelConfig};t.prototype.opacity=function t(e){return arguments.length?(this._opacity=typeof e==="function"?e:y.constant(e),this):this._opacity};t.prototype.pointerEvents=function t(e){return arguments.length?(this._pointerEvents=typeof e==="function"?e:y.constant(e),this):this._pointerEvents};t.prototype.role=function t(e){return e!==undefined?(this._role=typeof e==="function"?e:y.constant(e),this):this._role};t.prototype.rotate=function t(e){return arguments.length?(this._rotate=typeof e==="function"?e:y.constant(e),this):this._rotate};t.prototype.rx=function t(e){return arguments.length?(this._rx=typeof e==="function"?e:y.constant(e),this):this._rx};t.prototype.ry=function t(e){return arguments.length?(this._ry=typeof e==="function"?e:y.constant(e),this):this._ry};t.prototype.scale=function t(e){return arguments.length?(this._scale=typeof e==="function"?e:y.constant(e),this):this._scale};t.prototype.select=function t(e){return arguments.length?(this._select=f.select(e),this):this._select};t.prototype.shapeRendering=function t(e){return arguments.length?(this._shapeRendering=typeof e==="function"?e:y.constant(e),this):this._shapeRendering};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.stroke=function t(e){return arguments.length?(this._stroke=typeof e==="function"?e:y.constant(e),this):this._stroke};t.prototype.strokeDasharray=function t(e){return arguments.length?(this._strokeDasharray=typeof e==="function"?e:y.constant(e),this):this._strokeDasharray};t.prototype.strokeLinecap=function t(e){return arguments.length?(this._strokeLinecap=typeof e==="function"?e:y.constant(e),this):this._strokeLinecap};t.prototype.strokeOpacity=function t(e){return arguments.length?(this._strokeOpacity=typeof e==="function"?e:y.constant(e),this):this._strokeOpacity};t.prototype.strokeWidth=function t(e){return arguments.length?(this._strokeWidth=typeof e==="function"?e:y.constant(e),this):this._strokeWidth};t.prototype.textAnchor=function t(e){return arguments.length?(this._textAnchor=typeof e==="function"?e:y.constant(e),this):this._textAnchor};t.prototype.vectorEffect=function t(e){return arguments.length?(this._vectorEffect=typeof e==="function"?e:y.constant(e),this):this._vectorEffect};t.prototype.verticalAlign=function t(e){return arguments.length?(this._verticalAlign=typeof e==="function"?e:y.constant(e),this):this._verticalAlign};t.prototype.x=function t(e){return arguments.length?(this._x=typeof e==="function"?e:y.constant(e),this):this._x};t.prototype.y=function t(e){return arguments.length?(this._y=typeof e==="function"?e:y.constant(e),this):this._y};return t}(y.BaseClass);function m(t,e,i,n){var r=1e-9;var s=t[0]-e[0],o=i[0]-n[0],a=t[1]-e[1],h=i[1]-n[1];var l=s*h-a*o;if(Math.abs(l)<r){return null}var c=t[0]*e[1]-t[1]*e[0],u=i[0]*n[1]-i[1]*n[0];var p=(c*o-u*s)/l,_=(c*h-u*a)/l;return[p,_]}function b(t,e,i){var n=1e-9;var r=i[0];var s=i[1];return!(r<Math.min(t[0],e[0])-n||r>Math.max(t[0],e[0])+n||s<Math.min(t[1],e[1])-n||s>Math.max(t[1],e[1])+n)}function c(t,e,i,n){var r=m(t,e,i,n);if(!r){return false}return b(t,e,r)&&b(i,n,r)}function ft(t,e){var i=-1;var n=t.length;var r=e.length;var s=t[n-1];while(++i<n){var o=s;s=t[i];var a=-1;var h=e[r-1];while(++a<r){var l=h;h=e[a];if(c(o,s,l,h)){return false}}}return pt.polygonContains(e,t[0])}function dt(t,e,i){if(i===void 0)i=0;var n=1e-9;e=[e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)];var r=e[0];var s=e[1];var o=[r+Math.cos(i),s+Math.sin(i)];var a=0;if(Math.abs(o[0]-r)<n){a=1}var h=-1;var l=t.length;var c=t[l-1];var u=Number.MAX_VALUE;var p=Number.MAX_VALUE;var _=null;var f=null;while(++h<l){var d=c;c=t[h];var y=m(e,o,d,c);if(y&&b(d,c,y)){var v=_t(e,y);if(y[a]<e[a]){if(v<u){u=v;_=y}}else if(y[a]>e[a]){if(v<p){p=v;f=y}}}}return[_,f]}function n(t,e,i){if(i===void 0)i=[0,0];var n=Math.cos(e),r=Math.sin(e),s=t[0]-i[0],o=t[1]-i[1];return[n*s-r*o+i[0],r*s+n*o+i[1]]}function yt(t,e,i){if(i===void 0)i=[0,0];return t.map(function(t){return n(t,e,i)})}function u(t,e,i){var n=e[0],r=e[1];var s=i[0]-n,o=i[1]-r;if(s!==0||o!==0){var a=((t[0]-n)*s+(t[1]-r)*o)/(s*s+o*o);if(a>1){n=i[0];r=i[1]}else if(a>0){n+=s*a;r+=o*a}}s=t[0]-n;o=t[1]-r;return s*s+o*o}function s(t,e){var i,n=t[0];var r=[n];for(var s=1,o=t.length;s<o;s++){i=t[s];if(_t(i,n)>e){r.push(i);n=i}}if(n!==i){r.push(i)}return r}function p(t,e,i,n,r){var s,o=n;for(var a=e+1;a<i;a++){var h=u(t[a],t[e],t[i]);if(h>o){s=a;o=h}}if(o>n){if(s-e>1){p(t,e,s,n,r)}r.push(t[s]);if(i-s>1){p(t,s,i,n,r)}}}function a(t,e){var i=t.length-1;var n=[t[0]];p(t,0,i,e,n);n.push(t[i]);return n}function vt(t,e,i){if(e===void 0)e=1;if(i===void 0)i=false;if(t.length<=2){return t}var n=e*e;t=i?t:s(t,n);t=a(t,n);return t}var gt=.5;var xt=5;var mt={};function _(t,e){var i,n;if(e===void 0)e={};if(t.length<3){if(e.verbose){console.error("polygon has to have at least 3 points",t)}return null}var r=[];e=Object.assign({angle:ut.range(-90,90+xt,xt),cache:true,maxAspectRatio:15,minAspectRatio:1,minHeight:0,minWidth:0,nTries:20,tolerance:.02,verbose:false},e);var s=e.angle instanceof Array?e.angle:typeof e.angle==="number"?[e.angle]:typeof e.angle==="string"&&!isNaN(e.angle)?[Number(e.angle)]:[];var o=e.aspectRatio instanceof Array?e.aspectRatio:typeof e.aspectRatio==="number"?[e.aspectRatio]:typeof e.aspectRatio==="string"&&!isNaN(e.aspectRatio)?[Number(e.aspectRatio)]:[];var a=e.origin&&e.origin instanceof Array?e.origin[0]instanceof Array?e.origin:[e.origin]:[];var h;if(e.cache){h=ut.merge(t).join(",");h+="-"+e.minAspectRatio;h+="-"+e.maxAspectRatio;h+="-"+e.minHeight;h+="-"+e.minWidth;h+="-"+s.join(",");h+="-"+a.join(",");if(mt[h]){return mt[h]}}var l=Math.abs(pt.polygonArea(t));if(l===0){if(e.verbose){console.error("polygon has 0 area",t)}return null}var c=ut.extent(t,function(t){return t[0]});var u=c[0];var p=c[1];var _=ut.extent(t,function(t){return t[1]});var f=_[0];var d=_[1];var y=Math.min(p-u,d-f)*e.tolerance;if(y>0){t=vt(t,y)}if(e.events){r.push({type:"simplify",poly:t})}i=ut.extent(t,function(t){return t[0]}),u=i[0],p=i[1];n=ut.extent(t,function(t){return t[1]}),f=n[0],d=n[1];var v=[p-u,d-f];var g=v[0];var x=v[1];var m=Math.min(g,x)/50;if(!a.length){var b=pt.polygonCentroid(t);if(!isFinite(b[0])){if(e.verbose){console.error("cannot find centroid",t)}return null}if(pt.polygonContains(t,b)){a.push(b)}var w=e.nTries;while(w){var k=Math.random()*g+u;var C=Math.random()*x+f;var O=[k,C];if(pt.polygonContains(t,O)){a.push(O)}w--}}if(e.events){r.push({type:"origins",points:a})}var A=0;var S=null;for(var M=0;M<s.length;M++){var E=s[M];var W=-E*Math.PI/180;if(e.events){r.push({type:"angle",angle:E})}for(var P=0;P<a.length;P++){var R=a[P];var L=dt(t,R,W);var N=L[0];var j=L[1];var B=dt(t,R,W+Math.PI/2);var H=B[0];var I=B[1];var q=[];if(N&&j){q.push([(N[0]+j[0])/2,(N[1]+j[1])/2])}if(H&&I){q.push([(H[0]+I[0])/2,(H[1]+I[1])/2])}if(e.events){r.push({type:"modifOrigin",idx:P,p1W:N,p2W:j,p1H:H,p2H:I,modifOrigins:q})}for(var T=0;T<q.length;T++){var D=q[T];if(e.events){r.push({type:"origin",cx:D[0],cy:D[1]})}var z=dt(t,D,W);var F=z[0];var V=z[1];if(F===null||V===null){continue}var G=Math.min(_t(D,F),_t(D,V));var U=2*Math.sqrt(G);var X=dt(t,D,W+Math.PI/2);var Y=X[0];var Z=X[1];if(Y===null||Z===null){continue}var J=Math.min(_t(D,Y),_t(D,Z));var K=2*Math.sqrt(J);if(U*K<A){continue}var Q=o;if(!Q.length){var $=Math.max(e.minAspectRatio,e.minWidth/K,A/(K*K));var tt=Math.min(e.maxAspectRatio,U/e.minHeight,U*U/A);Q=ut.range($,tt+gt,gt)}for(var et=0;et<Q.length;et++){var it=Q[et];var nt=Math.max(e.minWidth,Math.sqrt(A*it));var rt=Math.min(U,K*it);if(rt*K<A){continue}if(e.events&&rt-nt>=m){r.push({type:"aRatio",aRatio:it})}while(rt-nt>=m){var st=(nt+rt)/2;var ot=st/it;var at=D[0];var ht=D[1];var lt=[[at-st/2,ht-ot/2],[at+st/2,ht-ot/2],[at+st/2,ht+ot/2],[at-st/2,ht+ot/2]];lt=yt(lt,W,D);var ct=ft(lt,t);if(ct){A=st*ot;lt.push(lt[0]);S={area:A,cx:at,cy:ht,width:st,height:ot,angle:-E,points:lt};nt=st}else{rt=st}if(e.events){r.push({type:"rectangle",areaFraction:st*ot/l,cx:at,cy:ht,width:st,height:ot,angle:E,insidePoly:ct})}}}}}}if(e.cache){mt[h]=S}return e.events?Object.assign(S||{},{events:r}):S}var w=function(s){function t(){var r=this;s.call(this);this._curve="linear";this._defined=function(){return true};this._labelBounds=function(t,e,i){var n=_(i.points);if(!n){return null}return{angle:n.angle,width:n.width,height:n.height,x:n.cx-n.width/2-r._x(t,e),y:n.cy-n.height/2-r._y(t,e)}};this._labelConfig=Object.assign(this._labelConfig,{textAnchor:"middle",verticalAlign:"middle"});this._name="Area";this._x=y.accessor("x");this._x0=y.accessor("x");this._x1=null;this._y=y.constant(0);this._y0=y.constant(0);this._y1=y.accessor("y")}if(s)t.__proto__=s;t.prototype=Object.create(s&&s.prototype);t.prototype.constructor=t;t.prototype._aes=function t(e){var i=this;var n=e.values.slice().sort(function(t,e){return i._y1?i._x(t)-i._x(e):i._y(t)-i._y(e)});var r=n.map(function(t,e){return[i._x0(t,e),i._y0(t,e)]});var s=n.reverse().map(function(t,e){return i._y1?[i._x(t,e),i._y1(t,e)]:[i._x1(t,e),i._y(t,e)]});var o=r.concat(s);if(r[0][1]>s[0][1]){o=o.reverse()}o.push(o[0]);return{points:o}};t.prototype._dataFilter=function t(n){var r=this;var e=l.nest().key(this._id).entries(n).map(function(t){t.data=y.merge(t.values);t.i=n.indexOf(t.values[0]);var e=ut.extent(t.values.map(r._x).concat(t.values.map(r._x0)).concat(r._x1?t.values.map(r._x1):[]));t.xR=e;t.width=e[1]-e[0];t.x=e[0]+t.width/2;var i=ut.extent(t.values.map(r._y).concat(t.values.map(r._y0)).concat(r._y1?t.values.map(r._y1):[]));t.yR=i;t.height=i[1]-i[0];t.y=i[0]+t.height/2;t.nested=true;t.translate=[t.x,t.y];t.__d3plusShape__=true;return t});e.key=function(t){return t.key};return e};t.prototype.render=function t(e){s.prototype.render.call(this,e);var i=this._path=v.area().defined(this._defined).curve(v["curve"+this._curve.charAt(0).toUpperCase()+this._curve.slice(1)]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1);var n=v.area().defined(function(t){return t}).curve(v["curve"+this._curve.charAt(0).toUpperCase()+this._curve.slice(1)]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1);this._enter.append("path").attr("transform",function(t){return"translate("+(-t.xR[0]-t.width/2)+", "+(-t.yR[0]-t.height/2)+")"}).attr("d",function(t){return i(t.values)}).call(this._applyStyle.bind(this));this._update.select("path").transition(this._transition).attr("transform",function(t){return"translate("+(-t.xR[0]-t.width/2)+", "+(-t.yR[0]-t.height/2)+")"}).attrTween("d",function(t){return o.interpolatePath(f.select(this).attr("d"),i(t.values))}).call(this._applyStyle.bind(this));this._exit.select("path").transition(this._transition).attrTween("d",function(t){return o.interpolatePath(f.select(this).attr("d"),n(t.values))});return this};t.prototype.curve=function t(e){return arguments.length?(this._curve=e,this):this._curve};t.prototype.defined=function t(e){return arguments.length?(this._defined=e,this):this._defined};t.prototype.x=function t(e){if(!arguments.length){return this._x}this._x=typeof e==="function"?e:y.constant(e);this._x0=this._x;return this};t.prototype.x0=function t(e){if(!arguments.length){return this._x0}this._x0=typeof e==="function"?e:y.constant(e);this._x=this._x0;return this};t.prototype.x1=function t(e){return arguments.length?(this._x1=typeof e==="function"||e===null?e:y.constant(e),this):this._x1};t.prototype.y=function t(e){if(!arguments.length){return this._y}this._y=typeof e==="function"?e:y.constant(e);this._y0=this._y;return this};t.prototype.y0=function t(e){if(!arguments.length){return this._y0}this._y0=typeof e==="function"?e:y.constant(e);this._y=this._y0;return this};t.prototype.y1=function t(e){return arguments.length?(this._y1=typeof e==="function"||e===null?e:y.constant(e),this):this._y1};return t}(e);var k=function(r){function t(){var n=this;r.call(this,"rect");this._name="Bar";this._height=y.constant(10);this._labelBounds=function(t,e,i){return{width:i.width,height:i.height,x:n._x1!==null?n._getX(t,e):-i.width/2,y:n._x1===null?n._getY(t,e):-i.height/2}};this._width=y.constant(10);this._x=y.accessor("x");this._x0=y.accessor("x");this._x1=null;this._y=y.constant(0);this._y0=y.constant(0);this._y1=y.accessor("y")}if(r)t.__proto__=r;t.prototype=Object.create(r&&r.prototype);t.prototype.constructor=t;t.prototype.render=function t(e){var i=this;r.prototype.render.call(this,e);this._enter.attr("width",function(t,e){return i._x1===null?i._getWidth(t,e):0}).attr("height",function(t,e){return i._x1!==null?i._getHeight(t,e):0}).attr("x",function(t,e){return i._x1===null?-i._getWidth(t,e)/2:0}).attr("y",function(t,e){return i._x1!==null?-i._getHeight(t,e)/2:0}).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("width",function(t,e){return i._x1===null?i._getWidth(t,e):0}).attr("height",function(t,e){return i._x1!==null?i._getHeight(t,e):0}).attr("x",function(t,e){return i._x1===null?-i._getWidth(t,e)/2:0}).attr("y",function(t,e){return i._x1!==null?-i._getHeight(t,e)/2:0});return this};t.prototype._aes=function t(e,i){return{height:this._getHeight(e,i),width:this._getWidth(e,i)}};t.prototype._applyPosition=function t(e){var i=this;e.attr("width",function(t,e){return i._getWidth(t,e)}).attr("height",function(t,e){return i._getHeight(t,e)}).attr("x",function(t,e){return i._x1!==null?i._getX(t,e):-i._getWidth(t,e)/2}).attr("y",function(t,e){return i._x1===null?i._getY(t,e):-i._getHeight(t,e)/2})};t.prototype._getHeight=function t(e,i){if(this._x1!==null){return this._height(e,i)}return Math.abs(this._y1(e,i)-this._y(e,i))};t.prototype._getWidth=function t(e,i){if(this._x1===null){return this._width(e,i)}return Math.abs(this._x1(e,i)-this._x(e,i))};t.prototype._getX=function t(e,i){var n=this._x1===null?this._x(e,i):this._x1(e,i)-this._x(e,i);if(n<0){return n}else{return 0}};t.prototype._getY=function t(e,i){var n=this._x1!==null?this._y(e,i):this._y1(e,i)-this._y(e,i);if(n<0){return n}else{return 0}};t.prototype.height=function t(e){return arguments.length?(this._height=typeof e==="function"?e:y.constant(e),this):this._height};t.prototype.width=function t(e){return arguments.length?(this._width=typeof e==="function"?e:y.constant(e),this):this._width};t.prototype.x0=function t(e){if(!arguments.length){return this._x0}this._x0=typeof e==="function"?e:y.constant(e);this._x=this._x0;return this};t.prototype.x1=function t(e){return arguments.length?(this._x1=typeof e==="function"||e===null?e:y.constant(e),this):this._x1};t.prototype.y0=function t(e){if(!arguments.length){return this._y0}this._y0=typeof e==="function"?e:y.constant(e);this._y=this._y0;return this};t.prototype.y1=function t(e){return arguments.length?(this._y1=typeof e==="function"||e===null?e:y.constant(e),this):this._y1};return t}(e);var C=function(i){function t(){i.call(this,"circle");this._labelBounds=function(t,e,i){return{width:i.r*1.5,height:i.r*1.5,x:-i.r*.75,y:-i.r*.75}};this._labelConfig=y.assign(this._labelConfig,{textAnchor:"middle",verticalAlign:"middle"});this._name="Circle";this._r=y.accessor("r")}if(i)t.__proto__=i;t.prototype=Object.create(i&&i.prototype);t.prototype.constructor=t;t.prototype._applyPosition=function t(e){var i=this;e.attr("r",function(t,e){return i._r(t,e)}).attr("x",function(t,e){return-i._r(t,e)/2}).attr("y",function(t,e){return-i._r(t,e)/2})};t.prototype.render=function t(e){i.prototype.render.call(this,e);this._enter.attr("r",0).attr("x",0).attr("y",0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("r",0).attr("x",0).attr("y",0);return this};t.prototype._aes=function t(e,i){return{r:this._r(e,i)}};t.prototype.r=function t(e){return arguments.length?(this._r=typeof e==="function"?e:y.constant(e),this):this._r};return t}(e);var O=function(i){function t(){i.call(this,"rect");this._height=y.accessor("height");this._labelBounds=function(t,e,i){return{width:i.width,height:i.height,x:-i.width/2,y:-i.height/2}};this._name="Rect";this._width=y.accessor("width")}if(i)t.__proto__=i;t.prototype=Object.create(i&&i.prototype);t.prototype.constructor=t;t.prototype.render=function t(e){i.prototype.render.call(this,e);this._enter.attr("width",0).attr("height",0).attr("x",0).attr("y",0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("width",0).attr("height",0).attr("x",0).attr("y",0);return this};t.prototype._aes=function t(e,i){return{width:this._width(e,i),height:this._height(e,i)}};t.prototype._applyPosition=function t(e){var i=this;e.attr("width",function(t,e){return i._width(t,e)}).attr("height",function(t,e){return i._height(t,e)}).attr("x",function(t,e){return-i._width(t,e)/2}).attr("y",function(t,e){return-i._height(t,e)/2})};t.prototype.height=function t(e){return arguments.length?(this._height=typeof e==="function"?e:y.constant(e),this):this._height};t.prototype.width=function t(e){return arguments.length?(this._width=typeof e==="function"?e:y.constant(e),this):this._width};return t}(e);var A=function(r){function t(){var e=this;r.call(this);this._curve="linear";this._defined=function(t){return t};this._fill=y.constant("none");this._hitArea=y.constant({d:function(t){return e._path(t.values)},fill:"none","stroke-width":10,transform:null});this._name="Line";this._path=v.line();this._stroke=y.constant("black");this._strokeWidth=y.constant(1)}if(r)t.__proto__=r;t.prototype=Object.create(r&&r.prototype);t.prototype.constructor=t;t.prototype._dataFilter=function t(n){var r=this;var e=l.nest().key(this._id).entries(n).map(function(t){t.data=y.merge(t.values);t.i=n.indexOf(t.values[0]);var e=ut.extent(t.values,r._x);t.xR=e;t.width=e[1]-e[0];t.x=e[0]+t.width/2;var i=ut.extent(t.values,r._y);t.yR=i;t.height=i[1]-i[0];t.y=i[0]+t.height/2;t.nested=true;t.translate=[t.x,t.y];t.__d3plusShape__=true;return t});e.key=function(t){return t.key};return e};t.prototype.render=function t(e){var i=this;r.prototype.render.call(this,e);var n=this;this._path.curve(v["curve"+this._curve.charAt(0).toUpperCase()+this._curve.slice(1)]).defined(this._defined).x(this._x).y(this._y);this._enter.append("path").attr("transform",function(t){return"translate("+(-t.xR[0]-t.width/2)+", "+(-t.yR[0]-t.height/2)+")"}).attr("d",function(t){return i._path(t.values)}).call(this._applyStyle.bind(this));this._update.select("path").transition(this._transition).attr("transform",function(t){return"translate("+(-t.xR[0]-t.width/2)+", "+(-t.yR[0]-t.height/2)+")"}).attrTween("d",function(t){return o.interpolatePath(f.select(this).attr("d"),n._path(t.values))}).call(this._applyStyle.bind(this));return this};t.prototype._aes=function t(e,i){var n=this;return{points:e.values.map(function(t){return[n._x(t,i),n._y(t,i)]})}};t.prototype.curve=function t(e){return arguments.length?(this._curve=e,this):this._curve};t.prototype.defined=function t(e){return arguments.length?(this._defined=e,this):this._defined};return t}(e);var S={Circle:C,Rect:O};var M=function(t){function e(){t.call(this);this._endpoint=y.accessor("endpoint","Rect");this._endpointConfig={Circle:{r:y.accessor("r",5)}};this._length=y.accessor("length",25);this._lineConfig={};this._orient=y.accessor("orient","top");this._x=y.accessor("x",0);this._y=y.accessor("y",0)}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.render=function t(e){var a=this;if(this._select===void 0){this.select(f.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").style("display","block").node())}var h=[];this._data.forEach(function(t,e){var i=a._orient(t,e);var n=a._x(t,e);var r=a._y(t,e);var s=n;if(i==="left"){s-=a._length(t,e)}else if(i==="right"){s+=a._length(t,e)}var o=r;if(i==="top"){o-=a._length(t,e)}else if(i==="bottom"){o+=a._length(t,e)}h.push({__d3plus__:true,data:t,i:e,id:e,x:n,y:r});h.push({__d3plus__:true,data:t,i:e,id:e,x:s,y:o})});this._line=(new A).data(h).select(y.elem("g.d3plus-Whisker",{parent:this._select}).node()).config(y.configPrep.bind(this)(this._lineConfig,"shape")).render(e);var i=this._data.map(function(t,e){var i={};i.__d3plus__=true;i.data=t;i.i=e;i.endpoint=a._endpoint(t,e);i.length=a._length(t,e);i.orient=a._orient(t,e);var n=a._x(t,e);if(i.orient==="left"){n-=i.length}else if(i.orient==="right"){n+=i.length}var r=a._y(t,e);if(i.orient==="top"){r-=i.length}else if(i.orient==="bottom"){r+=i.length}i.x=n;i.y=r;return i});this._whiskerEndpoint=[];l.nest().key(function(t){return t.endpoint}).entries(i).forEach(function(t){var e=t.key;a._whiskerEndpoint.push((new S[e]).data(t.values).select(y.elem("g.d3plus-Whisker-Endpoint-"+e,{parent:a._select}).node()).config({height:function(t){return t.orient==="top"||t.orient==="bottom"?5:20},width:function(t){return t.orient==="top"||t.orient==="bottom"?20:5}}).config(y.configPrep.bind(a)(a._endpointConfig,"shape",e)).render())});return this};e.prototype.active=function t(e){if(this._line){this._line.active(e)}if(this._whiskerEndpoint){this._whiskerEndpoint.forEach(function(t){return t.active(e)})}};e.prototype.data=function t(e){return arguments.length?(this._data=e,this):this._data};e.prototype.endpoint=function t(e){return arguments.length?(this._endpoint=typeof e==="function"?e:y.constant(e),this):this._endpoint};e.prototype.endpointConfig=function t(e){return arguments.length?(this._endpointConfig=y.assign(this._endpointConfig,e),this):this._endpointConfig};e.prototype.hover=function t(e){if(this._line){this._line.hover(e)}if(this._whiskerEndpoint){this._whiskerEndpoint.forEach(function(t){return t.hover(e)})}};e.prototype.length=function t(e){return arguments.length?(this._length=typeof e==="function"?e:y.constant(e),this):this._length};e.prototype.lineConfig=function t(e){return arguments.length?(this._lineConfig=y.assign(this._lineConfig,e),this):this._lineConfig};e.prototype.orient=function t(e){return arguments.length?(this._orient=typeof e==="function"?e:y.constant(e),this):this._orient};e.prototype.select=function t(e){return arguments.length?(this._select=f.select(e),this):this._select};e.prototype.x=function t(e){return arguments.length?(this._x=typeof e==="function"?e:y.constant(e),this):this._x};e.prototype.y=function t(e){return arguments.length?(this._y=typeof e==="function"?e:y.constant(e),this):this._y};return e}(y.BaseClass);var E={Circle:C,Rect:O};var W=function(t){function e(){var i=this;t.call(this);this._medianConfig={fill:y.constant("black")};this._orient=y.accessor("orient","vertical");this._outlier=y.accessor("outlier","Circle");this._outlierConfig={Circle:{r:y.accessor("r",5)},Rect:{height:function(t,e){return i._orient(t,e)==="vertical"?5:20},width:function(t,e){return i._orient(t,e)==="vertical"?20:5}}};this._rectConfig={fill:y.constant("white"),stroke:y.constant("black"),strokeWidth:y.constant(1)};this._rectWidth=y.constant(50);this._whiskerConfig={};this._whiskerMode=["tukey","tukey"];this._x=y.accessor("x",250);this._y=y.accessor("y",250)}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.render=function t(){var s=this;if(this._select===void 0){this.select(f.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").style("display","block").node())}var o=[];var e=l.nest().key(function(t,e){return s._orient(t,e)==="vertical"?s._x(t,e):s._y(t,e)}).entries(this._data).map(function(r){r.data=y.merge(r.values);r.i=s._data.indexOf(r.values[0]);r.orient=s._orient(r.data,r.i);var t=r.values.map(r.orient==="vertical"?s._y:s._x);t.sort(function(t,e){return t-e});r.first=ut.quantile(t,.25);r.median=ut.quantile(t,.5);r.third=ut.quantile(t,.75);var e=s._whiskerMode;if(e[0]==="tukey"){r.lowerLimit=r.first-(r.third-r.first)*1.5;if(r.lowerLimit<ut.min(t)){r.lowerLimit=ut.min(t)}}else if(e[0]==="extent"){r.lowerLimit=ut.min(t)}else if(typeof e[0]==="number"){r.lowerLimit=ut.quantile(t,e[0])}if(e[1]==="tukey"){r.upperLimit=r.third+(r.third-r.first)*1.5;if(r.upperLimit>ut.max(t)){r.upperLimit=ut.max(t)}}else if(e[1]==="extent"){r.upperLimit=ut.max(t)}else if(typeof e[1]==="number"){r.upperLimit=ut.quantile(t,e[1])}var i=r.third-r.first;if(r.orient==="vertical"){r.height=i;r.width=s._rectWidth(r.data,r.i);r.x=s._x(r.data,r.i);r.y=r.first+i/2}else if(r.orient==="horizontal"){r.height=s._rectWidth(r.data,r.i);r.width=i;r.x=r.first+i/2;r.y=s._y(r.data,r.i)}r.values.forEach(function(t,e){var i=r.orient==="vertical"?s._y(t,e):s._x(t,e);if(i<r.lowerLimit||i>r.upperLimit){var n={};n.__d3plus__=true;n.data=t;n.i=e;n.outlier=s._outlier(t,e);if(r.orient==="vertical"){n.x=r.x;n.y=i;o.push(n)}else if(r.orient==="horizontal"){n.y=r.y;n.x=i;o.push(n)}}});r.__d3plus__=true;return r});this._box=(new O).data(e).x(function(t){return t.x}).y(function(t){return t.y}).select(y.elem("g.d3plus-Box",{parent:this._select}).node()).config(y.configPrep.bind(this)(this._rectConfig,"shape")).render();this._median=(new O).data(e).x(function(t){return t.orient==="vertical"?t.x:t.median}).y(function(t){return t.orient==="vertical"?t.median:t.y}).height(function(t){return t.orient==="vertical"?1:t.height}).width(function(t){return t.orient==="vertical"?t.width:1}).select(y.elem("g.d3plus-Box-Median",{parent:this._select}).node()).config(y.configPrep.bind(this)(this._medianConfig,"shape")).render();var c=[];e.forEach(function(t,e){var i=t.x;var n=t.y;var r=t.first-t.lowerLimit;var s=t.upperLimit-t.third;if(t.orient==="vertical"){var o=n-t.height/2;var a=n+t.height/2;c.push({__d3plus__:true,data:t,i:e,x:i,y:o,length:r,orient:"top"},{__d3plus__:true,data:t,i:e,x:i,y:a,length:s,orient:"bottom"})}else if(t.orient==="horizontal"){var h=i+t.width/2;var l=i-t.width/2;c.push({__d3plus__:true,data:t,i:e,x:h,y:n,length:s,orient:"right"},{__d3plus__:true,data:t,i:e,x:l,y:n,length:r,orient:"left"})}});this._whisker=(new M).data(c).select(y.elem("g.d3plus-Box-Whisker",{parent:this._select}).node()).config(y.configPrep.bind(this)(this._whiskerConfig,"shape")).render();this._whiskerEndpoint=[];l.nest().key(function(t){return t.outlier}).entries(o).forEach(function(t){var e=t.key;s._whiskerEndpoint.push((new E[e]).data(t.values).select(y.elem("g.d3plus-Box-Outlier-"+e,{parent:s._select}).node()).config(y.configPrep.bind(s)(s._outlierConfig,"shape",e)).render())});return this};e.prototype.active=function t(e){if(this._box){this._box.active(e)}if(this._median){this._median.active(e)}if(this._whisker){this._whisker.active(e)}if(this._whiskerEndpoint){this._whiskerEndpoint.forEach(function(t){return t.active(e)})}};e.prototype.data=function t(e){return arguments.length?(this._data=e,this):this._data};e.prototype.hover=function t(e){if(this._box){this._box.hover(e)}if(this._median){this._median.hover(e)}if(this._whisker){this._whisker.hover(e)}if(this._whiskerEndpoint){this._whiskerEndpoint.forEach(function(t){return t.hover(e)})}};e.prototype.medianConfig=function t(e){return arguments.length?(this._medianConfig=y.assign(this._medianConfig,e),this):this._medianConfig};e.prototype.orient=function t(e){return arguments.length?(this._orient=typeof e==="function"?e:y.constant(e),this):this._orient};e.prototype.outlier=function t(e){return arguments.length?(this._outlier=typeof e==="function"?e:y.constant(e),this):this._outlier};e.prototype.outlierConfig=function t(e){return arguments.length?(this._outlierConfig=y.assign(this._outlierConfig,e),this):this._outlierConfig};e.prototype.rectConfig=function t(e){return arguments.length?(this._rectConfig=y.assign(this._rectConfig,e),this):this._rectConfig};e.prototype.rectWidth=function t(e){return arguments.length?(this._rectWidth=typeof e==="function"?e:y.constant(e),this):this._rectWidth};e.prototype.select=function t(e){return arguments.length?(this._select=f.select(e),this):this._select};e.prototype.whiskerConfig=function t(e){return arguments.length?(this._whiskerConfig=y.assign(this._whiskerConfig,e),this):this._whiskerConfig};e.prototype.whiskerMode=function t(e){return arguments.length?(this._whiskerMode=e instanceof Array?e:[e,e],this):this._whiskerMode};e.prototype.x=function t(e){return arguments.length?(this._x=typeof e==="function"?e:y.accessor(e),this):this._x};e.prototype.y=function t(e){return arguments.length?(this._y=typeof e==="function"?e:y.accessor(e),this):this._y};return e}(y.BaseClass);var P=Math.PI;function R(t,e,i){if(i===void 0)i="circle";if(t<0){t=P*2+t}if(i==="square"){var n=45*(P/180);var r=0,s=0;if(t<P/2){var o=Math.tan(t);r+=t<n?e:e/o;s+=t<n?o*e:e}else if(t<=P){var a=Math.tan(P-t);r-=t<P-n?e/a:e;s+=t<P-n?e:a*e}else if(t<n+P){r-=e;s-=Math.tan(t-P)*e}else if(t<3*P/2){r-=e/Math.tan(t-P);s-=e}else if(t<2*P-n){r+=e/Math.tan(2*P-t);s-=e}else{r+=e;s-=Math.tan(2*P-t)*e}return[r,s]}else if(i==="circle"){return[e*Math.cos(t),e*Math.sin(t)]}else{return null}}var L=Math.PI;function N(t,e){if(e===void 0)e=20;var i=[],n=/([MLA])([^MLAZ]+)/gi;var r=n.exec(t);while(r!==null){if(["M","L"].includes(r[1])){i.push(r[2].split(",").map(Number))}else if(r[1]==="A"){var s=r[2].split(",").map(Number);var o=s.slice(s.length-2,s.length),a=i[i.length-1],h=s[0],l=x(a,o);var c=Math.acos((h*h+h*h-l*l)/(2*h*h));if(s[2]){c=L*2-c}var u=c/(c/(L*2)*(h*L*2)/e);var p=Math.atan2(-a[1],-a[0])-L;var _=u;while(_<c){i.push(R(s[4]?p+_:p-_,h));_+=u}i.push(o)}r=n.exec(t)}return i}var j=function(i){function t(){var r=this;i.call(this,"path");this._d=y.accessor("path");this._labelBounds=function(t,e,i){var n=_(i.points,{angle:r._labelConfig.rotate?r._labelConfig.rotate(t,e):0});return n?{angle:n.angle,width:n.width,height:n.height,x:n.cx-n.width/2,y:n.cy-n.height/2}:false};this._name="Path";this._labelConfig=Object.assign(this._labelConfig,{textAnchor:"middle",verticalAlign:"middle"})}if(i)t.__proto__=i;t.prototype=Object.create(i&&i.prototype);t.prototype.constructor=t;t.prototype._aes=function t(e,i){return{points:N(this._d(e,i))}};t.prototype.render=function t(e){i.prototype.render.call(this,e);this._enter.attr("opacity",0).attr("d",this._d).call(this._applyStyle.bind(this)).transition(this._transition).attr("opacity",1);this._update.transition(this._transition).call(this._applyStyle.bind(this)).attr("opacity",1).attr("d",this._d);this._exit.transition(this._transition).attr("opacity",0);return this};t.prototype.d=function t(e){return arguments.length?(this._d=typeof e==="function"?e:y.constant(e),this):this._d};return t}(e);t.Image=h;t.Shape=e;t.Area=w;t.Bar=k;t.Box=W;t.Circle=C;t.Line=A;t.Path=j;t.Rect=O;t.Whisker=M;t.largestRect=_;t.lineIntersection=m;t.path2polygon=N;t.pointDistance=x;t.pointDistanceSquared=_t;t.pointRotate=n;t.polygonInside=ft;t.polygonRayCast=dt;t.polygonRotate=yt;t.segmentBoxContains=b;t.segmentsIntersect=c;t.shapeEdgePoint=R;t.simplify=vt;Object.defineProperty(t,"__esModule",{value:true})}); | ||
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("d3-selection"),require("d3-transition"),require("d3plus-common"),require("d3-array"),require("d3-color"),require("d3plus-color"),require("d3-shape"),require("d3plus-text"),require("d3-collection"),require("d3-interpolate-path"),require("d3-polygon")):typeof define==="function"&&define.amd?define("d3plus-shape",["exports","d3-selection","d3-transition","d3plus-common","d3-array","d3-color","d3plus-color","d3-shape","d3plus-text","d3-collection","d3-interpolate-path","d3-polygon"],e):(t=t||self,e(t.d3plus={},t.d3Selection,t.d3Transition,t.d3plusCommon,t.d3Array,t.d3Color,t.d3plusColor,t.paths,t.d3plusText,t.d3Collection,t.d3InterpolatePath,t.d3Polygon))})(this,function(t,d,v,p,xt,a,i,y,g,u,s,mt){"use strict";function o(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||false;i.configurable=true;if("value"in i)i.writable=true;Object.defineProperty(t,i.key,i)}}function c(t,e,n){if(e)r(t.prototype,e);if(n)r(t,n);return t}function h(t,e){if(typeof e!=="function"&&e!==null){throw new TypeError("Super expression must either be null or a function")}t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:true,configurable:true}});if(e)n(t,e)}function l(t){l=Object.setPrototypeOf?Object.getPrototypeOf:function t(e){return e.__proto__||Object.getPrototypeOf(e)};return l(t)}function n(t,e){n=Object.setPrototypeOf||function t(e,n){e.__proto__=n;return e};return n(t,e)}function f(t){if(t===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return t}function _(t,e){if(e&&(typeof e==="object"||typeof e==="function")){return e}return f(t)}function x(t,e){while(!Object.prototype.hasOwnProperty.call(t,e)){t=l(t);if(t===null)break}return t}function m(t,e,n){if(typeof Reflect!=="undefined"&&Reflect.get){m=Reflect.get}else{m=function t(e,n,i){var r=x(e,n);if(!r)return;var a=Object.getOwnPropertyDescriptor(r,n);if(a.get){return a.get.call(i)}return a.value}}return m(t,e,n||t)}function kt(t,e){return k(t)||b(t,e)||w()}function k(t){if(Array.isArray(t))return t}function b(t,e){var n=[];var i=true;var r=false;var a=undefined;try{for(var s=t[Symbol.iterator](),o;!(i=(o=s.next()).done);i=true){n.push(o.value);if(e&&n.length===e)break}}catch(t){r=true;a=t}finally{try{if(!i&&s["return"]!=null)s["return"]()}finally{if(r)throw a}}return n}function w(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var O=function(){function h(){o(this,h);this._duration=600;this._height=p.accessor("height");this._id=p.accessor("id");this._pointerEvents=p.constant("auto");this._select;this._url=p.accessor("url");this._width=p.accessor("width");this._x=p.accessor("x",0);this._y=p.accessor("y",0)}c(h,[{key:"render",value:function t(e){var n=this;if(this._select===void 0)this.select(d.select("body").append("svg").style("width","".concat(window.innerWidth,"px")).style("height","".concat(window.innerHeight,"px")).style("display","block").node());var i=this._select.selectAll(".d3plus-Image").data(this._data,this._id);var r=i.enter().append("image").attr("class","d3plus-Image").attr("opacity",0).attr("width",0).attr("height",0).attr("x",function(t,e){return n._x(t,e)+n._width(t,e)/2}).attr("y",function(t,e){return n._y(t,e)+n._height(t,e)/2});var a=v.transition().duration(this._duration),s=this,o=r.merge(i);o.attr("xlink:href",this._url).style("pointer-events",this._pointerEvents).transition(a).attr("opacity",1).attr("width",function(t,e){return n._width(t,e)}).attr("height",function(t,e){return n._height(t,e)}).attr("x",function(t,e){return n._x(t,e)}).attr("y",function(t,e){return n._y(t,e)}).each(function(t,e){var n=d.select(this),i=s._url(t,e);var r=i.indexOf("http://")===0||i.indexOf("https://")===0;if(!r||i.indexOf(window.location.hostname)===0){var a=new h;a.src=i;a.crossOrigin="Anonymous";a.onload=function(){var t=document.createElement("canvas");t.width=this.width;t.height=this.height;var e=t.getContext("2d");e.drawImage(this,0,0);n.attr("xlink:href",t.toDataURL("image/png"))}}});i.exit().transition(a).attr("width",function(t,e){return n._width(t,e)}).attr("height",function(t,e){return n._height(t,e)}).attr("x",function(t,e){return n._x(t,e)}).attr("y",function(t,e){return n._y(t,e)}).attr("opacity",0).remove();if(e)setTimeout(e,this._duration+100);return this}},{key:"data",value:function t(e){return arguments.length?(this._data=e,this):this._data}},{key:"duration",value:function t(e){return arguments.length?(this._duration=e,this):this._duration}},{key:"height",value:function t(e){return arguments.length?(this._height=typeof e==="function"?e:p.constant(e),this):this._height}},{key:"id",value:function t(e){return arguments.length?(this._id=e,this):this._id}},{key:"pointerEvents",value:function t(e){return arguments.length?(this._pointerEvents=typeof e==="function"?e:p.constant(e),this):this._pointerEvents}},{key:"select",value:function t(e){return arguments.length?(this._select=d.select(e),this):this._select}},{key:"url",value:function t(e){return arguments.length?(this._url=e,this):this._url}},{key:"width",value:function t(e){return arguments.length?(this._width=typeof e==="function"?e:p.constant(e),this):this._width}},{key:"x",value:function t(e){return arguments.length?(this._x=typeof e==="function"?e:p.constant(e),this):this._x}},{key:"y",value:function t(e){return arguments.length?(this._y=typeof e==="function"?e:p.constant(e),this):this._y}}]);return h}();var bt=function(t,e){var n=e[0]-t[0],i=e[1]-t[1];return n*n+i*i};var C=function(t,e){return Math.sqrt(bt(t,e))};var e=function(t){h(e,t);function e(){var r;var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"g";o(this,e);r=_(this,l(e).call(this));r._activeOpacity=.25;r._activeStyle={stroke:function t(e,n){var i=r._fill(e,n);if(["transparent","none"].includes(i))i=r._stroke(e,n);return a.color(i).darker(1)},"stroke-width":function t(e,n){var i=r._strokeWidth(e,n)||1;return i*3}};r._ariaLabel=p.constant("");r._backgroundImage=p.constant(false);r._backgroundImageClass=new O;r._data=[];r._duration=600;r._fill=p.constant("black");r._fillOpacity=p.constant(1);r._hoverOpacity=.5;r._hoverStyle={stroke:function t(e,n){var i=r._fill(e,n);if(["transparent","none"].includes(i))i=r._stroke(e,n);return a.color(i).darker(.5)},"stroke-width":function t(e,n){var i=r._strokeWidth(e,n)||1;return i*2}};r._id=function(t,e){return t.id!==void 0?t.id:e};r._label=p.constant(false);r._labelClass=new g.TextBox;r._labelConfig={fontColor:function t(e,n){return i.colorContrast(r._fill(e,n))},fontSize:12,padding:5};r._name="Shape";r._opacity=p.constant(1);r._pointerEvents=p.constant("visiblePainted");r._role=p.constant("presentation");r._rotate=p.constant(0);r._rx=p.constant(0);r._ry=p.constant(0);r._scale=p.constant(1);r._shapeRendering=p.constant("geometricPrecision");r._stroke=function(t,e){return a.color(r._fill(t,e)).darker(1)};r._strokeDasharray=p.constant("0");r._strokeLinecap=p.constant("butt");r._strokeOpacity=p.constant(1);r._strokeWidth=p.constant(0);r._tagName=t;r._textAnchor=p.constant("start");r._vectorEffect=p.constant("non-scaling-stroke");r._verticalAlign=p.constant("top");r._x=p.accessor("x",0);r._y=p.accessor("y",0);return r}c(e,[{key:"_aes",value:function t(){return{}}},{key:"_applyEvents",value:function t(e){var a=this;var s=Object.keys(this._on);var n=function t(r){e.on(s[r],function(t,e){if(!a._on[s[r]])return;if(t.i!==void 0)e=t.i;if(t.nested&&t.values){var n=d.mouse(a._select.node()),i=t.values.map(function(t){return C(n,[a._x(t,e),a._y(t,e)])});t=t.values[i.indexOf(xt.min(i))]}a._on[s[r]].bind(a)(t,e)})};for(var i=0;i<s.length;i++){n(i)}}},{key:"_updateStyle",value:function t(e,n){var i=this;if(e.size()&&e.node().tagName==="g")e=e.selectAll("*");function r(t,e){return typeof this!=="function"?this:t.nested&&t.key&&t.values?this(t.values[0],i._data.indexOf(t.values[0])):this(t,e)}var a={};for(var s in n){if({}.hasOwnProperty.call(n,s)){a[s]=r.bind(n[s])}}e.transition().duration(0).call(p.attrize,a)}},{key:"_applyStyle",value:function t(e){var n=this;if(e.size()&&e.node().tagName==="g")e=e.selectAll("*");function i(t,e){return typeof this!=="function"?this:t.nested&&t.key&&t.values?this(t.values[0],n._data.indexOf(t.values[0])):this(t,e)}e.attr("fill",i.bind(this._fill)).attr("fill-opacity",i.bind(this._fillOpacity)).attr("rx",i.bind(this._rx)).attr("ry",i.bind(this._ry)).attr("stroke",i.bind(this._stroke)).attr("stroke-dasharray",i.bind(this._strokeDasharray)).attr("stroke-linecap",i.bind(this._strokeLinecap)).attr("stroke-opacity",i.bind(this._strokeOpacity)).attr("stroke-width",i.bind(this._strokeWidth)).attr("vector-effect",i.bind(this._vectorEffect))}},{key:"_applyTransform",value:function t(e){var n=this;e.attr("transform",function(t,e){return"\n translate(".concat(t.__d3plusShape__?t.translate?t.translate:"".concat(n._x(t.data,t.i),",").concat(n._y(t.data,t.i)):"".concat(n._x(t,e),",").concat(n._y(t,e)),")\n scale(").concat(t.__d3plusShape__?t.scale||n._scale(t.data,t.i):n._scale(t,e),")\n rotate(").concat(t.__d3plusShape__?t.rotate?t.rotate:n._rotate(t.data||t,t.i):n._rotate(t.data||t,t.i),")")})}},{key:"_nestWrapper",value:function t(n){return function(t,e){return n(t.__d3plusShape__?t.data:t,t.__d3plusShape__?t.i:e)}}},{key:"_renderActive",value:function t(){var r=this;this._group.selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(t,e){if(!t)t={};if(!t.parentNode)t.parentNode=this.parentNode;var n=t.parentNode;if(d.select(this).classed("d3plus-textBox"))t=t.data;if(t.__d3plusShape__||t.__d3plus__){while(t&&(t.__d3plusShape__||t.__d3plus__)){e=t.i;t=t.data}}else e=r._data.indexOf(t);var i=!r._active||typeof r._active!=="function"||!r._active(t,e)?n:r._activeGroup.node();if(i!==this.parentNode){i.appendChild(this);if(this.className.baseVal.includes("d3plus-Shape")){if(n===i)d.select(this).call(r._applyStyle.bind(r));else d.select(this).call(r._updateStyle.bind(r,d.select(this),r._activeStyle))}}});this._group.selectAll("g.d3plus-".concat(this._name,"-shape, g.d3plus-").concat(this._name,"-image, g.d3plus-").concat(this._name,"-text")).attr("opacity",this._hover?this._hoverOpacity:this._active?this._activeOpacity:1)}},{key:"_renderHover",value:function t(){var r=this;this._group.selectAll("g.d3plus-".concat(this._name,"-shape, g.d3plus-").concat(this._name,"-image, g.d3plus-").concat(this._name,"-text, g.d3plus-").concat(this._name,"-hover")).selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(t,e){if(!t)t={};if(!t.parentNode)t.parentNode=this.parentNode;var n=t.parentNode;if(d.select(this).classed("d3plus-textBox"))t=t.data;if(t.__d3plusShape__||t.__d3plus__){while(t&&(t.__d3plusShape__||t.__d3plus__)){e=t.i;t=t.data}}else e=r._data.indexOf(t);var i=!r._hover||typeof r._hover!=="function"||!r._hover(t,e)?n:r._hoverGroup.node();if(i!==this.parentNode)i.appendChild(this);if(this.className.baseVal.includes("d3plus-Shape")){if(n===i)d.select(this).call(r._applyStyle.bind(r));else d.select(this).call(r._updateStyle.bind(r,d.select(this),r._hoverStyle))}});this._group.selectAll("g.d3plus-".concat(this._name,"-shape, g.d3plus-").concat(this._name,"-image, g.d3plus-").concat(this._name,"-text")).attr("opacity",this._hover?this._hoverOpacity:this._active?this._activeOpacity:1)}},{key:"_renderImage",value:function t(){var u=this;var c=[];this._update.merge(this._enter).data().forEach(function(t,e){var n=u._aes(t,e);if(n.r||n.width&&n.height){var i=t;if(t.nested&&t.key&&t.values){i=t.values[0];e=u._data.indexOf(i)}var r=n.r?n.r*2:n.height,a=u._backgroundImage(i,e),s=n.r?n.r*2:n.width;if(a){var o=i.__d3plusShape__?i.translate?i.translate[0]:u._x(i.data,i.i):u._x(i,e),h=i.__d3plusShape__?i.translate?i.translate[1]:u._y(i.data,i.i):u._y(i,e);if(n.x)o+=n.x;if(n.y)h+=n.y;if(i.__d3plusShape__){i=i.data;e=i.i}c.push({__d3plus__:true,data:i,height:r,i:e,id:u._id(i,e),url:a,width:s,x:o+-s/2,y:h+-r/2})}}});this._backgroundImageClass.data(c).duration(this._duration).pointerEvents("none").select(p.elem("g.d3plus-".concat(this._name,"-image"),{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).node()).render()}},{key:"_renderLabels",value:function t(){var f=this;var _=[];this._update.merge(this._enter).data().forEach(function(t,e){var n=t;if(t.nested&&t.key&&t.values){n=t.values[0];e=f._data.indexOf(n)}var i=f._label(n,e);if(f._labelBounds&&i!==false&&i!==undefined&&i!==null){var r=f._labelBounds(n,e,f._aes(t,e));if(r){if(i.constructor!==Array)i=[i];var a=n.__d3plusShape__?n.translate?n.translate[0]:f._x(n.data,n.i):f._x(n,e),s=n.__d3plusShape__?n.translate?n.translate[1]:f._y(n.data,n.i):f._y(n,e);if(n.__d3plusShape__){n=n.data;e=n.i}for(var o=0;o<i.length;o++){var h=r.constructor===Array?r[o]:Object.assign({},r);var u=f._rotate(n,e);var c=n.labelConfig&&n.labelConfig.rotate?n.labelConfig.rotate:r.angle!==undefined?r.angle:0;c+=u;var l=u!==0?[h.x*-1||0,h.y*-1||0]:[h.width/2,h.height/2];_.push({__d3plus__:true,data:n,height:h.height,l:o,id:"".concat(f._id(n,e),"_").concat(o),r:c,rotateAnchor:l,text:i[o],width:h.width,x:a+h.x,y:s+h.y})}}}});this._labelClass.data(_).duration(this._duration).pointerEvents("none").rotate(function(t){return t.__d3plus__?t.r:t.data.r}).rotateAnchor(function(t){return t.__d3plus__?t.rotateAnchor:t.data.rotateAnchor}).select(p.elem("g.d3plus-".concat(this._name,"-text"),{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).node()).config(p.configPrep.bind(this)(this._labelConfig)).render()}},{key:"render",value:function t(e){var n=this;if(this._select===void 0){this.select(d.select("body").append("svg").style("width","".concat(window.innerWidth,"px")).style("height","".concat(window.innerHeight,"px")).style("display","block").node())}this._transition=v.transition().duration(this._duration);var i=this._data,r=this._id;if(this._dataFilter){i=this._dataFilter(i);if(i.key)r=i.key}if(this._sort){i=i.sort(function(t,e){while(t.__d3plusShape__||t.__d3plus__){t=t.data}while(e.__d3plusShape__||e.__d3plus__){e=e.data}return n._sort(t,e)})}d.selectAll("g.d3plus-".concat(this._name,"-hover > *, g.d3plus-").concat(this._name,"-active > *")).each(function(t){if(t&&t.parentNode)t.parentNode.appendChild(this);else this.parentNode.removeChild(this)});this._group=p.elem("g.d3plus-".concat(this._name,"-group"),{parent:this._select});var a=this._update=p.elem("g.d3plus-".concat(this._name,"-shape"),{parent:this._group,update:{opacity:this._active?this._activeOpacity:1}}).selectAll(".d3plus-".concat(this._name)).data(i,r);a.order().transition(this._transition).call(this._applyTransform.bind(this));var s=this._enter=a.enter().append(this._tagName).attr("class",function(t,e){return"d3plus-Shape d3plus-".concat(n._name," d3plus-id-").concat(g.strip(n._nestWrapper(n._id)(t,e)))}).call(this._applyTransform.bind(this)).attr("aria-label",this._ariaLabel).attr("role",this._role).attr("opacity",this._nestWrapper(this._opacity));var o=s.merge(a);o.attr("shape-rendering",this._nestWrapper(this._shapeRendering)).attr("pointer-events","none").transition(this._transition).attr("opacity",this._nestWrapper(this._opacity)).attr("pointer-events",this._pointerEvents);var h=this._exit=a.exit();h.transition().delay(this._duration).remove();this._renderImage();this._renderLabels();this._hoverGroup=p.elem("g.d3plus-".concat(this._name,"-hover"),{parent:this._group});this._activeGroup=p.elem("g.d3plus-".concat(this._name,"-active"),{parent:this._group});var u=this._group.selectAll(".d3plus-HitArea").data(this._hitArea?i:[],r);u.order().call(this._applyTransform.bind(this));var c=this._name==="Line";c&&this._path.curve(y["curve".concat(this._curve.charAt(0).toUpperCase()).concat(this._curve.slice(1))]).defined(this._defined).x(this._x).y(this._y);var l=u.enter().append(c?"path":"rect").attr("class",function(t,e){return"d3plus-HitArea d3plus-id-".concat(g.strip(n._nestWrapper(n._id)(t,e)))}).attr("fill","black").attr("stroke","black").attr("pointer-events","painted").attr("opacity",0).call(this._applyTransform.bind(this));var f=this;var _=u.merge(l).each(function(t){var e=f._data.indexOf(t);var n=f._hitArea(t,e,f._aes(t,e));return n&&!(f._name==="Line"&&parseFloat(f._strokeWidth(t,e))>10)?d.select(this).call(p.attrize,n):d.select(this).remove()});u.exit().remove();this._applyEvents(this._hitArea?_:o);setTimeout(function(){if(n._active)n._renderActive();else if(n._hover)n._renderHover();if(e)e()},this._duration+100);return this}},{key:"active",value:function t(e){if(!arguments.length||e===undefined)return this._active;this._active=e;if(this._group){this._renderActive()}return this}},{key:"activeOpacity",value:function t(e){return arguments.length?(this._activeOpacity=e,this):this._activeOpacity}},{key:"activeStyle",value:function t(e){return arguments.length?(this._activeStyle=p.assign({},this._activeStyle,e),this):this._activeStyle}},{key:"ariaLabel",value:function t(e){return e!==undefined?(this._ariaLabel=typeof e==="function"?e:p.constant(e),this):this._ariaLabel}},{key:"backgroundImage",value:function t(e){return arguments.length?(this._backgroundImage=typeof e==="function"?e:p.constant(e),this):this._backgroundImage}},{key:"data",value:function t(e){return arguments.length?(this._data=e,this):this._data}},{key:"duration",value:function t(e){return arguments.length?(this._duration=e,this):this._duration}},{key:"fill",value:function t(e){return arguments.length?(this._fill=typeof e==="function"?e:p.constant(e),this):this._fill}},{key:"fillOpacity",value:function t(e){return arguments.length?(this._fillOpacity=typeof e==="function"?e:p.constant(e),this):this._fillOpacity}},{key:"hover",value:function t(e){if(!arguments.length||e===void 0)return this._hover;this._hover=e;if(this._group){this._renderHover()}return this}},{key:"hoverStyle",value:function t(e){return arguments.length?(this._hoverStyle=p.assign({},this._hoverStyle,e),this):this._hoverStyle}},{key:"hoverOpacity",value:function t(e){return arguments.length?(this._hoverOpacity=e,this):this._hoverOpacity}},{key:"hitArea",value:function t(e){return arguments.length?(this._hitArea=typeof e==="function"?e:p.constant(e),this):this._hitArea}},{key:"id",value:function t(e){return arguments.length?(this._id=e,this):this._id}},{key:"label",value:function t(e){return arguments.length?(this._label=typeof e==="function"?e:p.constant(e),this):this._label}},{key:"labelBounds",value:function t(e){return arguments.length?(this._labelBounds=typeof e==="function"?e:p.constant(e),this):this._labelBounds}},{key:"labelConfig",value:function t(e){return arguments.length?(this._labelConfig=p.assign(this._labelConfig,e),this):this._labelConfig}},{key:"opacity",value:function t(e){return arguments.length?(this._opacity=typeof e==="function"?e:p.constant(e),this):this._opacity}},{key:"pointerEvents",value:function t(e){return arguments.length?(this._pointerEvents=typeof e==="function"?e:p.constant(e),this):this._pointerEvents}},{key:"role",value:function t(e){return e!==undefined?(this._role=typeof e==="function"?e:p.constant(e),this):this._role}},{key:"rotate",value:function t(e){return arguments.length?(this._rotate=typeof e==="function"?e:p.constant(e),this):this._rotate}},{key:"rx",value:function t(e){return arguments.length?(this._rx=typeof e==="function"?e:p.constant(e),this):this._rx}},{key:"ry",value:function t(e){return arguments.length?(this._ry=typeof e==="function"?e:p.constant(e),this):this._ry}},{key:"scale",value:function t(e){return arguments.length?(this._scale=typeof e==="function"?e:p.constant(e),this):this._scale}},{key:"select",value:function t(e){return arguments.length?(this._select=d.select(e),this):this._select}},{key:"shapeRendering",value:function t(e){return arguments.length?(this._shapeRendering=typeof e==="function"?e:p.constant(e),this):this._shapeRendering}},{key:"sort",value:function t(e){return arguments.length?(this._sort=e,this):this._sort}},{key:"stroke",value:function t(e){return arguments.length?(this._stroke=typeof e==="function"?e:p.constant(e),this):this._stroke}},{key:"strokeDasharray",value:function t(e){return arguments.length?(this._strokeDasharray=typeof e==="function"?e:p.constant(e),this):this._strokeDasharray}},{key:"strokeLinecap",value:function t(e){return arguments.length?(this._strokeLinecap=typeof e==="function"?e:p.constant(e),this):this._strokeLinecap}},{key:"strokeOpacity",value:function t(e){return arguments.length?(this._strokeOpacity=typeof e==="function"?e:p.constant(e),this):this._strokeOpacity}},{key:"strokeWidth",value:function t(e){return arguments.length?(this._strokeWidth=typeof e==="function"?e:p.constant(e),this):this._strokeWidth}},{key:"textAnchor",value:function t(e){return arguments.length?(this._textAnchor=typeof e==="function"?e:p.constant(e),this):this._textAnchor}},{key:"vectorEffect",value:function t(e){return arguments.length?(this._vectorEffect=typeof e==="function"?e:p.constant(e),this):this._vectorEffect}},{key:"verticalAlign",value:function t(e){return arguments.length?(this._verticalAlign=typeof e==="function"?e:p.constant(e),this):this._verticalAlign}},{key:"x",value:function t(e){return arguments.length?(this._x=typeof e==="function"?e:p.constant(e),this):this._x}},{key:"y",value:function t(e){return arguments.length?(this._y=typeof e==="function"?e:p.constant(e),this):this._y}}]);return e}(p.BaseClass);function S(t,e,n,i){var r=1e-9;var a=t[0]-e[0],s=n[0]-i[0],o=t[1]-e[1],h=n[1]-i[1];var u=a*h-o*s;if(Math.abs(u)<r)return null;var c=t[0]*e[1]-t[1]*e[0],l=n[0]*i[1]-n[1]*i[0];var f=(c*s-l*a)/u,_=(c*h-l*o)/u;return[f,_]}function A(t,e,n){var i=1e-9,r=kt(n,2),a=r[0],s=r[1];return!(a<Math.min(t[0],e[0])-i||a>Math.max(t[0],e[0])+i||s<Math.min(t[1],e[1])-i||s>Math.max(t[1],e[1])+i)}function E(t,e,n,i){var r=S(t,e,n,i);if(!r)return false;return A(t,e,r)&&A(n,i,r)}function wt(t,e){var n=-1;var i=t.length;var r=e.length;var a=t[i-1];while(++n<i){var s=a;a=t[n];var o=-1;var h=e[r-1];while(++o<r){var u=h;h=e[o];if(E(s,a,u,h))return false}}return mt.polygonContains(e,t[0])}function Ot(t,e){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var i=1e-9;e=[e[0]+i*Math.cos(n),e[1]+i*Math.sin(n)];var r=e,a=kt(r,2),s=a[0],o=a[1];var h=[s+Math.cos(n),o+Math.sin(n)];var u=0;if(Math.abs(h[0]-s)<i)u=1;var c=-1;var l=t.length;var f=t[l-1];var _=Number.MAX_VALUE;var d=Number.MAX_VALUE;var v=null;var p=null;while(++c<l){var y=f;f=t[c];var g=S(e,h,y,f);if(g&&A(y,f,g)){var x=bt(e,g);if(g[u]<e[u]){if(x<_){_=x;v=g}}else if(g[u]>e[u]){if(x<d){d=x;p=g}}}}return[v,p]}function M(t,e){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[0,0];var i=Math.cos(e),r=Math.sin(e),a=t[0]-n[0],s=t[1]-n[1];return[i*a-r*s+n[0],r*a+i*s+n[1]]}var Ct=function(t,e){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[0,0];return t.map(function(t){return M(t,e,n)})};function P(t,e,n){var i=e[0],r=e[1];var a=n[0]-i,s=n[1]-r;if(a!==0||s!==0){var o=((t[0]-i)*a+(t[1]-r)*s)/(a*a+s*s);if(o>1){i=n[0];r=n[1]}else if(o>0){i+=a*o;r+=s*o}}a=t[0]-i;s=t[1]-r;return a*a+s*s}function j(t,e){var n,i=t[0];var r=[i];for(var a=1,s=t.length;a<s;a++){n=t[a];if(bt(n,i)>e){r.push(n);i=n}}if(i!==n)r.push(n);return r}function R(t,e,n,i,r){var a,s=i;for(var o=e+1;o<n;o++){var h=P(t[o],t[e],t[n]);if(h>s){a=o;s=h}}if(s>i){if(a-e>1)R(t,e,a,i,r);r.push(t[a]);if(n-a>1)R(t,a,n,i,r)}}function W(t,e){var n=t.length-1;var i=[t[0]];R(t,0,n,e,i);i.push(t[n]);return i}var St=function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(t.length<=2)return t;var i=e*e;t=n?t:j(t,i);t=W(t,i);return t};var At=.5;var Et=5;var Mt={};function L(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(t.length<3){if(e.verbose)console.error("polygon has to have at least 3 points",t);return null}var n=[];e=Object.assign({angle:xt.range(-90,90+Et,Et),cache:true,maxAspectRatio:15,minAspectRatio:1,minHeight:0,minWidth:0,nTries:20,tolerance:.02,verbose:false},e);var i=e.angle instanceof Array?e.angle:typeof e.angle==="number"?[e.angle]:typeof e.angle==="string"&&!isNaN(e.angle)?[Number(e.angle)]:[];var r=e.aspectRatio instanceof Array?e.aspectRatio:typeof e.aspectRatio==="number"?[e.aspectRatio]:typeof e.aspectRatio==="string"&&!isNaN(e.aspectRatio)?[Number(e.aspectRatio)]:[];var a=e.origin&&e.origin instanceof Array?e.origin[0]instanceof Array?e.origin:[e.origin]:[];var s;if(e.cache){s=xt.merge(t).join(",");s+="-".concat(e.minAspectRatio);s+="-".concat(e.maxAspectRatio);s+="-".concat(e.minHeight);s+="-".concat(e.minWidth);s+="-".concat(i.join(","));s+="-".concat(a.join(","));if(Mt[s])return Mt[s]}var o=Math.abs(mt.polygonArea(t));if(o===0){if(e.verbose)console.error("polygon has 0 area",t);return null}var h=xt.extent(t,function(t){return t[0]}),u=kt(h,2),c=u[0],l=u[1];var f=xt.extent(t,function(t){return t[1]}),_=kt(f,2),d=_[0],v=_[1];var p=Math.min(l-c,v-d)*e.tolerance;if(p>0)t=St(t,p);if(e.events)n.push({type:"simplify",poly:t});var y=xt.extent(t,function(t){return t[0]});var g=kt(y,2);c=g[0];l=g[1];var x=xt.extent(t,function(t){return t[1]});var m=kt(x,2);d=m[0];v=m[1];var k=l-c,b=v-d;var w=Math.min(k,b)/50;if(!a.length){var O=mt.polygonCentroid(t);if(!isFinite(O[0])){if(e.verbose)console.error("cannot find centroid",t);return null}if(mt.polygonContains(t,O))a.push(O);var C=e.nTries;while(C){var S=Math.random()*k+c;var A=Math.random()*b+d;var E=[S,A];if(mt.polygonContains(t,E)){a.push(E)}C--}}if(e.events)n.push({type:"origins",points:a});var M=0;var P=null;for(var j=0;j<i.length;j++){var R=i[j];var W=-R*Math.PI/180;if(e.events)n.push({type:"angle",angle:R});for(var L=0;L<a.length;L++){var N=a[L];var T=Ot(t,N,W),I=kt(T,2),B=I[0],H=I[1];var q=Ot(t,N,W+Math.PI/2),F=kt(q,2),D=F[0],z=F[1];var G=[];if(B&&H)G.push([(B[0]+H[0])/2,(B[1]+H[1])/2]);if(D&&z)G.push([(D[0]+z[0])/2,(D[1]+z[1])/2]);if(e.events)n.push({type:"modifOrigin",idx:L,p1W:B,p2W:H,p1H:D,p2H:z,modifOrigins:G});for(var V=0;V<G.length;V++){var U=G[V];if(e.events)n.push({type:"origin",cx:U[0],cy:U[1]});var X=Ot(t,U,W),Y=kt(X,2),K=Y[0],Z=Y[1];if(K===null||Z===null)continue;var J=Math.min(bt(U,K),bt(U,Z));var Q=2*Math.sqrt(J);var $=Ot(t,U,W+Math.PI/2),tt=kt($,2),et=tt[0],nt=tt[1];if(et===null||nt===null)continue;var it=Math.min(bt(U,et),bt(U,nt));var rt=2*Math.sqrt(it);if(Q*rt<M)continue;var at=r;if(!at.length){var st=Math.max(e.minAspectRatio,e.minWidth/rt,M/(rt*rt));var ot=Math.min(e.maxAspectRatio,Q/e.minHeight,Q*Q/M);at=xt.range(st,ot+At,At)}for(var ht=0;ht<at.length;ht++){var ut=at[ht];var ct=Math.max(e.minWidth,Math.sqrt(M*ut));var lt=Math.min(Q,rt*ut);if(lt*rt<M)continue;if(e.events&<-ct>=w)n.push({type:"aRatio",aRatio:ut});while(lt-ct>=w){var ft=(ct+lt)/2;var _t=ft/ut;var dt=kt(U,2),vt=dt[0],pt=dt[1];var yt=[[vt-ft/2,pt-_t/2],[vt+ft/2,pt-_t/2],[vt+ft/2,pt+_t/2],[vt-ft/2,pt+_t/2]];yt=Ct(yt,W,U);var gt=wt(yt,t);if(gt){M=ft*_t;yt.push(yt[0]);P={area:M,cx:vt,cy:pt,width:ft,height:_t,angle:-R,points:yt};ct=ft}else{lt=ft}if(e.events)n.push({type:"rectangle",areaFraction:ft*_t/o,cx:vt,cy:pt,width:ft,height:_t,angle:R,insidePoly:gt})}}}}}if(e.cache){Mt[s]=P}return e.events?Object.assign(P||{},{events:n}):P}var N=function(t){h(a,t);function a(){var r;o(this,a);r=_(this,l(a).call(this));r._curve="linear";r._defined=function(){return true};r._labelBounds=function(t,e,n){var i=L(n.points);if(!i)return null;return{angle:i.angle,width:i.width,height:i.height,x:i.cx-i.width/2-r._x(t,e),y:i.cy-i.height/2-r._y(t,e)}};r._labelConfig=Object.assign(r._labelConfig,{textAnchor:"middle",verticalAlign:"middle"});r._name="Area";r._x=p.accessor("x");r._x0=p.accessor("x");r._x1=null;r._y=p.constant(0);r._y0=p.constant(0);r._y1=p.accessor("y");return r}c(a,[{key:"_aes",value:function t(e){var n=this;var i=e.values.slice().sort(function(t,e){return n._y1?n._x(t)-n._x(e):n._y(t)-n._y(e)});var r=i.map(function(t,e){return[n._x0(t,e),n._y0(t,e)]});var a=i.reverse().map(function(t,e){return n._y1?[n._x(t,e),n._y1(t,e)]:[n._x1(t,e),n._y(t,e)]});var s=r.concat(a);if(r[0][1]>a[0][1])s=s.reverse();s.push(s[0]);return{points:s}}},{key:"_dataFilter",value:function t(i){var r=this;var e=u.nest().key(this._id).entries(i).map(function(t){t.data=p.merge(t.values);t.i=i.indexOf(t.values[0]);var e=xt.extent(t.values.map(r._x).concat(t.values.map(r._x0)).concat(r._x1?t.values.map(r._x1):[]));t.xR=e;t.width=e[1]-e[0];t.x=e[0]+t.width/2;var n=xt.extent(t.values.map(r._y).concat(t.values.map(r._y0)).concat(r._y1?t.values.map(r._y1):[]));t.yR=n;t.height=n[1]-n[0];t.y=n[0]+t.height/2;t.nested=true;t.translate=[t.x,t.y];t.__d3plusShape__=true;return t});e.key=function(t){return t.key};return e}},{key:"render",value:function t(e){m(l(a.prototype),"render",this).call(this,e);var n=this._path=y.area().defined(this._defined).curve(y["curve".concat(this._curve.charAt(0).toUpperCase()).concat(this._curve.slice(1))]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1);var i=y.area().defined(function(t){return t}).curve(y["curve".concat(this._curve.charAt(0).toUpperCase()).concat(this._curve.slice(1))]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1);this._enter.append("path").attr("transform",function(t){return"translate(".concat(-t.xR[0]-t.width/2,", ").concat(-t.yR[0]-t.height/2,")")}).attr("d",function(t){return n(t.values)}).call(this._applyStyle.bind(this));this._update.select("path").transition(this._transition).attr("transform",function(t){return"translate(".concat(-t.xR[0]-t.width/2,", ").concat(-t.yR[0]-t.height/2,")")}).attrTween("d",function(t){return s.interpolatePath(d.select(this).attr("d"),n(t.values))}).call(this._applyStyle.bind(this));this._exit.select("path").transition(this._transition).attrTween("d",function(t){return s.interpolatePath(d.select(this).attr("d"),i(t.values))});return this}},{key:"curve",value:function t(e){return arguments.length?(this._curve=e,this):this._curve}},{key:"defined",value:function t(e){return arguments.length?(this._defined=e,this):this._defined}},{key:"x",value:function t(e){if(!arguments.length)return this._x;this._x=typeof e==="function"?e:p.constant(e);this._x0=this._x;return this}},{key:"x0",value:function t(e){if(!arguments.length)return this._x0;this._x0=typeof e==="function"?e:p.constant(e);this._x=this._x0;return this}},{key:"x1",value:function t(e){return arguments.length?(this._x1=typeof e==="function"||e===null?e:p.constant(e),this):this._x1}},{key:"y",value:function t(e){if(!arguments.length)return this._y;this._y=typeof e==="function"?e:p.constant(e);this._y0=this._y;return this}},{key:"y0",value:function t(e){if(!arguments.length)return this._y0;this._y0=typeof e==="function"?e:p.constant(e);this._y=this._y0;return this}},{key:"y1",value:function t(e){return arguments.length?(this._y1=typeof e==="function"||e===null?e:p.constant(e),this):this._y1}}]);return a}(e);var T=function(t){h(r,t);function r(){var i;o(this,r);i=_(this,l(r).call(this,"rect"));i._name="Bar";i._height=p.constant(10);i._labelBounds=function(t,e,n){return{width:n.width,height:n.height,x:i._x1!==null?i._getX(t,e):-n.width/2,y:i._x1===null?i._getY(t,e):-n.height/2}};i._width=p.constant(10);i._x=p.accessor("x");i._x0=p.accessor("x");i._x1=null;i._y=p.constant(0);i._y0=p.constant(0);i._y1=p.accessor("y");return i}c(r,[{key:"render",value:function t(e){var n=this;m(l(r.prototype),"render",this).call(this,e);this._enter.attr("width",function(t,e){return n._x1===null?n._getWidth(t,e):0}).attr("height",function(t,e){return n._x1!==null?n._getHeight(t,e):0}).attr("x",function(t,e){return n._x1===null?-n._getWidth(t,e)/2:0}).attr("y",function(t,e){return n._x1!==null?-n._getHeight(t,e)/2:0}).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("width",function(t,e){return n._x1===null?n._getWidth(t,e):0}).attr("height",function(t,e){return n._x1!==null?n._getHeight(t,e):0}).attr("x",function(t,e){return n._x1===null?-n._getWidth(t,e)/2:0}).attr("y",function(t,e){return n._x1!==null?-n._getHeight(t,e)/2:0});return this}},{key:"_aes",value:function t(e,n){return{height:this._getHeight(e,n),width:this._getWidth(e,n)}}},{key:"_applyPosition",value:function t(e){var n=this;e.attr("width",function(t,e){return n._getWidth(t,e)}).attr("height",function(t,e){return n._getHeight(t,e)}).attr("x",function(t,e){return n._x1!==null?n._getX(t,e):-n._getWidth(t,e)/2}).attr("y",function(t,e){return n._x1===null?n._getY(t,e):-n._getHeight(t,e)/2})}},{key:"_getHeight",value:function t(e,n){if(this._x1!==null)return this._height(e,n);return Math.abs(this._y1(e,n)-this._y(e,n))}},{key:"_getWidth",value:function t(e,n){if(this._x1===null)return this._width(e,n);return Math.abs(this._x1(e,n)-this._x(e,n))}},{key:"_getX",value:function t(e,n){var i=this._x1===null?this._x(e,n):this._x1(e,n)-this._x(e,n);if(i<0)return i;else return 0}},{key:"_getY",value:function t(e,n){var i=this._x1!==null?this._y(e,n):this._y1(e,n)-this._y(e,n);if(i<0)return i;else return 0}},{key:"height",value:function t(e){return arguments.length?(this._height=typeof e==="function"?e:p.constant(e),this):this._height}},{key:"width",value:function t(e){return arguments.length?(this._width=typeof e==="function"?e:p.constant(e),this):this._width}},{key:"x0",value:function t(e){if(!arguments.length)return this._x0;this._x0=typeof e==="function"?e:p.constant(e);this._x=this._x0;return this}},{key:"x1",value:function t(e){return arguments.length?(this._x1=typeof e==="function"||e===null?e:p.constant(e),this):this._x1}},{key:"y0",value:function t(e){if(!arguments.length)return this._y0;this._y0=typeof e==="function"?e:p.constant(e);this._y=this._y0;return this}},{key:"y1",value:function t(e){return arguments.length?(this._y1=typeof e==="function"||e===null?e:p.constant(e),this):this._y1}}]);return r}(e);var I=function(t){h(n,t);function n(){var t;o(this,n);t=_(this,l(n).call(this,"circle"));t._labelBounds=function(t,e,n){return{width:n.r*1.5,height:n.r*1.5,x:-n.r*.75,y:-n.r*.75}};t._labelConfig=p.assign(t._labelConfig,{textAnchor:"middle",verticalAlign:"middle"});t._name="Circle";t._r=p.accessor("r");return t}c(n,[{key:"_applyPosition",value:function t(e){var n=this;e.attr("r",function(t,e){return n._r(t,e)}).attr("x",function(t,e){return-n._r(t,e)/2}).attr("y",function(t,e){return-n._r(t,e)/2})}},{key:"render",value:function t(e){m(l(n.prototype),"render",this).call(this,e);this._enter.attr("r",0).attr("x",0).attr("y",0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("r",0).attr("x",0).attr("y",0);return this}},{key:"_aes",value:function t(e,n){return{r:this._r(e,n)}}},{key:"r",value:function t(e){return arguments.length?(this._r=typeof e==="function"?e:p.constant(e),this):this._r}}]);return n}(e);var B=function(t){h(n,t);function n(){var t;o(this,n);t=_(this,l(n).call(this,"rect"));t._height=p.accessor("height");t._labelBounds=function(t,e,n){return{width:n.width,height:n.height,x:-n.width/2,y:-n.height/2}};t._name="Rect";t._width=p.accessor("width");return t}c(n,[{key:"render",value:function t(e){m(l(n.prototype),"render",this).call(this,e);this._enter.attr("width",0).attr("height",0).attr("x",0).attr("y",0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this));this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this));this._exit.transition(this._transition).attr("width",0).attr("height",0).attr("x",0).attr("y",0);return this}},{key:"_aes",value:function t(e,n){return{width:this._width(e,n),height:this._height(e,n)}}},{key:"_applyPosition",value:function t(e){var n=this;e.attr("width",function(t,e){return n._width(t,e)}).attr("height",function(t,e){return n._height(t,e)}).attr("x",function(t,e){return-n._width(t,e)/2}).attr("y",function(t,e){return-n._height(t,e)/2})}},{key:"height",value:function t(e){return arguments.length?(this._height=typeof e==="function"?e:p.constant(e),this):this._height}},{key:"width",value:function t(e){return arguments.length?(this._width=typeof e==="function"?e:p.constant(e),this):this._width}}]);return n}(e);var H=function(t){h(r,t);function r(){var n;o(this,r);n=_(this,l(r).call(this));n._curve="linear";n._defined=function(t){return t};n._fill=p.constant("none");n._hitArea=p.constant({d:function t(e){return n._path(e.values)},fill:"none","stroke-width":10,transform:null});n._name="Line";n._path=y.line();n._stroke=p.constant("black");n._strokeWidth=p.constant(1);return n}c(r,[{key:"_dataFilter",value:function t(i){var r=this;var e=u.nest().key(this._id).entries(i).map(function(t){t.data=p.merge(t.values);t.i=i.indexOf(t.values[0]);var e=xt.extent(t.values,r._x);t.xR=e;t.width=e[1]-e[0];t.x=e[0]+t.width/2;var n=xt.extent(t.values,r._y);t.yR=n;t.height=n[1]-n[0];t.y=n[0]+t.height/2;t.nested=true;t.translate=[t.x,t.y];t.__d3plusShape__=true;return t});e.key=function(t){return t.key};return e}},{key:"render",value:function t(e){var n=this;m(l(r.prototype),"render",this).call(this,e);var i=this;this._path.curve(y["curve".concat(this._curve.charAt(0).toUpperCase()).concat(this._curve.slice(1))]).defined(this._defined).x(this._x).y(this._y);this._enter.append("path").attr("transform",function(t){return"translate(".concat(-t.xR[0]-t.width/2,", ").concat(-t.yR[0]-t.height/2,")")}).attr("d",function(t){return n._path(t.values)}).call(this._applyStyle.bind(this));this._update.select("path").transition(this._transition).attr("transform",function(t){return"translate(".concat(-t.xR[0]-t.width/2,", ").concat(-t.yR[0]-t.height/2,")")}).attrTween("d",function(t){return s.interpolatePath(d.select(this).attr("d"),i._path(t.values))}).call(this._applyStyle.bind(this));return this}},{key:"_aes",value:function t(e,n){var i=this;return{points:e.values.map(function(t){return[i._x(t,n),i._y(t,n)]})}}},{key:"curve",value:function t(e){return arguments.length?(this._curve=e,this):this._curve}},{key:"defined",value:function t(e){return arguments.length?(this._defined=e,this):this._defined}}]);return r}(e);var q={Circle:I,Rect:B};var F=function(t){h(e,t);function e(){var t;o(this,e);t=_(this,l(e).call(this));t._endpoint=p.accessor("endpoint","Rect");t._endpointConfig={Circle:{r:p.accessor("r",5)}};t._length=p.accessor("length",25);t._lineConfig={};t._orient=p.accessor("orient","top");t._x=p.accessor("x",0);t._y=p.accessor("y",0);return t}c(e,[{key:"render",value:function t(e){var o=this;if(this._select===void 0){this.select(d.select("body").append("svg").style("width","".concat(window.innerWidth,"px")).style("height","".concat(window.innerHeight,"px")).style("display","block").node())}var h=[];this._data.forEach(function(t,e){var n=o._orient(t,e);var i=o._x(t,e);var r=o._y(t,e);var a=i;if(n==="left")a-=o._length(t,e);else if(n==="right")a+=o._length(t,e);var s=r;if(n==="top")s-=o._length(t,e);else if(n==="bottom")s+=o._length(t,e);h.push({__d3plus__:true,data:t,i:e,id:e,x:i,y:r});h.push({__d3plus__:true,data:t,i:e,id:e,x:a,y:s})});this._line=(new H).data(h).select(p.elem("g.d3plus-Whisker",{parent:this._select}).node()).config(p.configPrep.bind(this)(this._lineConfig,"shape")).render(e);var n=this._data.map(function(t,e){var n={};n.__d3plus__=true;n.data=t;n.i=e;n.endpoint=o._endpoint(t,e);n.length=o._length(t,e);n.orient=o._orient(t,e);var i=o._x(t,e);if(n.orient==="left")i-=n.length;else if(n.orient==="right")i+=n.length;var r=o._y(t,e);if(n.orient==="top")r-=n.length;else if(n.orient==="bottom")r+=n.length;n.x=i;n.y=r;return n});this._whiskerEndpoint=[];u.nest().key(function(t){return t.endpoint}).entries(n).forEach(function(t){var e=t.key;o._whiskerEndpoint.push((new q[e]).data(t.values).select(p.elem("g.d3plus-Whisker-Endpoint-".concat(e),{parent:o._select}).node()).config({height:function t(e){return e.orient==="top"||e.orient==="bottom"?5:20},width:function t(e){return e.orient==="top"||e.orient==="bottom"?20:5}}).config(p.configPrep.bind(o)(o._endpointConfig,"shape",e)).render())});return this}},{key:"active",value:function t(e){if(this._line)this._line.active(e);if(this._whiskerEndpoint)this._whiskerEndpoint.forEach(function(t){return t.active(e)})}},{key:"data",value:function t(e){return arguments.length?(this._data=e,this):this._data}},{key:"endpoint",value:function t(e){return arguments.length?(this._endpoint=typeof e==="function"?e:p.constant(e),this):this._endpoint}},{key:"endpointConfig",value:function t(e){return arguments.length?(this._endpointConfig=p.assign(this._endpointConfig,e),this):this._endpointConfig}},{key:"hover",value:function t(e){if(this._line)this._line.hover(e);if(this._whiskerEndpoint)this._whiskerEndpoint.forEach(function(t){return t.hover(e)})}},{key:"length",value:function t(e){return arguments.length?(this._length=typeof e==="function"?e:p.constant(e),this):this._length}},{key:"lineConfig",value:function t(e){return arguments.length?(this._lineConfig=p.assign(this._lineConfig,e),this):this._lineConfig}},{key:"orient",value:function t(e){return arguments.length?(this._orient=typeof e==="function"?e:p.constant(e),this):this._orient}},{key:"select",value:function t(e){return arguments.length?(this._select=d.select(e),this):this._select}},{key:"x",value:function t(e){return arguments.length?(this._x=typeof e==="function"?e:p.constant(e),this):this._x}},{key:"y",value:function t(e){return arguments.length?(this._y=typeof e==="function"?e:p.constant(e),this):this._y}}]);return e}(p.BaseClass);var D={Circle:I,Rect:B};var z=function(t){h(e,t);function e(){var i;o(this,e);i=_(this,l(e).call(this));i._medianConfig={fill:p.constant("black")};i._orient=p.accessor("orient","vertical");i._outlier=p.accessor("outlier","Circle");i._outlierConfig={Circle:{r:p.accessor("r",5)},Rect:{height:function t(e,n){return i._orient(e,n)==="vertical"?5:20},width:function t(e,n){return i._orient(e,n)==="vertical"?20:5}}};i._rectConfig={fill:p.constant("white"),stroke:p.constant("black"),strokeWidth:p.constant(1)};i._rectWidth=p.constant(50);i._whiskerConfig={};i._whiskerMode=["tukey","tukey"];i._x=p.accessor("x",250);i._y=p.accessor("y",250);return i}c(e,[{key:"render",value:function t(){var a=this;if(this._select===void 0){this.select(d.select("body").append("svg").style("width","".concat(window.innerWidth,"px")).style("height","".concat(window.innerHeight,"px")).style("display","block").node())}var s=[];var e=u.nest().key(function(t,e){return a._orient(t,e)==="vertical"?a._x(t,e):a._y(t,e)}).entries(this._data).map(function(r){r.data=p.merge(r.values);r.i=a._data.indexOf(r.values[0]);r.orient=a._orient(r.data,r.i);var t=r.values.map(r.orient==="vertical"?a._y:a._x);t.sort(function(t,e){return t-e});r.first=xt.quantile(t,.25);r.median=xt.quantile(t,.5);r.third=xt.quantile(t,.75);var e=a._whiskerMode;if(e[0]==="tukey"){r.lowerLimit=r.first-(r.third-r.first)*1.5;if(r.lowerLimit<xt.min(t))r.lowerLimit=xt.min(t)}else if(e[0]==="extent")r.lowerLimit=xt.min(t);else if(typeof e[0]==="number")r.lowerLimit=xt.quantile(t,e[0]);if(e[1]==="tukey"){r.upperLimit=r.third+(r.third-r.first)*1.5;if(r.upperLimit>xt.max(t))r.upperLimit=xt.max(t)}else if(e[1]==="extent")r.upperLimit=xt.max(t);else if(typeof e[1]==="number")r.upperLimit=xt.quantile(t,e[1]);var n=r.third-r.first;if(r.orient==="vertical"){r.height=n;r.width=a._rectWidth(r.data,r.i);r.x=a._x(r.data,r.i);r.y=r.first+n/2}else if(r.orient==="horizontal"){r.height=a._rectWidth(r.data,r.i);r.width=n;r.x=r.first+n/2;r.y=a._y(r.data,r.i)}r.values.forEach(function(t,e){var n=r.orient==="vertical"?a._y(t,e):a._x(t,e);if(n<r.lowerLimit||n>r.upperLimit){var i={};i.__d3plus__=true;i.data=t;i.i=e;i.outlier=a._outlier(t,e);if(r.orient==="vertical"){i.x=r.x;i.y=n;s.push(i)}else if(r.orient==="horizontal"){i.y=r.y;i.x=n;s.push(i)}}});r.__d3plus__=true;return r});this._box=(new B).data(e).x(function(t){return t.x}).y(function(t){return t.y}).select(p.elem("g.d3plus-Box",{parent:this._select}).node()).config(p.configPrep.bind(this)(this._rectConfig,"shape")).render();this._median=(new B).data(e).x(function(t){return t.orient==="vertical"?t.x:t.median}).y(function(t){return t.orient==="vertical"?t.median:t.y}).height(function(t){return t.orient==="vertical"?1:t.height}).width(function(t){return t.orient==="vertical"?t.width:1}).select(p.elem("g.d3plus-Box-Median",{parent:this._select}).node()).config(p.configPrep.bind(this)(this._medianConfig,"shape")).render();var c=[];e.forEach(function(t,e){var n=t.x;var i=t.y;var r=t.first-t.lowerLimit;var a=t.upperLimit-t.third;if(t.orient==="vertical"){var s=i-t.height/2;var o=i+t.height/2;c.push({__d3plus__:true,data:t,i:e,x:n,y:s,length:r,orient:"top"},{__d3plus__:true,data:t,i:e,x:n,y:o,length:a,orient:"bottom"})}else if(t.orient==="horizontal"){var h=n+t.width/2;var u=n-t.width/2;c.push({__d3plus__:true,data:t,i:e,x:h,y:i,length:a,orient:"right"},{__d3plus__:true,data:t,i:e,x:u,y:i,length:r,orient:"left"})}});this._whisker=(new F).data(c).select(p.elem("g.d3plus-Box-Whisker",{parent:this._select}).node()).config(p.configPrep.bind(this)(this._whiskerConfig,"shape")).render();this._whiskerEndpoint=[];u.nest().key(function(t){return t.outlier}).entries(s).forEach(function(t){var e=t.key;a._whiskerEndpoint.push((new D[e]).data(t.values).select(p.elem("g.d3plus-Box-Outlier-".concat(e),{parent:a._select}).node()).config(p.configPrep.bind(a)(a._outlierConfig,"shape",e)).render())});return this}},{key:"active",value:function t(e){if(this._box)this._box.active(e);if(this._median)this._median.active(e);if(this._whisker)this._whisker.active(e);if(this._whiskerEndpoint)this._whiskerEndpoint.forEach(function(t){return t.active(e)})}},{key:"data",value:function t(e){return arguments.length?(this._data=e,this):this._data}},{key:"hover",value:function t(e){if(this._box)this._box.hover(e);if(this._median)this._median.hover(e);if(this._whisker)this._whisker.hover(e);if(this._whiskerEndpoint)this._whiskerEndpoint.forEach(function(t){return t.hover(e)})}},{key:"medianConfig",value:function t(e){return arguments.length?(this._medianConfig=p.assign(this._medianConfig,e),this):this._medianConfig}},{key:"orient",value:function t(e){return arguments.length?(this._orient=typeof e==="function"?e:p.constant(e),this):this._orient}},{key:"outlier",value:function t(e){return arguments.length?(this._outlier=typeof e==="function"?e:p.constant(e),this):this._outlier}},{key:"outlierConfig",value:function t(e){return arguments.length?(this._outlierConfig=p.assign(this._outlierConfig,e),this):this._outlierConfig}},{key:"rectConfig",value:function t(e){return arguments.length?(this._rectConfig=p.assign(this._rectConfig,e),this):this._rectConfig}},{key:"rectWidth",value:function t(e){return arguments.length?(this._rectWidth=typeof e==="function"?e:p.constant(e),this):this._rectWidth}},{key:"select",value:function t(e){return arguments.length?(this._select=d.select(e),this):this._select}},{key:"whiskerConfig",value:function t(e){return arguments.length?(this._whiskerConfig=p.assign(this._whiskerConfig,e),this):this._whiskerConfig}},{key:"whiskerMode",value:function t(e){return arguments.length?(this._whiskerMode=e instanceof Array?e:[e,e],this):this._whiskerMode}},{key:"x",value:function t(e){return arguments.length?(this._x=typeof e==="function"?e:p.accessor(e),this):this._x}},{key:"y",value:function t(e){return arguments.length?(this._y=typeof e==="function"?e:p.accessor(e),this):this._y}}]);return e}(p.BaseClass);var G=Math.PI;var V=function(t,e){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"circle";if(t<0)t=G*2+t;if(n==="square"){var i=45*(G/180);var r=0,a=0;if(t<G/2){var s=Math.tan(t);r+=t<i?e:e/s;a+=t<i?s*e:e}else if(t<=G){var o=Math.tan(G-t);r-=t<G-i?e/o:e;a+=t<G-i?e:o*e}else if(t<i+G){r-=e;a-=Math.tan(t-G)*e}else if(t<3*G/2){r-=e/Math.tan(t-G);a-=e}else if(t<2*G-i){r+=e/Math.tan(2*G-t);a-=e}else{r+=e;a-=Math.tan(2*G-t)*e}return[r,a]}else if(n==="circle"){return[e*Math.cos(t),e*Math.sin(t)]}else return null};var U=Math.PI;var X=function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:20;var n=[],i=/([MLA])([^MLAZ]+)/gi;var r=i.exec(t);while(r!==null){if(["M","L"].includes(r[1]))n.push(r[2].split(",").map(Number));else if(r[1]==="A"){var a=r[2].split(",").map(Number);var s=a.slice(a.length-2,a.length),o=n[n.length-1],h=a[0],u=C(o,s);var c=Math.acos((h*h+h*h-u*u)/(2*h*h));if(a[2])c=U*2-c;var l=c/(c/(U*2)*(h*U*2)/e);var f=Math.atan2(-o[1],-o[0])-U;var _=l;while(_<c){n.push(V(a[4]?f+_:f-_,h));_+=l}n.push(s)}r=i.exec(t)}return n};var Y=function(t){h(n,t);function n(){var r;o(this,n);r=_(this,l(n).call(this,"path"));r._d=p.accessor("path");r._labelBounds=function(t,e,n){var i=L(n.points,{angle:r._labelConfig.rotate?r._labelConfig.rotate(t,e):0});return i?{angle:i.angle,width:i.width,height:i.height,x:i.cx-i.width/2,y:i.cy-i.height/2}:false};r._name="Path";r._labelConfig=Object.assign(r._labelConfig,{textAnchor:"middle",verticalAlign:"middle"});return r}c(n,[{key:"_aes",value:function t(e,n){return{points:X(this._d(e,n))}}},{key:"render",value:function t(e){m(l(n.prototype),"render",this).call(this,e);this._enter.attr("opacity",0).attr("d",this._d).call(this._applyStyle.bind(this)).transition(this._transition).attr("opacity",1);this._update.transition(this._transition).call(this._applyStyle.bind(this)).attr("opacity",1).attr("d",this._d);this._exit.transition(this._transition).attr("opacity",0);return this}},{key:"d",value:function t(e){return arguments.length?(this._d=typeof e==="function"?e:p.constant(e),this):this._d}}]);return n}(e);t.Area=N;t.Bar=T;t.Box=z;t.Circle=I;t.Image=O;t.Line=H;t.Path=Y;t.Rect=B;t.Shape=e;t.Whisker=F;t.largestRect=L;t.lineIntersection=S;t.path2polygon=X;t.pointDistance=C;t.pointDistanceSquared=bt;t.pointRotate=M;t.polygonInside=wt;t.polygonRayCast=Ot;t.polygonRotate=Ct;t.segmentBoxContains=A;t.segmentsIntersect=E;t.shapeEdgePoint=V;t.simplify=St;Object.defineProperty(t,"__esModule",{value:true})});(function(t){typeof define==="function"&&define.amd?define(t):t()})(function(){"use strict";var t=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};function e(t,e){return e={exports:{}},t(e,e.exports),e.exports}var n="object";var i=function(t){return t&&t.Math==Math&&t};var l=i(typeof globalThis==n&&globalThis)||i(typeof window==n&&window)||i(typeof self==n&&self)||i(typeof t==n&&t)||Function("return this")();var r=function(t){try{return!!t()}catch(t){return true}};var _=!r(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7});var a={}.propertyIsEnumerable;var s=Object.getOwnPropertyDescriptor;var o=s&&!a.call({1:2},1);var h=o?function t(e){var n=s(this,e);return!!n&&n.enumerable}:a;var d={f:h};var u=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}};var c={}.toString;var f=function(t){return c.call(t).slice(8,-1)};var v="".split;var m=r(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return f(t)=="String"?v.call(t,""):Object(t)}:Object;var p=function(t){if(t==undefined)throw TypeError("Can't call method on "+t);return t};var y=function(t){return m(p(t))};var g=function(t){return typeof t==="object"?t!==null:typeof t==="function"};var x=function(t,e){if(!g(t))return t;var n,i;if(e&&typeof(n=t.toString)=="function"&&!g(i=n.call(t)))return i;if(typeof(n=t.valueOf)=="function"&&!g(i=n.call(t)))return i;if(!e&&typeof(n=t.toString)=="function"&&!g(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")};var k={}.hasOwnProperty;var b=function(t,e){return k.call(t,e)};var w=l.document;var O=g(w)&&g(w.createElement);var C=function(t){return O?w.createElement(t):{}};var S=!_&&!r(function(){return Object.defineProperty(C("div"),"a",{get:function(){return 7}}).a!=7});var A=Object.getOwnPropertyDescriptor;var E=_?A:function t(e,n){e=y(e);n=x(n,true);if(S)try{return A(e,n)}catch(t){}if(b(e,n))return u(!d.f.call(e,n),e[n])};var M={f:E};var P=function(t){if(!g(t)){throw TypeError(String(t)+" is not an object")}return t};var j=Object.defineProperty;var R=_?j:function t(e,n,i){P(e);n=x(n,true);P(i);if(S)try{return j(e,n,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported");if("value"in i)e[n]=i.value;return e};var W={f:R};var L=_?function(t,e,n){return W.f(t,e,u(1,n))}:function(t,e,n){t[e]=n;return t};var N=function(e,n){try{L(l,e,n)}catch(t){l[e]=n}return n};var T=e(function(t){var e="__core-js_shared__";var n=l[e]||N(e,{});(t.exports=function(t,e){return n[t]||(n[t]=e!==undefined?e:{})})("versions",[]).push({version:"3.1.3",mode:"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})});var I=T("native-function-to-string",Function.toString);var B=l.WeakMap;var H=typeof B==="function"&&/native code/.test(I.call(B));var q=0;var F=Math.random();var D=function(t){return"Symbol("+String(t===undefined?"":t)+")_"+(++q+F).toString(36)};var z=T("keys");var G=function(t){return z[t]||(z[t]=D(t))};var V={};var U=l.WeakMap;var X,Y,K;var Z=function(t){return K(t)?Y(t):X(t,{})};var J=function(n){return function(t){var e;if(!g(t)||(e=Y(t)).type!==n){throw TypeError("Incompatible receiver, "+n+" required")}return e}};if(H){var Q=new U;var $=Q.get;var tt=Q.has;var et=Q.set;X=function(t,e){et.call(Q,t,e);return e};Y=function(t){return $.call(Q,t)||{}};K=function(t){return tt.call(Q,t)}}else{var nt=G("state");V[nt]=true;X=function(t,e){L(t,nt,e);return e};Y=function(t){return b(t,nt)?t[nt]:{}};K=function(t){return b(t,nt)}}var it={set:X,get:Y,has:K,enforce:Z,getterFor:J};var rt=e(function(t){var e=it.get;var o=it.enforce;var h=String(I).split("toString");T("inspectSource",function(t){return I.call(t)});(t.exports=function(t,e,n,i){var r=i?!!i.unsafe:false;var a=i?!!i.enumerable:false;var s=i?!!i.noTargetGet:false;if(typeof n=="function"){if(typeof e=="string"&&!b(n,"name"))L(n,"name",e);o(n).source=h.join(typeof e=="string"?e:"")}if(t===l){if(a)t[e]=n;else N(e,n);return}else if(!r){delete t[e]}else if(!s&&t[e]){a=true}if(a)t[e]=n;else L(t,e,n)})(Function.prototype,"toString",function t(){return typeof this=="function"&&e(this).source||I.call(this)})});var at=l;var st=function(t){return typeof t=="function"?t:undefined};var ot=function(t,e){return arguments.length<2?st(at[t])||st(l[t]):at[t]&&at[t][e]||l[t]&&l[t][e]};var ht=Math.ceil;var ut=Math.floor;var ct=function(t){return isNaN(t=+t)?0:(t>0?ut:ht)(t)};var lt=Math.min;var ft=function(t){return t>0?lt(ct(t),9007199254740991):0};var _t=Math.max;var dt=Math.min;var vt=function(t,e){var n=ct(t);return n<0?_t(n+e,0):dt(n,e)};var pt=function(o){return function(t,e,n){var i=y(t);var r=ft(i.length);var a=vt(n,r);var s;if(o&&e!=e)while(r>a){s=i[a++];if(s!=s)return true}else for(;r>a;a++){if((o||a in i)&&i[a]===e)return o||a||0}return!o&&-1}};var yt={includes:pt(true),indexOf:pt(false)};var gt=yt.indexOf;var xt=function(t,e){var n=y(t);var i=0;var r=[];var a;for(a in n)!b(V,a)&&b(n,a)&&r.push(a);while(e.length>i)if(b(n,a=e[i++])){~gt(r,a)||r.push(a)}return r};var mt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"];var kt=mt.concat("length","prototype");var bt=Object.getOwnPropertyNames||function t(e){return xt(e,kt)};var wt={f:bt};var Ot=Object.getOwnPropertySymbols;var Ct={f:Ot};var St=ot("Reflect","ownKeys")||function t(e){var n=wt.f(P(e));var i=Ct.f;return i?n.concat(i(e)):n};var At=function(t,e){var n=St(e);var i=W.f;var r=M.f;for(var a=0;a<n.length;a++){var s=n[a];if(!b(t,s))i(t,s,r(e,s))}};var Et=/#|\.prototype\./;var Mt=function(t,e){var n=jt[Pt(t)];return n==Wt?true:n==Rt?false:typeof e=="function"?r(e):!!e};var Pt=Mt.normalize=function(t){return String(t).replace(Et,".").toLowerCase()};var jt=Mt.data={};var Rt=Mt.NATIVE="N";var Wt=Mt.POLYFILL="P";var Lt=Mt;var Nt=M.f;var Tt=function(t,e){var n=t.target;var i=t.global;var r=t.stat;var a,s,o,h,u,c;if(i){s=l}else if(r){s=l[n]||N(n,{})}else{s=(l[n]||{}).prototype}if(s)for(o in e){u=e[o];if(t.noTargetGet){c=Nt(s,o);h=c&&c.value}else h=s[o];a=Lt(i?o:n+(r?".":"#")+o,t.forced);if(!a&&h!==undefined){if(typeof u===typeof h)continue;At(u,h)}if(t.sham||h&&h.sham){L(u,"sham",true)}rt(s,o,u,t)}};var It=function(t){if(typeof t!="function"){throw TypeError(String(t)+" is not a function")}return t};var Bt=function(i,r,t){It(i);if(r===undefined)return i;switch(t){case 0:return function(){return i.call(r)};case 1:return function(t){return i.call(r,t)};case 2:return function(t,e){return i.call(r,t,e)};case 3:return function(t,e,n){return i.call(r,t,e,n)}}return function(){return i.apply(r,arguments)}};var Ht=function(t){return Object(p(t))};var qt=Array.isArray||function t(e){return f(e)=="Array"};var Ft=!!Object.getOwnPropertySymbols&&!r(function(){return!String(Symbol())});var Dt=l.Symbol;var zt=T("wks");var Gt=function(t){return zt[t]||(zt[t]=Ft&&Dt[t]||(Ft?Dt:D)("Symbol."+t))};var Vt=Gt("species");var Ut=function(t,e){var n;if(qt(t)){n=t.constructor;if(typeof n=="function"&&(n===Array||qt(n.prototype)))n=undefined;else if(g(n)){n=n[Vt];if(n===null)n=undefined}}return new(n===undefined?Array:n)(e===0?0:e)};var Xt=[].push;var Yt=function(_){var d=_==1;var v=_==2;var p=_==3;var y=_==4;var g=_==6;var x=_==5||g;return function(t,e,n,i){var r=Ht(t);var a=m(r);var s=Bt(e,n,3);var o=ft(a.length);var h=0;var u=i||Ut;var c=d?u(t,o):v?u(t,0):undefined;var l,f;for(;o>h;h++)if(x||h in a){l=a[h];f=s(l,h,r);if(_){if(d)c[h]=f;else if(f)switch(_){case 3:return true;case 5:return l;case 6:return h;case 2:Xt.call(c,l)}else if(y)return false}}return g?-1:p||y?y:c}};var Kt={forEach:Yt(0),map:Yt(1),filter:Yt(2),some:Yt(3),every:Yt(4),find:Yt(5),findIndex:Yt(6)};var Zt=Object.keys||function t(e){return xt(e,mt)};var Jt=_?Object.defineProperties:function t(e,n){P(e);var i=Zt(n);var r=i.length;var a=0;var s;while(r>a)W.f(e,s=i[a++],n[s]);return e};var Qt=ot("document","documentElement");var $t=G("IE_PROTO");var te="prototype";var ee=function(){};var ne=function(){var t=C("iframe");var e=mt.length;var n="<";var i="script";var r=">";var a="java"+i+":";var s;t.style.display="none";Qt.appendChild(t);t.src=String(a);s=t.contentWindow.document;s.open();s.write(n+i+r+"document.F=Object"+n+"/"+i+r);s.close();ne=s.F;while(e--)delete ne[te][mt[e]];return ne()};var ie=Object.create||function t(e,n){var i;if(e!==null){ee[te]=P(e);i=new ee;ee[te]=null;i[$t]=e}else i=ne();return n===undefined?i:Jt(i,n)};V[$t]=true;var re=Gt("unscopables");var ae=Array.prototype;if(ae[re]==undefined){L(ae,re,ie(null))}var se=function(t){ae[re][t]=true};var oe=Kt.find;var he="find";var ue=true;if(he in[])Array(1)[he](function(){ue=false});Tt({target:"Array",proto:true,forced:ue},{find:function t(e){return oe(this,e,arguments.length>1?arguments[1]:undefined)}});se(he);var ce=yt.includes;Tt({target:"Array",proto:true},{includes:function t(e){return ce(this,e,arguments.length>1?arguments[1]:undefined)}});se("includes");var le=Object.assign;var fe=!le||r(function(){var t={};var e={};var n=Symbol();var i="abcdefghijklmnopqrst";t[n]=7;i.split("").forEach(function(t){e[t]=t});return le({},t)[n]!=7||Zt(le({},e)).join("")!=i})?function t(e,n){var i=Ht(e);var r=arguments.length;var a=1;var s=Ct.f;var o=d.f;while(r>a){var h=m(arguments[a++]);var u=s?Zt(h).concat(s(h)):Zt(h);var c=u.length;var l=0;var f;while(c>l){f=u[l++];if(!_||o.call(h,f))i[f]=h[f]}}return i}:le;Tt({target:"Object",stat:true,forced:Object.assign!==fe},{assign:fe});var _e=Gt("match");var de=function(t){var e;return g(t)&&((e=t[_e])!==undefined?!!e:f(t)=="RegExp")};var ve=function(t){if(de(t)){throw TypeError("The method doesn't accept regular expressions")}return t};var pe=Gt("match");var ye=function(e){var n=/./;try{"/./"[e](n)}catch(t){try{n[pe]=false;return"/./"[e](n)}catch(t){}}return false};var ge="".startsWith;var xe=Math.min;Tt({target:"String",proto:true,forced:!ye("startsWith")},{startsWith:function t(e){var n=String(p(this));ve(e);var i=ft(xe(arguments.length>1?arguments[1]:undefined,n.length));var r=String(e);return ge?ge.call(n,r,i):n.slice(i,i+r.length)===r}});if(typeof window!=="undefined"){(function(){var i=function(t,e){var n=t.nodeType;if(n===3){e.push(t.textContent.replace(/&/,"&").replace(/</,"<").replace(">",">"))}else if(n===1){e.push("<",t.tagName);if(t.hasAttributes()){[].forEach.call(t.attributes,function(t){e.push(" ",t.item.name,"='",t.item.value,"'")})}if(t.hasChildNodes()){e.push(">");[].forEach.call(t.childNodes,function(t){i(t,e)});e.push("</",t.tagName,">")}else{e.push("/>")}}else if(n==8){e.push("\x3c!--",t.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t=[];var e=this.firstChild;while(e){i(e,t);e=e.nextSibling}return t.join("")},set:function(t){while(this.firstChild){this.removeChild(this.firstChild)}try{var e=new DOMParser;e.async=false;var n="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+t+"</svg>";var i=e.parseFromString(n,"text/xml").documentElement;var r=i.firstChild;while(r){this.appendChild(this.ownerDocument.importNode(r,true));r=r.nextSibling}}catch(t){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(t){this.innerHTML=t}})})()}}); |
@@ -1,27 +0,23 @@ | ||
export {default as Image} from "./src/Image"; | ||
export {default as Shape} from "./src/Shape/Shape"; | ||
export {default as Area} from "./src/Shape/Area"; | ||
export {default as Bar} from "./src/Shape/Bar"; | ||
export {default as Box} from "./src/Shape/Box"; | ||
export {default as Circle} from "./src/Shape/Circle"; | ||
export {default as Line} from "./src/Shape/Line"; | ||
export {default as Path} from "./src/Shape/Path"; | ||
export {default as Rect} from "./src/Shape/Rect"; | ||
export {default as Whisker} from "./src/Shape/Whisker"; | ||
export {default as largestRect} from "./src/geom/largestRect"; | ||
export {default as lineIntersection} from "./src/geom/lineIntersection"; | ||
export {default as path2polygon} from "./src/geom/path2polygon"; | ||
export {default as pointDistance} from "./src/geom/pointDistance"; | ||
export {default as pointDistanceSquared} from "./src/geom/pointDistanceSquared"; | ||
export {default as pointRotate} from "./src/geom/pointRotate"; | ||
export {default as polygonInside} from "./src/geom/polygonInside"; | ||
export {default as polygonRayCast} from "./src/geom/polygonRayCast"; | ||
export {default as polygonRotate} from "./src/geom/polygonRotate"; | ||
export {default as segmentBoxContains} from "./src/geom/segmentBoxContains"; | ||
export {default as segmentsIntersect} from "./src/geom/segmentsIntersect"; | ||
export {default as shapeEdgePoint} from "./src/geom/shapeEdgePoint"; | ||
export {default as simplify} from "./src/geom/simplify"; | ||
//# sourceMappingURL=index.js.map | ||
export { default as Image } from "./src/Image"; | ||
export { default as Shape } from "./src/Shape/Shape"; | ||
export { default as Area } from "./src/Shape/Area"; | ||
export { default as Bar } from "./src/Shape/Bar"; | ||
export { default as Box } from "./src/Shape/Box"; | ||
export { default as Circle } from "./src/Shape/Circle"; | ||
export { default as Line } from "./src/Shape/Line"; | ||
export { default as Path } from "./src/Shape/Path"; | ||
export { default as Rect } from "./src/Shape/Rect"; | ||
export { default as Whisker } from "./src/Shape/Whisker"; | ||
export { default as largestRect } from "./src/geom/largestRect"; | ||
export { default as lineIntersection } from "./src/geom/lineIntersection"; | ||
export { default as path2polygon } from "./src/geom/path2polygon"; | ||
export { default as pointDistance } from "./src/geom/pointDistance"; | ||
export { default as pointDistanceSquared } from "./src/geom/pointDistanceSquared"; | ||
export { default as pointRotate } from "./src/geom/pointRotate"; | ||
export { default as polygonInside } from "./src/geom/polygonInside"; | ||
export { default as polygonRayCast } from "./src/geom/polygonRayCast"; | ||
export { default as polygonRotate } from "./src/geom/polygonRotate"; | ||
export { default as segmentBoxContains } from "./src/geom/segmentBoxContains"; | ||
export { default as segmentsIntersect } from "./src/geom/segmentsIntersect"; | ||
export { default as shapeEdgePoint } from "./src/geom/shapeEdgePoint"; | ||
export { default as simplify } from "./src/geom/simplify"; |
@@ -1,4 +0,3 @@ | ||
import {extent, merge, range} from "d3-array"; | ||
import {polygonArea, polygonCentroid, polygonContains} from "d3-polygon"; | ||
import { extent, merge, range } from "d3-array"; | ||
import { polygonArea, polygonCentroid, polygonContains } from "d3-polygon"; | ||
import polygonInside from "./polygonInside"; | ||
@@ -8,10 +7,9 @@ import polygonRayCast from "./polygonRayCast"; | ||
import simplify from "./simplify"; | ||
import pointDistanceSquared from "./pointDistanceSquared"; | ||
import pointDistanceSquared from "./pointDistanceSquared"; // Algorithm constants | ||
// Algorithm constants | ||
var aspectRatioStep = 0.5; // step size for the aspect ratio | ||
var angleStep = 5; // step size for angles (in degrees); has linear impact on running time | ||
const aspectRatioStep = 0.5; // step size for the aspect ratio | ||
var polyCache = {}; | ||
const angleStep = 5; // step size for angles (in degrees); has linear impact on running time | ||
const polyCache = {}; | ||
/** | ||
@@ -47,16 +45,12 @@ @typedef {Object} LargestRect | ||
*/ | ||
export default function(poly, options) { | ||
var assign, assign$1; | ||
if ( options === void 0 ) options = {}; | ||
export default function (poly, options = {}) { | ||
if (poly.length < 3) { | ||
if (options.verbose) { console.error("polygon has to have at least 3 points", poly); } | ||
if (options.verbose) console.error("polygon has to have at least 3 points", poly); | ||
return null; | ||
} | ||
} // For visualization debugging purposes | ||
// For visualization debugging purposes | ||
var events = []; | ||
// User's input normalization | ||
const events = []; // User's input normalization | ||
options = Object.assign({ | ||
@@ -73,156 +67,145 @@ angle: range(-90, 90 + angleStep, angleStep), | ||
}, options); | ||
const angles = options.angle instanceof Array ? options.angle : typeof options.angle === "number" ? [options.angle] : typeof options.angle === "string" && !isNaN(options.angle) ? [Number(options.angle)] : []; | ||
const aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio : typeof options.aspectRatio === "number" ? [options.aspectRatio] : typeof options.aspectRatio === "string" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)] : []; | ||
const origins = options.origin && options.origin instanceof Array ? options.origin[0] instanceof Array ? options.origin : [options.origin] : []; | ||
let cacheString; | ||
var angles = options.angle instanceof Array ? options.angle | ||
: typeof options.angle === "number" ? [options.angle] | ||
: typeof options.angle === "string" && !isNaN(options.angle) ? [Number(options.angle)] | ||
: []; | ||
var aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio | ||
: typeof options.aspectRatio === "number" ? [options.aspectRatio] | ||
: typeof options.aspectRatio === "string" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)] | ||
: []; | ||
var origins = options.origin && options.origin instanceof Array | ||
? options.origin[0] instanceof Array ? options.origin | ||
: [options.origin] : []; | ||
var cacheString; | ||
if (options.cache) { | ||
cacheString = merge(poly).join(","); | ||
cacheString += "-" + (options.minAspectRatio); | ||
cacheString += "-" + (options.maxAspectRatio); | ||
cacheString += "-" + (options.minHeight); | ||
cacheString += "-" + (options.minWidth); | ||
cacheString += "-" + (angles.join(",")); | ||
cacheString += "-" + (origins.join(",")); | ||
if (polyCache[cacheString]) { return polyCache[cacheString]; } | ||
cacheString += `-${options.minAspectRatio}`; | ||
cacheString += `-${options.maxAspectRatio}`; | ||
cacheString += `-${options.minHeight}`; | ||
cacheString += `-${options.minWidth}`; | ||
cacheString += `-${angles.join(",")}`; | ||
cacheString += `-${origins.join(",")}`; | ||
if (polyCache[cacheString]) return polyCache[cacheString]; | ||
} | ||
var area = Math.abs(polygonArea(poly)); // take absolute value of the signed area | ||
const area = Math.abs(polygonArea(poly)); // take absolute value of the signed area | ||
if (area === 0) { | ||
if (options.verbose) { console.error("polygon has 0 area", poly); } | ||
if (options.verbose) console.error("polygon has 0 area", poly); | ||
return null; | ||
} | ||
// get the width of the bounding box of the original polygon to determine tolerance | ||
var ref = extent(poly, function (d) { return d[0]; }); | ||
var minx = ref[0]; | ||
var maxx = ref[1]; | ||
var ref$1 = extent(poly, function (d) { return d[1]; }); | ||
var miny = ref$1[0]; | ||
var maxy = ref$1[1]; | ||
} // get the width of the bounding box of the original polygon to determine tolerance | ||
// simplify polygon | ||
var tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance; | ||
if (tolerance > 0) { poly = simplify(poly, tolerance); } | ||
if (options.events) { events.push({type: "simplify", poly: poly}); } | ||
let [minx, maxx] = extent(poly, d => d[0]); | ||
let [miny, maxy] = extent(poly, d => d[1]); // simplify polygon | ||
// get the width of the bounding box of the simplified polygon | ||
(assign = extent(poly, function (d) { return d[0]; }), minx = assign[0], maxx = assign[1]); | ||
(assign$1 = extent(poly, function (d) { return d[1]; }), miny = assign$1[0], maxy = assign$1[1]); | ||
var ref$2 = [maxx - minx, maxy - miny]; | ||
var boxWidth = ref$2[0]; | ||
var boxHeight = ref$2[1]; | ||
const tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance; | ||
if (tolerance > 0) poly = simplify(poly, tolerance); | ||
if (options.events) events.push({ | ||
type: "simplify", | ||
poly | ||
}); // get the width of the bounding box of the simplified polygon | ||
// discretize the binary search for optimal width to a resolution of this times the polygon width | ||
var widthStep = Math.min(boxWidth, boxHeight) / 50; | ||
[minx, maxx] = extent(poly, d => d[0]); | ||
[miny, maxy] = extent(poly, d => d[1]); | ||
const [boxWidth, boxHeight] = [maxx - minx, maxy - miny]; // discretize the binary search for optimal width to a resolution of this times the polygon width | ||
// populate possible center points with random points inside the polygon | ||
const widthStep = Math.min(boxWidth, boxHeight) / 50; // populate possible center points with random points inside the polygon | ||
if (!origins.length) { | ||
// get the centroid of the polygon | ||
var centroid = polygonCentroid(poly); | ||
const centroid = polygonCentroid(poly); | ||
if (!isFinite(centroid[0])) { | ||
if (options.verbose) { console.error("cannot find centroid", poly); } | ||
if (options.verbose) console.error("cannot find centroid", poly); | ||
return null; | ||
} | ||
if (polygonContains(poly, centroid)) { origins.push(centroid); } | ||
var nTries = options.nTries; | ||
// get few more points inside the polygon | ||
if (polygonContains(poly, centroid)) origins.push(centroid); | ||
let nTries = options.nTries; // get few more points inside the polygon | ||
while (nTries) { | ||
var rndX = Math.random() * boxWidth + minx; | ||
var rndY = Math.random() * boxHeight + miny; | ||
var rndPoint = [rndX, rndY]; | ||
const rndX = Math.random() * boxWidth + minx; | ||
const rndY = Math.random() * boxHeight + miny; | ||
const rndPoint = [rndX, rndY]; | ||
if (polygonContains(poly, rndPoint)) { | ||
origins.push(rndPoint); | ||
} | ||
nTries--; | ||
} | ||
} | ||
if (options.events) { events.push({type: "origins", points: origins}); } | ||
var maxArea = 0; | ||
var maxRect = null; | ||
for (var ai = 0; ai < angles.length; ai++) { | ||
var angle = angles[ai]; | ||
var angleRad = -angle * Math.PI / 180; | ||
if (options.events) { events.push({type: "angle", angle: angle}); } | ||
for (var i = 0; i < origins.length; i++) { | ||
var origOrigin = origins[i]; | ||
// generate improved origins | ||
var ref$3 = polygonRayCast(poly, origOrigin, angleRad); | ||
var p1W = ref$3[0]; | ||
var p2W = ref$3[1]; | ||
var ref$4 = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2); | ||
var p1H = ref$4[0]; | ||
var p2H = ref$4[1]; | ||
var modifOrigins = []; | ||
if (p1W && p2W) { modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); } // average along with width axis | ||
if (p1H && p2H) { modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); } // average along with height axis | ||
if (options.events) events.push({ | ||
type: "origins", | ||
points: origins | ||
}); | ||
let maxArea = 0; | ||
let maxRect = null; | ||
if (options.events) { events.push({type: "modifOrigin", idx: i, p1W: p1W, p2W: p2W, p1H: p1H, p2H: p2H, modifOrigins: modifOrigins}); } | ||
for (let ai = 0; ai < angles.length; ai++) { | ||
const angle = angles[ai]; | ||
const angleRad = -angle * Math.PI / 180; | ||
if (options.events) events.push({ | ||
type: "angle", | ||
angle | ||
}); | ||
for (var i$1 = 0; i$1 < modifOrigins.length; i$1++) { | ||
for (let i = 0; i < origins.length; i++) { | ||
const origOrigin = origins[i]; // generate improved origins | ||
var origin = modifOrigins[i$1]; | ||
const [p1W, p2W] = polygonRayCast(poly, origOrigin, angleRad); | ||
const [p1H, p2H] = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2); | ||
const modifOrigins = []; | ||
if (p1W && p2W) modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); // average along with width axis | ||
if (options.events) { events.push({type: "origin", cx: origin[0], cy: origin[1]}); } | ||
if (p1H && p2H) modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); // average along with height axis | ||
var ref$5 = polygonRayCast(poly, origin, angleRad); | ||
var p1W$1 = ref$5[0]; | ||
var p2W$1 = ref$5[1]; | ||
if (p1W$1 === null || p2W$1 === null) { continue; } | ||
var minSqDistW = Math.min(pointDistanceSquared(origin, p1W$1), pointDistanceSquared(origin, p2W$1)); | ||
var maxWidth = 2 * Math.sqrt(minSqDistW); | ||
if (options.events) events.push({ | ||
type: "modifOrigin", | ||
idx: i, | ||
p1W, | ||
p2W, | ||
p1H, | ||
p2H, | ||
modifOrigins | ||
}); | ||
var ref$6 = polygonRayCast(poly, origin, angleRad + Math.PI / 2); | ||
var p1H$1 = ref$6[0]; | ||
var p2H$1 = ref$6[1]; | ||
if (p1H$1 === null || p2H$1 === null) { continue; } | ||
var minSqDistH = Math.min(pointDistanceSquared(origin, p1H$1), pointDistanceSquared(origin, p2H$1)); | ||
var maxHeight = 2 * Math.sqrt(minSqDistH); | ||
for (let i = 0; i < modifOrigins.length; i++) { | ||
const origin = modifOrigins[i]; | ||
if (options.events) events.push({ | ||
type: "origin", | ||
cx: origin[0], | ||
cy: origin[1] | ||
}); | ||
const [p1W, p2W] = polygonRayCast(poly, origin, angleRad); | ||
if (p1W === null || p2W === null) continue; | ||
const minSqDistW = Math.min(pointDistanceSquared(origin, p1W), pointDistanceSquared(origin, p2W)); | ||
const maxWidth = 2 * Math.sqrt(minSqDistW); | ||
const [p1H, p2H] = polygonRayCast(poly, origin, angleRad + Math.PI / 2); | ||
if (p1H === null || p2H === null) continue; | ||
const minSqDistH = Math.min(pointDistanceSquared(origin, p1H), pointDistanceSquared(origin, p2H)); | ||
const maxHeight = 2 * Math.sqrt(minSqDistH); | ||
if (maxWidth * maxHeight < maxArea) continue; | ||
let aRatios = aspectRatios; | ||
if (maxWidth * maxHeight < maxArea) { continue; } | ||
var aRatios = aspectRatios; | ||
if (!aRatios.length) { | ||
var minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight)); | ||
var maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea); | ||
const minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight)); | ||
const maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea); | ||
aRatios = range(minAspectRatio, maxAspectRatio + aspectRatioStep, aspectRatioStep); | ||
} | ||
for (var a = 0; a < aRatios.length; a++) { | ||
for (let a = 0; a < aRatios.length; a++) { | ||
const aRatio = aRatios[a]; // do a binary search to find the max width that works | ||
var aRatio = aRatios[a]; | ||
let left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio)); | ||
let right = Math.min(maxWidth, maxHeight * aRatio); | ||
if (right * maxHeight < maxArea) continue; | ||
if (options.events && right - left >= widthStep) events.push({ | ||
type: "aRatio", | ||
aRatio | ||
}); | ||
// do a binary search to find the max width that works | ||
var left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio)); | ||
var right = Math.min(maxWidth, maxHeight * aRatio); | ||
if (right * maxHeight < maxArea) { continue; } | ||
if (options.events && right - left >= widthStep) { events.push({type: "aRatio", aRatio: aRatio}); } | ||
while (right - left >= widthStep) { | ||
var width = (left + right) / 2; | ||
var height = width / aRatio; | ||
var cx = origin[0]; | ||
var cy = origin[1]; | ||
var rectPoly = [ | ||
[cx - width / 2, cy - height / 2], | ||
[cx + width / 2, cy - height / 2], | ||
[cx + width / 2, cy + height / 2], | ||
[cx - width / 2, cy + height / 2] | ||
]; | ||
const width = (left + right) / 2; | ||
const height = width / aRatio; | ||
const [cx, cy] = origin; | ||
let rectPoly = [[cx - width / 2, cy - height / 2], [cx + width / 2, cy - height / 2], [cx + width / 2, cy + height / 2], [cx - width / 2, cy + height / 2]]; | ||
rectPoly = polygonRotate(rectPoly, angleRad, origin); | ||
var insidePoly = polygonInside(rectPoly, poly); | ||
const insidePoly = polygonInside(rectPoly, poly); | ||
if (insidePoly) { | ||
@@ -232,18 +215,30 @@ // we know that the area is already greater than the maxArea found so far | ||
rectPoly.push(rectPoly[0]); | ||
maxRect = {area: maxArea, cx: cx, cy: cy, width: width, height: height, angle: -angle, points: rectPoly}; | ||
maxRect = { | ||
area: maxArea, | ||
cx, | ||
cy, | ||
width, | ||
height, | ||
angle: -angle, | ||
points: rectPoly | ||
}; | ||
left = width; // increase the width in the binary search | ||
} | ||
else { | ||
} else { | ||
right = width; // decrease the width in the binary search | ||
} | ||
if (options.events) { events.push({type: "rectangle", areaFraction: width * height / area, cx: cx, cy: cy, width: width, height: height, angle: angle, insidePoly: insidePoly}); } | ||
if (options.events) events.push({ | ||
type: "rectangle", | ||
areaFraction: width * height / area, | ||
cx, | ||
cy, | ||
width, | ||
height, | ||
angle, | ||
insidePoly | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -255,6 +250,5 @@ | ||
return options.events ? Object.assign(maxRect || {}, {events: events}) : maxRect; | ||
} | ||
//# sourceMappingURL=largestRect.js.map | ||
return options.events ? Object.assign(maxRect || {}, { | ||
events | ||
}) : maxRect; | ||
} |
@@ -10,27 +10,17 @@ /** | ||
*/ | ||
export default function(p1, q1, p2, q2) { | ||
export default function (p1, q1, p2, q2) { | ||
// allow for some margins due to numerical errors | ||
var eps = 1e-9; | ||
const eps = 1e-9; // find the intersection point between the two infinite lines | ||
// find the intersection point between the two infinite lines | ||
var dx1 = p1[0] - q1[0], | ||
const dx1 = p1[0] - q1[0], | ||
dx2 = p2[0] - q2[0], | ||
dy1 = p1[1] - q1[1], | ||
dy2 = p2[1] - q2[1]; | ||
var denom = dx1 * dy2 - dy1 * dx2; | ||
if (Math.abs(denom) < eps) { return null; } | ||
var cross1 = p1[0] * q1[1] - p1[1] * q1[0], | ||
const denom = dx1 * dy2 - dy1 * dx2; | ||
if (Math.abs(denom) < eps) return null; | ||
const cross1 = p1[0] * q1[1] - p1[1] * q1[0], | ||
cross2 = p2[0] * q2[1] - p2[1] * q2[0]; | ||
var px = (cross1 * dx2 - cross2 * dx1) / denom, | ||
const px = (cross1 * dx2 - cross2 * dx1) / denom, | ||
py = (cross1 * dy2 - cross2 * dy1) / denom; | ||
return [px, py]; | ||
} | ||
//# sourceMappingURL=lineIntersection.js.map | ||
} |
import pointDistance from "./pointDistance"; | ||
import shapeEdgePoint from "./shapeEdgePoint"; | ||
var pi = Math.PI; | ||
const pi = Math.PI; | ||
/** | ||
@@ -13,28 +11,21 @@ @function path2polygon | ||
*/ | ||
export default function (path, segmentLength) { | ||
if ( segmentLength === void 0 ) segmentLength = 20; | ||
var poly = [], | ||
export default ((path, segmentLength = 20) => { | ||
const poly = [], | ||
regex = /([MLA])([^MLAZ]+)/ig; | ||
let match = regex.exec(path); | ||
var match = regex.exec(path); | ||
while (match !== null) { | ||
if (["M", "L"].includes(match[1])) { poly.push(match[2].split(",").map(Number)); } | ||
else if (match[1] === "A") { | ||
var points = match[2].split(",").map(Number); | ||
var last = points.slice(points.length - 2, points.length), | ||
if (["M", "L"].includes(match[1])) poly.push(match[2].split(",").map(Number));else if (match[1] === "A") { | ||
const points = match[2].split(",").map(Number); | ||
const last = points.slice(points.length - 2, points.length), | ||
prev = poly[poly.length - 1], | ||
radius = points[0], | ||
width = pointDistance(prev, last); | ||
let angle = Math.acos((radius * radius + radius * radius - width * width) / (2 * radius * radius)); | ||
if (points[2]) angle = pi * 2 - angle; | ||
const step = angle / (angle / (pi * 2) * (radius * pi * 2) / segmentLength); | ||
const start = Math.atan2(-prev[1], -prev[0]) - pi; | ||
let i = step; | ||
var angle = Math.acos((radius * radius + radius * radius - width * width) / (2 * radius * radius)); | ||
if (points[2]) { angle = pi * 2 - angle; } | ||
var step = angle / (angle / (pi * 2) * (radius * pi * 2) / segmentLength); | ||
var start = Math.atan2(-prev[1], -prev[0]) - pi; | ||
var i = step; | ||
while (i < angle) { | ||
@@ -44,13 +35,9 @@ poly.push(shapeEdgePoint(points[4] ? start + i : start - i, radius)); | ||
} | ||
poly.push(last); | ||
} | ||
match = regex.exec(path); | ||
} | ||
return poly; | ||
}; | ||
//# sourceMappingURL=path2polygon.js.map | ||
}); |
import pointDistanceSquared from "./pointDistanceSquared"; | ||
/** | ||
@@ -10,4 +9,3 @@ @function pointDistance | ||
*/ | ||
export default function (p1, p2) { return Math.sqrt(pointDistanceSquared(p1, p2)); }; | ||
//# sourceMappingURL=pointDistance.js.map | ||
export default ((p1, p2) => Math.sqrt(pointDistanceSquared(p1, p2))); |
@@ -8,11 +8,6 @@ /** | ||
*/ | ||
export default function (p1, p2) { | ||
var dx = p2[0] - p1[0], | ||
export default ((p1, p2) => { | ||
const dx = p2[0] - p1[0], | ||
dy = p2[1] - p1[1]; | ||
return dx * dx + dy * dy; | ||
}; | ||
//# sourceMappingURL=pointDistanceSquared.js.map | ||
}); |
@@ -9,18 +9,8 @@ /** | ||
*/ | ||
export default function(p, alpha, origin) { | ||
if ( origin === void 0 ) origin = [0, 0]; | ||
var cosAlpha = Math.cos(alpha), | ||
export default function (p, alpha, origin = [0, 0]) { | ||
const cosAlpha = Math.cos(alpha), | ||
sinAlpha = Math.sin(alpha), | ||
xshifted = p[0] - origin[0], | ||
yshifted = p[1] - origin[1]; | ||
return [ | ||
cosAlpha * xshifted - sinAlpha * yshifted + origin[0], | ||
sinAlpha * xshifted + cosAlpha * yshifted + origin[1] | ||
]; | ||
} | ||
//# sourceMappingURL=pointRotate.js.map | ||
return [cosAlpha * xshifted - sinAlpha * yshifted + origin[0], sinAlpha * xshifted + cosAlpha * yshifted + origin[1]]; | ||
} |
@@ -1,5 +0,3 @@ | ||
import {polygonContains} from "d3-polygon"; | ||
import { polygonContains } from "d3-polygon"; | ||
import segmentsIntersect from "./segmentsIntersect"; | ||
/** | ||
@@ -12,20 +10,19 @@ @function polygonInside | ||
*/ | ||
export default function(polyA, polyB) { | ||
var iA = -1; | ||
var nA = polyA.length; | ||
var nB = polyB.length; | ||
var bA = polyA[nA - 1]; | ||
export default function (polyA, polyB) { | ||
let iA = -1; | ||
const nA = polyA.length; | ||
const nB = polyB.length; | ||
let bA = polyA[nA - 1]; | ||
while (++iA < nA) { | ||
var aA = bA; | ||
const aA = bA; | ||
bA = polyA[iA]; | ||
let iB = -1; | ||
let bB = polyB[nB - 1]; | ||
var iB = -1; | ||
var bB = polyB[nB - 1]; | ||
while (++iB < nB) { | ||
var aB = bB; | ||
const aB = bB; | ||
bB = polyB[iB]; | ||
if (segmentsIntersect(aA, bA, aB, bB)) { return false; } | ||
if (segmentsIntersect(aA, bA, aB, bB)) return false; | ||
} | ||
@@ -35,5 +32,2 @@ } | ||
return polygonContains(polyB, polyA[0]); | ||
} | ||
//# sourceMappingURL=polygonInside.js.map | ||
} |
import lineIntersection from "./lineIntersection"; | ||
import segmentBoxContains from "./segmentBoxContains"; | ||
import pointDistanceSquared from "./pointDistanceSquared"; | ||
/** | ||
@@ -13,27 +12,26 @@ @function polygonRayCast | ||
*/ | ||
export default function(poly, origin, alpha) { | ||
if ( alpha === void 0 ) alpha = 0; | ||
var eps = 1e-9; | ||
export default function (poly, origin, alpha = 0) { | ||
const eps = 1e-9; | ||
origin = [origin[0] + eps * Math.cos(alpha), origin[1] + eps * Math.sin(alpha)]; | ||
var x0 = origin[0]; | ||
var y0 = origin[1]; | ||
var shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)]; | ||
const [x0, y0] = origin; | ||
const shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)]; | ||
let idx = 0; | ||
if (Math.abs(shiftedOrigin[0] - x0) < eps) idx = 1; | ||
let i = -1; | ||
const n = poly.length; | ||
let b = poly[n - 1]; | ||
let minSqDistLeft = Number.MAX_VALUE; | ||
let minSqDistRight = Number.MAX_VALUE; | ||
let closestPointLeft = null; | ||
let closestPointRight = null; | ||
var idx = 0; | ||
if (Math.abs(shiftedOrigin[0] - x0) < eps) { idx = 1; } | ||
var i = -1; | ||
var n = poly.length; | ||
var b = poly[n - 1]; | ||
var minSqDistLeft = Number.MAX_VALUE; | ||
var minSqDistRight = Number.MAX_VALUE; | ||
var closestPointLeft = null; | ||
var closestPointRight = null; | ||
while (++i < n) { | ||
var a = b; | ||
const a = b; | ||
b = poly[i]; | ||
var p = lineIntersection(origin, shiftedOrigin, a, b); | ||
const p = lineIntersection(origin, shiftedOrigin, a, b); | ||
if (p && segmentBoxContains(a, b, p)) { | ||
var sqDist = pointDistanceSquared(origin, p); | ||
const sqDist = pointDistanceSquared(origin, p); | ||
if (p[idx] < origin[idx]) { | ||
@@ -44,4 +42,3 @@ if (sqDist < minSqDistLeft) { | ||
} | ||
} | ||
else if (p[idx] > origin[idx]) { | ||
} else if (p[idx] > origin[idx]) { | ||
if (sqDist < minSqDistRight) { | ||
@@ -56,5 +53,2 @@ minSqDistRight = sqDist; | ||
return [closestPointLeft, closestPointRight]; | ||
} | ||
//# sourceMappingURL=polygonRayCast.js.map | ||
} |
import pointRotate from "./pointRotate"; | ||
/** | ||
@@ -11,8 +10,3 @@ @function polygonRotate | ||
*/ | ||
export default function (poly, alpha, origin) { | ||
if ( origin === void 0 ) origin = [0, 0]; | ||
return poly.map(function (p) { return pointRotate(p, alpha, origin); }); | ||
}; | ||
//# sourceMappingURL=polygonRotate.js.map | ||
export default ((poly, alpha, origin = [0, 0]) => poly.map(p => pointRotate(p, alpha, origin))); |
@@ -9,13 +9,6 @@ /** | ||
*/ | ||
export default function(s1, s2, p) { | ||
var eps = 1e-9; | ||
var px = p[0]; | ||
var py = p[1]; | ||
return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps || | ||
py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps); | ||
} | ||
//# sourceMappingURL=segmentBoxContains.js.map | ||
export default function (s1, s2, p) { | ||
const eps = 1e-9, | ||
[px, py] = p; | ||
return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps || py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps); | ||
} |
import lineIntersection from "./lineIntersection"; | ||
import segmentBoxContains from "./segmentBoxContains"; | ||
/** | ||
@@ -13,10 +12,7 @@ @function segmentsIntersect | ||
*/ | ||
export default function(p1, q1, p2, q2) { | ||
var p = lineIntersection(p1, q1, p2, q2); | ||
if (!p) { return false; } | ||
export default function (p1, q1, p2, q2) { | ||
const p = lineIntersection(p1, q1, p2, q2); | ||
if (!p) return false; | ||
return segmentBoxContains(p1, q1, p) && segmentBoxContains(p2, q2, p); | ||
} | ||
//# sourceMappingURL=segmentsIntersect.js.map | ||
} |
@@ -1,3 +0,2 @@ | ||
var pi = Math.PI; | ||
const pi = Math.PI; | ||
/** | ||
@@ -10,36 +9,29 @@ @function shapeEdgePoint | ||
*/ | ||
export default function (angle, distance, shape) { | ||
if ( shape === void 0 ) shape = "circle"; | ||
export default ((angle, distance, shape = "circle") => { | ||
if (angle < 0) angle = pi * 2 + angle; | ||
if (angle < 0) { angle = pi * 2 + angle; } | ||
if (shape === "square") { | ||
const diagonal = 45 * (pi / 180); | ||
let x = 0, | ||
y = 0; | ||
var diagonal = 45 * (pi / 180); | ||
var x = 0, y = 0; | ||
if (angle < pi / 2) { | ||
var tan = Math.tan(angle); | ||
const tan = Math.tan(angle); | ||
x += angle < diagonal ? distance : distance / tan; | ||
y += angle < diagonal ? tan * distance : distance; | ||
} | ||
else if (angle <= pi) { | ||
var tan$1 = Math.tan(pi - angle); | ||
x -= angle < pi - diagonal ? distance / tan$1 : distance; | ||
y += angle < pi - diagonal ? distance : tan$1 * distance; | ||
} | ||
else if (angle < diagonal + pi) { | ||
} else if (angle <= pi) { | ||
const tan = Math.tan(pi - angle); | ||
x -= angle < pi - diagonal ? distance / tan : distance; | ||
y += angle < pi - diagonal ? distance : tan * distance; | ||
} else if (angle < diagonal + pi) { | ||
x -= distance; | ||
y -= Math.tan(angle - pi) * distance; | ||
} | ||
else if (angle < 3 * pi / 2) { | ||
} else if (angle < 3 * pi / 2) { | ||
x -= distance / Math.tan(angle - pi); | ||
y -= distance; | ||
} | ||
else if (angle < 2 * pi - diagonal) { | ||
} else if (angle < 2 * pi - diagonal) { | ||
x += distance / Math.tan(2 * pi - angle); | ||
y -= distance; | ||
} | ||
else { | ||
} else { | ||
x += distance; | ||
@@ -50,11 +42,5 @@ y -= Math.tan(2 * pi - angle) * distance; | ||
return [x, y]; | ||
} | ||
else if (shape === "circle") { | ||
} else if (shape === "circle") { | ||
return [distance * Math.cos(angle), distance * Math.sin(angle)]; | ||
} | ||
else { return null; } | ||
}; | ||
//# sourceMappingURL=shapeEdgePoint.js.map | ||
} else return null; | ||
}); |
import pointDistanceSquared from "./pointDistanceSquared"; | ||
/** | ||
@@ -10,24 +9,19 @@ @desc square distance from a point to a segment | ||
*/ | ||
function getSqSegDist(p, p1, p2) { | ||
var x = p1[0], | ||
let x = p1[0], | ||
y = p1[1]; | ||
var dx = p2[0] - x, | ||
let dx = p2[0] - x, | ||
dy = p2[1] - y; | ||
if (dx !== 0 || dy !== 0) { | ||
const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy); | ||
var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy); | ||
if (t > 1) { | ||
x = p2[0]; | ||
y = p2[1]; | ||
} | ||
else if (t > 0) { | ||
} else if (t > 0) { | ||
x += dx * t; | ||
y += dy * t; | ||
} | ||
} | ||
@@ -37,7 +31,4 @@ | ||
dy = p[1] - y; | ||
return dx * dx + dy * dy; | ||
} | ||
/** | ||
@@ -49,10 +40,10 @@ @desc basic distance-based simplification | ||
*/ | ||
function simplifyRadialDist(poly, sqTolerance) { | ||
var point, | ||
let point, | ||
prevPoint = poly[0]; | ||
const newPoints = [prevPoint]; | ||
var newPoints = [prevPoint]; | ||
for (var i = 1, len = poly.length; i < len; i++) { | ||
for (let i = 1, len = poly.length; i < len; i++) { | ||
point = poly[i]; | ||
@@ -66,7 +57,5 @@ | ||
if (prevPoint !== point) { newPoints.push(point); } | ||
if (prevPoint !== point) newPoints.push(point); | ||
return newPoints; | ||
} | ||
/** | ||
@@ -80,9 +69,11 @@ @param {Array} polygon | ||
*/ | ||
function simplifyDPStep(poly, first, last, sqTolerance, simplified) { | ||
let index, | ||
maxSqDist = sqTolerance; | ||
var index, maxSqDist = sqTolerance; | ||
for (let i = first + 1; i < last; i++) { | ||
const sqDist = getSqSegDist(poly[i], poly[first], poly[last]); | ||
for (var i = first + 1; i < last; i++) { | ||
var sqDist = getSqSegDist(poly[i], poly[first], poly[last]); | ||
if (sqDist > maxSqDist) { | ||
@@ -95,8 +86,7 @@ index = i; | ||
if (maxSqDist > sqTolerance) { | ||
if (index - first > 1) { simplifyDPStep(poly, first, index, sqTolerance, simplified); } | ||
if (index - first > 1) simplifyDPStep(poly, first, index, sqTolerance, simplified); | ||
simplified.push(poly[index]); | ||
if (last - index > 1) { simplifyDPStep(poly, index, last, sqTolerance, simplified); } | ||
if (last - index > 1) simplifyDPStep(poly, index, last, sqTolerance, simplified); | ||
} | ||
} | ||
/** | ||
@@ -108,12 +98,11 @@ @desc simplification using Ramer-Douglas-Peucker algorithm | ||
*/ | ||
function simplifyDouglasPeucker(poly, sqTolerance) { | ||
var last = poly.length - 1; | ||
var simplified = [poly[0]]; | ||
const last = poly.length - 1; | ||
const simplified = [poly[0]]; | ||
simplifyDPStep(poly, 0, last, sqTolerance, simplified); | ||
simplified.push(poly[last]); | ||
return simplified; | ||
} | ||
/** | ||
@@ -128,18 +117,10 @@ @function largestRect | ||
*/ | ||
export default function (poly, tolerance, highestQuality) { | ||
if ( tolerance === void 0 ) tolerance = 1; | ||
if ( highestQuality === void 0 ) highestQuality = false; | ||
if (poly.length <= 2) { return poly; } | ||
var sqTolerance = tolerance * tolerance; | ||
export default ((poly, tolerance = 1, highestQuality = false) => { | ||
if (poly.length <= 2) return poly; | ||
const sqTolerance = tolerance * tolerance; | ||
poly = highestQuality ? poly : simplifyRadialDist(poly, sqTolerance); | ||
poly = simplifyDouglasPeucker(poly, sqTolerance); | ||
return poly; | ||
}; | ||
//# sourceMappingURL=simplify.js.map | ||
}); |
@@ -1,6 +0,4 @@ | ||
import {select} from "d3-selection"; | ||
import {transition} from "d3-transition"; | ||
import {accessor, constant} from "d3plus-common"; | ||
import { select } from "d3-selection"; | ||
import { transition } from "d3-transition"; | ||
import { accessor, constant } from "d3plus-common"; | ||
/** | ||
@@ -20,61 +18,53 @@ @class Image | ||
*/ | ||
var Image = function Image() { | ||
this._duration = 600; | ||
this._height = accessor("height"); | ||
this._id = accessor("id"); | ||
this._pointerEvents = constant("auto"); | ||
this._select; | ||
this._url = accessor("url"); | ||
this._width = accessor("width"); | ||
this._x = accessor("x", 0); | ||
this._y = accessor("y", 0); | ||
}; | ||
/** | ||
@memberof Image | ||
@desc Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing. | ||
@param {Function} [*callback*] | ||
@chainable | ||
*/ | ||
Image.prototype.render = function render (callback) { | ||
var this$1 = this; | ||
export default class Image { | ||
/** | ||
@memberof Image | ||
@desc Invoked when creating a new class instance, and sets any default parameters. | ||
@private | ||
*/ | ||
constructor() { | ||
this._duration = 600; | ||
this._height = accessor("height"); | ||
this._id = accessor("id"); | ||
this._pointerEvents = constant("auto"); | ||
this._select; | ||
this._url = accessor("url"); | ||
this._width = accessor("width"); | ||
this._x = accessor("x", 0); | ||
this._y = accessor("y", 0); | ||
} | ||
/** | ||
@memberof Image | ||
@desc Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing. | ||
@param {Function} [*callback*] | ||
@chainable | ||
*/ | ||
if (this._select === void 0) { this.select(select("body").append("svg").style("width", ((window.innerWidth) + "px")).style("height", ((window.innerHeight) + "px")).style("display", "block").node()); } | ||
render(callback) { | ||
if (this._select === void 0) this.select(select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node()); | ||
var images = this._select.selectAll(".d3plus-Image").data(this._data, this._id); | ||
const images = this._select.selectAll(".d3plus-Image").data(this._data, this._id); | ||
var enter = images.enter().append("image") | ||
.attr("class", "d3plus-Image") | ||
.attr("opacity", 0) | ||
.attr("width", 0) | ||
.attr("height", 0) | ||
.attr("x", function (d, i) { return this$1._x(d, i) + this$1._width(d, i) / 2; }) | ||
.attr("y", function (d, i) { return this$1._y(d, i) + this$1._height(d, i) / 2; }); | ||
const enter = images.enter().append("image").attr("class", "d3plus-Image").attr("opacity", 0).attr("width", 0).attr("height", 0).attr("x", (d, i) => this._x(d, i) + this._width(d, i) / 2).attr("y", (d, i) => this._y(d, i) + this._height(d, i) / 2); | ||
const t = transition().duration(this._duration), | ||
that = this, | ||
update = enter.merge(images); | ||
update.attr("xlink:href", this._url).style("pointer-events", this._pointerEvents).transition(t).attr("opacity", 1).attr("width", (d, i) => this._width(d, i)).attr("height", (d, i) => this._height(d, i)).attr("x", (d, i) => this._x(d, i)).attr("y", (d, i) => this._y(d, i)).each(function (d, i) { | ||
const image = select(this), | ||
link = that._url(d, i); | ||
var t = transition().duration(this._duration), | ||
that = this, | ||
update = enter.merge(images); | ||
const fullAddress = link.indexOf("http://") === 0 || link.indexOf("https://") === 0; | ||
update | ||
.attr("xlink:href", this._url) | ||
.style("pointer-events", this._pointerEvents) | ||
.transition(t) | ||
.attr("opacity", 1) | ||
.attr("width", function (d, i) { return this$1._width(d, i); }) | ||
.attr("height", function (d, i) { return this$1._height(d, i); }) | ||
.attr("x", function (d, i) { return this$1._x(d, i); }) | ||
.attr("y", function (d, i) { return this$1._y(d, i); }) | ||
.each(function(d, i) { | ||
var image = select(this), link = that._url(d, i); | ||
var fullAddress = link.indexOf("http://") === 0 || link.indexOf("https://") === 0; | ||
if (!fullAddress || link.indexOf(window.location.hostname) === 0) { | ||
var img = new Image(); | ||
const img = new Image(); | ||
img.src = link; | ||
img.crossOrigin = "Anonymous"; | ||
img.onload = function() { | ||
var canvas = document.createElement("canvas"); | ||
img.onload = function () { | ||
const canvas = document.createElement("canvas"); | ||
canvas.width = this.width; | ||
canvas.height = this.height; | ||
var context = canvas.getContext("2d"); | ||
const context = canvas.getContext("2d"); | ||
context.drawImage(this, 0, 0); | ||
@@ -85,142 +75,141 @@ image.attr("xlink:href", canvas.toDataURL("image/png")); | ||
}); | ||
images.exit().transition(t).attr("width", (d, i) => this._width(d, i)).attr("height", (d, i) => this._height(d, i)).attr("x", (d, i) => this._x(d, i)).attr("y", (d, i) => this._y(d, i)).attr("opacity", 0).remove(); | ||
if (callback) setTimeout(callback, this._duration + 100); | ||
return this; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *data* is specified, sets the data array to the specified array and returns the current class instance. If *data* is not specified, returns the current data array. An <image> tag will be drawn for each object in the array. | ||
@param {Array} [*data* = []] | ||
@chainable | ||
*/ | ||
images.exit().transition(t) | ||
.attr("width", function (d, i) { return this$1._width(d, i); }) | ||
.attr("height", function (d, i) { return this$1._height(d, i); }) | ||
.attr("x", function (d, i) { return this$1._x(d, i); }) | ||
.attr("y", function (d, i) { return this$1._y(d, i); }) | ||
.attr("opacity", 0).remove(); | ||
if (callback) { setTimeout(callback, this._duration + 100); } | ||
data(_) { | ||
return arguments.length ? (this._data = _, this) : this._data; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *ms* is specified, sets the animation duration to the specified number and returns the current class instance. If *ms* is not specified, returns the current animation duration. | ||
@param {Number} [*ms* = 600] | ||
@chainable | ||
*/ | ||
return this; | ||
}; | ||
duration(_) { | ||
return arguments.length ? (this._duration = _, this) : this._duration; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the height accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.height; | ||
} | ||
*/ | ||
/** | ||
@memberof Image | ||
@desc If *data* is specified, sets the data array to the specified array and returns the current class instance. If *data* is not specified, returns the current data array. An <image> tag will be drawn for each object in the array. | ||
@param {Array} [*data* = []] | ||
@chainable | ||
*/ | ||
Image.prototype.data = function data (_) { | ||
return arguments.length ? (this._data = _, this) : this._data; | ||
}; | ||
/** | ||
@memberof Image | ||
@desc If *ms* is specified, sets the animation duration to the specified number and returns the current class instance. If *ms* is not specified, returns the current animation duration. | ||
@param {Number} [*ms* = 600] | ||
@chainable | ||
*/ | ||
Image.prototype.duration = function duration (_) { | ||
return arguments.length ? (this._duration = _, this) : this._duration; | ||
}; | ||
height(_) { | ||
return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the id accessor to the specified function and returns the current class instance. | ||
@param {Function} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.id; | ||
} | ||
*/ | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the height accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.height; | ||
} | ||
*/ | ||
Image.prototype.height = function height (_) { | ||
return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height; | ||
}; | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the id accessor to the specified function and returns the current class instance. | ||
@param {Function} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.id; | ||
} | ||
*/ | ||
Image.prototype.id = function id (_) { | ||
return arguments.length ? (this._id = _, this) : this._id; | ||
}; | ||
id(_) { | ||
return arguments.length ? (this._id = _, this) : this._id; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the pointer-events accessor to the specified function or string and returns the current class instance. | ||
@param {Function|String} [*value* = "auto"] | ||
@chainable | ||
*/ | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the pointer-events accessor to the specified function or string and returns the current class instance. | ||
@param {Function|String} [*value* = "auto"] | ||
@chainable | ||
*/ | ||
Image.prototype.pointerEvents = function pointerEvents (_) { | ||
return arguments.length ? (this._pointerEvents = typeof _ === "function" ? _ : constant(_), this) : this._pointerEvents; | ||
}; | ||
/** | ||
@memberof Image | ||
@desc If *selector* is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If *selector* is not specified, returns the current SVG container element. | ||
@param {String|HTMLElement} [*selector* = d3.select("body").append("svg")] | ||
@chainable | ||
*/ | ||
Image.prototype.select = function select$1 (_) { | ||
return arguments.length ? (this._select = select(_), this) : this._select; | ||
}; | ||
pointerEvents(_) { | ||
return arguments.length ? (this._pointerEvents = typeof _ === "function" ? _ : constant(_), this) : this._pointerEvents; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *selector* is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If *selector* is not specified, returns the current SVG container element. | ||
@param {String|HTMLElement} [*selector* = d3.select("body").append("svg")] | ||
@chainable | ||
*/ | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the URL accessor to the specified function and returns the current class instance. | ||
@param {Function} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.url; | ||
} | ||
*/ | ||
Image.prototype.url = function url (_) { | ||
return arguments.length ? (this._url = _, this) : this._url; | ||
}; | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the width accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.width; | ||
} | ||
*/ | ||
Image.prototype.width = function width (_) { | ||
return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width; | ||
}; | ||
select(_) { | ||
return arguments.length ? (this._select = select(_), this) : this._select; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the URL accessor to the specified function and returns the current class instance. | ||
@param {Function} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.url; | ||
} | ||
*/ | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the x accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.x || 0; | ||
} | ||
*/ | ||
Image.prototype.x = function x (_) { | ||
return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x; | ||
}; | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the y accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.y || 0; | ||
} | ||
*/ | ||
Image.prototype.y = function y (_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
}; | ||
url(_) { | ||
return arguments.length ? (this._url = _, this) : this._url; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the width accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.width; | ||
} | ||
*/ | ||
export default Image; | ||
//# sourceMappingURL=Image.js.map | ||
width(_) { | ||
return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the x accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.x || 0; | ||
} | ||
*/ | ||
x(_) { | ||
return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x; | ||
} | ||
/** | ||
@memberof Image | ||
@desc If *value* is specified, sets the y accessor to the specified function or number and returns the current class instance. | ||
@param {Function|Number} [*value*] | ||
@chainable | ||
@example | ||
function(d) { | ||
return d.y || 0; | ||
} | ||
*/ | ||
y(_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
} | ||
} |
@@ -1,12 +0,9 @@ | ||
import {extent} from "d3-array"; | ||
import {nest} from "d3-collection"; | ||
import {interpolatePath} from "d3-interpolate-path"; | ||
import {select} from "d3-selection"; | ||
import { extent } from "d3-array"; | ||
import { nest } from "d3-collection"; | ||
import { interpolatePath } from "d3-interpolate-path"; | ||
import { select } from "d3-selection"; | ||
import * as paths from "d3-shape"; | ||
import {accessor, constant, merge} from "d3plus-common"; | ||
import { accessor, constant, merge } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
import largestRect from "../geom/largestRect"; | ||
/** | ||
@@ -17,16 +14,27 @@ @class Area | ||
*/ | ||
var Area = /*@__PURE__*/(function (Shape) { | ||
function Area() { | ||
var this$1 = this; | ||
export default class Area extends Shape { | ||
/** | ||
@memberof Area | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super(); | ||
this._curve = "linear"; | ||
Shape.call(this); | ||
this._defined = () => true; | ||
this._curve = "linear"; | ||
this._defined = function () { return true; }; | ||
this._labelBounds = function (d, i, aes) { | ||
var r = largestRect(aes.points); | ||
if (!r) { return null; } | ||
return {angle: r.angle, width: r.width, height: r.height, x: r.cx - r.width / 2 - this$1._x(d, i), y: r.cy - r.height / 2 - this$1._y(d, i)}; | ||
this._labelBounds = (d, i, aes) => { | ||
const r = largestRect(aes.points); | ||
if (!r) return null; | ||
return { | ||
angle: r.angle, | ||
width: r.width, | ||
height: r.height, | ||
x: r.cx - r.width / 2 - this._x(d, i), | ||
y: r.cy - r.height / 2 - this._y(d, i) | ||
}; | ||
}; | ||
this._labelConfig = Object.assign(this._labelConfig, { | ||
@@ -43,9 +51,3 @@ textAnchor: "middle", | ||
this._y1 = accessor("y"); | ||
} | ||
if ( Shape ) Area.__proto__ = Shape; | ||
Area.prototype = Object.create( Shape && Shape.prototype ); | ||
Area.prototype.constructor = Area; | ||
/** | ||
@@ -58,14 +60,15 @@ @memberof Area | ||
*/ | ||
Area.prototype._aes = function _aes (d) { | ||
var this$1 = this; | ||
var values = d.values.slice().sort(function (a, b) { return this$1._y1 ? this$1._x(a) - this$1._x(b) : this$1._y(a) - this$1._y(b); }); | ||
var points1 = values.map(function (v, z) { return [this$1._x0(v, z), this$1._y0(v, z)]; }); | ||
var points2 = values.reverse().map(function (v, z) { return this$1._y1 ? [this$1._x(v, z), this$1._y1(v, z)] : [this$1._x1(v, z), this$1._y(v, z)]; }); | ||
var points = points1.concat(points2); | ||
if (points1[0][1] > points2[0][1]) { points = points.reverse(); } | ||
_aes(d) { | ||
const values = d.values.slice().sort((a, b) => this._y1 ? this._x(a) - this._x(b) : this._y(a) - this._y(b)); | ||
const points1 = values.map((v, z) => [this._x0(v, z), this._y0(v, z)]); | ||
const points2 = values.reverse().map((v, z) => this._y1 ? [this._x(v, z), this._y1(v, z)] : [this._x1(v, z), this._y(v, z)]); | ||
let points = points1.concat(points2); | ||
if (points1[0][1] > points2[0][1]) points = points.reverse(); | ||
points.push(points[0]); | ||
return {points: points}; | ||
}; | ||
return { | ||
points | ||
}; | ||
} | ||
/** | ||
@@ -77,39 +80,26 @@ @memberof Area | ||
*/ | ||
Area.prototype._dataFilter = function _dataFilter (data) { | ||
var this$1 = this; | ||
var areas = nest().key(this._id).entries(data).map(function (d) { | ||
_dataFilter(data) { | ||
const areas = nest().key(this._id).entries(data).map(d => { | ||
d.data = merge(d.values); | ||
d.i = data.indexOf(d.values[0]); | ||
var x = extent(d.values.map(this$1._x) | ||
.concat(d.values.map(this$1._x0)) | ||
.concat(this$1._x1 ? d.values.map(this$1._x1) : []) | ||
); | ||
const x = extent(d.values.map(this._x).concat(d.values.map(this._x0)).concat(this._x1 ? d.values.map(this._x1) : [])); | ||
d.xR = x; | ||
d.width = x[1] - x[0]; | ||
d.x = x[0] + d.width / 2; | ||
var y = extent(d.values.map(this$1._y) | ||
.concat(d.values.map(this$1._y0)) | ||
.concat(this$1._y1 ? d.values.map(this$1._y1) : []) | ||
); | ||
const y = extent(d.values.map(this._y).concat(d.values.map(this._y0)).concat(this._y1 ? d.values.map(this._y1) : [])); | ||
d.yR = y; | ||
d.height = y[1] - y[0]; | ||
d.y = y[0] + d.height / 2; | ||
d.nested = true; | ||
d.translate = [d.x, d.y]; | ||
d.__d3plusShape__ = true; | ||
return d; | ||
}); | ||
areas.key = function (d) { return d.key; }; | ||
areas.key = d => d.key; | ||
return areas; | ||
}; | ||
} | ||
/** | ||
@@ -121,39 +111,21 @@ @memberof Area | ||
*/ | ||
Area.prototype.render = function render (callback) { | ||
Shape.prototype.render.call(this, callback); | ||
var path = this._path = paths.area() | ||
.defined(this._defined) | ||
.curve(paths[("curve" + (this._curve.charAt(0).toUpperCase()) + (this._curve.slice(1)))]) | ||
.x(this._x).x0(this._x0).x1(this._x1) | ||
.y(this._y).y0(this._y0).y1(this._y1); | ||
render(callback) { | ||
super.render(callback); | ||
const path = this._path = paths.area().defined(this._defined).curve(paths[`curve${this._curve.charAt(0).toUpperCase()}${this._curve.slice(1)}`]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1); | ||
const exitPath = paths.area().defined(d => d).curve(paths[`curve${this._curve.charAt(0).toUpperCase()}${this._curve.slice(1)}`]).x(this._x).x0(this._x0).x1(this._x1).y(this._y).y0(this._y0).y1(this._y1); | ||
var exitPath = paths.area() | ||
.defined(function (d) { return d; }) | ||
.curve(paths[("curve" + (this._curve.charAt(0).toUpperCase()) + (this._curve.slice(1)))]) | ||
.x(this._x).x0(this._x0).x1(this._x1) | ||
.y(this._y).y0(this._y0).y1(this._y1); | ||
this._enter.append("path").attr("transform", d => `translate(${-d.xR[0] - d.width / 2}, ${-d.yR[0] - d.height / 2})`).attr("d", d => path(d.values)).call(this._applyStyle.bind(this)); | ||
this._enter.append("path") | ||
.attr("transform", function (d) { return ("translate(" + (-d.xR[0] - d.width / 2) + ", " + (-d.yR[0] - d.height / 2) + ")"); }) | ||
.attr("d", function (d) { return path(d.values); }) | ||
.call(this._applyStyle.bind(this)); | ||
this._update.select("path").transition(this._transition).attr("transform", d => `translate(${-d.xR[0] - d.width / 2}, ${-d.yR[0] - d.height / 2})`).attrTween("d", function (d) { | ||
return interpolatePath(select(this).attr("d"), path(d.values)); | ||
}).call(this._applyStyle.bind(this)); | ||
this._update.select("path").transition(this._transition) | ||
.attr("transform", function (d) { return ("translate(" + (-d.xR[0] - d.width / 2) + ", " + (-d.yR[0] - d.height / 2) + ")"); }) | ||
.attrTween("d", function(d) { | ||
return interpolatePath(select(this).attr("d"), path(d.values)); | ||
}) | ||
.call(this._applyStyle.bind(this)); | ||
this._exit.select("path").transition(this._transition).attrTween("d", function (d) { | ||
return interpolatePath(select(this).attr("d"), exitPath(d.values)); | ||
}); | ||
this._exit.select("path").transition(this._transition) | ||
.attrTween("d", function(d) { | ||
return interpolatePath(select(this).attr("d"), exitPath(d.values)); | ||
}); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -165,6 +137,7 @@ @memberof Area | ||
*/ | ||
Area.prototype.curve = function curve (_) { | ||
curve(_) { | ||
return arguments.length ? (this._curve = _, this) : this._curve; | ||
}; | ||
} | ||
/** | ||
@@ -176,6 +149,7 @@ @memberof Area | ||
*/ | ||
Area.prototype.defined = function defined (_) { | ||
defined(_) { | ||
return arguments.length ? (this._defined = _, this) : this._defined; | ||
}; | ||
} | ||
/** | ||
@@ -187,9 +161,10 @@ @memberof Area | ||
*/ | ||
Area.prototype.x = function x (_) { | ||
if (!arguments.length) { return this._x; } | ||
x(_) { | ||
if (!arguments.length) return this._x; | ||
this._x = typeof _ === "function" ? _ : constant(_); | ||
this._x0 = this._x; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -201,9 +176,10 @@ @memberof Area | ||
*/ | ||
Area.prototype.x0 = function x0 (_) { | ||
if (!arguments.length) { return this._x0; } | ||
x0(_) { | ||
if (!arguments.length) return this._x0; | ||
this._x0 = typeof _ === "function" ? _ : constant(_); | ||
this._x = this._x0; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -215,6 +191,7 @@ @memberof Area | ||
*/ | ||
Area.prototype.x1 = function x1 (_) { | ||
x1(_) { | ||
return arguments.length ? (this._x1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._x1; | ||
}; | ||
} | ||
/** | ||
@@ -226,9 +203,10 @@ @memberof Area | ||
*/ | ||
Area.prototype.y = function y (_) { | ||
if (!arguments.length) { return this._y; } | ||
y(_) { | ||
if (!arguments.length) return this._y; | ||
this._y = typeof _ === "function" ? _ : constant(_); | ||
this._y0 = this._y; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -240,9 +218,10 @@ @memberof Area | ||
*/ | ||
Area.prototype.y0 = function y0 (_) { | ||
if (!arguments.length) { return this._y0; } | ||
y0(_) { | ||
if (!arguments.length) return this._y0; | ||
this._y0 = typeof _ === "function" ? _ : constant(_); | ||
this._y = this._y0; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -254,11 +233,8 @@ @memberof Area | ||
*/ | ||
Area.prototype.y1 = function y1 (_) { | ||
return arguments.length ? (this._y1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._y1; | ||
}; | ||
return Area; | ||
}(Shape)); | ||
export default Area; | ||
y1(_) { | ||
return arguments.length ? (this._y1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._y1; | ||
} | ||
//# sourceMappingURL=Area.js.map | ||
} |
@@ -1,5 +0,3 @@ | ||
import {accessor, constant} from "d3plus-common"; | ||
import { accessor, constant } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
/** | ||
@@ -10,17 +8,21 @@ @class Bar | ||
*/ | ||
var Bar = /*@__PURE__*/(function (Shape) { | ||
function Bar() { | ||
var this$1 = this; | ||
Shape.call(this, "rect"); | ||
export default class Bar extends Shape { | ||
/** | ||
@memberof Bar | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super("rect"); | ||
this._name = "Bar"; | ||
this._height = constant(10); | ||
this._labelBounds = function (d, i, s) { return ({ | ||
this._labelBounds = (d, i, s) => ({ | ||
width: s.width, | ||
height: s.height, | ||
x: this$1._x1 !== null ? this$1._getX(d, i) : -s.width / 2, | ||
y: this$1._x1 === null ? this$1._getY(d, i) : -s.height / 2 | ||
}); }; | ||
x: this._x1 !== null ? this._getX(d, i) : -s.width / 2, | ||
y: this._x1 === null ? this._getY(d, i) : -s.height / 2 | ||
}); | ||
this._width = constant(10); | ||
@@ -33,9 +35,3 @@ this._x = accessor("x"); | ||
this._y1 = accessor("y"); | ||
} | ||
if ( Shape ) Bar.__proto__ = Shape; | ||
Bar.prototype = Object.create( Shape && Shape.prototype ); | ||
Bar.prototype.constructor = Bar; | ||
/** | ||
@@ -47,31 +43,15 @@ @memberof Bar | ||
*/ | ||
Bar.prototype.render = function render (callback) { | ||
var this$1 = this; | ||
Shape.prototype.render.call(this, callback); | ||
render(callback) { | ||
super.render(callback); | ||
this._enter | ||
.attr("width", function (d, i) { return this$1._x1 === null ? this$1._getWidth(d, i) : 0; }) | ||
.attr("height", function (d, i) { return this$1._x1 !== null ? this$1._getHeight(d, i) : 0; }) | ||
.attr("x", function (d, i) { return this$1._x1 === null ? -this$1._getWidth(d, i) / 2 : 0; }) | ||
.attr("y", function (d, i) { return this$1._x1 !== null ? -this$1._getHeight(d, i) / 2 : 0; }) | ||
.call(this._applyStyle.bind(this)) | ||
.transition(this._transition) | ||
.call(this._applyPosition.bind(this)); | ||
this._enter.attr("width", (d, i) => this._x1 === null ? this._getWidth(d, i) : 0).attr("height", (d, i) => this._x1 !== null ? this._getHeight(d, i) : 0).attr("x", (d, i) => this._x1 === null ? -this._getWidth(d, i) / 2 : 0).attr("y", (d, i) => this._x1 !== null ? -this._getHeight(d, i) / 2 : 0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this)); | ||
this._update.transition(this._transition) | ||
.call(this._applyStyle.bind(this)) | ||
.call(this._applyPosition.bind(this)); | ||
this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this)); | ||
this._exit.transition(this._transition) | ||
.attr("width", function (d, i) { return this$1._x1 === null ? this$1._getWidth(d, i) : 0; }) | ||
.attr("height", function (d, i) { return this$1._x1 !== null ? this$1._getHeight(d, i) : 0; }) | ||
.attr("x", function (d, i) { return this$1._x1 === null ? -this$1._getWidth(d, i) / 2 : 0; }) | ||
.attr("y", function (d, i) { return this$1._x1 !== null ? -this$1._getHeight(d, i) / 2 : 0; }); | ||
this._exit.transition(this._transition).attr("width", (d, i) => this._x1 === null ? this._getWidth(d, i) : 0).attr("height", (d, i) => this._x1 !== null ? this._getHeight(d, i) : 0).attr("x", (d, i) => this._x1 === null ? -this._getWidth(d, i) / 2 : 0).attr("y", (d, i) => this._x1 !== null ? -this._getHeight(d, i) / 2 : 0); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -84,6 +64,10 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._aes = function _aes (d, i) { | ||
return {height: this._getHeight(d, i), width: this._getWidth(d, i)}; | ||
}; | ||
_aes(d, i) { | ||
return { | ||
height: this._getHeight(d, i), | ||
width: this._getWidth(d, i) | ||
}; | ||
} | ||
/** | ||
@@ -95,12 +79,7 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._applyPosition = function _applyPosition (elem) { | ||
var this$1 = this; | ||
elem | ||
.attr("width", function (d, i) { return this$1._getWidth(d, i); }) | ||
.attr("height", function (d, i) { return this$1._getHeight(d, i); }) | ||
.attr("x", function (d, i) { return this$1._x1 !== null ? this$1._getX(d, i) : -this$1._getWidth(d, i) / 2; }) | ||
.attr("y", function (d, i) { return this$1._x1 === null ? this$1._getY(d, i) : -this$1._getHeight(d, i) / 2; }); | ||
}; | ||
_applyPosition(elem) { | ||
elem.attr("width", (d, i) => this._getWidth(d, i)).attr("height", (d, i) => this._getHeight(d, i)).attr("x", (d, i) => this._x1 !== null ? this._getX(d, i) : -this._getWidth(d, i) / 2).attr("y", (d, i) => this._x1 === null ? this._getY(d, i) : -this._getHeight(d, i) / 2); | ||
} | ||
/** | ||
@@ -113,7 +92,8 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._getHeight = function _getHeight (d, i) { | ||
if (this._x1 !== null) { return this._height(d, i); } | ||
_getHeight(d, i) { | ||
if (this._x1 !== null) return this._height(d, i); | ||
return Math.abs(this._y1(d, i) - this._y(d, i)); | ||
}; | ||
} | ||
/** | ||
@@ -126,7 +106,8 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._getWidth = function _getWidth (d, i) { | ||
if (this._x1 === null) { return this._width(d, i); } | ||
_getWidth(d, i) { | ||
if (this._x1 === null) return this._width(d, i); | ||
return Math.abs(this._x1(d, i) - this._x(d, i)); | ||
}; | ||
} | ||
/** | ||
@@ -139,8 +120,8 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._getX = function _getX (d, i) { | ||
var w = this._x1 === null ? this._x(d, i) : this._x1(d, i) - this._x(d, i); | ||
if (w < 0) { return w; } | ||
else { return 0; } | ||
}; | ||
_getX(d, i) { | ||
const w = this._x1 === null ? this._x(d, i) : this._x1(d, i) - this._x(d, i); | ||
if (w < 0) return w;else return 0; | ||
} | ||
/** | ||
@@ -153,8 +134,8 @@ @memberof Bar | ||
*/ | ||
Bar.prototype._getY = function _getY (d, i) { | ||
var h = this._x1 !== null ? this._y(d, i) : this._y1(d, i) - this._y(d, i); | ||
if (h < 0) { return h; } | ||
else { return 0; } | ||
}; | ||
_getY(d, i) { | ||
const h = this._x1 !== null ? this._y(d, i) : this._y1(d, i) - this._y(d, i); | ||
if (h < 0) return h;else return 0; | ||
} | ||
/** | ||
@@ -166,10 +147,11 @@ @memberof Bar | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.height; | ||
} | ||
} | ||
*/ | ||
Bar.prototype.height = function height (_) { | ||
height(_) { | ||
return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height; | ||
}; | ||
} | ||
/** | ||
@@ -181,10 +163,11 @@ @memberof Bar | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.width; | ||
} | ||
} | ||
*/ | ||
Bar.prototype.width = function width (_) { | ||
width(_) { | ||
return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width; | ||
}; | ||
} | ||
/** | ||
@@ -196,9 +179,10 @@ @memberof Bar | ||
*/ | ||
Bar.prototype.x0 = function x0 (_) { | ||
if (!arguments.length) { return this._x0; } | ||
x0(_) { | ||
if (!arguments.length) return this._x0; | ||
this._x0 = typeof _ === "function" ? _ : constant(_); | ||
this._x = this._x0; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -210,6 +194,7 @@ @memberof Bar | ||
*/ | ||
Bar.prototype.x1 = function x1 (_) { | ||
x1(_) { | ||
return arguments.length ? (this._x1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._x1; | ||
}; | ||
} | ||
/** | ||
@@ -221,9 +206,10 @@ @memberof Bar | ||
*/ | ||
Bar.prototype.y0 = function y0 (_) { | ||
if (!arguments.length) { return this._y0; } | ||
y0(_) { | ||
if (!arguments.length) return this._y0; | ||
this._y0 = typeof _ === "function" ? _ : constant(_); | ||
this._y = this._y0; | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -235,11 +221,8 @@ @memberof Bar | ||
*/ | ||
Bar.prototype.y1 = function y1 (_) { | ||
return arguments.length ? (this._y1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._y1; | ||
}; | ||
return Bar; | ||
}(Shape)); | ||
export default Bar; | ||
y1(_) { | ||
return arguments.length ? (this._y1 = typeof _ === "function" || _ === null ? _ : constant(_), this) : this._y1; | ||
} | ||
//# sourceMappingURL=Bar.js.map | ||
} |
@@ -1,13 +0,12 @@ | ||
import {max, min, quantile} from "d3-array"; | ||
import {nest} from "d3-collection"; | ||
import {select} from "d3-selection"; | ||
import {accessor, assign, BaseClass, configPrep, constant, merge, elem} from "d3plus-common"; | ||
import { max, min, quantile } from "d3-array"; | ||
import { nest } from "d3-collection"; | ||
import { select } from "d3-selection"; | ||
import { accessor, assign, BaseClass, configPrep, constant, merge, elem } from "d3plus-common"; | ||
import Circle from "./Circle"; | ||
import Rect from "./Rect"; | ||
import Whisker from "./Whisker"; | ||
var shapes = {Circle: Circle, Rect: Rect}; | ||
const shapes = { | ||
Circle, | ||
Rect | ||
}; | ||
/** | ||
@@ -18,9 +17,11 @@ @class Box | ||
*/ | ||
var Box = /*@__PURE__*/(function (BaseClass) { | ||
function Box() { | ||
var this$1 = this; | ||
BaseClass.call(this); | ||
export default class Box extends BaseClass { | ||
/** | ||
@memberof Box | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from BaseClass. | ||
@private | ||
*/ | ||
constructor() { | ||
super(); | ||
this._medianConfig = { | ||
@@ -36,4 +37,4 @@ fill: constant("black") | ||
Rect: { | ||
height: function (d, i) { return this$1._orient(d, i) === "vertical" ? 5 : 20; }, | ||
width: function (d, i) { return this$1._orient(d, i) === "vertical" ? 20 : 5; } | ||
height: (d, i) => this._orient(d, i) === "vertical" ? 5 : 20, | ||
width: (d, i) => this._orient(d, i) === "vertical" ? 20 : 5 | ||
} | ||
@@ -51,9 +52,3 @@ }; | ||
this._y = accessor("y", 250); | ||
} | ||
if ( BaseClass ) Box.__proto__ = BaseClass; | ||
Box.prototype = Object.create( BaseClass && BaseClass.prototype ); | ||
Box.prototype.constructor = Box; | ||
/** | ||
@@ -65,164 +60,145 @@ @memberof Box | ||
*/ | ||
Box.prototype.render = function render () { | ||
var this$1 = this; | ||
render() { | ||
if (this._select === void 0) { | ||
this.select(select("body").append("svg") | ||
.style("width", ((window.innerWidth) + "px")) | ||
.style("height", ((window.innerHeight) + "px")) | ||
.style("display", "block").node()); | ||
this.select(select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node()); | ||
} | ||
var outlierData = []; | ||
const outlierData = []; | ||
const filteredData = nest().key((d, i) => this._orient(d, i) === "vertical" ? this._x(d, i) : this._y(d, i)).entries(this._data).map(d => { | ||
d.data = merge(d.values); | ||
d.i = this._data.indexOf(d.values[0]); | ||
d.orient = this._orient(d.data, d.i); | ||
const values = d.values.map(d.orient === "vertical" ? this._y : this._x); | ||
values.sort((a, b) => a - b); | ||
d.first = quantile(values, 0.25); | ||
d.median = quantile(values, 0.50); | ||
d.third = quantile(values, 0.75); | ||
const mode = this._whiskerMode; | ||
var filteredData = nest() | ||
.key(function (d, i) { return this$1._orient(d, i) === "vertical" ? this$1._x(d, i) : this$1._y(d, i); }) | ||
.entries(this._data) | ||
.map(function (d) { | ||
d.data = merge(d.values); | ||
d.i = this$1._data.indexOf(d.values[0]); | ||
d.orient = this$1._orient(d.data, d.i); | ||
var values = d.values.map(d.orient === "vertical" ? this$1._y : this$1._x); | ||
values.sort(function (a, b) { return a - b; }); | ||
if (mode[0] === "tukey") { | ||
d.lowerLimit = d.first - (d.third - d.first) * 1.5; | ||
if (d.lowerLimit < min(values)) d.lowerLimit = min(values); | ||
} else if (mode[0] === "extent") d.lowerLimit = min(values);else if (typeof mode[0] === "number") d.lowerLimit = quantile(values, mode[0]); | ||
d.first = quantile(values, 0.25); | ||
d.median = quantile(values, 0.50); | ||
d.third = quantile(values, 0.75); | ||
if (mode[1] === "tukey") { | ||
d.upperLimit = d.third + (d.third - d.first) * 1.5; | ||
if (d.upperLimit > max(values)) d.upperLimit = max(values); | ||
} else if (mode[1] === "extent") d.upperLimit = max(values);else if (typeof mode[1] === "number") d.upperLimit = quantile(values, mode[1]); | ||
var mode = this$1._whiskerMode; | ||
const rectLength = d.third - d.first; // Compute values for vertical orientation. | ||
if (mode[0] === "tukey") { | ||
d.lowerLimit = d.first - (d.third - d.first) * 1.5; | ||
if (d.lowerLimit < min(values)) { d.lowerLimit = min(values); } | ||
} | ||
else if (mode[0] === "extent") { d.lowerLimit = min(values); } | ||
else if (typeof mode[0] === "number") { d.lowerLimit = quantile(values, mode[0]); } | ||
if (d.orient === "vertical") { | ||
d.height = rectLength; | ||
d.width = this._rectWidth(d.data, d.i); | ||
d.x = this._x(d.data, d.i); | ||
d.y = d.first + rectLength / 2; | ||
} else if (d.orient === "horizontal") { | ||
// Compute values for horizontal orientation. | ||
d.height = this._rectWidth(d.data, d.i); | ||
d.width = rectLength; | ||
d.x = d.first + rectLength / 2; | ||
d.y = this._y(d.data, d.i); | ||
} // Compute data for outliers. | ||
if (mode[1] === "tukey") { | ||
d.upperLimit = d.third + (d.third - d.first) * 1.5; | ||
if (d.upperLimit > max(values)) { d.upperLimit = max(values); } | ||
} | ||
else if (mode[1] === "extent") { d.upperLimit = max(values); } | ||
else if (typeof mode[1] === "number") { d.upperLimit = quantile(values, mode[1]); } | ||
var rectLength = d.third - d.first; | ||
d.values.forEach((eachValue, index) => { | ||
const value = d.orient === "vertical" ? this._y(eachValue, index) : this._x(eachValue, index); | ||
// Compute values for vertical orientation. | ||
if (d.orient === "vertical") { | ||
d.height = rectLength; | ||
d.width = this$1._rectWidth(d.data, d.i); | ||
d.x = this$1._x(d.data, d.i); | ||
d.y = d.first + rectLength / 2; | ||
} | ||
else if (d.orient === "horizontal") { | ||
// Compute values for horizontal orientation. | ||
d.height = this$1._rectWidth(d.data, d.i); | ||
d.width = rectLength; | ||
d.x = d.first + rectLength / 2; | ||
d.y = this$1._y(d.data, d.i); | ||
} | ||
if (value < d.lowerLimit || value > d.upperLimit) { | ||
const dataObj = {}; | ||
dataObj.__d3plus__ = true; | ||
dataObj.data = eachValue; | ||
dataObj.i = index; | ||
dataObj.outlier = this._outlier(eachValue, index); | ||
// Compute data for outliers. | ||
d.values.forEach(function (eachValue, index) { | ||
var value = d.orient === "vertical" ? this$1._y(eachValue, index) : this$1._x(eachValue, index); | ||
if (value < d.lowerLimit || value > d.upperLimit) { | ||
var dataObj = {}; | ||
dataObj.__d3plus__ = true; | ||
dataObj.data = eachValue; | ||
dataObj.i = index; | ||
dataObj.outlier = this$1._outlier(eachValue, index); | ||
if (d.orient === "vertical") { | ||
dataObj.x = d.x; | ||
dataObj.y = value; | ||
outlierData.push(dataObj); | ||
} | ||
else if (d.orient === "horizontal") { | ||
dataObj.y = d.y; | ||
dataObj.x = value; | ||
outlierData.push(dataObj); | ||
} | ||
if (d.orient === "vertical") { | ||
dataObj.x = d.x; | ||
dataObj.y = value; | ||
outlierData.push(dataObj); | ||
} else if (d.orient === "horizontal") { | ||
dataObj.y = d.y; | ||
dataObj.x = value; | ||
outlierData.push(dataObj); | ||
} | ||
}); | ||
d.__d3plus__ = true; | ||
return d; | ||
} | ||
}); | ||
d.__d3plus__ = true; | ||
return d; | ||
}); // Draw box. | ||
// Draw box. | ||
this._box = new Rect() | ||
.data(filteredData) | ||
.x(function (d) { return d.x; }) | ||
.y(function (d) { return d.y; }) | ||
.select(elem("g.d3plus-Box", {parent: this._select}).node()) | ||
.config(configPrep.bind(this)(this._rectConfig, "shape")) | ||
.render(); | ||
this._box = new Rect().data(filteredData).x(d => d.x).y(d => d.y).select(elem("g.d3plus-Box", { | ||
parent: this._select | ||
}).node()).config(configPrep.bind(this)(this._rectConfig, "shape")).render(); // Draw median. | ||
// Draw median. | ||
this._median = new Rect() | ||
.data(filteredData) | ||
.x(function (d) { return d.orient === "vertical" ? d.x : d.median; }) | ||
.y(function (d) { return d.orient === "vertical" ? d.median : d.y; }) | ||
.height(function (d) { return d.orient === "vertical" ? 1 : d.height; }) | ||
.width(function (d) { return d.orient === "vertical" ? d.width : 1; }) | ||
.select(elem("g.d3plus-Box-Median", {parent: this._select}).node()) | ||
.config(configPrep.bind(this)(this._medianConfig, "shape")) | ||
.render(); | ||
// Draw 2 lines using Whisker class. | ||
this._median = new Rect().data(filteredData).x(d => d.orient === "vertical" ? d.x : d.median).y(d => d.orient === "vertical" ? d.median : d.y).height(d => d.orient === "vertical" ? 1 : d.height).width(d => d.orient === "vertical" ? d.width : 1).select(elem("g.d3plus-Box-Median", { | ||
parent: this._select | ||
}).node()).config(configPrep.bind(this)(this._medianConfig, "shape")).render(); // Draw 2 lines using Whisker class. | ||
// Construct coordinates for whisker startpoints and push it to the whiskerData. | ||
var whiskerData = []; | ||
filteredData.forEach(function (d, i) { | ||
var x = d.x; | ||
var y = d.y; | ||
var topLength = d.first - d.lowerLimit; | ||
var bottomLength = d.upperLimit - d.third; | ||
const whiskerData = []; | ||
filteredData.forEach((d, i) => { | ||
const x = d.x; | ||
const y = d.y; | ||
const topLength = d.first - d.lowerLimit; | ||
const bottomLength = d.upperLimit - d.third; | ||
if (d.orient === "vertical") { | ||
var topY = y - d.height / 2; | ||
var bottomY = y + d.height / 2; | ||
whiskerData.push( | ||
{__d3plus__: true, data: d, i: i, x: x, y: topY, length: topLength, orient: "top"}, | ||
{__d3plus__: true, data: d, i: i, x: x, y: bottomY, length: bottomLength, orient: "bottom"} | ||
); | ||
const topY = y - d.height / 2; | ||
const bottomY = y + d.height / 2; | ||
whiskerData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
x, | ||
y: topY, | ||
length: topLength, | ||
orient: "top" | ||
}, { | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
x, | ||
y: bottomY, | ||
length: bottomLength, | ||
orient: "bottom" | ||
}); | ||
} else if (d.orient === "horizontal") { | ||
const topX = x + d.width / 2; | ||
const bottomX = x - d.width / 2; | ||
whiskerData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
x: topX, | ||
y, | ||
length: bottomLength, | ||
orient: "right" | ||
}, { | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
x: bottomX, | ||
y, | ||
length: topLength, | ||
orient: "left" | ||
}); | ||
} | ||
else if (d.orient === "horizontal") { | ||
var topX = x + d.width / 2; | ||
var bottomX = x - d.width / 2; | ||
whiskerData.push( | ||
{__d3plus__: true, data: d, i: i, x: topX, y: y, length: bottomLength, orient: "right"}, | ||
{__d3plus__: true, data: d, i: i, x: bottomX, y: y, length: topLength, orient: "left"} | ||
); | ||
} | ||
}); // Draw whiskers. | ||
}); | ||
this._whisker = new Whisker().data(whiskerData).select(elem("g.d3plus-Box-Whisker", { | ||
parent: this._select | ||
}).node()).config(configPrep.bind(this)(this._whiskerConfig, "shape")).render(); // Draw outliers. | ||
// Draw whiskers. | ||
this._whisker = new Whisker() | ||
.data(whiskerData) | ||
.select(elem("g.d3plus-Box-Whisker", {parent: this._select}).node()) | ||
.config(configPrep.bind(this)(this._whiskerConfig, "shape")) | ||
.render(); | ||
// Draw outliers. | ||
this._whiskerEndpoint = []; | ||
nest() | ||
.key(function (d) { return d.outlier; }) | ||
.entries(outlierData) | ||
.forEach(function (shapeData) { | ||
var shapeName = shapeData.key; | ||
this$1._whiskerEndpoint.push(new shapes[shapeName]() | ||
.data(shapeData.values) | ||
.select(elem(("g.d3plus-Box-Outlier-" + shapeName), {parent: this$1._select}).node()) | ||
.config(configPrep.bind(this$1)(this$1._outlierConfig, "shape", shapeName)) | ||
.render()); | ||
}); | ||
nest().key(d => d.outlier).entries(outlierData).forEach(shapeData => { | ||
const shapeName = shapeData.key; | ||
this._whiskerEndpoint.push(new shapes[shapeName]().data(shapeData.values).select(elem(`g.d3plus-Box-Outlier-${shapeName}`, { | ||
parent: this._select | ||
}).node()).config(configPrep.bind(this)(this._outlierConfig, "shape", shapeName)).render()); | ||
}); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -234,9 +210,10 @@ @memberof Box | ||
*/ | ||
Box.prototype.active = function active (_) { | ||
if (this._box) { this._box.active(_); } | ||
if (this._median) { this._median.active(_); } | ||
if (this._whisker) { this._whisker.active(_); } | ||
if (this._whiskerEndpoint) { this._whiskerEndpoint.forEach(function (endPoint) { return endPoint.active(_); }); } | ||
}; | ||
active(_) { | ||
if (this._box) this._box.active(_); | ||
if (this._median) this._median.active(_); | ||
if (this._whisker) this._whisker.active(_); | ||
if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(endPoint => endPoint.active(_)); | ||
} | ||
/** | ||
@@ -248,6 +225,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.data = function data (_) { | ||
data(_) { | ||
return arguments.length ? (this._data = _, this) : this._data; | ||
}; | ||
} | ||
/** | ||
@@ -259,9 +237,10 @@ @memberof Box | ||
*/ | ||
Box.prototype.hover = function hover (_) { | ||
if (this._box) { this._box.hover(_); } | ||
if (this._median) { this._median.hover(_); } | ||
if (this._whisker) { this._whisker.hover(_); } | ||
if (this._whiskerEndpoint) { this._whiskerEndpoint.forEach(function (endPoint) { return endPoint.hover(_); }); } | ||
}; | ||
hover(_) { | ||
if (this._box) this._box.hover(_); | ||
if (this._median) this._median.hover(_); | ||
if (this._whisker) this._whisker.hover(_); | ||
if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(endPoint => endPoint.hover(_)); | ||
} | ||
/** | ||
@@ -273,6 +252,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.medianConfig = function medianConfig (_) { | ||
medianConfig(_) { | ||
return arguments.length ? (this._medianConfig = assign(this._medianConfig, _), this) : this._medianConfig; | ||
}; | ||
} | ||
/** | ||
@@ -284,6 +264,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.orient = function orient (_) { | ||
orient(_) { | ||
return arguments.length ? (this._orient = typeof _ === "function" ? _ : constant(_), this) : this._orient; | ||
}; | ||
} | ||
/** | ||
@@ -295,6 +276,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.outlier = function outlier (_) { | ||
outlier(_) { | ||
return arguments.length ? (this._outlier = typeof _ === "function" ? _ : constant(_), this) : this._outlier; | ||
}; | ||
} | ||
/** | ||
@@ -306,6 +288,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.outlierConfig = function outlierConfig (_) { | ||
outlierConfig(_) { | ||
return arguments.length ? (this._outlierConfig = assign(this._outlierConfig, _), this) : this._outlierConfig; | ||
}; | ||
} | ||
/** | ||
@@ -317,6 +300,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.rectConfig = function rectConfig (_) { | ||
rectConfig(_) { | ||
return arguments.length ? (this._rectConfig = assign(this._rectConfig, _), this) : this._rectConfig; | ||
}; | ||
} | ||
/** | ||
@@ -328,10 +312,11 @@ @memberof Box | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.width; | ||
} | ||
} | ||
*/ | ||
Box.prototype.rectWidth = function rectWidth (_) { | ||
rectWidth(_) { | ||
return arguments.length ? (this._rectWidth = typeof _ === "function" ? _ : constant(_), this) : this._rectWidth; | ||
}; | ||
} | ||
/** | ||
@@ -343,6 +328,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.select = function select$1 (_) { | ||
select(_) { | ||
return arguments.length ? (this._select = select(_), this) : this._select; | ||
}; | ||
} | ||
/** | ||
@@ -354,6 +340,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.whiskerConfig = function whiskerConfig (_) { | ||
whiskerConfig(_) { | ||
return arguments.length ? (this._whiskerConfig = assign(this._whiskerConfig, _), this) : this._whiskerConfig; | ||
}; | ||
} | ||
/** | ||
@@ -365,6 +352,7 @@ @memberof Box | ||
*/ | ||
Box.prototype.whiskerMode = function whiskerMode (_) { | ||
whiskerMode(_) { | ||
return arguments.length ? (this._whiskerMode = _ instanceof Array ? _ : [_, _], this) : this._whiskerMode; | ||
}; | ||
} | ||
/** | ||
@@ -376,10 +364,11 @@ @memberof Box | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.x; | ||
} | ||
} | ||
*/ | ||
Box.prototype.x = function x (_) { | ||
x(_) { | ||
return arguments.length ? (this._x = typeof _ === "function" ? _ : accessor(_), this) : this._x; | ||
}; | ||
} | ||
/** | ||
@@ -391,15 +380,12 @@ @memberof Box | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.y; | ||
} | ||
} | ||
*/ | ||
Box.prototype.y = function y (_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : accessor(_), this) : this._y; | ||
}; | ||
return Box; | ||
}(BaseClass)); | ||
export default Box; | ||
y(_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : accessor(_), this) : this._y; | ||
} | ||
//# sourceMappingURL=Box.js.map | ||
} |
@@ -1,5 +0,3 @@ | ||
import {accessor, assign, constant} from "d3plus-common"; | ||
import { accessor, assign, constant } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
/** | ||
@@ -10,6 +8,19 @@ @class Circle | ||
*/ | ||
var Circle = /*@__PURE__*/(function (Shape) { | ||
function Circle() { | ||
Shape.call(this, "circle"); | ||
this._labelBounds = function (d, i, s) { return ({width: s.r * 1.5, height: s.r * 1.5, x: -s.r * 0.75, y: -s.r * 0.75}); }; | ||
export default class Circle extends Shape { | ||
/** | ||
@memberof Circle | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super("circle"); | ||
this._labelBounds = (d, i, s) => ({ | ||
width: s.r * 1.5, | ||
height: s.r * 1.5, | ||
x: -s.r * 0.75, | ||
y: -s.r * 0.75 | ||
}); | ||
this._labelConfig = assign(this._labelConfig, { | ||
@@ -22,7 +33,2 @@ textAnchor: "middle", | ||
} | ||
if ( Shape ) Circle.__proto__ = Shape; | ||
Circle.prototype = Object.create( Shape && Shape.prototype ); | ||
Circle.prototype.constructor = Circle; | ||
/** | ||
@@ -33,11 +39,7 @@ @memberof Circle | ||
*/ | ||
Circle.prototype._applyPosition = function _applyPosition (elem) { | ||
var this$1 = this; | ||
elem | ||
.attr("r", function (d, i) { return this$1._r(d, i); }) | ||
.attr("x", function (d, i) { return -this$1._r(d, i) / 2; }) | ||
.attr("y", function (d, i) { return -this$1._r(d, i) / 2; }); | ||
}; | ||
_applyPosition(elem) { | ||
elem.attr("r", (d, i) => this._r(d, i)).attr("x", (d, i) => -this._r(d, i) / 2).attr("y", (d, i) => -this._r(d, i) / 2); | ||
} | ||
/** | ||
@@ -49,23 +51,15 @@ @memberof Circle | ||
*/ | ||
Circle.prototype.render = function render (callback) { | ||
Shape.prototype.render.call(this, callback); | ||
this._enter | ||
.attr("r", 0).attr("x", 0).attr("y", 0) | ||
.call(this._applyStyle.bind(this)) | ||
.transition(this._transition) | ||
.call(this._applyPosition.bind(this)); | ||
render(callback) { | ||
super.render(callback); | ||
this._update.transition(this._transition) | ||
.call(this._applyStyle.bind(this)) | ||
.call(this._applyPosition.bind(this)); | ||
this._enter.attr("r", 0).attr("x", 0).attr("y", 0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this)); | ||
this._exit.transition(this._transition) | ||
.attr("r", 0).attr("x", 0).attr("y", 0); | ||
this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this)); | ||
this._exit.transition(this._transition).attr("r", 0).attr("x", 0).attr("y", 0); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -78,6 +72,9 @@ @memberof Circle | ||
*/ | ||
Circle.prototype._aes = function _aes (d, i) { | ||
return {r: this._r(d, i)}; | ||
}; | ||
_aes(d, i) { | ||
return { | ||
r: this._r(d, i) | ||
}; | ||
} | ||
/** | ||
@@ -89,15 +86,12 @@ @memberof Circle | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.r; | ||
} | ||
} | ||
*/ | ||
Circle.prototype.r = function r (_) { | ||
return arguments.length ? (this._r = typeof _ === "function" ? _ : constant(_), this) : this._r; | ||
}; | ||
return Circle; | ||
}(Shape)); | ||
export default Circle; | ||
r(_) { | ||
return arguments.length ? (this._r = typeof _ === "function" ? _ : constant(_), this) : this._r; | ||
} | ||
//# sourceMappingURL=Circle.js.map | ||
} |
@@ -1,11 +0,8 @@ | ||
import {extent} from "d3-array"; | ||
import {nest} from "d3-collection"; | ||
import {interpolatePath} from "d3-interpolate-path"; | ||
import {select} from "d3-selection"; | ||
import { extent } from "d3-array"; | ||
import { nest } from "d3-collection"; | ||
import { interpolatePath } from "d3-interpolate-path"; | ||
import { select } from "d3-selection"; | ||
import * as paths from "d3-shape"; | ||
import {constant, merge} from "d3plus-common"; | ||
import { constant, merge } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
/** | ||
@@ -16,14 +13,18 @@ @class Line | ||
*/ | ||
var Line = /*@__PURE__*/(function (Shape) { | ||
function Line() { | ||
var this$1 = this; | ||
export default class Line extends Shape { | ||
/** | ||
@memberof Line | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super(); | ||
this._curve = "linear"; | ||
Shape.call(this); | ||
this._defined = d => d; | ||
this._curve = "linear"; | ||
this._defined = function (d) { return d; }; | ||
this._fill = constant("none"); | ||
this._hitArea = constant({ | ||
"d": function (d) { return this$1._path(d.values); }, | ||
"d": d => this._path(d.values), | ||
"fill": "none", | ||
@@ -37,9 +38,3 @@ "stroke-width": 10, | ||
this._strokeWidth = constant(1); | ||
} | ||
if ( Shape ) Line.__proto__ = Shape; | ||
Line.prototype = Object.create( Shape && Shape.prototype ); | ||
Line.prototype.constructor = Line; | ||
/** | ||
@@ -51,33 +46,26 @@ @memberof Line | ||
*/ | ||
Line.prototype._dataFilter = function _dataFilter (data) { | ||
var this$1 = this; | ||
var lines = nest().key(this._id).entries(data).map(function (d) { | ||
_dataFilter(data) { | ||
const lines = nest().key(this._id).entries(data).map(d => { | ||
d.data = merge(d.values); | ||
d.i = data.indexOf(d.values[0]); | ||
var x = extent(d.values, this$1._x); | ||
const x = extent(d.values, this._x); | ||
d.xR = x; | ||
d.width = x[1] - x[0]; | ||
d.x = x[0] + d.width / 2; | ||
var y = extent(d.values, this$1._y); | ||
const y = extent(d.values, this._y); | ||
d.yR = y; | ||
d.height = y[1] - y[0]; | ||
d.y = y[0] + d.height / 2; | ||
d.nested = true; | ||
d.translate = [d.x, d.y]; | ||
d.__d3plusShape__ = true; | ||
return d; | ||
}); | ||
lines.key = function (d) { return d.key; }; | ||
lines.key = d => d.key; | ||
return lines; | ||
}; | ||
} | ||
/** | ||
@@ -89,32 +77,18 @@ @memberof Line | ||
*/ | ||
Line.prototype.render = function render (callback) { | ||
var this$1 = this; | ||
Shape.prototype.render.call(this, callback); | ||
render(callback) { | ||
super.render(callback); | ||
const that = this; | ||
var that = this; | ||
this._path.curve(paths[`curve${this._curve.charAt(0).toUpperCase()}${this._curve.slice(1)}`]).defined(this._defined).x(this._x).y(this._y); | ||
this._path | ||
.curve(paths[("curve" + (this._curve.charAt(0).toUpperCase()) + (this._curve.slice(1)))]) | ||
.defined(this._defined) | ||
.x(this._x) | ||
.y(this._y); | ||
this._enter.append("path").attr("transform", d => `translate(${-d.xR[0] - d.width / 2}, ${-d.yR[0] - d.height / 2})`).attr("d", d => this._path(d.values)).call(this._applyStyle.bind(this)); | ||
this._enter.append("path") | ||
.attr("transform", function (d) { return ("translate(" + (-d.xR[0] - d.width / 2) + ", " + (-d.yR[0] - d.height / 2) + ")"); }) | ||
.attr("d", function (d) { return this$1._path(d.values); }) | ||
.call(this._applyStyle.bind(this)); | ||
this._update.select("path").transition(this._transition).attr("transform", d => `translate(${-d.xR[0] - d.width / 2}, ${-d.yR[0] - d.height / 2})`).attrTween("d", function (d) { | ||
return interpolatePath(select(this).attr("d"), that._path(d.values)); | ||
}).call(this._applyStyle.bind(this)); | ||
this._update.select("path").transition(this._transition) | ||
.attr("transform", function (d) { return ("translate(" + (-d.xR[0] - d.width / 2) + ", " + (-d.yR[0] - d.height / 2) + ")"); }) | ||
.attrTween("d", function(d) { | ||
return interpolatePath(select(this).attr("d"), that._path(d.values)); | ||
}) | ||
.call(this._applyStyle.bind(this)); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -127,8 +101,9 @@ @memberof Line | ||
*/ | ||
Line.prototype._aes = function _aes (d, i) { | ||
var this$1 = this; | ||
return {points: d.values.map(function (p) { return [this$1._x(p, i), this$1._y(p, i)]; })}; | ||
}; | ||
_aes(d, i) { | ||
return { | ||
points: d.values.map(p => [this._x(p, i), this._y(p, i)]) | ||
}; | ||
} | ||
/** | ||
@@ -140,6 +115,7 @@ @memberof Line | ||
*/ | ||
Line.prototype.curve = function curve (_) { | ||
curve(_) { | ||
return arguments.length ? (this._curve = _, this) : this._curve; | ||
}; | ||
} | ||
/** | ||
@@ -151,11 +127,8 @@ @memberof Line | ||
*/ | ||
Line.prototype.defined = function defined (_) { | ||
return arguments.length ? (this._defined = _, this) : this._defined; | ||
}; | ||
return Line; | ||
}(Shape)); | ||
export default Line; | ||
defined(_) { | ||
return arguments.length ? (this._defined = _, this) : this._defined; | ||
} | ||
//# sourceMappingURL=Line.js.map | ||
} |
@@ -1,7 +0,5 @@ | ||
import {accessor, constant} from "d3plus-common"; | ||
import { accessor, constant } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
import largestRect from "../geom/largestRect"; | ||
import path2polygon from "../geom/path2polygon"; | ||
/** | ||
@@ -12,12 +10,26 @@ @class Path | ||
*/ | ||
var Path = /*@__PURE__*/(function (Shape) { | ||
function Path() { | ||
var this$1 = this; | ||
Shape.call(this, "path"); | ||
export default class Path extends Shape { | ||
/** | ||
@memberof Path | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super("path"); | ||
this._d = accessor("path"); | ||
this._labelBounds = function (d, i, aes) { | ||
var r = largestRect(aes.points, {angle: this$1._labelConfig.rotate ? this$1._labelConfig.rotate(d, i) : 0}); | ||
return r ? {angle: r.angle, width: r.width, height: r.height, x: r.cx - r.width / 2, y: r.cy - r.height / 2} : false; | ||
this._labelBounds = (d, i, aes) => { | ||
const r = largestRect(aes.points, { | ||
angle: this._labelConfig.rotate ? this._labelConfig.rotate(d, i) : 0 | ||
}); | ||
return r ? { | ||
angle: r.angle, | ||
width: r.width, | ||
height: r.height, | ||
x: r.cx - r.width / 2, | ||
y: r.cy - r.height / 2 | ||
} : false; | ||
}; | ||
this._name = "Path"; | ||
@@ -29,7 +41,2 @@ this._labelConfig = Object.assign(this._labelConfig, { | ||
} | ||
if ( Shape ) Path.__proto__ = Shape; | ||
Path.prototype = Object.create( Shape && Shape.prototype ); | ||
Path.prototype.constructor = Path; | ||
/** | ||
@@ -42,6 +49,9 @@ @memberof Path | ||
*/ | ||
Path.prototype._aes = function _aes (d, i) { | ||
return {points: path2polygon(this._d(d, i))}; | ||
}; | ||
_aes(d, i) { | ||
return { | ||
points: path2polygon(this._d(d, i)) | ||
}; | ||
} | ||
/** | ||
@@ -53,25 +63,15 @@ @memberof Path | ||
*/ | ||
Path.prototype.render = function render (callback) { | ||
Shape.prototype.render.call(this, callback); | ||
this._enter | ||
.attr("opacity", 0) | ||
.attr("d", this._d) | ||
.call(this._applyStyle.bind(this)) | ||
.transition(this._transition) | ||
.attr("opacity", 1); | ||
render(callback) { | ||
super.render(callback); | ||
this._update.transition(this._transition) | ||
.call(this._applyStyle.bind(this)) | ||
.attr("opacity", 1) | ||
.attr("d", this._d); | ||
this._enter.attr("opacity", 0).attr("d", this._d).call(this._applyStyle.bind(this)).transition(this._transition).attr("opacity", 1); | ||
this._exit.transition(this._transition) | ||
.attr("opacity", 0); | ||
this._update.transition(this._transition).call(this._applyStyle.bind(this)).attr("opacity", 1).attr("d", this._d); | ||
this._exit.transition(this._transition).attr("opacity", 0); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -83,15 +83,12 @@ @memberof Path | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.path; | ||
} | ||
} | ||
*/ | ||
Path.prototype.d = function d (_) { | ||
return arguments.length ? (this._d = typeof _ === "function" ? _ : constant(_), this) : this._d; | ||
}; | ||
return Path; | ||
}(Shape)); | ||
export default Path; | ||
d(_) { | ||
return arguments.length ? (this._d = typeof _ === "function" ? _ : constant(_), this) : this._d; | ||
} | ||
//# sourceMappingURL=Path.js.map | ||
} |
@@ -1,5 +0,3 @@ | ||
import {accessor, constant} from "d3plus-common"; | ||
import { accessor, constant } from "d3plus-common"; | ||
import Shape from "./Shape"; | ||
/** | ||
@@ -10,15 +8,23 @@ @class Rect | ||
*/ | ||
var Rect = /*@__PURE__*/(function (Shape) { | ||
function Rect() { | ||
Shape.call(this, "rect"); | ||
export default class Rect extends Shape { | ||
/** | ||
@memberof Rect | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Shape. | ||
@private | ||
*/ | ||
constructor() { | ||
super("rect"); | ||
this._height = accessor("height"); | ||
this._labelBounds = function (d, i, s) { return ({width: s.width, height: s.height, x: -s.width / 2, y: -s.height / 2}); }; | ||
this._labelBounds = (d, i, s) => ({ | ||
width: s.width, | ||
height: s.height, | ||
x: -s.width / 2, | ||
y: -s.height / 2 | ||
}); | ||
this._name = "Rect"; | ||
this._width = accessor("width"); | ||
} | ||
if ( Shape ) Rect.__proto__ = Shape; | ||
Rect.prototype = Object.create( Shape && Shape.prototype ); | ||
Rect.prototype.constructor = Rect; | ||
/** | ||
@@ -30,25 +36,15 @@ @memberof Rect | ||
*/ | ||
Rect.prototype.render = function render (callback) { | ||
Shape.prototype.render.call(this, callback); | ||
this._enter | ||
.attr("width", 0).attr("height", 0) | ||
.attr("x", 0).attr("y", 0) | ||
.call(this._applyStyle.bind(this)) | ||
.transition(this._transition) | ||
.call(this._applyPosition.bind(this)); | ||
render(callback) { | ||
super.render(callback); | ||
this._update.transition(this._transition) | ||
.call(this._applyStyle.bind(this)) | ||
.call(this._applyPosition.bind(this)); | ||
this._enter.attr("width", 0).attr("height", 0).attr("x", 0).attr("y", 0).call(this._applyStyle.bind(this)).transition(this._transition).call(this._applyPosition.bind(this)); | ||
this._exit.transition(this._transition) | ||
.attr("width", 0).attr("height", 0) | ||
.attr("x", 0).attr("y", 0); | ||
this._update.transition(this._transition).call(this._applyStyle.bind(this)).call(this._applyPosition.bind(this)); | ||
this._exit.transition(this._transition).attr("width", 0).attr("height", 0).attr("x", 0).attr("y", 0); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -61,6 +57,10 @@ @memberof Rect | ||
*/ | ||
Rect.prototype._aes = function _aes (d, i) { | ||
return {width: this._width(d, i), height: this._height(d, i)}; | ||
}; | ||
_aes(d, i) { | ||
return { | ||
width: this._width(d, i), | ||
height: this._height(d, i) | ||
}; | ||
} | ||
/** | ||
@@ -72,12 +72,7 @@ @memberof Rect | ||
*/ | ||
Rect.prototype._applyPosition = function _applyPosition (elem) { | ||
var this$1 = this; | ||
elem | ||
.attr("width", function (d, i) { return this$1._width(d, i); }) | ||
.attr("height", function (d, i) { return this$1._height(d, i); }) | ||
.attr("x", function (d, i) { return -this$1._width(d, i) / 2; }) | ||
.attr("y", function (d, i) { return -this$1._height(d, i) / 2; }); | ||
}; | ||
_applyPosition(elem) { | ||
elem.attr("width", (d, i) => this._width(d, i)).attr("height", (d, i) => this._height(d, i)).attr("x", (d, i) => -this._width(d, i) / 2).attr("y", (d, i) => -this._height(d, i) / 2); | ||
} | ||
/** | ||
@@ -89,10 +84,11 @@ @memberof Rect | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.height; | ||
} | ||
} | ||
*/ | ||
Rect.prototype.height = function height (_) { | ||
height(_) { | ||
return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height; | ||
}; | ||
} | ||
/** | ||
@@ -104,15 +100,12 @@ @memberof Rect | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.width; | ||
} | ||
} | ||
*/ | ||
Rect.prototype.width = function width (_) { | ||
return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width; | ||
}; | ||
return Rect; | ||
}(Shape)); | ||
export default Rect; | ||
width(_) { | ||
return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width; | ||
} | ||
//# sourceMappingURL=Rect.js.map | ||
} |
@@ -5,16 +5,12 @@ /** | ||
*/ | ||
import {min} from "d3-array"; | ||
import {color} from "d3-color"; | ||
import {mouse, select, selectAll} from "d3-selection"; | ||
import {transition} from "d3-transition"; | ||
import {accessor, assign, attrize, BaseClass, configPrep, constant, elem} from "d3plus-common"; | ||
import {colorContrast} from "d3plus-color"; | ||
import { min } from "d3-array"; | ||
import { color } from "d3-color"; | ||
import { mouse, select, selectAll } from "d3-selection"; | ||
import { transition } from "d3-transition"; | ||
import { accessor, assign, attrize, BaseClass, configPrep, constant, elem } from "d3plus-common"; | ||
import { colorContrast } from "d3plus-color"; | ||
import * as paths from "d3-shape"; | ||
import {strip, TextBox} from "d3plus-text"; | ||
import { strip, TextBox } from "d3plus-text"; | ||
import Image from "../Image"; | ||
import pointDistance from "../geom/pointDistance"; | ||
/** | ||
@@ -25,19 +21,21 @@ @class Shape | ||
*/ | ||
var Shape = /*@__PURE__*/(function (BaseClass) { | ||
function Shape(tagName) { | ||
var this$1 = this; | ||
if ( tagName === void 0 ) tagName = "g"; | ||
BaseClass.call(this); | ||
export default class Shape extends BaseClass { | ||
/** | ||
@memberof Shape | ||
@desc Invoked when creating a new class instance, and sets any default parameters. | ||
@private | ||
*/ | ||
constructor(tagName = "g") { | ||
super(); | ||
this._activeOpacity = 0.25; | ||
this._activeStyle = { | ||
"stroke": function (d, i) { | ||
var c = this$1._fill(d, i); | ||
if (["transparent", "none"].includes(c)) { c = this$1._stroke(d, i); } | ||
"stroke": (d, i) => { | ||
let c = this._fill(d, i); | ||
if (["transparent", "none"].includes(c)) c = this._stroke(d, i); | ||
return color(c).darker(1); | ||
}, | ||
"stroke-width": function (d, i) { | ||
var s = this$1._strokeWidth(d, i) || 1; | ||
"stroke-width": (d, i) => { | ||
const s = this._strokeWidth(d, i) || 1; | ||
return s * 3; | ||
@@ -53,20 +51,22 @@ } | ||
this._fillOpacity = constant(1); | ||
this._hoverOpacity = 0.5; | ||
this._hoverStyle = { | ||
"stroke": function (d, i) { | ||
var c = this$1._fill(d, i); | ||
if (["transparent", "none"].includes(c)) { c = this$1._stroke(d, i); } | ||
"stroke": (d, i) => { | ||
let c = this._fill(d, i); | ||
if (["transparent", "none"].includes(c)) c = this._stroke(d, i); | ||
return color(c).darker(0.5); | ||
}, | ||
"stroke-width": function (d, i) { | ||
var s = this$1._strokeWidth(d, i) || 1; | ||
"stroke-width": (d, i) => { | ||
const s = this._strokeWidth(d, i) || 1; | ||
return s * 2; | ||
} | ||
}; | ||
this._id = function (d, i) { return d.id !== void 0 ? d.id : i; }; | ||
this._id = (d, i) => d.id !== void 0 ? d.id : i; | ||
this._label = constant(false); | ||
this._labelClass = new TextBox(); | ||
this._labelConfig = { | ||
fontColor: function (d, i) { return colorContrast(this$1._fill(d, i)); }, | ||
fontColor: (d, i) => colorContrast(this._fill(d, i)), | ||
fontSize: 12, | ||
@@ -84,3 +84,5 @@ padding: 5 | ||
this._shapeRendering = constant("geometricPrecision"); | ||
this._stroke = function (d, i) { return color(this$1._fill(d, i)).darker(1); }; | ||
this._stroke = (d, i) => color(this._fill(d, i)).darker(1); | ||
this._strokeDasharray = constant("0"); | ||
@@ -94,12 +96,5 @@ this._strokeLinecap = constant("butt"); | ||
this._verticalAlign = constant("top"); | ||
this._x = accessor("x", 0); | ||
this._y = accessor("y", 0); | ||
} | ||
if ( BaseClass ) Shape.__proto__ = BaseClass; | ||
Shape.prototype = Object.create( BaseClass && BaseClass.prototype ); | ||
Shape.prototype.constructor = Shape; | ||
/** | ||
@@ -112,6 +107,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._aes = function _aes () { | ||
_aes() { | ||
return {}; | ||
}; | ||
} | ||
/** | ||
@@ -123,24 +119,22 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._applyEvents = function _applyEvents (handler) { | ||
var this$1 = this; | ||
var events = Object.keys(this._on); | ||
var loop = function ( e ) { | ||
handler.on(events[e], function (d, i) { | ||
if (!this$1._on[events[e]]) { return; } | ||
if (d.i !== void 0) { i = d.i; } | ||
_applyEvents(handler) { | ||
const events = Object.keys(this._on); | ||
for (let e = 0; e < events.length; e++) { | ||
handler.on(events[e], (d, i) => { | ||
if (!this._on[events[e]]) return; | ||
if (d.i !== void 0) i = d.i; | ||
if (d.nested && d.values) { | ||
var cursor = mouse(this$1._select.node()), | ||
values = d.values.map(function (d) { return pointDistance(cursor, [this$1._x(d, i), this$1._y(d, i)]); }); | ||
const cursor = mouse(this._select.node()), | ||
values = d.values.map(d => pointDistance(cursor, [this._x(d, i), this._y(d, i)])); | ||
d = d.values[values.indexOf(min(values))]; | ||
} | ||
this$1._on[events[e]].bind(this$1)(d, i); | ||
this._on[events[e]].bind(this)(d, i); | ||
}); | ||
}; | ||
for (var e = 0; e < events.length; e++) loop( e ); | ||
}; | ||
} | ||
} | ||
/** | ||
@@ -153,8 +147,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._updateStyle = function _updateStyle (elem, style) { | ||
var that = this; | ||
if (elem.size() && elem.node().tagName === "g") { elem = elem.selectAll("*"); } | ||
_updateStyle(elem, style) { | ||
const that = this; | ||
if (elem.size() && elem.node().tagName === "g") elem = elem.selectAll("*"); | ||
/** | ||
@@ -166,11 +159,10 @@ @desc Determines whether a shape is a nested collection of data points, and uses the appropriate data and index for the given function context. | ||
*/ | ||
function styleLogic(d, i) { | ||
return typeof this !== "function" ? this | ||
: d.nested && d.key && d.values | ||
? this(d.values[0], that._data.indexOf(d.values[0])) | ||
: this(d, i); | ||
return typeof this !== "function" ? this : d.nested && d.key && d.values ? this(d.values[0], that._data.indexOf(d.values[0])) : this(d, i); | ||
} | ||
var styleObject = {}; | ||
for (var key in style) { | ||
const styleObject = {}; | ||
for (const key in style) { | ||
if ({}.hasOwnProperty.call(style, key)) { | ||
@@ -182,5 +174,3 @@ styleObject[key] = styleLogic.bind(style[key]); | ||
elem.transition().duration(0).call(attrize, styleObject); | ||
}; | ||
} | ||
/** | ||
@@ -192,8 +182,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._applyStyle = function _applyStyle (elem) { | ||
var that = this; | ||
if (elem.size() && elem.node().tagName === "g") { elem = elem.selectAll("*"); } | ||
_applyStyle(elem) { | ||
const that = this; | ||
if (elem.size() && elem.node().tagName === "g") elem = elem.selectAll("*"); | ||
/** | ||
@@ -205,22 +194,9 @@ @desc Determines whether a shape is a nested collection of data points, and uses the appropriate data and index for the given function context. | ||
*/ | ||
function styleLogic(d, i) { | ||
return typeof this !== "function" ? this | ||
: d.nested && d.key && d.values | ||
? this(d.values[0], that._data.indexOf(d.values[0])) | ||
: this(d, i); | ||
return typeof this !== "function" ? this : d.nested && d.key && d.values ? this(d.values[0], that._data.indexOf(d.values[0])) : this(d, i); | ||
} | ||
elem | ||
.attr("fill", styleLogic.bind(this._fill)) | ||
.attr("fill-opacity", styleLogic.bind(this._fillOpacity)) | ||
.attr("rx", styleLogic.bind(this._rx)) | ||
.attr("ry", styleLogic.bind(this._ry)) | ||
.attr("stroke", styleLogic.bind(this._stroke)) | ||
.attr("stroke-dasharray", styleLogic.bind(this._strokeDasharray)) | ||
.attr("stroke-linecap", styleLogic.bind(this._strokeLinecap)) | ||
.attr("stroke-opacity", styleLogic.bind(this._strokeOpacity)) | ||
.attr("stroke-width", styleLogic.bind(this._strokeWidth)) | ||
.attr("vector-effect", styleLogic.bind(this._vectorEffect)); | ||
}; | ||
elem.attr("fill", styleLogic.bind(this._fill)).attr("fill-opacity", styleLogic.bind(this._fillOpacity)).attr("rx", styleLogic.bind(this._rx)).attr("ry", styleLogic.bind(this._ry)).attr("stroke", styleLogic.bind(this._stroke)).attr("stroke-dasharray", styleLogic.bind(this._strokeDasharray)).attr("stroke-linecap", styleLogic.bind(this._strokeLinecap)).attr("stroke-opacity", styleLogic.bind(this._strokeOpacity)).attr("stroke-width", styleLogic.bind(this._strokeWidth)).attr("vector-effect", styleLogic.bind(this._vectorEffect)); | ||
} | ||
/** | ||
@@ -232,16 +208,10 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._applyTransform = function _applyTransform (elem) { | ||
var this$1 = this; | ||
elem | ||
.attr("transform", function (d, i) { return ("\n translate(" + (d.__d3plusShape__ | ||
? d.translate ? d.translate | ||
: ((this$1._x(d.data, d.i)) + "," + (this$1._y(d.data, d.i))) | ||
: ((this$1._x(d, i)) + "," + (this$1._y(d, i)))) + ")\n scale(" + (d.__d3plusShape__ ? d.scale || this$1._scale(d.data, d.i) | ||
: this$1._scale(d, i)) + ")\n rotate(" + (d.__d3plusShape__ ? d.rotate ? d.rotate | ||
: this$1._rotate(d.data || d, d.i) | ||
: this$1._rotate(d.data || d, d.i)) + ")"); }); | ||
}; | ||
_applyTransform(elem) { | ||
elem.attr("transform", (d, i) => ` | ||
translate(${d.__d3plusShape__ ? d.translate ? d.translate : `${this._x(d.data, d.i)},${this._y(d.data, d.i)}` : `${this._x(d, i)},${this._y(d, i)}`}) | ||
scale(${d.__d3plusShape__ ? d.scale || this._scale(d.data, d.i) : this._scale(d, i)}) | ||
rotate(${d.__d3plusShape__ ? d.rotate ? d.rotate : this._rotate(d.data || d, d.i) : this._rotate(d.data || d, d.i)})`); | ||
} | ||
/** | ||
@@ -253,6 +223,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._nestWrapper = function _nestWrapper (method) { | ||
return function (d, i) { return method(d.__d3plusShape__ ? d.data : d, d.__d3plusShape__ ? d.i : i); }; | ||
}; | ||
_nestWrapper(method) { | ||
return (d, i) => method(d.__d3plusShape__ ? d.data : d, d.__d3plusShape__ ? d.i : i); | ||
} | ||
/** | ||
@@ -263,41 +234,35 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._renderActive = function _renderActive () { | ||
var that = this; | ||
this._group.selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox") | ||
.each(function(d, i) { | ||
_renderActive() { | ||
const that = this; | ||
if (!d) { d = {}; } | ||
if (!d.parentNode) { d.parentNode = this.parentNode; } | ||
var parent = d.parentNode; | ||
this._group.selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function (d, i) { | ||
if (!d) d = {}; | ||
if (!d.parentNode) d.parentNode = this.parentNode; | ||
const parent = d.parentNode; | ||
if (select(this).classed("d3plus-textBox")) d = d.data; | ||
if (select(this).classed("d3plus-textBox")) { d = d.data; } | ||
if (d.__d3plusShape__ || d.__d3plus__) { | ||
while (d && (d.__d3plusShape__ || d.__d3plus__)) { | ||
i = d.i; | ||
d = d.data; | ||
} | ||
if (d.__d3plusShape__ || d.__d3plus__) { | ||
while (d && (d.__d3plusShape__ || d.__d3plus__)) { | ||
i = d.i; | ||
d = d.data; | ||
} | ||
else { i = that._data.indexOf(d); } | ||
} else i = that._data.indexOf(d); | ||
var group = !that._active || typeof that._active !== "function" || !that._active(d, i) ? parent : that._activeGroup.node(); | ||
if (group !== this.parentNode) { | ||
group.appendChild(this); | ||
if (this.className.baseVal.includes("d3plus-Shape")) { | ||
if (parent === group) { select(this).call(that._applyStyle.bind(that)); } | ||
else { select(this).call(that._updateStyle.bind(that, select(this), that._activeStyle)); } | ||
} | ||
} | ||
const group = !that._active || typeof that._active !== "function" || !that._active(d, i) ? parent : that._activeGroup.node(); | ||
}); | ||
if (group !== this.parentNode) { | ||
group.appendChild(this); | ||
// this._renderImage(); | ||
if (this.className.baseVal.includes("d3plus-Shape")) { | ||
if (parent === group) select(this).call(that._applyStyle.bind(that));else select(this).call(that._updateStyle.bind(that, select(this), that._activeStyle)); | ||
} | ||
} | ||
}); // this._renderImage(); | ||
// this._renderLabels(); | ||
this._group.selectAll(("g.d3plus-" + (this._name) + "-shape, g.d3plus-" + (this._name) + "-image, g.d3plus-" + (this._name) + "-text")) | ||
.attr("opacity", this._hover ? this._hoverOpacity : this._active ? this._activeOpacity : 1); | ||
}; | ||
this._group.selectAll(`g.d3plus-${this._name}-shape, g.d3plus-${this._name}-image, g.d3plus-${this._name}-text`).attr("opacity", this._hover ? this._hoverOpacity : this._active ? this._activeOpacity : 1); | ||
} | ||
/** | ||
@@ -308,40 +273,32 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._renderHover = function _renderHover () { | ||
var that = this; | ||
this._group.selectAll(("g.d3plus-" + (this._name) + "-shape, g.d3plus-" + (this._name) + "-image, g.d3plus-" + (this._name) + "-text, g.d3plus-" + (this._name) + "-hover")) | ||
.selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox") | ||
.each(function(d, i) { | ||
_renderHover() { | ||
const that = this; | ||
if (!d) { d = {}; } | ||
if (!d.parentNode) { d.parentNode = this.parentNode; } | ||
var parent = d.parentNode; | ||
this._group.selectAll(`g.d3plus-${this._name}-shape, g.d3plus-${this._name}-image, g.d3plus-${this._name}-text, g.d3plus-${this._name}-hover`).selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function (d, i) { | ||
if (!d) d = {}; | ||
if (!d.parentNode) d.parentNode = this.parentNode; | ||
const parent = d.parentNode; | ||
if (select(this).classed("d3plus-textBox")) d = d.data; | ||
if (select(this).classed("d3plus-textBox")) { d = d.data; } | ||
if (d.__d3plusShape__ || d.__d3plus__) { | ||
while (d && (d.__d3plusShape__ || d.__d3plus__)) { | ||
i = d.i; | ||
d = d.data; | ||
} | ||
if (d.__d3plusShape__ || d.__d3plus__) { | ||
while (d && (d.__d3plusShape__ || d.__d3plus__)) { | ||
i = d.i; | ||
d = d.data; | ||
} | ||
else { i = that._data.indexOf(d); } | ||
} else i = that._data.indexOf(d); | ||
var group = !that._hover || typeof that._hover !== "function" || !that._hover(d, i) ? parent : that._hoverGroup.node(); | ||
if (group !== this.parentNode) { group.appendChild(this); } | ||
if (this.className.baseVal.includes("d3plus-Shape")) { | ||
if (parent === group) { select(this).call(that._applyStyle.bind(that)); } | ||
else { select(this).call(that._updateStyle.bind(that, select(this), that._hoverStyle)); } | ||
} | ||
const group = !that._hover || typeof that._hover !== "function" || !that._hover(d, i) ? parent : that._hoverGroup.node(); | ||
if (group !== this.parentNode) group.appendChild(this); | ||
}); | ||
// this._renderImage(); | ||
if (this.className.baseVal.includes("d3plus-Shape")) { | ||
if (parent === group) select(this).call(that._applyStyle.bind(that));else select(this).call(that._updateStyle.bind(that, select(this), that._hoverStyle)); | ||
} | ||
}); // this._renderImage(); | ||
// this._renderLabels(); | ||
this._group.selectAll(("g.d3plus-" + (this._name) + "-shape, g.d3plus-" + (this._name) + "-image, g.d3plus-" + (this._name) + "-text")) | ||
.attr("opacity", this._hover ? this._hoverOpacity : this._active ? this._activeOpacity : 1); | ||
}; | ||
this._group.selectAll(`g.d3plus-${this._name}-shape, g.d3plus-${this._name}-image, g.d3plus-${this._name}-text`).attr("opacity", this._hover ? this._hoverOpacity : this._active ? this._activeOpacity : 1); | ||
} | ||
/** | ||
@@ -352,67 +309,55 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._renderImage = function _renderImage () { | ||
var this$1 = this; | ||
var imageData = []; | ||
_renderImage() { | ||
const imageData = []; | ||
this._update.merge(this._enter).data() | ||
.forEach(function (datum, i) { | ||
this._update.merge(this._enter).data().forEach((datum, i) => { | ||
const aes = this._aes(datum, i); | ||
var aes = this$1._aes(datum, i); | ||
if (aes.r || aes.width && aes.height) { | ||
let d = datum; | ||
if (aes.r || aes.width && aes.height) { | ||
if (datum.nested && datum.key && datum.values) { | ||
d = datum.values[0]; | ||
i = this._data.indexOf(d); | ||
} | ||
var d = datum; | ||
if (datum.nested && datum.key && datum.values) { | ||
d = datum.values[0]; | ||
i = this$1._data.indexOf(d); | ||
} | ||
const height = aes.r ? aes.r * 2 : aes.height, | ||
url = this._backgroundImage(d, i), | ||
width = aes.r ? aes.r * 2 : aes.width; | ||
var height = aes.r ? aes.r * 2 : aes.height, | ||
url = this$1._backgroundImage(d, i), | ||
width = aes.r ? aes.r * 2 : aes.width; | ||
if (url) { | ||
let x = d.__d3plusShape__ ? d.translate ? d.translate[0] : this._x(d.data, d.i) : this._x(d, i), | ||
y = d.__d3plusShape__ ? d.translate ? d.translate[1] : this._y(d.data, d.i) : this._y(d, i); | ||
if (aes.x) x += aes.x; | ||
if (aes.y) y += aes.y; | ||
if (url) { | ||
var x = d.__d3plusShape__ ? d.translate ? d.translate[0] | ||
: this$1._x(d.data, d.i) : this$1._x(d, i), | ||
y = d.__d3plusShape__ ? d.translate ? d.translate[1] | ||
: this$1._y(d.data, d.i) : this$1._y(d, i); | ||
if (aes.x) { x += aes.x; } | ||
if (aes.y) { y += aes.y; } | ||
if (d.__d3plusShape__) { | ||
d = d.data; | ||
i = d.i; | ||
} | ||
imageData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
height: height, | ||
i: i, | ||
id: this$1._id(d, i), | ||
url: url, | ||
width: width, | ||
x: x + -width / 2, | ||
y: y + -height / 2 | ||
}); | ||
if (d.__d3plusShape__) { | ||
d = d.data; | ||
i = d.i; | ||
} | ||
imageData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
height, | ||
i, | ||
id: this._id(d, i), | ||
url, | ||
width, | ||
x: x + -width / 2, | ||
y: y + -height / 2 | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
this._backgroundImageClass | ||
.data(imageData) | ||
.duration(this._duration) | ||
.pointerEvents("none") | ||
.select(elem(("g.d3plus-" + (this._name) + "-image"), {parent: this._group, update: {opacity: this._active ? this._activeOpacity : 1}}).node()) | ||
.render(); | ||
}; | ||
this._backgroundImageClass.data(imageData).duration(this._duration).pointerEvents("none").select(elem(`g.d3plus-${this._name}-image`, { | ||
parent: this._group, | ||
update: { | ||
opacity: this._active ? this._activeOpacity : 1 | ||
} | ||
}).node()).render(); | ||
} | ||
/** | ||
@@ -423,79 +368,63 @@ @memberof Shape | ||
*/ | ||
Shape.prototype._renderLabels = function _renderLabels () { | ||
var this$1 = this; | ||
var labelData = []; | ||
_renderLabels() { | ||
const labelData = []; | ||
this._update.merge(this._enter).data() | ||
.forEach(function (datum, i) { | ||
this._update.merge(this._enter).data().forEach((datum, i) => { | ||
let d = datum; | ||
var d = datum; | ||
if (datum.nested && datum.key && datum.values) { | ||
d = datum.values[0]; | ||
i = this$1._data.indexOf(d); | ||
} | ||
if (datum.nested && datum.key && datum.values) { | ||
d = datum.values[0]; | ||
i = this._data.indexOf(d); | ||
} | ||
var labels = this$1._label(d, i); | ||
let labels = this._label(d, i); | ||
if (this$1._labelBounds && labels !== false && labels !== undefined && labels !== null) { | ||
if (this._labelBounds && labels !== false && labels !== undefined && labels !== null) { | ||
const bounds = this._labelBounds(d, i, this._aes(datum, i)); | ||
var bounds = this$1._labelBounds(d, i, this$1._aes(datum, i)); | ||
if (bounds) { | ||
if (labels.constructor !== Array) labels = [labels]; | ||
const x = d.__d3plusShape__ ? d.translate ? d.translate[0] : this._x(d.data, d.i) : this._x(d, i), | ||
y = d.__d3plusShape__ ? d.translate ? d.translate[1] : this._y(d.data, d.i) : this._y(d, i); | ||
if (bounds) { | ||
if (d.__d3plusShape__) { | ||
d = d.data; | ||
i = d.i; | ||
} | ||
if (labels.constructor !== Array) { labels = [labels]; } | ||
for (let l = 0; l < labels.length; l++) { | ||
const b = bounds.constructor === Array ? bounds[l] : Object.assign({}, bounds); | ||
var x = d.__d3plusShape__ ? d.translate ? d.translate[0] | ||
: this$1._x(d.data, d.i) : this$1._x(d, i), | ||
y = d.__d3plusShape__ ? d.translate ? d.translate[1] | ||
: this$1._y(d.data, d.i) : this$1._y(d, i); | ||
const rotate = this._rotate(d, i); | ||
if (d.__d3plusShape__) { | ||
d = d.data; | ||
i = d.i; | ||
} | ||
for (var l = 0; l < labels.length; l++) { | ||
var b = bounds.constructor === Array ? bounds[l] : Object.assign({}, bounds); | ||
var rotate = this$1._rotate(d, i); | ||
var r = d.labelConfig && d.labelConfig.rotate ? d.labelConfig.rotate : bounds.angle !== undefined ? bounds.angle : 0; | ||
r += rotate; | ||
var rotateAnchor = rotate !== 0 ? [b.x * -1 || 0, b.y * -1 || 0] : [b.width / 2, b.height / 2]; | ||
labelData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
height: b.height, | ||
l: l, | ||
id: ((this$1._id(d, i)) + "_" + l), | ||
r: r, | ||
rotateAnchor: rotateAnchor, | ||
text: labels[l], | ||
width: b.width, | ||
x: x + b.x, | ||
y: y + b.y | ||
}); | ||
} | ||
let r = d.labelConfig && d.labelConfig.rotate ? d.labelConfig.rotate : bounds.angle !== undefined ? bounds.angle : 0; | ||
r += rotate; | ||
const rotateAnchor = rotate !== 0 ? [b.x * -1 || 0, b.y * -1 || 0] : [b.width / 2, b.height / 2]; | ||
labelData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
height: b.height, | ||
l, | ||
id: `${this._id(d, i)}_${l}`, | ||
r, | ||
rotateAnchor, | ||
text: labels[l], | ||
width: b.width, | ||
x: x + b.x, | ||
y: y + b.y | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
this._labelClass | ||
.data(labelData) | ||
.duration(this._duration) | ||
.pointerEvents("none") | ||
.rotate(function (d) { return d.__d3plus__ ? d.r : d.data.r; }) | ||
.rotateAnchor(function (d) { return d.__d3plus__ ? d.rotateAnchor : d.data.rotateAnchor; }) | ||
.select(elem(("g.d3plus-" + (this._name) + "-text"), {parent: this._group, update: {opacity: this._active ? this._activeOpacity : 1}}).node()) | ||
.config(configPrep.bind(this)(this._labelConfig)) | ||
.render(); | ||
}; | ||
this._labelClass.data(labelData).duration(this._duration).pointerEvents("none").rotate(d => d.__d3plus__ ? d.r : d.data.r).rotateAnchor(d => d.__d3plus__ ? d.rotateAnchor : d.data.rotateAnchor).select(elem(`g.d3plus-${this._name}-text`, { | ||
parent: this._group, | ||
update: { | ||
opacity: this._active ? this._activeOpacity : 1 | ||
} | ||
}).node()).config(configPrep.bind(this)(this._labelConfig)).render(); | ||
} | ||
/** | ||
@@ -507,102 +436,76 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.render = function render (callback) { | ||
var this$1 = this; | ||
render(callback) { | ||
if (this._select === void 0) { | ||
this.select(select("body").append("svg") | ||
.style("width", ((window.innerWidth) + "px")) | ||
.style("height", ((window.innerHeight) + "px")) | ||
.style("display", "block").node()); | ||
this.select(select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node()); | ||
} | ||
this._transition = transition().duration(this._duration); | ||
let data = this._data, | ||
key = this._id; | ||
var data = this._data, key = this._id; | ||
if (this._dataFilter) { | ||
data = this._dataFilter(data); | ||
if (data.key) { key = data.key; } | ||
if (data.key) key = data.key; | ||
} | ||
if (this._sort) { | ||
data = data.sort(function (a, b) { | ||
while (a.__d3plusShape__ || a.__d3plus__) { a = a.data; } | ||
while (b.__d3plusShape__ || b.__d3plus__) { b = b.data; } | ||
return this$1._sort(a, b); | ||
data = data.sort((a, b) => { | ||
while (a.__d3plusShape__ || a.__d3plus__) a = a.data; | ||
while (b.__d3plusShape__ || b.__d3plus__) b = b.data; | ||
return this._sort(a, b); | ||
}); | ||
} | ||
selectAll(("g.d3plus-" + (this._name) + "-hover > *, g.d3plus-" + (this._name) + "-active > *")).each(function(d) { | ||
if (d && d.parentNode) { d.parentNode.appendChild(this); } | ||
else { this.parentNode.removeChild(this); } | ||
selectAll(`g.d3plus-${this._name}-hover > *, g.d3plus-${this._name}-active > *`).each(function (d) { | ||
if (d && d.parentNode) d.parentNode.appendChild(this);else this.parentNode.removeChild(this); | ||
}); // Makes the update state of the group selection accessible. | ||
this._group = elem(`g.d3plus-${this._name}-group`, { | ||
parent: this._select | ||
}); | ||
const update = this._update = elem(`g.d3plus-${this._name}-shape`, { | ||
parent: this._group, | ||
update: { | ||
opacity: this._active ? this._activeOpacity : 1 | ||
} | ||
}).selectAll(`.d3plus-${this._name}`).data(data, key); // Orders and transforms the updating Shapes. | ||
// Makes the update state of the group selection accessible. | ||
this._group = elem(("g.d3plus-" + (this._name) + "-group"), {parent: this._select}); | ||
var update = this._update = elem(("g.d3plus-" + (this._name) + "-shape"), {parent: this._group, update: {opacity: this._active ? this._activeOpacity : 1}}) | ||
.selectAll((".d3plus-" + (this._name))) | ||
.data(data, key); | ||
update.order().transition(this._transition).call(this._applyTransform.bind(this)); // Makes the enter state of the group selection accessible. | ||
// Orders and transforms the updating Shapes. | ||
update.order().transition(this._transition) | ||
.call(this._applyTransform.bind(this)); | ||
const enter = this._enter = update.enter().append(this._tagName).attr("class", (d, i) => `d3plus-Shape d3plus-${this._name} d3plus-id-${strip(this._nestWrapper(this._id)(d, i))}`).call(this._applyTransform.bind(this)).attr("aria-label", this._ariaLabel).attr("role", this._role).attr("opacity", this._nestWrapper(this._opacity)); | ||
const enterUpdate = enter.merge(update); | ||
enterUpdate.attr("shape-rendering", this._nestWrapper(this._shapeRendering)).attr("pointer-events", "none").transition(this._transition).attr("opacity", this._nestWrapper(this._opacity)).attr("pointer-events", this._pointerEvents); // Makes the exit state of the group selection accessible. | ||
// Makes the enter state of the group selection accessible. | ||
var enter = this._enter = update.enter().append(this._tagName) | ||
.attr("class", function (d, i) { return ("d3plus-Shape d3plus-" + (this$1._name) + " d3plus-id-" + (strip(this$1._nestWrapper(this$1._id)(d, i)))); }) | ||
.call(this._applyTransform.bind(this)) | ||
.attr("aria-label", this._ariaLabel) | ||
.attr("role", this._role) | ||
.attr("opacity", this._nestWrapper(this._opacity)); | ||
var enterUpdate = enter.merge(update); | ||
enterUpdate | ||
.attr("shape-rendering", this._nestWrapper(this._shapeRendering)) | ||
.attr("pointer-events", "none") | ||
.transition(this._transition) | ||
.attr("opacity", this._nestWrapper(this._opacity)) | ||
.attr("pointer-events", this._pointerEvents); | ||
// Makes the exit state of the group selection accessible. | ||
var exit = this._exit = update.exit(); | ||
const exit = this._exit = update.exit(); | ||
exit.transition().delay(this._duration).remove(); | ||
this._renderImage(); | ||
this._renderLabels(); | ||
this._hoverGroup = elem(("g.d3plus-" + (this._name) + "-hover"), {parent: this._group}); | ||
this._activeGroup = elem(("g.d3plus-" + (this._name) + "-active"), {parent: this._group}); | ||
this._hoverGroup = elem(`g.d3plus-${this._name}-hover`, { | ||
parent: this._group | ||
}); | ||
this._activeGroup = elem(`g.d3plus-${this._name}-active`, { | ||
parent: this._group | ||
}); | ||
var hitAreas = this._group.selectAll(".d3plus-HitArea") | ||
.data(this._hitArea ? data : [], key); | ||
const hitAreas = this._group.selectAll(".d3plus-HitArea").data(this._hitArea ? data : [], key); | ||
hitAreas.order() | ||
.call(this._applyTransform.bind(this)); | ||
hitAreas.order().call(this._applyTransform.bind(this)); | ||
const isLine = this._name === "Line"; | ||
isLine && this._path.curve(paths[`curve${this._curve.charAt(0).toUpperCase()}${this._curve.slice(1)}`]).defined(this._defined).x(this._x).y(this._y); | ||
const hitEnter = hitAreas.enter().append(isLine ? "path" : "rect").attr("class", (d, i) => `d3plus-HitArea d3plus-id-${strip(this._nestWrapper(this._id)(d, i))}`).attr("fill", "black").attr("stroke", "black").attr("pointer-events", "painted").attr("opacity", 0).call(this._applyTransform.bind(this)); | ||
const that = this; | ||
const hitUpdates = hitAreas.merge(hitEnter).each(function (d) { | ||
const i = that._data.indexOf(d); | ||
var isLine = this._name === "Line"; | ||
const h = that._hitArea(d, i, that._aes(d, i)); | ||
isLine && this._path | ||
.curve(paths[("curve" + (this._curve.charAt(0).toUpperCase()) + (this._curve.slice(1)))]) | ||
.defined(this._defined) | ||
.x(this._x) | ||
.y(this._y); | ||
var hitEnter = hitAreas.enter().append(isLine ? "path" : "rect") | ||
.attr("class", function (d, i) { return ("d3plus-HitArea d3plus-id-" + (strip(this$1._nestWrapper(this$1._id)(d, i)))); }) | ||
.attr("fill", "black") | ||
.attr("stroke", "black") | ||
.attr("pointer-events", "painted") | ||
.attr("opacity", 0) | ||
.call(this._applyTransform.bind(this)); | ||
var that = this; | ||
var hitUpdates = hitAreas.merge(hitEnter) | ||
.each(function(d) { | ||
var i = that._data.indexOf(d); | ||
var h = that._hitArea(d, i, that._aes(d, i)); | ||
return h && !(that._name === "Line" && parseFloat(that._strokeWidth(d, i)) > 10) ? select(this).call(attrize, h) : select(this).remove(); | ||
}); | ||
return h && !(that._name === "Line" && parseFloat(that._strokeWidth(d, i)) > 10) ? select(this).call(attrize, h) : select(this).remove(); | ||
}); | ||
hitAreas.exit().remove(); | ||
@@ -612,12 +515,8 @@ | ||
setTimeout(function () { | ||
if (this$1._active) { this$1._renderActive(); } | ||
else if (this$1._hover) { this$1._renderHover(); } | ||
if (callback) { callback(); } | ||
setTimeout(() => { | ||
if (this._active) this._renderActive();else if (this._hover) this._renderHover(); | ||
if (callback) callback(); | ||
}, this._duration + 100); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -629,6 +528,8 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.active = function active (_) { | ||
if (!arguments.length || _ === undefined) { return this._active; } | ||
active(_) { | ||
if (!arguments.length || _ === undefined) return this._active; | ||
this._active = _; | ||
if (this._group) { | ||
@@ -639,6 +540,5 @@ // this._renderImage(); | ||
} | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -650,6 +550,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.activeOpacity = function activeOpacity (_) { | ||
activeOpacity(_) { | ||
return arguments.length ? (this._activeOpacity = _, this) : this._activeOpacity; | ||
}; | ||
} | ||
/** | ||
@@ -661,6 +562,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.activeStyle = function activeStyle (_) { | ||
activeStyle(_) { | ||
return arguments.length ? (this._activeStyle = assign({}, this._activeStyle, _), this) : this._activeStyle; | ||
}; | ||
} | ||
/** | ||
@@ -672,8 +574,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.ariaLabel = function ariaLabel (_) { | ||
return _ !== undefined | ||
? (this._ariaLabel = typeof _ === "function" ? _ : constant(_), this) | ||
: this._ariaLabel; | ||
}; | ||
ariaLabel(_) { | ||
return _ !== undefined ? (this._ariaLabel = typeof _ === "function" ? _ : constant(_), this) : this._ariaLabel; | ||
} | ||
/** | ||
@@ -685,8 +586,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.backgroundImage = function backgroundImage (_) { | ||
return arguments.length | ||
? (this._backgroundImage = typeof _ === "function" ? _ : constant(_), this) | ||
: this._backgroundImage; | ||
}; | ||
backgroundImage(_) { | ||
return arguments.length ? (this._backgroundImage = typeof _ === "function" ? _ : constant(_), this) : this._backgroundImage; | ||
} | ||
/** | ||
@@ -698,8 +598,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.data = function data (_) { | ||
return arguments.length | ||
? (this._data = _, this) | ||
: this._data; | ||
}; | ||
data(_) { | ||
return arguments.length ? (this._data = _, this) : this._data; | ||
} | ||
/** | ||
@@ -711,8 +610,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.duration = function duration (_) { | ||
return arguments.length | ||
? (this._duration = _, this) | ||
: this._duration; | ||
}; | ||
duration(_) { | ||
return arguments.length ? (this._duration = _, this) : this._duration; | ||
} | ||
/** | ||
@@ -724,8 +622,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.fill = function fill (_) { | ||
return arguments.length | ||
? (this._fill = typeof _ === "function" ? _ : constant(_), this) | ||
: this._fill; | ||
}; | ||
fill(_) { | ||
return arguments.length ? (this._fill = typeof _ === "function" ? _ : constant(_), this) : this._fill; | ||
} | ||
/** | ||
@@ -737,8 +634,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.fillOpacity = function fillOpacity (_) { | ||
return arguments.length | ||
? (this._fillOpacity = typeof _ === "function" ? _ : constant(_), this) | ||
: this._fillOpacity; | ||
}; | ||
fillOpacity(_) { | ||
return arguments.length ? (this._fillOpacity = typeof _ === "function" ? _ : constant(_), this) : this._fillOpacity; | ||
} | ||
/** | ||
@@ -750,6 +646,8 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.hover = function hover (_) { | ||
if (!arguments.length || _ === void 0) { return this._hover; } | ||
hover(_) { | ||
if (!arguments.length || _ === void 0) return this._hover; | ||
this._hover = _; | ||
if (this._group) { | ||
@@ -760,6 +658,5 @@ // this._renderImage(); | ||
} | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -771,6 +668,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.hoverStyle = function hoverStyle (_) { | ||
hoverStyle(_) { | ||
return arguments.length ? (this._hoverStyle = assign({}, this._hoverStyle, _), this) : this._hoverStyle; | ||
}; | ||
} | ||
/** | ||
@@ -782,6 +680,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.hoverOpacity = function hoverOpacity (_) { | ||
hoverOpacity(_) { | ||
return arguments.length ? (this._hoverOpacity = _, this) : this._hoverOpacity; | ||
}; | ||
} | ||
/** | ||
@@ -793,3 +692,3 @@ @memberof Shape | ||
@example | ||
function(d, i, shape) { | ||
function(d, i, shape) { | ||
return { | ||
@@ -801,8 +700,9 @@ "width": shape.width, | ||
}; | ||
} | ||
} | ||
*/ | ||
Shape.prototype.hitArea = function hitArea (_) { | ||
hitArea(_) { | ||
return arguments.length ? (this._hitArea = typeof _ === "function" ? _ : constant(_), this) : this._hitArea; | ||
}; | ||
} | ||
/** | ||
@@ -814,6 +714,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.id = function id (_) { | ||
id(_) { | ||
return arguments.length ? (this._id = _, this) : this._id; | ||
}; | ||
} | ||
/** | ||
@@ -825,6 +726,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.label = function label (_) { | ||
label(_) { | ||
return arguments.length ? (this._label = typeof _ === "function" ? _ : constant(_), this) : this._label; | ||
}; | ||
} | ||
/** | ||
@@ -836,3 +738,3 @@ @memberof Shape | ||
@example | ||
function(d, i, shape) { | ||
function(d, i, shape) { | ||
return { | ||
@@ -844,8 +746,9 @@ "width": shape.width, | ||
}; | ||
} | ||
} | ||
*/ | ||
Shape.prototype.labelBounds = function labelBounds (_) { | ||
labelBounds(_) { | ||
return arguments.length ? (this._labelBounds = typeof _ === "function" ? _ : constant(_), this) : this._labelBounds; | ||
}; | ||
} | ||
/** | ||
@@ -857,6 +760,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.labelConfig = function labelConfig (_) { | ||
labelConfig(_) { | ||
return arguments.length ? (this._labelConfig = assign(this._labelConfig, _), this) : this._labelConfig; | ||
}; | ||
} | ||
/** | ||
@@ -868,6 +772,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.opacity = function opacity (_) { | ||
opacity(_) { | ||
return arguments.length ? (this._opacity = typeof _ === "function" ? _ : constant(_), this) : this._opacity; | ||
}; | ||
} | ||
/** | ||
@@ -879,6 +784,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.pointerEvents = function pointerEvents (_) { | ||
pointerEvents(_) { | ||
return arguments.length ? (this._pointerEvents = typeof _ === "function" ? _ : constant(_), this) : this._pointerEvents; | ||
}; | ||
} | ||
/** | ||
@@ -890,8 +796,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.role = function role (_) { | ||
return _ !== undefined | ||
? (this._role = typeof _ === "function" ? _ : constant(_), this) | ||
: this._role; | ||
}; | ||
role(_) { | ||
return _ !== undefined ? (this._role = typeof _ === "function" ? _ : constant(_), this) : this._role; | ||
} | ||
/** | ||
@@ -903,6 +808,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.rotate = function rotate (_) { | ||
rotate(_) { | ||
return arguments.length ? (this._rotate = typeof _ === "function" ? _ : constant(_), this) : this._rotate; | ||
}; | ||
} | ||
/** | ||
@@ -914,6 +820,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.rx = function rx (_) { | ||
rx(_) { | ||
return arguments.length ? (this._rx = typeof _ === "function" ? _ : constant(_), this) : this._rx; | ||
}; | ||
} | ||
/** | ||
@@ -925,6 +832,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.ry = function ry (_) { | ||
ry(_) { | ||
return arguments.length ? (this._ry = typeof _ === "function" ? _ : constant(_), this) : this._ry; | ||
}; | ||
} | ||
/** | ||
@@ -936,6 +844,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.scale = function scale (_) { | ||
scale(_) { | ||
return arguments.length ? (this._scale = typeof _ === "function" ? _ : constant(_), this) : this._scale; | ||
}; | ||
} | ||
/** | ||
@@ -947,6 +856,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.select = function select$1 (_) { | ||
select(_) { | ||
return arguments.length ? (this._select = select(_), this) : this._select; | ||
}; | ||
} | ||
/** | ||
@@ -958,10 +868,11 @@ @memberof Shape | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.x; | ||
} | ||
} | ||
*/ | ||
Shape.prototype.shapeRendering = function shapeRendering (_) { | ||
shapeRendering(_) { | ||
return arguments.length ? (this._shapeRendering = typeof _ === "function" ? _ : constant(_), this) : this._shapeRendering; | ||
}; | ||
} | ||
/** | ||
@@ -973,6 +884,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.sort = function sort (_) { | ||
sort(_) { | ||
return arguments.length ? (this._sort = _, this) : this._sort; | ||
}; | ||
} | ||
/** | ||
@@ -984,6 +896,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.stroke = function stroke (_) { | ||
stroke(_) { | ||
return arguments.length ? (this._stroke = typeof _ === "function" ? _ : constant(_), this) : this._stroke; | ||
}; | ||
} | ||
/** | ||
@@ -995,6 +908,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.strokeDasharray = function strokeDasharray (_) { | ||
strokeDasharray(_) { | ||
return arguments.length ? (this._strokeDasharray = typeof _ === "function" ? _ : constant(_), this) : this._strokeDasharray; | ||
}; | ||
} | ||
/** | ||
@@ -1006,6 +920,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.strokeLinecap = function strokeLinecap (_) { | ||
strokeLinecap(_) { | ||
return arguments.length ? (this._strokeLinecap = typeof _ === "function" ? _ : constant(_), this) : this._strokeLinecap; | ||
}; | ||
} | ||
/** | ||
@@ -1017,6 +932,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.strokeOpacity = function strokeOpacity (_) { | ||
strokeOpacity(_) { | ||
return arguments.length ? (this._strokeOpacity = typeof _ === "function" ? _ : constant(_), this) : this._strokeOpacity; | ||
}; | ||
} | ||
/** | ||
@@ -1028,6 +944,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.strokeWidth = function strokeWidth (_) { | ||
strokeWidth(_) { | ||
return arguments.length ? (this._strokeWidth = typeof _ === "function" ? _ : constant(_), this) : this._strokeWidth; | ||
}; | ||
} | ||
/** | ||
@@ -1039,6 +956,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.textAnchor = function textAnchor (_) { | ||
textAnchor(_) { | ||
return arguments.length ? (this._textAnchor = typeof _ === "function" ? _ : constant(_), this) : this._textAnchor; | ||
}; | ||
} | ||
/** | ||
@@ -1050,6 +968,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.vectorEffect = function vectorEffect (_) { | ||
vectorEffect(_) { | ||
return arguments.length ? (this._vectorEffect = typeof _ === "function" ? _ : constant(_), this) : this._vectorEffect; | ||
}; | ||
} | ||
/** | ||
@@ -1061,6 +980,7 @@ @memberof Shape | ||
*/ | ||
Shape.prototype.verticalAlign = function verticalAlign (_) { | ||
verticalAlign(_) { | ||
return arguments.length ? (this._verticalAlign = typeof _ === "function" ? _ : constant(_), this) : this._verticalAlign; | ||
}; | ||
} | ||
/** | ||
@@ -1072,10 +992,11 @@ @memberof Shape | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.x; | ||
} | ||
} | ||
*/ | ||
Shape.prototype.x = function x (_) { | ||
x(_) { | ||
return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x; | ||
}; | ||
} | ||
/** | ||
@@ -1087,15 +1008,12 @@ @memberof Shape | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.y; | ||
} | ||
} | ||
*/ | ||
Shape.prototype.y = function y (_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
}; | ||
return Shape; | ||
}(BaseClass)); | ||
export default Shape; | ||
y(_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
} | ||
//# sourceMappingURL=Shape.js.map | ||
} |
@@ -1,12 +0,11 @@ | ||
import {select} from "d3-selection"; | ||
import {accessor, assign, BaseClass, configPrep, constant, elem} from "d3plus-common"; | ||
import {nest} from "d3-collection"; | ||
import { select } from "d3-selection"; | ||
import { accessor, assign, BaseClass, configPrep, constant, elem } from "d3plus-common"; | ||
import { nest } from "d3-collection"; | ||
import Circle from "./Circle"; | ||
import Line from "./Line"; | ||
import Rect from "./Rect"; | ||
var shapes = {Circle: Circle, Rect: Rect}; | ||
const shapes = { | ||
Circle, | ||
Rect | ||
}; | ||
/** | ||
@@ -17,7 +16,11 @@ @class Whisker | ||
*/ | ||
var Whisker = /*@__PURE__*/(function (BaseClass) { | ||
function Whisker() { | ||
BaseClass.call(this); | ||
export default class Whisker extends BaseClass { | ||
/** | ||
@memberof Whisker | ||
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from BaseClass. | ||
@private | ||
*/ | ||
constructor() { | ||
super(); | ||
this._endpoint = accessor("endpoint", "Rect"); | ||
@@ -34,9 +37,3 @@ this._endpointConfig = { | ||
this._y = accessor("y", 0); | ||
} | ||
if ( BaseClass ) Whisker.__proto__ = BaseClass; | ||
Whisker.prototype = Object.create( BaseClass && BaseClass.prototype ); | ||
Whisker.prototype.constructor = Whisker; | ||
/** | ||
@@ -48,86 +45,80 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.render = function render (callback) { | ||
var this$1 = this; | ||
render(callback) { | ||
if (this._select === void 0) { | ||
this.select(select("body").append("svg") | ||
.style("width", ((window.innerWidth) + "px")) | ||
.style("height", ((window.innerHeight) + "px")) | ||
.style("display", "block").node()); | ||
this.select(select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node()); | ||
} | ||
var lineData = []; | ||
this._data.forEach(function (d, i) { | ||
const lineData = []; | ||
var orient = this$1._orient(d, i); | ||
var x = this$1._x(d, i); | ||
var y = this$1._y(d, i); | ||
this._data.forEach((d, i) => { | ||
const orient = this._orient(d, i); | ||
var endpointX = x; | ||
if (orient === "left") { endpointX -= this$1._length(d, i); } | ||
else if (orient === "right") { endpointX += this$1._length(d, i); } | ||
const x = this._x(d, i); | ||
var endpointY = y; | ||
if (orient === "top") { endpointY -= this$1._length(d, i); } | ||
else if (orient === "bottom") { endpointY += this$1._length(d, i); } | ||
const y = this._y(d, i); | ||
lineData.push({__d3plus__: true, data: d, i: i, id: i, x: x, y: y}); | ||
lineData.push({__d3plus__: true, data: d, i: i, id: i, x: endpointX, y: endpointY}); | ||
}); | ||
let endpointX = x; | ||
if (orient === "left") endpointX -= this._length(d, i);else if (orient === "right") endpointX += this._length(d, i); | ||
let endpointY = y; | ||
if (orient === "top") endpointY -= this._length(d, i);else if (orient === "bottom") endpointY += this._length(d, i); | ||
lineData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
id: i, | ||
x, | ||
y | ||
}); | ||
lineData.push({ | ||
__d3plus__: true, | ||
data: d, | ||
i, | ||
id: i, | ||
x: endpointX, | ||
y: endpointY | ||
}); | ||
}); // Draw whisker line. | ||
// Draw whisker line. | ||
this._line = new Line() | ||
.data(lineData) | ||
.select(elem("g.d3plus-Whisker", {parent: this._select}).node()) | ||
.config(configPrep.bind(this)(this._lineConfig, "shape")) | ||
.render(callback); | ||
var whiskerData = this._data.map(function (d, i) { | ||
this._line = new Line().data(lineData).select(elem("g.d3plus-Whisker", { | ||
parent: this._select | ||
}).node()).config(configPrep.bind(this)(this._lineConfig, "shape")).render(callback); | ||
var dataObj = {}; | ||
const whiskerData = this._data.map((d, i) => { | ||
const dataObj = {}; | ||
dataObj.__d3plus__ = true; | ||
dataObj.data = d; | ||
dataObj.i = i; | ||
dataObj.endpoint = this$1._endpoint(d, i); | ||
dataObj.length = this$1._length(d, i); | ||
dataObj.orient = this$1._orient(d, i); | ||
dataObj.endpoint = this._endpoint(d, i); | ||
dataObj.length = this._length(d, i); | ||
dataObj.orient = this._orient(d, i); | ||
var endpointX = this$1._x(d, i); | ||
if (dataObj.orient === "left") { endpointX -= dataObj.length; } | ||
else if (dataObj.orient === "right") { endpointX += dataObj.length; } | ||
let endpointX = this._x(d, i); | ||
var endpointY = this$1._y(d, i); | ||
if (dataObj.orient === "top") { endpointY -= dataObj.length; } | ||
else if (dataObj.orient === "bottom") { endpointY += dataObj.length; } | ||
if (dataObj.orient === "left") endpointX -= dataObj.length;else if (dataObj.orient === "right") endpointX += dataObj.length; | ||
let endpointY = this._y(d, i); | ||
if (dataObj.orient === "top") endpointY -= dataObj.length;else if (dataObj.orient === "bottom") endpointY += dataObj.length; | ||
dataObj.x = endpointX; | ||
dataObj.y = endpointY; | ||
return dataObj; | ||
}); // Draw whisker endpoint. | ||
}); | ||
// Draw whisker endpoint. | ||
this._whiskerEndpoint = []; | ||
nest() | ||
.key(function (d) { return d.endpoint; }) | ||
.entries(whiskerData) | ||
.forEach(function (shapeData) { | ||
var shapeName = shapeData.key; | ||
this$1._whiskerEndpoint.push(new shapes[shapeName]() | ||
.data(shapeData.values) | ||
.select(elem(("g.d3plus-Whisker-Endpoint-" + shapeName), {parent: this$1._select}).node()) | ||
.config({ | ||
height: function (d) { return d.orient === "top" || d.orient === "bottom" ? 5 : 20; }, | ||
width: function (d) { return d.orient === "top" || d.orient === "bottom" ? 20 : 5; } | ||
}) | ||
.config(configPrep.bind(this$1)(this$1._endpointConfig, "shape", shapeName)) | ||
.render()); | ||
}); | ||
nest().key(d => d.endpoint).entries(whiskerData).forEach(shapeData => { | ||
const shapeName = shapeData.key; | ||
this._whiskerEndpoint.push(new shapes[shapeName]().data(shapeData.values).select(elem(`g.d3plus-Whisker-Endpoint-${shapeName}`, { | ||
parent: this._select | ||
}).node()).config({ | ||
height: d => d.orient === "top" || d.orient === "bottom" ? 5 : 20, | ||
width: d => d.orient === "top" || d.orient === "bottom" ? 20 : 5 | ||
}).config(configPrep.bind(this)(this._endpointConfig, "shape", shapeName)).render()); | ||
}); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -139,7 +130,8 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.active = function active (_) { | ||
if (this._line) { this._line.active(_); } | ||
if (this._whiskerEndpoint) { this._whiskerEndpoint.forEach(function (endPoint) { return endPoint.active(_); }); } | ||
}; | ||
active(_) { | ||
if (this._line) this._line.active(_); | ||
if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(endPoint => endPoint.active(_)); | ||
} | ||
/** | ||
@@ -151,6 +143,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.data = function data (_) { | ||
data(_) { | ||
return arguments.length ? (this._data = _, this) : this._data; | ||
}; | ||
} | ||
/** | ||
@@ -162,6 +155,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.endpoint = function endpoint (_) { | ||
endpoint(_) { | ||
return arguments.length ? (this._endpoint = typeof _ === "function" ? _ : constant(_), this) : this._endpoint; | ||
}; | ||
} | ||
/** | ||
@@ -173,6 +167,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.endpointConfig = function endpointConfig (_) { | ||
endpointConfig(_) { | ||
return arguments.length ? (this._endpointConfig = assign(this._endpointConfig, _), this) : this._endpointConfig; | ||
}; | ||
} | ||
/** | ||
@@ -184,7 +179,8 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.hover = function hover (_) { | ||
if (this._line) { this._line.hover(_); } | ||
if (this._whiskerEndpoint) { this._whiskerEndpoint.forEach(function (endPoint) { return endPoint.hover(_); }); } | ||
}; | ||
hover(_) { | ||
if (this._line) this._line.hover(_); | ||
if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(endPoint => endPoint.hover(_)); | ||
} | ||
/** | ||
@@ -196,6 +192,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.length = function length (_) { | ||
length(_) { | ||
return arguments.length ? (this._length = typeof _ === "function" ? _ : constant(_), this) : this._length; | ||
}; | ||
} | ||
/** | ||
@@ -207,6 +204,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.lineConfig = function lineConfig (_) { | ||
lineConfig(_) { | ||
return arguments.length ? (this._lineConfig = assign(this._lineConfig, _), this) : this._lineConfig; | ||
}; | ||
} | ||
/** | ||
@@ -218,6 +216,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.orient = function orient (_) { | ||
orient(_) { | ||
return arguments.length ? (this._orient = typeof _ === "function" ? _ : constant(_), this) : this._orient; | ||
}; | ||
} | ||
/** | ||
@@ -229,6 +228,7 @@ @memberof Whisker | ||
*/ | ||
Whisker.prototype.select = function select$1 (_) { | ||
select(_) { | ||
return arguments.length ? (this._select = select(_), this) : this._select; | ||
}; | ||
} | ||
/** | ||
@@ -240,10 +240,11 @@ @memberof Whisker | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.x; | ||
} | ||
} | ||
*/ | ||
Whisker.prototype.x = function x (_) { | ||
x(_) { | ||
return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x; | ||
}; | ||
} | ||
/** | ||
@@ -255,15 +256,12 @@ @memberof Whisker | ||
@example | ||
function(d) { | ||
function(d) { | ||
return d.y; | ||
} | ||
} | ||
*/ | ||
Whisker.prototype.y = function y (_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
}; | ||
return Whisker; | ||
}(BaseClass)); | ||
export default Whisker; | ||
y(_) { | ||
return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y; | ||
} | ||
//# sourceMappingURL=Whisker.js.map | ||
} |
{ | ||
"name": "d3plus-shape", | ||
"version": "0.16.8", | ||
"version": "0.16.9", | ||
"description": "Fancy SVG shapes for visualizations", | ||
@@ -28,11 +28,11 @@ "main": "build/d3plus-shape.js", | ||
"d3-collection": "^1.0.7", | ||
"d3-color": "^1.2.3", | ||
"d3-interpolate-path": "^2.0.1", | ||
"d3-color": "^1.2.8", | ||
"d3-interpolate-path": "^2.1.0", | ||
"d3-polygon": "^1.0.5", | ||
"d3-selection": "^1.4.0", | ||
"d3-shape": "^1.3.4", | ||
"d3-shape": "^1.3.5", | ||
"d3-transition": "^1.2.0", | ||
"d3plus-color": "^0.6.4", | ||
"d3plus-common": "^0.6.47", | ||
"d3plus-text": "^0.9.43" | ||
"d3plus-color": "^0.6.5", | ||
"d3plus-common": "^0.6.50", | ||
"d3plus-text": "^0.9.44" | ||
}, | ||
@@ -49,3 +49,3 @@ "scripts": { | ||
"devDependencies": { | ||
"d3plus-dev": "^0.6.18" | ||
"d3plus-dev": "^0.7.1" | ||
}, | ||
@@ -52,0 +52,0 @@ "module": "es/index", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7012
629100
30
2
Updatedd3-color@^1.2.8
Updatedd3-interpolate-path@^2.1.0
Updatedd3-shape@^1.3.5
Updatedd3plus-color@^0.6.5
Updatedd3plus-common@^0.6.50
Updatedd3plus-text@^0.9.44