vk3cpu/chartjs-chart-smith.min.js

8 wiersze
6.7 KiB
JavaScript
Czysty Zwykły widok Historia

2021-10-11 21:19:08 +00:00
/*!
* chartjs-chart-smith v0.3.0
* https://github.com/chartjs/chartjs-chart-smith
* (c) 2020 Chart.js Contributors
* Released under the MIT license
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e((t=t||self).Chart)}(this,(function(t){"use strict";const e=(t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t).helpers,i=e.options.resolve,o=e.valueOrDefault;class n extends t.controllers.line{linkScales(){}updateElement(t,e){const i=this,n=i.getMeta(),s=t.custom||{},a=i.index,r=i.getScaleForId(n.yAxisID),l=i.getScaleForId(n.xAxisID),c=n.dataset._model,d=i._resolvePointOptions(t,e),{x:h,y:p}=i.calculatePointPosition(e);t._xScale=l,t._yScale=r,t._options=d,t._datasetIndex=a,t._index=e,t._model={x:h,y:p,skip:s.skip||isNaN(h)||isNaN(p),radius:d.radius,pointStyle:d.pointStyle,rotation:d.rotation,backgroundColor:d.backgroundColor,borderColor:d.borderColor,borderWidth:d.borderWidth,tension:o(s.tension,c?c.tension:0),steppedLine:!!c&&c.steppedLine,hitRadius:d.hitRadius}}_resolvePointOptions(t,e){const o=this.chart,n=o.data.datasets[this.index],s=t.custom||{},a=o.options.elements.point,r={};let l,c,d;const h={chart:o,dataIndex:e,dataset:n,datasetIndex:this.index},p={backgroundColor:"pointBackgroundColor",borderColor:"pointBorderColor",borderWidth:"pointBorderWidth",hitRadius:"pointHitRadius",hoverBackgroundColor:"pointHoverBackgroundColor",hoverBorderColor:"pointHoverBorderColor",hoverBorderWidth:"pointHoverBorderWidth",hoverRadius:"pointHoverRadius",pointStyle:"pointStyle",radius:"pointRadius",rotation:"pointRotation"},x=Object.keys(p);for(l=0,c=x.length;l<c;++l)d=x[l],r[d]=i([s[d],n[p[d]],n[d],a[d]],h,e);return r}calculatePointPosition(t){const e=this.chart.scale,i=this.getDataset().data[t];return e.getPointPosition(i.real,i.imag)}}const s=t.helpers;class a extends t.Scale{setDimensions(){this.height=this.maxHeight,this.width=this.maxWidth,this.xCenter=this.left+Math.round(this.width/2),this.yCenter=this.top+Math.round(this.height/2),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}buildTicks(){return this.rTicks=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.2,1.4,1.6,1.8,2,3,4,5,10,20,50],this.xTicks=[-50,-20,-10,-5,-4,-3,-2,-1,-.8,-.6,-.4,-.2,0,.2,.4,.6,.8,1,2,3,4,5,10,20,50],[]}convertTicksToLabels(){return this.rLabels=this.rTicks.map((function(t,e,i){return this.options.ticks.rCallback.apply(this,[t,e,i])}),this),this.xLabels=this.xTicks.map((function(t,e,i){return this.options.ticks.xCallback.apply(this,[t,e,i])}),this),[]}calculateTickRotation(){}fit(){const e=this;e.xCenter=(e.left+e.right)/2,e.yCenter=(e.top+e.bottom)/2;const i=s.getValueOrDefault(e.options.ticks.fontSize,t.defaults.global.defaultFontSize);if(e.options.ticks.display){const o=s.getValueOrDefault(e.options.ticks.fontStyle,t.defaults.global.defaultFontStyle),n=s.getValueOrDefault(e.options.ticks.fontFamily,t.defaults.global.defaultFontFamily),a=s.fontString(i,o,n);e.ctx.font=a;const r=e.xLabels.map(t=>e.ctx.measureText(t).width);e.minDimension=Math.min(e.right-e.left,e.bottom-e.top),s.each(e.xTicks,(t,o)=>{if(0!==t){const n=e.minDimension/2,a=e.getPointPosition(0,t),l=(a.x-e.xCenter)/n,c=(a.y-e.yCenter)/n,d=r[o]+e.options.ticks.padding,h=[{x:a.x+l*d+c*i,y:a.y+c*d-l*i},{x:a.x+l*d-c*i,y:a.y+c*d+l*i}];s.each(h,t=>{e.paddingLeft=Math.max(e.paddingLeft,e.left-t.x),e.paddingTop=Math.max(e.paddingTop,e.top-t.y),e.paddingRight=Math.max(e.paddingRight,t.x-e.right),e.paddingBottom=Math.max(e.paddingBottom,t.y-e.bottom)})}})}e.minDimension=Math.min(e.right-e.left-e.paddingLeft-e.paddingRight,e.bottom-e.top-e.paddingBottom-e.paddingTop),e.arcs=[],e.rLabelPoints=[],e.xLabelPoints=[],s.each(e.rTicks,t=>{const i=1/(1+t)*(e.minDimension/2),o=e.xCenter+t/(1+t)*(e.minDimension/2);e.arcs.push({x:o,y:e.yCenter,r:i,s:0,e:2*Math.PI,cc:!1}),e.rLabelPoints.push({x:o-i,y:e.yCenter})}),s.each(e.xTicks,t=>{if(0!==t){const i=1/Math.abs(t)*(e.minDimension/2),o=e.xCenter+e.minDimension/2,n=t>0?e.yCenter-i:e.yCenter+i,s=Math.sqrt(Math.pow(o-e.xCenter,2)+Math.pow(n-e.yCenter,2)),a=Math.atan2(e.yCenter-n,e.xCenter-o),r=(t>0?.5:-.5)*Math.acos((Math.pow(i,2)-Math.pow(e.minDimension/2,2))/Math.pow(s,2))+