Make boxplot sort configurable.

This commit is contained in:
Jason Davies 2011-04-13 20:13:58 +01:00
Родитель 2e8cd200df
Коммит 5719f19223
3 изменённых файлов: 29 добавлений и 5 удалений

Просмотреть файл

@ -1,17 +1,18 @@
(function(){d3.chart = {};
// Inspired by http://informationandvisualization.de/files/boxplottest.html
// Inspired by http://informationandvisualization.de/blog/box-plot
d3.chart.boxplot = function() {
var width = 1,
height = 1,
duration = 0,
domain = null,
sort = d3_chart_boxplotSort,
tickFormat = null;
// For each small multiple…
function boxplot(g) {
g.each(function(d, i) {
d = d.slice();
d.sort(function(a, b) { return a - b; });
d.sort(sort);
var len = d.length,
min = d[0],
q1 = d[Math.floor(.25 * len)],
@ -102,6 +103,7 @@ d3.chart.boxplot = function() {
// Compute the tick format.
var format = tickFormat || x1.tickFormat(8);
// Update ticks.
var tick = g.selectAll("text")
.data([min, q1, median, q3, max]);
@ -153,8 +155,18 @@ d3.chart.boxplot = function() {
return boxplot;
};
boxplot.sort = function(x) {
if (!arguments.length) return sort;
sort = x;
return boxplot;
};
return boxplot;
};
function d3_chart_boxplotSort(a, b) {
return a - b;
}
// ranges (bad, satisfactory, good)
// measures (actual, forecast)
// markers (previous, goal)

2
d3.chart.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,16 +1,17 @@
// Inspired by http://informationandvisualization.de/files/boxplottest.html
// Inspired by http://informationandvisualization.de/blog/box-plot
d3.chart.boxplot = function() {
var width = 1,
height = 1,
duration = 0,
domain = null,
sort = d3_chart_boxplotSort,
tickFormat = null;
// For each small multiple…
function boxplot(g) {
g.each(function(d, i) {
d = d.slice();
d.sort(function(a, b) { return a - b; });
d.sort(sort);
var len = d.length,
min = d[0],
q1 = d[Math.floor(.25 * len)],
@ -101,6 +102,7 @@ d3.chart.boxplot = function() {
// Compute the tick format.
var format = tickFormat || x1.tickFormat(8);
// Update ticks.
var tick = g.selectAll("text")
.data([min, q1, median, q3, max]);
@ -152,5 +154,15 @@ d3.chart.boxplot = function() {
return boxplot;
};
boxplot.sort = function(x) {
if (!arguments.length) return sort;
sort = x;
return boxplot;
};
return boxplot;
};
function d3_chart_boxplotSort(a, b) {
return a - b;
}