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.

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