RGraph.drawing.yaxis.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. // version: 2014-06-26
  2. /**
  3. * o--------------------------------------------------------------------------------o
  4. * | This file is part of the RGraph package. RGraph is Free Software, licensed |
  5. * | under the MIT license - so it's free to use for all purposes. If you want to |
  6. * | donate to help keep the project going then you can do so here: |
  7. * | |
  8. * | http://www.rgraph.net/donate |
  9. * o--------------------------------------------------------------------------------o
  10. */
  11. /**
  12. * Having this here means that the RGraph libraries can be included in any order, instead of you having
  13. * to include the common core library first.
  14. */
  15. // Define the RGraph global variable
  16. RGraph = window.RGraph || {isRGraph: true};
  17. RGraph.Drawing = RGraph.Drawing || {};
  18. /**
  19. * The constructor. This function sets up the object. It takes the ID (the HTML attribute) of the canvas as the
  20. * first argument and the X coordinate of the axis as the second
  21. *
  22. * @param string id The canvas tag ID
  23. * @param number x The X coordinate of the Y axis
  24. */
  25. RGraph.Drawing.YAxis = function (id, x)
  26. {
  27. var tmp = RGraph.getCanvasTag(id);
  28. // Get the canvas and context objects
  29. this.id = tmp[0];
  30. this.canvas = tmp[1];
  31. this.context = this.canvas.getContext ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null;
  32. this.canvas.__object__ = this;
  33. this.x = x;
  34. this.coords = [];
  35. this.coordsText = [];
  36. this.original_colors = [];
  37. this.maxLabelLength = 0;
  38. this.firstDraw = true; // After the first draw this will be false
  39. /**
  40. * This defines the type of this shape
  41. */
  42. this.type = 'drawing.yaxis';
  43. /**
  44. * This facilitates easy object identification, and should always be true
  45. */
  46. this.isRGraph = true;
  47. /**
  48. * This adds a uid to the object that you can use for identification purposes
  49. */
  50. this.uid = RGraph.CreateUID();
  51. /**
  52. * This adds a UID to the canvas for identification purposes
  53. */
  54. this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
  55. /**
  56. * This does a few things, for example adding the .fillText() method to the canvas 2D context when
  57. * it doesn't exist. This facilitates the graphs to be still shown in older browser (though without
  58. * text obviously). You'll find the function in RGraph.common.core.js
  59. */
  60. //RGraph.OldBrowserCompat(this.context);
  61. /**
  62. * Some example background properties
  63. */
  64. this.properties =
  65. {
  66. 'chart.gutter.top': 25,
  67. 'chart.gutter.bottom': 25,
  68. 'chart.min': 0,
  69. 'chart.max': null,
  70. 'chart.colors': ['black'],
  71. 'chart.title': '',
  72. 'chart.title.color': null,
  73. 'chart.text.color': null,
  74. 'chart.numticks': 5,
  75. 'chart.numlabels': 5,
  76. 'chart.labels.specific': null,
  77. 'chart.text.font': 'Arial',
  78. 'chart.text.size': 10,
  79. 'chart.align': 'left',
  80. 'hart.scale.formatter': null,
  81. 'chart.scale.point': '.',
  82. 'chart.scale.decimals': 0,
  83. 'chart.scale.invert': false,
  84. 'chart.scale.zerostart': true,
  85. 'chart.scale.visible': true,
  86. 'chart.units.pre': '',
  87. 'chart.units.post': '',
  88. 'chart.linewidth': 1,
  89. 'chart.noendtick.top': false,
  90. 'chart.noendtick.bottom': false,
  91. 'chart.noyaxis': false,
  92. 'chart.tooltips': null,
  93. 'chart.tooltips.effect': 'fade',
  94. 'chart.tooltips.css.class':'RGraph_tooltip',
  95. 'chart.tooltips.event': 'onclick',
  96. 'chart.xaxispos': 'bottom',
  97. 'chart.events.click': null,
  98. 'chart.events.mousemove': null
  99. }
  100. /**
  101. * A simple check that the browser has canvas support
  102. */
  103. if (!this.canvas) {
  104. alert('[DRAWING.YAXIS] No canvas support');
  105. return;
  106. }
  107. /**
  108. * Create the dollar object so that functions can be added to them
  109. */
  110. this.$0 = {};
  111. /**
  112. * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
  113. * done already
  114. *
  115. * ** Could use setTransform() here instead ?
  116. */
  117. if (!this.canvas.__rgraph_aa_translated__) {
  118. this.context.translate(0.5,0.5);
  119. this.canvas.__rgraph_aa_translated__ = true;
  120. }
  121. // Short variable names
  122. var RG = RGraph;
  123. var ca = this.canvas;
  124. var co = this.context;
  125. var prop = this.properties;
  126. var jq = jQuery;
  127. var pa = RG.Path;
  128. var win = window;
  129. var doc = document;
  130. var ma = Math;
  131. /**
  132. * "Decorate" the object with the generic effects if the effects library has been included
  133. */
  134. if (RG.Effects && typeof RG.Effects.decorate === 'function') {
  135. RG.Effects.decorate(this);
  136. }
  137. /**
  138. * A setter method for setting graph properties. It can be used like this: obj.Set('chart.strokestyle', '#666');
  139. *
  140. * @param name string The name of the property to set
  141. * @param value mixed The value of the property
  142. */
  143. this.set =
  144. this.Set = function (name, value)
  145. {
  146. name = name.toLowerCase();
  147. /**
  148. * This should be done first - prepend the property name with "chart." if necessary
  149. */
  150. if (name.substr(0,6) != 'chart.') {
  151. name = 'chart.' + name;
  152. }
  153. prop[name] = value;
  154. return this;
  155. };
  156. /**
  157. * A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
  158. *
  159. * @param name string The name of the property to get
  160. */
  161. this.get =
  162. this.Get = function (name)
  163. {
  164. /**
  165. * This should be done first - prepend the property name with "chart." if necessary
  166. */
  167. if (name.substr(0,6) != 'chart.') {
  168. name = 'chart.' + name;
  169. }
  170. return prop[name.toLowerCase()];
  171. };
  172. /**
  173. * Draws the axes
  174. */
  175. this.draw =
  176. this.Draw = function ()
  177. {
  178. /**
  179. * Fire the onbeforedraw event
  180. */
  181. RG.FireCustomEvent(this, 'onbeforedraw');
  182. /**
  183. * Some defaults
  184. */
  185. this.gutterTop = prop['chart.gutter.top'];
  186. this.gutterBottom = prop['chart.gutter.bottom'];
  187. /**
  188. * Stop this growing uncntrollably
  189. */
  190. this.coordsText = [];
  191. if (!prop['chart.text.color']) prop['chart.text.color'] = prop['chart.colors'][0];
  192. if (!prop['chart.title.color']) prop['chart.title.color'] = prop['chart.colors'][0];
  193. /**
  194. * Parse the colors. This allows for simple gradient syntax
  195. */
  196. if (!this.colorsParsed) {
  197. this.parseColors();
  198. // Don't want to do this again
  199. this.colorsParsed = true;
  200. }
  201. // DRAW Y AXIS HERE
  202. this.DrawYAxis();
  203. /**
  204. * This installs the event listeners
  205. */
  206. RG.InstallEventListeners(this);
  207. /**
  208. * Fire the onfirstdraw event
  209. */
  210. if (this.firstDraw) {
  211. RG.fireCustomEvent(this, 'onfirstdraw');
  212. this.firstDrawFunc();
  213. this.firstDraw = false;
  214. }
  215. /**
  216. * Fire the ondraw event
  217. */
  218. RG.FireCustomEvent(this, 'ondraw');
  219. return this;
  220. };
  221. /**
  222. * The getObjectByXY() worker method
  223. */
  224. this.getObjectByXY = function (e)
  225. {
  226. if (this.getShape(e)) {
  227. return this;
  228. }
  229. };
  230. /**
  231. * Not used by the class during creating the axis, but is used by event handlers
  232. * to get the coordinates (if any) of the selected shape
  233. *
  234. * @param object e The event object
  235. */
  236. this.getShape = function (e)
  237. {
  238. var mouseXY = RG.getMouseXY(e);
  239. var mouseX = mouseXY[0];
  240. var mouseY = mouseXY[1];
  241. if ( mouseX >= this.x - (prop['chart.align'] == 'right' ? 0 : this.getWidth())
  242. && mouseX <= this.x + (prop['chart.align'] == 'right' ? this.getWidth() : 0)
  243. && mouseY >= this.gutterTop
  244. && mouseY <= (ca.height - this.gutterBottom)
  245. ) {
  246. var x = this.x;
  247. var y = this.gutterTop;
  248. var w = 15;;
  249. var h = ca.height - this.gutterTop - this.gutterBottom;
  250. return {
  251. 0: this, 1: x, 2: y, 3: w, 4: h, 5: 0,
  252. 'object': this, 'x': x, 'y': y, 'width': w, 'height': h, 'index': 0, 'tooltip': prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
  253. };
  254. }
  255. return null;
  256. };
  257. /**
  258. * This function positions a tooltip when it is displayed
  259. *
  260. * @param obj object The chart object
  261. * @param int x The X coordinate specified for the tooltip
  262. * @param int y The Y coordinate specified for the tooltip
  263. * @param objec tooltip The tooltips DIV element
  264. */
  265. this.positionTooltip = function (obj, x, y, tooltip, idx)
  266. {
  267. // If there's multiple charts on the canvas they leave unknown font settings
  268. co.font = prop['chart.text.size'] + ' ' + prop['chart.text.font'];
  269. var coordW = co.measureText(prop['chart.max'].toFixed(prop['chart.scale.decimals'])).width;
  270. var coordX = obj.x - coordW;
  271. var coordY = obj.gutterTop;
  272. var coordH = ca.height - obj.gutterTop - obj.gutterBottom;
  273. var canvasXY = RG.getCanvasXY(ca);
  274. var width = tooltip.offsetWidth;
  275. var height = tooltip.offsetHeight;
  276. // Set the top position
  277. tooltip.style.left = 0;
  278. tooltip.style.top = canvasXY[1] + ((ca.height - this.gutterTop - this.gutterBottom) / 2) + 'px';
  279. // By default any overflow is hidden
  280. tooltip.style.overflow = '';
  281. // The arrow
  282. var img = new Image();
  283. img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC';
  284. img.style.position = 'absolute';
  285. img.id = '__rgraph_tooltip_pointer__';
  286. img.style.top = (tooltip.offsetHeight - 2) + 'px';
  287. tooltip.appendChild(img);
  288. // Reposition the tooltip if at the edges:
  289. // LEFT edge
  290. if ((canvasXY[0] + coordX + (coordW / 2) - (width / 2)) < 10) {
  291. tooltip.style.left = prop['chart.align'] == 'right' ? canvasXY[0] + obj.x - (width * 0.1) + (coordW / 2) + 'px'
  292. : (canvasXY[0] + coordX - (width * 0.1)) + (coordW / 2) + 'px';
  293. img.style.left = (width * 0.1) - 8.5 + 'px';
  294. // RIGHT edge
  295. } else if ((canvasXY[0] + coordX + (width / 2)) > document.body.offsetWidth) {
  296. tooltip.style.left = prop['chart.align'] == 'right' ? canvasXY[0] + obj.x - (width * 0.9) + (coordW / 2) + 'px'
  297. : canvasXY[0] + coordX - (width * 0.9) + (coordW / 2) + 'px';
  298. img.style.left = ((width * 0.9) - 8.5) + 'px';
  299. // Default positioning - CENTERED
  300. } else {
  301. tooltip.style.left = prop['chart.align'] == 'right' ? canvasXY[0] + obj.x - (width / 2) + (coordW / 2) + 'px'
  302. : canvasXY[0] + obj.x - (width / 2) - (coordW / 2) + 'px';
  303. img.style.left = ((width * 0.5) - 8.5) + 'px';
  304. }
  305. };
  306. /**
  307. * Each object type has its own Highlight() function which highlights the appropriate shape
  308. *
  309. * @param object shape The shape to highlight
  310. */
  311. this.highlight =
  312. this.Highlight = function (shape)
  313. {
  314. // When showing tooltips, this method can be used to highlight the X axis
  315. };
  316. /**
  317. * This allows for easy specification of gradients
  318. */
  319. this.parseColors = function ()
  320. {
  321. // Save the original colors so that they can be restored when the canvas is reset
  322. if (this.original_colors.length === 0) {
  323. this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors']);
  324. }
  325. /**
  326. * Parse various properties for colors
  327. */
  328. //prop['chart.title.color'] = this.parseSingleColorForGradient(prop['chart.title.color']);
  329. //prop['chart.text.color'] = this.parseSingleColorForGradient(prop['chart.text.color']);
  330. prop['chart.colors'][0] = this.parseSingleColorForGradient(prop['chart.colors'][0]);
  331. };
  332. /**
  333. * This parses a single color value
  334. */
  335. this.parseSingleColorForGradient = function (color)
  336. {
  337. if (!color) {
  338. return color;
  339. }
  340. if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
  341. var parts = RegExp.$1.split(':');
  342. // Create the gradient
  343. var grad = co.createLinearGradient(0,prop['chart.gutter.top'],0,ca.height - this.gutterBottom);
  344. var diff = 1 / (parts.length - 1);
  345. grad.addColorStop(0, RG.trim(parts[0]));
  346. for (var j=1; j<parts.length; ++j) {
  347. grad.addColorStop(j * diff, RG.trim(parts[j]));
  348. }
  349. }
  350. return grad ? grad : color;
  351. };
  352. /**
  353. * The function that draws the Y axis
  354. */
  355. this.drawYAxis =
  356. this.DrawYAxis = function ()
  357. {
  358. /**
  359. * Allow both axis.xxx and chart.xxx to prevent any confusion that may arise
  360. */
  361. for (i in prop) {
  362. if (typeof(i) == 'string') {
  363. var key = i.replace(/^chart\./, 'axis.');
  364. prop[key] = prop[i];
  365. }
  366. }
  367. var x = this.x;
  368. var y = this.gutterTop;
  369. var height = ca.height - this.gutterBottom - this.gutterTop;
  370. var min = prop['chart.min'] ? prop['chart.min'] : 0;
  371. var max = prop['chart.max'];
  372. var title = prop['chart.title'] ? prop['chart.title'] : '';
  373. var color = prop['chart.colors'] ? prop['chart.colors'][0] : 'black';
  374. var title_color = prop['chart.title.color'] ? prop['chart.title.color'] : color;
  375. var label_color = prop['chart.text.color'] ? prop['chart.text.color'] : color;
  376. var numticks = typeof(prop['chart.numticks']) == 'number' ? prop['chart.numticks'] : 10;
  377. var labels_specific = prop['chart.labels.specific'];
  378. var numlabels = prop['chart.numlabels'] ? prop['chart.numlabels'] : 5;
  379. var font = prop['chart.text.font'] ? prop['chart.text.font'] : 'Arial';
  380. var size = prop['chart.text.size'] ? prop['chart.text.size'] : 10;
  381. var align = typeof(prop['chart.align']) == 'string'? prop['chart.align'] : 'left';
  382. var formatter = prop['chart.scale.formatter'];
  383. var decimals = prop['chart.scale.decimals'];
  384. var invert = prop['chart.scale.invert'];
  385. var scale_visible = prop['chart.scale.visible'];
  386. var units_pre = prop['chart.units.pre'];
  387. var units_post = prop['chart.units.post'];
  388. var linewidth = prop['chart.linewidth'] ? prop['chart.linewidth'] : 1;
  389. var notopendtick = prop['chart.noendtick.top'];
  390. var nobottomendtick = prop['chart.noendtick.bottom'];
  391. var noyaxis = prop['chart.noyaxis'];
  392. var xaxispos = prop['chart.xaxispos'];
  393. // This fixes missing corner pixels in Chrome
  394. co.lineWidth = linewidth + 0.001;
  395. /**
  396. * Set the color
  397. */
  398. co.strokeStyle = color;
  399. if (!noyaxis) {
  400. /**
  401. * Draw the main vertical line
  402. */
  403. pa(co,['b','m',Math.round(x), y,'l',Math.round(x), y + height,'s',color]);
  404. /**
  405. * Draw the axes tickmarks
  406. */
  407. if (numticks) {
  408. var gap = (xaxispos == 'center' ? height / 2 : height) / numticks;
  409. var halfheight = height / 2;
  410. co.beginPath();
  411. for (var i=(notopendtick ? 1 : 0); i<=(numticks - (nobottomendtick || xaxispos == 'center'? 1 : 0)); ++i) {
  412. pa(co, ['m',align == 'right' ? x + 3 : x - 3, Math.round(y + (gap *i)),'l',x, Math.round(y + (gap *i))]);
  413. }
  414. // Draw the bottom halves ticks if the X axis is in the center
  415. if (xaxispos == 'center') {
  416. for (var i=1; i<=numticks; ++i) {
  417. pa(co, ['m',align == 'right' ? x + 3 : x - 3, Math.round(y + halfheight + (gap *i)),'l',x, Math.round(y + halfheight + (gap *i))]);
  418. }
  419. }
  420. co.stroke();
  421. }
  422. }
  423. /**
  424. * Draw the scale for the axes
  425. */
  426. co.fillStyle = label_color;
  427. //co.beginPath();
  428. var text_len = 0;
  429. if (scale_visible) {
  430. if (labels_specific && labels_specific.length) {
  431. var text_len = 0;
  432. // First - gp through the labels to find the longest
  433. for (var i=0,len=labels_specific.length; i<len; i+=1) {
  434. text_len = Math.max(text_len, co.measureText(labels_specific[i]).width);
  435. }
  436. for (var i=0,len=labels_specific.length; i<len; ++i) {
  437. var gap = (len-1) > 0 ? (height / (len-1)) : 0;
  438. if (xaxispos == 'center') {
  439. gap /= 2;
  440. }
  441. RG.Text2(this, {'font':font,
  442. 'size':size,
  443. 'x':x - (align == 'right' ? -5 : 5),
  444. 'y':(i * gap) + this.gutterTop,
  445. 'text':labels_specific[i],
  446. 'valign':'center',
  447. 'halign':align == 'right' ? 'left' : 'right',
  448. 'tag': 'scale'
  449. });
  450. /**
  451. * Store the max length so that it can be used if necessary to determine
  452. * whether the mouse is over the axis.
  453. */
  454. this.maxLabelLength = ma.max(this.maxLabelLength, co.measureText(labels_specific[i]).width);
  455. }
  456. if (xaxispos == 'center') {
  457. // It's "-2" so that the center label isn't added twice
  458. for (var i=(labels_specific.length-2); i>=0; --i) {
  459. RG.Text2(this, {'font':font,
  460. 'size':size,
  461. 'x':x - (align == 'right' ? -5 : 5),
  462. 'y':ca.height - this.gutterBottom - (i * gap),
  463. 'text':labels_specific[i],
  464. 'valign':'center',
  465. 'halign':align == 'right' ? 'left' : 'right',
  466. 'tag': 'scale'
  467. });
  468. }
  469. }
  470. } else {
  471. for (var i=0; i<=numlabels; ++i) {
  472. var original = ((max - min) * ((numlabels-i) / numlabels)) + min;
  473. if (original == 0 && prop['chart.scale.zerostart'] == false) {
  474. continue;
  475. }
  476. var text = RG.number_format(this, original.toFixed(decimals), units_pre, units_post);
  477. var text = String(typeof(formatter) == 'function' ? formatter(this, original) : text);
  478. // text_len is used below for positioning the title
  479. var text_len = Math.max(text_len, co.measureText(text).width);
  480. this.maxLabelLength = text_len;
  481. if (invert) {
  482. var y = height - ((height / numlabels)*i);
  483. } else {
  484. var y = (height / numlabels)*i;
  485. }
  486. if (prop['chart.xaxispos'] == 'center') {
  487. y = y / 2;
  488. }
  489. // This fixes a bug, Replace this: -,400 with this: -400
  490. text = text.replace(/^-,([0-9])/, '-$1');
  491. /**
  492. * Now - draw the labels
  493. */
  494. RG.Text2(this, {'font':font,
  495. 'size':size,
  496. 'x':x - (align == 'right' ? -5 : 5),
  497. 'y':y + this.gutterTop,
  498. 'text':text,
  499. 'valign':'center',
  500. 'halign':align == 'right' ? 'left' : 'right',
  501. 'tag': 'scale'
  502. });
  503. /**
  504. * Draw the bottom half of the labels if the X axis is in the center
  505. */
  506. if (prop['chart.xaxispos'] == 'center' && i < numlabels) {
  507. RG.Text2(this, {'font':font,
  508. 'size':size,
  509. 'x':x - (align == 'right' ? -5 : 5),
  510. 'y':ca.height - this.gutterBottom - y,
  511. 'text':'-' + text,
  512. 'valign':'center',
  513. 'halign':align == 'right' ? 'left' : 'right',
  514. 'tag': 'scale'
  515. });
  516. }
  517. }
  518. }
  519. }
  520. //co.stroke();
  521. /**
  522. * Draw the title for the axes
  523. */
  524. if (title) {
  525. co.beginPath();
  526. co.fillStyle = title_color;
  527. if (labels_specific) {
  528. var width = 0;
  529. for (var i=0,len=labels_specific.length; i<len; i+=1) {
  530. width = Math.max(width, co.measureText(labels_specific[i]).width);
  531. }
  532. } else {
  533. var width = co.measureText(prop['chart.units.pre'] + prop['chart.max'].toFixed(prop['chart.scale.decimals']) + prop['chart.units.post']).width;
  534. }
  535. RG.Text2(this, {'font':font,
  536. 'size':size + 2,
  537. 'x':align == 'right' ? x + width + 8 : x - width - 8,
  538. 'y':height / 2 + this.gutterTop,
  539. 'text':title,
  540. 'valign':'bottom',
  541. 'halign':'center',
  542. 'angle':align == 'right' ? 90 : -90});
  543. co.stroke();
  544. }
  545. };
  546. /**
  547. * This detemines the maximum text width of either the scale or text
  548. * labels - whichever is given
  549. *
  550. * @return number The maximum text width
  551. */
  552. this.getWidth = function ()
  553. {
  554. var width = this.maxLabelLength;
  555. // Add the title width if it's specified
  556. if (prop['chart.title'] && prop['chart.title'].length) {
  557. width += (prop['chart.text.size'] * 1.5);
  558. }
  559. this.width = width;
  560. return width;
  561. };
  562. /**
  563. * Using a function to add events makes it easier to facilitate method chaining
  564. *
  565. * @param string type The type of even to add
  566. * @param function func
  567. */
  568. this.on = function (type, func)
  569. {
  570. if (type.substr(0,2) !== 'on') {
  571. type = 'on' + type;
  572. }
  573. this[type] = func;
  574. return this;
  575. };
  576. /**
  577. * This function runs once only
  578. * (put at the end of the file (before any effects))
  579. */
  580. this.firstDrawFunc = function ()
  581. {
  582. };
  583. /**
  584. * Objects are now always registered so that the chart is redrawn if need be.
  585. */
  586. RG.Register(this);
  587. };