-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.js
More file actions
2 lines (2 loc) · 6.8 KB
/
chart.js
File metadata and controls
2 lines (2 loc) · 6.8 KB
1
2
/*! Chart.js v4.4.0 | MIT License | https://www.chartjs.org/ */
(function(global,factory){typeof exports==='object'&&typeof module!=='undefined'?factory(exports):typeof define==='function'&&define.amd?define(['exports'],factory):(global=typeof globalThis!=='undefined'?globalThis:global||self,factory(global.Chart={}))}(this,(function(exports){'use strict';const CANVAS_KEY='canvas';const CSS_KEY_REGEX=/^([\w-]+)=(.+)$/;const CSS_VALUE_REGEX=/^(.*?):\s*(.*)$/;const DEFAULT_BOXMODEL_MARGIN=0;const DEFAULT_PADDING=0;const LINE_HEIGHT_REGEX=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/;const FONT_WEIGHT_REGEX=/^(normal|bold|(\d+))$/;const FONT_STYLE_REGEX=/^(normal|italic|oblique)$/;const FONT_VARIANT_REGEX=/^(normal|small-caps)$/;const FONT_FAMILY_REGEX=/^(([-\w]+\s*,\s*)*[-\w]+)(\s*\/\s*(normal|bold|(\d+)?))?(\s*,\s*)?(italic|oblique)?(\s+small-caps)?$/;const FONT_REGEX=/^\s*(italic|oblique|normal)?\s*(small-caps)?\s*(bold|(\d+))?\s*(.+)\s*$/;const OFFSET_PROPS=['x','y'];const BORDER_PROPS=['top','right','bottom','left'];const CORNERS=['topLeft','topRight','bottomLeft','bottomRight'];const ALIAS_PROPS=['fill','stroke','borderDash','borderDashOffset','borderJoinStyle','borderLineCap','borderLineWidth','borderMiterLimit','borderSkipped','borderWidth','drawBorder'];const DEFAULT_CANVAS_HEIGHT=150;const DEFAULT_CANVAS_WIDTH=300;const LINE_STEPS=[],LINE_STEPS_COUNT=6;for(let i=1;i<LINE_STEPS_COUNT;i++){LINE_STEPS.push(i/LINE_STEPS_COUNT)}const EPSILON=Number.EPSILON||1e-15;const MAX_INTEGER=Number.MAX_SAFE_INTEGER||9007199254740991;const MIN_INTEGER=Number.MIN_SAFE_INTEGER||-9007199254740991;const HALF_PI=Math.PI/2;const QUARTER_PI=Math.PI/4;const TWO_PI=Math.PI*2;const THREE_HALVES_PI=Math.PI*1.5;function noop(){}function isNullOrUndef(value){return value==null}function isObject(value){return value!==null&&typeof value==='object'}const isObjectLike=isObject;function isArray(value){return Array.isArray(value)}function isFunction(value){return typeof value==='function'}function isNumber(value){return typeof value==='number'&&!Number.isNaN(value)}function isFinite(value){return isNumber(value)&&Number.isFinite(value)}function isString(value){return typeof value==='string'}function isBoolean(value){return typeof value==='boolean'}const isEvent=isObjectLike;function isPlainObject(value){if(!isObjectLike(value)){return false}const proto=Object.getPrototypeOf(value);return proto===null||proto===Object.prototype}function valueOrDefault(value,defaultValue){return typeof value==='undefined'?defaultValue:value}const toFloat=function(value,defaultValue){const n=parseFloat(value);return isNumber(n)?n:defaultValue};function parseInt(value,defaultValue){const n=Number.parseInt(value,10);return isNumber(n)?n:defaultValue}function noop(){}function Chart(item,config){this.config=config=mergeConfig({},config||{});this.canvas=item.canvas||item;this.ctx=this.canvas.getContext('2d');this.chartInstance=undefined}const Chart$1=Chart;Chart$1.prototype.initialize=function(){return this};Chart$1.version='4.4.0';function isPatternOrGradient(value){return value instanceof CanvasPattern||value instanceof CanvasGradient}const Chart$2=Chart$1;class ChartElement{constructor(cfg){Object.assign(this,cfg)}getProps(props){const values={};let i=props.length;while(i--){values[props[i]]=this[props[i]]}return values}setProps(props){Object.assign(this,props)}tooltipPosition(){return{x:this.x,y:this.y}}hasValue(){return isNumber(this.x)&&isNumber(this.y)}}function toTRBL(value){let t,r,b,l;if(isObject(value)){t=value.top;r=value.right;b=value.bottom;l=value.left}else{t=r=b=l=value}return{top:t,right:r,bottom:b,left:l}}function toTRBLCorners(value){let tl,tr,br,bl;if(isObject(value)){tl=value.topLeft;tr=value.topRight;br=value.bottomRight;bl=value.bottomLeft}else{tl=tr=br=bl=value}return{topLeft:tl,topRight:tr,bottomRight:br,bottomLeft:bl}}function mergeConfig(...descriptors){const config={};let i=descriptors.length;while(i--){deepMerge(config,descriptors[i])}return config}function deepMerge(target,source){let k,v;for(k in source){if(!source.hasOwnProperty(k)){continue}v=source[k];if(isPlainObject(v)){target[k]=mergeConfig(target[k]||{},v)}else{target[k]=v}}return target}function cloneDeep(source){if(isArray(source)){return source.map(item=>cloneDeep(item))}if(isPlainObject(source)){const target={};for(const key in source){target[key]=cloneDeep(source[key])}return target}return source}class Chart$3{static helpers={noop:noop,uid:0,toTRBL:toTRBL,toTRBLCorners:toTRBLCorners,mergeConfig:mergeConfig,deepMerge:deepMerge,cloneDeep:cloneDeep,toFloat:toFloat,parseInt:parseInt,isArray:isArray,isObject:isObject,isNumber:isNumber,isString:isString,isFunction:isFunction,isBoolean:isBoolean,isFinite:isFinite,valueOrDefault:valueOrDefault,isPlainObject:isPlainObject,isPatternOrGradient:isPatternOrGradient,isEvent:isEvent,noop:noop};static version='4.4.0';}window.Chart=Chart$3;Chart$3.Chart=Chart$2;exports.Chart=Chart$3;Object.defineProperty(exports,'__esModule',{value:true})})));if(typeof window!=='undefined'){window.Chart=window.Chart||Chart}(function(){const canvas=document.createElement('canvas');const ctx=canvas.getContext('2d');window.Chart.canvasHelper={drawRect:function(x,y,w,h,fill){ctx.fillRect(x,y,w,h)},drawLine:function(x0,y0,x1,y1){ctx.beginPath();ctx.moveTo(x0,y0);ctx.lineTo(x1,y1);ctx.stroke()}};const ChartType={bar:function(ctx,data,options){const{labels,datasets}=data;const{scales,plugins}=options||{};let maxValue=0;datasets.forEach(d=>{d.data.forEach(v=>{maxValue=Math.max(maxValue,v)})});const width=ctx.canvas.width;const height=ctx.canvas.height;const barWidth=width/(labels.length*1.5);const barGap=barWidth*0.25;ctx.fillStyle='#ccc';ctx.fillRect(0,0,width,height);ctx.fillStyle='#63b0ff';let x=20;datasets[0].data.forEach((value,i)=>{const barHeight=(value/maxValue)*(height-40);ctx.fillRect(x,height-20-barHeight,barWidth,barHeight);x+=barWidth+barGap})},doughnut:function(ctx,data,options){const{labels,datasets}=data;const{scales,plugins}=options||{};const values=datasets[0].data;const total=values.reduce((a,b)=>a+b,0);const colors=['#63b0ff','#8bd0ff','#2a7ef5','#f59e0b','#10b981','#ef4444','#a78bfa'];const centerX=ctx.canvas.width/2;const centerY=ctx.canvas.height/2;const radius=Math.min(centerX,centerY)*0.7;let currentAngle=0;values.forEach((value,i)=>{const sliceAngle=(value/total)*TWO_PI;ctx.fillStyle=colors[i%colors.length];ctx.beginPath();ctx.arc(centerX,centerY,radius,currentAngle,currentAngle+sliceAngle);ctx.lineTo(centerX,centerY);ctx.fill();currentAngle+=sliceAngle})}};window.ChartType=ChartType})();function Chart(ctx,config){const type=config.type||'bar';const Chart$4=window.Chart||{};this.ctx=ctx;this.data=config.data||{};this.options=config.options||{};this.type=type;this.draw=function(){const drawFn=window.ChartType&&window.ChartType[type];if(drawFn){drawFn(this.ctx,this.data,this.options)}};this.update=function(){this.draw()};this.destroy=function(){}}window.Chart=Chart;