Skip to content

Commit 5aa3310

Browse files
committed
add tiling orientation for icicle
1 parent 0822bf5 commit 5aa3310

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/traces/icicle/attributes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ module.exports = {
2222
maxdepth: sunburstAttrs.maxdepth,
2323

2424
tiling: {
25+
orientation: {
26+
valType: 'enumerated',
27+
values: ['v', 'h'],
28+
dflt: 'h',
29+
editType: 'plot',
30+
description: [
31+
'Sets the orientation of the icicle.',
32+
'With *v* the icicle grows vertically.',
33+
'With *h* the icicle grows horizontally.',
34+
].join(' ')
35+
},
36+
2537
flip: {
2638
valType: 'flaglist',
2739
flags: [

src/traces/icicle/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3434
coerce('level');
3535
coerce('maxdepth');
3636

37+
coerce('tiling.orientation');
3738
coerce('tiling.flip');
3839
coerce('tiling.pad');
3940

src/traces/icicle/draw_descendants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
4040
// N.B. slice data isn't the calcdata,
4141
// grab corresponding calcdata item in sliceData[i].data.data
4242
var allData = partition(entry, [width, height], {
43-
packing: trace.tiling.packing,
44-
squarifyratio: trace.tiling.squarifyratio,
4543
flipX: trace.tiling.flip.indexOf('x') > -1,
4644
flipY: trace.tiling.flip.indexOf('y') > -1,
45+
orientation: trace.tiling.orientation,
4746
pad: {
4847
inner: trace.tiling.pad
4948
}

src/traces/icicle/partition.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ var d3Hierarchy = require('d3-hierarchy');
55
module.exports = function partition(entry, size, opts) {
66
var flipX = opts.flipX;
77
var flipY = opts.flipY;
8+
var swapXY = opts.orientation === 'h';
89

910
var result = d3Hierarchy
1011
.partition()
1112
.padding(opts.pad.inner)
12-
.size(size)(entry);
13+
.size(
14+
swapXY ? [size[1], size[0]] : size
15+
)(entry);
1316

14-
if(flipX || flipY) {
17+
if(swapXY || flipX || flipY) {
1518
flipTree(result, size, {
19+
swapXY: swapXY,
1620
flipX: flipX,
1721
flipY: flipY
1822
});
@@ -23,6 +27,18 @@ module.exports = function partition(entry, size, opts) {
2327
function flipTree(node, size, opts) {
2428
var tmp;
2529

30+
if(opts.swapXY) {
31+
// swap x0 and y0
32+
tmp = node.x0;
33+
node.x0 = node.y0;
34+
node.y0 = tmp;
35+
36+
// swap x1 and y1
37+
tmp = node.x1;
38+
node.x1 = node.y1;
39+
node.y1 = tmp;
40+
}
41+
2642
if(opts.flipX) {
2743
tmp = node.x0;
2844
node.x0 = size[0] - node.x1;

0 commit comments

Comments
 (0)