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

Heat map sort #837

Closed
wants to merge 2 commits into from
Closed
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
35 changes: 33 additions & 2 deletions src/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ dc.heatMap = function (parent, chartGroup) {
var _xBorderRadius = DEFAULT_BORDER_RADIUS;
var _yBorderRadius = DEFAULT_BORDER_RADIUS;

var _rowSort = d3.ascending;
var _colSort = d3.ascending;

var _chart = dc.colorMixin(dc.marginMixin(dc.baseMixin({})));
_chart._mandatoryAttributes(['group']);
_chart.title(_chart.colorAccessor());
Expand Down Expand Up @@ -126,6 +129,34 @@ dc.heatMap = function (parent, chartGroup) {
return !i || a[i - 1] !== d;
}

/**
#### .colSort(function)
Gets or Sets the sorting function for the columns of the heatmap.
Default is d3.ascending
**/

_chart.colSort = function(_){
if (arguments.length) {
_colSort = _;
return _chart;
}
return _colSort;
}

/**
#### .rowSort(function)
Gets or Sets the sorting function for the columns of the heatmap.
Default is d3.ascending
**/

_chart.rowSort = function(_){
if (arguments.length) {
_rowSort = _;
return _chart;
}
return _rowSort;
}

/**
#### .rows([values])
Gets or sets the values used to create the rows of the heatmap, as an array. By default, all
Expand All @@ -142,7 +173,7 @@ dc.heatMap = function (parent, chartGroup) {
return _rows;
}
var rowValues = _chart.data().map(_chart.valueAccessor());
rowValues.sort(d3.ascending);
rowValues.sort(_chart.rowSort());
return d3.scale.ordinal().domain(rowValues.filter(uniq));
};

Expand All @@ -161,7 +192,7 @@ dc.heatMap = function (parent, chartGroup) {
return _cols;
}
var colValues = _chart.data().map(_chart.keyAccessor());
colValues.sort(d3.ascending);
colValues.sort(_chart.colSort());
return d3.scale.ordinal().domain(colValues.filter(uniq));
};

Expand Down
7 changes: 7 additions & 0 deletions web/docs/api-latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,13 @@ row labels on the Y axis. It is passed the row name.
// the default label function just returns the name
chart.rowsLabel(function(d) { return d; });
```
#### .colsSort(function)
Gets or Sets the sorting function for the columns of the heatmap.
Default is d3.ascending

#### .colsSort(function)
Gets or Sets the sorting function for the columns of the heatmap.
Default is d3.ascending

#### .rows([values])
Gets or sets the values used to create the rows of the heatmap, as an array. By default, all
Expand Down