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.

194 lines
5.0 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
11 years ago
11 years ago
  1. /**
  2. * Jake build script
  3. */
  4. var jake = require('jake'),
  5. browserify = require('browserify'),
  6. wrench = require('wrench'),
  7. fs = require('fs');
  8. require('jake-utils');
  9. // constants
  10. var DIST = './dist';
  11. var VIS = DIST + '/vis.js';
  12. var VIS_CSS = DIST + '/vis.css';
  13. var VIS_TMP = DIST + '/vis.js.tmp';
  14. var VIS_MIN = DIST + '/vis.min.js';
  15. /**
  16. * default task
  17. */
  18. desc('Default task: build all libraries');
  19. task('default', ['build', 'minify'], function () {
  20. console.log('done');
  21. });
  22. /**
  23. * build the visualization library vis.js
  24. */
  25. desc('Build the visualization library vis.js');
  26. task('build', {async: true}, function () {
  27. jake.mkdirP(DIST);
  28. jake.mkdirP(DIST + '/img');
  29. // concatenate and stringify the css files
  30. concat({
  31. src: [
  32. './src/timeline/component/css/timeline.css',
  33. './src/timeline/component/css/panel.css',
  34. './src/timeline/component/css/groupset.css',
  35. './src/timeline/component/css/itemset.css',
  36. './src/timeline/component/css/item.css',
  37. './src/timeline/component/css/timeaxis.css',
  38. './src/timeline/component/css/currenttime.css',
  39. './src/timeline/component/css/customtime.css',
  40. './src/graph/css/graph-manipulation.css',
  41. './src/graph/css/graph-navigation.css'
  42. ],
  43. dest: VIS_CSS,
  44. separator: '\n'
  45. });
  46. console.log('created ' + VIS_CSS);
  47. // concatenate the script files
  48. concat({
  49. dest: VIS_TMP,
  50. src: [
  51. './src/module/imports.js',
  52. './src/shim.js',
  53. './src/util.js',
  54. './src/DataSet.js',
  55. './src/DataView.js',
  56. './src/svgTimeline/svgTimeline.js',
  57. './src/timeline/TimeStep.js',
  58. './src/timeline/Stack.js',
  59. './src/timeline/Range.js',
  60. './src/timeline/Controller.js',
  61. './src/timeline/component/Component.js',
  62. './src/timeline/component/Panel.js',
  63. './src/timeline/component/RootPanel.js',
  64. './src/timeline/component/TimeAxis.js',
  65. './src/timeline/component/CurrentTime.js',
  66. './src/timeline/component/CustomTime.js',
  67. './src/timeline/component/ItemSet.js',
  68. './src/timeline/component/item/*.js',
  69. './src/timeline/component/Group.js',
  70. './src/timeline/component/GroupSet.js',
  71. './src/timeline/Timeline.js',
  72. './src/graph/dotparser.js',
  73. './src/graph/shapes.js',
  74. './src/graph/Node.js',
  75. './src/graph/Edge.js',
  76. './src/graph/Popup.js',
  77. './src/graph/Groups.js',
  78. './src/graph/Images.js',
  79. './src/graph/graphMixins/physics/PhysicsMixin.js',
  80. './src/graph/graphMixins/physics/HierarchialRepulsion.js',
  81. './src/graph/graphMixins/physics/BarnesHut.js',
  82. './src/graph/graphMixins/physics/Repulsion.js',
  83. './src/graph/graphMixins/HierarchicalLayoutMixin.js',
  84. './src/graph/graphMixins/ManipulationMixin.js',
  85. './src/graph/graphMixins/SectorsMixin.js',
  86. './src/graph/graphMixins/ClusterMixin.js',
  87. './src/graph/graphMixins/SelectionMixin.js',
  88. './src/graph/graphMixins/NavigationMixin.js',
  89. './src/graph/graphMixins/MixinLoader.js',
  90. './src/graph/Graph.js',
  91. './src/module/exports.js'
  92. ],
  93. separator: '\n'
  94. });
  95. // copy images
  96. wrench.copyDirSyncRecursive('./src/graph/img', DIST + '/img/graph', {
  97. forceDelete: true
  98. });
  99. wrench.copyDirSyncRecursive('./src/timeline/img', DIST + '/img/timeline', {
  100. forceDelete: true
  101. });
  102. var timeStart = Date.now();
  103. // bundle the concatenated script and dependencies into one file
  104. var b = browserify();
  105. b.add(VIS_TMP);
  106. b.bundle({
  107. standalone: 'vis'
  108. }, function (err, code) {
  109. if(err) {
  110. throw err;
  111. }
  112. console.log("browserify",Date.now() - timeStart); timeStart = Date.now();
  113. // add header and footer
  114. var lib = read('./src/module/header.js') + code;
  115. // write bundled file
  116. write(VIS, lib);
  117. console.log('created js' + VIS);
  118. // remove temporary file
  119. fs.unlinkSync(VIS_TMP);
  120. // update version number and stuff in the javascript files
  121. replacePlaceholders(VIS);
  122. complete();
  123. });
  124. });
  125. /**
  126. * minify the visualization library vis.js
  127. */
  128. desc('Minify the visualization library vis.js');
  129. task('minify', function () {
  130. // minify javascript
  131. minify({
  132. src: VIS,
  133. dest: VIS_MIN,
  134. header: read('./src/module/header.js')
  135. });
  136. // update version number and stuff in the javascript files
  137. replacePlaceholders(VIS_MIN);
  138. console.log('created minified ' + VIS_MIN);
  139. });
  140. /**
  141. * test task
  142. */
  143. desc('Test the library');
  144. task('test', function () {
  145. // TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
  146. var filelist = new jake.FileList();
  147. filelist.include([
  148. './test/**/*.js'
  149. ]);
  150. var files = filelist.toArray();
  151. files.forEach(function (file) {
  152. require('./' + file);
  153. });
  154. console.log('Executed ' + files.length + ' test files successfully');
  155. });
  156. /**
  157. * replace version, date, and name placeholders in the provided file
  158. * @param {String} filename
  159. */
  160. var replacePlaceholders = function (filename) {
  161. replace({
  162. replacements: [
  163. {pattern: '@@date', replacement: today()},
  164. {pattern: '@@version', replacement: version()}
  165. ],
  166. src: filename
  167. });
  168. };