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.

1303 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. console.log('redraw')
  446. var resized = false;
  447. this.svg.style.height = ('' + this.options.graphHeight).replace('px','') + 'px';
  448. if (this.lastWidth === undefined && this.width || this.lastWidth != this.width) {
  449. resized = true;
  450. }
  451. // check if this component is resized
  452. resized = this._isResized() || resized;
  453. // check whether zoomed (in that case we need to re-stack everything)
  454. var visibleInterval = this.body.range.end - this.body.range.start;
  455. var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.width != this.lastWidth);
  456. this.lastVisibleInterval = visibleInterval;
  457. this.lastWidth = this.width;
  458. // calculate actual size and position
  459. this.width = this.dom.frame.offsetWidth;
  460. // the svg element is three times as big as the width, this allows for fully dragging left and right
  461. // without reloading the graph. the controls for this are bound to events in the constructor
  462. if (resized == true) {
  463. this.svg.style.width = util.option.asSize(3*this.width);
  464. this.svg.style.left = util.option.asSize(-this.width);
  465. }
  466. if (zoomed == true || this.abortedGraphUpdate == true) {
  467. this._updateGraph();
  468. }
  469. else {
  470. // move the whole svg while dragging
  471. if (this.lastStart != 0) {
  472. var offset = this.body.range.start - this.lastStart;
  473. var range = this.body.range.end - this.body.range.start;
  474. if (this.width != 0) {
  475. var rangePerPixelInv = this.width/range;
  476. var xOffset = offset * rangePerPixelInv;
  477. this.svg.style.left = (-this.width - xOffset) + "px";
  478. }
  479. }
  480. }
  481. this.legendLeft.redraw();
  482. this.legendRight.redraw();
  483. return resized;
  484. };
  485. /**
  486. * Update and redraw the graph.
  487. *
  488. */
  489. LineGraph.prototype._updateGraph = function () {
  490. // reset the svg elements
  491. DOMutil.prepareElements(this.svgElements);
  492. if (this.width != 0 && this.itemsData != null) {
  493. var group, i;
  494. var preprocessedGroupData = {};
  495. var processedGroupData = {};
  496. var groupRanges = {};
  497. var changeCalled = false;
  498. // getting group Ids
  499. var groupIds = [];
  500. for (var groupId in this.groups) {
  501. if (this.groups.hasOwnProperty(groupId)) {
  502. group = this.groups[groupId];
  503. if (group.visible == true && (this.options.groups.visibility[groupId] === undefined || this.options.groups.visibility[groupId] == true)) {
  504. groupIds.push(groupId);
  505. }
  506. }
  507. }
  508. if (groupIds.length > 0) {
  509. // this is the range of the SVG canvas
  510. var minDate = this.body.util.toGlobalTime(- this.body.domProps.root.width);
  511. var maxDate = this.body.util.toGlobalTime(2 * this.body.domProps.root.width);
  512. var groupsData = {};
  513. // fill groups data
  514. this._getRelevantData(groupIds, groupsData, minDate, maxDate);
  515. // we transform the X coordinates to detect collisions
  516. for (i = 0; i < groupIds.length; i++) {
  517. preprocessedGroupData[groupIds[i]] = this._convertXcoordinates(groupsData[groupIds[i]]);
  518. }
  519. // now all needed data has been collected we start the processing.
  520. this._getYRanges(groupIds, preprocessedGroupData, groupRanges);
  521. // update the Y axis first, we use this data to draw at the correct Y points
  522. // changeCalled is required to clean the SVG on a change emit.
  523. changeCalled = this._updateYAxis(groupIds, groupRanges);
  524. if (changeCalled == true) {
  525. DOMutil.cleanupElements(this.svgElements);
  526. this.abortedGraphUpdate = true;
  527. this.body.emitter.emit("change");
  528. return;
  529. }
  530. this.abortedGraphUpdate = false;
  531. // With the yAxis scaled correctly, use this to get the Y values of the points.
  532. for (i = 0; i < groupIds.length; i++) {
  533. group = this.groups[groupIds[i]];
  534. processedGroupData[groupIds[i]] = this._convertYcoordinates(groupsData[groupIds[i]], group);
  535. }
  536. // draw the groups
  537. for (i = 0; i < groupIds.length; i++) {
  538. group = this.groups[groupIds[i]];
  539. if (group.options.style == 'line') {
  540. this._drawLineGraph(processedGroupData[groupIds[i]], group);
  541. }
  542. }
  543. this._drawBarGraphs(groupIds, processedGroupData);
  544. }
  545. }
  546. // cleanup unused svg elements
  547. DOMutil.cleanupElements(this.svgElements);
  548. };
  549. LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate, maxDate) {
  550. // first select and preprocess the data from the datasets.
  551. // the groups have their preselection of data, we now loop over this data to see
  552. // what data we need to draw. Sorted data is much faster.
  553. // more optimization is possible by doing the sampling before and using the binary search
  554. // to find the end date to determine the increment.
  555. var group, i, j, item;
  556. if (groupIds.length > 0) {
  557. for (i = 0; i < groupIds.length; i++) {
  558. group = this.groups[groupIds[i]];
  559. groupsData[groupIds[i]] = [];
  560. var dataContainer = groupsData[groupIds[i]];
  561. // optimization for sorted data
  562. if (group.options.sort == true) {
  563. var guess = Math.max(0, util.binarySearchGeneric(group.itemsData, minDate, 'x', 'before'));
  564. for (j = guess; j < group.itemsData.length; j++) {
  565. item = group.itemsData[j];
  566. if (item !== undefined) {
  567. if (item.x > maxDate) {
  568. dataContainer.push(item);
  569. break;
  570. }
  571. else {
  572. dataContainer.push(item);
  573. }
  574. }
  575. }
  576. }
  577. else {
  578. for (j = 0; j < group.itemsData.length; j++) {
  579. item = group.itemsData[j];
  580. if (item !== undefined) {
  581. if (item.x > minDate && item.x < maxDate) {
  582. dataContainer.push(item);
  583. }
  584. }
  585. }
  586. }
  587. }
  588. }
  589. this._applySampling(groupIds, groupsData);
  590. };
  591. LineGraph.prototype._applySampling = function (groupIds, groupsData) {
  592. var group;
  593. if (groupIds.length > 0) {
  594. for (var i = 0; i < groupIds.length; i++) {
  595. group = this.groups[groupIds[i]];
  596. if (group.options.sampling == true) {
  597. var dataContainer = groupsData[groupIds[i]];
  598. if (dataContainer.length > 0) {
  599. var increment = 1;
  600. var amountOfPoints = dataContainer.length;
  601. // the global screen is used because changing the width of the yAxis may affect the increment, resulting in an endless loop
  602. // of width changing of the yAxis.
  603. var xDistance = this.body.util.toGlobalScreen(dataContainer[dataContainer.length - 1].x) - this.body.util.toGlobalScreen(dataContainer[0].x);
  604. var pointsPerPixel = amountOfPoints / xDistance;
  605. increment = Math.min(Math.ceil(0.2 * amountOfPoints), Math.max(1, Math.round(pointsPerPixel)));
  606. var sampledData = [];
  607. for (var j = 0; j < amountOfPoints; j += increment) {
  608. sampledData.push(dataContainer[j]);
  609. }
  610. groupsData[groupIds[i]] = sampledData;
  611. }
  612. }
  613. }
  614. }
  615. };
  616. LineGraph.prototype._getYRanges = function (groupIds, groupsData, groupRanges) {
  617. var groupData, group, i,j;
  618. var barCombinedDataLeft = [];
  619. var barCombinedDataRight = [];
  620. var barCombinedData;
  621. if (groupIds.length > 0) {
  622. for (i = 0; i < groupIds.length; i++) {
  623. groupData = groupsData[groupIds[i]];
  624. if (groupData.length > 0) {
  625. group = this.groups[groupIds[i]];
  626. if (group.options.style == 'line' || group.options.barChart.handleOverlap != "stack") {
  627. var yMin = groupData[0].y;
  628. var yMax = groupData[0].y;
  629. for (j = 0; j < groupData.length; j++) {
  630. yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
  631. yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
  632. }
  633. groupRanges[groupIds[i]] = {min: yMin, max: yMax, yAxisOrientation: group.options.yAxisOrientation};
  634. }
  635. else if (group.options.style == 'bar') {
  636. if (group.options.yAxisOrientation == 'left') {
  637. barCombinedData = barCombinedDataLeft;
  638. }
  639. else {
  640. barCombinedData = barCombinedDataRight;
  641. }
  642. groupRanges[groupIds[i]] = {min: 0, max: 0, yAxisOrientation: group.options.yAxisOrientation, ignore: true};
  643. // combine data
  644. for (j = 0; j < groupData.length; j++) {
  645. barCombinedData.push({
  646. x: groupData[j].x,
  647. y: groupData[j].y,
  648. groupId: groupIds[i]
  649. });
  650. }
  651. }
  652. }
  653. }
  654. var intersections;
  655. if (barCombinedDataLeft.length > 0) {
  656. // sort by time and by group
  657. barCombinedDataLeft.sort(function (a, b) {
  658. if (a.x == b.x) {
  659. return a.groupId - b.groupId;
  660. } else {
  661. return a.x - b.x;
  662. }
  663. });
  664. intersections = {};
  665. this._getDataIntersections(intersections, barCombinedDataLeft);
  666. groupRanges["__barchartLeft"] = this._getStackedBarYRange(intersections, barCombinedDataLeft);
  667. groupRanges["__barchartLeft"].yAxisOrientation = "left";
  668. groupIds.push("__barchartLeft");
  669. }
  670. if (barCombinedDataRight.length > 0) {
  671. // sort by time and by group
  672. barCombinedDataRight.sort(function (a, b) {
  673. if (a.x == b.x) {
  674. return a.groupId - b.groupId;
  675. } else {
  676. return a.x - b.x;
  677. }
  678. });
  679. intersections = {};
  680. this._getDataIntersections(intersections, barCombinedDataRight);
  681. groupRanges["__barchartRight"] = this._getStackedBarYRange(intersections, barCombinedDataRight);
  682. groupRanges["__barchartRight"].yAxisOrientation = "right";
  683. groupIds.push("__barchartRight");
  684. }
  685. }
  686. };
  687. LineGraph.prototype._getStackedBarYRange = function (intersections, combinedData) {
  688. var key;
  689. var yMin = combinedData[0].y;
  690. var yMax = combinedData[0].y;
  691. for (var i = 0; i < combinedData.length; i++) {
  692. key = combinedData[i].x;
  693. if (intersections[key] === undefined) {
  694. yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
  695. yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
  696. }
  697. else {
  698. intersections[key].accumulated += combinedData[i].y;
  699. }
  700. }
  701. for (var xpos in intersections) {
  702. if (intersections.hasOwnProperty(xpos)) {
  703. yMin = yMin > intersections[xpos].accumulated ? intersections[xpos].accumulated : yMin;
  704. yMax = yMax < intersections[xpos].accumulated ? intersections[xpos].accumulated : yMax;
  705. }
  706. }
  707. return {min: yMin, max: yMax};
  708. };
  709. /**
  710. * this sets the Y ranges for the Y axis. It also determines which of the axis should be shown or hidden.
  711. * @param {Array} groupIds
  712. * @param {Object} groupRanges
  713. * @private
  714. */
  715. LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
  716. var changeCalled = false;
  717. var yAxisLeftUsed = false;
  718. var yAxisRightUsed = false;
  719. var minLeft = 1e9, minRight = 1e9, maxLeft = -1e9, maxRight = -1e9, minVal, maxVal;
  720. // if groups are present
  721. if (groupIds.length > 0) {
  722. for (var i = 0; i < groupIds.length; i++) {
  723. if (groupRanges.hasOwnProperty(groupIds[i])) {
  724. if (groupRanges[groupIds[i]].ignore !== true) {
  725. minVal = groupRanges[groupIds[i]].min;
  726. maxVal = groupRanges[groupIds[i]].max;
  727. if (groupRanges[groupIds[i]].yAxisOrientation == 'left') {
  728. yAxisLeftUsed = true;
  729. minLeft = minLeft > minVal ? minVal : minLeft;
  730. maxLeft = maxLeft < maxVal ? maxVal : maxLeft;
  731. }
  732. else {
  733. yAxisRightUsed = true;
  734. minRight = minRight > minVal ? minVal : minRight;
  735. maxRight = maxRight < maxVal ? maxVal : maxRight;
  736. }
  737. }
  738. }
  739. }
  740. if (yAxisLeftUsed == true) {
  741. this.yAxisLeft.setRange(minLeft, maxLeft);
  742. }
  743. if (yAxisRightUsed == true) {
  744. this.yAxisRight.setRange(minRight, maxRight);
  745. }
  746. }
  747. changeCalled = this._toggleAxisVisiblity(yAxisLeftUsed , this.yAxisLeft) || changeCalled;
  748. changeCalled = this._toggleAxisVisiblity(yAxisRightUsed, this.yAxisRight) || changeCalled;
  749. if (yAxisRightUsed == true && yAxisLeftUsed == true) {
  750. this.yAxisLeft.drawIcons = true;
  751. this.yAxisRight.drawIcons = true;
  752. }
  753. else {
  754. this.yAxisLeft.drawIcons = false;
  755. this.yAxisRight.drawIcons = false;
  756. }
  757. this.yAxisRight.master = !yAxisLeftUsed;
  758. if (this.yAxisRight.master == false) {
  759. if (yAxisRightUsed == true) {this.yAxisLeft.lineOffset = this.yAxisRight.width;}
  760. else {this.yAxisLeft.lineOffset = 0;}
  761. changeCalled = this.yAxisLeft.redraw() || changeCalled;
  762. this.yAxisRight.stepPixelsForced = this.yAxisLeft.stepPixels;
  763. changeCalled = this.yAxisRight.redraw() || changeCalled;
  764. }
  765. else {
  766. changeCalled = this.yAxisRight.redraw() || changeCalled;
  767. }
  768. // clean the accumulated lists
  769. if (groupIds.indexOf("__barchartLeft") != -1) {
  770. groupIds.splice(groupIds.indexOf("__barchartLeft"),1);
  771. }
  772. if (groupIds.indexOf("__barchartRight") != -1) {
  773. groupIds.splice(groupIds.indexOf("__barchartRight"),1);
  774. }
  775. return changeCalled;
  776. };
  777. /**
  778. * This shows or hides the Y axis if needed. If there is a change, the changed event is emitted by the updateYAxis function
  779. *
  780. * @param {boolean} axisUsed
  781. * @returns {boolean}
  782. * @private
  783. * @param axis
  784. */
  785. LineGraph.prototype._toggleAxisVisiblity = function (axisUsed, axis) {
  786. var changed = false;
  787. if (axisUsed == false) {
  788. if (axis.dom.frame.parentNode) {
  789. axis.hide();
  790. changed = true;
  791. }
  792. }
  793. else {
  794. if (!axis.dom.frame.parentNode) {
  795. axis.show();
  796. changed = true;
  797. }
  798. }
  799. return changed;
  800. };
  801. /**
  802. * draw a bar graph
  803. *
  804. * @param groupIds
  805. * @param processedGroupData
  806. */
  807. LineGraph.prototype._drawBarGraphs = function (groupIds, processedGroupData) {
  808. var combinedData = [];
  809. var intersections = {};
  810. var coreDistance;
  811. var key, drawData;
  812. var group;
  813. var i,j;
  814. var barPoints = 0;
  815. // combine all barchart data
  816. for (i = 0; i < groupIds.length; i++) {
  817. group = this.groups[groupIds[i]];
  818. if (group.options.style == 'bar') {
  819. if (group.visible == true && (this.options.groups.visibility[groupIds[i]] === undefined || this.options.groups.visibility[groupIds[i]] == true)) {
  820. for (j = 0; j < processedGroupData[groupIds[i]].length; j++) {
  821. combinedData.push({
  822. x: processedGroupData[groupIds[i]][j].x,
  823. y: processedGroupData[groupIds[i]][j].y,
  824. groupId: groupIds[i]
  825. });
  826. barPoints += 1;
  827. }
  828. }
  829. }
  830. }
  831. if (barPoints == 0) {return;}
  832. // sort by time and by group
  833. combinedData.sort(function (a, b) {
  834. if (a.x == b.x) {
  835. return a.groupId - b.groupId;
  836. } else {
  837. return a.x - b.x;
  838. }
  839. });
  840. // get intersections
  841. this._getDataIntersections(intersections, combinedData);
  842. // plot barchart
  843. for (i = 0; i < combinedData.length; i++) {
  844. group = this.groups[combinedData[i].groupId];
  845. var minWidth = 0.1 * group.options.barChart.width;
  846. key = combinedData[i].x;
  847. var heightOffset = 0;
  848. if (intersections[key] === undefined) {
  849. if (i+1 < combinedData.length) {coreDistance = Math.abs(combinedData[i+1].x - key);}
  850. if (i > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[i-1].x - key));}
  851. drawData = this._getSafeDrawData(coreDistance, group, minWidth);
  852. }
  853. else {
  854. var nextKey = i + (intersections[key].amount - intersections[key].resolved);
  855. var prevKey = i - (intersections[key].resolved + 1);
  856. if (nextKey < combinedData.length) {coreDistance = Math.abs(combinedData[nextKey].x - key);}
  857. if (prevKey > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[prevKey].x - key));}
  858. drawData = this._getSafeDrawData(coreDistance, group, minWidth);
  859. intersections[key].resolved += 1;
  860. if (group.options.barChart.handleOverlap == 'stack') {
  861. heightOffset = intersections[key].accumulated;
  862. intersections[key].accumulated += group.zeroPosition - combinedData[i].y;
  863. }
  864. else if (group.options.barChart.handleOverlap == 'sideBySide') {
  865. drawData.width = drawData.width / intersections[key].amount;
  866. drawData.offset += (intersections[key].resolved) * drawData.width - (0.5*drawData.width * (intersections[key].amount+1));
  867. if (group.options.barChart.align == 'left') {drawData.offset -= 0.5*drawData.width;}
  868. else if (group.options.barChart.align == 'right') {drawData.offset += 0.5*drawData.width;}
  869. }
  870. }
  871. 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);
  872. // draw points
  873. if (group.options.drawPoints.enabled == true) {
  874. DOMutil.drawPoint(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, group, this.svgElements, this.svg);
  875. }
  876. }
  877. };
  878. /**
  879. * Fill the intersections object with counters of how many datapoints share the same x coordinates
  880. * @param intersections
  881. * @param combinedData
  882. * @private
  883. */
  884. LineGraph.prototype._getDataIntersections = function (intersections, combinedData) {
  885. // get intersections
  886. var coreDistance;
  887. for (var i = 0; i < combinedData.length; i++) {
  888. if (i + 1 < combinedData.length) {
  889. coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
  890. }
  891. if (i > 0) {
  892. coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
  893. }
  894. if (coreDistance == 0) {
  895. if (intersections[combinedData[i].x] === undefined) {
  896. intersections[combinedData[i].x] = {amount: 0, resolved: 0, accumulated: 0};
  897. }
  898. intersections[combinedData[i].x].amount += 1;
  899. }
  900. }
  901. };
  902. /**
  903. * Get the width and offset for bargraphs based on the coredistance between datapoints
  904. *
  905. * @param coreDistance
  906. * @param group
  907. * @param minWidth
  908. * @returns {{width: Number, offset: Number}}
  909. * @private
  910. */
  911. LineGraph.prototype._getSafeDrawData = function (coreDistance, group, minWidth) {
  912. var width, offset;
  913. if (coreDistance < group.options.barChart.width && coreDistance > 0) {
  914. width = coreDistance < minWidth ? minWidth : coreDistance;
  915. offset = 0; // recalculate offset with the new width;
  916. if (group.options.barChart.align == 'left') {
  917. offset -= 0.5 * coreDistance;
  918. }
  919. else if (group.options.barChart.align == 'right') {
  920. offset += 0.5 * coreDistance;
  921. }
  922. }
  923. else {
  924. // default settings
  925. width = group.options.barChart.width;
  926. offset = 0;
  927. if (group.options.barChart.align == 'left') {
  928. offset -= 0.5 * group.options.barChart.width;
  929. }
  930. else if (group.options.barChart.align == 'right') {
  931. offset += 0.5 * group.options.barChart.width;
  932. }
  933. }
  934. return {width: width, offset: offset};
  935. };
  936. /**
  937. * draw a line graph
  938. *
  939. * @param dataset
  940. * @param group
  941. */
  942. LineGraph.prototype._drawLineGraph = function (dataset, group) {
  943. if (dataset != null) {
  944. if (dataset.length > 0) {
  945. var path, d;
  946. var svgHeight = Number(this.svg.style.height.replace("px",""));
  947. path = DOMutil.getSVGElement('path', this.svgElements, this.svg);
  948. path.setAttributeNS(null, "class", group.className);
  949. // construct path from dataset
  950. if (group.options.catmullRom.enabled == true) {
  951. d = this._catmullRom(dataset, group);
  952. }
  953. else {
  954. d = this._linear(dataset);
  955. }
  956. // append with points for fill and finalize the path
  957. if (group.options.shaded.enabled == true) {
  958. var fillPath = DOMutil.getSVGElement('path',this.svgElements, this.svg);
  959. var dFill;
  960. if (group.options.shaded.orientation == 'top') {
  961. dFill = "M" + dataset[0].x + "," + 0 + " " + d + "L" + dataset[dataset.length - 1].x + "," + 0;
  962. }
  963. else {
  964. dFill = "M" + dataset[0].x + "," + svgHeight + " " + d + "L" + dataset[dataset.length - 1].x + "," + svgHeight;
  965. }
  966. fillPath.setAttributeNS(null, "class", group.className + " fill");
  967. fillPath.setAttributeNS(null, "d", dFill);
  968. }
  969. // copy properties to path for drawing.
  970. path.setAttributeNS(null, "d", "M" + d);
  971. // draw points
  972. if (group.options.drawPoints.enabled == true) {
  973. this._drawPoints(dataset, group, this.svgElements, this.svg);
  974. }
  975. }
  976. }
  977. };
  978. /**
  979. * draw the data points
  980. *
  981. * @param {Array} dataset
  982. * @param {Object} JSONcontainer
  983. * @param {Object} svg | SVG DOM element
  984. * @param {GraphGroup} group
  985. * @param {Number} [offset]
  986. */
  987. LineGraph.prototype._drawPoints = function (dataset, group, JSONcontainer, svg, offset) {
  988. if (offset === undefined) {offset = 0;}
  989. for (var i = 0; i < dataset.length; i++) {
  990. DOMutil.drawPoint(dataset[i].x + offset, dataset[i].y, group, JSONcontainer, svg);
  991. }
  992. };
  993. /**
  994. * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
  995. * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
  996. * the yAxis.
  997. *
  998. * @param datapoints
  999. * @returns {Array}
  1000. * @private
  1001. */
  1002. LineGraph.prototype._convertXcoordinates = function (datapoints) {
  1003. var extractedData = [];
  1004. var xValue, yValue;
  1005. var toScreen = this.body.util.toScreen;
  1006. for (var i = 0; i < datapoints.length; i++) {
  1007. xValue = toScreen(datapoints[i].x) + this.width - 1;
  1008. yValue = datapoints[i].y;
  1009. extractedData.push({x: xValue, y: yValue});
  1010. }
  1011. return extractedData;
  1012. };
  1013. /**
  1014. * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
  1015. * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
  1016. * the yAxis.
  1017. *
  1018. * @param datapoints
  1019. * @returns {Array}
  1020. * @private
  1021. */
  1022. LineGraph.prototype._convertYcoordinates = function (datapoints, group) {
  1023. var extractedData = [];
  1024. var xValue, yValue;
  1025. var toScreen = this.body.util.toScreen;
  1026. var axis = this.yAxisLeft;
  1027. var svgHeight = Number(this.svg.style.height.replace("px",""));
  1028. if (group.options.yAxisOrientation == 'right') {
  1029. axis = this.yAxisRight;
  1030. }
  1031. for (var i = 0; i < datapoints.length; i++) {
  1032. xValue = toScreen(datapoints[i].x) + this.width - 1;
  1033. yValue = Math.round(axis.convertValue(datapoints[i].y));
  1034. extractedData.push({x: xValue, y: yValue});
  1035. }
  1036. group.setZeroPosition(Math.min(svgHeight, axis.convertValue(0)));
  1037. return extractedData;
  1038. };
  1039. /**
  1040. * This uses an uniform parametrization of the CatmullRom algorithm:
  1041. * "On the Parameterization of Catmull-Rom Curves" by Cem Yuksel et al.
  1042. * @param data
  1043. * @returns {string}
  1044. * @private
  1045. */
  1046. LineGraph.prototype._catmullRomUniform = function(data) {
  1047. // catmull rom
  1048. var p0, p1, p2, p3, bp1, bp2;
  1049. var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
  1050. var normalization = 1/6;
  1051. var length = data.length;
  1052. for (var i = 0; i < length - 1; i++) {
  1053. p0 = (i == 0) ? data[0] : data[i-1];
  1054. p1 = data[i];
  1055. p2 = data[i+1];
  1056. p3 = (i + 2 < length) ? data[i+2] : p2;
  1057. // Catmull-Rom to Cubic Bezier conversion matrix
  1058. // 0 1 0 0
  1059. // -1/6 1 1/6 0
  1060. // 0 1/6 1 -1/6
  1061. // 0 0 1 0
  1062. // bp0 = { x: p1.x, y: p1.y };
  1063. bp1 = { x: ((-p0.x + 6*p1.x + p2.x) *normalization), y: ((-p0.y + 6*p1.y + p2.y) *normalization)};
  1064. bp2 = { x: (( p1.x + 6*p2.x - p3.x) *normalization), y: (( p1.y + 6*p2.y - p3.y) *normalization)};
  1065. // bp0 = { x: p2.x, y: p2.y };
  1066. d += "C" +
  1067. bp1.x + "," +
  1068. bp1.y + " " +
  1069. bp2.x + "," +
  1070. bp2.y + " " +
  1071. p2.x + "," +
  1072. p2.y + " ";
  1073. }
  1074. return d;
  1075. };
  1076. /**
  1077. * This uses either the chordal or centripetal parameterization of the catmull-rom algorithm.
  1078. * By default, the centripetal parameterization is used because this gives the nicest results.
  1079. * These parameterizations are relatively heavy because the distance between 4 points have to be calculated.
  1080. *
  1081. * One optimization can be used to reuse distances since this is a sliding window approach.
  1082. * @param data
  1083. * @returns {string}
  1084. * @private
  1085. */
  1086. LineGraph.prototype._catmullRom = function(data, group) {
  1087. var alpha = group.options.catmullRom.alpha;
  1088. if (alpha == 0 || alpha === undefined) {
  1089. return this._catmullRomUniform(data);
  1090. }
  1091. else {
  1092. var p0, p1, p2, p3, bp1, bp2, d1,d2,d3, A, B, N, M;
  1093. var d3powA, d2powA, d3pow2A, d2pow2A, d1pow2A, d1powA;
  1094. var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
  1095. var length = data.length;
  1096. for (var i = 0; i < length - 1; i++) {
  1097. p0 = (i == 0) ? data[0] : data[i-1];
  1098. p1 = data[i];
  1099. p2 = data[i+1];
  1100. p3 = (i + 2 < length) ? data[i+2] : p2;
  1101. d1 = Math.sqrt(Math.pow(p0.x - p1.x,2) + Math.pow(p0.y - p1.y,2));
  1102. d2 = Math.sqrt(Math.pow(p1.x - p2.x,2) + Math.pow(p1.y - p2.y,2));
  1103. d3 = Math.sqrt(Math.pow(p2.x - p3.x,2) + Math.pow(p2.y - p3.y,2));
  1104. // Catmull-Rom to Cubic Bezier conversion matrix
  1105. //
  1106. // A = 2d1^2a + 3d1^a * d2^a + d3^2a
  1107. // B = 2d3^2a + 3d3^a * d2^a + d2^2a
  1108. //
  1109. // [ 0 1 0 0 ]
  1110. // [ -d2^2a/N A/N d1^2a/N 0 ]
  1111. // [ 0 d3^2a/M B/M -d2^2a/M ]
  1112. // [ 0 0 1 0 ]
  1113. // [ 0 1 0 0 ]
  1114. // [ -d2pow2a/N A/N d1pow2a/N 0 ]
  1115. // [ 0 d3pow2a/M B/M -d2pow2a/M ]
  1116. // [ 0 0 1 0 ]
  1117. d3powA = Math.pow(d3, alpha);
  1118. d3pow2A = Math.pow(d3,2*alpha);
  1119. d2powA = Math.pow(d2, alpha);
  1120. d2pow2A = Math.pow(d2,2*alpha);
  1121. d1powA = Math.pow(d1, alpha);
  1122. d1pow2A = Math.pow(d1,2*alpha);
  1123. A = 2*d1pow2A + 3*d1powA * d2powA + d2pow2A;
  1124. B = 2*d3pow2A + 3*d3powA * d2powA + d2pow2A;
  1125. N = 3*d1powA * (d1powA + d2powA);
  1126. if (N > 0) {N = 1 / N;}
  1127. M = 3*d3powA * (d3powA + d2powA);
  1128. if (M > 0) {M = 1 / M;}
  1129. bp1 = { x: ((-d2pow2A * p0.x + A*p1.x + d1pow2A * p2.x) * N),
  1130. y: ((-d2pow2A * p0.y + A*p1.y + d1pow2A * p2.y) * N)};
  1131. bp2 = { x: (( d3pow2A * p1.x + B*p2.x - d2pow2A * p3.x) * M),
  1132. y: (( d3pow2A * p1.y + B*p2.y - d2pow2A * p3.y) * M)};
  1133. if (bp1.x == 0 && bp1.y == 0) {bp1 = p1;}
  1134. if (bp2.x == 0 && bp2.y == 0) {bp2 = p2;}
  1135. d += "C" +
  1136. bp1.x + "," +
  1137. bp1.y + " " +
  1138. bp2.x + "," +
  1139. bp2.y + " " +
  1140. p2.x + "," +
  1141. p2.y + " ";
  1142. }
  1143. return d;
  1144. }
  1145. };
  1146. /**
  1147. * this generates the SVG path for a linear drawing between datapoints.
  1148. * @param data
  1149. * @returns {string}
  1150. * @private
  1151. */
  1152. LineGraph.prototype._linear = function(data) {
  1153. // linear
  1154. var d = "";
  1155. for (var i = 0; i < data.length; i++) {
  1156. if (i == 0) {
  1157. d += data[i].x + "," + data[i].y;
  1158. }
  1159. else {
  1160. d += " " + data[i].x + "," + data[i].y;
  1161. }
  1162. }
  1163. return d;
  1164. };
  1165. module.exports = LineGraph;