dchart-core
Advanced tools
Comparing version 2.8.1 to 2.8.4
@@ -1,1 +0,1 @@ | ||
"use strict";function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,i=new Array(t.length);e<t.length;e++)i[e]=t[e];return i}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var i=[],n=!0,s=!1,a=void 0;try{for(var r,o=t[Symbol.iterator]();!(n=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);n=!0);}catch(t){s=!0,a=t}finally{try{n||null==o.return||o.return()}finally{if(s)throw a}}return i}}function _arrayWithHoles(t){if(Array.isArray(t))return t}var _=require("../util"),Com=require("./index"),d3=require("d3"),numberUtil=require("../util/number"),TICK_PADDING=2,MAX_TICK_COUNT=30,ONE_SECOND=1e3,timeUnitsMSMap={seconds:ONE_SECOND,minutes:60*ONE_SECOND,hours:60*ONE_SECOND*60,days:60*ONE_SECOND*60*24,months:60*ONE_SECOND*60*24*30,years:60*ONE_SECOND*60*24*30*12};function Axis(t,e,i){this.reset(),this.options={fontSize:12,fontColor:"#fff",fontWeight:"normal",fontStrokeWidth:0,key:"x",type:"defaults",orient:null,dy:0,padding:.4,groupPadding:[.4,.4],assistLine:!0,assistLineColor:"#fff",rotate:0,min:null,max:null,maxLabel:!1,tickSize:0,tickValues:null,tickFormat:null,ticks:null,nondecile:{key:"y",tickPadding:10},format:"%Y-%m-%d",label:null,labelColor:"#aaa",labelInAxis:!0,labelFontSize:12,labelFontWeight:"normal",labelFontStrokeWidth:0,textAnchor:"middle",textShow:!0,net:!1,netColor:"#aaa",digit:0,show:!0},this.x=null,this.axisx=null,this.groupX=null,this.net=null,this.init(t,e,i),this._valid()}function getStep(t){var e=t.step,i=t.f,n=t.maxNeedNice,s=t.tickFormat,a="string"==typeof s?(s.split(".")[1]||"0f").split("f")[0]:0;return e=n?i(Math.ceil(Math.pow(10,a)*e)/Math.pow(10,a)):i(10*e)/10}function isTicksOverlap(t,e){if(t&&e&&t.getBoundingClientRect&&e.getBoundingClientRect){var i=t.getBoundingClientRect(),n=e.getBoundingClientRect();return i.left+i.width+TICK_PADDING>n.left&&n.left+n.width+TICK_PADDING>i.left&&i.top+i.height+TICK_PADDING>n.top&&n.top+n.height+TICK_PADDING>i.top}return!1}function removeOverlapTicksOfTargetAxis(t,e){return new Promise((function(i,n){if(!t)return i();var s=t.selectAll(".tick")[0],a=[];if(e.maxLabel)for(var r=s.length-1;r>=0;r--){var o=s[r],l=s[r-1];if(o&&l&&o.getBoundingClientRect&&l.getBoundingClientRect)for(;isTicksOverlap(o,l)&&(d3.select(l).remove(),l=s[--r-1]););}else for(r=0;r<s.length;r++){var h=s[r],c=s[r+1];if(h&&c&&h.getBoundingClientRect&&c.getBoundingClientRect)for(;isTicksOverlap(h,c)&&(d3.select(c).remove(),c=s[++r+1]););}return t.selectAll(".tick")[0].forEach((function(t){a.push(t.__data__)})),i(a)}))}Axis=Com.extend(Axis,{init:function(t,e,i){if(!t&&!this.el)return!1;t&&(this.elContainer=d3.select(t)),this.options&&_.toLower(this.options.type)!==_.toLower(e.type)?this.isReset=!0:this.isReset=!1,this.options=_.deepMerge(this.options,e),this.alloptions=i||this.alloptions},_valid:function(){var t=this.options,e=["defaults","category","time","nondecile"];-1===_.indexOf(e,t.type.toLowerCase())&&(this.msg="axis arguments error. there is no "+t.type+" in types.",t.type=e[0],this.valid=!1),t.type=_.initialUpperCase(t.type);var i=["left","top","right","bottom"];-1===_.indexOf(i,t.orient.toLowerCase())&&(this.msg="axis arguments error. there is no "+t.orient+" in orients.",t.orient=i[0],this.valid=!1),t.orient=_.initialUpperCase(t.orient)},renderSeries:function(){var t=this.options;this["cal"+t.orient](),this.__el||(this.__el=this.elContainer.append("g").attr({class:"virtual_axis",opacity:0}).call(this.axisx)),this.renderStyle(),this.renderLabel(),"function"==typeof t.afterRender&&t.afterRender.call(this),this.el.selectAll(".tick line").style("display",t.net?"block":"none"),this.isReset=!1},cut:function(t,e,i){var n=_slicedToArray(t,2),s=n[0],a=n[1],r=d3.format(i),o=this.options.maxNeedNice,l=((a=+a||0)-(s=+s||0))/(e-1);l=getStep({step:l,f:r,maxNeedNice:o,tickFormat:i}),t=[],+s==+r(s)&&t.push(s);for(var h=0;h<e-1;h++){var c=r(s+l*(h+1));(c<=a||o)&&t.push(c)}var d=(t=(t=_.uniq(t.map((function(t){return+t})).sort((function(t,e){return t-e})))).filter((function(t){return t<=(o?2*a:a)}))).length-e,u=r(a),f=r(s);return d>0?t.splice(e-1,t.length-e):0===d?t[t.length-1]<u&&(t[t.length-1]=u):d<0&&(t.push(u),t.push(f)),t},format:function(){var t=this,e=this.options,i=this.axisx,n=this.x;i.tickPadding(e.dy),"object"===_typeof(e.tickSize)?i.tickSize.apply(this,e.tickSize):i.tickSize(e.tickSize),e.tickValues&&i.tickValues(e.tickValues);var s=!1;if(e.ticks){if("Category"===e.type&&_.isNumber(e.ticks)){var a=this._data;e.tickFormat=function(t,i){var n=_.toNumber(e.ticks),s=a.length,r=parseInt((s-1)/(n-1));if(0===r)return t;var o=(s-1)%(n-1),l=parseInt(o%2&&o/2+1||o/2);return i<l?"":s-i<=o-l?"":(i-l)%r?"":t},i.ticks.apply(this,[e.ticks])}else if("array"==typeof e.ticks)i.ticks.apply(this,e.ticks);else if(_.isNumber(e.ticks))if("Time"!==e.type)if(e.ticks=_.toNumber(e.ticks),"string"==typeof e.tickFormat){var r=_.clone(n.domain());switch(e.ticks){case 0:i.tickValues([r[0]]);break;case 1:i.tickValues([r[1]]);break;default:if(e.tickFormat){var o=_slicedToArray(r,2),l=o[0],h=o[1];if(r=this.cut(r,e.ticks,e.tickFormat),"defaults"===e.type.toLocaleLowerCase()){var c=+d3.format(e.tickFormat)(h),d=+d3.format(e.tickFormat)(l);r=r.filter((function(t){return+t==+d3.format(e.tickFormat)(t)&&t<=c&&t>=d}))}}i.tickValues(r)}setTimeout((function(){var e=t.el&&t.el.selectAll(".tick")[0];if(e&&e.length>1){var i=e[e.length-2];isTicksOverlap(i,e[e.length-1])&&d3.select(i).remove()}}),0)}else i.ticks(e.ticks),s=!0;else{var u=_slicedToArray(this._getTimeAxisExtent(),2),f=(u[0],u[1]),p=Math.min(MAX_TICK_COUNT,e.ticks);i.ticks(p),e.maxLabel&&i.tickValues([].concat(_toConsumableArray(i.scale().ticks()),[f])),s=!0}}else if(_.isNumber(e.ticks)&&"time"===e.type.toLowerCase()){var m=5*e.tickFormat(new Date).length+5,g=Math.min(e.innerWidth/m||10,MAX_TICK_COUNT);if(this._data.length<g){var y=e.tickFormat;"function"!=typeof y&&(y=d3.format(y));var x=d3.time.format(e.format),k=[],v=[],b=e.key;this._data.map((function(t){var e=x.parse(t[b]);-1===v.indexOf(y(e))&&(v.push(y(e)),k.push(e))})),i.tickValues(k)}else i.ticks(g);s=!0}if("string"==typeof e.tickFormat)i.tickFormat(d3.format(e.tickFormat));else if("function"==typeof e.tickFormat){var A=this;i.tickFormat((function(t,i){return e.tickFormat.call(A._data[i],t,i)}))}s?setTimeout((function(){removeOverlapTicksOfTargetAxis(t.__el,e).then((function(s){if(s&&s.length){var a=d3.svg.axis().scale(n).orient(i.orient()).tickPadding(e.dy).tickFormat(i.tickFormat()).tickValues(s).tickSize(0);t.el.call(a),t.renderStyle()}}))}),0):this.el&&this.el.call(i)},_afterAxis:function(){var t=this.options;"function"==typeof t._afterAxis&&t._afterAxis.call(this)},renderLabel:function(){var t=this.options,e=this.alloptions;if(t.label){if(t.labelInAxis){var i=this.el.select(".axis-unit")[0][0]&&this.el.select(".axis-unit")||this.el.append("g").attr({class:"axis-unit"}),n=this.el.selectAll(".tick:nth-last-child(3)").select("text");n&&n.length&&n[0].length&&("Left"===t.orient||"Right"===t.orient?i.attr("transform","translate(0,"+-1.5*parseInt(n.style("font-size"))+")"):i.attr("transform","translate("+((t.innerWidth||e.innerWidth)+3*parseInt(n.style("font-size")))+", 0)"),(i.select("text")[0][0]&&i.select("text")||i.append("text")).attr({dy:n.attr("dy"),x:n.attr("x"),y:n.attr("y"),transform:n.attr("transform")}).text(t.label).style({"text-anchor":n.style("text-anchor"),"font-size":n.style("font-size"),"font-weight":n.style("font-weight"),fill:n.style("fill")}))}}else this.el.select(".axis-unit").remove()},calLeft:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),n=this.axisx=d3.svg.axis().scale(i).orient("left");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.call(n):this.el=this.elContainer.append("g").attr("class","axis").call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:t.innerWidth||e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateLeft:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),this.format(),this._afterAxis(),this.__el&&this.__el.call(this.axisx),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:t.innerWidth||e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},calRight:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),n=this.axisx=d3.svg.axis().scale(i).orient("right");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.attr({transform:"translate("+(t.innerWidth||e.innerWidth)+", 0)"}).call(n):this.el=this.elContainer.append("g").attr({class:"axis",transform:"translate("+(t.innerWidth||e.innerWidth)+", 0)"}).call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:-t.innerWidth||-e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateRight:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),this.format(),this._afterAxis(),this.__el&&this.__el.attr("transform","translate("+(t.innerWidth||e.innerWidth)+", 0)").call(this.axisx),this.el.attr("transform","translate("+(t.innerWidth||e.innerWidth)+", 0)"),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:-t.innerWidth||-e.innerWidth,y2:"0"}).style({stroke:t.netColor})},calTop:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),n=this.axisx=d3.svg.axis().scale(i).orient("top");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.call(n):this.el=this.elContainer.append("g").attr("class","axis").call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:t.innerHeight||e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateTop:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),this.format(),this._afterAxis(),this.__el&&this.__el.call(this.axisx),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:t.innerHeight||e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},calBottom:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),n=this.axisx=d3.svg.axis().scale(i).orient("bottom");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.attr({transform:"translate(0,"+(t.innerHeight||e.innerHeight)+")"}).call(n):this.el=this.elContainer.append("g").attr({class:"axis",transform:"translate(0,"+(t.innerHeight||e.innerHeight)+")"}).call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:-t.innerHeight||-e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateBottom:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),this.format(),this._afterAxis(),this.__el&&this.__el.attr("transform","translate(0,"+(t.innerHeight||e.innerHeight)+")").call(this.axisx),this.el.attr("transform","translate(0,"+(t.innerHeight||e.innerHeight)+")"),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:-t.innerHeight||-e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},niceExtent:function(t,e){var i=this.options,n=Math.abs(e[1]-e[0]);t<=1&&(t=2);var s=numberUtil.nice(n/t,!0),a=numberUtil.getPrecisionSafe(s)+2,r=[i.minNeedNice?numberUtil.round(Math.floor(e[0]/s)*s,a):e[0],i.maxNeedNice?numberUtil.round(Math.ceil(e[1]/s)*s,a):e[1]];return _.toNumber(r[0])>_.toNumber(r[1])&&_.reverse(r),"defaults"===i.type.toLocaleLowerCase()&&i.tickFormat&&(r=d3.extent(this.cut(r,i.ticks,i.tickFormat).concat(r[0],r[1]))),r},axisDefaults:function(t){var e=this.x=d3.scale.linear().range(t),i=this.calExtent(),n=this.options,s=this.niceExtent(n.ticks,i);return e.domain(s),e},updateAxisDefaults:function(t){this.x.range(t);var e=this.calExtent(),i=this.options,n=this.niceExtent(i.ticks,e);return this.x.domain(n),this.x},axisCategory:function(t){var e,i=this.options;e=_.isArray(i.padding)?this.x=d3.scale.ordinal().rangeBands(t,i.padding[0],i.padding[1]):this.x=d3.scale.ordinal().rangeBands(t,i.padding/2,i.padding);var n=this.calExtent();return e.domain(n),e},updateAxisCategory:function(t){var e=this.options;return _.isArray(e.padding)?this.x.rangeBands(t,e.padding[0],e.padding[1]):this.x.rangeBands(t,e.padding/2,e.padding),this.x.domain(this.calExtent()),this.x},_setTimeAxisBoundaryGap:function(t){var e=this.options.blank?this.options.blankDis:0;if(e&&this._data&&this._data.length){var i=(+t[1]-t[0])/this._data.length,n=parseInt(i*e);t=[new Date(+t[0]-n),new Date(+t[1]+n)]}return t},_getTimeAxisExtent:function(){var t=this.options,e=d3.time.format(t.format),i=t.min,n=t.max,s=[i=i||"auto",n=n||"auto"],a=e.parse(i),r=e.parse(n),o=_.isDate(a),l=_.isDate(r);if(l&&o)s[0]=a,s[1]=r;else{var h=t.key,c=this._data.map((function(t){var i=t[h];return _.isDate(i)?+i:_.isString(i)?+e.parse(i):(console.log("date error: "+i+"is not a Date"),null)})),d=new Date(_.min(c)),u=new Date(_.max(c));s[0]=o?a:d,s[1]=l?r:u}return+(s=this._setTimeAxisBoundaryGap(s))[0]==+s[1]&&(s[1]=new Date(+s[1]+ONE_SECOND)),s},axisTime:function(t){var e=this._getTimeAxisExtent();return this.x=d3.time.scale().range(t).domain(e),this.x},updateAxisTime:function(t){var e=this._getTimeAxisExtent(),i=_.cloneDeep(this.x.domain());return+i[0]==+e[0]&&+i[1]==+e[1]||(this.__domain=i),this.x.range(t).domain(e),this.x},axisNondecile:function(t){var e=this.options,i=this.x=d3.scale.linear().range(t);e.max=_.sum(this._data,e.nondecile.key),i.domain(this.calExtent());var n=_.groupBy(this._data,e.key),s=this._data=[],a=0,r=s.length,o=(t[1]-t[0])/(i.domain()[1]-i.domain()[0]);for(var l in n){var h={sum:_.sum(n[l],e.nondecile.key),begin:a,end:0,center:0,radio:0};r--,h[e.key]=l,h.end=h.begin+h.sum,a+=h.sum,h.center=(h.begin+h.end)/2,e.nondecile.tickPadding&&0!==h.begin&&(h.begin=(i(h.begin)-e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),e.nondecile.tickPadding&&0!==r&&(h.end=(i(h.end)+e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),h.radio=(h.end-h.begin)/h.sum,s.push(h)}return e._afterAxis=function(){this.axisx.tickValues(_.pluck(this._data,"center"))},e.afterRender=function(){this.el.selectAll(".tick").data(this._data)},i},updateAxisNondecile:function(t){var e=this.options,i=this.x.range(t);e.max=_.sum(this._data,e.nondecile.key),i.domain(this.calExtent());var n=_.groupBy(this._data,e.key),s=this._data=[],a=0,r=s.length,o=(t[1]-t[0])/(i.domain()[1]-i.domain()[0]);for(var l in n){var h={sum:_.sum(n[l],e.nondecile.key),begin:a,end:0,center:0,radio:0};r--,h[e.key]=l,h.end=h.begin+h.sum,a+=h.sum,h.center=(h.begin+h.end)/2,e.nondecile.tickPadding&&0!==h.begin&&(h.begin=(i(h.begin)-e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),e.nondecile.tickPadding&&0!==r&&(h.end=(i(h.end)+e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),h.radio=(h.end-h.begin)/h.sum,s.push(h)}return i.domain(this.calExtent()),e._afterAxis=function(){this.axisx.tickValues(_.pluck(this._data,"center")),this.el&&this.el.selectAll(".tick").data(_.pluck(this._data,"center"))},i},calExtent:function(){var t=this,e=this.options,i=[];if("category"!==e.type.toLocaleLowerCase()){var n=[];this._data.forEach((function(i){var s=i[e.key];_.isArray(s)?("defaults"===e.type.toLocaleLowerCase()&&(s=_.map(s,(function(e){return _.toNumber(t._getValue(e))}))),n=_.union(n,s)):("defaults"===e.type.toLocaleLowerCase()&&(s=_.toNumber(t._getValue(s))),n.push(s))})),i=d3.extent(n),isFinite(e.min)&&null!==e.min&&(i[0]=e.min),i[1]=e.max||i[1]}else i=_.map(this._data,(function(i){return t._getValue(i[e.key])}));return i},_getValue:function(t){return _.isObject(t)&&t.hasOwnProperty("value")?t.value:t},getX:function(){return this.x},getAxisX:function(){return this.axisx},getMin:function(){return _.first(this.x.domain())},getMax:function(){return _.last(this.x.domain())},calGroupStep:function(t){var e=this.options.groupPadding;return Array.isArray(e)?this.groupX=d3.scale.ordinal().rangeBands([0,this.x.rangeBand()],_.isNumber(e[0])?e[0]:.4,_.isNumber(e[1])?e[1]:0):this.groupX=d3.scale.ordinal().rangeBands([0,this.x.rangeBand()],_.isNumber(e)?e:.4),Array.isArray(t)||(t=this._createCategory(parseInt(t))),this.groupX.domain(t),this.groupX},getGroupStep:function(t){return this.groupX?this.groupX.rangeBand():(this.calGroupStep(t),this.groupX.rangeBand())},_createCategory:function(t){for(var e=[],i=0;i<t;i++)e.push(""+i);return e},getGroupX:function(){return this.groupX},updateSeries:function(){var t=this.options;this.el.selectAll(".net-line").remove(),this.isReset&&this["cal"+t.orient]()||this["update"+t.orient](),this.renderStyle(),this.renderLabel(),"function"==typeof t.afterRender&&t.afterRender.call(this),this.el.selectAll(".net-line").style("display",t.net?"block":"none"),this.isReset=!1},renderStyle:function(){var t=this.options,e=this.el.selectAll(".tick text").style({fill:t.fontColor,"font-size":t.fontSize,"font-weight":t.fontWeight,"stroke-width":0,display:t.textShow?"block":"none"});t.fontStrokeWidth&&e.style({stroke:t.fontColor,"stroke-width":t.fontStrokeWidth}),t.rotate&&_.isNumber(t.rotate)?e.each((function(e){var i=d3.select(this),n=_.toNumber(i.attr("x")),s=_.toNumber(i.attr("y")),a=t.rotate/360*2*Math.PI;i.attr("transform",(("Top"===t.orient||"Bottom"===t.orient)&&"translate(0 "+.5*Math.sin(a)*t.fontSize*("Bottom"===t.orient?.01:-1.99)+")"||"")+" rotate("+t.rotate+" "+n+" "+s+")").style({"text-anchor":"start"})})):e.attr("transform",""),this.el.selectAll(".domain, .tick line:not(.net-line)").style({display:t.assistLine?"block":"none",fill:"none",stroke:t.assistLineColor}),this.el.style("display",t.show?"block":"none")}}),module.exports=Axis; | ||
"use strict";function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,i=new Array(t.length);e<t.length;e++)i[e]=t[e];return i}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var i=[],n=!0,s=!1,a=void 0;try{for(var r,o=t[Symbol.iterator]();!(n=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);n=!0);}catch(t){s=!0,a=t}finally{try{n||null==o.return||o.return()}finally{if(s)throw a}}return i}}function _arrayWithHoles(t){if(Array.isArray(t))return t}var _=require("../util"),Com=require("./index"),d3=require("d3"),numberUtil=require("../util/number"),TICK_PADDING=2,MAX_TICK_COUNT=30,ONE_SECOND=1e3,timeUnitsMSMap={seconds:ONE_SECOND,minutes:60*ONE_SECOND,hours:60*ONE_SECOND*60,days:60*ONE_SECOND*60*24,months:60*ONE_SECOND*60*24*30,years:60*ONE_SECOND*60*24*30*12};function Axis(t,e,i){this.reset(),this.options={fontSize:12,fontColor:"#fff",fontWeight:"normal",fontStrokeWidth:0,key:"x",type:"defaults",orient:null,dy:0,padding:.4,groupPadding:[.4,.4],assistLine:!0,assistLineColor:"#fff",rotate:0,min:null,max:null,maxLabel:!1,tickSize:0,tickValues:null,tickFormat:null,ticks:null,nondecile:{key:"y",tickPadding:10},format:"%Y-%m-%d",label:null,labelColor:"#aaa",labelInAxis:!0,labelFontSize:12,labelFontWeight:"normal",labelFontStrokeWidth:0,textAnchor:"middle",textShow:!0,net:!1,netColor:"#aaa",digit:0,show:!0},this.x=null,this.axisx=null,this.groupX=null,this.net=null,this.init(t,e,i),this._valid()}function getStep(t){var e=t.step,i=t.f,n=t.maxNeedNice,s=t.tickFormat,a="string"==typeof s?(s.split(".")[1]||"0f").split("f")[0]:0;return e=n?i(Math.ceil(Math.pow(10,a)*e)/Math.pow(10,a)):i(10*e)/10}function isTicksOverlap(t,e){if(t&&e&&t.getBoundingClientRect&&e.getBoundingClientRect){var i=t.getBoundingClientRect(),n=e.getBoundingClientRect();return i.left+i.width+TICK_PADDING>n.left&&n.left+n.width+TICK_PADDING>i.left&&i.top+i.height+TICK_PADDING>n.top&&n.top+n.height+TICK_PADDING>i.top}return!1}function removeOverlapTicksOfTargetAxis(t,e){return new Promise((function(i,n){if(!t)return i();var s=t.selectAll(".tick")[0],a=[];if(e.maxLabel)for(var r=s.length-1;r>=0;r--){var o=s[r],l=s[r-1];if(o&&l&&o.getBoundingClientRect&&l.getBoundingClientRect)for(;isTicksOverlap(o,l)&&(d3.select(l).remove(),l=s[--r-1]););}else for(r=0;r<s.length;r++){var h=s[r],c=s[r+1];if(h&&c&&h.getBoundingClientRect&&c.getBoundingClientRect)for(;isTicksOverlap(h,c)&&(d3.select(c).remove(),c=s[++r+1]););}return t.selectAll(".tick")[0].forEach((function(t){a.push(t.__data__)})),i(a)}))}Axis=Com.extend(Axis,{init:function(t,e,i){if(!t&&!this.el)return!1;t&&(this.elContainer=d3.select(t)),this.options&&_.toLower(this.options.type)!==_.toLower(e.type)?this.isReset=!0:this.isReset=!1,this.options=_.deepMerge(this.options,e),this.alloptions=i||this.alloptions},_valid:function(){var t=this.options,e=["defaults","category","time","nondecile"];-1===_.indexOf(e,t.type.toLowerCase())&&(this.msg="axis arguments error. there is no "+t.type+" in types.",t.type=e[0],this.valid=!1),t.type=_.initialUpperCase(t.type);var i=["left","top","right","bottom"];-1===_.indexOf(i,t.orient.toLowerCase())&&(this.msg="axis arguments error. there is no "+t.orient+" in orients.",t.orient=i[0],this.valid=!1),t.orient=_.initialUpperCase(t.orient)},renderSeries:function(){var t=this.options;this["cal"+t.orient](),this.__el||(this.__el=this.elContainer.append("g").attr({class:"virtual_axis",opacity:0}).call(this.axisx)),this.renderStyle(),this.renderLabel(),"function"==typeof t.afterRender&&t.afterRender.call(this),this.el.selectAll(".tick line").style("display",t.net?"block":"none"),this.isReset=!1},cut:function(t,e,i){var n=_slicedToArray(t,2),s=n[0],a=n[1],r=d3.format(i),o=this.options.maxNeedNice,l=((a=+a||0)-(s=+s||0))/(e-1);l=getStep({step:l,f:r,maxNeedNice:o,tickFormat:i}),t=[],+s==+r(s)&&t.push(s);for(var h=0;h<e-1;h++){var c=r(s+l*(h+1));(c<=a||o)&&t.push(c)}var d=(t=(t=_.uniq(t.map((function(t){return+t})).sort((function(t,e){return t-e})))).filter((function(t){return t<=(o?2*a:a)}))).length-e,u=r(a),f=r(s);return d>0?t.splice(e-1,t.length-e):0===d?t[t.length-1]<u&&(t[t.length-1]=u):d<0&&(t.push(u),t.push(f)),t},format:function(){var t=this,e=this.options,i=this.axisx,n=this.x;i.tickPadding(e.dy),"object"===_typeof(e.tickSize)?i.tickSize.apply(this,e.tickSize):i.tickSize(e.tickSize),e.tickValues&&i.tickValues(e.tickValues);var s=!1;if(e.ticks){if("Category"===e.type&&_.isNumber(e.ticks)){var a=this._data;e.tickFormat=function(t,i){var n=_.toNumber(e.ticks),s=a.length,r=parseInt((s-1)/(n-1));if(0===r)return t;var o=(s-1)%(n-1),l=parseInt(o%2&&o/2+1||o/2);return i<l?"":s-i<=o-l?"":(i-l)%r?"":t},i.ticks.apply(this,[e.ticks])}else if("array"==typeof e.ticks)i.ticks.apply(this,e.ticks);else if(_.isNumber(e.ticks))if("Time"!==e.type)if(e.ticks=_.toNumber(e.ticks),"string"==typeof e.tickFormat){var r=_.clone(n.domain());switch(e.ticks){case 0:i.tickValues([r[0]]);break;case 1:i.tickValues([r[1]]);break;default:if(e.tickFormat){var o=_slicedToArray(r,2),l=o[0],h=o[1];if(r=this.cut(r,e.ticks,e.tickFormat),"defaults"===e.type.toLocaleLowerCase()){var c=+d3.format(e.tickFormat)(h),d=+d3.format(e.tickFormat)(l);r=r.filter((function(t){return+t==+d3.format(e.tickFormat)(t)&&t<=c&&t>=d}))}}i.tickValues(r)}setTimeout((function(){var e=t.el&&t.el.selectAll(".tick")[0];if(e&&e.length>1){var i=e[e.length-2];isTicksOverlap(i,e[e.length-1])&&d3.select(i).remove()}}),0)}else i.ticks(e.ticks),s=!0;else{var u=_slicedToArray(this._getTimeAxisExtent(),2),f=(u[0],u[1]),p=Math.min(MAX_TICK_COUNT,e.ticks);i.ticks(p),e.maxLabel&&i.tickValues([].concat(_toConsumableArray(i.scale().ticks()),[f])),s=!0}}else if(_.isNumber(e.ticks)&&"time"===e.type.toLowerCase()){var m=5*e.tickFormat(new Date).length+5,g=Math.min(e.innerWidth/m||10,MAX_TICK_COUNT);if(this._data.length<g){var y=e.tickFormat;"function"!=typeof y&&(y=d3.format(y));var x=d3.time.format(e.format),k=[],v=[],b=e.key;this._data.map((function(t){var e=x.parse(t[b]);-1===v.indexOf(y(e))&&(v.push(y(e)),k.push(e))})),i.tickValues(k)}else i.ticks(g);s=!0}if("string"==typeof e.tickFormat)i.tickFormat(d3.format(e.tickFormat));else if("function"==typeof e.tickFormat){var A=this;i.tickFormat((function(t,i){return e.tickFormat.call(A._data[i],t,i)}))}s?setTimeout((function(){removeOverlapTicksOfTargetAxis(t.__el,e).then((function(s){if(s&&s.length){var a=d3.svg.axis().scale(n).orient(i.orient()).tickPadding(e.dy).tickFormat(i.tickFormat()).tickValues(s).tickSize(0);t.el.call(a),t.renderStyle()}}))}),0):this.el&&this.el.call(i)},_afterAxis:function(){var t=this.options;"function"==typeof t._afterAxis&&t._afterAxis.call(this)},renderLabel:function(){var t=this.options,e=this.alloptions;if(t.label){if(t.labelInAxis){var i=this.el.select(".axis-unit")[0][0]&&this.el.select(".axis-unit")||this.el.append("g").attr({class:"axis-unit"}),n=this.el.selectAll(".tick:nth-last-child(3)").select("text");n&&n.length&&n[0].length&&("Left"===t.orient||"Right"===t.orient?i.attr("transform","translate(0,"+-1.5*parseInt(n.style("font-size"))+")"):i.attr("transform","translate("+((t.innerWidth||e.innerWidth)+3*parseInt(n.style("font-size")))+", 0)"),(i.select("text")[0][0]&&i.select("text")||i.append("text")).attr({dy:n.attr("dy"),x:n.attr("x"),y:n.attr("y"),transform:n.attr("transform")}).text(t.label).style({"text-anchor":n.style("text-anchor"),"font-size":n.style("font-size"),"font-weight":n.style("font-weight"),fill:n.style("fill")}))}}else this.el.select(".axis-unit").remove()},calLeft:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),n=this.axisx=d3.svg.axis().scale(i).orient("left");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.call(n):this.el=this.elContainer.append("g").attr("class","axis").call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:t.innerWidth||e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateLeft:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),this.format(),this._afterAxis(),this.__el&&this.__el.call(this.axisx),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:t.innerWidth||e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},calRight:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),n=this.axisx=d3.svg.axis().scale(i).orient("right");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.attr({transform:"translate("+(t.innerWidth||e.innerWidth)+", 0)"}).call(n):this.el=this.elContainer.append("g").attr({class:"axis",transform:"translate("+(t.innerWidth||e.innerWidth)+", 0)"}).call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:-t.innerWidth||-e.innerWidth,y2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateRight:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[t.innerHeight||e.innerHeight,0]),this.format(),this._afterAxis(),this.__el&&this.__el.attr("transform","translate("+(t.innerWidth||e.innerWidth)+", 0)").call(this.axisx),this.el.attr("transform","translate("+(t.innerWidth||e.innerWidth)+", 0)"),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",x2:-t.innerWidth||-e.innerWidth,y2:"0"}).style({stroke:t.netColor})},calTop:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),n=this.axisx=d3.svg.axis().scale(i).orient("top");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.call(n):this.el=this.elContainer.append("g").attr("class","axis").call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:t.innerHeight||e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateTop:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),this.format(),this._afterAxis(),this.__el&&this.__el.call(this.axisx),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:t.innerHeight||e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},calBottom:function(){var t=this.options,e=this.alloptions,i=this.x=this["axis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),n=this.axisx=d3.svg.axis().scale(i).orient("bottom");this.format(),this._afterAxis(),this.el&&-1!==this.el.attr("class").indexOf("axis")?this.el.attr({transform:"translate(0,"+(t.innerHeight||e.innerHeight)+")"}).call(n):this.el=this.elContainer.append("g").attr({class:"axis",transform:"translate(0,"+(t.innerHeight||e.innerHeight)+")"}).call(n),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:-t.innerHeight||-e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},updateBottom:function(){var t=this.options,e=this.alloptions;this["updateAxis"+t.type].call(this,[0,t.innerWidth||e.innerWidth]),this.format(),this._afterAxis(),this.__el&&this.__el.attr("transform","translate(0,"+(t.innerHeight||e.innerHeight)+")").call(this.axisx),this.el.attr("transform","translate(0,"+(t.innerHeight||e.innerHeight)+")"),this.net=this.el.selectAll(".tick"+("Category"!==t.type&&1!==t.ticks?":not(:first-child)":"")).append("line").attr({class:"net-line",y2:-t.innerHeight||-e.innerHeight,x2:"0"}).style({"stroke-dasharray":"2 2",stroke:t.netColor})},niceExtent:function(t,e){var i=this.options,n=Math.abs(e[1]-e[0]);t<=1&&(t=2);var s=numberUtil.nice(n/t,!0),a=numberUtil.getPrecisionSafe(s)+2,r=[i.minNeedNice?numberUtil.round(Math.floor(e[0]/s)*s,a):e[0],i.maxNeedNice?numberUtil.round(Math.ceil(e[1]/s)*s,a):e[1]];return _.toNumber(r[0])>_.toNumber(r[1])&&_.reverse(r),"defaults"===i.type.toLocaleLowerCase()&&i.tickFormat&&(r=d3.extent(this.cut(r,i.ticks,i.tickFormat).concat(r[0],r[1]))),r},axisDefaults:function(t){var e=this.x=d3.scale.linear().range(t),i=this.calExtent(),n=this.options,s=this.niceExtent(n.ticks,i);return e.domain(s),e},updateAxisDefaults:function(t){this.x.range(t);var e=this.calExtent(),i=this.options,n=this.niceExtent(i.ticks,e);return this.x.domain(n),this.x},axisCategory:function(t){var e,i=this.options;e=_.isArray(i.padding)?this.x=d3.scale.ordinal().rangeBands(t,i.padding[0],i.padding[1]):this.x=d3.scale.ordinal().rangeBands(t,i.padding/2,i.padding);var n=this.calExtent();return e.domain(n),e},updateAxisCategory:function(t){var e=this.options;return _.isArray(e.padding)?this.x.rangeBands(t,e.padding[0],e.padding[1]):this.x.rangeBands(t,e.padding/2,e.padding),this.x.domain(this.calExtent()),this.x},_setTimeAxisBoundaryGap:function(t){var e=this.options.blank?this.options.blankDis:0;if(e&&this._data&&this._data.length){var i=(+t[1]-t[0])/this._data.length,n=parseInt(i*e);t=[new Date(+t[0]-n),new Date(+t[1]+n)]}return t},_getTimeAxisExtent:function(){var t=this.options,e=d3.time.format(t.format),i=t.min,n=t.max,s=[i=i||"auto",n=n||"auto"],a=e.parse(i),r=e.parse(n),o=_.isDate(a),l=_.isDate(r);if(l&&o)s[0]=a,s[1]=r;else{var h=t.key,c=this._data.map((function(t){var i=t[h];return _.isDate(i)?+i:_.isString(i)?+e.parse(i):(console.log("date error: "+i+"is not a Date"),null)})),d=new Date(_.min(c)),u=new Date(_.max(c));s[0]=o?a:d,s[1]=l?r:u}return+(s=this._setTimeAxisBoundaryGap(s))[0]==+s[1]&&(s[1]=new Date(+s[1]+ONE_SECOND)),s},axisTime:function(t){var e=this._getTimeAxisExtent();return this.x=d3.time.scale().range(t).domain(e),this.x},updateAxisTime:function(t){var e=this._getTimeAxisExtent(),i=_.cloneDeep(this.x.domain());return+i[0]==+e[0]&&+i[1]==+e[1]||(this.__domain=i),this.x.range(t).domain(e),this.x},axisNondecile:function(t){var e=this.options,i=this.x=d3.scale.linear().range(t);e.max=_.sum(this._data,e.nondecile.key),i.domain(this.calExtent());var n=_.groupBy(this._data,e.key),s=this._data=[],a=0,r=s.length,o=(t[1]-t[0])/(i.domain()[1]-i.domain()[0]);for(var l in n){var h={sum:_.sum(n[l],e.nondecile.key),begin:a,end:0,center:0,radio:0};r--,h[e.key]=l,h.end=h.begin+h.sum,a+=h.sum,h.center=(h.begin+h.end)/2,e.nondecile.tickPadding&&0!==h.begin&&(h.begin=(i(h.begin)-e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),e.nondecile.tickPadding&&0!==r&&(h.end=(i(h.end)+e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),h.radio=(h.end-h.begin)/h.sum,s.push(h)}return e._afterAxis=function(){this.axisx.tickValues(_.pluck(this._data,"center"))},e.afterRender=function(){this.el.selectAll(".tick").data(this._data)},i},updateAxisNondecile:function(t){var e=this.options,i=this.x.range(t);e.max=_.sum(this._data,e.nondecile.key),i.domain(this.calExtent());var n=_.groupBy(this._data,e.key),s=this._data=[],a=0,r=s.length,o=(t[1]-t[0])/(i.domain()[1]-i.domain()[0]);for(var l in n){var h={sum:_.sum(n[l],e.nondecile.key),begin:a,end:0,center:0,radio:0};r--,h[e.key]=l,h.end=h.begin+h.sum,a+=h.sum,h.center=(h.begin+h.end)/2,e.nondecile.tickPadding&&0!==h.begin&&(h.begin=(i(h.begin)-e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),e.nondecile.tickPadding&&0!==r&&(h.end=(i(h.end)+e.nondecile.tickPadding/2-t[0])/o+i.domain()[0]),h.radio=(h.end-h.begin)/h.sum,s.push(h)}return i.domain(this.calExtent()),e._afterAxis=function(){this.axisx.tickValues(_.pluck(this._data,"center")),this.el&&this.el.selectAll(".tick").data(_.pluck(this._data,"center"))},i},calExtent:function(){var t=this,e=this.options,i=[];if("category"!==e.type.toLocaleLowerCase()){var n=[];this._data.forEach((function(i){var s=i[e.key];_.isArray(s)?("defaults"===e.type.toLocaleLowerCase()&&(s=_.map(s,(function(e){return _.toNumber(t._getValue(e))}))),n=_.union(n,s)):("defaults"===e.type.toLocaleLowerCase()&&(s=_.toNumber(t._getValue(s))),n.push(s))})),i=d3.extent(n),isFinite(e.min)&&null!==e.min&&(i[0]=e.min),i[1]=e.max||i[1]}else i=_.map(this._data,(function(i){return t._getValue(i[e.key])}));return i},_getValue:function(t){return _.isObject(t)&&t.hasOwnProperty("value")?t.value:t},getX:function(){return this.x},getAxisX:function(){return this.axisx},getMin:function(){return _.first(this.x.domain())},getMax:function(){return _.last(this.x.domain())},calGroupStep:function(t){var e=this.options.groupPadding;return Array.isArray(e)?this.groupX=d3.scale.ordinal().rangeBands([0,this.x.rangeBand()],_.isNumber(e[0])?e[0]:.4,_.isNumber(e[1])?e[1]:0):this.groupX=d3.scale.ordinal().rangeBands([0,this.x.rangeBand()],_.isNumber(e)?e:.4),Array.isArray(t)||(t=this._createCategory(parseInt(t))),this.groupX.domain(t),this.groupX},getGroupStep:function(t){return this.groupX?this.groupX.rangeBand():(this.calGroupStep(t),this.groupX.rangeBand())},_createCategory:function(t){for(var e=[],i=0;i<t;i++)e.push(""+i);return e},getGroupX:function(){return this.groupX},updateSeries:function(){var t=this.options;this.el.selectAll(".net-line").remove(),this.isReset&&this["cal"+t.orient]()||this["update"+t.orient](),this.renderStyle(),this.renderLabel(),"function"==typeof t.afterRender&&t.afterRender.call(this),this.el.selectAll(".net-line").style("display",t.net?"block":"none"),this.isReset=!1},renderStyle:function(){var t=this.options,e=this.el.selectAll(".tick text").style({fill:t.fontColor,"font-size":t.fontSize,"font-weight":t.fontWeight,"stroke-width":0,display:t.textShow?"block":"none"});t.fontStrokeWidth&&e.style({stroke:t.fontColor,"stroke-width":t.fontStrokeWidth}),t.rotate&&_.isNumber(t.rotate)?e.each((function(e){var i=d3.select(this),n=_.toNumber(i.attr("x")),s=_.toNumber(i.attr("y")),a=t.rotate/360*2*Math.PI;i.attr("transform",(("Top"===t.orient||"Bottom"===t.orient)&&"translate(0 "+.5*Math.sin(a)*t.fontSize*("Bottom"===t.orient?.01:-1.99)+")"||"")+" rotate("+t.rotate+" "+n+" "+s+")").style({"text-anchor":"start"})})):e.attr("transform","none"),this.el.selectAll(".domain, .tick line:not(.net-line)").style({display:t.assistLine?"block":"none",fill:"none",stroke:t.assistLineColor}),this.el.style("display",t.show?"block":"none")}}),module.exports=Axis; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var i=[],o=!0,r=!1,s=void 0;try{for(var n,a=t[Symbol.iterator]();!(o=(n=a.next()).done)&&(i.push(n.value),!e||i.length!==e);o=!0);}catch(t){r=!0,s=t}finally{try{o||null==a.return||a.return()}finally{if(r)throw s}}return i}}function _arrayWithHoles(t){if(Array.isArray(t))return t}var _=require("../util"),Com=require("./index"),d3=require("d3"),TRIGGER_AXIS="axis",STROKE_DASH_MAP={solid:"none",dashed:"10, 10",dotted:"2, 2"},ITEM_TRIGGER_METHOD_MAP={click:{show:"click",hide:"dblclick"},hover:{show:"mouseover",hide:"mouseout"}},AXIS_TRIGGER_METHOD_MAP={click:"click",hover:"mousemove"},_defaultFormatterMap={xyzAxisChart:_xyzAxisChartFormatter,xyAxisChart:_xyAxisChartFormatter,doubleLineChart:_doubelLineChartFormatter,pieChart:_pieChartFormatter,horiBarChart:_horiBarFormatter};function Tooltip(t,e,i,o){this.reset(),this.comObj=e,this.options={show:"true",formatter:{},trigger:"item",enterFocus:!1,hideDelay:100,axisPointer:"line",autoSize:!0,backgroundColor:"rgba(0,0,0,0.65)",color:"#fff",beforeFormat:null,padding:10,lineStyle:{color:"#f00",width:1,_type:"solid"}},this.init(t,i,o),this._valid()}function getTrans(t,e){if(!t&&!e)return{transX:0,transY:0};var i=getXY(t),o=i.x,r=i.y,s=getXY(e);return{transX:o+s.x,transY:r+s.y}}function getXY(t){if(!t||-1===t.indexOf("(")||-1===t.indexOf(")"))return{x:0,y:0};var e=_slicedToArray(t.split("(")[1].split(")")[0].split(","),2);return{x:+e[0],y:+e[1]}}function _creatToolTipSerieRow(t){var e=t.serie,i=t.color,o=t.value,r=t.key,s=t.format;return'<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px;\n background:'.concat(i||e&&e.color&&(e.color.gradientValue||e.color.value)||"#ccc",'"></span>\n ').concat(r?r+": ":"").concat(_.isFunction(s)&&s(o)||o,"</div>")}function _xyAxisChartFormatter(t,e,i){var o=this.options.trigger,r='<div class="dchart-tooltip">',s=this.alloptions.series,n=this.alloptions.hiddenEmptyData,a=[],l=this.alloptions.yaxis.format?d3.format(this.alloptions.yaxis.format):function(t){return t};if(o===TRIGGER_AXIS)t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach((function(t,e){return!(n&&t.__isNull)&&a.push(_creatToolTipSerieRow({serie:s[e],value:t.value,format:l}))}));else{var h=Array.isArray(t.y)?t.y[e]:t.y;n&&h.__isNull||a.push(_creatToolTipSerieRow({serie:s[e],value:h.value&&h.value.toString()||0,key:t.x.toString(),format:l}))}return r+="".concat(a.join(""),"</div>")}function _doubelLineChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions,s=r.series,n=r.series2,a=[],l=(this.data()||[]).length;return this.options.trigger===TRIGGER_AXIS?(t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach((function(t,e){return a.push(_creatToolTipSerieRow({color:s[e]&&s[e].line.color,value:t}))})),t.z&&t.z.forEach((function(t,e){return a.push(_creatToolTipSerieRow({color:n[e]&&n[e].line.color,value:t}))}))):a.push(_creatToolTipSerieRow({color:(i/l>=1?s:n)[0].point.color,value:i/l>=1?t.y&&t.y.toString()||0:t.z&&t.z.toString()||0,key:t.x.toString()})),o+="".concat(a.join(""),"</div>")}function _pieChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions,s=r.series,n=r.label,a=this._data.map((function(t){return t.y})).reduce((function(t,e){return t+e}),0),l=(t.y/a*100).toFixed(n.account.decimal)+"%";return t.y&&(o+=_creatToolTipSerieRow({color:s[e].color.value,key:t.x,value:"".concat(t.y," (").concat(l,")")})),o}function _xyzAxisChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions.series,s=this._data.length,n=[];t.x&&n.push("<b>".concat(t.x.toString(),"</b>"));var a=this.options.trigger===TRIGGER_AXIS,l=d3.format(this.alloptions.yaxis.format),h=d3.format(this.alloptions.zaxis.format);return(a||i/s<1)&&t.y&&(t.y=[].concat(t.y))&&t.y.forEach((function(t,e){return n.push(_creatToolTipSerieRow({serie:r[e]&&r[e].bar,value:t.value,format:l}))})),(a||i/s>1)&&t.z&&t.z.forEach&&t.z.forEach((function(t,e){return n.push(_creatToolTipSerieRow({serie:r[e]&&r[e].line,value:t.value,format:h}))})),o+="".concat(n.join(""),"</div>")}function _horiBarFormatter(t,e,i,o){var r=this.options.trigger,s='<div class="dchart-tooltip">',n=this.alloptions.series,a=[],l=this.alloptions.xaxis.format?d3.format(this.alloptions.xaxis.format):function(t){return t};if(r===TRIGGER_AXIS)t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach((function(t,e){return(0===t||t)&&a.push(_creatToolTipSerieRow({format:l,serie:n[e],value:t.value}))}));else{var h=Array.isArray(t.y)?t.y[e]:t.y,c=+o.select("rect").attr("order");a.push(_creatToolTipSerieRow({format:l,serie:n[c],value:h.value&&h.value.toString()||0,key:t.x.toString()}))}return s+="".concat(a.join(""),"</div>")}function clearListenersOnSelector(t){t&&t.on&&t.on("mouseover",(function(){})).on("mousemove",(function(){})).on("mouseleave",(function(){})).on("click",(function(){})).on("mouseout",(function(){})).on("dblclick",(function(){}))}function getLeft(t,e){return t.getBBox().width-(e.options.net?e.options.innerWidth:0)}Tooltip=Com.extend(Tooltip,{init:function(t,e,i){return!(!t&&!this.el)&&(t&&(this.el=d3.select(t)),this.options=_.deepMerge(this.options,e),this.alloptions=i||this.alloptions,this)},_valid:function(){},renderSeries:function(){var t=this.options,e=this.alloptions;this.layer={};var i=this.el.select(".con-svg");this.layer.width=e.innerWidth,this.layer.height=e.innerHeight,this.layer.svgContainer=i,this.layer.x=this.comObj.getComs("axis","xaxis"),this.layer.y=this.comObj.getComs("axis","yaxis"),this.dispatch=d3.dispatch("elementMouseover","elementMouseout"),this.tooltip=this.el.select(".dc-tooltip")[0][0]?this.el.select(".dc-tooltip"):this.el.append("div").attr("class","dc-tooltip").style({display:"none",position:"absolute",color:t.color,background:t.backgroundColor,padding:t.padding+"px","border-radius":"5%"});var o=this;this.tooltip.on("mouseenter",(function(){o.options.enterFocus&&clearTimeout(o._hideTimeout)})).on("mouseout",(function(){o.options.trigger&&(clearTimeout(this._hideTimeout),o.hide(o.options.hideDelay))})),this.initGuildLayer()},show:function(){clearTimeout(this._hideTimeout),this.options.trigger===TRIGGER_AXIS&&this.isAxisChart()?this.showAxis.apply(this,arguments):this.showItem.apply(this,arguments)},showItem:function(t,e,i,o,r,s){"function"==typeof i&&(t=i.call(this,t,o,r,s));var n=this.defaultFormatter(t),a=this.options.formatter;"string"==typeof a?n=_defaultFormatterMap[a]&&_defaultFormatterMap[a].call(this,t,o,r,s):"function"==typeof a&&(n=a(t,o,r,s)),this.tooltip.html(n),this.tooltip.transition().duration(20).style("display","block");var l=d3.event||window.event,h=this.getTipPosition(l);this.tooltip.style("left",+h.x+"px").style("top",+h.y+"px")},showAxis:function(t,e,i){"function"==typeof i&&(t=i.call(this,t));var o=this.defaultFormatter(t),r=this.options.formatter;"string"==typeof r?o=_defaultFormatterMap[r]&&_defaultFormatterMap[r].call(this,t):"function"==typeof r&&(o=r(t));var s,n,a,l,h,c=d3.mouse(e[0][0]),u=this.alloptions,d=this.isVertical();d?(s=this.layer.x.getX(),n=u.xaxis.key,a=u.xaxis.type,l=this.layer.y,h=u.yaxis.orient):(s=this.layer.y.getX(),n=u.yaxis.key,a=u.yaxis.type,l=this.layer.x,h=u.xaxis.orient);var p=l.el[0][0],f=0;if(d){var y=t[n];if("time"===a)y=s(d3.time.format(u.xaxis.format).parse(t[n]));else y=s(t[n]);f=y+ +u.margin.left+(u.margin.containLabel&&"left"===h?getLeft(p,l):0)}else f=c[0]+u.margin.left;var m=d&&c[1]+u.margin.top||s("time"===a&&new Date(t[n])||t[n])+u.margin.top+(u.margin.containLabel&&"top"===h?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");var g=this.options,x=this.getTipPositionAxis({left:f+(d&&s.rangeBand&&s.rangeBand()/2||0)+2*+g.xOffset,top:m+(d?0:s.rangeBand&&s.rangeBand()/2||0)+ +g.yOffset});this.tooltip.style("left",x.left+"px").style("top",x.top+"px")},getBoxSize:function(){var t=150,e=50;if(this.options.autoSize){var i=this.tooltip&&this.tooltip.node();i&&(t=i.offsetWidth||t,e=i.offsetHeight||e)}else t=this.options.width,e=this.options.height;return{boxWidth:t,boxHeight:e}},getTipPositionAxis:function(t){var e=t.left,i=t.top,o=document.body,r=o.offsetWidth,s=o.offsetHeight,n=this.el.node().parentElement.parentElement,a=n.offsetLeft,l=n.offsetTop,h=this.getBoxSize(),c=h.boxWidth,u=h.boxHeight;return a+e+c>r&&(e=Math.max(e-c,0)),l+i+u>s&&(i=Math.max(i-u)),{top:i,left:e}},getTipPosition:function(t){var e=this.options,i=e.xOffset,o=e.yOffset,r=t.offsetX,s=t.offsetY,n={x:r+i,y:s+o},a=document.body,l=a.offsetWidth,h=a.offsetHeight,c=this.getBoxSize(),u=c.boxWidth,d=c.boxHeight,p=this.el.node().parentElement.parentElement,f=p.offsetLeft,y=p.offsetTop;return f+r+u+i>l&&(n.x=Math.max(r-u,0)),y+s+d+o>h&&(n.y=Math.max(s-d)),n},hide:function(){this.options.enterFocus=!0,this.options.enterFocus?this._delayHide():this._contentHide()},_contentHide:function(){this.tooltip.style("display","none")},_delayHide:function(){var t=this;this.options.enterFocus&&(clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout((function(){t._contentHide()}),this.options.hideDelay))},defaultFormatter:function(t){var e='<div class="dchart-tooltip">',i=0;return _.forIn(t,(function(t,o,r){e+=(0!==i?"<br>":"")+o+": "+(t=t||0).toString(),i++})),e+="</div>"},initGuildLayer:function(){var t=this.alloptions;this.wrap=this.el.select(".guildLayer")[0][0]?this.el.select(".guildLayer"):this.el.select(".con-svg").append("g").attr({class:"guildLayer",transform:"translate("+t.margin.left+","+t.margin.top+")"});var e=this.wrap.select(".guildLineLayer")[0][0]?this.wrap.select(".guildLineLayer"):this.wrap.append("g").attr("class","guildLineLayer");e.style("pointer-events","none"),e.select(".guildLine")[0][0]?e.select(".guildLine"):e.append("g").attr("class","guildLine")},triggerAxis:function(){var t=this,e=this,i=(this.options,this.layer.width),o=this.layer.height,r=this.layer.y,s=this.layer.x,n=this.dispatch,a=this.alloptions.margin,l=this,h=this.alloptions,c=this.options.triggerMethod,u=10,d=this.layer.svgContainer,p=getTrans(this.el.select(".con-g").attr("transform"),this.el.select(".series").attr("transform")),f=p.transX;p.transY;d.on(AXIS_TRIGGER_METHOD_MAP[c]||"mousemove",(function(){if(e.isAxisChart()&&e.options.trigger===TRIGGER_AXIS){var t=d3.event,c=t.offsetX,d=t.offsetY,p=e.isVertical(),y=p&&s.getX()||r.getX(),m=p&&y.range()||_.clone(y.range()).reverse(),g=p&&y.domain()||_.clone(y.domain()).reverse();if(c-=a.left,d-=a.top,a.containLabel&&("top"===h.xaxis.orient&&(d-=s.options.__height),"left"===h.yaxis.orient&&(c-=f)),c+u<0||d+u<0||c-u>i||d-u>o)return n.elementMouseout({mouseX:c,mouseY:d}),void l.renderGuildLayer(null);l.renderGuildLayer(null);var x="function"==typeof y.rangeBands,v=void 0,T=p?c:d;if(x){var b=d3.bisect(m,T),S=y.rangeBand(),w=m.length;if(0===b)v=g[b];else if(b===w)v=g[b-1];else{var A=Math.abs(m[b]-T);Math.abs(T-m[b-1]-S)<A&&(b-=1),v=g[b]}}else v=y.invert(T);n.elementMouseover({mouseX:c,mouseY:d,pointValue:v})}})),d.on("mouseleave",(function(){"hover"===c&&(t.renderGuildLayer(null),t.hide())}))},hideGuidLine:function(){this.el.select(".guildLine").selectAll("line").attr("display","none")},renderGuildLayer:function(t){if(0!==t&&!t)return this.hideGuidLine(),!1;var e=getTrans(this.el.select(".con-g").attr("transform"),this.el.select(".series").attr("transform")),i=e.transX,o=e.transY;this.el.select(".guildLayer").attr("transform","translate(".concat(i,", ").concat(o,")"));var r=this.options.lineStyle,s=this.isVertical(),n=this.el.select(".guildLine").selectAll("line").data(null!=t?[t]:[],String);n.enter().append("line");var a=this.layer.y.options,l=this.alloptions;n.attr("display","block").attr("class","tooltip-guideline").attr("x1",(function(t){return s&&_.isNumber(t)?t:0})).attr("x2",(function(t){return s&&_.isNumber(t)?t:a.innerWidth})).attr("y1",(function(t){return s?a.innerHeight||l.innerHeight:t})).attr("y2",(function(t){return!s&&_.isNumber(t)?t:0})).attr("stroke",r.color).attr("stroke-width",r.width).attr("stroke-dasharray",STROKE_DASH_MAP[r._type]).style("cursor","pointer"),n.exit().remove()},isVertical:function(){var t=this.alloptions;return"time"===t.xaxis.type||"category"===t.xaxis.type||"time"!==t.yaxis.type&&"category"!==t.yaxis.type},isAxisChart:function(){var t=this.alloptions;return t&&t.xaxis&&t.yaxis},updateItem:function(t){var e=this,i=this.selector,o=this.selectorText,r=this.options.triggerMethod,s=this.layer.svgContainer.select(".con-g");if(i){clearListenersOnSelector(i);var n=this.options.beforeFormat;i.on(ITEM_TRIGGER_METHOD_MAP[r].show||"mouseover",(function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,s,n,i,o,d3.select(this))})).on(ITEM_TRIGGER_METHOD_MAP[r].hide||"mouseout",(function(){clearTimeout(e._hideTimeout),e.hide()}))}if(o){clearListenersOnSelector(o);var a=this.options.beforeFormat;o.on(ITEM_TRIGGER_METHOD_MAP[r].show||"mouseover",(function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,s,a,i,o,d3.select(this))})).on(ITEM_TRIGGER_METHOD_MAP[r].hide||"mouseout",(function(){clearTimeout(e._hideTimeout),e.hide()}))}},updateAxis:function(){this.triggerAxis();var t,e,i,o,r=this,s=this.alloptions,n=this.options,a=this.isVertical(),l=s.xaxis.key,h=s.yaxis.key,c=s.zaxis&&s.zaxis.key,u=null;a?(t=l,e=s.xaxis.type,i=this.comObj.getComs("axis","xaxis").getX(),u=this.comObj.getComs("axis","xaxis").getX(),o=s.xaxis.format):(t=h,e=s.yaxis.type,i=this.comObj.getComs("axis","yaxis").getX(),u=this.comObj.getComs("axis","xaxis").getX(),o=s.yaxis.format);var d=a?this.layer.width:this.layer.height,p=this.layer.svgContainer.select(".con-g"),f=r.data();this.dispatch.on("elementMouseover",(function(s){var a,y,m,g=0,x=(a=s,y=d,m=0,f.forEach((function(r,s){var n=r[t];"time"===e&&o&&(n=d3.time.format(o).parse(r[t])),diff=Math.abs(i(n)-i(a.pointValue)),u(r[t]),diff<y&&(y=diff,m=s,g=n)})),f[m]);if(r.show(x,p,n.beforeFormat||function(t){var e={};return e[l]=t[l],e[h]=t[h],c&&(e[c]=t[c]),e}),"line"===n.axisPointer){var v=i(g)+("category"===e?i.rangeBand()/2:0);r.renderGuildLayer(v)}})),this.dispatch.on("elementMouseout",(function(){r.hide()}))},updateEvent:function(t){var e=this.options,i=e.trigger;if(t&&"function"==typeof t){var o=t();o&&(this.selector=o,this.selectorText=d3.select(".series").selectAll(".series-group").selectAll(".serie-label-text"))}if(this.selector&&this.selector.style("cursor",e.show?"pointer":"default"),this.selectorText&&this.selectorText.style("cursor",e.show?"pointer":"default"),this.clearListeners(),this.renderGuildLayer(null),e.show){this.isAxisChart()&&i===TRIGGER_AXIS?this.updateAxis():this.updateItem(t);var r=this.el.select(".dc-tooltip");r.style({display:"none",position:"absolute",color:e.color,background:e.backgroundColor,padding:"".concat(e.padding,"px"),"border-radius":"5%","border-color":e.borderColor,"border-width":"".concat(e.borderWidth,"px"),"border-style":"solid","font-size":e.fontSize,"font-weight":e.fontWeight,"font-family":e.fontFamily,"pointer-events":"none"}),e.autoSize?(r[0]&&(r[0][0].style.height=""),r.style("white-space","nowrap"),r.style("width","fit-content")):r.style({width:"".concat(e.width,"px"),height:"".concat(e.height,"px"),"word-break":"break-all","white-space":"normal"})}},clearListeners:function(){clearListenersOnSelector(this.layer.svgContainer),this.selector&&clearListenersOnSelector(this.selector)},destroy:function(){this.clearListeners(),this.tooltip&&this.tooltip.remove()}}),module.exports=Tooltip; | ||
"use strict";function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var i=[],o=!0,r=!1,s=void 0;try{for(var n,a=t[Symbol.iterator]();!(o=(n=a.next()).done)&&(i.push(n.value),!e||i.length!==e);o=!0);}catch(t){r=!0,s=t}finally{try{o||null==a.return||a.return()}finally{if(r)throw s}}return i}}function _arrayWithHoles(t){if(Array.isArray(t))return t}var _=require("../util"),Com=require("./index"),d3=require("d3"),TRIGGER_AXIS="axis",STROKE_DASH_MAP={solid:"none",dashed:"10, 10",dotted:"2, 2"},ITEM_TRIGGER_METHOD_MAP={click:{show:"click",hide:"dblclick"},hover:{show:"mouseover",hide:"mouseout"}},AXIS_TRIGGER_METHOD_MAP={click:"click",hover:"mousemove"},_defaultFormatterMap={xyzAxisChart:_xyzAxisChartFormatter,xyAxisChart:_xyAxisChartFormatter,doubleLineChart:_doubelLineChartFormatter,pieChart:_pieChartFormatter,horiBarChart:_horiBarFormatter};function Tooltip(t,e,i,o){this.reset(),this.comObj=e,this.options={show:"true",formatter:{},trigger:"item",enterFocus:!1,hideDelay:100,axisPointer:"line",autoSize:!0,backgroundColor:"rgba(0,0,0,0.65)",color:"#fff",beforeFormat:null,padding:10,lineStyle:{color:"#f00",width:1,_type:"solid"}},this.init(t,i,o),this._valid()}function getTrans(t,e){if(!t&&!e)return{transX:0,transY:0};var i=getXY(t),o=i.x,r=i.y,s=getXY(e);return{transX:o+s.x,transY:r+s.y}}function getXY(t){if(!t||-1===t.indexOf("(")||-1===t.indexOf(")"))return{x:0,y:0};var e=_slicedToArray(t.split("(")[1].split(")")[0].split(","),2);return{x:+e[0],y:+e[1]}}function _creatToolTipSerieRow(t){var e=t.serie,i=t.color,o=t.value,r=t.key,s=t.format;return'<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px;\n background:'.concat(i||e&&e.color&&(e.color.gradientValue||e.color.value)||"#ccc",'"></span>\n ').concat(r?r+": ":"").concat(_.isFunction(s)&&s(o)||o,"</div>")}function _xyAxisChartFormatter(t,e,i){var o=this.options.trigger,r='<div class="dchart-tooltip">',s=this.alloptions.series,n=this.alloptions.hiddenEmptyData,a=[],l=this.alloptions.yaxis.format?d3.format(this.alloptions.yaxis.format):function(t){return t};if(o===TRIGGER_AXIS)t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach((function(t,e){return!(n&&t.__isNull)&&a.push(_creatToolTipSerieRow({serie:s[e],value:t.value,format:l}))}));else{var h=Array.isArray(t.y)?t.y[e]:t.y;n&&h.__isNull||a.push(_creatToolTipSerieRow({serie:s[e],value:h.value&&h.value.toString()||0,key:t.x.toString(),format:l}))}return r+="".concat(a.join(""),"</div>")}function _doubelLineChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions,s=r.series,n=r.series2,a=[],l=(this.data()||[]).length;return this.options.trigger===TRIGGER_AXIS?(t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach((function(t,e){return a.push(_creatToolTipSerieRow({color:s[e]&&s[e].line.color,value:t}))})),t.z&&t.z.forEach((function(t,e){return a.push(_creatToolTipSerieRow({color:n[e]&&n[e].line.color,value:t}))}))):a.push(_creatToolTipSerieRow({color:(i/l>=1?s:n)[0].point.color,value:i/l>=1?t.y&&t.y.toString()||0:t.z&&t.z.toString()||0,key:t.x.toString()})),o+="".concat(a.join(""),"</div>")}function _pieChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions,s=r.series,n=r.label,a=this._data.map((function(t){return t.y})).reduce((function(t,e){return t+e}),0),l=(t.y/a*100).toFixed(n.account.decimal)+"%";return t.y&&(o+=_creatToolTipSerieRow({color:s[e].color.value,key:t.x,value:"".concat(t.y," (").concat(l,")")})),o}function _xyzAxisChartFormatter(t,e,i){var o='<div class="dchart-tooltip">',r=this.alloptions.series,s=this._data.length,n=[];t.x&&n.push("<b>".concat(t.x.toString(),"</b>"));var a=this.options.trigger===TRIGGER_AXIS,l=d3.format(this.alloptions.yaxis.format),h=d3.format(this.alloptions.zaxis.format);return(a||i/s<1)&&t.y&&(t.y=[].concat(t.y))&&t.y.forEach((function(t,e){return n.push(_creatToolTipSerieRow({serie:r[e]&&r[e].bar,value:t.value,format:l}))})),(a||i/s>1)&&t.z&&t.z.forEach&&t.z.forEach((function(t,e){return n.push(_creatToolTipSerieRow({serie:r[e]&&r[e].line,value:t.value,format:h}))})),o+="".concat(n.join(""),"</div>")}function _horiBarFormatter(t,e,i,o){var r=this.options.trigger,s='<div class="dchart-tooltip">',n=this.alloptions.series,a=[],l=this.alloptions.xaxis.format?d3.format(this.alloptions.xaxis.format):function(t){return t};if(r===TRIGGER_AXIS)t.x&&a.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach((function(t,e){return(0===t||t)&&a.push(_creatToolTipSerieRow({format:l,serie:n[e],value:t.value}))}));else{var h=Array.isArray(t.y)?t.y[e]:t.y,c=+o.select("rect").attr("order");a.push(_creatToolTipSerieRow({format:l,serie:n[c],value:h.value&&h.value.toString()||0,key:t.x.toString()}))}return s+="".concat(a.join(""),"</div>")}function clearListenersOnSelector(t){t&&t.on&&t.on("mouseover",(function(){})).on("mousemove",(function(){})).on("mouseleave",(function(){})).on("click",(function(){})).on("mouseout",(function(){})).on("dblclick",(function(){}))}function getLeft(t,e){return t.getBBox().width-(e.options.net?e.options.innerWidth:0)}Tooltip=Com.extend(Tooltip,{init:function(t,e,i){return!(!t&&!this.el)&&(t&&(this.el=d3.select(t)),this.options=_.deepMerge(this.options,e),this.alloptions=i||this.alloptions,this)},_valid:function(){},renderSeries:function(){var t=this.options,e=this.alloptions;this.layer={};var i=this.el.select(".con-svg");this.layer.width=e.innerWidth,this.layer.height=e.innerHeight,this.layer.svgContainer=i,this.layer.x=this.comObj.getComs("axis","xaxis"),this.layer.y=this.comObj.getComs("axis","yaxis"),this.dispatch=d3.dispatch("elementMouseover","elementMouseout"),this.tooltip=this.el.select(".dc-tooltip")[0][0]?this.el.select(".dc-tooltip"):this.el.append("div").attr("class","dc-tooltip").style({display:"none",position:"absolute",color:t.color,background:t.backgroundColor,padding:t.padding+"px","border-radius":"5%"});var o=this;this.tooltip.on("mouseenter",(function(){o.options.enterFocus&&clearTimeout(o._hideTimeout)})).on("mouseout",(function(){o.options.trigger&&(clearTimeout(this._hideTimeout),o.hide(o.options.hideDelay))})),this.initGuildLayer()},show:function(){clearTimeout(this._hideTimeout),this.options.trigger===TRIGGER_AXIS&&this.isAxisChart()?this.showAxis.apply(this,arguments):this.showItem.apply(this,arguments)},showItem:function(t,e,i,o,r,s){"function"==typeof i&&(t=i.call(this,t,o,r,s));var n=this.defaultFormatter(t),a=this.options.formatter;"string"==typeof a?n=_defaultFormatterMap[a]&&_defaultFormatterMap[a].call(this,t,o,r,s):"function"==typeof a&&(n=a(t,o,r,s)),this.tooltip.html(n),this.tooltip.transition().duration(20).style("display","block");var l=d3.event||window.event,h=this.getTipPosition(l);this.tooltip.style("left",+h.x+"px").style("top",+h.y+"px")},showAxis:function(t,e,i){"function"==typeof i&&(t=i.call(this,t));var o=this.defaultFormatter(t),r=this.options.formatter;"string"==typeof r?o=_defaultFormatterMap[r]&&_defaultFormatterMap[r].call(this,t):"function"==typeof r&&(o=r(t));var s,n,a,l,h,c=d3.mouse(e[0][0]),u=this.alloptions,d=this.isVertical();d?(s=this.layer.x.getX(),n=u.xaxis.key,a=u.xaxis.type,l=this.layer.y,h=u.yaxis.orient):(s=this.layer.y.getX(),n=u.yaxis.key,a=u.yaxis.type,l=this.layer.x,h=u.xaxis.orient);var p=l.el[0][0],f=0;if(d){var y=t[n];if("time"===a)y=s(d3.time.format(u.xaxis.format).parse(t[n]));else y=s(t[n]);f=y+ +u.margin.left+(u.margin.containLabel&&"left"===h?getLeft(p,l):0)}else f=c[0]+u.margin.left;var m=d&&c[1]+u.margin.top||s("time"===a&&new Date(t[n])||t[n])+u.margin.top+(u.margin.containLabel&&"top"===h?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");var g=this.options,x=this.getTipPositionAxis({left:f+(d&&s.rangeBand&&s.rangeBand()/2||0)+2*+g.xOffset,top:m+(d?0:s.rangeBand&&s.rangeBand()/2||0)+ +g.yOffset});this.tooltip.style("left",x.left+"px").style("top",x.top+"px")},getBoxSize:function(){var t=150,e=50;if(this.options.autoSize){var i=this.tooltip&&this.tooltip.node();i&&(i.style.display="block",i.style.visibility="hidden",t=i.offsetWidth||t,e=i.offsetHeight||e,i.style.display="none",i.style.visibility="")}else t=this.options.width,e=this.options.height;return{boxWidth:t,boxHeight:e}},getTipPositionAxis:function(t){var e=t.left,i=t.top,o=document.body,r=o.offsetWidth,s=o.offsetHeight,n=this.el.node().parentElement.parentElement,a=n.offsetLeft,l=n.offsetTop,h=this.getBoxSize(),c=h.boxWidth,u=h.boxHeight,d=_.toNumber(_.get(n,"style.height").replace("px","")),p=_.toNumber(_.get(n,"style.width").replace("px",""));return(a+e+c>r||p-e<c)&&(e=Math.max(e-c,0)),(l+i+u>s||d-i<u)&&(i=Math.max(i-u)),{top:i,left:e}},getTipPosition:function(t){var e=this.options,i=e.xOffset,o=e.yOffset,r=this.getBoxSize(),s=r.boxWidth,n=r.boxHeight,a=document.body,l=a.offsetWidth,h=a.offsetHeight,c=this.el.node().parentElement.parentElement,u=c.offsetLeft,d=c.offsetTop,p=t.offsetX,f=t.offsetY,y=_.toNumber(_.get(c,"style.height").replace("px","")),m=_.toNumber(_.get(c,"style.width").replace("px","")),g={x:p+i,y:f+o};return(u+p+s+i>l||m-p<s)&&(g.x=Math.max(p-s,0)),(d+f+n+o>h||y-f<n)&&(g.y=Math.max(f-n)),g},hide:function(){this.options.enterFocus=!0,this.options.enterFocus?this._delayHide():this._contentHide()},_contentHide:function(){this.tooltip.style("display","none")},_delayHide:function(){var t=this;this.options.enterFocus&&(clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout((function(){t._contentHide()}),this.options.hideDelay))},defaultFormatter:function(t){var e='<div class="dchart-tooltip">',i=0;return _.forIn(t,(function(t,o,r){e+=(0!==i?"<br>":"")+o+": "+(t=t||0).toString(),i++})),e+="</div>"},initGuildLayer:function(){var t=this.alloptions;this.wrap=this.el.select(".guildLayer")[0][0]?this.el.select(".guildLayer"):this.el.select(".con-svg").append("g").attr({class:"guildLayer",transform:"translate("+t.margin.left+","+t.margin.top+")"});var e=this.wrap.select(".guildLineLayer")[0][0]?this.wrap.select(".guildLineLayer"):this.wrap.append("g").attr("class","guildLineLayer");e.style("pointer-events","none"),e.select(".guildLine")[0][0]?e.select(".guildLine"):e.append("g").attr("class","guildLine")},triggerAxis:function(){var t=this,e=this,i=(this.options,this.layer.width),o=this.layer.height,r=this.layer.y,s=this.layer.x,n=this.dispatch,a=this.alloptions.margin,l=this,h=this.alloptions,c=this.options.triggerMethod,u=10,d=this.layer.svgContainer,p=getTrans(this.el.select(".con-g").attr("transform"),this.el.select(".series").attr("transform")),f=p.transX;p.transY;d.on(AXIS_TRIGGER_METHOD_MAP[c]||"mousemove",(function(){if(e.isAxisChart()&&e.options.trigger===TRIGGER_AXIS){var t=d3.event,c=t.offsetX,d=t.offsetY,p=e.isVertical(),y=p&&s.getX()||r.getX(),m=p&&y.range()||_.clone(y.range()).reverse(),g=p&&y.domain()||_.clone(y.domain()).reverse();if(c-=a.left,d-=a.top,a.containLabel&&("top"===h.xaxis.orient&&(d-=s.options.__height),"left"===h.yaxis.orient&&(c-=f)),c+u<0||d+u<0||c-u>i||d-u>o)return n.elementMouseout({mouseX:c,mouseY:d}),void l.renderGuildLayer(null);l.renderGuildLayer(null);var x="function"==typeof y.rangeBands,v=void 0,T=p?c:d;if(x){var b=d3.bisect(m,T),w=y.rangeBand(),S=m.length;if(0===b)v=g[b];else if(b===S)v=g[b-1];else{var A=Math.abs(m[b]-T);Math.abs(T-m[b-1]-w)<A&&(b-=1),v=g[b]}}else v=y.invert(T);n.elementMouseover({mouseX:c,mouseY:d,pointValue:v})}})),d.on("mouseleave",(function(){"hover"===c&&(t.renderGuildLayer(null),t.hide())}))},hideGuidLine:function(){this.el.select(".guildLine").selectAll("line").attr("display","none")},renderGuildLayer:function(t){if(0!==t&&!t)return this.hideGuidLine(),!1;var e=getTrans(this.el.select(".con-g").attr("transform"),this.el.select(".series").attr("transform")),i=e.transX,o=e.transY;this.el.select(".guildLayer").attr("transform","translate(".concat(i,", ").concat(o,")"));var r=this.options.lineStyle,s=this.isVertical(),n=this.el.select(".guildLine").selectAll("line").data(null!=t?[t]:[],String);n.enter().append("line");var a=this.layer.y.options,l=this.alloptions;n.attr("display","block").attr("class","tooltip-guideline").attr("x1",(function(t){return s&&_.isNumber(t)?t:0})).attr("x2",(function(t){return s&&_.isNumber(t)?t:a.innerWidth})).attr("y1",(function(t){return s?a.innerHeight||l.innerHeight:t})).attr("y2",(function(t){return!s&&_.isNumber(t)?t:0})).attr("stroke",r.color).attr("stroke-width",r.width).attr("stroke-dasharray",STROKE_DASH_MAP[r._type]).style("cursor","pointer"),n.exit().remove()},isVertical:function(){var t=this.alloptions;return"time"===t.xaxis.type||"category"===t.xaxis.type||"time"!==t.yaxis.type&&"category"!==t.yaxis.type},isAxisChart:function(){var t=this.alloptions;return t&&t.xaxis&&t.yaxis},updateItem:function(t){var e=this,i=this.selector,o=this.selectorText,r=this.options.triggerMethod,s=this.layer.svgContainer.select(".con-g");if(i){clearListenersOnSelector(i);var n=this.options.beforeFormat;i.on(ITEM_TRIGGER_METHOD_MAP[r].show||"mouseover",(function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,s,n,i,o,d3.select(this))})).on(ITEM_TRIGGER_METHOD_MAP[r].hide||"mouseout",(function(){clearTimeout(e._hideTimeout),e.hide()}))}if(o){clearListenersOnSelector(o);var a=this.options.beforeFormat;o.on(ITEM_TRIGGER_METHOD_MAP[r].show||"mouseover",(function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,s,a,i,o,d3.select(this))})).on(ITEM_TRIGGER_METHOD_MAP[r].hide||"mouseout",(function(){clearTimeout(e._hideTimeout),e.hide()}))}},updateAxis:function(){this.triggerAxis();var t,e,i,o,r=this,s=this.alloptions,n=this.options,a=this.isVertical(),l=s.xaxis.key,h=s.yaxis.key,c=s.zaxis&&s.zaxis.key,u=null;a?(t=l,e=s.xaxis.type,i=this.comObj.getComs("axis","xaxis").getX(),u=this.comObj.getComs("axis","xaxis").getX(),o=s.xaxis.format):(t=h,e=s.yaxis.type,i=this.comObj.getComs("axis","yaxis").getX(),u=this.comObj.getComs("axis","xaxis").getX(),o=s.yaxis.format);var d=a?this.layer.width:this.layer.height,p=this.layer.svgContainer.select(".con-g"),f=r.data();this.dispatch.on("elementMouseover",(function(s){var a,y,m,g=0,x=(a=s,y=d,m=0,f.forEach((function(r,s){var n=r[t];"time"===e&&o&&(n=d3.time.format(o).parse(r[t])),diff=Math.abs(i(n)-i(a.pointValue)),u(r[t]),diff<y&&(y=diff,m=s,g=n)})),f[m]);if(r.show(x,p,n.beforeFormat||function(t){var e={};return e[l]=t[l],e[h]=t[h],c&&(e[c]=t[c]),e}),"line"===n.axisPointer){var v=i(g)+("category"===e?i.rangeBand()/2:0);r.renderGuildLayer(v)}})),this.dispatch.on("elementMouseout",(function(){r.hide()}))},updateEvent:function(t){var e=this.options,i=e.trigger;if(t&&"function"==typeof t){var o=t();o&&(this.selector=o,this.selectorText=d3.select(".series").selectAll(".series-group").selectAll(".serie-label-text"))}if(this.selector&&this.selector.style("cursor",e.show?"pointer":"default"),this.selectorText&&this.selectorText.style("cursor",e.show?"pointer":"default"),this.clearListeners(),this.renderGuildLayer(null),e.show){this.isAxisChart()&&i===TRIGGER_AXIS?this.updateAxis():this.updateItem(t);var r=this.el.select(".dc-tooltip");r.style({display:"none",position:"absolute",color:e.color,background:e.backgroundColor,padding:"".concat(e.padding,"px"),"border-radius":"5%","border-color":e.borderColor,"border-width":"".concat(e.borderWidth,"px"),"border-style":"solid","font-size":e.fontSize,"font-weight":e.fontWeight,"font-family":e.fontFamily,"pointer-events":"none"}),e.autoSize?(r[0]&&(r[0][0].style.height=""),r.style("white-space","nowrap"),r.style("width","fit-content")):r.style({width:"".concat(e.width,"px"),height:"".concat(e.height,"px"),"word-break":"break-all","white-space":"normal"})}},clearListeners:function(){clearListenersOnSelector(this.layer.svgContainer),this.selector&&clearListenersOnSelector(this.selector)},destroy:function(){this.clearListeners(),this.tooltip&&this.tooltip.remove()}}),module.exports=Tooltip; |
{ | ||
"name": "dchart-core", | ||
"version": "2.8.1", | ||
"version": "2.8.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
155467