/** * o------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | This package is licensed under the RGraph license. For all kinds of business | * | purposes there is a small one-time licensing fee to pay and for non | * | commercial purposes it is free to use. You can read the full license here: | * | | * | http://www.rgraph.net/LICENSE.txt | * o------------------------------------------------------------------------------o */ if (typeof(RGraph) == 'undefined') RGraph = {}; /** * The odometer constructor. Pass it the ID of the canvas tag, the start value of the odo, * the end value, and the value that the pointer should point to. * * @param string id The ID of the canvas tag * @param int start The start value of the Odo * @param int end The end value of the odo * @param int value The indicated value (what the needle points to) */ RGraph.Odometer = function (id, start, end, value) { this.id = id this.canvas = document.getElementById(id); this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.type = 'odo'; this.isRGraph = true; this.start = start; this.end = end; this.value = value; this.currentValue = null; /** * Compatibility with older browsers */ RGraph.OldBrowserCompat(this.context); this.properties = { 'chart.radius': null, 'chart.value.text': false, 'chart.value.text.decimals': 0, 'chart.needle.color': 'black', 'chart.needle.width': 2, 'chart.needle.head': true, 'chart.needle.tail': true, 'chart.needle.type': 'pointer', 'chart.needle.extra': [], 'chart.needle.triangle.border': '#aaa', 'chart.text.size': 10, 'chart.text.color': 'black', 'chart.text.font': 'Verdana', 'chart.green.max': end * 0.75, 'chart.red.min': end * 0.9, 'chart.green.color': 'green', 'chart.yellow.color': 'yellow', 'chart.red.color': 'red', 'chart.green.solid': false, 'chart.yellow.solid': false, 'chart.red.solid': false, 'chart.label.area': 35, 'chart.gutter.left': 25, 'chart.gutter.right': 25, 'chart.gutter.top': 25, 'chart.gutter.bottom': 25, 'chart.title': '', 'chart.title.background': null, 'chart.title.hpos': null, 'chart.title.vpos': null, 'chart.title.font': null, 'chart.title.bold': true, 'chart.contextmenu': null, 'chart.linewidth': 1, 'chart.shadow.inner': false, 'chart.shadow.inner.color': 'black', 'chart.shadow.inner.offsetx': 3, 'chart.shadow.inner.offsety': 3, 'chart.shadow.inner.blur': 6, 'chart.shadow.outer': false, 'chart.shadow.outer.color': '#666', 'chart.shadow.outer.offsetx': 0, 'chart.shadow.outer.offsety': 0, 'chart.shadow.outer.blur': 15, 'chart.annotatable': false, 'chart.annotate.color': 'black', 'chart.scale.decimals': 0, 'chart.zoom.factor': 1.5, 'chart.zoom.fade.in': true, 'chart.zoom.fade.out': true, 'chart.zoom.hdir': 'right', 'chart.zoom.vdir': 'down', 'chart.zoom.frames': 25, 'chart.zoom.delay': 16.666, 'chart.zoom.shadow': true, 'chart.zoom.mode': 'canvas', 'chart.zoom.thumbnail.width': 75, 'chart.zoom.thumbnail.height': 75, 'chart.zoom.background': true, 'chart.zoom.action': 'zoom', 'chart.resizable': false, 'chart.resize.handle.adjust': [0,0], 'chart.resize.handle.background': null, 'chart.units.pre': '', 'chart.units.post': '', 'chart.border': false, 'chart.border.color1': '#BEBCB0', 'chart.border.color2': '#F0EFEA', 'chart.border.color3': '#BEBCB0', 'chart.tickmarks.highlighted': false, 'chart.zerostart': false, 'chart.labels': null, 'chart.units.pre': '', 'chart.units.post': '', 'chart.value.units.pre': '', 'chart.value.units.post': '', 'chart.key': [], 'chart.key.background': 'white', 'chart.key.position': 'graph', 'chart.key.shadow': false, 'chart.key.shadow.color': '#666', 'chart.key.shadow.blur': 3, 'chart.key.shadow.offsetx': 2, 'chart.key.shadow.offsety': 2, 'chart.key.position.gutter.boxed': true, 'chart.key.position.x': null, 'chart.key.position.y': null, 'chart.key.halign': 'right', 'chart.key.color.shape': 'square', 'chart.key.rounded': true, 'chart.key.text.size': 10, } } /** * A peudo setter * * @param name string The name of the property to set * @param value mixed The value of the property */ RGraph.Odometer.prototype.Set = function (name, value) { if (name == 'chart.needle.style') { alert('[RGRAPH] The RGraph property chart.needle.style has changed to chart.needle.color'); } if (name == 'chart.needle.thickness') { name = 'chart.needle.width'; } if (name == 'chart.value') { this.value = value; return; } this.properties[name.toLowerCase()] = value; } /** * A getter * * @param name string The name of the property to get */ RGraph.Odometer.prototype.Get = function (name) { if (name == 'chart.value') { return this.value; } return this.properties[name.toLowerCase()]; } /** * Draws the odometer */ RGraph.Odometer.prototype.Draw = function () { /** * Fire the onbeforedraw event */ RGraph.FireCustomEvent(this, 'onbeforedraw'); /** * Clear all of this canvases event handlers (the ones installed by RGraph) */ RGraph.ClearEventListeners(this.id); /** * Set the current value */ this.currentValue = this.value; /** * No longer allow values outside the range of the Odo */ if (this.value > this.end) { this.value = this.end; } if (this.value < this.start) { this.value = this.start; } /** * This is new in May 2011 and facilitates indiviual gutter settings, * eg chart.gutter.left */ this.gutterLeft = this.Get('chart.gutter.left'); this.gutterRight = this.Get('chart.gutter.right'); this.gutterTop = this.Get('chart.gutter.top'); this.gutterBottom = this.Get('chart.gutter.bottom'); // Work out a few things this.radius = Math.min((RGraph.GetWidth(this) - this.gutterLeft - this.gutterRight) / 2, (RGraph.GetHeight(this) - this.gutterTop - this.gutterBottom) / 2) - (this.Get('chart.border') ? 25 : 0); this.diameter = 2 * this.radius; this.centerx = this.canvas.width / 2; this.centery = this.canvas.height / 2; this.range = this.end - this.start; if (typeof(this.Get('chart.radius')) == 'number') { this.radius = this.Get('chart.radius'); } /** * Move the centerx if the key is defined */ if (this.Get('chart.key').length > 0 && this.canvas.width > this.canvas.height) { this.centerx = 5 + this.radius; } this.context.lineWidth = this.Get('chart.linewidth'); // Draw the background this.DrawBackground(); // And lastly, draw the labels this.DrawLabels(); // Draw the needle this.DrawNeedle(this.value, this.Get('chart.needle.color')); /** * Draw any extra needles */ if (this.Get('chart.needle.extra').length > 0) { for (var i=0; i 0) { // Build a colors array out of the needle colors var colors = [this.Get('chart.needle.color')]; if (this.Get('chart.needle.extra').length > 0) { for (var i=0; i