RGraph.hbar.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. /**
  2. * o------------------------------------------------------------------------------o
  3. * | This file is part of the RGraph package - you can learn more at: |
  4. * | |
  5. * | http://www.rgraph.net |
  6. * | |
  7. * | This package is licensed under the RGraph license. For all kinds of business |
  8. * | purposes there is a small one-time licensing fee to pay and for non |
  9. * | commercial purposes it is free to use. You can read the full license here: |
  10. * | |
  11. * | http://www.rgraph.net/license |
  12. * o------------------------------------------------------------------------------o
  13. */
  14. if (typeof(RGraph) == 'undefined') RGraph = {};
  15. /**
  16. * The horizontal bar chart constructor. The horizontal bar is a minor variant
  17. * on the bar chart. If you have big labels, this may be useful as there is usually
  18. * more space available for them.
  19. *
  20. * @param object canvas The canvas object
  21. * @param array data The chart data
  22. */
  23. RGraph.HBar = function (id, data)
  24. {
  25. // Get the canvas and context objects
  26. this.id = id;
  27. this.canvas = document.getElementById(typeof id === 'object' ? id.id : id);
  28. this.context = this.canvas.getContext ? this.canvas.getContext("2d") : null;
  29. this.canvas.__object__ = this;
  30. this.data = data;
  31. this.type = 'hbar';
  32. this.isRGraph = true;
  33. this.uid = RGraph.CreateUID();
  34. this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
  35. this.colorsParsed = false;
  36. this.coords = [];
  37. this.coords2 = [];
  38. this.coordsText = [];
  39. /**
  40. * Compatibility with older browsers
  41. */
  42. RGraph.OldBrowserCompat(this.context);
  43. this.max = 0;
  44. this.stackedOrGrouped = false;
  45. // Default properties
  46. this.properties = {
  47. 'chart.gutter.left': 75,
  48. 'chart.gutter.right': 25,
  49. 'chart.gutter.top': 25,
  50. 'chart.gutter.bottom': 25,
  51. 'chart.background.grid': true,
  52. 'chart.background.grid.color': '#ddd',
  53. 'chart.background.grid.width': 1,
  54. 'chart.background.grid.hsize': 25,
  55. 'chart.background.grid.vsize': 25,
  56. 'chart.background.barcolor1': 'rgba(0,0,0,0)',
  57. 'chart.background.barcolor2': 'rgba(0,0,0,0)',
  58. 'chart.background.grid.hlines': true,
  59. 'chart.background.grid.vlines': true,
  60. 'chart.background.grid.border': true,
  61. 'chart.background.grid.autofit':true,
  62. 'chart.background.grid.autofit.numhlines': 14,
  63. 'chart.background.grid.autofit.numvlines': 20,
  64. 'chart.background.grid.dashed': false,
  65. 'chart.background.grid.dotted': false,
  66. 'chart.linewidth': 1,
  67. 'chart.title': '',
  68. 'chart.title.background': null,
  69. 'chart.title.xaxis': '',
  70. 'chart.title.xaxis.bold': true,
  71. 'chart.title.xaxis.size': null,
  72. 'chart.title.xaxis.font': null,
  73. 'chart.title.yaxis': '',
  74. 'chart.title.yaxis.bold': true,
  75. 'chart.title.yaxis.size': null,
  76. 'chart.title.yaxis.font': null,
  77. 'chart.title.yaxis.color': null,
  78. 'chart.title.xaxis.pos': null,
  79. 'chart.title.yaxis.pos': 0.8,
  80. 'chart.title.yaxis.x': null,
  81. 'chart.title.yaxis.y': null,
  82. 'chart.title.xaxis.x': null,
  83. 'chart.title.xaxis.y': null,
  84. 'chart.title.hpos': null,
  85. 'chart.title.vpos': null,
  86. 'chart.title.bold': true,
  87. 'chart.title.font': null,
  88. 'chart.title.x': null,
  89. 'chart.title.y': null,
  90. 'chart.title.halign': null,
  91. 'chart.title.valign': null,
  92. 'chart.text.size': 10,
  93. 'chart.text.color': 'black',
  94. 'chart.text.font': 'Arial',
  95. 'chart.colors': ['Gradient(white:red)', 'Gradient(white:blue)', 'Gradient(white:green)', 'Gradient(white:pink)', 'Gradient(white:yellow)', 'Gradient(white:cyan)', 'Gradient(white:navy)', 'Gradient(white:gray)', 'Gradient(white:black)'],
  96. 'chart.colors.sequential': false,
  97. 'chart.xlabels.specific': null,
  98. 'chart.labels': [],
  99. 'chart.labels.above': false,
  100. 'chart.labels.above.decimals': 0,
  101. 'chart.labels.above.specific': null,
  102. 'chart.xlabels': true,
  103. 'chart.xlabels.count': 5,
  104. 'chart.contextmenu': null,
  105. 'chart.key': null,
  106. 'chart.key.background': 'white',
  107. 'chart.key.position': 'graph',
  108. 'chart.key.halign': 'right',
  109. 'chart.key.shadow': false,
  110. 'chart.key.shadow.color': '#666',
  111. 'chart.key.shadow.blur': 3,
  112. 'chart.key.shadow.offsetx': 2,
  113. 'chart.key.shadow.offsety': 2,
  114. 'chart.key.position.gutter.boxed': false,
  115. 'chart.key.position.x': null,
  116. 'chart.key.position.y': null,
  117. 'chart.key.color.shape': 'square',
  118. 'chart.key.rounded': true,
  119. 'chart.key.linewidth': 1,
  120. 'chart.key.colors': null,
  121. 'chart.key.interactive': false,
  122. 'chart.key.interactive.highlight.chart.stroke': 'black',
  123. 'chart.key.interactive.highlight.chart.fill':'rgba(255,255,255,0.7)',
  124. 'chart.key.interactive.highlight.label':'rgba(255,0,0,0.2)',
  125. 'chart.key.text.color': 'black',
  126. 'chart.units.pre': '',
  127. 'chart.units.post': '',
  128. 'chart.units.ingraph': false,
  129. 'chart.strokestyle': 'rgba(0,0,0,0)',
  130. 'chart.xmin': 0,
  131. 'chart.xmax': 0,
  132. 'chart.axis.color': 'black',
  133. 'chart.shadow': false,
  134. 'chart.shadow.color': '#666',
  135. 'chart.shadow.blur': 3,
  136. 'chart.shadow.offsetx': 3,
  137. 'chart.shadow.offsety': 3,
  138. 'chart.vmargin': 2,
  139. 'chart.vmargin.grouped': 2,
  140. 'chart.grouping': 'grouped',
  141. 'chart.tooltips': null,
  142. 'chart.tooltips.event': 'onclick',
  143. 'chart.tooltips.effect': 'fade',
  144. 'chart.tooltips.css.class': 'RGraph_tooltip',
  145. 'chart.tooltips.highlight': true,
  146. 'chart.highlight.fill': 'rgba(255,255,255,0.7)',
  147. 'chart.highlight.stroke': 'rgba(0,0,0,0)',
  148. 'chart.annotatable': false,
  149. 'chart.annotate.color': 'black',
  150. 'chart.zoom.factor': 1.5,
  151. 'chart.zoom.fade.in': true,
  152. 'chart.zoom.fade.out': true,
  153. 'chart.zoom.hdir': 'right',
  154. 'chart.zoom.vdir': 'down',
  155. 'chart.zoom.frames': 25,
  156. 'chart.zoom.delay': 16.666,
  157. 'chart.zoom.shadow': true,
  158. 'chart.zoom.background': true,
  159. 'chart.zoom.action': 'zoom',
  160. 'chart.resizable': false,
  161. 'chart.resize.handle.adjust': [0,0],
  162. 'chart.resize.handle.background': null,
  163. 'chart.scale.point': '.',
  164. 'chart.scale.thousand': ',',
  165. 'chart.scale.decimals': null,
  166. 'chart.noredraw': false,
  167. 'chart.events.click': null,
  168. 'chart.events.mousemove': null,
  169. 'chart.noxaxis': false,
  170. 'chart.noyaxis': false,
  171. 'chart.noaxes': false,
  172. 'chart.noxtickmarks': false,
  173. 'chart.noytickmarks': false,
  174. 'chart.numyticks': data.length,
  175. 'chart.numxticks': 10
  176. }
  177. // Check for support
  178. if (!this.canvas) {
  179. alert('[HBAR] No canvas support');
  180. return;
  181. }
  182. for (i=0; i<this.data.length; ++i) {
  183. if (typeof(this.data[i]) == 'object') {
  184. this.stackedOrGrouped = true;
  185. }
  186. }
  187. /**
  188. * Create the dollar objects so that functions can be added to them
  189. */
  190. var linear_data = RGraph.array_linearize(data);
  191. for (var i=0; i<linear_data.length; ++i) {
  192. this['$' + i] = {};
  193. }
  194. /**
  195. * Create the linear data array
  196. */
  197. this.data_arr = RGraph.array_linearize(this.data);
  198. /**
  199. * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
  200. * done already
  201. */
  202. if (!this.canvas.__rgraph_aa_translated__) {
  203. this.context.translate(0.5,0.5);
  204. this.canvas.__rgraph_aa_translated__ = true;
  205. }
  206. ///////////////////////////////// SHORT PROPERTIES /////////////////////////////////
  207. var RG = RGraph;
  208. var ca = this.canvas;
  209. var co = ca.getContext('2d');
  210. var prop = this.properties;
  211. //////////////////////////////////// METHODS ///////////////////////////////////////
  212. /**
  213. * A setter
  214. *
  215. * @param name string The name of the property to set
  216. * @param value mixed The value of the property
  217. */
  218. this.Set = function (name, value)
  219. {
  220. name = name.toLowerCase();
  221. /**
  222. * This should be done first - prepend the propertyy name with "chart." if necessary
  223. */
  224. if (name.substr(0,6) != 'chart.') {
  225. name = 'chart.' + name;
  226. }
  227. if (name == 'chart.labels.abovebar') {
  228. name = 'chart.labels.above';
  229. }
  230. prop[name] = value;
  231. return this;
  232. }
  233. /**
  234. * A getter
  235. *
  236. * @param name string The name of the property to get
  237. */
  238. this.Get = function (name)
  239. {
  240. /**
  241. * This should be done first - prepend the property name with "chart." if necessary
  242. */
  243. if (name.substr(0,6) != 'chart.') {
  244. name = 'chart.' + name;
  245. }
  246. if (name == 'chart.labels.abovebar') {
  247. name = 'chart.labels.above';
  248. }
  249. return prop[name];
  250. }
  251. /**
  252. * The function you call to draw the bar chart
  253. */
  254. this.Draw = function ()
  255. {
  256. /**
  257. * Fire the onbeforedraw event
  258. */
  259. RG.FireCustomEvent(this, 'onbeforedraw');
  260. /**
  261. * Parse the colors. This allows for simple gradient syntax
  262. */
  263. if (!this.colorsParsed) {
  264. this.parseColors();
  265. // Don't want to do this again
  266. this.colorsParsed = true;
  267. }
  268. /**
  269. * This is new in May 2011 and facilitates indiviual gutter settings,
  270. * eg chart.gutter.left
  271. */
  272. this.gutterLeft = prop['chart.gutter.left'];
  273. this.gutterRight = prop['chart.gutter.right'];
  274. this.gutterTop = prop['chart.gutter.top'];
  275. this.gutterBottom = prop['chart.gutter.bottom'];
  276. /**
  277. * Stop the coords array from growing uncontrollably
  278. */
  279. this.coords = [];
  280. this.coords2 = [];
  281. this.max = 0;
  282. /**
  283. * Check for chart.xmin in stacked charts
  284. */
  285. if (prop['chart.xmin'] > 0 && prop['chart.grouping'] == 'stacked') {
  286. alert('[HBAR] Using chart.xmin is not supported with stacked charts, resetting chart.xmin to zero');
  287. this.Set('chart.xmin', 0);
  288. }
  289. /**
  290. * Work out a few things. They need to be here because they depend on things you can change before you
  291. * call Draw() but after you instantiate the object
  292. */
  293. this.graphwidth = ca.width - this.gutterLeft - this.gutterRight;
  294. this.graphheight = ca.height - this.gutterTop - this.gutterBottom;
  295. this.halfgrapharea = this.grapharea / 2;
  296. this.halfTextHeight = prop['chart.text.size'] / 2;
  297. // Progressively Draw the chart
  298. RG.background.Draw(this);
  299. this.Drawbars();
  300. this.DrawAxes();
  301. this.DrawLabels();
  302. // Draw the key if necessary
  303. if (prop['chart.key'] && prop['chart.key'].length) {
  304. RG.DrawKey(this, prop['chart.key'], prop['chart.colors']);
  305. }
  306. /**
  307. * Setup the context menu if required
  308. */
  309. if (prop['chart.contextmenu']) {
  310. RG.ShowContext(this);
  311. }
  312. /**
  313. * Draw "in graph" labels
  314. */
  315. RG.DrawInGraphLabels(this);
  316. /**
  317. * This function enables resizing
  318. */
  319. if (prop['chart.resizable']) {
  320. RG.AllowResizing(this);
  321. }
  322. /**
  323. * This installs the event listeners
  324. */
  325. RG.InstallEventListeners(this);
  326. /**
  327. * Fire the RGraph ondraw event
  328. */
  329. RG.FireCustomEvent(this, 'ondraw');
  330. return this;
  331. }
  332. /**
  333. * This draws the axes
  334. */
  335. this.DrawAxes = function ()
  336. {
  337. var halfway = Math.round((this.graphwidth / 2) + this.gutterLeft);
  338. co.beginPath();
  339. co.lineWidth = prop['chart.axis.linewidth'] ? prop['chart.axis.linewidth'] + 0.001 : 1.001;
  340. co.strokeStyle = prop['chart.axis.color'];
  341. // Draw the Y axis
  342. if (prop['chart.noyaxis'] == false && prop['chart.noaxes'] == false) {
  343. if (prop['chart.yaxispos'] == 'center') {
  344. co.moveTo(halfway, this.gutterTop);
  345. co.lineTo(halfway, ca.height - this.gutterBottom);
  346. } else {
  347. co.moveTo(this.gutterLeft, this.gutterTop);
  348. co.lineTo(this.gutterLeft, ca.height - this.gutterBottom);
  349. }
  350. }
  351. // Draw the X axis
  352. if (prop['chart.noxaxis'] == false && prop['chart.noaxes'] == false) {
  353. co.moveTo(this.gutterLeft +0.001, ca.height - this.gutterBottom + 0.001);
  354. co.lineTo(ca.width - this.gutterRight + 0.001, ca.height - this.gutterBottom + 0.001);
  355. }
  356. // Draw the Y tickmarks
  357. if ( prop['chart.noytickmarks'] == false
  358. && prop['chart.noyaxis'] == false
  359. && prop['chart.numyticks'] > 0
  360. && prop['chart.noaxes'] == false
  361. ) {
  362. var yTickGap = (ca.height - this.gutterTop - this.gutterBottom) / (prop['chart.numyticks'] > 0 ? prop['chart.numyticks'] : this.data.length);
  363. for (y=this.gutterTop; y<(ca.height - this.gutterBottom - 1); y+=yTickGap) {
  364. if (prop['chart.yaxispos'] == 'center') {
  365. co.moveTo(halfway + 3, Math.round(y));
  366. co.lineTo(halfway - 3, Math.round(y));
  367. } else {
  368. co.moveTo(this.gutterLeft, Math.round(y));
  369. co.lineTo( this.gutterLeft - 3, Math.round(y));
  370. }
  371. }
  372. // If the X axis isn't being shown draw the end tick
  373. if (prop['chart.noxaxis'] == true) {
  374. if (prop['chart.yaxispos'] == 'center') {
  375. co.moveTo(halfway + 3, Math.round(y));
  376. co.lineTo(halfway - 3, Math.round(y));
  377. } else {
  378. co.moveTo(this.gutterLeft, Math.round(y));
  379. co.lineTo( this.gutterLeft - 3, Math.round(y));
  380. }
  381. }
  382. }
  383. // Draw the X tickmarks
  384. if ( prop['chart.noxtickmarks'] == false
  385. && prop['chart.noxaxis'] == false
  386. && prop['chart.numxticks'] > 0
  387. && prop['chart.noaxes'] == false) {
  388. xTickGap = (ca.width - this.gutterLeft - this.gutterRight ) / prop['chart.numxticks'];
  389. yStart = ca.height - this.gutterBottom;
  390. yEnd = (ca.height - this.gutterBottom) + 3;
  391. for (x=(ca.width - this.gutterRight), i=0; prop['chart.yaxispos'] == 'center' ? x>=this.gutterLeft : x>this.gutterLeft; x-=xTickGap) {
  392. if (prop['chart.yaxispos'] != 'center' || i != 5) {
  393. co.moveTo(Math.round(x), yStart);
  394. co.lineTo(Math.round(x), yEnd);
  395. }
  396. i++;
  397. }
  398. // If the Y axis isn't being shown draw the end tick
  399. if (prop['chart.noyaxis'] == true) {
  400. co.moveTo(this.gutterLeft, Math.round(yStart));
  401. co.lineTo( this.gutterLeft, Math.round(yEnd));
  402. }
  403. }
  404. co.stroke();
  405. /**
  406. * Reset the linewidth
  407. */
  408. co.lineWidth = 1;
  409. }
  410. /**
  411. * This draws the labels for the graph
  412. */
  413. this.DrawLabels = function ()
  414. {
  415. var units_pre = prop['chart.units.pre'];
  416. var units_post = prop['chart.units.post'];
  417. var text_size = prop['chart.text.size'];
  418. var font = prop['chart.text.font'];
  419. /**
  420. * Set the units to blank if they're to be used for ingraph labels only
  421. */
  422. if (prop['chart.units.ingraph']) {
  423. units_pre = '';
  424. units_post = '';
  425. }
  426. /**
  427. * Draw the X axis labels
  428. */
  429. if (prop['chart.xlabels']) {
  430. /**
  431. * Specific X labels
  432. */
  433. if (RGraph.is_array(prop['chart.xlabels.specific'])) {
  434. if (prop['chart.yaxispos'] == 'center') {
  435. var halfGraphWidth = this.graphwidth / 2;
  436. var labels = prop['chart.xlabels.specific'];
  437. var interval = (this.graphwidth / 2) / (labels.length - 1);
  438. co.fillStyle = prop['chart.text.color'];
  439. for (var i=0; i<labels.length; i+=1) {
  440. RG.Text2(this, {'font':font,
  441. 'size':text_size,
  442. 'x':this.gutterLeft + halfGraphWidth + (interval * i),
  443. 'y':ca.height - this.gutterBottom,
  444. 'text':labels[i],
  445. 'valign':'top',
  446. 'halign':'center',
  447. 'tag': 'scale'});
  448. }
  449. for (var i=(labels.length - 1); i>0; i-=1) {
  450. RG.Text2(this, {'font':font,
  451. 'size':text_size,
  452. 'x':this.gutterLeft + (interval * (labels.length - i - 1)),
  453. 'y':ca.height - this.gutterBottom,
  454. 'text':labels[i],
  455. 'valign':'top',
  456. 'halign':'center',
  457. 'tag': 'scale'});
  458. }
  459. } else {
  460. var labels = prop['chart.xlabels.specific'];
  461. var interval = this.graphwidth / (labels.length - 1);
  462. co.fillStyle = prop['chart.text.color'];
  463. for (var i=0; i<labels.length; i+=1) {
  464. RG.Text2(this, {'font':font,
  465. 'size':text_size,
  466. 'x':this.gutterLeft + (interval * i),
  467. 'y':ca.height - this.gutterBottom,
  468. 'text':labels[i],
  469. 'valign':'top',
  470. 'halign':'center',
  471. 'tag': 'scale'});
  472. }
  473. }
  474. /**
  475. * Draw an X scale
  476. */
  477. } else {
  478. var gap = 7;
  479. co.beginPath();
  480. co.fillStyle = prop['chart.text.color'];
  481. if (prop['chart.yaxispos'] == 'center') {
  482. for (var i=0; i<this.scale2.labels.length; ++i) {
  483. RG.Text2(this, {'font':font,
  484. 'size':text_size,
  485. 'x':this.gutterLeft + (this.graphwidth / 2) - ((this.graphwidth / 2) * ((i+1)/this.scale2.labels.length)),
  486. 'y':this.gutterTop + this.halfTextHeight + this.graphheight + gap,
  487. 'text':this.scale2.labels[i],
  488. 'valign':'center',
  489. 'halign':'center',
  490. 'tag': 'scale'});
  491. }
  492. for (var i=0; i<this.scale2.labels.length; ++i) {
  493. RG.Text2(this, {'font':font,
  494. 'size':text_size,
  495. 'x':this.gutterLeft + ((this.graphwidth / 2) * ((i+1)/this.scale2.labels.length)) + (this.graphwidth / 2),
  496. 'y':this.gutterTop + this.halfTextHeight + this.graphheight + gap,
  497. 'text':this.scale2.labels[i],
  498. 'valign':'center',
  499. 'halign':'center',
  500. 'tag': 'scale'});
  501. }
  502. } else {
  503. for (var i=0; i<this.scale2.labels.length; ++i) {
  504. RG.Text2(this, {'font':font,
  505. 'size':text_size,
  506. 'x':this.gutterLeft + (this.graphwidth * ((i+1)/this.scale2.labels.length)),
  507. 'y':this.gutterTop + this.halfTextHeight + this.graphheight + gap,
  508. 'text':this.scale2.labels[i],
  509. 'valign':'center',
  510. 'halign':'center',
  511. 'tag': 'scale'
  512. });
  513. }
  514. }
  515. /**
  516. * If xmin is not zero - draw that
  517. */
  518. if (prop['chart.xmin'] > 0 || prop['chart.noyaxis'] == true) {
  519. var x = prop['chart.yaxispos'] == 'center' ? this.gutterLeft + (this.graphwidth / 2): this.gutterLeft;
  520. RG.Text2(this, {'font':font,
  521. 'size':text_size,
  522. 'x':x,
  523. 'y':this.gutterTop + this.halfTextHeight + this.graphheight + gap,
  524. 'text':RG.number_format(this, prop['chart.xmin'].toFixed(prop['chart.scale.decimals']), units_pre, units_post),
  525. 'valign':'center',
  526. 'halign':'center',
  527. 'tag': 'scale'
  528. });
  529. }
  530. co.fill();
  531. co.stroke();
  532. }
  533. }
  534. /**
  535. * The Y axis labels
  536. */
  537. if (typeof(prop['chart.labels']) == 'object') {
  538. var xOffset = 5;
  539. var font = prop['chart.text.font'];
  540. // Draw the X axis labels
  541. co.fillStyle = prop['chart.text.color'];
  542. // How wide is each bar
  543. var barHeight = (ca.height - this.gutterTop - this.gutterBottom ) / prop['chart.labels'].length;
  544. // Reset the xTickGap
  545. yTickGap = (ca.height - this.gutterTop - this.gutterBottom) / prop['chart.labels'].length
  546. // Draw the X tickmarks
  547. var i=0;
  548. for (y=this.gutterTop + (yTickGap / 2); y<=ca.height - this.gutterBottom; y+=yTickGap) {
  549. RG.Text2(this, {'font':font,
  550. 'size':prop['chart.text.size'],
  551. 'x':this.gutterLeft - xOffset,
  552. 'y':y,
  553. 'text':String(prop['chart.labels'][i++]),
  554. 'halign':'right',
  555. 'valign':'center',
  556. 'tag': 'labels'
  557. });
  558. }
  559. }
  560. }
  561. /**
  562. * This function draws the bars
  563. */
  564. this.Drawbars = function ()
  565. {
  566. co.lineWidth = prop['chart.linewidth'];
  567. co.strokeStyle = prop['chart.strokestyle'];
  568. co.fillStyle = prop['chart.colors'][0];
  569. var prevX = 0;
  570. var prevY = 0;
  571. /**
  572. * Work out the max value
  573. */
  574. if (prop['chart.xmax']) {
  575. this.scale2 = RG.getScale2(this, {'max':prop['chart.xmax'],
  576. 'min':prop['chart.xmin'],
  577. 'scale.decimals':Number(prop['chart.scale.decimals']),
  578. 'scale.point':prop['chart.scale.point'],
  579. 'scale.thousand':prop['chart.scale.thousand'],
  580. 'scale.round':prop['chart.scale.round'],
  581. 'units.pre':prop['chart.units.pre'],
  582. 'units.post':prop['chart.units.post'],
  583. 'ylabels.count':prop['chart.xlabels.count'],
  584. 'strict':true
  585. });
  586. this.max = this.scale2.max;
  587. } else {
  588. var grouping = prop['chart.grouping'];
  589. for (i=0; i<this.data.length; ++i) {
  590. if (typeof(this.data[i]) == 'object') {
  591. var value = grouping == 'grouped' ? Number(RG.array_max(this.data[i], true)) : Number(RG.array_sum(this.data[i])) ;
  592. } else {
  593. var value = Number(Math.abs(this.data[i]));
  594. }
  595. this.max = Math.max(Math.abs(this.max), Math.abs(value));
  596. }
  597. this.scale2 = RG.getScale2(this, {'max':this.max,
  598. 'min':prop['chart.xmin'],
  599. 'scale.decimals':Number(prop['chart.scale.decimals']),
  600. 'scale.point':prop['chart.scale.point'],
  601. 'scale.thousand':prop['chart.scale.thousand'],
  602. 'scale.round':prop['chart.scale.round'],
  603. 'units.pre':prop['chart.units.pre'],
  604. 'units.post':prop['chart.units.post'],
  605. 'ylabels.count':prop['chart.xlabels.count']
  606. });
  607. this.max = this.scale2.max;
  608. this.min = this.scale2.min;
  609. }
  610. if (prop['chart.scale.decimals'] == null && Number(this.max) == 1) {
  611. this.Set('chart.scale.decimals', 1);
  612. }
  613. /**
  614. * This is here to facilitate sequential colors
  615. */
  616. var colorIdx = 0;
  617. /**
  618. * The bars are drawn HERE
  619. */
  620. var graphwidth = (ca.width - this.gutterLeft - this.gutterRight);
  621. var halfwidth = graphwidth / 2;
  622. for (i=0; i<this.data.length; ++i) {
  623. // Work out the width and height
  624. var width = (this.data[i] / this.max) * graphwidth;
  625. var height = this.graphheight / this.data.length;
  626. var orig_height = height;
  627. var x = this.gutterLeft;
  628. var y = this.gutterTop + (i * height);
  629. var vmargin = prop['chart.vmargin'];
  630. // Account for negative lengths - Some browsers (eg Chrome) don't like a negative value
  631. if (width < 0) {
  632. x -= width;
  633. width = Math.abs(width);
  634. }
  635. /**
  636. * Turn on the shadow if need be
  637. */
  638. if (prop['chart.shadow']) {
  639. co.shadowColor = prop['chart.shadow.color'];
  640. co.shadowBlur = prop['chart.shadow.blur'];
  641. co.shadowOffsetX = prop['chart.shadow.offsetx'];
  642. co.shadowOffsetY = prop['chart.shadow.offsety'];
  643. }
  644. /**
  645. * Draw the bar
  646. */
  647. co.beginPath();
  648. if (typeof(this.data[i]) == 'number') {
  649. var barHeight = height - (2 * vmargin);
  650. var barWidth = ((this.data[i] - prop['chart.xmin']) / (this.max - prop['chart.xmin'])) * this.graphwidth;
  651. var barX = this.gutterLeft;
  652. // Account for Y axis pos
  653. if (prop['chart.yaxispos'] == 'center') {
  654. barWidth /= 2;
  655. barX += halfwidth;
  656. if (this.data[i] < 0) {
  657. barWidth = (Math.abs(this.data[i]) - prop['chart.xmin']) / (this.max - prop['chart.xmin']);
  658. barWidth = barWidth * (this.graphwidth / 2);
  659. barX = ((this.graphwidth / 2) + this.gutterLeft) - barWidth;
  660. }
  661. }
  662. // Set the fill color
  663. co.strokeStyle = prop['chart.strokestyle'];
  664. co.fillStyle = prop['chart.colors'][0];
  665. // Sequential colors
  666. if (prop['chart.colors.sequential']) {
  667. co.fillStyle = prop['chart.colors'][colorIdx++];
  668. }
  669. co.strokeRect(barX, this.gutterTop + (i * height) + prop['chart.vmargin'], barWidth, barHeight);
  670. co.fillRect(barX, this.gutterTop + (i * height) + prop['chart.vmargin'], barWidth, barHeight);
  671. this.coords.push([barX,
  672. y + vmargin,
  673. barWidth,
  674. height - (2 * vmargin),
  675. co.fillStyle,
  676. this.data[i],
  677. true]);
  678. /**
  679. * Stacked bar chart
  680. */
  681. } else if (typeof(this.data[i]) == 'object' && prop['chart.grouping'] == 'stacked') {
  682. if (prop['chart.yaxispos'] == 'center') {
  683. alert('[HBAR] You can\'t have a stacked chart with the Y axis in the center, change it to grouped');
  684. }
  685. var barHeight = height - (2 * vmargin);
  686. if (typeof this.coords2[i] == 'undefined') {
  687. this.coords2[i] = [];
  688. }
  689. for (j=0; j<this.data[i].length; ++j) {
  690. // Set the fill/stroke colors
  691. co.strokeStyle = prop['chart.strokestyle'];
  692. co.fillStyle = prop['chart.colors'][j];
  693. // Sequential colors
  694. if (prop['chart.colors.sequential']) {
  695. co.fillStyle = prop['chart.colors'][colorIdx++];
  696. }
  697. var width = (((this.data[i][j]) / (this.max))) * this.graphwidth;
  698. var totalWidth = (RG.array_sum(this.data[i]) / this.max) * this.graphwidth;
  699. co.strokeRect(x, this.gutterTop + prop['chart.vmargin'] + (this.graphheight / this.data.length) * i, width, height - (2 * vmargin) );
  700. co.fillRect(x, this.gutterTop + prop['chart.vmargin'] + (this.graphheight / this.data.length) * i, width, height - (2 * vmargin) );
  701. /**
  702. * Store the coords for tooltips
  703. */
  704. // The last property of this array is a boolean which tells you whether the value is the last or not
  705. this.coords.push([x,
  706. y + vmargin,
  707. width,
  708. height - (2 * vmargin),
  709. co.fillStyle,
  710. RG.array_sum(this.data[i]),
  711. j == (this.data[i].length - 1)
  712. ]);
  713. this.coords2[i].push([x,
  714. y + vmargin,
  715. width,
  716. height - (2 * vmargin),
  717. co.fillStyle,
  718. RG.array_sum(this.data[i]),
  719. j == (this.data[i].length - 1)
  720. ]);
  721. x += width;
  722. }
  723. /**
  724. * A grouped bar chart
  725. */
  726. } else if (typeof(this.data[i]) == 'object' && prop['chart.grouping'] == 'grouped') {
  727. var vmarginGrouped = prop['chart.vmargin.grouped'];
  728. var individualBarHeight = ((height - (2 * vmargin) - ((this.data[i].length - 1) * vmarginGrouped)) / this.data[i].length)
  729. if (typeof this.coords2[i] == 'undefined') {
  730. this.coords2[i] = [];
  731. }
  732. for (j=0; j<this.data[i].length; ++j) {
  733. /**
  734. * Turn on the shadow if need be
  735. */
  736. if (prop['chart.shadow']) {
  737. RG.SetShadow(this, prop['chart.shadow.color'], prop['chart.shadow.offsetx'], prop['chart.shadow.offsety'], prop['chart.shadow.blur']);
  738. }
  739. // Set the fill/stroke colors
  740. co.strokeStyle = prop['chart.strokestyle'];
  741. co.fillStyle = prop['chart.colors'][j];
  742. // Sequential colors
  743. if (prop['chart.colors.sequential']) {
  744. co.fillStyle = prop['chart.colors'][colorIdx++];
  745. }
  746. var startY = this.gutterTop + (height * i) + (individualBarHeight * j) + vmargin + (vmarginGrouped * j);
  747. var width = ((this.data[i][j] - prop['chart.xmin']) / (this.max - prop['chart.xmin'])) * (ca.width - this.gutterLeft - this.gutterRight );
  748. var startX = this.gutterLeft;
  749. // Account for the Y axis being in the middle
  750. if (prop['chart.yaxispos'] == 'center') {
  751. width /= 2;
  752. startX += halfwidth;
  753. }
  754. if (width < 0) {
  755. startX += width;
  756. width *= -1;
  757. }
  758. co.strokeRect(startX, startY, width, individualBarHeight);
  759. co.fillRect(startX, startY, width, individualBarHeight);
  760. this.coords.push([startX,
  761. startY,
  762. width,
  763. individualBarHeight,
  764. co.fillStyle,
  765. this.data[i][j],
  766. true]);
  767. this.coords2[i].push([startX,
  768. startY,
  769. width,
  770. individualBarHeight,
  771. co.fillStyle,
  772. this.data[i][j],
  773. true]);
  774. }
  775. startY += vmargin;
  776. }
  777. co.closePath();
  778. }
  779. co.stroke();
  780. co.fill();
  781. /**
  782. * Now the bars are stroke()ed, turn off the shadow
  783. */
  784. RG.NoShadow(this);
  785. this.RedrawBars();
  786. }
  787. /**
  788. * This function goes over the bars after they been drawn, so that upwards shadows are underneath the bars
  789. */
  790. this.RedrawBars = function ()
  791. {
  792. if (prop['chart.noredraw']) {
  793. return;
  794. }
  795. var coords = this.coords;
  796. var font = prop['chart.text.font'];
  797. var size = prop['chart.text.size'];
  798. var color = prop['chart.text.color'];
  799. RG.NoShadow(this);
  800. co.strokeStyle = prop['chart.strokestyle'];
  801. for (var i=0; i<coords.length; ++i) {
  802. if (prop['chart.shadow']) {
  803. co.beginPath();
  804. co.strokeStyle = prop['chart.strokestyle'];
  805. co.fillStyle = coords[i][4];
  806. co.lineWidth = prop['chart.linewidth'];
  807. co.strokeRect(coords[i][0], coords[i][1], coords[i][2], coords[i][3]);
  808. co.fillRect(coords[i][0], coords[i][1], coords[i][2], coords[i][3]);
  809. co.fill();
  810. co.stroke();
  811. }
  812. /**
  813. * Draw labels "above" the bar
  814. */
  815. if (prop['chart.labels.above'] && coords[i][6]) {
  816. co.fillStyle = prop['chart.text.color'];
  817. co.strokeStyle = 'black';
  818. RG.NoShadow(this);
  819. var border = (coords[i][0] + coords[i][2] + 7 + co.measureText(prop['chart.units.pre'] + this.coords[i][5] + prop['chart.units.post']).width) > ca.width ? true : false;
  820. /**
  821. * Default to the value - then check for specific labels
  822. */
  823. var text = RG.number_format(this, (this.coords[i][5]).toFixed(prop['chart.labels.above.decimals']), prop['chart.units.pre'], prop['chart.units.post']);
  824. if (typeof prop['chart.labels.above.specific'] == 'object' && prop['chart.labels.above.specific'] && prop['chart.labels.above.specific'][i]) {
  825. text = prop['chart.labels.above.specific'][i];
  826. }
  827. RG.Text2(this, {'font':font,
  828. 'size':size,
  829. 'x':coords[i][0] + coords[i][2] + 5,
  830. 'y':coords[i][1] + (coords[i][3] / 2),
  831. 'text': text,
  832. 'valign':'center',
  833. 'halign':'left',
  834. 'tag': 'labels.above'
  835. });
  836. }
  837. }
  838. }
  839. /**
  840. * This function can be used to get the appropriate bar information (if any)
  841. *
  842. * @param e Event object
  843. * @return Appriate bar information (if any)
  844. */
  845. this.getShape =
  846. this.getBar = function (e)
  847. {
  848. var mouseCoords = RG.getMouseXY(e);
  849. /**
  850. * Loop through the bars determining if the mouse is over a bar
  851. */
  852. for (var i=0,len=this.coords.length; i<len; i++) {
  853. var mouseX = mouseCoords[0]; // In relation to the canvas
  854. var mouseY = mouseCoords[1]; // In relation to the canvas
  855. var left = this.coords[i][0];
  856. var top = this.coords[i][1];
  857. var width = this.coords[i][2];
  858. var height = this.coords[i][3];
  859. var idx = i;
  860. if (mouseX >= left && mouseX <= (left + width) && mouseY >= top && mouseY <= (top + height) ) {
  861. var tooltip = RG.parseTooltipText(prop['chart.tooltips'], i);
  862. return {
  863. 0: this, 'object': this,
  864. 1: left, 'x': left,
  865. 2: top, 'y': top,
  866. 3: width, 'width': width,
  867. 4: height, 'height': height,
  868. 5: idx, 'index': idx,
  869. 'tooltip': tooltip
  870. };
  871. }
  872. }
  873. }
  874. /**
  875. * When you click on the chart, this method can return the X value at that point. It works for any point on the
  876. * chart (that is inside the gutters) - not just points within the Bars.
  877. *
  878. * @param object e The event object
  879. */
  880. this.getValue = function (arg)
  881. {
  882. if (arg.length == 2) {
  883. var mouseX = arg[0];
  884. var mouseY = arg[1];
  885. } else {
  886. var mouseCoords = RG.getMouseXY(arg);
  887. var mouseX = mouseCoords[0];
  888. var mouseY = mouseCoords[1];
  889. }
  890. if ( mouseY < this.gutterTop
  891. || mouseY > (ca.height - this.gutterBottom)
  892. || mouseX < this.gutterLeft
  893. || mouseX > (ca.width - this.gutterRight)
  894. ) {
  895. return null;
  896. }
  897. if (prop['chart.yaxispos'] == 'center') {
  898. var value = ((mouseX - this.gutterLeft) / (this.graphwidth / 2)) * (this.max - prop['chart.xmin']);
  899. value = value - this.max
  900. // Special case if xmin is defined
  901. if (prop['chart.xmin'] > 0) {
  902. value = ((mouseX - this.gutterLeft - (this.graphwidth / 2)) / (this.graphwidth / 2)) * (this.max - prop['chart.xmin']);
  903. value += prop['chart.xmin'];
  904. if (mouseX < (this.gutterLeft + (this.graphwidth / 2))) {
  905. value -= (2 * prop['chart.xmin']);
  906. }
  907. }
  908. } else {
  909. var value = ((mouseX - this.gutterLeft) / this.graphwidth) * (this.max - prop['chart.xmin']);
  910. value += prop['chart.xmin'];
  911. }
  912. return value;
  913. }
  914. /**
  915. * Each object type has its own Highlight() function which highlights the appropriate shape
  916. *
  917. * @param object shape The shape to highlight
  918. */
  919. this.Highlight = function (shape)
  920. {
  921. // Add the new highlight
  922. RG.Highlight.Rect(this, shape);
  923. }
  924. /**
  925. * The getObjectByXY() worker method. Don't call this call:
  926. *
  927. * RG.ObjectRegistry.getObjectByXY(e)
  928. *
  929. * @param object e The event object
  930. */
  931. this.getObjectByXY = function (e)
  932. {
  933. var mouseXY = RG.getMouseXY(e);
  934. if (
  935. mouseXY[0] > this.gutterLeft
  936. && mouseXY[0] < (ca.width - this.gutterRight)
  937. && mouseXY[1] > this.gutterTop
  938. && mouseXY[1] < (ca.height - this.gutterBottom)
  939. ) {
  940. return this;
  941. }
  942. }
  943. /**
  944. * This function positions a tooltip when it is displayed
  945. *
  946. * @param obj object The chart object
  947. * @param int x The X coordinate specified for the tooltip
  948. * @param int y The Y coordinate specified for the tooltip
  949. * @param objec tooltip The tooltips DIV element
  950. */
  951. this.positionTooltip = function (obj, x, y, tooltip, idx)
  952. {
  953. var coordX = obj.coords[tooltip.__index__][0];
  954. var coordY = obj.coords[tooltip.__index__][1];
  955. var coordW = obj.coords[tooltip.__index__][2];
  956. var coordH = obj.coords[tooltip.__index__][3];
  957. var canvasXY = RG.getCanvasXY(obj.canvas);
  958. var gutterLeft = obj.gutterLeft;
  959. var gutterTop = obj.gutterTop;
  960. var width = tooltip.offsetWidth;
  961. var height = tooltip.offsetHeight;
  962. // Set the top position
  963. tooltip.style.left = 0;
  964. tooltip.style.top = canvasXY[1] + coordY + (coordH / 2) - height + 'px';
  965. // By default any overflow is hidden
  966. tooltip.style.overflow = '';
  967. // The arrow
  968. var img = new Image();
  969. img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC';
  970. img.style.position = 'absolute';
  971. img.id = '__rgraph_tooltip_pointer__';
  972. img.style.top = (tooltip.offsetHeight - 2) + 'px';
  973. tooltip.appendChild(img);
  974. // Reposition the tooltip if at the edges:
  975. // LEFT edge
  976. if ((canvasXY[0] + coordX + (coordW / 2) - (width / 2)) < 10) {
  977. tooltip.style.left = (canvasXY[0] + coordX - (width * 0.1)) + (coordW / 2) + 'px';
  978. img.style.left = ((width * 0.1) - 8.5) + 'px';
  979. // RIGHT edge
  980. } else if ((canvasXY[0] + (coordW / 2) + coordX + (width / 2)) > document.body.offsetWidth) {
  981. tooltip.style.left = canvasXY[0] + coordX - (width * 0.9) + (coordW / 2) + 'px';
  982. img.style.left = ((width * 0.9) - 8.5) + 'px';
  983. // Default positioning - CENTERED
  984. } else {
  985. tooltip.style.left = (canvasXY[0] + coordX + (coordW / 2) - (width * 0.5)) + 'px';
  986. img.style.left = ((width * 0.5) - 8.5) + 'px';
  987. }
  988. }
  989. /**
  990. * Returns the appropriate Y coord for the given value
  991. *
  992. * @param number value The value to get the coord for
  993. */
  994. this.getXCoord = function (value)
  995. {
  996. if (prop['chart.yaxispos'] == 'center') {
  997. // Range checking
  998. if (value > this.max || value < (-1 * this.max)) {
  999. return null;
  1000. }
  1001. var width = (ca.width - prop['chart.gutter.left'] - prop['chart.gutter.right']) / 2;
  1002. var coord = (((value - prop['chart.xmin']) / (this.max - prop['chart.xmin'])) * width) + width;
  1003. coord = prop['chart.gutter.left'] + coord;
  1004. } else {
  1005. // Range checking
  1006. if (value > this.max || value < 0) {
  1007. return null;
  1008. }
  1009. var width = ca.width - prop['chart.gutter.left'] - prop['chart.gutter.right'];
  1010. var coord = ((value - prop['chart.xmin']) / (this.max - prop['chart.xmin'])) * width;
  1011. coord = prop['chart.gutter.left'] + coord;
  1012. }
  1013. return coord;
  1014. }
  1015. /**
  1016. *
  1017. */
  1018. this.parseColors = function ()
  1019. {
  1020. var colors = prop['chart.colors'];
  1021. for (var i=0; i<colors.length; ++i) {
  1022. colors[i] = this.parseSingleColorForGradient(colors[i]);
  1023. }
  1024. prop['chart.background.grid.color'] = this.parseSingleColorForGradient(prop['chart.background.grid.color']);
  1025. prop['chart.background.barcolor1'] = this.parseSingleColorForGradient(prop['chart.background.barcolor1']);
  1026. prop['chart.background.barcolor2'] = this.parseSingleColorForGradient(prop['chart.background.barcolor2']);
  1027. prop['chart.text.color'] = this.parseSingleColorForGradient(prop['chart.text.color']);
  1028. prop['chart.labels.colors'] = this.parseSingleColorForGradient(prop['chart.labels.colors']);
  1029. prop['chart.strokestyle'] = this.parseSingleColorForGradient(prop['chart.strokestyle']);
  1030. prop['chart.axis.color'] = this.parseSingleColorForGradient(prop['chart.axis.color']);
  1031. prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
  1032. prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
  1033. }
  1034. /**
  1035. * This parses a single color value
  1036. */
  1037. this.parseSingleColorForGradient = function (color)
  1038. {
  1039. if (!color || typeof(color) != 'string') {
  1040. return color;
  1041. }
  1042. if (color.match(/^gradient\((.*)\)$/i)) {
  1043. var parts = RegExp.$1.split(':');
  1044. // Create the gradient
  1045. var grad = co.createLinearGradient(prop['chart.gutter.left'],0,ca.width - prop['chart.gutter.right'],0);
  1046. var diff = 1 / (parts.length - 1);
  1047. grad.addColorStop(0, RG.trim(parts[0]));
  1048. for (var j=1; j<parts.length; ++j) {
  1049. grad.addColorStop(j * diff, RG.trim(parts[j]));
  1050. }
  1051. }
  1052. return grad ? grad : color;
  1053. }
  1054. /**
  1055. * This function handles highlighting an entire data-series for the interactive
  1056. * key
  1057. *
  1058. * @param int index The index of the data series to be highlighted
  1059. */
  1060. this.interactiveKeyHighlight = function (index)
  1061. {
  1062. var obj = this;
  1063. this.coords2.forEach(function (value, idx, arr)
  1064. {
  1065. var shape = obj.coords2[idx][index]
  1066. var pre_linewidth = co.lineWidth;
  1067. co.lineWidth = 2;
  1068. co.fillStyle = prop['chart.key.interactive.highlight.chart.fill'];
  1069. co.strokeStyle = prop['chart.key.interactive.highlight.chart.stroke'];
  1070. co.fillRect(shape[0], shape[1], shape[2], shape[3]);
  1071. co.strokeRect(shape[0], shape[1], shape[2], shape[3]);
  1072. // Reset the lineWidth
  1073. co.lineWidth = pre_linewidth;
  1074. });
  1075. }
  1076. /**
  1077. * Charts are now always registered
  1078. */
  1079. RG.Register(this);
  1080. }