Skip to content

Commit 42df07b

Browse files
authored
refactor: use prettier, switch to 2 indent (c3js#2766)
1 parent 6749eb6 commit 42df07b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+23714
-19915
lines changed

.jshintrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"maxlen": 210,
99
"undef": true,
1010
"unused": true,
11-
"indent": 4,
11+
"indent": 2,
1212
"eqnull": true,
1313
"expr": true,
1414
"newcap": false,
1515
"loopfunc": true,
1616
"bitwise": false,
17+
"asi": true,
18+
"laxbreak": true,
1719

1820
"browser": true,
1921
"jasmine": true,

.prettierrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"semi": false,
4+
"singleQuote": true
5+
}

bower.json

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
{
22
"name": "c3",
3-
"main": [
4-
"c3.css",
5-
"c3.js"
6-
],
3+
"main": ["c3.css", "c3.js"],
74
"homepage": "https://github.com/c3js/c3",
8-
"authors": [
9-
"Masayuki Tanaka <[email protected]>"
10-
],
5+
"authors": ["Masayuki Tanaka <[email protected]>"],
116
"description": "D3-based reusable chart library",
12-
"keywords": [
13-
"chart",
14-
"d3"
15-
],
7+
"keywords": ["chart", "d3"],
168
"license": "MIT",
179
"ignore": [
1810
"**/.*",

component.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
"development": {},
1111
"license": "MIT",
1212
"main": "c3.js",
13-
"scripts": [
14-
"c3.js"
15-
],
16-
"styles": [
17-
"c3.css"
18-
]
13+
"scripts": ["c3.js"],
14+
"styles": ["c3.css"]
1915
}

extensions/chart-bubble/bubble.js

+159-116
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,159 @@
1-
(function() {
2-
var extra = {};
3-
4-
c3.chart.internal.fn.additionalConfig = {
5-
data_pairs: [],
6-
};
7-
8-
c3.chart.internal.fn.beforeInit = function (config) {
9-
10-
var that = this;
11-
12-
// update internals only when chart type is "bubble"
13-
if (config.data.type !== 'bubble') {
14-
return;
15-
}
16-
17-
// Set extra to ba able to be used in other part
18-
this.extra = extra;
19-
20-
extra.getKey = function (x, y) {
21-
return x + '::' + y;
22-
};
23-
24-
this.config.data_type = 'scatter';
25-
26-
this.config.axis_x_padding = 0;
27-
this.config.axis_y_padding = 0;
28-
this.config.axis_x_tick_centered = true;
29-
this.config.axis_x_tick_format = function (d) {
30-
return extra.names[d];
31-
};
32-
this.config.axis_y_tick_format = function (d) {
33-
return extra.names[d];
34-
};
35-
36-
if (!config.color || !config.color.pattern) {
37-
this.config.color_pattern = ['#1f77b4'];
38-
}
39-
40-
this.config.point_r = function (d) {
41-
var names = extra.names, values = extra.values, base_length = extra.base_length,
42-
x = names[d.x], y = d.id,
43-
key = extra.getKey(x, y), value = !values[key] ? 0 : values[key],
44-
max, max_r, max_area, a, area, r;
45-
46-
if (!base_length) {
47-
base_length = extra.base_length = d3.min([
48-
that.svg.select('.c3-axis.c3-axis-y path').node().getTotalLength(),
49-
that.svg.select('.c3-axis.c3-axis-x path').node().getTotalLength(),
50-
]);
51-
}
52-
53-
max = d3.max(Object.keys(values).map(function (key) { return values[key]; }));
54-
max_r = (base_length / (names.length * 2));
55-
max_area = max_r * max_r * Math.PI;
56-
57-
a = max_area / max;
58-
59-
area = value * a;
60-
r = Math.sqrt(area / Math.PI);
61-
62-
return r;
63-
};
64-
this.config.point_sensitivity = 25;
65-
this.config.point_focus_expand_enabled = false;
66-
67-
this.config.legend_show = false;
68-
69-
if (!config.tooltip || !config.tooltip.contents) {
70-
this.config.tooltip_contents = function (d, defaultTitleFormat, defaultValueFormat, color) {
71-
var x = extra.names[d[0].x], y = d[0].name, v = extra.values[extra.getKey(x, y)], text;
72-
73-
text = "<table class='" + this.CLASS.tooltip + "'>";
74-
text += "<tr><th colspan='2'>" + x + "&nbsp;/&nbsp;" + y + "</th></tr>";
75-
text += "<tr><td class='value'>" + (!v ? 0 : v) + "</td></tr>";
76-
text += "</table>";
77-
78-
return text;
79-
};
80-
}
81-
82-
// construct bubble chart data and setup config based on the values
83-
84-
var xs = this.config.data_pairs.map(function (pair) { return pair.x; }),
85-
ys = this.config.data_pairs.map(function (pair) { return pair.y; });
86-
87-
extra.names = d3.set(xs.concat(ys)).values().sort();
88-
89-
this.config.axis_y_tick_values = extra.names.map(function (name, i) { return i; });
90-
91-
var data_xs = {};
92-
extra.names.forEach(function (name) {
93-
data_xs[name] = name + '_x';
94-
});
95-
var data_columns_xs = Object.keys(data_xs).map(function (key) {
96-
return [data_xs[key]].concat(extra.names.map(function (name, i) { return i; }));
97-
});
98-
var data_columns_values = extra.names.map(function (name, i) {
99-
return [name].concat(extra.names.map(function (name) { return i; }));
100-
});
101-
this.config.data_xs = data_xs;
102-
this.config.data_columns = data_columns_xs.concat(data_columns_values);
103-
104-
var values = {};
105-
this.config.data_pairs.forEach(function (pair) {
106-
if (!pair.x || !pair.y) {
107-
throw "x and y are required in data.";
108-
}
109-
values[extra.getKey(pair.x, pair.y)] = pair.value;
110-
});
111-
extra.values = values;
112-
113-
this.config.axis_x_min = this.config.axis_y_min = -0.5;
114-
this.config.axis_x_max = this.config.axis_y_max = extra.names.length - 0.5;
115-
};
116-
})(window);
1+
;(function() {
2+
var extra = {}
3+
4+
c3.chart.internal.fn.additionalConfig = {
5+
data_pairs: []
6+
}
7+
8+
c3.chart.internal.fn.beforeInit = function(config) {
9+
var that = this
10+
11+
// update internals only when chart type is "bubble"
12+
if (config.data.type !== 'bubble') {
13+
return
14+
}
15+
16+
// Set extra to ba able to be used in other part
17+
this.extra = extra
18+
19+
extra.getKey = function(x, y) {
20+
return x + '::' + y
21+
}
22+
23+
this.config.data_type = 'scatter'
24+
25+
this.config.axis_x_padding = 0
26+
this.config.axis_y_padding = 0
27+
this.config.axis_x_tick_centered = true
28+
this.config.axis_x_tick_format = function(d) {
29+
return extra.names[d]
30+
}
31+
this.config.axis_y_tick_format = function(d) {
32+
return extra.names[d]
33+
}
34+
35+
if (!config.color || !config.color.pattern) {
36+
this.config.color_pattern = ['#1f77b4']
37+
}
38+
39+
this.config.point_r = function(d) {
40+
var names = extra.names,
41+
values = extra.values,
42+
base_length = extra.base_length,
43+
x = names[d.x],
44+
y = d.id,
45+
key = extra.getKey(x, y),
46+
value = !values[key] ? 0 : values[key],
47+
max,
48+
max_r,
49+
max_area,
50+
a,
51+
area,
52+
r
53+
54+
if (!base_length) {
55+
base_length = extra.base_length = d3.min([
56+
that.svg
57+
.select('.c3-axis.c3-axis-y path')
58+
.node()
59+
.getTotalLength(),
60+
that.svg
61+
.select('.c3-axis.c3-axis-x path')
62+
.node()
63+
.getTotalLength()
64+
])
65+
}
66+
67+
max = d3.max(
68+
Object.keys(values).map(function(key) {
69+
return values[key]
70+
})
71+
)
72+
max_r = base_length / (names.length * 2)
73+
max_area = max_r * max_r * Math.PI
74+
75+
a = max_area / max
76+
77+
area = value * a
78+
r = Math.sqrt(area / Math.PI)
79+
80+
return r
81+
}
82+
this.config.point_sensitivity = 25
83+
this.config.point_focus_expand_enabled = false
84+
85+
this.config.legend_show = false
86+
87+
if (!config.tooltip || !config.tooltip.contents) {
88+
this.config.tooltip_contents = function(
89+
d,
90+
defaultTitleFormat,
91+
defaultValueFormat,
92+
color
93+
) {
94+
var x = extra.names[d[0].x],
95+
y = d[0].name,
96+
v = extra.values[extra.getKey(x, y)],
97+
text
98+
99+
text = "<table class='" + this.CLASS.tooltip + "'>"
100+
text += "<tr><th colspan='2'>" + x + '&nbsp;/&nbsp;' + y + '</th></tr>'
101+
text += "<tr><td class='value'>" + (!v ? 0 : v) + '</td></tr>'
102+
text += '</table>'
103+
104+
return text
105+
}
106+
}
107+
108+
// construct bubble chart data and setup config based on the values
109+
110+
var xs = this.config.data_pairs.map(function(pair) {
111+
return pair.x
112+
}),
113+
ys = this.config.data_pairs.map(function(pair) {
114+
return pair.y
115+
})
116+
117+
extra.names = d3
118+
.set(xs.concat(ys))
119+
.values()
120+
.sort()
121+
122+
this.config.axis_y_tick_values = extra.names.map(function(name, i) {
123+
return i
124+
})
125+
126+
var data_xs = {}
127+
extra.names.forEach(function(name) {
128+
data_xs[name] = name + '_x'
129+
})
130+
var data_columns_xs = Object.keys(data_xs).map(function(key) {
131+
return [data_xs[key]].concat(
132+
extra.names.map(function(name, i) {
133+
return i
134+
})
135+
)
136+
})
137+
var data_columns_values = extra.names.map(function(name, i) {
138+
return [name].concat(
139+
extra.names.map(function(name) {
140+
return i
141+
})
142+
)
143+
})
144+
this.config.data_xs = data_xs
145+
this.config.data_columns = data_columns_xs.concat(data_columns_values)
146+
147+
var values = {}
148+
this.config.data_pairs.forEach(function(pair) {
149+
if (!pair.x || !pair.y) {
150+
throw 'x and y are required in data.'
151+
}
152+
values[extra.getKey(pair.x, pair.y)] = pair.value
153+
})
154+
extra.values = values
155+
156+
this.config.axis_x_min = this.config.axis_y_min = -0.5
157+
this.config.axis_x_max = this.config.axis_y_max = extra.names.length - 0.5
158+
}
159+
})(window)

0 commit comments

Comments
 (0)