@@ -29,6 +29,8 @@ dc.heatMap = function (parent, chartGroup) {
29
29
var _rowOrdering = d3 . ascending ;
30
30
var _colScale = d3 . scale . ordinal ( ) ;
31
31
var _rowScale = d3 . scale . ordinal ( ) ;
32
+ var _colAxis = d3 . svg . axis ( ) . orient ( 'bottom' ) ;
33
+ var _rowAxis = d3 . svg . axis ( ) . orient ( 'left' ) ;
32
34
33
35
var _xBorderRadius = DEFAULT_BORDER_RADIUS ;
34
36
var _yBorderRadius = DEFAULT_BORDER_RADIUS ;
@@ -193,6 +195,13 @@ dc.heatMap = function (parent, chartGroup) {
193
195
. append ( 'g' )
194
196
. attr ( 'class' , 'heatmap' )
195
197
. attr ( 'transform' , 'translate(' + _chart . margins ( ) . left + ',' + _chart . margins ( ) . top + ')' ) ;
198
+ _chartBody . append ( 'g' )
199
+ . attr ( 'class' , 'cols axis' )
200
+ . attr ( 'transform' , 'translate(0,' + _chart . effectiveHeight ( ) + ')' ) ;
201
+ _chartBody . append ( 'g' )
202
+ . attr ( 'class' , 'rows axis' ) ;
203
+ _colScale . rangeRoundBands ( [ 0 , _chart . effectiveWidth ( ) ] ) ;
204
+ _rowScale . rangeRoundBands ( [ _chart . effectiveHeight ( ) , 0 ] ) ;
196
205
197
206
return _chart . _doRedraw ( ) ;
198
207
} ;
@@ -210,17 +219,39 @@ dc.heatMap = function (parent, chartGroup) {
210
219
rows = _rowScale . domain ( rows ) ;
211
220
cols = _colScale . domain ( cols ) ;
212
221
213
- var rowCount = rows . domain ( ) . length ,
214
- colCount = cols . domain ( ) . length ,
215
- boxWidth = Math . floor ( _chart . effectiveWidth ( ) / colCount ) ,
216
- boxHeight = Math . floor ( _chart . effectiveHeight ( ) / rowCount ) ;
222
+ // Update axis
223
+ _colAxis . scale ( cols )
224
+ . tickFormat ( _chart . colsLabel ( ) ) ;
225
+ var _colAxisTransition = dc . transition ( _chartBody . select ( 'g.cols.axis' ) , _chart . transitionDuration ( ) , _chart . transitionDelay ( ) )
226
+ . call ( _colAxis ) ;
227
+ _rowAxis . scale ( rows )
228
+ . tickFormat ( _chart . rowsLabel ( ) ) ;
229
+ var _rowAxisTransition = dc . transition ( _chartBody . select ( 'g.rows.axis' ) , _chart . transitionDuration ( ) , _chart . transitionDelay ( ) )
230
+ . call ( _rowAxis ) ;
231
+ // We need the clicks added after the transition. Unfortunately, this is handled differently
232
+ // for selection/transition
233
+ if ( _colAxisTransition . duration || _rowAxisTransition . duration ) {
234
+ _colAxisTransition . each ( 'end' , function ( ) {
235
+ d3 . select ( this )
236
+ . selectAll ( 'g' )
237
+ . on ( 'click' , _chart . xAxisOnClick ( ) ) ;
238
+ } ) ;
239
+ _rowAxisTransition . each ( 'end' , function ( ) {
240
+ d3 . select ( this )
241
+ . selectAll ( 'g' )
242
+ . on ( 'click' , _chart . yAxisOnClick ( ) ) ;
243
+ } ) ;
244
+ } else {
245
+ _colAxisTransition . selectAll ( 'g' ) . on ( 'click' , _chart . xAxisOnClick ( ) ) ;
246
+ _rowAxisTransition . selectAll ( 'g' ) . on ( 'click' , _chart . yAxisOnClick ( ) ) ;
247
+ }
217
248
218
- cols . rangeRoundBands ( [ 0 , _chart . effectiveWidth ( ) ] ) ;
219
- rows . rangeRoundBands ( [ _chart . effectiveHeight ( ) , 0 ] ) ;
249
+ // Update boxes
250
+ var boxes = _chartBody . selectAll ( 'g.box-group' )
251
+ . data ( _chart . data ( ) , function ( d , i ) {
252
+ return _chart . keyAccessor ( ) ( d , i ) + '\0' + _chart . valueAccessor ( ) ( d , i ) ;
253
+ } ) ;
220
254
221
- var boxes = _chartBody . selectAll ( 'g.box-group' ) . data ( _chart . data ( ) , function ( d , i ) {
222
- return _chart . keyAccessor ( ) ( d , i ) + '\0' + _chart . valueAccessor ( ) ( d , i ) ;
223
- } ) ;
224
255
var gEnter = boxes . enter ( ) . append ( 'g' )
225
256
. attr ( 'class' , 'box-group' ) ;
226
257
@@ -240,45 +271,11 @@ dc.heatMap = function (parent, chartGroup) {
240
271
. attr ( 'rx' , _xBorderRadius )
241
272
. attr ( 'ry' , _yBorderRadius )
242
273
. attr ( 'fill' , _chart . getColor )
243
- . attr ( 'width' , boxWidth )
244
- . attr ( 'height' , boxHeight ) ;
274
+ . attr ( 'width' , _colScale . rangeBand ( ) )
275
+ . attr ( 'height' , _rowScale . rangeBand ( ) ) ;
245
276
246
277
boxes . exit ( ) . remove ( ) ;
247
278
248
- var gCols = _chartBody . selectAll ( 'g.cols' ) ;
249
- if ( gCols . empty ( ) ) {
250
- gCols = _chartBody . append ( 'g' ) . attr ( 'class' , 'cols axis' ) ;
251
- }
252
- var gColsText = gCols . selectAll ( 'text' ) . data ( cols . domain ( ) ) ;
253
- gColsText . enter ( ) . append ( 'text' )
254
- . attr ( 'x' , function ( d ) { return cols ( d ) + boxWidth / 2 ; } )
255
- . style ( 'text-anchor' , 'middle' )
256
- . attr ( 'y' , _chart . effectiveHeight ( ) )
257
- . attr ( 'dy' , 12 )
258
- . on ( 'click' , _chart . xAxisOnClick ( ) )
259
- . text ( _chart . colsLabel ( ) ) ;
260
- dc . transition ( gColsText , _chart . transitionDuration ( ) , _chart . transitionDelay ( ) )
261
- . text ( _chart . colsLabel ( ) )
262
- . attr ( 'x' , function ( d ) { return cols ( d ) + boxWidth / 2 ; } )
263
- . attr ( 'y' , _chart . effectiveHeight ( ) ) ;
264
- gColsText . exit ( ) . remove ( ) ;
265
- var gRows = _chartBody . selectAll ( 'g.rows' ) ;
266
- if ( gRows . empty ( ) ) {
267
- gRows = _chartBody . append ( 'g' ) . attr ( 'class' , 'rows axis' ) ;
268
- }
269
- var gRowsText = gRows . selectAll ( 'text' ) . data ( rows . domain ( ) ) ;
270
- gRowsText . enter ( ) . append ( 'text' )
271
- . attr ( 'dy' , 6 )
272
- . style ( 'text-anchor' , 'end' )
273
- . attr ( 'x' , 0 )
274
- . attr ( 'dx' , - 2 )
275
- . on ( 'click' , _chart . yAxisOnClick ( ) )
276
- . text ( _chart . rowsLabel ( ) ) ;
277
- dc . transition ( gRowsText , _chart . transitionDuration ( ) , _chart . transitionDelay ( ) )
278
- . text ( _chart . rowsLabel ( ) )
279
- . attr ( 'y' , function ( d ) { return rows ( d ) + boxHeight / 2 ; } ) ;
280
- gRowsText . exit ( ) . remove ( ) ;
281
-
282
279
if ( _chart . hasFilter ( ) ) {
283
280
_chart . selectAll ( 'g.box-group' ) . each ( function ( d ) {
284
281
if ( _chart . isSelectedNode ( d ) ) {
0 commit comments