Skip to content

Commit d3bbf39

Browse files
committed
Save a few bytes.
1 parent abbe1c7 commit d3bbf39

3 files changed

Lines changed: 27 additions & 33 deletions

File tree

d3.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@
16201620
return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
16211621
}
16221622
function d3_rgb_parse(format, rgb, hsl) {
1623-
var r = 0, g = 0, b = 0, value, m1, m2, name;
1623+
var r = 0, g = 0, b = 0, m1, m2, color;
16241624
m1 = /([a-z]+)\((.*)\)/i.exec(format);
16251625
if (m1) {
16261626
m2 = m1[2].split(",");
@@ -1636,22 +1636,19 @@
16361636
}
16371637
}
16381638
}
1639-
if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
1640-
if (format != null && format.charAt(0) === "#") {
1641-
value = parseInt(format.substring(1), 16);
1642-
if (!isNaN(value)) {
1643-
if (format.length === 4) {
1644-
r = (value & 3840) >> 4;
1645-
r = r >> 4 | r;
1646-
g = value & 240;
1647-
g = g >> 4 | g;
1648-
b = value & 15;
1649-
b = b << 4 | b;
1650-
} else if (format.length === 7) {
1651-
r = (value & 16711680) >> 16;
1652-
g = (value & 65280) >> 8;
1653-
b = value & 255;
1654-
}
1639+
if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
1640+
if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
1641+
if (format.length === 4) {
1642+
r = (color & 3840) >> 4;
1643+
r = r >> 4 | r;
1644+
g = color & 240;
1645+
g = g >> 4 | g;
1646+
b = color & 15;
1647+
b = b << 4 | b;
1648+
} else if (format.length === 7) {
1649+
r = (color & 16711680) >> 16;
1650+
g = (color & 65280) >> 8;
1651+
b = color & 255;
16551652
}
16561653
}
16571654
return rgb(r, g, b);

0 commit comments

Comments
 (0)