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.

514 lines
16 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
Implementation of a week scale feature (#3009) * Add Gitter badge (#2179) * do not generate source-maps in distribution version * add 'dist' folder for deployment * added Badges * added codeclimate badge * added @Tooa to the support team * added badges from isitmaintained.com (#2517) * do not ignore dist and test folders in master * generated dist files for v4.18.0 * generated dist files for v4.18.1 * Cheap fix for bug #2795 * Update to PR #2826 to use newline format * changed to v4.18.1-SNAPSHOT * chore(docs): general improvements (#2652) * removed NOTICE file * updated license date range to include 2017 * chore(docs): updated support team members * chore: updated dependencies and devDependencies (#2649) * Fixes instanceof Object statements for objects from other windows and iFrames. (#2631) * Replaces instanceof Object checks with typeof to prevent cross tab issues. * Adds missing space. * chore: removed google-analytics from all examples (#2670) * chore(docs): Add note that PRs should be submitted against the `develop` branch (#2623) Related to: https://github.com/almende/vis/pull/2618 Related to: https://github.com/almende/vis/pull/2620 * feat(timeline): Change setCustomTimeTitle title parameter to be a string or a function (#2611) * change setCustomTimeTitle title parameter, Now could be an string or a function * Fixed indent and spacing * feat(timeline): refactor tooltip to only use one dom-element (#2662) * feat(network): Allow for image nodes to have a selected or broken image (#2601) * feat(tests): run mocha tests in travis ci (#2687) * Added showX(YZ)Axis options to Graph3d (#2686) * Added showX(YZ)Axis to Graph3d * Added show_Axis options to docs and playground example * Resolved merge conflict * Added show_Axis options to docs and playground example * fix(build): use babel version compatible with webpack@1.14 (#2693) fixes #2685 * feat(docs): use babel preset2015 for custom builds (#2678) * add link to a mentioned example (#2709) * chore(lint): added support for eslint (#2695) * Trivial typo fix in how_to_help doc. (#2714) * fix(timeline): #2598 Flickering onUpdateTimeTooltip (#2702) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Add animation to onUpdateTooltip * fix(timeline): #778 Tooltip does not work with background items in timeline (#2703) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Make items z-index default to 1 * Add initial tests for Timeline PointItem (#2716) * fix(timeline): #2679 TypeError: Cannot read property 'hasOwnProperty' of null (#2735) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Fix bug in item editable * feat(timeline): #2647 Dynamic rolling mode option (#2705) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Add toggleRollingMode option * Update docs with toggleRollingMode option * fixes timestep next issue (#2732) * feat(timeline): added new locales for french and espanol (#2723) * Fix eslint problem on Travis. (#2744) * fix: Range.js "event" is undeclared (#2749) * fix(timeline): #2720 Problems with option editable (#2743) Clean up and centralise edit status for Timeline Items. * feat(network): Improve the performance of the network layout engine (#2729) * Improve the performance of the network layout engine Short-cut the execution of a number of methods in LayoutEngine to make them handle highly-connected graphs better. * Demonstrations of layouts of large networks * Added support to supply an end to bar charts to have them scale (#2760) * Added support to supply an X2 to bar charts to have them scale * Fixed graph2d stacking issue. It no longer takes into account hidden items * Changed x2 to end per recommendation and added this to the docs * Initial tests for timeline ItemSet. (#2750) Somewhat more complicated setup, associated with the need for a real window. * [Timeline] Modify redraw logic to treat scroll as needing restack. (#2774) This addresses #1982 and #1417. It possibly reduces performance, but correctness seems better. * fix(timeline): #2672 Item events original event (#2704) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Fix events returned from mouse events * Fix example * Rename censor to stringifyObject in example * [timeline] Update examples to use ISOString format. (#2791) Resolves #2790 * [timeline] Update serialization example to use ISOString dates. (#2789) Resolves #2696 * added github templates for issues and pull-requests (#2787) fixes #2418 * feat(timeline): Add item data as argument to the template function (#2799) * Fix regression introduced in #2743. (#2796) * Fix for issue #2536 (#2803) * Fix for issue #2536 * Adjusted documentation for fix. * Adjustments due to review * Grrrrr whitespace * Fixed Travis issue * Cheap fix for bug #2795 * Update to PR #2826 to use newline format * Update to gitignore to reflect changes on remote * clean dist folder * Local gitignore update * Just a first example file for the week scale feature * Allowing sourcemap creation * Initial (non-functional) commit to ensure we insert code at the right places (check TODOs) * Functional, not bug-free version which works with locale aware week numbers. * Locale-aware implementation and simplified major labels to a full year * Trying to make the major labels show the correct start date * Working implementation of week numbers using localization. * removing development leftovers * Updated package.json * Reintagrate package.json from accidental deletion * Updates for package.json * Fixing package.json * Integrate the week numbers feature in the documentation. * Reverting local changes to .gitignore * Reverting local changes * Extending examples to cover the case when 1st day of week and 1st day of month align; Fixing display bug so that week numbers are not repeated in minorLabels * Putting the examples into a loop
7 years ago
Implementation of a week scale feature (#3009) * Add Gitter badge (#2179) * do not generate source-maps in distribution version * add 'dist' folder for deployment * added Badges * added codeclimate badge * added @Tooa to the support team * added badges from isitmaintained.com (#2517) * do not ignore dist and test folders in master * generated dist files for v4.18.0 * generated dist files for v4.18.1 * Cheap fix for bug #2795 * Update to PR #2826 to use newline format * changed to v4.18.1-SNAPSHOT * chore(docs): general improvements (#2652) * removed NOTICE file * updated license date range to include 2017 * chore(docs): updated support team members * chore: updated dependencies and devDependencies (#2649) * Fixes instanceof Object statements for objects from other windows and iFrames. (#2631) * Replaces instanceof Object checks with typeof to prevent cross tab issues. * Adds missing space. * chore: removed google-analytics from all examples (#2670) * chore(docs): Add note that PRs should be submitted against the `develop` branch (#2623) Related to: https://github.com/almende/vis/pull/2618 Related to: https://github.com/almende/vis/pull/2620 * feat(timeline): Change setCustomTimeTitle title parameter to be a string or a function (#2611) * change setCustomTimeTitle title parameter, Now could be an string or a function * Fixed indent and spacing * feat(timeline): refactor tooltip to only use one dom-element (#2662) * feat(network): Allow for image nodes to have a selected or broken image (#2601) * feat(tests): run mocha tests in travis ci (#2687) * Added showX(YZ)Axis options to Graph3d (#2686) * Added showX(YZ)Axis to Graph3d * Added show_Axis options to docs and playground example * Resolved merge conflict * Added show_Axis options to docs and playground example * fix(build): use babel version compatible with webpack@1.14 (#2693) fixes #2685 * feat(docs): use babel preset2015 for custom builds (#2678) * add link to a mentioned example (#2709) * chore(lint): added support for eslint (#2695) * Trivial typo fix in how_to_help doc. (#2714) * fix(timeline): #2598 Flickering onUpdateTimeTooltip (#2702) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Add animation to onUpdateTooltip * fix(timeline): #778 Tooltip does not work with background items in timeline (#2703) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Make items z-index default to 1 * Add initial tests for Timeline PointItem (#2716) * fix(timeline): #2679 TypeError: Cannot read property 'hasOwnProperty' of null (#2735) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Fix bug in item editable * feat(timeline): #2647 Dynamic rolling mode option (#2705) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Add toggleRollingMode option * Update docs with toggleRollingMode option * fixes timestep next issue (#2732) * feat(timeline): added new locales for french and espanol (#2723) * Fix eslint problem on Travis. (#2744) * fix: Range.js "event" is undeclared (#2749) * fix(timeline): #2720 Problems with option editable (#2743) Clean up and centralise edit status for Timeline Items. * feat(network): Improve the performance of the network layout engine (#2729) * Improve the performance of the network layout engine Short-cut the execution of a number of methods in LayoutEngine to make them handle highly-connected graphs better. * Demonstrations of layouts of large networks * Added support to supply an end to bar charts to have them scale (#2760) * Added support to supply an X2 to bar charts to have them scale * Fixed graph2d stacking issue. It no longer takes into account hidden items * Changed x2 to end per recommendation and added this to the docs * Initial tests for timeline ItemSet. (#2750) Somewhat more complicated setup, associated with the need for a real window. * [Timeline] Modify redraw logic to treat scroll as needing restack. (#2774) This addresses #1982 and #1417. It possibly reduces performance, but correctness seems better. * fix(timeline): #2672 Item events original event (#2704) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Fix events returned from mouse events * Fix example * Rename censor to stringifyObject in example * [timeline] Update examples to use ISOString format. (#2791) Resolves #2790 * [timeline] Update serialization example to use ISOString dates. (#2789) Resolves #2696 * added github templates for issues and pull-requests (#2787) fixes #2418 * feat(timeline): Add item data as argument to the template function (#2799) * Fix regression introduced in #2743. (#2796) * Fix for issue #2536 (#2803) * Fix for issue #2536 * Adjusted documentation for fix. * Adjustments due to review * Grrrrr whitespace * Fixed Travis issue * Cheap fix for bug #2795 * Update to PR #2826 to use newline format * Update to gitignore to reflect changes on remote * clean dist folder * Local gitignore update * Just a first example file for the week scale feature * Allowing sourcemap creation * Initial (non-functional) commit to ensure we insert code at the right places (check TODOs) * Functional, not bug-free version which works with locale aware week numbers. * Locale-aware implementation and simplified major labels to a full year * Trying to make the major labels show the correct start date * Working implementation of week numbers using localization. * removing development leftovers * Updated package.json * Reintagrate package.json from accidental deletion * Updates for package.json * Fixing package.json * Integrate the week numbers feature in the documentation. * Reverting local changes to .gitignore * Reverting local changes * Extending examples to cover the case when 1st day of week and 1st day of month align; Fixing display bug so that week numbers are not repeated in minorLabels * Putting the examples into a loop
7 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. var util = require('../../util');
  2. var Component = require('./Component');
  3. var TimeStep = require('../TimeStep');
  4. var DateUtil = require('../DateUtil');
  5. var moment = require('../../module/moment');
  6. /**
  7. * A horizontal time axis
  8. * @param {{dom: Object, domProps: Object, emitter: Emitter, range: Range}} body
  9. * @param {Object} [options] See TimeAxis.setOptions for the available
  10. * options.
  11. * @constructor TimeAxis
  12. * @extends Component
  13. */
  14. function TimeAxis (body, options) {
  15. this.dom = {
  16. foreground: null,
  17. lines: [],
  18. majorTexts: [],
  19. minorTexts: [],
  20. redundant: {
  21. lines: [],
  22. majorTexts: [],
  23. minorTexts: []
  24. }
  25. };
  26. this.props = {
  27. range: {
  28. start: 0,
  29. end: 0,
  30. minimumStep: 0
  31. },
  32. lineTop: 0
  33. };
  34. this.defaultOptions = {
  35. orientation: {
  36. axis: 'bottom'
  37. }, // axis orientation: 'top' or 'bottom'
  38. showMinorLabels: true,
  39. showMajorLabels: true,
  40. maxMinorChars: 7,
  41. format: TimeStep.FORMAT,
  42. moment: moment,
  43. timeAxis: null
  44. };
  45. this.options = util.extend({}, this.defaultOptions);
  46. this.body = body;
  47. // create the HTML DOM
  48. this._create();
  49. this.setOptions(options);
  50. }
  51. TimeAxis.prototype = new Component();
  52. /**
  53. * Set options for the TimeAxis.
  54. * Parameters will be merged in current options.
  55. * @param {Object} options Available options:
  56. * {string} [orientation.axis]
  57. * {boolean} [showMinorLabels]
  58. * {boolean} [showMajorLabels]
  59. */
  60. TimeAxis.prototype.setOptions = function(options) {
  61. if (options) {
  62. // copy all options that we know
  63. util.selectiveExtend([
  64. 'showMinorLabels',
  65. 'showMajorLabels',
  66. 'maxMinorChars',
  67. 'hiddenDates',
  68. 'timeAxis',
  69. 'moment',
  70. 'rtl'
  71. ], this.options, options);
  72. // deep copy the format options
  73. util.selectiveDeepExtend(['format'], this.options, options);
  74. if ('orientation' in options) {
  75. if (typeof options.orientation === 'string') {
  76. this.options.orientation.axis = options.orientation;
  77. }
  78. else if (typeof options.orientation === 'object' && 'axis' in options.orientation) {
  79. this.options.orientation.axis = options.orientation.axis;
  80. }
  81. }
  82. // apply locale to moment.js
  83. // TODO: not so nice, this is applied globally to moment.js
  84. if ('locale' in options) {
  85. if (typeof moment.locale === 'function') {
  86. // moment.js 2.8.1+
  87. moment.locale(options.locale);
  88. }
  89. else {
  90. moment.lang(options.locale);
  91. }
  92. }
  93. }
  94. };
  95. /**
  96. * Create the HTML DOM for the TimeAxis
  97. */
  98. TimeAxis.prototype._create = function() {
  99. this.dom.foreground = document.createElement('div');
  100. this.dom.background = document.createElement('div');
  101. this.dom.foreground.className = 'vis-time-axis vis-foreground';
  102. this.dom.background.className = 'vis-time-axis vis-background';
  103. };
  104. /**
  105. * Destroy the TimeAxis
  106. */
  107. TimeAxis.prototype.destroy = function() {
  108. // remove from DOM
  109. if (this.dom.foreground.parentNode) {
  110. this.dom.foreground.parentNode.removeChild(this.dom.foreground);
  111. }
  112. if (this.dom.background.parentNode) {
  113. this.dom.background.parentNode.removeChild(this.dom.background);
  114. }
  115. this.body = null;
  116. };
  117. /**
  118. * Repaint the component
  119. * @return {boolean} Returns true if the component is resized
  120. */
  121. TimeAxis.prototype.redraw = function () {
  122. var props = this.props;
  123. var foreground = this.dom.foreground;
  124. var background = this.dom.background;
  125. // determine the correct parent DOM element (depending on option orientation)
  126. var parent = (this.options.orientation.axis == 'top') ? this.body.dom.top : this.body.dom.bottom;
  127. var parentChanged = (foreground.parentNode !== parent);
  128. // calculate character width and height
  129. this._calculateCharSize();
  130. // TODO: recalculate sizes only needed when parent is resized or options is changed
  131. var showMinorLabels = this.options.showMinorLabels && this.options.orientation.axis !== 'none';
  132. var showMajorLabels = this.options.showMajorLabels && this.options.orientation.axis !== 'none';
  133. // determine the width and height of the elemens for the axis
  134. props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
  135. props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
  136. props.height = props.minorLabelHeight + props.majorLabelHeight;
  137. props.width = foreground.offsetWidth;
  138. props.minorLineHeight = this.body.domProps.root.height - props.majorLabelHeight -
  139. (this.options.orientation.axis == 'top' ? this.body.domProps.bottom.height : this.body.domProps.top.height);
  140. props.minorLineWidth = 1; // TODO: really calculate width
  141. props.majorLineHeight = props.minorLineHeight + props.majorLabelHeight;
  142. props.majorLineWidth = 1; // TODO: really calculate width
  143. // take foreground and background offline while updating (is almost twice as fast)
  144. var foregroundNextSibling = foreground.nextSibling;
  145. var backgroundNextSibling = background.nextSibling;
  146. foreground.parentNode && foreground.parentNode.removeChild(foreground);
  147. background.parentNode && background.parentNode.removeChild(background);
  148. foreground.style.height = this.props.height + 'px';
  149. this._repaintLabels();
  150. // put DOM online again (at the same place)
  151. if (foregroundNextSibling) {
  152. parent.insertBefore(foreground, foregroundNextSibling);
  153. }
  154. else {
  155. parent.appendChild(foreground)
  156. }
  157. if (backgroundNextSibling) {
  158. this.body.dom.backgroundVertical.insertBefore(background, backgroundNextSibling);
  159. }
  160. else {
  161. this.body.dom.backgroundVertical.appendChild(background)
  162. }
  163. return this._isResized() || parentChanged;
  164. };
  165. /**
  166. * Repaint major and minor text labels and vertical grid lines
  167. * @private
  168. */
  169. TimeAxis.prototype._repaintLabels = function () {
  170. var orientation = this.options.orientation.axis;
  171. // calculate range and step (step such that we have space for 7 characters per label)
  172. var start = util.convert(this.body.range.start, 'Number');
  173. var end = util.convert(this.body.range.end, 'Number');
  174. var timeLabelsize = this.body.util.toTime((this.props.minorCharWidth || 10) * this.options.maxMinorChars).valueOf();
  175. var minimumStep = timeLabelsize - DateUtil.getHiddenDurationBefore(this.options.moment, this.body.hiddenDates, this.body.range, timeLabelsize);
  176. minimumStep -= this.body.util.toTime(0).valueOf();
  177. var step = new TimeStep(new Date(start), new Date(end), minimumStep, this.body.hiddenDates, this.options);
  178. step.setMoment(this.options.moment);
  179. if (this.options.format) {
  180. step.setFormat(this.options.format);
  181. }
  182. if (this.options.timeAxis) {
  183. step.setScale(this.options.timeAxis);
  184. }
  185. this.step = step;
  186. // Move all DOM elements to a "redundant" list, where they
  187. // can be picked for re-use, and clear the lists with lines and texts.
  188. // At the end of the function _repaintLabels, left over elements will be cleaned up
  189. var dom = this.dom;
  190. dom.redundant.lines = dom.lines;
  191. dom.redundant.majorTexts = dom.majorTexts;
  192. dom.redundant.minorTexts = dom.minorTexts;
  193. dom.lines = [];
  194. dom.majorTexts = [];
  195. dom.minorTexts = [];
  196. var current; // eslint-disable-line no-unused-vars
  197. var next;
  198. var x;
  199. var xNext;
  200. var isMajor;
  201. var nextIsMajor; // eslint-disable-line no-unused-vars
  202. var showMinorGrid;
  203. var width = 0, prevWidth;
  204. var line;
  205. var labelMinor;
  206. var xFirstMajorLabel = undefined;
  207. var count = 0;
  208. const MAX = 1000;
  209. var className;
  210. step.start();
  211. next = step.getCurrent();
  212. xNext = this.body.util.toScreen(next);
  213. while (step.hasNext() && count < MAX) {
  214. count++;
  215. isMajor = step.isMajor();
  216. className = step.getClassName();
  217. labelMinor = step.getLabelMinor();
  218. current = next;
  219. x = xNext;
  220. step.next();
  221. next = step.getCurrent();
  222. nextIsMajor = step.isMajor();
  223. xNext = this.body.util.toScreen(next);
  224. prevWidth = width;
  225. width = xNext - x;
  226. switch (step.scale) {
  227. case 'week': showMinorGrid = true; break;
  228. default: showMinorGrid = (width >= prevWidth * 0.4); break; // prevent displaying of the 31th of the month on a scale of 5 days
  229. }
  230. if (this.options.showMinorLabels && showMinorGrid) {
  231. var label = this._repaintMinorText(x, labelMinor, orientation, className);
  232. label.style.width = width + 'px'; // set width to prevent overflow
  233. }
  234. if (isMajor && this.options.showMajorLabels) {
  235. if (x > 0) {
  236. if (xFirstMajorLabel == undefined) {
  237. xFirstMajorLabel = x;
  238. }
  239. label = this._repaintMajorText(x, step.getLabelMajor(), orientation, className);
  240. }
  241. line = this._repaintMajorLine(x, width, orientation, className);
  242. }
  243. else { // minor line
  244. if (showMinorGrid) {
  245. line = this._repaintMinorLine(x, width, orientation, className);
  246. }
  247. else {
  248. if (line) {
  249. // adjust the width of the previous grid
  250. line.style.width = (parseInt (line.style.width) + width) + 'px';
  251. }
  252. }
  253. }
  254. }
  255. if (count === MAX && !warnedForOverflow) {
  256. console.warn(`Something is wrong with the Timeline scale. Limited drawing of grid lines to ${MAX} lines.`);
  257. warnedForOverflow = true;
  258. }
  259. // create a major label on the left when needed
  260. if (this.options.showMajorLabels) {
  261. var leftTime = this.body.util.toTime(0),
  262. leftText = step.getLabelMajor(leftTime),
  263. widthText = leftText.length * (this.props.majorCharWidth || 10) + 10; // upper bound estimation
  264. if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) {
  265. this._repaintMajorText(0, leftText, orientation, className);
  266. }
  267. }
  268. // Cleanup leftover DOM elements from the redundant list
  269. util.forEach(this.dom.redundant, function (arr) {
  270. while (arr.length) {
  271. var elem = arr.pop();
  272. if (elem && elem.parentNode) {
  273. elem.parentNode.removeChild(elem);
  274. }
  275. }
  276. });
  277. };
  278. /**
  279. * Create a minor label for the axis at position x
  280. * @param {number} x
  281. * @param {string} text
  282. * @param {string} orientation "top" or "bottom" (default)
  283. * @param {string} className
  284. * @return {Element} Returns the HTML element of the created label
  285. * @private
  286. */
  287. TimeAxis.prototype._repaintMinorText = function (x, text, orientation, className) {
  288. // reuse redundant label
  289. var label = this.dom.redundant.minorTexts.shift();
  290. if (!label) {
  291. // create new label
  292. var content = document.createTextNode('');
  293. label = document.createElement('div');
  294. label.appendChild(content);
  295. this.dom.foreground.appendChild(label);
  296. }
  297. this.dom.minorTexts.push(label);
  298. label.innerHTML = text;
  299. label.style.top = (orientation == 'top') ? (this.props.majorLabelHeight + 'px') : '0';
  300. if (this.options.rtl) {
  301. label.style.left = "";
  302. label.style.right = x + 'px';
  303. } else {
  304. label.style.left = x + 'px';
  305. }
  306. label.className = 'vis-text vis-minor ' + className;
  307. //label.title = title; // TODO: this is a heavy operation
  308. return label;
  309. };
  310. /**
  311. * Create a Major label for the axis at position x
  312. * @param {number} x
  313. * @param {string} text
  314. * @param {string} orientation "top" or "bottom" (default)
  315. * @param {string} className
  316. * @return {Element} Returns the HTML element of the created label
  317. * @private
  318. */
  319. TimeAxis.prototype._repaintMajorText = function (x, text, orientation, className) {
  320. // reuse redundant label
  321. var label = this.dom.redundant.majorTexts.shift();
  322. if (!label) {
  323. // create label
  324. var content = document.createElement('div');
  325. label = document.createElement('div');
  326. label.appendChild(content);
  327. this.dom.foreground.appendChild(label);
  328. }
  329. label.childNodes[0].innerHTML = text;
  330. label.className = 'vis-text vis-major ' + className;
  331. //label.title = title; // TODO: this is a heavy operation
  332. label.style.top = (orientation == 'top') ? '0' : (this.props.minorLabelHeight + 'px');
  333. if (this.options.rtl) {
  334. label.style.left = "";
  335. label.style.right = x + 'px';
  336. } else {
  337. label.style.left = x + 'px';
  338. }
  339. this.dom.majorTexts.push(label);
  340. return label;
  341. };
  342. /**
  343. * Create a minor line for the axis at position x
  344. * @param {number} x
  345. * @param {number} width
  346. * @param {string} orientation "top" or "bottom" (default)
  347. * @param {string} className
  348. * @return {Element} Returns the created line
  349. * @private
  350. */
  351. TimeAxis.prototype._repaintMinorLine = function (x, width, orientation, className) {
  352. // reuse redundant line
  353. var line = this.dom.redundant.lines.shift();
  354. if (!line) {
  355. // create vertical line
  356. line = document.createElement('div');
  357. this.dom.background.appendChild(line);
  358. }
  359. this.dom.lines.push(line);
  360. var props = this.props;
  361. if (orientation == 'top') {
  362. line.style.top = props.majorLabelHeight + 'px';
  363. }
  364. else {
  365. line.style.top = this.body.domProps.top.height + 'px';
  366. }
  367. line.style.height = props.minorLineHeight + 'px';
  368. if (this.options.rtl) {
  369. line.style.left = "";
  370. line.style.right = (x - props.minorLineWidth / 2) + 'px';
  371. line.className = 'vis-grid vis-vertical-rtl vis-minor ' + className;
  372. } else {
  373. line.style.left = (x - props.minorLineWidth / 2) + 'px';
  374. line.className = 'vis-grid vis-vertical vis-minor ' + className;
  375. }
  376. line.style.width = width + 'px';
  377. return line;
  378. };
  379. /**
  380. * Create a Major line for the axis at position x
  381. * @param {number} x
  382. * @param {number} width
  383. * @param {string} orientation "top" or "bottom" (default)
  384. * @param {string} className
  385. * @return {Element} Returns the created line
  386. * @private
  387. */
  388. TimeAxis.prototype._repaintMajorLine = function (x, width, orientation, className) {
  389. // reuse redundant line
  390. var line = this.dom.redundant.lines.shift();
  391. if (!line) {
  392. // create vertical line
  393. line = document.createElement('div');
  394. this.dom.background.appendChild(line);
  395. }
  396. this.dom.lines.push(line);
  397. var props = this.props;
  398. if (orientation == 'top') {
  399. line.style.top = '0';
  400. }
  401. else {
  402. line.style.top = this.body.domProps.top.height + 'px';
  403. }
  404. if (this.options.rtl) {
  405. line.style.left = "";
  406. line.style.right = (x - props.majorLineWidth / 2) + 'px';
  407. line.className = 'vis-grid vis-vertical-rtl vis-major ' + className;
  408. } else {
  409. line.style.left = (x - props.majorLineWidth / 2) + 'px';
  410. line.className = 'vis-grid vis-vertical vis-major ' + className;
  411. }
  412. line.style.height = props.majorLineHeight + 'px';
  413. line.style.width = width + 'px';
  414. return line;
  415. };
  416. /**
  417. * Determine the size of text on the axis (both major and minor axis).
  418. * The size is calculated only once and then cached in this.props.
  419. * @private
  420. */
  421. TimeAxis.prototype._calculateCharSize = function () {
  422. // Note: We calculate char size with every redraw. Size may change, for
  423. // example when any of the timelines parents had display:none for example.
  424. // determine the char width and height on the minor axis
  425. if (!this.dom.measureCharMinor) {
  426. this.dom.measureCharMinor = document.createElement('DIV');
  427. this.dom.measureCharMinor.className = 'vis-text vis-minor vis-measure';
  428. this.dom.measureCharMinor.style.position = 'absolute';
  429. this.dom.measureCharMinor.appendChild(document.createTextNode('0'));
  430. this.dom.foreground.appendChild(this.dom.measureCharMinor);
  431. }
  432. this.props.minorCharHeight = this.dom.measureCharMinor.clientHeight;
  433. this.props.minorCharWidth = this.dom.measureCharMinor.clientWidth;
  434. // determine the char width and height on the major axis
  435. if (!this.dom.measureCharMajor) {
  436. this.dom.measureCharMajor = document.createElement('DIV');
  437. this.dom.measureCharMajor.className = 'vis-text vis-major vis-measure';
  438. this.dom.measureCharMajor.style.position = 'absolute';
  439. this.dom.measureCharMajor.appendChild(document.createTextNode('0'));
  440. this.dom.foreground.appendChild(this.dom.measureCharMajor);
  441. }
  442. this.props.majorCharHeight = this.dom.measureCharMajor.clientHeight;
  443. this.props.majorCharWidth = this.dom.measureCharMajor.clientWidth;
  444. };
  445. var warnedForOverflow = false;
  446. module.exports = TimeAxis;