diff options
author | Adam Spiers <git@adamspiers.org> | 2015-01-10 00:28:19 +0000 |
---|---|---|
committer | Adam Spiers <git@adamspiers.org> | 2015-01-10 15:19:51 +0000 |
commit | 42923257d9c37a65e4065d66cd9b6b469ad02247 (patch) | |
tree | 0b899d6162718f67779a23432380282702b62b03 /html/js | |
parent | 6f40bf1b66addeab7be4e8b867fa18456f201181 (diff) | |
download | git-deps-42923257d9c37a65e4065d66cd9b6b469ad02247.tar.gz |
switch to using Browserify
For now this requires using my fork noty which adds support for
CommonJS.
Unfortunately WebCola is still broken with CommonJS.
Gulp automation will come soon ...
Diffstat (limited to 'html/js')
-rw-r--r-- | html/js/.gitignore | 1 | ||||
-rw-r--r-- | html/js/git-deps-data.js | 15 | ||||
-rw-r--r-- | html/js/git-deps-graph.js | 39 | ||||
-rw-r--r-- | html/js/git-deps-noty.js (renamed from html/js/noty.js) | 12 |
4 files changed, 51 insertions, 16 deletions
diff --git a/html/js/.gitignore b/html/js/.gitignore new file mode 100644 index 0000000..0e804e3 --- /dev/null +++ b/html/js/.gitignore @@ -0,0 +1 @@ +bundle.js diff --git a/html/js/git-deps-data.js b/html/js/git-deps-data.js index b970f23..e45217a 100644 --- a/html/js/git-deps-data.js +++ b/html/js/git-deps-data.js @@ -1,3 +1,5 @@ +var $ = require('jquery'); + // The list of nodes, links, and constraints to feed into WebCola. // These will be dynamically built as we retrieve them via XHR. var nodes = [], links = [], constraints = []; @@ -57,7 +59,7 @@ function add_link(parent_sha1, child_sha1) { } function build_constraints() { - constraints = []; // FIXME: only rebuild constraints which changed + constraints.length = 0; // FIXME: only rebuild constraints which changed for (var parent_sha1 in deps) { constraints.push(build_constraint(parent_sha1)); } @@ -97,3 +99,14 @@ function add_data(data) { return false; } +module.exports = { + // Variables + nodes: nodes, + links: links, + constraints: constraints, + node_index: node_index, + deps: deps, + + // Functions + add: add_data, +}; diff --git a/html/js/git-deps-graph.js b/html/js/git-deps-graph.js index 0c156f9..2031355 100644 --- a/html/js/git-deps-graph.js +++ b/html/js/git-deps-graph.js @@ -1,3 +1,14 @@ +var jQuery = require('jquery'); +var $ = jQuery; +var d3 = require('d3'); +var d3tip = require('d3-tip'); +d3tip(d3); + +global.gdn = require('./git-deps-noty'); +global.gdd = require('./git-deps-data'); + +require('./fullscreen'); + var SVG_MARGIN = 2, // space around <svg>, matching #svg-container border RECT_MARGIN = 14, // space in between <rects> PADDING = 5, // space in between <text> label and <rect> border @@ -8,7 +19,7 @@ var svg_width = 960, old_svg_width, var color = d3.scale.category20(); -var d3cola = cola.d3adaptor(); +global.d3cola = cola.d3adaptor(); d3cola .flowLayout("y", 150) .linkDistance(60) @@ -156,23 +167,23 @@ function init_svg() { function update_cola() { d3cola - .nodes(nodes) - .links(links) - .constraints(constraints); + .nodes(gdd.nodes) + .links(gdd.links) + .constraints(gdd.constraints); } function draw_graph(commitish) { d3.json("deps.json/" + commitish, function (error, data) { if (error) { var details = JSON.parse(error.responseText); - noty_error(details.message); + gdn.error(details.message); return; } - var new_data = add_data(data); + var new_data = gdd.add(data); if (! new_data) { - noty_warn('No new commits or dependencies found!'); + gdn.warn('No new commits or dependencies found!'); return; } @@ -181,13 +192,13 @@ function draw_graph(commitish) { new_data_notification(new_data); path = fg.selectAll(".link") - .data(links, link_key); + .data(gdd.links, link_key); path.enter().append('svg:path') .attr('class', 'link'); node = fg.selectAll(".node") - .data(nodes, function (d) { + .data(gdd.nodes, function (d) { return d.sha1; }) .call(d3cola.drag); @@ -214,7 +225,7 @@ function link_key(link) { function sha1_of_link_pointer(pointer) { if (typeof(pointer) == 'object') return pointer.sha1; - return nodes[pointer].sha1; + return gdd.nodes[pointer].sha1; } function new_data_notification(new_data) { @@ -233,7 +244,7 @@ function new_data_notification(new_data) { ((new_nodes == 1) ? 'dependency' : 'dependencies'); notification += '</p>'; - noty_success(notification); + gdn.success(notification); } function define_arrow_markers(fg) { @@ -299,7 +310,7 @@ function position_nodes(rect, label, tip) { // turn on overlap avoidance after first convergence // d3cola.on("end", function () { // if (!d3cola.avoidOverlaps()) { - // nodes.forEach(function (v) { + // gdd.nodes.forEach(function (v) { // v.width = v.height = 10; // }); // d3cola.avoidOverlaps(true); @@ -325,9 +336,9 @@ function tip_html(d) { var pre = fragment.find(".commit-body pre").text(d.body); if (options.debug) { - var index = node_index[d.sha1]; + var index = gdd.node_index[d.sha1]; var debug = "node index: " + index; - $.each(constraints, function (i, constraint) { + $.each(gdd.constraints, function (i, constraint) { if (constraint.parent == d.sha1) { var siblings = $.map(constraint.offsets, function (offset, i) { diff --git a/html/js/noty.js b/html/js/git-deps-noty.js index 8ee7f31..2639078 100644 --- a/html/js/noty.js +++ b/html/js/git-deps-noty.js @@ -1,3 +1,5 @@ +require('noty'); + // Different noty types: // alert, success, error, warning, information, confirmation function noty_error(text) { @@ -22,7 +24,7 @@ function noty_debug(text) { // Haha, did you see what I did here? function notyfication(type, text) { - var n = noty({ + var n = window.noty({ text: text, type: type, layout: 'topRight', @@ -36,3 +38,11 @@ function notyfication(type, text) { } }); } + +module.exports = { + error: noty_error, + warn: noty_warn, + success: noty_success, + info: noty_info, + debug: noty_debug +}; |