Commit dba95af6 authored by S Anand's avatar S Anand

BLD: update G.js and G.min.js

parent 22a219f4
This diff is collapsed.
......@@ -878,22 +878,30 @@
if (!("fill" in options)) options.fill = true;
var PATH = 0, WIDTH = 1, END_POS = 2, PATH_LENGTH = 3, FILL = 4, self = this, paths = [], total_width = 0, default_duration = 0, easing = options.easing || function(t) {
return t;
}, start_pos = 0, pos, end_pos, start_time, duration, index, length, path, request_id, timeout_id;
self.off("stop.g.doodle start.g.doodle").on("stop.g.doodle", function() {
if (request_id) request_id = global.cancelAnimationFrame(request_id);
}, start_pos = 0, start_time, pos, path_pos, end_path_pos, duration, index, length, path, request_id, timeout_id;
self.off("stop.g.doodle start.g.doodle").on("stop.g.doodle", function(e, position) {
if (!request_id) return;
if (typeof position != "undefined") {
start_pos = position;
start_time = Date.now();
draw();
} else {
start_pos = pos;
}
request_id = global.cancelAnimationFrame(request_id);
if (timeout_id) timeout_id = global.clearTimeout(timeout_id);
start_pos = pos;
}).on("start.g.doodle", function(e, pos) {
}).on("start.g.doodle", function(e, position) {
if (request_id) return;
if (typeof pos != "undefined") {
start_pos = pos;
for (index = 0; index < length; index++) paths[index][PATH].attr("stroke-dashoffset", pos < paths[index][END_POS] ? paths[index][PATH_LENGTH] : 0);
if (options.fill) for (index = 0; index < length; index++) paths[index][PATH].css("fill", pos < paths[index][END_POS] ? "none" : paths[index][FILL]);
if (typeof position != "undefined") {
start_pos = position;
path_pos = easing(position);
for (index = 0; index < length; index++) paths[index][PATH].attr("stroke-dashoffset", path_pos < paths[index][END_POS] ? paths[index][PATH_LENGTH] : 0);
if (options.fill) for (index = 0; index < length; index++) paths[index][PATH].css("fill", path_pos < paths[index][END_POS] ? "none" : paths[index][FILL]);
}
index = 0;
path = paths[index];
end_pos = path[WIDTH];
start_time = +new Date();
end_path_pos = path[WIDTH];
start_time = Date.now();
tick();
}).each(function() {
var $this = $(this), width = parseFloat($this.data("duration") || "1"), path_length = this.getTotalLength();
......@@ -912,27 +920,32 @@
paths[index][END_POS] /= total_width;
}
duration = (options.duration || default_duration || 2) * 1e3;
function tick() {
pos = start_pos + easing((+new Date() - start_time) / duration);
if (index >= length || pos > paths[index][END_POS]) {
while (index < length && pos > paths[index][END_POS]) {
function draw() {
pos = start_pos + (Date.now() - start_time) / duration;
path_pos = easing(pos);
if (index >= length || path_pos >= paths[index][END_POS]) {
while (index < length && path_pos >= paths[index][END_POS]) {
paths[index][PATH].attr("stroke-dashoffset", 0);
if (options.fill) paths[index][PATH].css("fill", paths[index][FILL]);
index++;
}
if (index >= length) {
if (typeof options.loop != "undefined") timeout_id = setTimeout(function() {
self.doodle(options);
self.last().trigger("stop").trigger("start", [ 0 ]);
}, options.loop * 1e3);
return self.last().trigger("end.g.doodle");
self.last().trigger("end.g.doodle");
return false;
}
path = paths[index];
end_pos = path[WIDTH] + paths[index - 1][END_POS];
end_path_pos = path[WIDTH] + paths[index - 1][END_POS];
}
path[PATH].attr("stroke-dashoffset", path[PATH_LENGTH] * (end_pos - pos) / path[WIDTH]);
request_id = global.requestAnimationFrame(tick);
path[PATH].attr("stroke-dashoffset", path[PATH_LENGTH] * (end_path_pos - path_pos) / path[WIDTH]);
return true;
}
function tick() {
if (draw()) request_id = global.requestAnimationFrame(tick);
}
if (typeof options.start === "undefined" || options.start) $(this).eq(0).trigger("start.g.doodle", [ 0 ]);
if (typeof options.start === "undefined" || options.start) self.last().trigger("start.g.doodle", [ 0 ]);
return self;
};
}
......@@ -1252,6 +1265,7 @@
function draw_circle(circles) {
circles.attr("r", 5).attr("fill", "rgba(0,0,0,.5)");
}
var draw_label;
force.on("tick", function() {
self.lines.attr("x1", function(d) {
return d.source.x;
......@@ -1262,9 +1276,11 @@
}).attr("y2", function(d) {
return d.target.y;
});
self.circles.attr("transform", function(d) {
var set_pos = function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
};
self.circles.attr("transform", set_pos);
self.labels.attr("transform", set_pos);
});
force.drag().on("dragstart", _node_fix);
self.nodes = function(fn, namespace) {
......@@ -1288,9 +1304,16 @@
return self;
};
function filter_links() {
for (var links = [], i = 0, link; link = data.links[i]; i++) if (link.source.id in node_ids && link.target.id in node_ids) links.push(link);
for (var ns in link_filter) links = links.filter(link_filter[ns]);
return links;
var filtered_links = [], i = 0, link;
if (links.length) {
if (typeof links[0].source == "object") {
for (;link = links[i]; i++) if (link.source.id in node_ids && link.target.id in node_ids) filtered_links.push(link);
} else {
for (;link = links[i]; i++) if (nodes[link.source].id in node_ids && nodes[link.target].id in node_ids) filtered_links.push(link);
}
for (var ns in link_filter) filtered_links = filtered_links.filter(link_filter[ns]);
}
return filtered_links;
}
self.links = function(fn, namespace) {
if (typeof fn != "function" && fn !== null) return link_filter[fn];
......@@ -1322,6 +1345,11 @@
draw_circle = v;
return self;
};
self.label = function(v) {
if (!arguments.length) return draw_label;
draw_label = v;
return self;
};
self.line = function(v) {
if (!arguments.length) return draw_line;
draw_line = v;
......@@ -1329,7 +1357,7 @@
};
self.draw = function(svg) {
svg = d3.select(svg);
var width = +svg.attr("width"), height = +svg.attr("height");
var width = +svg.attr("width"), height = +svg.attr("height"), enter;
force.size([ width, height ]);
var $brush = svg.select("g.brush");
if ($brush.empty()) $brush = svg.append("g").attr("class", "brush");
......@@ -1337,19 +1365,33 @@
if ($lines.empty()) $lines = svg.append("g").attr("class", "lines");
var $circles = svg.select("g.circles");
if ($circles.empty()) $circles = svg.append("g").attr("class", "circles");
var $labels = svg.select("g.labels");
if ($labels.empty()) $labels = svg.append("g").attr("class", "labels");
force.nodes(nodes).links(links);
self.lines = $lines.selectAll("line.link").data(links, function(d) {
return d.id;
});
self.lines.exit().remove();
var enter = self.lines.enter().append("line").attr("class", "link");
draw_line(self.lines);
if (draw_line) {
enter = self.lines.enter().append("line").attr("class", "link");
draw_line(self.lines);
}
self.circles = $circles.selectAll("circle.node").data(nodes, function(d) {
return d.id;
});
self.circles.exit().remove();
enter = self.circles.enter().append("circle").attr("class", "node").on("dblclick.release", _node_release).call(force.drag);
draw_circle(self.circles);
if (draw_circle) {
enter = self.circles.enter().append("circle").attr("class", "node").on("dblclick.release", _node_release).call(force.drag);
draw_circle(self.circles);
}
self.labels = $labels.selectAll("text.node").data(nodes, function(d) {
return d.id;
});
self.labels.exit().remove();
if (draw_label) {
enter = self.labels.enter().append("text").attr("class", "node").on("dblclick.release", _node_release).call(force.drag);
draw_label(self.labels);
}
if (!svg.on("dblclick.release")) svg.on("dblclick.release", function() {
if (d3.event.target == svg.node()) {
self.circles.filter(function(d) {
......@@ -1357,6 +1399,11 @@
}).classed("fixed", function(d) {
return d.fixed = false;
});
self.labels.filter(function(d) {
return d.fixed;
}).classed("fixed", function(d) {
return d.fixed = false;
});
force.start();
}
});
......@@ -1365,6 +1412,9 @@
self.circles.classed("selected", function(d) {
return d.selected = extent[0][0] <= d.x && d.x < extent[1][0] && extent[0][1] <= d.y && d.y < extent[1][1];
});
self.labels.classed("selected", function(d) {
return d.selected = extent[0][0] <= d.x && d.x < extent[1][0] && extent[0][1] <= d.y && d.y < extent[1][1];
});
});
brush($brush);
force.start();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment