dchart-core
Advanced tools
Comparing version 2.6.3 to 2.6.4
@@ -1,1 +0,1 @@ | ||
"use strict";var DataV=require("./barHorizontal"),d3=require("d3"),_=require("../util"),animationController=require("../util/animation");function BarMultiHoriColumn(e,r){var i={xaxis:{orient:"bottom",key:"y",min:0},yaxis:{type:"category",key:"x"},label:{pos:"center",dy:"0"}};this.enterSerie=[],this.outerSerie=[],i=_.deepMerge(i,r),DataV.call(this,e,i)}BarMultiHoriColumn=DataV.extend(BarMultiHoriColumn,{renderSeries:function(){this.svg.classed("bar-chart-g",!0);var e,r,i=this.options,t=this.data(),s=this,a=i.xaxis.key,l=i.yaxis.key;e=this.getComs("axis","xaxis"),r=this.getComs("axis","yaxis");var n=e.getX(),o=r.getX(),u=(_.maxBy(t,function(e){return e[a].length})[a].length,this.series.selectAll(".series-group").data(this._data,function(e){return e[l]}));this.outerSeries=u.exit().remove(),this.enterSeries=u.enter().append("g").attr("class","series-group"),u.each(function(r,t){var u=d3.select(this);u.selectAll(".serie-text").remove();var c=u.append("g").attr("class","serie-text"),d=u.selectAll(".serie-single").data(s.trans(r)),m=d.enter().insert("g",":first-child").attr("class","serie serie-single");m.append("rect"),d.each(function(r,t){d3.select(this).select("rect").attr({class:"serie serie"+(t+1),x:n(e.getMin()),y:o(r[l]),width:0,height:o.rangeBand()}),c.append("text").attr({class:"serie-label serie"+(t+1)+"-label",x:n(e.getMin()),y:o(r[l])+o.rangeBand()/2,dx:i.series[t]&&i.series[t].label&&i.series[t].label.dx||i.label.dx||0,dy:i.series[t]&&i.series[t].label&&i.series[t].label.dy||i.label.dy||0})}),function(e,r,t){e.each(function(e,u){var c=d3.select(this),d=c.selectAll(".serie"),m=d3.select(c.node().parentNode).select(".serie-label:nth-child("+(u+1)+")"),h=Math.abs(n(0)-n(e[a])),x=0,b=0;e[a]>=0?x=n(Math.max(r.maxSum,i.xaxis.min)):(r.minSum+=e[a],x=n(r.minSum)),i.xaxis.min>r.maxSum?(r.maxSum+=e[a],b=Math.abs(n(i.xaxis.min)-n(e[a]))):(r.maxSum+=e[a],b=h);var f=o.rangeBand(),y={x:x,y:o(e[l]),width:b,height:f,class:"serie serie"+(u+1)},g={x:function(){var t=i.label.pos;return"left"===t?e[a]>=0&&n(r.maxSum)-h||n(r.minSum):"center"===t?e[a]>=0&&n(r.maxSum)-h/2||n(r.minSum)+h/2:e[a]>=0&&n(r.maxSum)||n(r.minSum)-h},y:o(e[l])+f/2,dx:i.series[u]&&i.series[u].label&&i.series[u].label.dx||i.label.dx||0,dy:i.series[u]&&i.series[u].label&&i.series[u].label.dy||i.label.dy||0};d.attr({__width:b,__x:x}),animationController({options:i,animationHandler:function({duration:e,ease:r,delay:i}){d.transition().duration(e).delay(i).ease(r).attr(y),m.transition().duration(e).delay(i).ease(r).attr(g)},notAnimationHandler:function(){d.attr(y),m.attr(g)},animationFromOriginHandler:function(){d.attr({x:0,y:o(0),width:0}),m.attr({x:0,y:o(0),opacity:0})},index:u}),d.style({fill:function(){return i.series[u]&&i.series[u].color&&i.series[u].color.res||i.color&&i.color.res},stroke:function(){return i.series[u]&&i.series[u].frameColor&&i.series[u].frameColor.res||i.frameColor&&i.frameColor.res},"stroke-width":function(){return i.series[u]&&i.series[u].frameColorWidth||i.frameColorWidth}}),m.html(function(){var l=i.series[u]&&i.series[u].label&&i.series[u].label.format||i.label.format||null;return l?l.call(s,e,t):r[a][u]}).style({"text-anchor":function(){return i.series[u]&&i.series[u].label&&i.series[u].label.anchor||i.label.anchor||"middle"},display:function(){return(i.series[u]&&"boolean"==typeof i.series[u].show?i.series[u].show:"boolean"==typeof i.label.show&&i.label.show)?"block":"none"},"font-size":function(){return(i.series[u]&&i.series[u].label&&i.series[u].label.fontSize||i.label.fontSize||"10")+"px"},"font-weight":function(){return i.series[u]&&i.series[u].label&&i.series[u].label.fontWeight||i.label.fontWeight},fill:function(){return i.series[u]&&i.series[u].label&&i.series[u].label.color||i.label.color},stroke:i.label.strokeWidth&&i.series[u]&&i.series[u].label&&i.series[u].label.color||i.label.color||"#fff","stroke-width":i.label.strokeWidth,"vertical-align":"middle","alignment-baseline":"middle","line-height":f,height:f})})}(d,r,t),s.enterSerie[t]=m,s.outerSerie[t]=d.exit().remove()})},updateSeries:function(){BarMultiHoriColumn.prototype.renderSeries.call(this)}}),module.exports=BarMultiHoriColumn; | ||
"use strict";var DataV=require("./barHorizontal"),d3=require("d3"),_=require("../util"),animationController=require("../util/animation");function BarMultiHoriColumn(e,r){var i={xaxis:{orient:"bottom",key:"y",min:0},yaxis:{type:"category",key:"x"},label:{pos:"center",dy:"0"}};this.enterSerie=[],this.outerSerie=[],i=_.deepMerge(i,r),DataV.call(this,e,i)}BarMultiHoriColumn=DataV.extend(BarMultiHoriColumn,{renderSeries:function(){this.svg.classed("bar-chart-g",!0);var e,r,i=this.options,t=this.data(),s=this,a=i.xaxis.key,l=i.yaxis.key;e=this.getComs("axis","xaxis"),r=this.getComs("axis","yaxis");var n=e.getX(),o=r.getX(),u=(_.maxBy(t,function(e){return e[a].length})[a].length,this.series.selectAll(".series-group").data(this._data,function(e){return e[l]}));this.outerSeries=u.exit().remove(),this.enterSeries=u.enter().append("g").attr("class","series-group"),u.each(function(r,t){var u=d3.select(this);u.selectAll(".serie-text").remove();var d=u.append("g").attr("class","serie-text"),c=u.selectAll(".serie-single").data(s.trans(r)),m=c.enter().insert("g",":first-child").attr("class","serie serie-single");m.append("rect"),c.each(function(r,t){d3.select(this).select("rect").attr({class:"serie serie"+(t+1),x:n(e.getMin()),y:o(r[l]),width:0,height:o.rangeBand()}),d.append("text").attr({class:"serie-label serie"+(t+1)+"-label",x:n(e.getMin()),y:o(r[l])+o.rangeBand()/2,dx:i.series[t]&&i.series[t].label&&i.series[t].label.dx||i.label.dx||0,dy:i.series[t]&&i.series[t].label&&i.series[t].label.dy||i.label.dy||0})}),function(e,r,t){e.each(function(e,u){var d=d3.select(this),c=d.selectAll(".serie"),m=d3.select(d.node().parentNode).select(".serie-label:nth-child("+(u+1)+")"),h=Math.abs(n(0)-n(e[a])),x=0,b=0;e[a]>=0?x=n(Math.max(r.maxSum,i.xaxis.min)):(r.minSum+=e[a],x=n(r.minSum)),i.xaxis.min>r.maxSum?(r.maxSum+=e[a],b=Math.abs(n(i.xaxis.min)-n(e[a]))):(r.maxSum+=e[a],b=h);var f=o.rangeBand(),y={x:x,y:o(e[l]),width:b,height:f,class:"serie serie"+(u+1)},g={x:function(){var t=i.label.pos;return"left"===t?e[a]>=0&&n(r.maxSum)-h||n(r.minSum):"center"===t?e[a]>=0&&n(r.maxSum)-h/2||n(r.minSum)+h/2:e[a]>=0&&n(r.maxSum)||n(r.minSum)-h},y:o(e[l])+f/2,dx:i.series[u]&&i.series[u].label&&i.series[u].label.dx||i.label.dx||0,dy:i.series[u]&&i.series[u].label&&i.series[u].label.dy||i.label.dy||0};c.attr({__width:b,__x:x,order:u}),animationController({options:i,animationHandler:function({duration:e,ease:r,delay:i}){c.transition().duration(e).delay(i).ease(r).attr(y),m.transition().duration(e).delay(i).ease(r).attr(g)},notAnimationHandler:function(){c.attr(y),m.attr(g)},animationFromOriginHandler:function(){c.attr({x:0,y:o(0),width:0}),m.attr({x:0,y:o(0),opacity:0})},index:u}),c.style({fill:function(){return i.series[u]&&i.series[u].color&&i.series[u].color.res||i.color&&i.color.res},stroke:function(){return i.series[u]&&i.series[u].frameColor&&i.series[u].frameColor.res||i.frameColor&&i.frameColor.res},"stroke-width":function(){return i.series[u]&&i.series[u].frameColorWidth||i.frameColorWidth}}),m.html(function(){var l=i.series[u]&&i.series[u].label&&i.series[u].label.format||i.label.format||null;return l?l.call(s,e,t):r[a][u]}).style({"text-anchor":function(){return i.series[u]&&i.series[u].label&&i.series[u].label.anchor||i.label.anchor||"middle"},display:function(){return(i.series[u]&&"boolean"==typeof i.series[u].show?i.series[u].show:"boolean"==typeof i.label.show&&i.label.show)?"block":"none"},"font-size":function(){return(i.series[u]&&i.series[u].label&&i.series[u].label.fontSize||i.label.fontSize||"10")+"px"},"font-weight":function(){return i.series[u]&&i.series[u].label&&i.series[u].label.fontWeight||i.label.fontWeight},fill:function(){return i.series[u]&&i.series[u].label&&i.series[u].label.color||i.label.color},stroke:i.label.strokeWidth&&i.series[u]&&i.series[u].label&&i.series[u].label.color||i.label.color||"#fff","stroke-width":i.label.strokeWidth,"vertical-align":"middle","alignment-baseline":"middle","line-height":f,height:f})})}(c,r,t),s.enterSerie[t]=m,s.outerSerie[t]=c.exit().remove()})},updateSeries:function(){BarMultiHoriColumn.prototype.renderSeries.call(this)}}),module.exports=BarMultiHoriColumn; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _=require("../util"),Com=require("./index"),d3=require("d3");const 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"},_creatToolTipSerieRow=({serie:t,color:e,value:i,key:o})=>`<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px; \n background-color:${e||t&&t.color&&t.color.value||"#ccc"}"></span>\n ${o?o+": ":""}${i}</div>`,_xyAxisChartFormatter=function(t,e,i){var o=this.options.trigger,s='<div class="dchart-tooltip">';let r=this.alloptions.series,a=[];if(o===TRIGGER_AXIS)t.x&&a.push(`<b>${t.x.toString()}</b>`),t.y&&t.y.forEach&&t.y.forEach((t,e)=>(0===t||t)&&a.push(_creatToolTipSerieRow({serie:r[e],value:t})));else{let i=Array.isArray(t.y)?t.y[e]:t.y;a.push(_creatToolTipSerieRow({serie:r[e],value:i&&i.toString()||0,key:t.x.toString()}))}return s+=`${a.join("")}</div>`},_xyzAxisChartFormatter=function(t,e,i){var o='<div class="dchart-tooltip">';let s=this.alloptions.series,r=this._data.length,a=[];t.x&&a.push(`<b>${t.x.toString()}</b>`);let n=this.options.trigger===TRIGGER_AXIS;return(n||i/r<1)&&t.y&&(t.y=[].concat(t.y))&&t.y.forEach((t,e)=>a.push(_creatToolTipSerieRow({serie:s[e]&&s[e].bar,value:t}))),(n||i/r>1)&&t.z&&t.z.forEach&&t.z.forEach((t,e)=>a.push(_creatToolTipSerieRow({serie:s[e]&&s[e].line,value:t}))),o+=`${a.join("")}</div>`},_doubelLineChartFormatter=function(t,e,i){var o='<div class="dchart-tooltip">';let{series:s,series2:r}=this.alloptions,a=[],n=(this.data()||[]).length;return this.options.trigger===TRIGGER_AXIS?(t.x&&a.push(`<b>${t.x.toString()}</b>`),t.y&&t.y.forEach((t,e)=>a.push(_creatToolTipSerieRow({color:s[e]&&s[e].line.color,value:t}))),t.z&&t.z.forEach((t,e)=>a.push(_creatToolTipSerieRow({color:r[e]&&r[e].line.color,value:t})))):a.push(_creatToolTipSerieRow({color:(i/n>1?s:r)[0].point.color,value:i/n>1?t.y&&t.y.toString()||0:t.z&&t.z.toString()||0,key:t.x.toString()})),o+=`${a.join("")}</div>`},_pieChartFormatter=function(t,e,i){let o='<div class="dchart-tooltip">',{series:s,label:r}=this.alloptions,a=this._data.map(t=>t.y).reduce((t,e)=>t+e,0),n=(t.y/a*100).toFixed(r.account.decimal)+"%";return t.y&&(o+=_creatToolTipSerieRow({color:s[e].color.value,key:t.x,value:`${t.y} (${n})`})),o},_defaultFormatterMap={xyzAxisChart:_xyzAxisChartFormatter,xyAxisChart:_xyAxisChartFormatter,doubleLineChart:_doubelLineChartFormatter,pieChart:_pieChartFormatter},clearListenersOnSelector=t=>{t&&t.on&&t.on("mouseover",()=>{}).on("mousemove",()=>{}).on("mouseleave",()=>{}).on("click",()=>{}).on("mouseout",()=>{}).on("dblclick",()=>{})},getLeft=(t,e)=>t.getBBox().width-(e.options.net?e.options.innerWidth:0);function Tooltip(t,e,i,o){this.reset(),this.comObj=e,this.options={show:"true",formatter:{},trigger:"item",enterFocus:!1,hideDelay:100,axisPointer:"line",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 getXY(t){if(!t||-1===t.indexOf("(")||-1===t.indexOf(")"))return{x:0,y:0};let[e,i]=t.split("(")[1].split(")")[0].split(",");return{x:+e,y:+i}}function getTrans(t,e){if(!t&&!e)return{transX:0,transY:0};let{x:i,y:o}=getXY(t),{x:s,y:r}=getXY(e);return{transX:i+s,transY:o+r}}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(...t){clearTimeout(this._hideTimeout),this.options.trigger===TRIGGER_AXIS&&this.isAxisChart()?this.showAxis(...t):this.showItem(...t)},showItem(t,e,i,o,s){"function"==typeof i&&(t=i.call(this,t,o,s));var r=this.defaultFormatter(t);let a=this.options.formatter;"string"==typeof a?r=_defaultFormatterMap[a]&&_defaultFormatterMap[a].call(this,t,o,s):"function"==typeof a&&(r=a(t,o,s)),this.tooltip.html(r),this.tooltip.transition().duration(20).style("display","block");let n=d3.event||window.event;this.tooltip.style("left",+n.offsetX+ +this.options.xOffset+"px").style("top",+n.offsetY+ +this.options.yOffset+"px")},showAxis:function(t,e,i){"function"==typeof i&&(t=i.call(this,t));var o=this.defaultFormatter(t);let s=this.options.formatter;"string"==typeof s?o=_defaultFormatterMap[s]&&_defaultFormatterMap[s].call(this,t):"function"==typeof s&&(o=s(t));var r,a,n,l,h,c=d3.mouse(e[0][0]),d=this.alloptions,u=this.isVertical();u?(r=this.layer.x.getX(),a=d.xaxis.key,n=d.xaxis.type,l=this.layer.y,h=d.yaxis.orient):(r=this.layer.y.getX(),a=d.yaxis.key,n=d.yaxis.type,l=this.layer.x,h=d.xaxis.orient);let p=l.el[0][0];var y=u?r("time"===n&&new Date(t[a])||t[a])+d.margin.left+(d.margin.containLabel&&"left"===h?getLeft(p,l):0):c[0]+d.margin.left,g=u&&c[1]+d.margin.top||r("time"===n&&new Date(t[a])||t[a])+d.margin.top+(d.margin.containLabel&&"top"===h?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");let f=this.options;this.tooltip.style("left",y+(u&&r.rangeBand&&r.rangeBand()/2||0)+2*+f.xOffset+"px").style("top",g+(u?0:r.rangeBand&&r.rangeBand()/2||0)+ +f.yOffset+"px")},hide:function(){this.options.enterFocus=!0,this.options.enterFocus?this._delayHide():this._contentHide()},_contentHide:function(){this.tooltip.style("display","none")},_delayHide:function(){this.options.enterFocus&&(clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._contentHide()},this.options.hideDelay))},defaultFormatter:function(t){var e='<div class="dchart-tooltip">',i=0;return _.forIn(t,function(t,o,s){e+=(0!==i?"<br>":"")+o+": "+(t=t||0).toString(),i++}),e+="</div>"},initGuildLayer:function(){let 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.select(".guildLine")[0][0]?e.select(".guildLine"):e.append("g").attr("class","guildLine")},triggerAxis(){var t=this,e=(this.options,this.layer.width),i=this.layer.height,o=this.layer.y,s=this.layer.x,r=this.dispatch,a=this.alloptions.margin,n=this,l=this.alloptions;let h=this.options.triggerMethod;const c=.5;let d=this.layer.svgContainer,u=this.el.select(".con-g").attr("transform"),p=this.el.select(".series").attr("transform"),{transX:y,transY:g}=getTrans(u,p);d.on(AXIS_TRIGGER_METHOD_MAP[h]||"mousemove",function(){if(t.isAxisChart()&&t.options.trigger===TRIGGER_AXIS){var h=d3.event,d=h.offsetX,u=h.offsetY,p=t.isVertical(),g=p&&s.getX()||o.getX(),f=p&&g.range()||_.clone(g.range()).reverse(),m=p&&g.domain()||_.clone(g.domain()).reverse();if(d-=a.left,u-=a.top,a.containLabel&&("top"===l.xaxis.orient&&(u-=s.options.__height),"left"===l.yaxis.orient&&(d-=y)),d<0||u<0||d>e||u>i)return r.elementMouseout({mouseX:d,mouseY:u}),void n.renderGuildLayer(null);n.renderGuildLayer(null);var x="function"==typeof g.rangeBands,v=void 0,T=p?d:u;if(x){var b=d3.bisect(f,T)-1;if(f[b]+g.rangeBand()*(1+c)>=T)v=m[b];else{if(b=d3.bisect(f,T+c*g.rangeBand())-1,!(f[b]+g.rangeBand()*(1+c)>=T))return r.elementMouseout({mouseX:d,mouseY:u}),void n.renderGuildLayer(null);v=m[b]}}else v=g.invert(T);r.elementMouseover({mouseX:d,mouseY:u,pointValue:v})}}),d.on("mouseleave",()=>{"hover"===h&&(this.renderGuildLayer(null),this.hide())})},hideGuidLine(){this.el.select(".guildLine").selectAll("line").attr("display","none")},renderGuildLayer:function(t){if(0!==t&&!t)return this.hideGuidLine(),!1;let e=this.el.select(".con-g").attr("transform"),i=this.el.select(".series").attr("transform"),{transX:o,transY:s}=getTrans(e,i);this.el.select(".guildLayer").attr("transform",`translate(${o}, ${s})`);let{lineStyle:r}=this.options;var a=this.isVertical(),n=this.el.select(".guildLine").selectAll("line").data(null!=t?[t]:[],String);n.enter().append("line");let l=this.layer.y.options,h=this.alloptions;n.attr("display","block").attr("class","tooltip-guideline").attr("x1",t=>a&&_.isNumber(t)?t:0).attr("x2",t=>a&&_.isNumber(t)?t:l.innerWidth).attr("y1",t=>a?l.innerHeight||h.innerHeight:t).attr("y2",t=>!a&&_.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(){let t=this.alloptions;return t&&t.xaxis&&t.yaxis},updateItem(t){let e=this.selector,i=this.options.triggerMethod,o=this.layer.svgContainer.select(".con-g");e&&(clearListenersOnSelector(e),e.on(ITEM_TRIGGER_METHOD_MAP[i].show||"mouseover",(t,e,i)=>{clearTimeout(this._hideTimeout),(t||void 0!==e||void 0!==i)&&this.show(t&&t.data||t,o,this.options.beforeFormat,e,i)}).on(ITEM_TRIGGER_METHOD_MAP[i].hide||"mouseout",()=>{clearTimeout(this._hideTimeout),this.hide()}))},updateAxis(){this.triggerAxis();var t=this;let{alloptions:e,options:i}=this;var o,s,r,a,n=this.isVertical(),l=e.xaxis.key,h=e.yaxis.key,c=e.zaxis&&e.zaxis.key;let d=null;n?(o=l,s=e.xaxis.type,r=this.comObj.getComs("axis","xaxis").getX(),d=this.comObj.getComs("axis","xaxis").getX(),a=e.xaxis.format):(o=h,s=e.yaxis.type,r=this.comObj.getComs("axis","yaxis").getX(),d=this.comObj.getComs("axis","xaxis").getX(),a=e.yaxis.format);let u=n?this.layer.width:this.layer.height,p=this.layer.svgContainer.select(".con-g"),y=t.data();this.dispatch.on("elementMouseover",function(e){let n=0,g=function(t){let e=u,i=0;return y.forEach(function(l,h){var c=l[o];"time"===s&&a&&(c=d3.time.format(a).parse(l[o])),diff=Math.abs(r(c)-r(t.pointValue)),d(l[o]),diff<e&&(e=diff,i=h,n=c)}),y[i]}(e);if(t.show(g,p,i.beforeFormat||function(t){var e={};return e[l]=t[l],e[h]=t[h],c&&(e[c]=t[c]),e}),"line"===i.axisPointer){var f=r(n)+("category"===s?r.rangeBand()/2:0);t.renderGuildLayer(f)}}),this.dispatch.on("elementMouseout",function(){t.hide()})},updateEvent:function(t){var e=this.options;let i=e.trigger;if(t&&"function"==typeof t){let e=t();e&&(this.selector=e)}if(this.selector&&this.selector.style("cursor",e.show?"pointer":"default"),this.clearListeners(),this.renderGuildLayer(null),e.show){this.isAxisChart()&&i===TRIGGER_AXIS?this.updateAxis():this.updateItem(t);let o=this.el.select(".dc-tooltip");o.style({display:"none",position:"absolute",color:e.color,background:e.backgroundColor,padding:`${e.padding}px`,"border-radius":"5%","border-color":e.borderColor,"border-width":`${e.borderWidth}px`,"border-style":"solid","font-size":e.fontSize,"font-weight":e.fontWeight,"font-family":e.fontFamily,"pointer-events":"none"}),e.autoSize?(o[0]&&(o[0][0].style.height=""),o.style("white-space","nowrap"),o.style("width","fit-content")):o.style({width:`${e.width}px`,height:`${e.height}px`,"word-break":"break-all","white-space":"normal"})}},clearListeners(){clearListenersOnSelector(this.layer.svgContainer),this.selector&&clearListenersOnSelector(this.selector)},destroy:function(){this.clearListeners(),this.tooltip&&this.tooltip.remove()}}),module.exports=Tooltip; | ||
"use strict";var _=require("../util"),Com=require("./index"),d3=require("d3");const 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"},_creatToolTipSerieRow=({serie:t,color:e,value:i,key:o})=>`<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px; \n background-color:${e||t&&t.color&&t.color.value||"#ccc"}"></span>\n ${o?o+": ":""}${i}</div>`,_xyAxisChartFormatter=function(t,e,i){var o=this.options.trigger,s='<div class="dchart-tooltip">';let r=this.alloptions.series,a=[];if(o===TRIGGER_AXIS)t.x&&a.push(`<b>${t.x.toString()}</b>`),t.y&&t.y.forEach&&t.y.forEach((t,e)=>(0===t||t)&&a.push(_creatToolTipSerieRow({serie:r[e],value:t})));else{let i=Array.isArray(t.y)?t.y[e]:t.y;a.push(_creatToolTipSerieRow({serie:r[e],value:i&&i.toString()||0,key:t.x.toString()}))}return s+=`${a.join("")}</div>`},_xyzAxisChartFormatter=function(t,e,i){var o='<div class="dchart-tooltip">';let s=this.alloptions.series,r=this._data.length,a=[];t.x&&a.push(`<b>${t.x.toString()}</b>`);let n=this.options.trigger===TRIGGER_AXIS;return(n||i/r<1)&&t.y&&(t.y=[].concat(t.y))&&t.y.forEach((t,e)=>a.push(_creatToolTipSerieRow({serie:s[e]&&s[e].bar,value:t}))),(n||i/r>1)&&t.z&&t.z.forEach&&t.z.forEach((t,e)=>a.push(_creatToolTipSerieRow({serie:s[e]&&s[e].line,value:t}))),o+=`${a.join("")}</div>`},_doubelLineChartFormatter=function(t,e,i){var o='<div class="dchart-tooltip">';let{series:s,series2:r}=this.alloptions,a=[],n=(this.data()||[]).length;return this.options.trigger===TRIGGER_AXIS?(t.x&&a.push(`<b>${t.x.toString()}</b>`),t.y&&t.y.forEach((t,e)=>a.push(_creatToolTipSerieRow({color:s[e]&&s[e].line.color,value:t}))),t.z&&t.z.forEach((t,e)=>a.push(_creatToolTipSerieRow({color:r[e]&&r[e].line.color,value:t})))):a.push(_creatToolTipSerieRow({color:(i/n>1?s:r)[0].point.color,value:i/n>1?t.y&&t.y.toString()||0:t.z&&t.z.toString()||0,key:t.x.toString()})),o+=`${a.join("")}</div>`},_pieChartFormatter=function(t,e,i){let o='<div class="dchart-tooltip">',{series:s,label:r}=this.alloptions,a=this._data.map(t=>t.y).reduce((t,e)=>t+e,0),n=(t.y/a*100).toFixed(r.account.decimal)+"%";return t.y&&(o+=_creatToolTipSerieRow({color:s[e].color.value,key:t.x,value:`${t.y} (${n})`})),o},_horiBarFormatter=function(t,e,i,o){var s=this.options.trigger,r='<div class="dchart-tooltip">';let a=this.alloptions.series,n=[];if(s===TRIGGER_AXIS)t.x&&n.push(`<b>${t.x.toString()}</b>`),t.y&&t.y.forEach&&t.y.forEach((t,e)=>(0===t||t)&&n.push(_creatToolTipSerieRow({serie:a[e],value:t})));else{let i=Array.isArray(t.y)?t.y[e]:t.y,s=+o.select("rect").attr("order");n.push(_creatToolTipSerieRow({serie:a[s],value:i&&i.toString()||0,key:t.x.toString()}))}return r+=`${n.join("")}</div>`},_defaultFormatterMap={xyzAxisChart:_xyzAxisChartFormatter,xyAxisChart:_xyAxisChartFormatter,doubleLineChart:_doubelLineChartFormatter,pieChart:_pieChartFormatter,horiBarChart:_horiBarFormatter},clearListenersOnSelector=t=>{t&&t.on&&t.on("mouseover",()=>{}).on("mousemove",()=>{}).on("mouseleave",()=>{}).on("click",()=>{}).on("mouseout",()=>{}).on("dblclick",()=>{})},getLeft=(t,e)=>t.getBBox().width-(e.options.net?e.options.innerWidth:0);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 getXY(t){if(!t||-1===t.indexOf("(")||-1===t.indexOf(")"))return{x:0,y:0};let[e,i]=t.split("(")[1].split(")")[0].split(",");return{x:+e,y:+i}}function getTrans(t,e){if(!t&&!e)return{transX:0,transY:0};let{x:i,y:o}=getXY(t),{x:s,y:r}=getXY(e);return{transX:i+s,transY:o+r}}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(...t){clearTimeout(this._hideTimeout),this.options.trigger===TRIGGER_AXIS&&this.isAxisChart()?this.showAxis(...t):this.showItem(...t)},showItem(t,e,i,o,s,r){"function"==typeof i&&(t=i.call(this,t,o,s,r));var a=this.defaultFormatter(t);let n=this.options.formatter;"string"==typeof n?a=_defaultFormatterMap[n]&&_defaultFormatterMap[n].call(this,t,o,s,r):"function"==typeof n&&(a=n(t,o,s,r)),this.tooltip.html(a),this.tooltip.transition().duration(20).style("display","block");let l=d3.event||window.event;this.tooltip.style("left",+l.offsetX+ +this.options.xOffset+"px").style("top",+l.offsetY+ +this.options.yOffset+"px")},showAxis:function(t,e,i){"function"==typeof i&&(t=i.call(this,t));var o=this.defaultFormatter(t);let s=this.options.formatter;"string"==typeof s?o=_defaultFormatterMap[s]&&_defaultFormatterMap[s].call(this,t):"function"==typeof s&&(o=s(t));var r,a,n,l,h,c=d3.mouse(e[0][0]),d=this.alloptions,u=this.isVertical();u?(r=this.layer.x.getX(),a=d.xaxis.key,n=d.xaxis.type,l=this.layer.y,h=d.yaxis.orient):(r=this.layer.y.getX(),a=d.yaxis.key,n=d.yaxis.type,l=this.layer.x,h=d.xaxis.orient);let p=l.el[0][0];var y=u?r("time"===n&&new Date(t[a])||t[a])+d.margin.left+(d.margin.containLabel&&"left"===h?getLeft(p,l):0):c[0]+d.margin.left,g=u&&c[1]+d.margin.top||r("time"===n&&new Date(t[a])||t[a])+d.margin.top+(d.margin.containLabel&&"top"===h?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");let f=this.options;this.tooltip.style("left",y+(u&&r.rangeBand&&r.rangeBand()/2||0)+2*+f.xOffset+"px").style("top",g+(u?0:r.rangeBand&&r.rangeBand()/2||0)+ +f.yOffset+"px")},hide:function(){this.options.enterFocus=!0,this.options.enterFocus?this._delayHide():this._contentHide()},_contentHide:function(){this.tooltip.style("display","none")},_delayHide:function(){this.options.enterFocus&&(clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._contentHide()},this.options.hideDelay))},defaultFormatter:function(t){var e='<div class="dchart-tooltip">',i=0;return _.forIn(t,function(t,o,s){e+=(0!==i?"<br>":"")+o+": "+(t=t||0).toString(),i++}),e+="</div>"},initGuildLayer:function(){let 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.select(".guildLine")[0][0]?e.select(".guildLine"):e.append("g").attr("class","guildLine")},triggerAxis(){var t=this,e=(this.options,this.layer.width),i=this.layer.height,o=this.layer.y,s=this.layer.x,r=this.dispatch,a=this.alloptions.margin,n=this,l=this.alloptions;let h=this.options.triggerMethod;const c=.5;let d=this.layer.svgContainer,u=this.el.select(".con-g").attr("transform"),p=this.el.select(".series").attr("transform"),{transX:y,transY:g}=getTrans(u,p);d.on(AXIS_TRIGGER_METHOD_MAP[h]||"mousemove",function(){if(t.isAxisChart()&&t.options.trigger===TRIGGER_AXIS){var h=d3.event,d=h.offsetX,u=h.offsetY,p=t.isVertical(),g=p&&s.getX()||o.getX(),f=p&&g.range()||_.clone(g.range()).reverse(),m=p&&g.domain()||_.clone(g.domain()).reverse();if(d-=a.left,u-=a.top,a.containLabel&&("top"===l.xaxis.orient&&(u-=s.options.__height),"left"===l.yaxis.orient&&(d-=y)),d<0||u<0||d>e||u>i)return r.elementMouseout({mouseX:d,mouseY:u}),void n.renderGuildLayer(null);n.renderGuildLayer(null);var x="function"==typeof g.rangeBands,v=void 0,T=p?d:u;if(x){var b=d3.bisect(f,T)-1;if(f[b]+g.rangeBand()*(1+c)>=T)v=m[b];else{if(b=d3.bisect(f,T+c*g.rangeBand())-1,!(f[b]+g.rangeBand()*(1+c)>=T))return r.elementMouseout({mouseX:d,mouseY:u}),void n.renderGuildLayer(null);v=m[b]}}else v=g.invert(T);r.elementMouseover({mouseX:d,mouseY:u,pointValue:v})}}),d.on("mouseleave",()=>{"hover"===h&&(this.renderGuildLayer(null),this.hide())})},hideGuidLine(){this.el.select(".guildLine").selectAll("line").attr("display","none")},renderGuildLayer:function(t){if(0!==t&&!t)return this.hideGuidLine(),!1;let e=this.el.select(".con-g").attr("transform"),i=this.el.select(".series").attr("transform"),{transX:o,transY:s}=getTrans(e,i);this.el.select(".guildLayer").attr("transform",`translate(${o}, ${s})`);let{lineStyle:r}=this.options;var a=this.isVertical(),n=this.el.select(".guildLine").selectAll("line").data(null!=t?[t]:[],String);n.enter().append("line");let l=this.layer.y.options,h=this.alloptions;n.attr("display","block").attr("class","tooltip-guideline").attr("x1",t=>a&&_.isNumber(t)?t:0).attr("x2",t=>a&&_.isNumber(t)?t:l.innerWidth).attr("y1",t=>a?l.innerHeight||h.innerHeight:t).attr("y2",t=>!a&&_.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(){let t=this.alloptions;return t&&t.xaxis&&t.yaxis},updateItem(t){let e=this,i=this.selector,o=this.options.triggerMethod,s=this.layer.svgContainer.select(".con-g");if(i){clearListenersOnSelector(i);let t=this.options.beforeFormat;i.on(ITEM_TRIGGER_METHOD_MAP[o].show||"mouseover",function(i,o,r){clearTimeout(e._hideTimeout),(i||void 0!==o||void 0!==r)&&e.show(i&&i.data||i,s,t,o,r,d3.select(this))}).on(ITEM_TRIGGER_METHOD_MAP[o].hide||"mouseout",()=>{clearTimeout(e._hideTimeout),e.hide()})}},updateAxis(){this.triggerAxis();var t=this;let{alloptions:e,options:i}=this;var o,s,r,a,n=this.isVertical(),l=e.xaxis.key,h=e.yaxis.key,c=e.zaxis&&e.zaxis.key;let d=null;n?(o=l,s=e.xaxis.type,r=this.comObj.getComs("axis","xaxis").getX(),d=this.comObj.getComs("axis","xaxis").getX(),a=e.xaxis.format):(o=h,s=e.yaxis.type,r=this.comObj.getComs("axis","yaxis").getX(),d=this.comObj.getComs("axis","xaxis").getX(),a=e.yaxis.format);let u=n?this.layer.width:this.layer.height,p=this.layer.svgContainer.select(".con-g"),y=t.data();this.dispatch.on("elementMouseover",function(e){let n=0,g=function(t){let e=u,i=0;return y.forEach(function(l,h){var c=l[o];"time"===s&&a&&(c=d3.time.format(a).parse(l[o])),diff=Math.abs(r(c)-r(t.pointValue)),d(l[o]),diff<e&&(e=diff,i=h,n=c)}),y[i]}(e);if(t.show(g,p,i.beforeFormat||function(t){var e={};return e[l]=t[l],e[h]=t[h],c&&(e[c]=t[c]),e}),"line"===i.axisPointer){var f=r(n)+("category"===s?r.rangeBand()/2:0);t.renderGuildLayer(f)}}),this.dispatch.on("elementMouseout",function(){t.hide()})},updateEvent:function(t){var e=this.options;let i=e.trigger;if(t&&"function"==typeof t){let e=t();e&&(this.selector=e)}if(this.selector&&this.selector.style("cursor",e.show?"pointer":"default"),this.clearListeners(),this.renderGuildLayer(null),e.show){this.isAxisChart()&&i===TRIGGER_AXIS?this.updateAxis():this.updateItem(t);let o=this.el.select(".dc-tooltip");o.style({display:"none",position:"absolute",color:e.color,background:e.backgroundColor,padding:`${e.padding}px`,"border-radius":"5%","border-color":e.borderColor,"border-width":`${e.borderWidth}px`,"border-style":"solid","font-size":e.fontSize,"font-weight":e.fontWeight,"font-family":e.fontFamily,"pointer-events":"none"}),e.autoSize?(o[0]&&(o[0][0].style.height=""),o.style("white-space","nowrap"),o.style("width","fit-content")):o.style({width:`${e.width}px`,height:`${e.height}px`,"word-break":"break-all","white-space":"normal"})}},clearListeners(){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.6.3", | ||
"version": "2.6.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
141775