g.raphael
g.raphael copied to clipboard
Enhancement: keep the color index for the pie
The pie sorts the value. However, sometimes, we want to keep the order of colors. I add an option for that:
for (i = 0; i < len; i++) { var angleplus = values[i] == total ? 359 : 360 * values[i] / total; var mangle = angle - angleplus / 2; if (!i) { angle = 90 - mangle; mangle = angle - angleplus / 2; } if (opts.init) { var ipath = sector(cx, cy, 1, angle, angle - angleplus).join(","); } var path = sector(cx, cy, r, angle, angle -= angleplus); var colorToUse = opts.colors ? (opts.preserveColorIndexes ? opts.colors[values[i].order] : opts.colors[i] ) : null; var p = this.path(opts.init ? ipath : path).attr({fill: colorToUse || this.g.colors[i] || "#666", stroke: opts.stroke || "#fff", "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), "stroke-linejoin": "round"}); p.value = values[i]; p.middle = path.middle; p.mangle = mangle; sectors.push(p); series.push(p); opts.init && p.animate({path: path.join(",")}, (+opts.init - 1) || 1000, ">"); }
It would be very useful. For example, I need to make a chart to visualize availability of some system, which will contain 2 sectors: "Available" and "Unavailable". So I want to paint them in green and red, respectively. But with the current version of the library, if I supply an option colors["green","red"], I get the biggest sector painted green, but not that one, which corresponds to the persentage of avaliability.
I'd like to take the opportunity to bump this feature request up. I have a use case where data is displayed in different ways but the colouring needs to be consistent across these visualizations.
Bump please