Skip to content

Commit 10ed200

Browse files
committed
Fixes heatmap tests
1 parent 655c6e9 commit 10ed200

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

spec/heatmap-spec.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ describe("dc.heatmap", function() {
7575
});
7676

7777
it('should position the y-axis labels with their associated rows', function() {
78-
var yaxisTexts = chart.selectAll(".rows.axis text");
79-
expect(+yaxisTexts[0][0].getAttribute("y")).toEqual(150 );
80-
expect(+yaxisTexts[0][0].getAttribute("x")).toEqual(0);
81-
expect(+yaxisTexts[0][1].getAttribute("y")).toEqual(50);
82-
expect(+yaxisTexts[0][1].getAttribute("x")).toEqual(0);
78+
var yaxisTicks = chart.selectAll(".rows.axis .tick");
79+
expect(yaxisTicks[0][0].getAttribute("transform")).toEqual("translate(0,150)");
80+
expect(yaxisTicks[0][1].getAttribute("transform")).toEqual("translate(0,50)");
8381
});
8482

8583
it('should have labels on the y-axis corresponding to the row values', function() {
@@ -89,11 +87,9 @@ describe("dc.heatmap", function() {
8987
});
9088

9189
it('should position the x-axis labels with their associated columns', function() {
92-
var xaxisTexts = chart.selectAll(".cols.axis text");
93-
expect(+xaxisTexts[0][0].getAttribute("y")).toEqual(200);
94-
expect(+xaxisTexts[0][0].getAttribute("x")).toEqual(50);
95-
expect(+xaxisTexts[0][1].getAttribute("y")).toEqual(200);
96-
expect(+xaxisTexts[0][1].getAttribute("x")).toEqual(150);
90+
var xaxisTexts = chart.selectAll(".cols.axis .tick");
91+
expect(xaxisTexts[0][0].getAttribute("transform")).toEqual("translate(50,0)");
92+
expect(xaxisTexts[0][1].getAttribute("transform")).toEqual("translate(150,0)");
9793
});
9894

9995
it('should have labels on the x-axis corresponding to the row values', function() {
@@ -344,13 +340,13 @@ describe("dc.heatmap", function() {
344340
describe('on axis labels', function() {
345341
describe('with nothing previously filtered', function () {
346342
it('should filter all cells on that axis', function () {
347-
chart.selectAll(".cols.axis text").each( function(d) {
343+
chart.selectAll(".cols.axis g").each( function(d) {
348344
var axisLabel = d3.select(this);
349345
axisLabel.on("click")(d);
350346
assertOnlyThisAxisIsFiltered(chart, 0, d);
351347
axisLabel.on("click")(d);
352348
});
353-
chart.selectAll(".rows.axis text").each( function(d) {
349+
chart.selectAll(".rows.axis g").each( function(d) {
354350
var axisLabel = d3.select(this);
355351
axisLabel.on("click")(d);
356352
assertOnlyThisAxisIsFiltered(chart, 1, d);
@@ -369,7 +365,7 @@ describe("dc.heatmap", function() {
369365

370366
var xVal = box.datum().key[0];
371367

372-
var columns = chart.selectAll(".cols.axis text");
368+
var columns = chart.selectAll(".cols.axis g");
373369
var column = columns.filter( function (columnData) {
374370
return columnData == xVal;
375371
});
@@ -393,7 +389,7 @@ describe("dc.heatmap", function() {
393389

394390
assertOnlyThisAxisIsFiltered(chart, 0, xVal);
395391

396-
var columns = chart.selectAll(".cols.axis text");
392+
var columns = chart.selectAll(".cols.axis g");
397393
var column = columns.filter( function (columnData) {
398394
return columnData == xVal;
399395
});

src/heatmap.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ dc.heatMap = function (parent, chartGroup) {
188188
.attr('class', 'heatmap')
189189
.attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')');
190190
_chartBody.append('g')
191-
.attr('class', 'axis x')
191+
.attr('class', 'cols axis')
192192
.attr('transform', 'translate(0,' + _chart.effectiveHeight() + ')');
193193
_chartBody.append('g')
194-
.attr('class', 'axis y');
194+
.attr('class', 'rows axis');
195195
_colScale.rangeRoundBands([0, _chart.effectiveWidth()]);
196196
_rowScale.rangeRoundBands([_chart.effectiveHeight(), 0]);
197197

@@ -214,23 +214,29 @@ dc.heatMap = function (parent, chartGroup) {
214214
// Update axis
215215
_colAxis.scale(cols)
216216
.tickFormat(_chart.colsLabel());
217-
dc.transition(_chartBody.select('g.axis.x'), _chart.transitionDuration())
218-
.call(_colAxis)
219-
.each('end', function () {
217+
var _colAxisTransition = dc.transition(_chartBody.select('g.cols.axis'), _chart.transitionDuration())
218+
.call(_colAxis);
219+
_rowAxis.scale(rows)
220+
.tickFormat(_chart.rowsLabel());
221+
var _rowAxisTransition = dc.transition(_chartBody.select('g.rows.axis'), _chart.transitionDuration())
222+
.call(_rowAxis);
223+
// We need the clicks added after the transition. Unfortunately, this is handled differently
224+
// for selection/transition
225+
if (_colAxisTransition.duration || _rowAxisTransition.duration) {
226+
_colAxisTransition.each('end', function () {
220227
d3.select(this)
221228
.selectAll('g')
222229
.on('click', _chart.xAxisOnClick());
223230
});
224-
225-
_rowAxis.scale(rows)
226-
.tickFormat(_chart.rowsLabel());
227-
dc.transition(_chartBody.select('g.axis.y'), _chart.transitionDuration())
228-
.call(_rowAxis)
229-
.each('end', function () {
231+
_rowAxisTransition.each('end', function () {
230232
d3.select(this)
231233
.selectAll('g')
232234
.on('click', _chart.yAxisOnClick());
233235
});
236+
} else {
237+
_colAxisTransition.selectAll('g').on('click', _chart.xAxisOnClick());
238+
_rowAxisTransition.selectAll('g').on('click', _chart.yAxisOnClick());
239+
}
234240

235241
// Update boxes
236242
var boxes = _chartBody.selectAll('g.box-group')

0 commit comments

Comments
 (0)