|
1620 | 1620 | return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16); |
1621 | 1621 | } |
1622 | 1622 | 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; |
1624 | 1624 | m1 = /([a-z]+)\((.*)\)/i.exec(format); |
1625 | 1625 | if (m1) { |
1626 | 1626 | m2 = m1[2].split(","); |
|
1636 | 1636 | } |
1637 | 1637 | } |
1638 | 1638 | } |
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; |
1655 | 1652 | } |
1656 | 1653 | } |
1657 | 1654 | return rgb(r, g, b); |
|
0 commit comments