Browse Source

Modify color.values to color.threshold

pull/264/head
Masayuki Tanaka 11 years ago
parent
commit
d26da94ae1
  1. 30
      c3.js
  2. 6
      htdocs/samples/chart_arc_gauge.html

30
c3.js

@ -170,7 +170,7 @@
// color // color
var __color_pattern = getConfig(['color', 'pattern'], []), var __color_pattern = getConfig(['color', 'pattern'], []),
__color_values = getConfig(['color', 'values'], []); __color_threshold = getConfig(['color', 'threshold'], {});
// legend // legend
var __legend_show = getConfig(['legend', 'show'], true), var __legend_show = getConfig(['legend', 'show'], true),
@ -294,7 +294,7 @@
name = d[i].name; name = d[i].name;
value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index);
bgcolor = (__gauge_style === 'arc' && __color_values) ? levelColor(d[i].value) : color(d[i].id); bgcolor = levelColor ? levelColor(d[i].value) : color(d[i].id);
text += "<tr class='" + CLASS.tooltipName + "-" + d[i].id + "'>"; text += "<tr class='" + CLASS.tooltipName + "-" + d[i].id + "'>";
text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</td>"; text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</td>";
@ -325,7 +325,7 @@
var defaultColorPattern = d3.scale.category10().range(), var defaultColorPattern = d3.scale.category10().range(),
color = generateColor(__data_colors, notEmpty(__color_pattern) ? __color_pattern : defaultColorPattern, __data_color), color = generateColor(__data_colors, notEmpty(__color_pattern) ? __color_pattern : defaultColorPattern, __data_color),
levelColor = generateLevelColor(__color_pattern, __color_values); levelColor = notEmpty(__color_threshold) ? generateLevelColor(__color_pattern, __color_threshold) : null;
var timeFormat = __axis_x_localtime ? d3.time.format : d3.time.format.utc, var timeFormat = __axis_x_localtime ? d3.time.format : d3.time.format.utc,
defaultTimeFormat = timeFormat.multi([ defaultTimeFormat = timeFormat.multi([
@ -2229,20 +2229,20 @@
}; };
} }
function generateLevelColor(_colors, _values) { function generateLevelColor(colors, threshold) {
var colors = _colors, var asValue = threshold.unit === 'value',
levels = _values; values = threshold.values && threshold.values.length ? threshold.values : [],
max = threshold.max || 100;
return function (value) { return function (value) {
for (var a = 1; a < levels.length; a++) { var i, v, color = colors[colors.length - 1];
if (levels[0] === 'percentage' && ((value / __gauge_max) * 100) < levels[a]) { for (i = 0; i < values.length; i++) {
return colors[a - 1]; v = asValue ? value : (value * 100 / max);
} if (v < values[i]) {
if (levels[0] === 'whole' && value < levels[a]) { color = colors[i];
return colors[a - 1]; break;
} }
} }
return colors[colors.length - 1]; return color;
}; };
} }
@ -3751,7 +3751,7 @@
}) })
.attr("transform", withTransform ? "scale(1)" : "") .attr("transform", withTransform ? "scale(1)" : "")
.style("fill", function (d) { .style("fill", function (d) {
return (__gauge_style === 'arc' && __color_values) ? levelColor(d.data.values[0].value) : color(d.data.id); return levelColor ? levelColor(d.data.values[0].value) : color(d.data.id);
}) // Where gauge reading color would receive customization. }) // Where gauge reading color would receive customization.
.style("opacity", 1) .style("opacity", 1)
.call(endall, function () { .call(endall, function () {

6
htdocs/samples/chart_arc_gauge.html

@ -38,7 +38,11 @@
}, },
color: { color: {
pattern: ['#FF0000', '#F6C600', '#60B044'], // the three color levels for the percentage values. pattern: ['#FF0000', '#F6C600', '#60B044'], // the three color levels for the percentage values.
values: ['percentage', 30, 60, 90] // alternate first value is 'value' threshold: {
// unit: 'value', // percentage is default
// max: 200, // 100 is default
values: [30, 60, 90] // alternate first value is 'value'
}
} }
}); });

Loading…
Cancel
Save