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.

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