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.

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