vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1302 lines
40 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. var util = require('../../util');
  2. var DOMutil = require('../../DOMutil');
  3. var DataSet = require('../../DataSet');
  4. var DataView = require('../../DataView');
  5. var Component = require('./Component');
  6. var DataAxis = require('./DataAxis');
  7. var GraphGroup = require('./GraphGroup');
  8. var Legend = require('./Legend');
  9. var UNGROUPED = '__ungrouped__'; // reserved group id for ungrouped items
  10. /**
  11. * This is the constructor of the LineGraph. It requires a Timeline body and options.
  12. *
  13. * @param body
  14. * @param options
  15. * @constructor
  16. */
  17. function LineGraph(body, options) {
  18. this.id = util.randomUUID();
  19. this.body = body;
  20. this.defaultOptions = {
  21. yAxisOrientation: 'left',
  22. defaultGroup: 'default',
  23. sort: true,
  24. sampling: true,
  25. graphHeight: '400px',
  26. shaded: {
  27. enabled: false,
  28. orientation: 'bottom' // top, bottom
  29. },
  30. style: 'line', // line, bar
  31. barChart: {
  32. width: 50,
  33. handleOverlap: 'overlap',
  34. align: 'center' // left, center, right
  35. },
  36. catmullRom: {
  37. enabled: true,
  38. parametrization: 'centripetal', // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
  39. alpha: 0.5
  40. },
  41. drawPoints: {
  42. enabled: true,
  43. size: 6,
  44. style: 'square' // square, circle
  45. },
  46. dataAxis: {
  47. showMinorLabels: true,
  48. showMajorLabels: true,
  49. icons: false,
  50. width: '40px',
  51. visible: true,
  52. customRange: {
  53. left: {min:undefined, max:undefined},
  54. right: {min:undefined, max:undefined}
  55. }
  56. },
  57. legend: {
  58. enabled: false,
  59. icons: true,
  60. left: {
  61. visible: true,
  62. position: 'top-left' // top/bottom - left,right
  63. },
  64. right: {
  65. visible: true,
  66. position: 'top-right' // top/bottom - left,right
  67. }
  68. },
  69. groups: {
  70. visibility: {}
  71. }
  72. };
  73. // options is shared by this ItemSet and all its items
  74. this.options = util.extend({}, this.defaultOptions);
  75. this.dom = {};
  76. this.props = {};
  77. this.hammer = null;
  78. this.groups = {};
  79. this.abortedGraphUpdate = false;
  80. var me = this;
  81. this.itemsData = null; // DataSet
  82. this.groupsData = null; // DataSet
  83. // listeners for the DataSet of the items
  84. this.itemListeners = {
  85. 'add': function (event, params, senderId) {
  86. me._onAdd(params.items);
  87. },
  88. 'update': function (event, params, senderId) {
  89. me._onUpdate(params.items);
  90. },
  91. 'remove': function (event, params, senderId) {
  92. me._onRemove(params.items);
  93. }
  94. };
  95. // listeners for the DataSet of the groups
  96. this.groupListeners = {
  97. 'add': function (event, params, senderId) {
  98. me._onAddGroups(params.items);
  99. },
  100. 'update': function (event, params, senderId) {
  101. me._onUpdateGroups(params.items);
  102. },
  103. 'remove': function (event, params, senderId) {
  104. me._onRemoveGroups(params.items);
  105. }
  106. };
  107. this.items = {}; // object with an Item for every data item
  108. this.selection = []; // list with the ids of all selected nodes
  109. this.lastStart = this.body.range.start;
  110. this.touchParams = {}; // stores properties while dragging
  111. this.svgElements = {};
  112. this.setOptions(options);
  113. this.groupsUsingDefaultStyles = [0];
  114. this.body.emitter.on("rangechanged", function() {
  115. me.lastStart = me.body.range.start;
  116. me.svg.style.left = util.option.asSize(-me.width);
  117. me._updateGraph.apply(me);
  118. });
  119. // create the HTML DOM
  120. this._create();
  121. this.body.emitter.emit("change");
  122. }
  123. LineGraph.prototype = new Component();
  124. /**
  125. * Create the HTML DOM for the ItemSet
  126. */
  127. LineGraph.prototype._create = function(){
  128. var frame = document.createElement('div');
  129. frame.className = 'LineGraph';
  130. this.dom.frame = frame;
  131. // create svg element for graph drawing.
  132. this.svg = document.createElementNS('http://www.w3.org/2000/svg',"svg");
  133. this.svg.style.position = "relative";
  134. this.svg.style.height = ('' + this.options.graphHeight).replace("px",'') + 'px';
  135. this.svg.style.display = "block";
  136. frame.appendChild(this.svg);
  137. // data axis
  138. this.options.dataAxis.orientation = 'left';
  139. this.yAxisLeft = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
  140. this.options.dataAxis.orientation = 'right';
  141. this.yAxisRight = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
  142. delete this.options.dataAxis.orientation;
  143. // legends
  144. this.legendLeft = new Legend(this.body, this.options.legend, 'left', this.options.groups);
  145. this.legendRight = new Legend(this.body, this.options.legend, 'right', this.options.groups);
  146. this.show();
  147. };
  148. /**
  149. * set the options of the LineGraph. the mergeOptions is used for subObjects that have an enabled element.
  150. * @param options
  151. */
  152. LineGraph.prototype.setOptions = function(options) {
  153. if (options) {
  154. var fields = ['sampling','defaultGroup','graphHeight','yAxisOrientation','style','barChart','dataAxis','sort','groups'];
  155. util.selectiveDeepExtend(fields, this.options, options);
  156. util.mergeOptions(this.options, options,'catmullRom');
  157. util.mergeOptions(this.options, options,'drawPoints');
  158. util.mergeOptions(this.options, options,'shaded');
  159. util.mergeOptions(this.options, options,'legend');
  160. if (options.catmullRom) {
  161. if (typeof options.catmullRom == 'object') {
  162. if (options.catmullRom.parametrization) {
  163. if (options.catmullRom.parametrization == 'uniform') {
  164. this.options.catmullRom.alpha = 0;
  165. }
  166. else if (options.catmullRom.parametrization == 'chordal') {
  167. this.options.catmullRom.alpha = 1.0;
  168. }
  169. else {
  170. this.options.catmullRom.parametrization = 'centripetal';
  171. this.options.catmullRom.alpha = 0.5;
  172. }
  173. }
  174. }
  175. }
  176. if (this.yAxisLeft) {
  177. if (options.dataAxis !== undefined) {
  178. this.yAxisLeft.setOptions(this.options.dataAxis);
  179. this.yAxisRight.setOptions(this.options.dataAxis);
  180. }
  181. }
  182. if (this.legendLeft) {
  183. if (options.legend !== undefined) {
  184. this.legendLeft.setOptions(this.options.legend);
  185. this.legendRight.setOptions(this.options.legend);
  186. }
  187. }
  188. if (this.groups.hasOwnProperty(UNGROUPED)) {
  189. this.groups[UNGROUPED].setOptions(options);
  190. }
  191. }
  192. if (this.dom.frame) {
  193. this._updateGraph();
  194. }
  195. };
  196. /**
  197. * Hide the component from the DOM
  198. */
  199. LineGraph.prototype.hide = function() {
  200. // remove the frame containing the items
  201. if (this.dom.frame.parentNode) {
  202. this.dom.frame.parentNode.removeChild(this.dom.frame);
  203. }
  204. };
  205. /**
  206. * Show the component in the DOM (when not already visible).
  207. * @return {Boolean} changed
  208. */
  209. LineGraph.prototype.show = function() {
  210. // show frame containing the items
  211. if (!this.dom.frame.parentNode) {
  212. this.body.dom.center.appendChild(this.dom.frame);
  213. }
  214. };
  215. /**
  216. * Set items
  217. * @param {vis.DataSet | null} items
  218. */
  219. LineGraph.prototype.setItems = function(items) {
  220. var me = this,
  221. ids,
  222. oldItemsData = this.itemsData;
  223. // replace the dataset
  224. if (!items) {
  225. this.itemsData = null;
  226. }
  227. else if (items instanceof DataSet || items instanceof DataView) {
  228. this.itemsData = items;
  229. }
  230. else {
  231. throw new TypeError('Data must be an instance of DataSet or DataView');
  232. }
  233. if (oldItemsData) {
  234. // unsubscribe from old dataset
  235. util.forEach(this.itemListeners, function (callback, event) {
  236. oldItemsData.off(event, callback);
  237. });
  238. // remove all drawn items
  239. ids = oldItemsData.getIds();
  240. this._onRemove(ids);
  241. }
  242. if (this.itemsData) {
  243. // subscribe to new dataset
  244. var id = this.id;
  245. util.forEach(this.itemListeners, function (callback, event) {
  246. me.itemsData.on(event, callback, id);
  247. });
  248. // add all new items
  249. ids = this.itemsData.getIds();
  250. this._onAdd(ids);
  251. }
  252. this._updateUngrouped();
  253. this._updateGraph();
  254. this.redraw();
  255. };
  256. /**
  257. * Set groups
  258. * @param {vis.DataSet} groups
  259. */
  260. LineGraph.prototype.setGroups = function(groups) {
  261. var me = this,
  262. ids;
  263. // unsubscribe from current dataset
  264. if (this.groupsData) {
  265. util.forEach(this.groupListeners, function (callback, event) {
  266. me.groupsData.unsubscribe(event, callback);
  267. });
  268. // remove all drawn groups
  269. ids = this.groupsData.getIds();
  270. this.groupsData = null;
  271. this._onRemoveGroups(ids); // note: this will cause a redraw
  272. }
  273. // replace the dataset
  274. if (!groups) {
  275. this.groupsData = null;
  276. }
  277. else if (groups instanceof DataSet || groups instanceof DataView) {
  278. this.groupsData = groups;
  279. }
  280. else {
  281. throw new TypeError('Data must be an instance of DataSet or DataView');
  282. }
  283. if (this.groupsData) {
  284. // subscribe to new dataset
  285. var id = this.id;
  286. util.forEach(this.groupListeners, function (callback, event) {
  287. me.groupsData.on(event, callback, id);
  288. });
  289. // draw all ms
  290. ids = this.groupsData.getIds();
  291. this._onAddGroups(ids);
  292. }
  293. this._onUpdate();
  294. };
  295. /**
  296. * Update the datapoints
  297. * @param [ids]
  298. * @private
  299. */
  300. LineGraph.prototype._onUpdate = function(ids) {
  301. this._updateUngrouped();
  302. this._updateAllGroupData();
  303. this._updateGraph();
  304. this.redraw();
  305. };
  306. LineGraph.prototype._onAdd = function (ids) {this._onUpdate(ids);};
  307. LineGraph.prototype._onRemove = function (ids) {this._onUpdate(ids);};
  308. LineGraph.prototype._onUpdateGroups = function (groupIds) {
  309. for (var i = 0; i < groupIds.length; i++) {
  310. var group = this.groupsData.get(groupIds[i]);
  311. this._updateGroup(group, groupIds[i]);
  312. }
  313. this._updateGraph();
  314. this.redraw();
  315. };
  316. LineGraph.prototype._onAddGroups = function (groupIds) {this._onUpdateGroups(groupIds);};
  317. LineGraph.prototype._onRemoveGroups = function (groupIds) {
  318. for (var i = 0; i < groupIds.length; i++) {
  319. if (!this.groups.hasOwnProperty(groupIds[i])) {
  320. if (this.groups[groupIds[i]].options.yAxisOrientation == 'right') {
  321. this.yAxisRight.removeGroup(groupIds[i]);
  322. this.legendRight.removeGroup(groupIds[i]);
  323. this.legendRight.redraw();
  324. }
  325. else {
  326. this.yAxisLeft.removeGroup(groupIds[i]);
  327. this.legendLeft.removeGroup(groupIds[i]);
  328. this.legendLeft.redraw();
  329. }
  330. delete this.groups[groupIds[i]];
  331. }
  332. }
  333. this._updateUngrouped();
  334. this._updateGraph();
  335. this.redraw();
  336. };
  337. /**
  338. * update a group object
  339. *
  340. * @param group
  341. * @param groupId
  342. * @private
  343. */
  344. LineGraph.prototype._updateGroup = function (group, groupId) {
  345. if (!this.groups.hasOwnProperty(groupId)) {
  346. this.groups[groupId] = new GraphGroup(group, groupId, this.options, this.groupsUsingDefaultStyles);
  347. if (this.groups[groupId].options.yAxisOrientation == 'right') {
  348. this.yAxisRight.addGroup(groupId, this.groups[groupId]);
  349. this.legendRight.addGroup(groupId, this.groups[groupId]);
  350. }
  351. else {
  352. this.yAxisLeft.addGroup(groupId, this.groups[groupId]);
  353. this.legendLeft.addGroup(groupId, this.groups[groupId]);
  354. }
  355. }
  356. else {
  357. this.groups[groupId].update(group);
  358. if (this.groups[groupId].options.yAxisOrientation == 'right') {
  359. this.yAxisRight.updateGroup(groupId, this.groups[groupId]);
  360. this.legendRight.updateGroup(groupId, this.groups[groupId]);
  361. }
  362. else {
  363. this.yAxisLeft.updateGroup(groupId, this.groups[groupId]);
  364. this.legendLeft.updateGroup(groupId, this.groups[groupId]);
  365. }
  366. }
  367. this.legendLeft.redraw();
  368. this.legendRight.redraw();
  369. };
  370. LineGraph.prototype._updateAllGroupData = function () {
  371. if (this.itemsData != null) {
  372. var groupsContent = {};
  373. var groupId;
  374. for (groupId in this.groups) {
  375. if (this.groups.hasOwnProperty(groupId)) {
  376. groupsContent[groupId] = [];
  377. }
  378. }
  379. for (var itemId in this.itemsData._data) {
  380. if (this.itemsData._data.hasOwnProperty(itemId)) {
  381. var item = this.itemsData._data[itemId];
  382. item.x = util.convert(item.x,"Date");
  383. groupsContent[item.group].push(item);
  384. }
  385. }
  386. for (groupId in this.groups) {
  387. if (this.groups.hasOwnProperty(groupId)) {
  388. this.groups[groupId].setItems(groupsContent[groupId]);
  389. }
  390. }
  391. }
  392. };
  393. /**
  394. * Create or delete the group holding all ungrouped items. This group is used when
  395. * there are no groups specified. This anonymous group is called 'graph'.
  396. * @protected
  397. */
  398. LineGraph.prototype._updateUngrouped = function() {
  399. if (this.itemsData != null) {
  400. // var t0 = new Date();
  401. var group = {id: UNGROUPED, content: this.options.defaultGroup};
  402. this._updateGroup(group, UNGROUPED);
  403. var ungroupedCounter = 0;
  404. if (this.itemsData) {
  405. for (var itemId in this.itemsData._data) {
  406. if (this.itemsData._data.hasOwnProperty(itemId)) {
  407. var item = this.itemsData._data[itemId];
  408. if (item != undefined) {
  409. if (item.hasOwnProperty('group')) {
  410. if (item.group === undefined) {
  411. item.group = UNGROUPED;
  412. }
  413. }
  414. else {
  415. item.group = UNGROUPED;
  416. }
  417. ungroupedCounter = item.group == UNGROUPED ? ungroupedCounter + 1 : ungroupedCounter;
  418. }
  419. }
  420. }
  421. }
  422. if (ungroupedCounter == 0) {
  423. delete this.groups[UNGROUPED];
  424. this.legendLeft.removeGroup(UNGROUPED);
  425. this.legendRight.removeGroup(UNGROUPED);
  426. this.yAxisLeft.removeGroup(UNGROUPED);
  427. this.yAxisRight.removeGroup(UNGROUPED);
  428. }
  429. }
  430. else {
  431. delete this.groups[UNGROUPED];
  432. this.legendLeft.removeGroup(UNGROUPED);
  433. this.legendRight.removeGroup(UNGROUPED);
  434. this.yAxisLeft.removeGroup(UNGROUPED);
  435. this.yAxisRight.removeGroup(UNGROUPED);
  436. }
  437. this.legendLeft.redraw();
  438. this.legendRight.redraw();
  439. };
  440. /**
  441. * Redraw the component, mandatory function
  442. * @return {boolean} Returns true if the component is resized
  443. */
  444. LineGraph.prototype.redraw = function() {
  445. var resized = false;
  446. this.svg.style.height = ('' + this.options.graphHeight).replace('px','') + 'px';
  447. if (this.lastWidth === undefined && this.width || this.lastWidth != this.width) {
  448. resized = true;
  449. }
  450. // check if this component is resized
  451. resized = this._isResized() || resized;
  452. // check whether zoomed (in that case we need to re-stack everything)
  453. var visibleInterval = this.body.range.end - this.body.range.start;
  454. var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.width != this.lastWidth);
  455. this.lastVisibleInterval = visibleInterval;
  456. this.lastWidth = this.width;
  457. // calculate actual size and position
  458. this.width = this.dom.frame.offsetWidth;
  459. // the svg element is three times as big as the width, this allows for fully dragging left and right
  460. // without reloading the graph. the controls for this are bound to events in the constructor
  461. if (resized == true) {
  462. this.svg.style.width = util.option.asSize(3*this.width);
  463. this.svg.style.left = util.option.asSize(-this.width);
  464. }
  465. if (zoomed == true || this.abortedGraphUpdate == true) {
  466. this._updateGraph();
  467. }
  468. else {
  469. // move the whole svg while dragging
  470. if (this.lastStart != 0) {
  471. var offset = this.body.range.start - this.lastStart;
  472. var range = this.body.range.end - this.body.range.start;
  473. if (this.width != 0) {
  474. var rangePerPixelInv = this.width/range;
  475. var xOffset = offset * rangePerPixelInv;
  476. this.svg.style.left = (-this.width - xOffset) + "px";
  477. }
  478. }
  479. }
  480. this.legendLeft.redraw();
  481. this.legendRight.redraw();
  482. return resized;
  483. };
  484. /**
  485. * Update and redraw the graph.
  486. *
  487. */
  488. LineGraph.prototype._updateGraph = function () {
  489. // reset the svg elements
  490. DOMutil.prepareElements(this.svgElements);
  491. if (this.width != 0 && this.itemsData != null) {
  492. var group, i;
  493. var preprocessedGroupData = {};
  494. var processedGroupData = {};
  495. var groupRanges = {};
  496. var changeCalled = false;
  497. // getting group Ids
  498. var groupIds = [];
  499. for (var groupId in this.groups) {
  500. if (this.groups.hasOwnProperty(groupId)) {
  501. group = this.groups[groupId];
  502. if (group.visible == true && (this.options.groups.visibility[groupId] === undefined || this.options.groups.visibility[groupId] == true)) {
  503. groupIds.push(groupId);
  504. }
  505. }
  506. }
  507. if (groupIds.length > 0) {
  508. // this is the range of the SVG canvas
  509. var minDate = this.body.util.toGlobalTime(- this.body.domProps.root.width);
  510. var maxDate = this.body.util.toGlobalTime(2 * this.body.domProps.root.width);
  511. var groupsData = {};
  512. // fill groups data
  513. this._getRelevantData(groupIds, groupsData, minDate, maxDate);
  514. // we transform the X coordinates to detect collisions
  515. for (i = 0; i < groupIds.length; i++) {
  516. preprocessedGroupData[groupIds[i]] = this._convertXcoordinates(groupsData[groupIds[i]]);
  517. }
  518. // now all needed data has been collected we start the processing.
  519. this._getYRanges(groupIds, preprocessedGroupData, groupRanges);
  520. // update the Y axis first, we use this data to draw at the correct Y points
  521. // changeCalled is required to clean the SVG on a change emit.
  522. changeCalled = this._updateYAxis(groupIds, groupRanges);
  523. if (changeCalled == true) {
  524. DOMutil.cleanupElements(this.svgElements);
  525. this.abortedGraphUpdate = true;
  526. this.body.emitter.emit("change");
  527. return;
  528. }
  529. this.abortedGraphUpdate = false;
  530. // With the yAxis scaled correctly, use this to get the Y values of the points.
  531. for (i = 0; i < groupIds.length; i++) {
  532. group = this.groups[groupIds[i]];
  533. processedGroupData[groupIds[i]] = this._convertYcoordinates(groupsData[groupIds[i]], group);
  534. }
  535. // draw the groups
  536. for (i = 0; i < groupIds.length; i++) {
  537. group = this.groups[groupIds[i]];
  538. if (group.options.style == 'line') {
  539. this._drawLineGraph(processedGroupData[groupIds[i]], group);
  540. }
  541. }
  542. this._drawBarGraphs(groupIds, processedGroupData);
  543. }
  544. }
  545. // cleanup unused svg elements
  546. DOMutil.cleanupElements(this.svgElements);
  547. };
  548. LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate, maxDate) {
  549. // first select and preprocess the data from the datasets.
  550. // the groups have their preselection of data, we now loop over this data to see
  551. // what data we need to draw. Sorted data is much faster.
  552. // more optimization is possible by doing the sampling before and using the binary search
  553. // to find the end date to determine the increment.
  554. var group, i, j, item;
  555. if (groupIds.length > 0) {
  556. for (i = 0; i < groupIds.length; i++) {
  557. group = this.groups[groupIds[i]];
  558. groupsData[groupIds[i]] = [];
  559. var dataContainer = groupsData[groupIds[i]];
  560. // optimization for sorted data
  561. if (group.options.sort == true) {
  562. var guess = Math.max(0, util.binarySearchGeneric(group.itemsData, minDate, 'x', 'before'));
  563. for (j = guess; j < group.itemsData.length; j++) {
  564. item = group.itemsData[j];
  565. if (item !== undefined) {
  566. if (item.x > maxDate) {
  567. dataContainer.push(item);
  568. break;
  569. }
  570. else {
  571. dataContainer.push(item);
  572. }
  573. }
  574. }
  575. }
  576. else {
  577. for (j = 0; j < group.itemsData.length; j++) {
  578. item = group.itemsData[j];
  579. if (item !== undefined) {
  580. if (item.x > minDate && item.x < maxDate) {
  581. dataContainer.push(item);
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. this._applySampling(groupIds, groupsData);
  589. };
  590. LineGraph.prototype._applySampling = function (groupIds, groupsData) {
  591. var group;
  592. if (groupIds.length > 0) {
  593. for (var i = 0; i < groupIds.length; i++) {
  594. group = this.groups[groupIds[i]];
  595. if (group.options.sampling == true) {
  596. var dataContainer = groupsData[groupIds[i]];
  597. if (dataContainer.length > 0) {
  598. var increment = 1;
  599. var amountOfPoints = dataContainer.length;
  600. // the global screen is used because changing the width of the yAxis may affect the increment, resulting in an endless loop
  601. // of width changing of the yAxis.
  602. var xDistance = this.body.util.toGlobalScreen(dataContainer[dataContainer.length - 1].x) - this.body.util.toGlobalScreen(dataContainer[0].x);
  603. var pointsPerPixel = amountOfPoints / xDistance;
  604. increment = Math.min(Math.ceil(0.2 * amountOfPoints), Math.max(1, Math.round(pointsPerPixel)));
  605. var sampledData = [];
  606. for (var j = 0; j < amountOfPoints; j += increment) {
  607. sampledData.push(dataContainer[j]);
  608. }
  609. groupsData[groupIds[i]] = sampledData;
  610. }
  611. }
  612. }
  613. }
  614. };
  615. LineGraph.prototype._getYRanges = function (groupIds, groupsData, groupRanges) {
  616. var groupData, group, i,j;
  617. var barCombinedDataLeft = [];
  618. var barCombinedDataRight = [];
  619. var barCombinedData;
  620. if (groupIds.length > 0) {
  621. for (i = 0; i < groupIds.length; i++) {
  622. groupData = groupsData[groupIds[i]];
  623. if (groupData.length > 0) {
  624. group = this.groups[groupIds[i]];
  625. if (group.options.style == 'line' || group.options.barChart.handleOverlap != "stack") {
  626. var yMin = groupData[0].y;
  627. var yMax = groupData[0].y;
  628. for (j = 0; j < groupData.length; j++) {
  629. yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
  630. yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
  631. }
  632. groupRanges[groupIds[i]] = {min: yMin, max: yMax, yAxisOrientation: group.options.yAxisOrientation};
  633. }
  634. else if (group.options.style == 'bar') {
  635. if (group.options.yAxisOrientation == 'left') {
  636. barCombinedData = barCombinedDataLeft;
  637. }
  638. else {
  639. barCombinedData = barCombinedDataRight;
  640. }
  641. groupRanges[groupIds[i]] = {min: 0, max: 0, yAxisOrientation: group.options.yAxisOrientation, ignore: true};
  642. // combine data
  643. for (j = 0; j < groupData.length; j++) {
  644. barCombinedData.push({
  645. x: groupData[j].x,
  646. y: groupData[j].y,
  647. groupId: groupIds[i]
  648. });
  649. }
  650. }
  651. }
  652. }
  653. var intersections;
  654. if (barCombinedDataLeft.length > 0) {
  655. // sort by time and by group
  656. barCombinedDataLeft.sort(function (a, b) {
  657. if (a.x == b.x) {
  658. return a.groupId - b.groupId;
  659. } else {
  660. return a.x - b.x;
  661. }
  662. });
  663. intersections = {};
  664. this._getDataIntersections(intersections, barCombinedDataLeft);
  665. groupRanges["__barchartLeft"] = this._getStackedBarYRange(intersections, barCombinedDataLeft);
  666. groupRanges["__barchartLeft"].yAxisOrientation = "left";
  667. groupIds.push("__barchartLeft");
  668. }
  669. if (barCombinedDataRight.length > 0) {
  670. // sort by time and by group
  671. barCombinedDataRight.sort(function (a, b) {
  672. if (a.x == b.x) {
  673. return a.groupId - b.groupId;
  674. } else {
  675. return a.x - b.x;
  676. }
  677. });
  678. intersections = {};
  679. this._getDataIntersections(intersections, barCombinedDataRight);
  680. groupRanges["__barchartRight"] = this._getStackedBarYRange(intersections, barCombinedDataRight);
  681. groupRanges["__barchartRight"].yAxisOrientation = "right";
  682. groupIds.push("__barchartRight");
  683. }
  684. }
  685. };
  686. LineGraph.prototype._getStackedBarYRange = function (intersections, combinedData) {
  687. var key;
  688. var yMin = combinedData[0].y;
  689. var yMax = combinedData[0].y;
  690. for (var i = 0; i < combinedData.length; i++) {
  691. key = combinedData[i].x;
  692. if (intersections[key] === undefined) {
  693. yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
  694. yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
  695. }
  696. else {
  697. intersections[key].accumulated += combinedData[i].y;
  698. }
  699. }
  700. for (var xpos in intersections) {
  701. if (intersections.hasOwnProperty(xpos)) {
  702. yMin = yMin > intersections[xpos].accumulated ? intersections[xpos].accumulated : yMin;
  703. yMax = yMax < intersections[xpos].accumulated ? intersections[xpos].accumulated : yMax;
  704. }
  705. }
  706. return {min: yMin, max: yMax};
  707. };
  708. /**
  709. * this sets the Y ranges for the Y axis. It also determines which of the axis should be shown or hidden.
  710. * @param {Array} groupIds
  711. * @param {Object} groupRanges
  712. * @private
  713. */
  714. LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
  715. var changeCalled = false;
  716. var yAxisLeftUsed = false;
  717. var yAxisRightUsed = false;
  718. var minLeft = 1e9, minRight = 1e9, maxLeft = -1e9, maxRight = -1e9, minVal, maxVal;
  719. // if groups are present
  720. if (groupIds.length > 0) {
  721. for (var i = 0; i < groupIds.length; i++) {
  722. if (groupRanges.hasOwnProperty(groupIds[i])) {
  723. if (groupRanges[groupIds[i]].ignore !== true) {
  724. minVal = groupRanges[groupIds[i]].min;
  725. maxVal = groupRanges[groupIds[i]].max;
  726. if (groupRanges[groupIds[i]].yAxisOrientation == 'left') {
  727. yAxisLeftUsed = true;
  728. minLeft = minLeft > minVal ? minVal : minLeft;
  729. maxLeft = maxLeft < maxVal ? maxVal : maxLeft;
  730. }
  731. else {
  732. yAxisRightUsed = true;
  733. minRight = minRight > minVal ? minVal : minRight;
  734. maxRight = maxRight < maxVal ? maxVal : maxRight;
  735. }
  736. }
  737. }
  738. }
  739. if (yAxisLeftUsed == true) {
  740. this.yAxisLeft.setRange(minLeft, maxLeft);
  741. }
  742. if (yAxisRightUsed == true) {
  743. this.yAxisRight.setRange(minRight, maxRight);
  744. }
  745. }
  746. changeCalled = this._toggleAxisVisiblity(yAxisLeftUsed , this.yAxisLeft) || changeCalled;
  747. changeCalled = this._toggleAxisVisiblity(yAxisRightUsed, this.yAxisRight) || changeCalled;
  748. if (yAxisRightUsed == true && yAxisLeftUsed == true) {
  749. this.yAxisLeft.drawIcons = true;
  750. this.yAxisRight.drawIcons = true;
  751. }
  752. else {
  753. this.yAxisLeft.drawIcons = false;
  754. this.yAxisRight.drawIcons = false;
  755. }
  756. this.yAxisRight.master = !yAxisLeftUsed;
  757. if (this.yAxisRight.master == false) {
  758. if (yAxisRightUsed == true) {this.yAxisLeft.lineOffset = this.yAxisRight.width;}
  759. else {this.yAxisLeft.lineOffset = 0;}
  760. changeCalled = this.yAxisLeft.redraw() || changeCalled;
  761. this.yAxisRight.stepPixelsForced = this.yAxisLeft.stepPixels;
  762. changeCalled = this.yAxisRight.redraw() || changeCalled;
  763. }
  764. else {
  765. changeCalled = this.yAxisRight.redraw() || changeCalled;
  766. }
  767. // clean the accumulated lists
  768. if (groupIds.indexOf("__barchartLeft") != -1) {
  769. groupIds.splice(groupIds.indexOf("__barchartLeft"),1);
  770. }
  771. if (groupIds.indexOf("__barchartRight") != -1) {
  772. groupIds.splice(groupIds.indexOf("__barchartRight"),1);
  773. }
  774. return changeCalled;
  775. };
  776. /**
  777. * This shows or hides the Y axis if needed. If there is a change, the changed event is emitted by the updateYAxis function
  778. *
  779. * @param {boolean} axisUsed
  780. * @returns {boolean}
  781. * @private
  782. * @param axis
  783. */
  784. LineGraph.prototype._toggleAxisVisiblity = function (axisUsed, axis) {
  785. var changed = false;
  786. if (axisUsed == false) {
  787. if (axis.dom.frame.parentNode) {
  788. axis.hide();
  789. changed = true;
  790. }
  791. }
  792. else {
  793. if (!axis.dom.frame.parentNode) {
  794. axis.show();
  795. changed = true;
  796. }
  797. }
  798. return changed;
  799. };
  800. /**
  801. * draw a bar graph
  802. *
  803. * @param groupIds
  804. * @param processedGroupData
  805. */
  806. LineGraph.prototype._drawBarGraphs = function (groupIds, processedGroupData) {
  807. var combinedData = [];
  808. var intersections = {};
  809. var coreDistance;
  810. var key, drawData;
  811. var group;
  812. var i,j;
  813. var barPoints = 0;
  814. // combine all barchart data
  815. for (i = 0; i < groupIds.length; i++) {
  816. group = this.groups[groupIds[i]];
  817. if (group.options.style == 'bar') {
  818. if (group.visible == true && (this.options.groups.visibility[groupIds[i]] === undefined || this.options.groups.visibility[groupIds[i]] == true)) {
  819. for (j = 0; j < processedGroupData[groupIds[i]].length; j++) {
  820. combinedData.push({
  821. x: processedGroupData[groupIds[i]][j].x,
  822. y: processedGroupData[groupIds[i]][j].y,
  823. groupId: groupIds[i]
  824. });
  825. barPoints += 1;
  826. }
  827. }
  828. }
  829. }
  830. if (barPoints == 0) {return;}
  831. // sort by time and by group
  832. combinedData.sort(function (a, b) {
  833. if (a.x == b.x) {
  834. return a.groupId - b.groupId;
  835. } else {
  836. return a.x - b.x;
  837. }
  838. });
  839. // get intersections
  840. this._getDataIntersections(intersections, combinedData);
  841. // plot barchart
  842. for (i = 0; i < combinedData.length; i++) {
  843. group = this.groups[combinedData[i].groupId];
  844. var minWidth = 0.1 * group.options.barChart.width;
  845. key = combinedData[i].x;
  846. var heightOffset = 0;
  847. if (intersections[key] === undefined) {
  848. if (i+1 < combinedData.length) {coreDistance = Math.abs(combinedData[i+1].x - key);}
  849. if (i > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[i-1].x - key));}
  850. drawData = this._getSafeDrawData(coreDistance, group, minWidth);
  851. }
  852. else {
  853. var nextKey = i + (intersections[key].amount - intersections[key].resolved);
  854. var prevKey = i - (intersections[key].resolved + 1);
  855. if (nextKey < combinedData.length) {coreDistance = Math.abs(combinedData[nextKey].x - key);}
  856. if (prevKey > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[prevKey].x - key));}
  857. drawData = this._getSafeDrawData(coreDistance, group, minWidth);
  858. intersections[key].resolved += 1;
  859. if (group.options.barChart.handleOverlap == 'stack') {
  860. heightOffset = intersections[key].accumulated;
  861. intersections[key].accumulated += group.zeroPosition - combinedData[i].y;
  862. }
  863. else if (group.options.barChart.handleOverlap == 'sideBySide') {
  864. drawData.width = drawData.width / intersections[key].amount;
  865. drawData.offset += (intersections[key].resolved) * drawData.width - (0.5*drawData.width * (intersections[key].amount+1));
  866. if (group.options.barChart.align == 'left') {drawData.offset -= 0.5*drawData.width;}
  867. else if (group.options.barChart.align == 'right') {drawData.offset += 0.5*drawData.width;}
  868. }
  869. }
  870. DOMutil.drawBar(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].y, group.className + ' bar', this.svgElements, this.svg);
  871. // draw points
  872. if (group.options.drawPoints.enabled == true) {
  873. DOMutil.drawPoint(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, group, this.svgElements, this.svg);
  874. }
  875. }
  876. };
  877. /**
  878. * Fill the intersections object with counters of how many datapoints share the same x coordinates
  879. * @param intersections
  880. * @param combinedData
  881. * @private
  882. */
  883. LineGraph.prototype._getDataIntersections = function (intersections, combinedData) {
  884. // get intersections
  885. var coreDistance;
  886. for (var i = 0; i < combinedData.length; i++) {
  887. if (i + 1 < combinedData.length) {
  888. coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
  889. }
  890. if (i > 0) {
  891. coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
  892. }
  893. if (coreDistance == 0) {
  894. if (intersections[combinedData[i].x] === undefined) {
  895. intersections[combinedData[i].x] = {amount: 0, resolved: 0, accumulated: 0};
  896. }
  897. intersections[combinedData[i].x].amount += 1;
  898. }
  899. }
  900. };
  901. /**
  902. * Get the width and offset for bargraphs based on the coredistance between datapoints
  903. *
  904. * @param coreDistance
  905. * @param group
  906. * @param minWidth
  907. * @returns {{width: Number, offset: Number}}
  908. * @private
  909. */
  910. LineGraph.prototype._getSafeDrawData = function (coreDistance, group, minWidth) {
  911. var width, offset;
  912. if (coreDistance < group.options.barChart.width && coreDistance > 0) {
  913. width = coreDistance < minWidth ? minWidth : coreDistance;
  914. offset = 0; // recalculate offset with the new width;
  915. if (group.options.barChart.align == 'left') {
  916. offset -= 0.5 * coreDistance;
  917. }
  918. else if (group.options.barChart.align == 'right') {
  919. offset += 0.5 * coreDistance;
  920. }
  921. }
  922. else {
  923. // default settings
  924. width = group.options.barChart.width;
  925. offset = 0;
  926. if (group.options.barChart.align == 'left') {
  927. offset -= 0.5 * group.options.barChart.width;
  928. }
  929. else if (group.options.barChart.align == 'right') {
  930. offset += 0.5 * group.options.barChart.width;
  931. }
  932. }
  933. return {width: width, offset: offset};
  934. };
  935. /**
  936. * draw a line graph
  937. *
  938. * @param dataset
  939. * @param group
  940. */
  941. LineGraph.prototype._drawLineGraph = function (dataset, group) {
  942. if (dataset != null) {
  943. if (dataset.length > 0) {
  944. var path, d;
  945. var svgHeight = Number(this.svg.style.height.replace("px",""));
  946. path = DOMutil.getSVGElement('path', this.svgElements, this.svg);
  947. path.setAttributeNS(null, "class", group.className);
  948. // construct path from dataset
  949. if (group.options.catmullRom.enabled == true) {
  950. d = this._catmullRom(dataset, group);
  951. }
  952. else {
  953. d = this._linear(dataset);
  954. }
  955. // append with points for fill and finalize the path
  956. if (group.options.shaded.enabled == true) {
  957. var fillPath = DOMutil.getSVGElement('path',this.svgElements, this.svg);
  958. var dFill;
  959. if (group.options.shaded.orientation == 'top') {
  960. dFill = "M" + dataset[0].x + "," + 0 + " " + d + "L" + dataset[dataset.length - 1].x + "," + 0;
  961. }
  962. else {
  963. dFill = "M" + dataset[0].x + "," + svgHeight + " " + d + "L" + dataset[dataset.length - 1].x + "," + svgHeight;
  964. }
  965. fillPath.setAttributeNS(null, "class", group.className + " fill");
  966. fillPath.setAttributeNS(null, "d", dFill);
  967. }
  968. // copy properties to path for drawing.
  969. path.setAttributeNS(null, "d", "M" + d);
  970. // draw points
  971. if (group.options.drawPoints.enabled == true) {
  972. this._drawPoints(dataset, group, this.svgElements, this.svg);
  973. }
  974. }
  975. }
  976. };
  977. /**
  978. * draw the data points
  979. *
  980. * @param {Array} dataset
  981. * @param {Object} JSONcontainer
  982. * @param {Object} svg | SVG DOM element
  983. * @param {GraphGroup} group
  984. * @param {Number} [offset]
  985. */
  986. LineGraph.prototype._drawPoints = function (dataset, group, JSONcontainer, svg, offset) {
  987. if (offset === undefined) {offset = 0;}
  988. for (var i = 0; i < dataset.length; i++) {
  989. DOMutil.drawPoint(dataset[i].x + offset, dataset[i].y, group, JSONcontainer, svg);
  990. }
  991. };
  992. /**
  993. * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
  994. * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
  995. * the yAxis.
  996. *
  997. * @param datapoints
  998. * @returns {Array}
  999. * @private
  1000. */
  1001. LineGraph.prototype._convertXcoordinates = function (datapoints) {
  1002. var extractedData = [];
  1003. var xValue, yValue;
  1004. var toScreen = this.body.util.toScreen;
  1005. for (var i = 0; i < datapoints.length; i++) {
  1006. xValue = toScreen(datapoints[i].x) + this.width;
  1007. yValue = datapoints[i].y;
  1008. extractedData.push({x: xValue, y: yValue});
  1009. }
  1010. return extractedData;
  1011. };
  1012. /**
  1013. * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
  1014. * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
  1015. * the yAxis.
  1016. *
  1017. * @param datapoints
  1018. * @returns {Array}
  1019. * @private
  1020. */
  1021. LineGraph.prototype._convertYcoordinates = function (datapoints, group) {
  1022. var extractedData = [];
  1023. var xValue, yValue;
  1024. var toScreen = this.body.util.toScreen;
  1025. var axis = this.yAxisLeft;
  1026. var svgHeight = Number(this.svg.style.height.replace("px",""));
  1027. if (group.options.yAxisOrientation == 'right') {
  1028. axis = this.yAxisRight;
  1029. }
  1030. for (var i = 0; i < datapoints.length; i++) {
  1031. xValue = toScreen(datapoints[i].x) + this.width;
  1032. yValue = Math.round(axis.convertValue(datapoints[i].y));
  1033. extractedData.push({x: xValue, y: yValue});
  1034. }
  1035. group.setZeroPosition(Math.min(svgHeight, axis.convertValue(0)));
  1036. return extractedData;
  1037. };
  1038. /**
  1039. * This uses an uniform parametrization of the CatmullRom algorithm:
  1040. * "On the Parameterization of Catmull-Rom Curves" by Cem Yuksel et al.
  1041. * @param data
  1042. * @returns {string}
  1043. * @private
  1044. */
  1045. LineGraph.prototype._catmullRomUniform = function(data) {
  1046. // catmull rom
  1047. var p0, p1, p2, p3, bp1, bp2;
  1048. var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
  1049. var normalization = 1/6;
  1050. var length = data.length;
  1051. for (var i = 0; i < length - 1; i++) {
  1052. p0 = (i == 0) ? data[0] : data[i-1];
  1053. p1 = data[i];
  1054. p2 = data[i+1];
  1055. p3 = (i + 2 < length) ? data[i+2] : p2;
  1056. // Catmull-Rom to Cubic Bezier conversion matrix
  1057. // 0 1 0 0
  1058. // -1/6 1 1/6 0
  1059. // 0 1/6 1 -1/6
  1060. // 0 0 1 0
  1061. // bp0 = { x: p1.x, y: p1.y };
  1062. bp1 = { x: ((-p0.x + 6*p1.x + p2.x) *normalization), y: ((-p0.y + 6*p1.y + p2.y) *normalization)};
  1063. bp2 = { x: (( p1.x + 6*p2.x - p3.x) *normalization), y: (( p1.y + 6*p2.y - p3.y) *normalization)};
  1064. // bp0 = { x: p2.x, y: p2.y };
  1065. d += "C" +
  1066. bp1.x + "," +
  1067. bp1.y + " " +
  1068. bp2.x + "," +
  1069. bp2.y + " " +
  1070. p2.x + "," +
  1071. p2.y + " ";
  1072. }
  1073. return d;
  1074. };
  1075. /**
  1076. * This uses either the chordal or centripetal parameterization of the catmull-rom algorithm.
  1077. * By default, the centripetal parameterization is used because this gives the nicest results.
  1078. * These parameterizations are relatively heavy because the distance between 4 points have to be calculated.
  1079. *
  1080. * One optimization can be used to reuse distances since this is a sliding window approach.
  1081. * @param data
  1082. * @returns {string}
  1083. * @private
  1084. */
  1085. LineGraph.prototype._catmullRom = function(data, group) {
  1086. var alpha = group.options.catmullRom.alpha;
  1087. if (alpha == 0 || alpha === undefined) {
  1088. return this._catmullRomUniform(data);
  1089. }
  1090. else {
  1091. var p0, p1, p2, p3, bp1, bp2, d1,d2,d3, A, B, N, M;
  1092. var d3powA, d2powA, d3pow2A, d2pow2A, d1pow2A, d1powA;
  1093. var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
  1094. var length = data.length;
  1095. for (var i = 0; i < length - 1; i++) {
  1096. p0 = (i == 0) ? data[0] : data[i-1];
  1097. p1 = data[i];
  1098. p2 = data[i+1];
  1099. p3 = (i + 2 < length) ? data[i+2] : p2;
  1100. d1 = Math.sqrt(Math.pow(p0.x - p1.x,2) + Math.pow(p0.y - p1.y,2));
  1101. d2 = Math.sqrt(Math.pow(p1.x - p2.x,2) + Math.pow(p1.y - p2.y,2));
  1102. d3 = Math.sqrt(Math.pow(p2.x - p3.x,2) + Math.pow(p2.y - p3.y,2));
  1103. // Catmull-Rom to Cubic Bezier conversion matrix
  1104. //
  1105. // A = 2d1^2a + 3d1^a * d2^a + d3^2a
  1106. // B = 2d3^2a + 3d3^a * d2^a + d2^2a
  1107. //
  1108. // [ 0 1 0 0 ]
  1109. // [ -d2^2a/N A/N d1^2a/N 0 ]
  1110. // [ 0 d3^2a/M B/M -d2^2a/M ]
  1111. // [ 0 0 1 0 ]
  1112. // [ 0 1 0 0 ]
  1113. // [ -d2pow2a/N A/N d1pow2a/N 0 ]
  1114. // [ 0 d3pow2a/M B/M -d2pow2a/M ]
  1115. // [ 0 0 1 0 ]
  1116. d3powA = Math.pow(d3, alpha);
  1117. d3pow2A = Math.pow(d3,2*alpha);
  1118. d2powA = Math.pow(d2, alpha);
  1119. d2pow2A = Math.pow(d2,2*alpha);
  1120. d1powA = Math.pow(d1, alpha);
  1121. d1pow2A = Math.pow(d1,2*alpha);
  1122. A = 2*d1pow2A + 3*d1powA * d2powA + d2pow2A;
  1123. B = 2*d3pow2A + 3*d3powA * d2powA + d2pow2A;
  1124. N = 3*d1powA * (d1powA + d2powA);
  1125. if (N > 0) {N = 1 / N;}
  1126. M = 3*d3powA * (d3powA + d2powA);
  1127. if (M > 0) {M = 1 / M;}
  1128. bp1 = { x: ((-d2pow2A * p0.x + A*p1.x + d1pow2A * p2.x) * N),
  1129. y: ((-d2pow2A * p0.y + A*p1.y + d1pow2A * p2.y) * N)};
  1130. bp2 = { x: (( d3pow2A * p1.x + B*p2.x - d2pow2A * p3.x) * M),
  1131. y: (( d3pow2A * p1.y + B*p2.y - d2pow2A * p3.y) * M)};
  1132. if (bp1.x == 0 && bp1.y == 0) {bp1 = p1;}
  1133. if (bp2.x == 0 && bp2.y == 0) {bp2 = p2;}
  1134. d += "C" +
  1135. bp1.x + "," +
  1136. bp1.y + " " +
  1137. bp2.x + "," +
  1138. bp2.y + " " +
  1139. p2.x + "," +
  1140. p2.y + " ";
  1141. }
  1142. return d;
  1143. }
  1144. };
  1145. /**
  1146. * this generates the SVG path for a linear drawing between datapoints.
  1147. * @param data
  1148. * @returns {string}
  1149. * @private
  1150. */
  1151. LineGraph.prototype._linear = function(data) {
  1152. // linear
  1153. var d = "";
  1154. for (var i = 0; i < data.length; i++) {
  1155. if (i == 0) {
  1156. d += data[i].x + "," + data[i].y;
  1157. }
  1158. else {
  1159. d += " " + data[i].x + "," + data[i].y;
  1160. }
  1161. }
  1162. return d;
  1163. };
  1164. module.exports = LineGraph;