|
88 | 88 | return s; |
89 | 89 | }; |
90 | 90 | function d3_number(x) { |
91 | | - return x != null && !isNaN(x); |
| 91 | + return x === null ? NaN : +x; |
| 92 | + } |
| 93 | + function d3_numeric(x) { |
| 94 | + return !isNaN(x); |
92 | 95 | } |
93 | 96 | d3.mean = function(array, f) { |
94 | 97 | var s = 0, n = array.length, a, i = -1, j = n; |
95 | 98 | if (arguments.length === 1) { |
96 | | - while (++i < n) if (d3_number(a = array[i])) s += a; else --j; |
| 99 | + while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j; |
97 | 100 | } else { |
98 | | - while (++i < n) if (d3_number(a = f.call(array, array[i], i))) s += a; else --j; |
| 101 | + while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j; |
99 | 102 | } |
100 | 103 | return j ? s / j : undefined; |
101 | 104 | }; |
|
104 | 107 | return e ? v + e * (values[h] - v) : v; |
105 | 108 | }; |
106 | 109 | d3.median = function(array, f) { |
107 | | - if (arguments.length > 1) array = array.map(f); |
108 | | - array = array.filter(d3_number); |
109 | | - return array.length ? d3.quantile(array.sort(d3_ascending), .5) : undefined; |
| 110 | + var array1 = [], n = array.length, a, i = -1; |
| 111 | + if (arguments.length === 1) { |
| 112 | + while (++i < n) if (d3_numeric(a = d3_number(array[i]))) array1.push(a); |
| 113 | + } else { |
| 114 | + while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) array1.push(a); |
| 115 | + } |
| 116 | + return array1.length ? d3.quantile(array1.sort(d3_ascending), .5) : undefined; |
110 | 117 | }; |
111 | 118 | function d3_bisector(compare) { |
112 | 119 | return { |
|
2122 | 2129 | return t.reverse().join(locale_thousands); |
2123 | 2130 | } : d3_identity; |
2124 | 2131 | return function(specifier) { |
2125 | | - var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false; |
| 2132 | + var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false; |
2126 | 2133 | if (precision) precision = +precision.substring(1); |
2127 | 2134 | if (zfill || fill === "0" && align === "=") { |
2128 | 2135 | zfill = fill = "0"; |
|
2174 | 2181 | return function(value) { |
2175 | 2182 | var fullSuffix = suffix; |
2176 | 2183 | if (integer && value % 1) return ""; |
2177 | | - var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign; |
| 2184 | + var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign; |
2178 | 2185 | if (scale < 0) { |
2179 | 2186 | var unit = d3.formatPrefix(value, precision); |
2180 | 2187 | value = unit.scale(value); |
|
7676 | 7683 | } |
7677 | 7684 | scale.domain = function(x) { |
7678 | 7685 | if (!arguments.length) return domain; |
7679 | | - domain = x.filter(d3_number).sort(d3_ascending); |
| 7686 | + domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending); |
7680 | 7687 | return rescale(); |
7681 | 7688 | }; |
7682 | 7689 | scale.range = function(x) { |
|
0 commit comments