📄 chart.js
字号:
/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.widget.vml.Chart");dojo.require("dojo.widget.HtmlWidget");dojo.require("dojo.widget.Chart");dojo.require("dojo.math");dojo.require("dojo.html.layout");dojo.require("dojo.gfx.color");dojo.widget.defineWidget("dojo.widget.vml.Chart", [dojo.widget.HtmlWidget, dojo.widget.Chart], function () { this.templatePath = null; this.templateCssPath = null; this._isInitialize = false; this.hasData = false; this.vectorNode = null; this.plotArea = null; this.dataGroup = null; this.axisGroup = null; this.properties = {height:0, width:0, defaultWidth:600, defaultHeight:400, plotType:null, padding:{top:10, bottom:2, left:60, right:30}, axes:{x:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}, y:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}}};}, {parseProperties:function (node) { var bRangeX = false; var bRangeY = false; if (node.getAttribute("width")) { this.properties.width = node.getAttribute("width"); } if (node.getAttribute("height")) { this.properties.height = node.getAttribute("height"); } if (node.getAttribute("plotType")) { this.properties.plotType = node.getAttribute("plotType"); } if (node.getAttribute("padding")) { if (node.getAttribute("padding").indexOf(",") > -1) { var p = node.getAttribute("padding").split(","); } else { var p = node.getAttribute("padding").split(" "); } if (p.length == 1) { var pad = parseFloat(p[0]); this.properties.padding.top = pad; this.properties.padding.right = pad; this.properties.padding.bottom = pad; this.properties.padding.left = pad; } else { if (p.length == 2) { var padV = parseFloat(p[0]); var padH = parseFloat(p[1]); this.properties.padding.top = padV; this.properties.padding.right = padH; this.properties.padding.bottom = padV; this.properties.padding.left = padH; } else { if (p.length == 4) { this.properties.padding.top = parseFloat(p[0]); this.properties.padding.right = parseFloat(p[1]); this.properties.padding.bottom = parseFloat(p[2]); this.properties.padding.left = parseFloat(p[3]); } } } } if (node.getAttribute("rangeX")) { var p = node.getAttribute("rangeX"); if (p.indexOf(",") > -1) { p = p.split(","); } else { p = p.split(" "); } this.properties.axes.x.range.min = parseFloat(p[0]); this.properties.axes.x.range.max = parseFloat(p[1]); bRangeX = true; } if (node.getAttribute("rangeY")) { var p = node.getAttribute("rangeY"); if (p.indexOf(",") > -1) { p = p.split(","); } else { p = p.split(" "); } this.properties.axes.y.range.min = parseFloat(p[0]); this.properties.axes.y.range.max = parseFloat(p[1]); bRangeY = true; } return {rangeX:bRangeX, rangeY:bRangeY};}, setAxesPlot:function (table) { if (table.getAttribute("axisAt")) { var p = table.getAttribute("axisAt"); if (p.indexOf(",") > -1) { p = p.split(","); } else { p = p.split(" "); } if (!isNaN(parseFloat(p[0]))) { this.properties.axes.x.plotAt = parseFloat(p[0]); } else { if (p[0].toLowerCase() == "ymin") { this.properties.axes.x.plotAt = this.properties.axes.y.range.min; } else { if (p[0].toLowerCase() == "ymax") { this.properties.axes.x.plotAt = this.properties.axes.y.range.max; } } } if (!isNaN(parseFloat(p[1]))) { this.properties.axes.y.plotAt = parseFloat(p[1]); } else { if (p[1].toLowerCase() == "xmin") { this.properties.axes.y.plotAt = this.properties.axes.x.range.min; } else { if (p[1].toLowerCase() == "xmax") { this.properties.axes.y.plotAt = this.properties.axes.x.range.max; } } } } else { this.properties.axes.x.plotAt = this.properties.axes.y.range.min; this.properties.axes.y.plotAt = this.properties.axes.x.range.min; }}, drawVectorNode:function () { if (this.vectorNode) { this.destroy(); } this.vectorNode = document.createElement("div"); this.vectorNode.style.width = this.properties.width + "px"; this.vectorNode.style.height = this.properties.height + "px"; this.vectorNode.style.position = "relative"; this.domNode.appendChild(this.vectorNode);}, drawPlotArea:function () { var plotWidth = this.properties.width - this.properties.padding.left - this.properties.padding.right; var plotHeight = this.properties.height - this.properties.padding.top - this.properties.padding.bottom; if (this.plotArea) { this.plotArea.parentNode.removeChild(this.plotArea); this.plotArea = null; } this.plotArea = document.createElement("div"); this.plotArea.style.position = "absolute"; this.plotArea.style.backgroundColor = "#fff"; this.plotArea.style.top = (this.properties.padding.top) - 2 + "px"; this.plotArea.style.left = (this.properties.padding.left - 1) + "px"; this.plotArea.style.width = plotWidth + "px"; this.plotArea.style.height = plotHeight + "px"; this.plotArea.style.clip = "rect(0 " + plotWidth + " " + plotHeight + " 0)"; this.vectorNode.appendChild(this.plotArea);}, drawDataGroup:function () { var plotWidth = this.properties.width - this.properties.padding.left - this.properties.padding.right; var plotHeight = this.properties.height - this.properties.padding.top - this.properties.padding.bottom; if (this.dataGroup) { this.dataGroup.parentNode.removeChild(this.dataGroup); this.dataGroup = null; } this.dataGroup = document.createElement("div"); this.dataGroup.style.position = "absolute"; this.dataGroup.setAttribute("title", "Data Group"); this.dataGroup.style.top = "0px"; this.dataGroup.style.left = "0px"; this.dataGroup.style.width = plotWidth + "px"; this.dataGroup.style.height = plotHeight + "px"; this.plotArea.appendChild(this.dataGroup);}, drawAxes:function () { var plotWidth = this.properties.width - this.properties.padding.left - this.properties.padding.right; var plotHeight = this.properties.height - this.properties.padding.top - this.properties.padding.bottom; if (this.axisGroup) { this.axisGroup.parentNode.removeChild(this.axisGroup); this.axisGroup = null; } this.axisGroup = document.createElement("div"); this.axisGroup.style.position = "absolute"; this.axisGroup.setAttribute("title", "Axis Group"); this.axisGroup.style.top = "0px"; this.axisGroup.style.left = "0px"; this.axisGroup.style.width = plotWidth + "px"; this.axisGroup.style.height = plotHeight + "px"; this.plotArea.appendChild(this.axisGroup); var stroke = 1; var line = document.createElement("v:line"); var y = dojo.widget.vml.Chart.Plotter.getY(this.properties.axes.x.plotAt, this); line.setAttribute("from", "0px," + y + "px"); line.setAttribute("to", plotWidth + "px," + y + "px"); line.style.position = "absolute"; line.style.top = "0px"; line.style.left = "0px"; line.style.antialias = "false"; line.setAttribute("strokecolor", "#666"); line.setAttribute("strokeweight", stroke * 2 + "px"); this.axisGroup.appendChild(line); var line = document.createElement("v:line"); var x = dojo.widget.vml.Chart.Plotter.getX(this.properties.axes.y.plotAt, this); line.setAttribute("from", x + "px,0px"); line.setAttribute("to", x + "px," + plotHeight + "px"); line.style.position = "absolute"; line.style.top = "0px"; line.style.left = "0px"; line.style.antialias = "false"; line.setAttribute("strokecolor", "#666"); line.setAttribute("strokeweight", stroke * 2 + "px"); this.axisGroup.appendChild(line); var size = 10; var t = document.createElement("div"); t.style.position = "absolute"; t.style.top = (this.properties.height - this.properties.padding.bottom) + "px"; t.style.left = this.properties.padding.left + "px"; t.style.fontFamily = "sans-serif"; t.style.fontSize = size + "px"; t.innerHTML = dojo.math.round(parseFloat(this.properties.axes.x.range.min), 2); this.vectorNode.appendChild(t); t = document.createElement("div"); t.style.position = "absolute"; t.style.top = (this.properties.height - this.properties.padding.bottom) + "px"; t.style.left = (this.properties.width - this.properties.padding.right - size) + "px"; t.style.fontFamily = "sans-serif"; t.style.fontSize = size + "px"; t.innerHTML = dojo.math.round(parseFloat(this.properties.axes.x.range.max), 2); this.vectorNode.appendChild(t); t = document.createElement("div"); t.style.position = "absolute"; t.style.top = (size / 2) + "px"; t.style.left = "0px"; t.style.width = this.properties.padding.left + "px"; t.style.textAlign = "right"; t.style.paddingRight = "4px"; t.style.fontFamily = "sans-serif"; t.style.fontSize = size + "px"; t.innerHTML = dojo.math.round(parseFloat(this.properties.axes.y.range.max), 2); this.vectorNode.appendChild(t); t = document.createElement("div"); t.style.position = "absolute"; t.style.top = (this.properties.height - this.properties.padding.bottom - size) + "px"; t.style.left = "0px"; t.style.width = this.properties.padding.left + "px"; t.style.textAlign = "right"; t.style.paddingRight = "4px"; t.style.fontFamily = "sans-serif"; t.style.fontSize = size + "px"; t.innerHTML = dojo.math.round(parseFloat(this.properties.axes.y.range.min), 2); this.vectorNode.appendChild(t);}, init:function () { if (!this.properties.width || !this.properties.height) { var box = dojo.html.getContentBox(this.domNode); if (!this.properties.width) { this.properties.width = (box.width < 32) ? this.properties.defaultWidth : box.width; } if (!this.properties.height) { this.properties.height = (box.height < 32) ? this.properties.defaultHeight : box.height; } } this.drawVectorNode(); this.drawPlotArea(); this.drawDataGroup(); this.drawAxes(); this.assignColors(); this._isInitialized = true;}, destroy:function () { while (this.domNode.childNodes.length > 0) { this.domNode.removeChild(this.domNode.childNodes[0]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -