Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing bug "pie char is not shown when only one option has votes" #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions g.pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,38 @@
others && values.splice(len) && (values[cut].others = true);

for (i = 0; i < len; i++) {
var mangle = angle - 360 * values[i] / total / 2;

if (!i) {
angle = 90 - mangle;
mangle = angle - 360 * values[i] / total / 2;
}

if (opts.init) {
var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(",");
//if all votes are in only one option must draw a circle
if (values[i] / total === 1) {
var circle = paper.circle(cx, cy, r).attr({ fill: chartinst.colors[i], stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be:
var circle = paper.circle(cx, cy, r).attr({ fill: opts.colors && opts.colors[i] || chartinst.colors[i], stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth });

Otherwise you're not getting the colors set up in options.

circle.value = values[i];
series.push(circle);
sectors.push(circle);
covers.push(paper.circle(cx, cy, r).attr(chartinst.shim));
total = values[i];
series[i].middle = {x: cx, y: cy};
series[i].mangle = 180;
} else {
var mangle = angle - 360 * values[i] / total / 2;

if (!i) {
angle = 90 - mangle;
mangle = angle - 360 * values[i] / total / 2;
}

if (opts.init) {
var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(",");
}

var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total);
var p = paper.path(opts.init ? ipath : path).attr({ fill: opts.colors && opts.colors[i] || chartinst.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, ">");
}

var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total);
var p = paper.path(opts.init ? ipath : path).attr({ fill: opts.colors && opts.colors[i] || chartinst.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, ">");
}

for (i = 0; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion min/g.pie-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.