forked from dima117/Chart.Scatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chart.Scatter.min.js
4 lines (4 loc) · 16.8 KB
/
Chart.Scatter.min.js
1
2
3
4
(function(n,t){typeof define=="function"&&define.amd?define(["Chart"],t):typeof exports=="object"?t(require("Chart")):t(n.Chart)})(this,function(n){"use strict";var t=n.helpers,i={formatDateValue:function(n,t,i,u){var f,e;return(n=new Date(+n),f=u?n.getUTCMilliseconds():n.getMilliseconds(),f)?("000"+f).slice(-3):(e=u?n.getUTCHours()+n.getUTCMinutes()+n.getUTCSeconds():n.getHours()+n.getMinutes()+n.getSeconds(),e?r(n,t||"h:MM",u):r(n,i||"mmm d",u))},getElementOrDefault:function(n,t,i){return t>=0&&t<n.length?n[t]:i},applyRange:function(n,t,i){return n>i?i:n<t?t:n},ScatterPoint:n.Point.extend({inRange:function(n,t){var i=this.hitDetectionRadius+this.radius*this.size;return Math.pow(n-this.x,2)+Math.pow(t-this.y,2)<Math.pow(i,2)},draw:function(){if(this.display&&this.size>0){var n=this.ctx;n.beginPath();n.arc(this.x,this.y,this.size*this.radius,0,Math.PI*2);n.closePath();n.strokeStyle=this.strokeColor;n.lineWidth=this.strokeWidth;n.fillStyle=this.fillColor;n.fill();n.stroke()}}})},r=function(){var r=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,u=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,f=/[^-+\dA-Z]/g,n=function(n,t){for(n=String(n),t=t||2;n.length<t;)n="0"+n;return n},i={"default":"ddd mmm dd yyyy HH:MM:ss"},t={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]};return function(e,o,s){if(arguments.length!=1||Object.prototype.toString.call(e)!="[object String]"||/\d/.test(e)||(o=e,e=undefined),e=e?new Date(e):new Date,isNaN(e))throw SyntaxError("invalid date");o=String(i[o]||o||i["default"]);o.slice(0,4)=="UTC:"&&(o=o.slice(4),s=!0);var h=s?"getUTC":"get",l=e[h+"Date"](),p=e[h+"Day"](),a=e[h+"Month"](),w=e[h+"FullYear"](),c=e[h+"Hours"](),b=e[h+"Minutes"](),k=e[h+"Seconds"](),v=e[h+"Milliseconds"](),y=s?0:e.getTimezoneOffset(),d={d:l,dd:n(l),ddd:t.dayNames[p],dddd:t.dayNames[p+7],m:a+1,mm:n(a+1),mmm:t.monthNames[a],mmmm:t.monthNames[a+12],yy:String(w).slice(2),yyyy:w,h:c%12||12,hh:n(c%12||12),H:c,HH:n(c),M:b,MM:n(b),s:k,ss:n(k),l:n(v,3),L:n(v>99?Math.round(v/10):v),t:c<12?"a":"p",tt:c<12?"am":"pm",T:c<12?"A":"P",TT:c<12?"AM":"PM",Z:s?"UTC":(String(e).match(u)||[""]).pop().replace(f,""),o:(y>0?"-":"+")+n(Math.floor(Math.abs(y)/60)*100+Math.abs(y)%60,4),S:["th","st","nd","rd"][l%10>3?0:(l%100-l%10!=10)*l%10]};return o.replace(r,function(n){return n in d?d[n]:n.slice(1,n.length-1)})}}();n.ScatterNumberScale=n.Element.extend({initialize:function(){this.font=t.fontString(this.fontSize,this.fontStyle,this.fontFamily);this.padding=this.fontSize/2},setDataRange:function(n){this.dataRange=n},api:{calculateControlPoints:function(n,t,r,u,f){var l=!n?0:f,a=!r?0:f,o=t,h=n?n:t,v=r?r:t,y={xx:o.arg-h.arg,yy:o.value-h.value},e={xx:v.arg-h.arg,yy:v.value-h.value},w=y.xx*e.xx+y.yy*e.yy,p=Math.sqrt(e.xx*e.xx+e.yy*e.yy),c=Math.min(Math.max(w/(p*p),.3),.7),s={before:{x:o.arg-e.xx*c*l,y:o.value-e.yy*c*l},after:{x:o.arg+e.xx*(1-c)*a,y:o.value+e.yy*(1-c)*a}};return s.before.y=i.applyRange(s.before.y,u.ymin,u.ymax),s.after.y=i.applyRange(s.after.y,u.ymin,u.ymax),s},generateLabels:function(n,i,r,u){var f=new Array(i+1);return n&&t.each(f,function(i,e){f[e]=t.template(n,{value:r+u*e})}),f}},calculateYscaleRange:function(){this.yScaleRange=this.scaleOverride?{steps:this.scaleSteps,stepValue:this.scaleStepWidth,min:this.scaleStartValue,max:this.scaleStartValue+this.scaleSteps*this.scaleStepWidth}:t.calculateScaleRange([this.dataRange.ymin,this.dataRange.ymax],this.chart.height,this.fontSize,this.beginAtZero,this.integersOnly)},calculateXscaleRange:function(){this.xScaleRange=t.calculateScaleRange([this.dataRange.xmin,this.dataRange.xmax],this.chart.width,this.fontSize,!1,!0)},generateYLabels:function(){this.yLabels=this.api.generateLabels(this.labelTemplate,this.yScaleRange.steps,this.yScaleRange.min,this.yScaleRange.stepValue)},generateXLabels:function(){this.xLabels=this.api.generateLabels(this.argLabelTemplate,this.xScaleRange.steps,this.xScaleRange.min,this.xScaleRange.stepValue)},argToString:function(n){return+n+""},fit:function(){var n,i,r,u;this.calculateYscaleRange();this.calculateXscaleRange();this.generateYLabels();this.generateXLabels();n=t.longestText(this.chart.ctx,this.font,this.xLabels);i=t.longestText(this.chart.ctx,this.font,this.yLabels);this.xPadding=this.display&&this.showLabels?i+this.padding*2:this.padding;r=Math.floor((this.chart.width-this.xPadding)/this.xScaleRange.steps);u=this.fontSize*1.5;this.xLabelRotation=n>r;this.xPaddingRight=this.display&&this.showLabels&&!this.xLabelRotation?n/2:this.padding;this.yPadding=this.display&&this.showLabels?(this.xLabelRotation?n:u)+this.padding*2:this.padding},updateBezierControlPoints:function(n,t,r){for(var u=0;u<n.length;u++){var e=i.getElementOrDefault(n,u),o=i.getElementOrDefault(n,u-1),s=i.getElementOrDefault(n,u+1),f=this.api.calculateControlPoints(o,e,s,this.dataRange,r);e.controlPoints={x1:this.calculateX(f.before.x),y1:this.calculateY(f.before.y,t),x2:this.calculateX(f.after.x),y2:this.calculateY(f.after.y,t)}}},updatePoints:function(n,t){for(var i,r=0;r<n.length;r++)i=n[r],i.x=this.calculateX(i.arg),i.y=this.calculateY(i.value,t)},calculateX:function(n){return this.xPadding+(n-this.xScaleRange.min)*(this.chart.width-this.xPadding-this.xPaddingRight)/(this.xScaleRange.max-this.xScaleRange.min)},calculateY:function(n,t){return this.chart.height-this.yPadding-(n-this.yScaleRange.min)*(this.chart.height-this.yPadding-this.padding)/(this.yScaleRange.max-this.yScaleRange.min)*(t||1)},draw:function(){var n=this.chart.ctx,i,t,r,u;if(this.display){var f=this.calculateX(this.xScaleRange.min),o=this.chart.width,e=this.calculateY(this.yScaleRange.min);for(t=0,i=this.yScaleRange.min;t<=this.yScaleRange.steps;t++,i+=this.yScaleRange.stepValue)r=this.calculateY(i),(this.showLabels||this.showHorizontalLines)&&(n.lineWidth=t==0?this.lineWidth:this.gridLineWidth,n.strokeStyle=t==0?this.lineColor:this.gridLineColor,n.beginPath(),n.moveTo(f-this.padding,r),n.lineTo(this.showHorizontalLines||t==0?o:f,r),n.stroke()),this.showLabels&&(n.lineWidth=this.lineWidth,n.strokeStyle=this.lineColor,n.textAlign="right",n.textBaseline="middle",n.font=this.font,n.fillStyle=this.textColor,n.fillText(this.yLabels[t],f-this.padding*1.4,r));for(t=0,i=this.xScaleRange.min;t<=this.xScaleRange.steps;t++,i+=this.xScaleRange.stepValue)u=this.calculateX(i),(this.showLabels||this.showVerticalLines)&&(n.lineWidth=t==0?this.lineWidth:this.gridLineWidth,n.strokeStyle=t==0?this.lineColor:this.gridLineColor,n.beginPath(),n.moveTo(u,e+this.padding),n.lineTo(u,this.showVerticalLines||t==0?0:e),n.stroke()),this.showLabels&&(n.lineWidth=this.lineWidth,n.strokeStyle=this.lineColor,n.save(),n.translate(u,e+this.padding*1.4),n.rotate(this.xLabelRotation?-Math.PI/2:0),n.textAlign=this.xLabelRotation?"right":"center",n.textBaseline=this.xLabelRotation?"middle":"top",n.font=this.font,n.fillStyle=this.textColor,n.fillText(this.xLabels[t],0,0),n.restore())}}});n.ScatterDateScale=n.ScatterNumberScale.extend({_calculateDateScaleRange:function(n,t,i,r){for(var u=[{u:1,c:1,t:1,n:"ms"},{u:1,c:2,t:2,n:"ms"},{u:1,c:5,t:5,n:"ms"},{u:1,c:10,t:10,n:"ms"},{u:1,c:20,t:20,n:"ms"},{u:1,c:50,t:50,n:"ms"},{u:1,c:100,t:100,n:"ms"},{u:1,c:200,t:200,n:"ms"},{u:1,c:500,t:500,n:"ms"},{u:1e3,c:1,t:1e3,n:"s"},{u:1e3,c:2,t:2e3,n:"s"},{u:1e3,c:5,t:5e3,n:"s"},{u:1e3,c:10,t:1e4,n:"s"},{u:1e3,c:15,t:15e3,n:"s"},{u:1e3,c:20,t:2e4,n:"s"},{u:1e3,c:30,t:3e4,n:"s"},{u:6e4,c:1,t:6e4,n:"m"},{u:6e4,c:2,t:12e4,n:"m"},{u:6e4,c:5,t:3e5,n:"m"},{u:6e4,c:10,t:6e5,n:"m"},{u:6e4,c:15,t:9e5,n:"m"},{u:6e4,c:20,t:12e5,n:"m"},{u:6e4,c:30,t:18e5,n:"m"},{u:36e5,c:1,t:36e5,n:"h"},{u:36e5,c:2,t:72e5,n:"h"},{u:36e5,c:3,t:108e5,n:"h"},{u:36e5,c:4,t:144e5,n:"h"},{u:36e5,c:6,t:216e5,n:"h"},{u:36e5,c:8,t:288e5,n:"h"},{u:36e5,c:12,t:432e5,n:"h"},{u:864e5,c:1,t:864e5,n:"d"},{u:864e5,c:2,t:1728e5,n:"d"},{u:864e5,c:4,t:3456e5,n:"d"},{u:864e5,c:5,t:432e6,n:"d"},{u:6048e5,c:1,t:6048e5,n:"w"}],v=i/(r*3.3),y=+t-n,s=this.useUtc?0:(new Date).getTimezoneOffset()*6e4,p=+n-s,w=+t-s,h=0,c=[2,3,5,7,10],f,e;y/u[h].t>v;)if(h++,h==u.length)for(f=u[u.length-1],e=0;e<c.length;e++)u.push({u:f.u,c:f.c*c[e],t:f.c*c[e]*f.u,n:f.n});var o=u[h].t,l=Math.floor(p/o)*o,a=Math.ceil((w-l)/o),b=l+o*a;return{min:l+s,max:b+s,steps:a,stepValue:o}},calculateXscaleRange:function(){this.xScaleRange=this._calculateDateScaleRange(this.dataRange.xmin,this.dataRange.xmax,this.chart.width,this.fontSize)},argToString:function(n){return r(+n,this.dateTimeFormat,this.useUtc)},generateXLabels:function(){var r=this.xScaleRange.min,u=this.xScaleRange.stepValue,n=new Array(this.xScaleRange.steps+1);t.each(n,function(t,f){var e=r+u*f;n[f]=i.formatDateValue(e,this.timeFormat,this.dateFormat,this.useUtc)},this);this.xLabels=n}});n.ScatterDataSet=function(){var n=function(n,t,i,r){this.chart=i;this.scale=r;this.label=n.label||null;this.strokeColor=n.strokeColor||t.datasetStrokeColor;this.pointColor=n.pointColor||n.strokeColor||t.datasetStrokeColor;this.pointStrokeColor=n.pointStrokeColor||t.datasetPointStrokeColor;this.pointDot=t.pointDot;this.pointDotRadius=t.pointDotRadius;this.pointHitDetectionRadius=t.pointHitDetectionRadius;this.pointDotStrokeWidth=t.pointDotStrokeWidth;this.scaleArgLabel=t.scaleArgLabel;this.scaleLabel=t.scaleLabel;this.scaleSizeLabel=t.scaleSizeLabel;this.points=[]};return n.prototype.addPoint=function(n,t,i){i=arguments.length<3?1:i;var r=this._createNewPoint();this._setPointData(r,n,t,i);this.points.push(r)},n.prototype.setPointData=function(n,t,r,u){u=arguments.length<4?1:u;var f=i.getElementOrDefault(this.points,n);f&&this._setPointData(f,t,r,u)},n.prototype.removePoint=function(n){n>=0&&n<this.points.length&&this.points.splice(n,1)},n.prototype._createNewPoint=function(){return new i.ScatterPoint({ctx:this.chart.ctx,datasetLabel:this.label,display:this.pointDot,radius:this.pointDotRadius,hitDetectionRadius:this.pointHitDetectionRadius,strokeWidth:this.pointDotStrokeWidth,strokeColor:this.pointStrokeColor,highlightStroke:this.pointColor,fillColor:this.pointColor,highlightFill:this.pointStrokeColor})},n.prototype._setPointData=function(n,i,r,u){var f=this.scale.argToString(+i),e=+r+"",o=+u+"";n.arg=+i;n.value=+r;n.size=+u;n.argLabel=t.template(this.scaleArgLabel,{value:f});n.valueLabel=t.template(this.scaleLabel,{value:e});n.sizeLabel=t.template(this.scaleSizeLabel,{value:o})},n}();n.Type.extend({name:"Scatter",defaults:{scaleArgLabel:"<%=value%>",scaleSizeLabel:"<%=value%>",emptyDataMessage:"chart has no data",scaleShowGridLines:!0,scaleGridLineWidth:1,scaleGridLineColor:"rgba(0,0,0,.05)",scaleShowHorizontalLines:!0,scaleShowVerticalLines:!0,scaleType:"number",useUtc:!0,scaleDateFormat:"mmm d",scaleTimeFormat:"h:MM",scaleDateTimeFormat:"mmm d, yyyy, hh:MM",datasetStroke:!0,datasetStrokeWidth:2,datasetStrokeColor:"#007ACC",datasetPointStrokeColor:"white",bezierCurve:!0,bezierCurveTension:.4,pointDot:!0,pointDotStrokeWidth:1,pointDotRadius:4,pointHitDetectionRadius:4,multiTooltipTemplate:"<%=argLabel%>; <%=valueLabel%>",tooltipTemplate:"<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%=argLabel%>; <%=valueLabel%>",legendTemplate:'<ul class="<%=name.toLowerCase()%>-legend"><%for(var i=0;i<datasets.length;i++){%><li><span class="<%=name.toLowerCase()%>-legend-marker" style="background-color:<%=datasets[i].strokeColor%>"><\/span><%=datasets[i].label%><\/li><%}%><\/ul>'},initialize:function(i){this.hasData=!1;this.datasets=[];this.scale=this._initScale();i.datasets&&(i=i.datasets);t.each(i,function(i){var r=new n.ScatterDataSet(i,this.options,this.chart,this.scale);this.datasets.push(r);this.hasData|=!!i.data.length;t.each(i.data,function(n){r.addPoint(n.x,n.y,n.r||1)})},this);this.options.showTooltips&&t.bindEvents(this,this.options.tooltipEvents,function(n){var i=n.type!=="mouseout"?this.getPointsAtEvent(n):[];this._forEachPoint(function(n){n.restore(["fillColor","strokeColor"])});t.each(i,function(n){n.fillColor=n.highlightFill;n.strokeColor=n.highlightStroke});this.showTooltip(i)});var r=this._calculateRange();this.scale.setDataRange(r);this.update()},_initScale:function(){var t={chart:this.chart,textColor:this.options.scaleFontColor,fontSize:this.options.scaleFontSize,fontStyle:this.options.scaleFontStyle,fontFamily:this.options.scaleFontFamily,labelTemplate:this.options.scaleLabel,argLabelTemplate:this.options.scaleArgLabel,showLabels:this.options.scaleShowLabels,beginAtZero:this.options.scaleBeginAtZero,integersOnly:this.options.scaleIntegersOnly,gridLineWidth:this.options.scaleShowGridLines?this.options.scaleGridLineWidth:0,gridLineColor:this.options.scaleShowGridLines?this.options.scaleGridLineColor:"rgba(0,0,0,0)",showHorizontalLines:this.options.scaleShowHorizontalLines,showVerticalLines:this.options.scaleShowVerticalLines,lineWidth:this.options.scaleLineWidth,lineColor:this.options.scaleLineColor,display:this.options.showScale,scaleOverride:this.options.scaleOverride,scaleSteps:this.options.scaleSteps,scaleStepWidth:this.options.scaleStepWidth,scaleStartValue:this.options.scaleStartValue,useUtc:this.options.useUtc,dateFormat:this.options.scaleDateFormat,timeFormat:this.options.scaleTimeFormat,dateTimeFormat:this.options.scaleDateTimeFormat};return this.options.scaleType==="date"?new n.ScatterDateScale(t):new n.ScatterNumberScale(t)},getPointsAtEvent:function(n){var i=[],r=t.getRelativePosition(n);return t.each(this.datasets,function(n){t.each(n.points,function(n){n.inRange(r.x,r.y)&&i.push(n)})},this),i},showTooltip:function(i){var u,r,f,e;return this.draw(),i.length>0&&(u=i[0],r=u.tooltipPosition(),i.length==1?new n.Tooltip({x:Math.round(r.x),y:Math.round(r.y),xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,caretHeight:this.options.tooltipCaretSize,cornerRadius:this.options.tooltipCornerRadius,text:t.template(this.options.tooltipTemplate,u),chart:this.chart,custom:this.options.customTooltips}).draw():(f=[],e=[],t.each(i,function(n){f.push(t.template(this.options.multiTooltipTemplate,n));e.push({fill:n._saved.fillColor||n.fillColor,stroke:n._saved.strokeColor||n.strokeColor})},this),new Chart.MultiTooltip({x:Math.round(r.x),y:Math.round(r.y),xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,xOffset:this.options.tooltipXOffset,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,titleTextColor:this.options.tooltipTitleFontColor,titleFontFamily:this.options.tooltipTitleFontFamily,titleFontStyle:this.options.tooltipTitleFontStyle,titleFontSize:this.options.tooltipTitleFontSize,cornerRadius:this.options.tooltipCornerRadius,labels:f,legendColors:e,legendColorBackground:this.options.multiTooltipKeyBackground,title:"",chart:this.chart,ctx:this.chart.ctx,custom:this.options.customTooltips}).draw())),this},_forEachPoint:function(n){t.each(this.datasets,function(i){t.each(i.points,n,this)},this)},_forEachDataset:function(n){t.each(this.datasets,n,this)},_calculateRange:function(){var n=undefined,t=undefined,i=undefined,r=undefined;return this._forEachPoint(function(u){(n===undefined||u.arg<n)&&(n=u.arg);(t===undefined||u.arg>t)&&(t=u.arg);(i===undefined||u.value<i)&&(i=u.value);(r===undefined||u.value>r)&&(r=u.value)}),{xmin:n,xmax:t,ymin:i,ymax:r}},_drawMessage:function(n){var i=this.chart.ctx,r=this.chart.width,u=this.chart.height,f=this.options.scaleFontSize,e=this.options.scaleFontStyle,o=this.options.scaleFontFamily,s=t.fontString(f,e,o);i.save();i.translate(r/2,u/2);i.textAlign="center";i.textBaseline="middle";i.font=s;i.fillStyle=this.options.scaleFontColor;i.fillText(n,0,0);i.restore()},_drawLine:function(n){var i=this.chart.ctx,r=undefined;i.lineJoin="round";i.lineWidth=this.options.datasetStrokeWidth;i.strokeStyle=n.strokeColor||this.options.datasetStrokeColor;i.beginPath();t.each(n.points,function(n,t){t===0?i.moveTo(n.x,n.y):this.options.bezierCurve?i.bezierCurveTo(r.controlPoints.x2,r.controlPoints.y2,n.controlPoints.x1,n.controlPoints.y1,n.x,n.y):i.lineTo(n.x,n.y);r=n},this);i.stroke()},update:function(){var n=this._calculateRange();this.scale.setDataRange(n);this.render()},draw:function(n){this.hasData?(this.scale.fit(),this._forEachDataset(function(t){this.scale.updatePoints(t.points,n);this.options.bezierCurve&&this.scale.updateBezierControlPoints(t.points,n,this.options.bezierCurveTension)}),this.clear(),this.scale.draw(),this.options.datasetStroke&&t.each(this.datasets,this._drawLine,this),this.options.pointDot&&this._forEachPoint(function(n){n.draw()})):(this.clear(),this._drawMessage(this.options.emptyDataMessage))}})});
/*
//# sourceMappingURL=Chart.Scatter.min.js.map
*/