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

Make sorting optional #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 13 additions & 11 deletions g.pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
> Usage
| r.piechart(cx, cy, r, values, opts)
\*/

(function () {

function Piechart(paper, cx, cy, r, values, opts) {
Expand Down Expand Up @@ -94,12 +94,14 @@
total += values[i];
values[i] = { value: values[i], order: i, valueOf: function () { return this.value; } };
}

//values are sorted numerically
values.sort(function (a, b) {
return b.value - a.value;
});


//values are sorted numerically if option is provided
if(opts.sort){
values.sort(function (a, b) {
return b.value - a.value;
});
}

for (i = 0; i < len; i++) {
if (defcut && values[i] * 100 / total < minPercent) {
cut = i;
Expand Down Expand Up @@ -282,15 +284,15 @@

return chart;
};

//inheritance
var F = function() {};
F.prototype = Raphael.g;
Piechart.prototype = new F;

//public
Raphael.fn.piechart = function(cx, cy, r, values, opts) {
return new Piechart(this, cx, cy, r, values, opts);
}
})();

})();