MCPcopy Create free account
hub / github.com/BloombergGraphics/whatiscode / jetpack

Function jetpack

scripts/libs/d3-jetpack.js:14–147  ·  view source on GitHub ↗
(d3)

Source from the content-addressed store, hash-verified

12(function() {
13
14 function jetpack(d3) {
15 d3.selection.prototype.translate = function(xy) {
16 return this.attr('transform', function(d,i) {
17 return 'translate('+[typeof xy == 'function' ? xy(d,i) : xy]+')';
18 });
19 };
20
21 d3.transition.prototype.translate = function(xy) {
22 return this.attr('transform', function(d,i) {
23 return 'translate('+[typeof xy == 'function' ? xy(d,i) : xy]+')';
24 });
25 };
26
27 d3.selection.prototype.tspans = function(lines, lh) {
28 return this.selectAll('tspan')
29 .data(lines)
30 .enter()
31 .append('tspan')
32 .text(function(d) { return d; })
33 .attr('x', 0)
34 .attr('dy', function(d,i) { return i ? lh || 15 : 0; });
35 };
36
37 d3.selection.prototype.append =
38 d3.selection.enter.prototype.append = function(name) {
39 var n = d3_parse_attributes(name), s;
40 //console.log(name, n);
41 name = n.attr ? n.tag : name;
42 name = d3_selection_creator(name);
43 s = this.select(function() {
44 return this.appendChild(name.apply(this, arguments));
45 });
46 return n.attr ? s.attr(n.attr) : s;
47 };
48
49 d3.selection.prototype.insert =
50 d3.selection.enter.prototype.insert = function(name, before) {
51 var n = d3_parse_attributes(name), s;
52 name = n.attr ? n.tag : name;
53 name = d3_selection_creator(name);
54 before = d3_selection_selector(before);
55 s = this.select(function() {
56 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
57 });
58 return n.attr ? s.attr(n.attr) : s;
59 };
60
61 var d3_parse_attributes_regex = /([\.#])/g;
62
63 function d3_parse_attributes(name) {
64 if (typeof name === "string") {
65 var attr = {},
66 parts = name.split(d3_parse_attributes_regex), p;
67 name = parts.shift();
68 while ((p = parts.shift())) {
69 if (p == '.') attr['class'] = attr['class'] ? attr['class'] + ' ' + parts.shift() : parts.shift();
70 else if (p == '#') attr.id = parts.shift();
71 }

Callers 1

d3-jetpack.jsFile · 0.85

Calls 3

d3_parse_attributesFunction · 0.85
d3_selection_creatorFunction · 0.85
d3_selection_selectorFunction · 0.85

Tested by

no test coverage detected