New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dchart-core

Package Overview
Dependencies
Maintainers
2
Versions
284
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dchart-core - npm Package Compare versions

Comparing version 2.6.19 to 2.6.20

2

bar/bar.js

@@ -1,1 +0,1 @@

"use strict";var DataV=require("../datav"),d3=require("d3"),_=require("../util"),animationController=_.animationController;function BarMulti(e,t){var r={xaxis:{type:"category",orient:"bottom"},groupLabel:null,yaxis:{key:"y"},label:{show:!1,pos:"top",dx:"0",dy:"-0.26em",anchor:"middle",strokeWidth:0},series:[{label:{}},{label:{}}]};r=_.deepMerge(r,t),DataV.call(this,e,r)}BarMulti=DataV.extend(BarMulti,{data:function(e){if(!e)return this._data;var t=this.options.yaxis.key;e.forEach(function(e){_.isArray(e[t])||(e[t]=[e[t]]),e[t]=_.map(e[t],function(e){return"string"==typeof e&&(e=_.toNumber(e)),e||(e=0),e})}),this._data=e},trans:function(e){var t=this.options,r=[],s=t.yaxis.key,i=t.xaxis.key;return _.map(e[s],function(t){var l={};l[i]=e[i],l[s]=t,r.push(l)}),r},getSelector:function(){return this.svg.select(".series").selectAll(".series-group").selectAll(".serie-single")},afterRender:function(){var e=this.options,t=this.getComs("tooltip","tooltip");t&&t.update(this.data(),e.tooltip,e),t&&t.updateEvent(this.getSelector.bind(this)),e.tooltip&&!e.tooltip.show&&t&&t.clearListeners()},updateAfterRender:function(){BarMulti.prototype.afterRender.call(this)},renderSeries:function(){this.svg.classed("bar-chart-g",!0);var e,t,r=this.options,s=this,i=this.data(),l=r.xaxis.key,a=r.yaxis.key;e=this.getComs("axis","xaxis"),t=this.getComs("axis","yaxis");var o=e.getX(),n=t.getX(),c=_.maxBy(i,function(e){return e[a].length})[a].length,d=e.calGroupStep(r.groupLabel||c),u=(r.tooltip&&this.getComs("tooltip","tooltip"),this.series.selectAll(".series-group").data(this._data,function(e){return e[l]}));this.enterSeries=u.enter().append("g").attr("class","series-group"),this.outerSeries=u.exit().remove(),u.each(function(e,i){var c=d3.select(this).selectAll(".serie-single").data(s.trans(e));c.enter().append("g").attr("class","serie serie-single").each(function(e,s){var i=d3.select(this),a=d(""+s)||d("0");i.append("rect").attr({class:"serie serie"+(s+1),x:o(e[l])+a,y:n(t.getMin()),width:d.rangeBand(),height:0}),i.append("text").attr({class:"serie-label serie"+(s+1)+"-label",x:o(e[l])+a+d.rangeBand()/2,y:n(t.getMin()),dx:r.series[s]&&r.series[s].label&&r.series[s].label.dx||r.label.dx||0,dy:r.series[s]&&r.series[s].label&&r.series[s].label.dy||r.label.dy||0})});!function(e,i,c){e.each(function(e,u){var h=d3.select(this),f=h.selectAll(".serie"),p=h.selectAll(".serie-label"),b=d(""+u)||d("0"),g={x:o(e[l])+b,y:n(e[a]),width:d.rangeBand(),height:n(t.getMin())-n(e[a])},y={x:o(e[l])+b+d.rangeBand()/2,y:function(){var s=r.label.pos;return"top"===s?n(e[a]):"center"===s?n(e[a])/2+n(t.getMin()):n(t.getMax())},dx:r.series[u]&&r.series[u].label&&r.series[u].label.dx||r.label.dx||0,dy:r.series[u]&&r.series[u].label&&r.series[u].label.dy||r.label.dy||0};animationController({options:r,animationHandler:function(e){var t=e.duration,r=e.ease;e.delay,f.transition().duration(t).ease(r).attr(g),p.transition().duration(t).ease(r).attr(y)},notAnimationHandler:function(){f.attr(g),p.attr(y)},animationFromOriginHandler:function(){f.attr({y:n(0),height:0}),p.attr({y:n(0)})},index:u}),f.style({fill:function(){return r.series[u]&&r.series[u].color&&r.series[u].color.res||r.color&&r.color.res},stroke:function(){return r.series[u]&&r.series[u].frameColor&&r.series[u].frameColor.res||r.frameColor&&r.frameColor.res},"stroke-width":function(){return r.series[u]&&r.series[u].frameColorWidth||r.frameColorWidth}}),p.html(function(){var t=r.series[u]&&r.series[u].label&&r.series[u].label.format||r.label.format||null;return t?t.call(s,e,c):i[a][u]}).style({"text-anchor":function(){return r.series[u]&&r.series[u].label&&r.series[u].label.anchor||r.label.anchor||"middle"},display:function(){return(r.series[u]&&"boolean"==typeof r.series[u].show?r.series[u].show:"boolean"==typeof r.label.show&&r.label.show)?"block":"none"},"font-size":function(){return(r.series[u]&&r.series[u].label&&r.series[u].label.fontSize||r.label.fontSize||"10")+"px"},"font-weight":function(){return r.series[u]&&r.series[u].label&&r.series[u].label.fontWeight||r.label.fontWeight},fill:r.series[u]&&r.series[u].label&&r.series[u].label.color||r.label.color,stroke:r.label.strokeWidth&&r.series[u]&&r.series[u].label&&r.series[u].label.color||r.label.color||"#fff","stroke-width":r.label.strokeWidth})})}(c,e,i),s.outerSerie=c.exit().remove()})},updateBeforeRender:function(){BarMulti.prototype.beforeRender.call(this)},beforeRender:function(){var e=this.options,t=this;this.dealColor(e,"color"),this.dealColor(e,"frameColor"),e.series&&e.series.length&&e.series.forEach(function(r,s){r.color&&t.dealColor(e,"series["+s+"].color"),r.frameColor&&t.dealColor(e,"series["+s+"].frameColor")})},updateSeries:function(){BarMulti.prototype.renderSeries.call(this)}}),module.exports=BarMulti;
"use strict";var DataV=require("../datav"),d3=require("d3"),_=require("../util"),animationController=_.animationController;function BarMulti(e,t){var r={xaxis:{type:"category",orient:"bottom"},groupLabel:null,yaxis:{key:"y"},label:{show:!1,pos:"top",dx:"0",dy:"-0.26em",anchor:"middle",strokeWidth:0},series:[{label:{}},{label:{}}]};r=_.deepMerge(r,t),DataV.call(this,e,r)}BarMulti=DataV.extend(BarMulti,{data:function(e){if(!e)return this._data;var t=this.options.yaxis.key;e.forEach(function(e){_.isArray(e[t])||(e[t]=[e[t]]),e[t]=_.map(e[t],function(e){return"string"==typeof e&&(e=_.toNumber(e)),e||(e=0),e})}),this._data=e},trans:function(e){var t=this.options,r=[],s=t.yaxis.key,i=t.xaxis.key;return _.map(e[s],function(t){var l={};l[i]=e[i],l[s]=t,r.push(l)}),r},getSelector:function(){return this.svg.select(".series").selectAll(".series-group").selectAll(".serie-single")},afterRender:function(){var e=this.options,t=this.getComs("tooltip","tooltip");t&&t.update(this.data(),e.tooltip,e),t&&t.updateEvent(this.getSelector.bind(this)),e.tooltip&&!e.tooltip.show&&t&&t.clearListeners()},updateAfterRender:function(){BarMulti.prototype.afterRender.call(this)},renderSeries:function(){this.svg.classed("bar-chart-g",!0);var e,t,r=this.options,s=this,i=this.data(),l=r.xaxis.key,a=r.yaxis.key;e=this.getComs("axis","xaxis"),t=this.getComs("axis","yaxis");var o=e.getX(),n=t.getX(),c=_.maxBy(i,function(e){return e[a].length})[a].length,d=e.calGroupStep(r.groupLabel||c),u=(r.tooltip&&this.getComs("tooltip","tooltip"),this.series.selectAll(".series-group").data(this._data,function(e){return e[l]}));this.enterSeries=u.enter().append("g").attr("class","series-group"),this.outerSeries=u.exit().remove(),u.each(function(e,i){var c=d3.select(this).selectAll(".serie-single").data(s.trans(e));c.enter().append("g").attr("class","serie serie-single").each(function(e,s){var i=d3.select(this),a=d(""+s)||d("0");i.append("rect").attr({class:"serie serie"+(s+1),x:o(e[l])+a,y:n(t.getMin()),width:d.rangeBand(),height:0}),i.append("text").attr({class:"serie-label serie"+(s+1)+"-label",x:o(e[l])+a+d.rangeBand()/2,y:n(t.getMin()),dx:r.series[s]&&r.series[s].label&&r.series[s].label.dx||r.label.dx||0,dy:r.series[s]&&r.series[s].label&&r.series[s].label.dy||r.label.dy||0})});!function(e,i,c){e.each(function(e,u){var h=d3.select(this),f=h.selectAll(".serie"),p=h.selectAll(".serie-label"),b=d(""+u)||d("0"),g={x:o(e[l])+b,y:n(e[a]),width:d.rangeBand(),height:n(t.getMin())-n(e[a])},y={x:o(e[l])+b+d.rangeBand()/2,y:function(){var e=r.label.pos;return g.y+g.height*("top"===e?0:"center"===e?.5:1)},dx:r.series[u]&&r.series[u].label&&r.series[u].label.dx||r.label.dx||0,dy:r.series[u]&&r.series[u].label&&r.series[u].label.dy||r.label.dy||0};animationController({options:r,animationHandler:function(e){var t=e.duration,r=e.ease;e.delay,f.transition().duration(t).ease(r).attr(g),p.transition().duration(t).ease(r).attr(y)},notAnimationHandler:function(){f.attr(g),p.attr(y)},animationFromOriginHandler:function(){f.attr({y:n(0),height:0}),p.attr({y:n(0)})},index:u}),f.style({fill:function(){return r.series[u]&&r.series[u].color&&r.series[u].color.res||r.color&&r.color.res},stroke:function(){return r.series[u]&&r.series[u].frameColor&&r.series[u].frameColor.res||r.frameColor&&r.frameColor.res},"stroke-width":function(){return r.series[u]&&r.series[u].frameColorWidth||r.frameColorWidth}}),p.html(function(){var t=r.series[u]&&r.series[u].label&&r.series[u].label.format||r.label.format||null;return t?t.call(s,e,c):i[a][u]}).style({"text-anchor":function(){return r.series[u]&&r.series[u].label&&r.series[u].label.anchor||r.label.anchor||"middle"},display:function(){return(r.series[u]&&"boolean"==typeof r.series[u].show?r.series[u].show:"boolean"==typeof r.label.show&&r.label.show)?"block":"none"},"font-size":function(){return(r.series[u]&&r.series[u].label&&r.series[u].label.fontSize||r.label.fontSize||"10")+"px"},"font-weight":function(){return r.series[u]&&r.series[u].label&&r.series[u].label.fontWeight||r.label.fontWeight},fill:r.series[u]&&r.series[u].label&&r.series[u].label.color||r.label.color,stroke:r.label.strokeWidth&&r.series[u]&&r.series[u].label&&r.series[u].label.color||r.label.color||"#fff","stroke-width":r.label.strokeWidth})})}(c,e,i),s.outerSerie=c.exit().remove()})},updateBeforeRender:function(){BarMulti.prototype.beforeRender.call(this)},beforeRender:function(){var e=this.options,t=this;this.dealColor(e,"color"),this.dealColor(e,"frameColor"),e.series&&e.series.length&&e.series.forEach(function(r,s){r.color&&t.dealColor(e,"series["+s+"].color"),r.frameColor&&t.dealColor(e,"series["+s+"].frameColor")})},updateSeries:function(){BarMulti.prototype.renderSeries.call(this)}}),module.exports=BarMulti;

@@ -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){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;return'<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px; \n background-color:'.concat(i||e&&e.color&&e.color.value||"#ccc",'"></span>\n ').concat(r?r+": ":"").concat(o,"</div>")}function _xyAxisChartFormatter(t,e,i){var o=this.options.trigger,r='<div class="dchart-tooltip">',s=this.alloptions.series,n=[];if(o===TRIGGER_AXIS)t.x&&n.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach(function(t,e){return(0===t||t)&&n.push(_creatToolTipSerieRow({serie:s[e],value:t}))});else{var a=Array.isArray(t.y)?t.y[e]:t.y;n.push(_creatToolTipSerieRow({serie:s[e],value:a&&a.toString()||0,key:t.x.toString()}))}return r+="".concat(n.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;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}))}),(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}))}),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=[];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({serie:n[e],value:t}))});else{var l=Array.isArray(t.y)?t.y[e]:t.y,c=+o.select("rect").attr("order");a.push(_creatToolTipSerieRow({serie:n[c],value:l&&l.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;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),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,c,h=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,c=u.yaxis.orient):(s=this.layer.y.getX(),n=u.yaxis.key,a=u.yaxis.type,l=this.layer.x,c=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]));f=y+ +u.margin.left+(u.margin.containLabel&&"left"===c?getLeft(p,l):0)}else f=h[0]+u.margin.left;var g=d&&h[1]+u.margin.top||s("time"===a&&new Date(t[n])||t[n])+u.margin.top+(u.margin.containLabel&&"top"===c?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");var m=this.options;this.tooltip.style("left",f+(d&&s.rangeBand&&s.rangeBand()/2||0)+2*+m.xOffset+"px").style("top",g+(d?0:s.rangeBand&&s.rangeBand()/2||0)+ +m.yOffset+"px")},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.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,c=this.alloptions,h=this.options.triggerMethod,u=.5,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[h]||"mousemove",function(){if(e.isAxisChart()&&e.options.trigger===TRIGGER_AXIS){var t=d3.event,h=t.offsetX,d=t.offsetY,p=e.isVertical(),y=p&&s.getX()||r.getX(),g=p&&y.range()||_.clone(y.range()).reverse(),m=p&&y.domain()||_.clone(y.domain()).reverse();if(h-=a.left,d-=a.top,a.containLabel&&("top"===c.xaxis.orient&&(d-=s.options.__height),"left"===c.yaxis.orient&&(h-=f)),h<0||d<0||h>i||d>o)return n.elementMouseout({mouseX:h,mouseY:d}),void l.renderGuildLayer(null);l.renderGuildLayer(null);var x="function"==typeof y.rangeBands,v=void 0,T=p?h:d;if(x){var b=d3.bisect(g,T)-1;if(g[b]+y.rangeBand()*(1+u)>=T)v=m[b];else{if(b=d3.bisect(g,T+u*y.rangeBand())-1,!(g[b]+y.rangeBand()*(1+u)>=T))return n.elementMouseout({mouseX:h,mouseY:d}),void l.renderGuildLayer(null);v=m[b]}}else v=y.invert(T);n.elementMouseover({mouseX:h,mouseY:d,pointValue:v})}}),d.on("mouseleave",function(){"hover"===h&&(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.options.triggerMethod,r=this.layer.svgContainer.select(".con-g");if(i){clearListenersOnSelector(i);var s=this.options.beforeFormat;i.on(ITEM_TRIGGER_METHOD_MAP[o].show||"mouseover",function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,r,s,i,o,d3.select(this))}).on(ITEM_TRIGGER_METHOD_MAP[o].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,c=s.yaxis.key,h=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=c,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,g,m=0,x=(a=s,y=d,g=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,g=s,m=n)}),f[g]);if(r.show(x,p,n.beforeFormat||function(t){var e={};return e[l]=t[l],e[c]=t[c],h&&(e[h]=t[h]),e}),"line"===n.axisPointer){var v=i(m)+("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)}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);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){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;return'<div><span style="display:inline-block; margin-right:5px; border-radius:2px; width:10px; height:10px; \n background-color:'.concat(i||e&&e.color&&e.color.value||"#ccc",'"></span>\n ').concat(r?r+": ":"").concat(o,"</div>")}function _xyAxisChartFormatter(t,e,i){var o=this.options.trigger,r='<div class="dchart-tooltip">',s=this.alloptions.series,n=[];if(o===TRIGGER_AXIS)t.x&&n.push("<b>".concat(t.x.toString(),"</b>")),t.y&&t.y.forEach&&t.y.forEach(function(t,e){return(0===t||t)&&n.push(_creatToolTipSerieRow({serie:s[e],value:t}))});else{var a=Array.isArray(t.y)?t.y[e]:t.y;n.push(_creatToolTipSerieRow({serie:s[e],value:a&&a.toString()||0,key:t.x.toString()}))}return r+="".concat(n.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;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}))}),(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}))}),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=[];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({serie:n[e],value:t}))});else{var l=Array.isArray(t.y)?t.y[e]:t.y,c=+o.select("rect").attr("order");a.push(_creatToolTipSerieRow({serie:n[c],value:l&&l.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;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),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,c,h=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,c=u.yaxis.orient):(s=this.layer.y.getX(),n=u.yaxis.key,a=u.yaxis.type,l=this.layer.x,c=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"===c?getLeft(p,l):0)}else f=h[0]+u.margin.left;var g=d&&h[1]+u.margin.top||s("time"===a&&new Date(t[n])||t[n])+u.margin.top+(u.margin.containLabel&&"top"===c?p.getBBox().height:0);this.tooltip.html(o),this.tooltip.transition().duration(20).style("display","block");var m=this.options;this.tooltip.style("left",f+(d&&s.rangeBand&&s.rangeBand()/2||0)+2*+m.xOffset+"px").style("top",g+(d?0:s.rangeBand&&s.rangeBand()/2||0)+ +m.yOffset+"px")},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.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,c=this.alloptions,h=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[h]||"mousemove",function(){if(e.isAxisChart()&&e.options.trigger===TRIGGER_AXIS){var t=d3.event,h=t.offsetX,d=t.offsetY,p=e.isVertical(),y=p&&s.getX()||r.getX(),g=p&&y.range()||_.clone(y.range()).reverse(),m=p&&y.domain()||_.clone(y.domain()).reverse();if(h-=a.left,d-=a.top,a.containLabel&&("top"===c.xaxis.orient&&(d-=s.options.__height),"left"===c.yaxis.orient&&(h-=f)),h+u<0||d+u<0||h-u>i||d-u>o)return n.elementMouseout({mouseX:h,mouseY:d}),void l.renderGuildLayer(null);l.renderGuildLayer(null);var x="function"==typeof y.rangeBands,v=void 0,T=p?h:d;if(x){var b=d3.bisect(g,T),w=y.rangeBand(),S=g.length;if(0===b)v=m[b];else if(b===S)v=m[b-1];else{var A=Math.abs(g[b]-T),L=Math.abs(T-g[b-1]-w);L<A&&(b-=1),v=m[b]}}else v=y.invert(T);n.elementMouseover({mouseX:h,mouseY:d,pointValue:v})}}),d.on("mouseleave",function(){"hover"===h&&(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.options.triggerMethod,r=this.layer.svgContainer.select(".con-g");if(i){clearListenersOnSelector(i);var s=this.options.beforeFormat;i.on(ITEM_TRIGGER_METHOD_MAP[o].show||"mouseover",function(t,i,o){clearTimeout(e._hideTimeout),(t||void 0!==i||void 0!==o)&&e.show(t&&t.data||t,r,s,i,o,d3.select(this))}).on(ITEM_TRIGGER_METHOD_MAP[o].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,c=s.yaxis.key,h=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=c,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,g,m=0,x=(a=s,y=d,g=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,g=s,m=n)}),f[g]);if(r.show(x,p,n.beforeFormat||function(t){var e={};return e[l]=t[l],e[c]=t[c],h&&(e[h]=t[h]),e}),"line"===n.axisPointer){var v=i(m)+("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)}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);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.6.19",
"version": "2.6.20",
"description": "",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc