Skip to content

Commit 1cecce8

Browse files
committed
2 parents 6103e15 + 4cfddd5 commit 1cecce8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

d3.layout.cloud.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
text = cloudText,
77
font = cloudFont,
88
fontSize = cloudFontSize,
9+
fontStyle = cloudFontNormal,
10+
fontWeight = cloudFontNormal,
911
rotate = cloudRotate,
1012
padding = cloudPadding,
1113
spiral = archimedeanSpiral,
@@ -25,6 +27,8 @@
2527
return {
2628
text: text.call(this, d, i),
2729
font: font.call(this, d, i),
30+
style: fontStyle.call(this, d, i),
31+
weight: fontWeight.call(this, d, i),
2832
rotate: rotate.call(this, d, i),
2933
size: ~~fontSize.call(this, d, i),
3034
padding: cloudPadding.call(this, d, i)
@@ -144,6 +148,18 @@
144148
return cloud;
145149
};
146150

151+
cloud.fontStyle = function(x) {
152+
if (!arguments.length) return fontStyle;
153+
fontStyle = d3.functor(x);
154+
return cloud;
155+
};
156+
157+
cloud.fontWeight = function(x) {
158+
if (!arguments.length) return fontWeight;
159+
fontWeight = d3.functor(x);
160+
return cloud;
161+
};
162+
147163
cloud.rotate = function(x) {
148164
if (!arguments.length) return rotate;
149165
rotate = d3.functor(x);
@@ -185,6 +201,10 @@
185201
return "serif";
186202
}
187203

204+
function cloudFontNormal() {
205+
return "normal";
206+
}
207+
188208
function cloudFontSize(d) {
189209
return Math.sqrt(d.value);
190210
}
@@ -210,7 +230,7 @@
210230
while (++di < n) {
211231
d = data[di];
212232
c.save();
213-
c.font = ~~((d.size + 1) / ratio) + "px " + d.font;
233+
c.font = d.style + " " + d.weight + " " + ~~((d.size + 1) / ratio) + "px " + d.font;
214234
var w = c.measureText(d.text + "m").width * ratio,
215235
h = d.size << 1;
216236
if (d.rotate) {

0 commit comments

Comments
 (0)