-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.shapes.chart.min.js
More file actions
14 lines (8 loc) · 34.9 KB
/
joint.shapes.chart.min.js
File metadata and controls
14 lines (8 loc) · 34.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
this.joint=this.joint||{},function(e,o,t,V){"use strict";o=o&&o.hasOwnProperty("default")?o.default:o;var i=t.Generic.extend({markup:['<clipPath class="clip"><rect/></clipPath>','<g class="rotatable">','<g class="scalable"></g>','<g class="background"><rect/><text/></g>','<g class="axis">','<g class="y-axis"><path/><g class="ticks"></g></g>','<g class="x-axis"><path/><g class="ticks"></g></g>','<g class="markings"></g>',"</g>",'<g class="data"><g class="series"></g></g>','<g class="foreground">','<rect/><text class="caption"/><text class="subcaption"/>','<g class="legend"><g class="legend-items"></g></g>','<line class="guideline x-guideline" /><line class="guideline y-guideline" />',"</g>","</g>"].join(""),tickMarkup:'<g class="tick"><line/><text/></g>',pointMarkup:'<g class="point"><circle/><text/></g>',barMarkup:'<path class="bar"/>',markingMarkup:'<g class="marking"><rect/><text/></g>',serieMarkup:'<g><clipPath class="serie-clip"><rect/></clipPath><path/><g class="bars"></g><g class="points"></g></g>',legendItemMarkup:'<g class="legend-item"><circle/><text/></g>',defaults:V.util.deepSupplement({type:"chart.Plot",attrs:{".data path":{fill:"none",stroke:"black"},".data .bars rect":{fill:"none",stroke:"black"},".background rect":{fill:"white",stroke:"#e5e5e5",opacity:1},".background text":{fill:"black",text:"No data available.",ref:".","ref-x":.5,"ref-y":.5,"text-anchor":"middle","y-alignment":"middle",display:"none"},".foreground > rect":{fill:"white",stroke:"#e5e5e5",opacity:0,"pointer-events":"none"},".foreground .caption":{fill:"black",text:"",ref:".foreground > rect","ref-x":.5,"ref-y":10,"text-anchor":"middle","y-alignment":"middle","font-size":14},".foreground .subcaption":{fill:"black",text:"",ref:".foreground > rect","ref-x":.5,"ref-y":23,"text-anchor":"middle","y-alignment":"middle","font-size":10},".point":{display:"inline-block"},".point circle":{r:2,stroke:"black",fill:"black",opacity:.3},".point text":{fill:"black","font-size":8,"text-anchor":"middle",display:"none"},".axis path":{fill:"none",stroke:"black"},".axis .tick":{fill:"none",stroke:"black"},".y-axis .tick line":{fill:"none",stroke:"black",x2:2,y2:0,opacity:1},".x-axis .tick line":{fill:"none",stroke:"black",x2:0,y2:-3,opacity:1},".y-axis .tick text":{fill:"black",stroke:"none","font-size":10,"text-anchor":"end"},".x-axis .tick text":{fill:"black",stroke:"none","font-size":10,"text-anchor":"middle"},".y-axis .tick text > tspan":{dy:"-.5em",x:-5},".x-axis .tick text > tspan":{dy:".5em",x:0},".axis .markings":{fill:"black",stroke:"none","fill-opacity":1},".axis .markings text":{fill:"black","text-anchor":"end","font-size":10,dy:-5,dx:-5},".guideline":{"pointer-events":"none",display:"none"},".x-guideline":{stroke:"black",visibility:"hidden"},".y-guideline":{stroke:"black",visibility:"hidden"},".legend":{"ref-x":10,"ref-y":10},".legend-item text":{fill:"black",transform:"translate(14, 0)","font-size":11},".legend-item circle":{r:5,transform:"translate(5,5)"},".legend-item":{cursor:"pointer"},".legend-item.disabled circle":{fill:"gray"},".legend-item.disabled text":{opacity:.5}}},t.Generic.prototype.defaults),legendPosition:function(e,t){t=t||{},this.trigger("batch:start"),[".legend/ref-x",".legend/ref-y",".legend/ref-dx",".legend/ref-dy",".legend/x-alignment",".legend/y-alignment"].forEach(function(e){this.removeAttr(e,{silent:!0})},this);var i=t.padding||10,a={n:{".legend":{"ref-x":.5,"x-alignment":-.5,"ref-y":i}},ne:{".legend":{"ref-dx":-i,"x-alignment":-.999,"ref-y":i}},e:{".legend":{"ref-dx":-i,"x-alignment":-.999,"ref-y":.5,"y-alignment":-.5}},se:{".legend":{"ref-dx":-i,"ref-dy":-i,"x-alignment":-.999,"y-alignment":-.999}},s:{".legend":{"ref-x":.5,"ref-dy":-i,"x-alignment":-.5,"y-alignment":-.999}},sw:{".legend":{"ref-x":i,"ref-dy":-i,"y-alignment":-.999}},w:{".legend":{"ref-x":i,"ref-y":.5,"y-alignment":-.5}},nw:{".legend":{"ref-x":i,"ref-y":i}},nnw:{".legend":{"ref-x":i,"ref-y":-i,"y-alignment":-.999}},nn:{".legend":{"ref-x":.5,"ref-y":-i,"x-alignment":-.5,"y-alignment":-.999}},nne:{".legend":{"ref-dx":-i,"ref-y":-i,"x-alignment":-.999,"y-alignment":-.999}},nnee:{".legend":{"ref-dx":i,"ref-y":-i,"y-alignment":-.999}},nee:{".legend":{"ref-y":i,"ref-dx":i}},ee:{".legend":{"ref-dx":i,"ref-y":.5,"y-alignment":-.5}},see:{".legend":{"ref-dx":i,"ref-dy":-i,"y-alignment":-.999}},ssee:{".legend":{"ref-dx":i,"ref-dy":i}},sse:{".legend":{"ref-dx":-i,"ref-dy":i,"x-alignment":-.999}},ss:{".legend":{"ref-x":.5,"ref-dy":i,"x-alignment":-.5}},ssw:{".legend":{"ref-x":i,"ref-dy":i}},ssww:{".legend":{"ref-x":-i,"ref-dy":i,"x-alignment":-.999}},sww:{".legend":{"ref-x":-i,"ref-dy":-i,"x-alignment":-.999,"y-alignment":-.999}},ww:{".legend":{"ref-x":-i,"ref-y":.5,"x-alignment":-.999,"y-alignment":-.5}},nww:{".legend":{"ref-x":-i,"ref-y":i,"x-alignment":-.999}},nnww:{".legend":{"ref-x":-i,"ref-y":-i,"x-alignment":-.999,"y-alignment":-.999}}};a[e]&&this.attr(a[e]),this.trigger("batch:stop")},addPoint:function(e,t,i){i=i||{};var a=this.get("series"),s=V.util.toArray(a).findIndex(function(e){return e.name===t});if(-1===s)throw new Error("Serie "+t+" was not found.");var n=V.util.cloneDeep(a[s]);n.data.push(e),Number.isFinite(i.maxLen)&&n.data.length>i.maxLen&&n.data.shift(),(a=a.slice())[s]=n,this.set("series",a,i)},lastPoint:function(t){var e=V.util.toArray(this.get("series")).find(function(e){return e&&e.name===t}).data;return e[e.length-1]},firstPoint:function(t){return V.util.toArray(this.get("series")).find(function(e){return e&&e.name===t}).data[0]}}),a=V.dia.ElementView.extend({events:{mousemove:"onMouseMove",mouseout:"onMouseOut"},presentationAttributes:V.dia.ElementView.addPresentationAttributes({series:["UPDATE"],interpolate:["UPDATE"],padding:["UPDATE"],canvas:["UPDATE"],markings:["UPDATE"],axis:["UPDATE"]}),initialize:function(){V.dia.ElementView.prototype.initialize.apply(this,arguments),this.on("cell:pointerdown",this.onPointerDown,this),this._disabledSeries=[]},renderMarkup:function(){V.dia.ElementView.prototype.renderMarkup.apply(this,arguments),this.elDataClipPath=this.$(".clip")[0],this.elDataClipPathRect=this.elDataClipPath.firstChild,this.elBackgroundRect=this.$(".background rect")[0],this.elBackgroundText=this.$(".background text")[0],this.elForeground=this.$(".foreground")[0],this.elForegroundRect=this.$(".foreground rect")[0],this.elDataSeries=this.$(".data .series")[0],this.elYAxisPath=this.$(".y-axis path")[0],this.elYAxisTicks=this.$(".y-axis .ticks")[0],this.elXAxisPath=this.$(".x-axis path")[0],this.elXAxisTicks=this.$(".x-axis .ticks")[0],this.elMarkings=this.$(".axis .markings")[0],this.elXGuideline=this.$(".x-guideline")[0],this.elYGuideline=this.$(".y-guideline")[0],this.elLegend=this.$(".legend")[0],this.elLegendItems=this.$(".legend-items")[0],this.elTick=V.V(this.model.tickMarkup),this.elMarking=V.V(this.model.markingMarkup),this.elLegendItem=V.V(this.model.legendItemMarkup),this.elPoint=V.V(this.model.pointMarkup),this.elBar=V.V(this.model.barMarkup),this.elSerie=V.V(this.model.serieMarkup),this.elDataClipPath.id="clip_"+this.cid,V.V(this.$(".data")[0]).attr("clip-path","url(#"+this.elDataClipPath.id+")"),V.V(this.elMarkings).attr("clip-path","url(#"+this.elDataClipPath.id+")")},update:function(){var e=this.filterSeries();this.calculateStats(e);var t,i=this.model.get("size"),a=i.width,s=i.height;this.canvas=V.util.assign({x:0,y:0,width:a,height:s},this.model.get("canvas"));var n={top:0,right:0,bottom:0,left:0},l=this.model.get("padding");t=V.util.isObject(l)?V.util.assign({},n,l):void 0!==l?{top:l,right:2*l,bottom:2*l,left:l}:n,this.canvas=V.g.rect(this.canvas).moveAndExpand(V.g.rect(t.left,t.top,-t.right,-t.bottom));var r={x:0,y:0,width:a,height:s};V.V(this.elDataClipPathRect).attr(r),V.V(this.elBackgroundRect).attr(r),V.V(this.elForegroundRect).attr(r),this.updateAxis(),this.updateMarkings(),this.isEmpty()?o(this.elBackgroundText).show():o(this.elBackgroundText).hide(),this.updateSeries(e),this.updateLegend(),V.dia.ElementView.prototype.update.apply(this,arguments)},calculateStats:function(e){e=e||this.model.get("series");var s=[],n=[],l={},r={},o={};V.util.toArray(e).forEach(function(t,e){var i,a=o[t.name||e]||(o[t.name||e]={});a.decreasingX=!0,a.decreasingY=!0,a.nonDecreasingX=!0,a.nonDecreasingY=!0,V.util.forIn(t.data,function(e){a.minX=void 0===a.minX?e.x:Math.min(a.minX,e.x),a.maxX=void 0===a.maxX?e.x:Math.max(a.maxX,e.x),a.minY=void 0===a.minY?e.y:Math.min(a.minY,e.y),a.maxY=void 0===a.maxY?e.y:Math.max(a.maxY,e.y),i&&(a.decreasingX=a.decreasingX&&e.x<i.x,a.decreasingY=a.decreasingY&&e.y<i.y,a.nonDecreasingX=a.nonDecreasingX&&e.x>=i.x,a.nonDecreasingY=a.nonDecreasingY&&e.y>=i.y),s.includes(e.x)||s.push(e.x),n.includes(e.y)||n.push(e.y),(l[e.x]||(l[e.x]=[])).push({serie:t,x:e.x,y:e.y}),(r[e.y]||(r[e.y]=[])).push({serie:t,x:e.x,y:e.y}),i=e})});var t=this.model.get("axis")||{},i=t["x-axis"]||{},a=t["y-axis"]||{};this.stats={minX:void 0===i.min?s.reduce(function(e,t){return t<e?t:e},1/0):i.min,maxX:void 0===i.max?s.reduce(function(e,t){return e<t?t:e},-1/0):i.max,minY:void 0===a.min?n.reduce(function(e,t){return t<e?t:e},1/0):a.min,maxY:void 0===a.max?n.reduce(function(e,t){return e<t?t:e},-1/0):a.max,bySerie:o,xValues:s,yValues:n,xMap:l,yMap:r}},isEmpty:function(){return!this.stats.xValues.length},updateSeries:function(e){if(e=e||this.model.get("series"),this.elDataSeries.textContent="",!this.isEmpty()){var c=[this.stats.minX,this.stats.maxX],h=[this.stats.minY,this.stats.maxY],g=[this.canvas.x,this.canvas.x+this.canvas.width],u=[this.canvas.y+this.canvas.height,this.canvas.y],f=this.model.get("attrs");V.util.toArray(e).forEach(function(a,e){var t=a.data,s=[],i=this.elSerie.clone().attr("class",a.name||"serie-"+e);V.V(this.elDataSeries).append(i),V.util.forIn(t,function(e){var t=V.g.scale.linear(c,g,e.x),i=V.g.scale.linear(h,u,e.y);s.push({x:t,y:i}),f[".point"]&&"none"!==f[".point"].display&&this.renderPoint(e,a),a.bars&&this.renderBar(e,a)}.bind(this));var n=i.findOne(".serie-clip"),l=this.model.get("size"),r=this.stats.bySerie[a.name||e],o=V.g.scale.linear(c,g,r.minX),d=V.g.scale.linear(c,g,r.maxX);n.findOne("rect").attr(V.g.rect(o,0,d-o,l.height)),a.bars||i.findOne("path").attr({d:this.seriePathData(s,a,e),"clip-path":"url(#"+n.node.id+")"})},this)}},seriePathClipData:function(e,t){var i=this.model.get("size"),a=e[0];return["M",a.x,a.y,"V",i.height+10].join(" ")},renderBar:function(e,t){var i=[this.stats.minX,this.stats.maxX],a=[this.stats.minY,this.stats.maxY],s=[this.canvas.x,this.canvas.x+this.canvas.width],n=[this.canvas.y+this.canvas.height,this.canvas.y],l=V.g.scale.linear(i,s,e.x),r=V.g.scale.linear(a,n,e.y),o=t.bars.barWidth||.8,d=1<o?o:this.canvas.width/(this.stats.maxX-this.stats.minX)*o,c=V.g.scale.linear(a,n,0)-r;a[0]===a[1]&&(r=this.canvas.y+this.canvas.height,c=0);var h=e["top-rx"]||t.bars["top-rx"],g=e["top-ry"]||t.bars["top-ry"],u=e["bottom-rx"]||t.bars["bottom-rx"],f=e["bottom-ry"]||t.bars["bottom-ry"],m={left:l,middle:l-d/2,right:l-d}[t.bars.align||"middle"],p=this.elBar.clone();p.attr({"data-serie":t.name,"data-x":e.x,"data-y":e.y,d:V.V.rectToPath({x:m,y:r,width:d,height:c,"top-rx":h,"top-ry":g,"bottom-rx":u,"bottom-ry":f})});var x=t.name||"serie-"+this.model.get("series").indexOf(t);return V.V(this.elDataSeries).findOne("."+x+" .bars").append(p),p.node},renderPoint:function(e,t){var i=[this.stats.minX,this.stats.maxX],a=[this.stats.minY,this.stats.maxY],s=[this.canvas.x,this.canvas.x+this.canvas.width],n=[this.canvas.y+this.canvas.height,this.canvas.y],l=V.g.scale.linear(i,s,e.x),r=V.g.scale.linear(a,n,e.y);a[0]===a[1]&&(r=this.canvas.y+this.canvas.height);var o=this.elPoint.clone();o.attr({"data-serie":t.name,"data-x":e.x,"data-y":e.y}),o.findOne("circle").attr({cx:l,cy:r}),o.findOne("text").attr({x:l,dy:r}).text(this.pointLabel(e,t));var d=t.name||"serie-"+this.model.get("series").indexOf(t);return V.V(this.elDataSeries).findOne("."+d+" .points").append(o),o.node},seriePathData:function(e,t,i){var a,s,n=e.length,l=[this.stats.minY,this.stats.maxY];if(l[0]===l[1])for(a=0;a<n;a++)e[a].y=this.canvas.y+this.canvas.height;switch(void 0===t.interpolate?this.model.get("interpolate"):t.interpolate){case"bezier":s=new V.g.Path(V.g.Curve.throughPoints(e));break;case"step":for((s=new V.g.Path).appendSegment(V.g.Path.createSegment("M",e[0].x,e[0].y)),a=1;a<n;a++)s.appendSegment(V.g.Path.createSegment("L",(e[a-1].x+e[a].x)/2,e[a-1].y)),s.appendSegment(V.g.Path.createSegment("L",(e[a-1].x+e[a].x)/2,e[a].y));s.appendSegment(V.g.Path.createSegment("L",e[n-1].x,e[n-1].y));break;case"stepBefore":for((s=new V.g.Path).appendSegment(V.g.Path.createSegment("M",e[0].x,e[0].y)),a=1;a<n;a++)s.appendSegment(V.g.Path.createSegment("L",e[a-1].x,e[a].y)),s.appendSegment(V.g.Path.createSegment("L",e[a].x,e[a].y));break;case"stepAfter":for((s=new V.g.Path).appendSegment(V.g.Path.createSegment("M",e[0].x,e[0].y)),a=1;a<n;a++)s.appendSegment(V.g.Path.createSegment("L",e[a].x,e[a-1].y)),s.appendSegment(V.g.Path.createSegment("L",e[a].x,e[a].y));break;default:for((s=new V.g.Path).appendSegment(V.g.Path.createSegment("M",e[0].x,e[0].y)),a=1;a<n;a++)s.appendSegment(V.g.Path.createSegment("L",e[a].x,e[a].y))}return this.fixPathForFill(s,e,t,i).serialize()},fixPathForFill:function(e,t,i,a){if(0===t.length)return e;if(i.hideFillBoundaries)return e;if(!this.stats.bySerie[i.name||a].nonDecreasingX)return e;var s=e.getSegment(0);e.replaceSegment(0,V.g.Path.createSegment("L",s.end.x,s.end.y));var n=i.fillPadding&&i.fillPadding.left||0,l=i.fillPadding&&i.fillPadding.right||0,r=i.fillPadding&&i.fillPadding.bottom||10,o=this.model.get("size"),d=t[0],c=t[t.length-1];return e.insertSegment(0,V.g.Path.createSegment("M",c.x+l,o.height+r)),e.insertSegment(1,V.g.Path.createSegment("L",d.x-n,o.height+r)),e.insertSegment(2,V.g.Path.createSegment("L",d.x-n,d.y)),i.showRightFillBoundary&&(e.appendSegment(V.g.Path.createSegment("L",c.x+l,c.y)),e.appendSegment(V.g.Path.createSegment("Z"))),e},updateAxis:function(){var e=this.model.get("axis"),t=this.model.get("size"),i=t.height,a=t.width;if(V.V(this.elXAxisPath).attr("d",["M",0,i,"L",a,i].join(" ")),V.V(this.elYAxisPath).attr("d",["M",0,0,"L",0,i].join(" ")),this.elXAxisTicks.textContent="",this.elYAxisTicks.textContent="",!this.isEmpty()){var s=[this.stats.minX,this.stats.maxX],n=[this.stats.minY,this.stats.maxY],l=[this.canvas.x,this.canvas.x+this.canvas.width],r=[0,this.canvas.height],o=e&&e["y-axis"]||{},d=e&&e["x-axis"]||{};(function(e,t,i,a){function s(e,t,i){e.translate(t,i.height),V.V(this.elXAxisTicks).append(e)}function n(e,t,i){return V.g.scale.linear(e,t,i)}function l(e){return e}if(!e.ticks){var r=this.stats.xValues;return void function(i,a,s,n,l,r,o,e){e.forEach(function(e,t){t%(i.tickStep||1)==0&&u.call(this,i,a,s,n,l,r,o,e)},this)}.call(this,e,t,i,a,n,s,l,r)}var o=this.canvas.width/(t.width-2*this.canvas.x);c.call(this,e,t,i,a,n,s,l,o)}).call(this,d,t,s,l),function(e,t,i,a){var s=this.canvas.height/t.height;c.call(this,e,t,i,a,function(e,t,i){return e[0]===e[1]?this.canvas.y+this.canvas.height:V.g.scale.linear(e,t,i)},function(e,t){e.translate(0,t),V.V(this.elYAxisTicks).append(e)},function(e,t,i){var a=t[1]-(e-t[0]);return a+=V.g.scale.linear(i,t,this.canvas.y)-t[0]},s)}.call(this,o,t,n,r)}function c(e,t,i,a,s,n,l,r){var o=i[1]-i[0],d=e.ticks||11;0==o&&(d=1);for(var c=o/d/r,h=i[0],g=0;g<d;g++)u.call(this,e,t,i,a,s,n,l,h),h+=c}function u(e,t,i,a,s,n,l,r){var o=this.elTick.clone(),d=s.call(this,i,a,r);if(!(d>t.width)){n.call(this,o,d,t);var c=l.call(this,r,i,a);o.findOne("text").text(this.tickLabel(c,e))}}},tickLabel:function(e,t){if(V.util.isFunction(t.tickFormat))return t.tickFormat(e);var i=t.tickFormat||".1f";return V.util.format.number(i,e)+(V.util.isFunction(t.tickSuffix)?t.tickSuffix(e):t.tickSuffix||"")},pointLabel:function(e,t){if(V.util.isFunction(t.pointFormat))return t.pointFormat(e);var i=t.pointFormat||".1f";return V.util.format.number(i,e.y)+(t.pointSuffix||"")},updateMarkings:function(){this.elMarkings.textContent="";var e=this.model.get("markings");if(e&&0!==e.length){var t=this.model.get("size"),b=t.width,k=t.height,S=[this.stats.minX,this.stats.maxX],w=[this.stats.minY,this.stats.maxY],M=[this.canvas.x,this.canvas.x+this.canvas.width],L=[this.canvas.y,this.canvas.y+this.canvas.height];V.util.toArray(e).forEach(function(e,t){var i=e.start||e.end,a=e.end||e.start,s=Math.min(P(i.x,this.stats.minX),P(a.x,this.stats.minX)),n=Math.max(P(i.x,this.stats.maxX),P(a.x,this.stats.maxX)),l=Math.min(P(i.y,this.stats.minY),P(a.y,this.stats.minY)),r=Math.max(P(i.y,this.stats.maxY),P(a.y,this.stats.maxY)),o=void 0===i.x||void 0===a.x,d=void 0===i.y||void 0===a.y;o&&(M=[0,b]),d&&(L=[0,k]);var c=V.g.scale.linear(S,M,s),h=V.g.scale.linear(S,M,n),g=V.g.scale.linear(w,L,l),u=V.g.scale.linear(w,L,r),f=c,m=L[1]-u+L[0],p=h-c,x=u-g;if(w[0]===w[1]&&l===r){if(w[0]!==l)return;m=this.canvas.y+this.canvas.height,x=1}p=Math.max(p,1),x=Math.max(x,1);var y=this.elMarking.clone();y.findOne("rect").attr({x:f,y:m,width:p,height:x}),y.findOne("text").text(e.label||"").attr({x:f+p,y:m});var v=y.attr("class")+" "+(e.name||"marking-"+t);y.attr(V.util.assign({class:v},e.attrs)),V.V(this.elMarkings).append(y)},this)}function P(e,t){return void 0===e?t:e}},updateLegend:function(){var e=this.model.get("series");this.elLegendItems.textContent="",V.util.toArray(e).forEach(function(e,t){if((!V.util.isFunction(e.showLegend)||e.showLegend(e,this.stats.bySerie[e.name||t]))&&!1!==e.showLegend){var i=this.elLegendItem.clone();this._disabledSeries.includes(e.name)&&i.addClass("disabled"),i.attr("data-serie",e.name),i.findOne("circle").attr({fill:this.getSerieColor(e.name)}),i.findOne("text").text(e.label||e.name),i.translate(0,t*(e.legendLabelLineHeight||16)),V.V(this.elLegendItems).append(i)}},this)},getSerieColor:function(t){var e=this.model.get("attrs"),i=Object.keys(e).find(function(e){return e.includes(t)});return i?e[i].stroke||e[i].fill:"black"},hideSerie:function(e){this._disabledSeries.includes(e)||this._disabledSeries.push(e);var t=this.filterSeries();this.update(t)},showSerie:function(e){this._disabledSeries=V.util.without(this._disabledSeries,e);var t=this.filterSeries();this.update(t)},filterSeries:function(e){return e=e||this.model.get("series"),e=V.util.toArray(e).filter(function(e){return!this._disabledSeries.includes(e.name)},this)},onPointerDown:function(e,t,i){var a=o(e.target).closest(".legend-item")[0];a&&(V.V(a).toggleClass("disabled"),V.V(a).hasClass("disabled")?this.hideSerie(V.V(a).attr("data-serie")):this.showSerie(V.V(a).attr("data-serie")))},onMouseMove:function(e){this.showGuidelines(e.clientX,e.clientY,e)},onMouseOut:function(e){this.hideGuidelines(),this.trigger("mouseout",e)},showGuidelines:function(e,t,i){var a=this.model.get("angle"),s=this.model.getBBox(),n=new V.g.Point(V.V(this.paper.layers).toLocalPoint(e,t)).rotate(s.center(),a);if(V.g.rect(s).containsPoint(n)){var l=this.model.get("size"),r=n.x-s.x,o=n.y-s.y;V.V(this.elXGuideline).attr({x1:r,y1:0,x2:r,y2:l.height,visibility:"visible"}),V.V(this.elYGuideline).attr({x1:0,y1:o,x2:l.width,y2:o,visibility:"visible"});var d=V.g.scale.linear([this.canvas.x,this.canvas.x+this.canvas.width],[this.stats.minX,this.stats.maxX],r),c=V.g.scale.linear([this.canvas.y,this.canvas.y+this.canvas.height],[this.stats.minY,this.stats.maxY],o),h={x:d,y:this.stats.minY+this.stats.maxY-c},g={x:e,y:t},u=this.closestPoints(d);this.trigger("mouseover",h,g,u,i)}},closestPoints:function(e){var t=V.util.sortedIndex(this.stats.xValues,e),i=this.stats.xValues[t],a=this.stats.xValues[t-1],s=void 0===a?i:Math.abs(e-i)<Math.abs(e-a)?i:a;return this.stats.xMap[s]},hideGuidelines:function(){V.V(this.elXGuideline).attr("visibility","hidden"),V.V(this.elYGuideline).attr("visibility","hidden")}}),s=t.Generic.extend({markup:['<g class="rotatable">','<g class="scalable"></g>','<g class="background"><rect/><text/></g>','<g class="data"></g>','<g class="foreground">','<rect/><text class="caption"/><text class="subcaption"/>','<g class="legend"><g class="legend-items"></g></g>',"</g>","</g>"].join(""),sliceMarkup:'<g class="slice"/>',sliceFillMarkup:'<path class="slice-fill"/>',sliceBorderMarkup:'<path class="slice-border"/>',sliceInnerLabelMarkup:'<text class="slice-inner-label"/>',legendSerieMarkup:'<g class="legend-serie"><text/></g>',legendSliceMarkup:'<g class="legend-slice"><circle/><text/></g>',defaults:V.util.deepSupplement({type:"chart.Pie",size:{width:200,height:200},pieHole:0,serieDefaults:{startAngle:0,degree:360,label:null,showLegend:!0,labelLineHeight:6},sliceDefaults:{innerLabel:"{percentage:.0f}%",innerLabelMargin:6,legendLabel:"{label}: {value}",legendLabelLineHeight:6,legendLabelMargin:14,offset:0,onClickEffect:{type:"offset",offset:20},onHoverEffect:null},series:[],attrs:{".background > rect":{opacity:0},".background > text":{fill:"black",text:"No data available.",ref:".background > rect","ref-x":.5,"ref-y":.5,"text-anchor":"middle","y-alignment":"middle",display:"none"},".foreground > rect":{fill:"white",stroke:"#e5e5e5",opacity:0,"pointer-events":"none"},".foreground .caption":{fill:"black",text:"",ref:".foreground > rect","ref-x":2,"ref-y":6,"text-anchor":"start","y-alignment":"middle","font-size":14},".foreground .subcaption":{fill:"black",text:"",ref:".foreground > rect","ref-x":2,"ref-y":18,"text-anchor":"start","y-alignment":"middle","font-size":10},".data":{ref:".background","ref-x":.5,"ref-y":.5},".slice":{cursor:"pointer"},".slice > .slice-fill":{stroke:"#ffffff","stroke-width":1,"fill-opacity":1},".slice.hover > .slice-fill":{"fill-opacity":.8},".slice > .slice-border":{"stroke-width":6,"stroke-opacity":.4,"fill-opacity":1,fill:"none",display:"none"},".slice.hover > .slice-border":{display:"block"},".slice > .slice-inner-label":{"text-anchor":"middle","font-size":"12",stroke:"none","stroke-width":"0",fill:"#ffffff"},".slice > .slice-inner-label > tspan":{dy:"-.5em"},".legend":{"ref-dx":20,"ref-y":5},".legend-serie text":{fill:"grey",transform:"translate(2, 0)","font-size":13},".legend-slice":{cursor:"pointer"},".legend-slice text":{"font-weight":"normal",fill:"black","font-size":11},".legend-slice.hover text":{"font-weight":"bold"},".legend-slice circle":{r:5,transform:"translate(5,5)"}}},t.Generic.prototype.defaults),addSlice:function(e,t,i){i=i||{},t=t||0;var a=this.get("series");void 0===a[t]&&(a[t]={data:[]});var s=V.util.cloneDeep(a[t]);s.data.push(e),i=1<((a=a.slice())[t]=s).data.length?V.util.assign(i,{changedSerieIndex:t}):i,this.set("series",a,i)},editSlice:function(e,t,i,a){a=a||{},i=i||0;var s=this.get("series");if(void 0===s[i]||void 0===s[i].data[t])throw new Error("Slice "+t+" on serie "+i+" was not found.");var n=V.util.cloneDeep(s[i]);n.data[t]=V.util.assign(n.data[t],e),(s=s.slice())[i]=n,this.set("series",s,V.util.assign(a,{changedSerieIndex:i}))}}),n=V.dia.ElementView.extend({events:{"mouseover .slice":"onMouseOverSlice","mouseout .slice":"onMouseOverSlice","mousemove .slice":"onMouseMoveSlice","mouseover .legend-slice":"onEventLegendItem","mouseout .legend-slice":"onEventLegendItem"},presentationAttributes:V.dia.ElementView.addPresentationAttributes({series:["UPDATE"],serieDefaults:["UPDATE"],sliceDefaults:["UPDATE"],pieHole:["UPDATE"]}),initialize:function(){V.dia.ElementView.prototype.initialize.apply(this,arguments),this.on("cell:pointerclick",this.onClickSlice,this),this.on("cell:pointerclick",this.onEventLegendItem,this)},renderMarkup:function(){V.dia.ElementView.prototype.renderMarkup.apply(this,arguments),this.elBackgroundRect=this.$(".background rect")[0],this.elBackgroundText=this.$(".background text")[0],this.elForegroundRect=this.$(".foreground rect")[0],this.elLegendItems=this.$(".legend-items")[0],this.elPie=this.$(".data")[0],this.elSlice=V.V(this.model.sliceMarkup),this.elSliceFill=V.V(this.model.sliceFillMarkup),this.elSliceBorder=V.V(this.model.sliceBorderMarkup),this.elSliceInnerLabel=V.V(this.model.sliceInnerLabelMarkup),this.elLegendSerie=V.V(this.model.legendSerieMarkup),this.elLegendSlice=V.V(this.model.legendSliceMarkup)},update:function(e,t,i){var a=(i=i||{}).changedSerieIndex,s=this.calculateSeries(a);a in s?o(this.elPie).find(".serie-"+a).remove():o(this.elPie).empty();var n=this.model.get("size");V.V(this.elBackgroundRect).attr(n),V.V(this.elForegroundRect).attr(n),s.length?o(this.elBackgroundText).hide():o(this.elBackgroundText).show(),V.util.toArray(s).forEach(function(e,t){void 0!==a&&a!==t||V.util.forIn(e.data,this.updateSlice.bind(this))},this),this.updateLegend(),V.dia.ElementView.prototype.update.apply(this,arguments)},calculateSeries:function(i){var e=V.util.cloneDeep(this.model.get("series")),r=this.model.get("serieDefaults"),o=this.model.get("sliceDefaults"),t=this.model.get("size"),a=Math.min(t.width,t.height)/2,s=this.model.get("pieHole"),d=a,c=(a-(s=1<s?s:a*s))/e.length;return this._series=e.map(function(e,a){if(void 0!==i&&i!==a)return e;var s=(e=V.util.defaults(e,r)).startAngle,t=e.data.reduce(function(e,t){return e+t.value},0),n=e.degree/t||0,l=100/t;return e.data=e.data.map(function(e,t){(e=V.util.defaults(e,V.util.omit(o,"offset","onClickEffect","onHoverEffect"))).outerRadius=d,e.innerRadius=d-c,a||((e=V.util.defaults(e,V.util.pick(o,"offset","onClickEffect","onHoverEffect"))).isOuter=!0,e.offset=1<e.offset?e.offset:e.offset*e.outerRadius,e.onClickEffect.offset=1<e.onClickEffect.offset?e.onClickEffect.offset:e.onClickEffect.offset*e.outerRadius),e.serieIndex=a,e.sliceIndex=t,e.innerLabelMargin=e.innerLabelMargin<-1||1<e.innerLabelMargin?e.innerLabelMargin:e.innerLabelMargin*e.outerRadius,e.percentage=e.value*l;var i=e.value*n;return e.degree={angle:i,start:s,end:i+s},e.rad={angle:V.g.toRad(e.degree.angle,!0),start:V.g.toRad(e.degree.start,!0),end:V.g.toRad(e.degree.end,!0)},e.middleangle=(e.rad.start+e.rad.end)/2,s=e.degree.end,e}),d-=c,e}),this._series},updateLegend:function(){var e=this._series;this.elLegendItems.textContent="";var n=0,i=parseInt(this.model.attr(".legend-serie text/font-size"),10),l=parseInt(this.model.attr(".legend-slice text/font-size"),10);V.util.toArray(e).forEach(function(e,s){if(e.showLegend){if(e.label){var t=this.elLegendSerie.clone();e.name&&t.addClass(e.name),t.attr({"data-serie":s}),t.findOne("text").text(e.label),t.translate(0,n),V.V(this.elLegendItems).append(t),n+=i+e.labelLineHeight}V.util.forIn(e.data,function(e,t){var i=this.elLegendSlice.clone(),a=this.getSliceFillColor(t,s);e.name&&i.addClass(e.name),i.attr({"data-serie":s,"data-slice":t}),i.findOne("text").text(V.util.format.string(e.legendLabel,e)),i.findOne("text").translate(e.legendLabelMargin),i.translate(0,n),n+=l+e.legendLabelLineHeight,V.util.isObject(a)?this.applyGradient(i.findOne("circle"),"fill",a):i.findOne("circle").attr({fill:a}),V.V(this.elLegendItems).append(i)}.bind(this))}},this)},applyGradient:function(e,t,i){var a=V.util.isString(e)?this.findBySelector(e):o(e).toArray(),s=this.paper.defineGradient(i);a.forEach(function(e){V.V(e).attr(t,"url(#"+s+")")})},updateSlice:function(e){var t=this.elSlice.clone();V.V(this.elPie).append(t);var i=this.elSliceFill.clone(),a=this.getSliceFillColor(e.sliceIndex,e.serieIndex);i.attr({fill:a,d:V.V.createSlicePathData(e.innerRadius,e.outerRadius,e.rad.start,e.rad.end)}),t.append(i),V.util.isObject(a)&&this.applyGradient("#"+i.attr("id"),"fill",a);var s=this.elSliceBorder.clone(),n=parseInt(this.model.attr(".slice > .slice-border/stroke-width"),10),l=V.g.point.fromPolar(e.outerRadius+n/2,-e.rad.start,V.g.point(0,0)),r=V.g.point.fromPolar(e.outerRadius+n/2,-e.rad.end,V.g.point(0,0));s.attr({stroke:a,d:this.drawArc(l,r,e.outerRadius+n/2,e.rad.start,e.rad.end)}),t.append(s),V.util.isObject(a)&&this.applyGradient("#"+s.attr("id"),"stroke",a);var o=this.elSliceInnerLabel.clone();o.text(V.util.format.string(e.innerLabel,e)),t.append(o);var d=o.bbox(),c=e.outerRadius-d.width/2-e.innerLabelMargin;o.translate(c*Math.cos(-e.middleangle),-c*Math.sin(-e.middleangle)),t.attr({"data-serie":e.serieIndex,"data-slice":e.sliceIndex,"data-value":e.value});var h=this._series[e.serieIndex].name;return h&&t.addClass(h),e.name&&t.addClass(e.name),t.addClass("serie-"+e.serieIndex+" slice-"+e.sliceIndex),e.isOuter&&(t.addClass("outer"),e.offset&&(t.addClass("clicked"),this.effectOnSlice(t,e,{type:"offset",offset:e.offset}))),t},getSliceFillColor:function(t,i){i=i||0;var e=this.model.get("attrs"),a=Object.keys(e).find(function(e){return-1<e.indexOf(".serie-"+i+".slice-"+t+" > .slice-fill")});return a?e[a].fill:this._series[i].data[t].fill},onMouseMoveSlice:function(e){var t=V.V(e.currentTarget),i=t.attr("data-serie"),a=t.attr("data-slice"),s=this._series[i].data[a];this.trigger(e.type,s,e)},mouseOverSlice:function(e,t){t=t||0;var i=V.V(this.$('.slice[data-serie="'+t+'"][data-slice="'+e+'"]')[0]),a=this._series[t].data[e];i.toggleClass("hover"),a.isOuter&&!V.util.isEmpty(a.onHoverEffect)&&this.effectOnSlice(i,a,a.onHoverEffect,!i.hasClass("hover"));var s=V.V(this.$('.legend-slice[data-serie="'+t+'"][data-slice="'+e+'"]')[0]);s&&s.toggleClass("hover");var n=Object.keys(this.model.get("attrs")).filter(function(e){return-1<e.indexOf(".slice")||-1<e.indexOf(".legend-slice")});V.dia.ElementView.prototype.update.call(this,this.model,V.util.pick(this.model.get("attrs"),n))},onMouseOverSlice:function(e){var t=V.V(e.currentTarget),i=t.attr("data-serie"),a=t.attr("data-slice");this.mouseOverSlice(a,i);var s=this._series[i].data[a];this.trigger(e.type,s,e)},clickSlice:function(e,t){t=t||0;var i=V.V(this.$('.slice[data-serie="'+t+'"][data-slice="'+e+'"]')[0]),a=this._series[t].data[e];a.isOuter&&(i.hasClass("clicked")?(i.removeClass("clicked"),this.model.get("series")[t].data[e].offset=0,this.effectOnSlice(i,a,a.onClickEffect,!0)):(i.addClass("clicked"),this.model.get("series")[t].data[e].offset=a.onClickEffect.offset,this.effectOnSlice(i,a,a.onClickEffect)))},onClickSlice:function(e){var t=V.V(o(e.target).closest(".slice.outer")[0]);if(t){var i=t.attr("data-serie"),a=t.attr("data-slice");this.clickSlice(a,i);var s=this._series[i].data[a];this.trigger(e.type,s,e)}},onEventLegendItem:function(e){var t=V.V(o(e.target).closest(".legend-slice")[0]);if(t){var i=t.attr("data-serie"),a=t.attr("data-slice");switch(e.type){case"click":this.clickSlice(a,i);break;case"mouseover":case"mouseout":this.mouseOverSlice(a,i)}}},effectOnSlice:function(e,t,i,a){switch(a=a||!1,i.type){case"enlarge":a?e.scale(1):e.scale(i.scale||1.05);break;case"offset":a?e.translate(0,0,{absolute:!0}):e.translate(i.offset*Math.cos(-t.middleangle),-i.offset*Math.sin(-t.middleangle))}},svgArcMax:2*Math.PI-1e-6,drawArc:function(e,t,i,a,s){var n=0,l=1,r=s-a;return r>Math.PI&&(n=1,r>=this.svgArcMax&&(l=n=0)),"M"+e.x+","+e.y+" A"+i+","+i+" 0 "+n+","+l+" "+t.x+","+t.y}}),l=s.extend({defaults:V.util.deepSupplement({type:"chart.Knob",sliceDefaults:{legendLabel:"{value:.0f}",outer:{offsetOnClick:0}},pieHole:.7,value:0,attrs:{".legend":{"ref-x":.5,"ref-y":.5,"ref-dx":null,"x-alignment":-.5,"y-alignment":-.5},".legend-slice text":{"font-size":30},".legend-slice circle":{display:"none"},".slice-inner-label":{display:"none"},".slice-fill":{stroke:"none"}}},s.prototype.defaults),initialize:function(){this.set("series",this.getKnobSeries(),{silent:!0}),s.prototype.initialize.apply(this,arguments),this.on("change:value change:min change:max change:fill",this.updateKnob,this)},getKnobSeries:function(){var e=Array.isArray(this.get("value"))?this.get("value"):[this.get("value")],n=Array.isArray(this.get("fill"))?this.get("fill"):[this.get("fill")],l=Array.isArray(this.get("min"))?this.get("min"):[this.get("min")],r=Array.isArray(this.get("max"))?this.get("max"):[this.get("max")];return e.map(function(e,t){var i=void 0===l[t]?l[0]:l[t],a=void 0===r[t]?r[0]:r[t],s=void 0===n[t]?n[0]:n[t];return{degree:V.g.scale.linear([i,a],[0,360],e),data:[{value:e,fill:s}],showLegend:!(0<t)}})},updateKnob:function(){this.set("series",this.getKnobSeries())}}),r=n,d=t.Generic.extend({markup:['<g class="rotatable">','<g class="scalable">','<g class="background"><rect/></g>','<g class="cells"/>','<g class="foreground"/>',"</g>",'<g class="labels">','<g class="rows"/>','<g class="columns"/>',"</g>","</g>"].join(""),cellMarkup:'<rect class="cell"/>',labelMarkup:'<text class="label"/>',gridLineMarkup:'<path class="grid-line"/>',defaults:V.util.deepSupplement({type:"chart.Matrix",attrs:{".background rect":{fill:"#eeeeee"},".grid-line":{stroke:"white","stroke-width":2},".label":{fill:"black","alignment-baseline":"middle"},".labels .rows .label":{"text-anchor":"end"},".labels .columns .label":{"text-anchor":"start"}}},t.Generic.prototype.defaults)}),c=V.dia.ElementView.extend({presentationAttributes:V.dia.ElementView.addPresentationAttributes({size:["LABELS"],cells:["MARKUP","LABELS"]}),initFlag:["LABELS"].concat(V.dia.ElementView.prototype.initFlag),confirmUpdate:function(){var e=V.dia.ElementView.prototype.confirmUpdate.apply(this,arguments);return this.hasFlag(e,"MARKUP")&&(this.renderMarkup(),e=this.removeFlag(e,"MARKUP")),this.hasFlag(e,"LABELS")&&(this.renderLabels(),e=this.removeFlag(e,"LABELS")),e},renderMarkup:function(){V.dia.ElementView.prototype.renderMarkup.apply(this,arguments),this.elCells=this.$(".cells")[0],this.elRowLabels=this.$(".labels .rows")[0],this.elColumnLabels=this.$(".labels .columns")[0],this.elForeground=this.$(".foreground")[0],this.elCell=V.V(this.model.cellMarkup),this.elGridLine=V.V(this.model.gridLineMarkup);var e=this.model.get("cells")||[],t=this.model.get("size");this.elBackgroundRect=this.$(".background rect")[0],V.V(this.elBackgroundRect).attr(t);var i=t.height/e.length,a=t.width/e.length,s=document.createDocumentFragment();this.elCells.textContent="",this.elForeground.textContent="";for(var n,l,r,o,d,c=document.createDocumentFragment(),h=0;h<e.length;h++)for((r=this.elGridLine.clone()).addClass("horizontal"),r.attr("d","M 0 "+h*i+" "+t.width+" "+h*i),c.appendChild(r.node),n=e[h],l=0;l<n.length;l++)0===h&&((r=this.elGridLine.clone()).addClass("vertical"),r.attr("d","M "+l*a+" 0 "+l*a+" "+t.height),c.appendChild(r.node)),(o=n[l])&&((d=this.elCell.clone()).attr(V.util.assign({x:l*a,y:h*i,width:a,height:i},o)),s.appendChild(d.node));this.elForeground.appendChild(c),this.elCells.appendChild(s)},renderLabels:function(){this.elLabel=V.V(this.model.labelMarkup);var e,t,i=this.model.get("cells")||[],a=this.model.get("labels")||{},s=a.rows||[],n=a.columns||[],l=this.model.get("size"),r=l.height/i.length,o=l.width/i.length;this.elRowLabels.textContent="",this.elColumnLabels.textContent="";for(var d,c,h=document.createDocumentFragment(),g=0;g<s.length;g++)e=a.rows[g],(t=this.elLabel.clone()).text(e.text),t.attr(V.util.assign({x:-(a.padding||5),y:g*r+r/2,"text-anchor":"end","dominant-baseline":"central","font-size":r,"data-row":g},V.util.omit(e,"text"))),h.appendChild(t.node);this.elRowLabels.appendChild(h);for(var u=document.createDocumentFragment(),f=0;f<n.length;f++)e=a.columns[f],t=this.elLabel.clone(),d=f*o+o/2,c=-(a.padding||5),t.attr("x",d),t.text(e.text),t.attr(V.util.assign({y:c,"text-anchor":"start","dominant-baseline":"central","font-size":o,"data-column":f},V.util.omit(e,"text"))),t.rotate(-90,d,c),u.appendChild(t.node);this.elColumnLabels.appendChild(u)}});e.Knob=l,e.KnobView=r,e.Matrix=d,e.MatrixView=c,e.Pie=s,e.PieView=n,e.Plot=i,e.PlotView=a}(this.joint.shapes=this.joint.shapes||{},$,joint.shapes.basic,joint);