Skip to content

Commit d96f3f1

Browse files
committed
reuse flip tree in icicle
1 parent eaad10d commit d96f3f1

File tree

3 files changed

+38
-70
lines changed

3 files changed

+38
-70
lines changed

src/traces/icicle/partition.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var d3Hierarchy = require('d3-hierarchy');
4+
var flipTree = require('../treemap/flip_tree');
45

56
module.exports = function partition(entry, size, opts) {
67
var flipX = opts.flipX;
@@ -31,38 +32,3 @@ module.exports = function partition(entry, size, opts) {
3132
}
3233
return result;
3334
};
34-
35-
function flipTree(node, size, opts) {
36-
var tmp;
37-
38-
if(opts.swapXY) {
39-
// swap x0 and y0
40-
tmp = node.x0;
41-
node.x0 = node.y0;
42-
node.y0 = tmp;
43-
44-
// swap x1 and y1
45-
tmp = node.x1;
46-
node.x1 = node.y1;
47-
node.y1 = tmp;
48-
}
49-
50-
if(opts.flipX) {
51-
tmp = node.x0;
52-
node.x0 = size[0] - node.x1;
53-
node.x1 = size[0] - tmp;
54-
}
55-
56-
if(opts.flipY) {
57-
tmp = node.y0;
58-
node.y0 = size[1] - node.y1;
59-
node.y1 = size[1] - tmp;
60-
}
61-
62-
var children = node.children;
63-
if(children) {
64-
for(var i = 0; i < children.length; i++) {
65-
flipTree(children[i], size, opts);
66-
}
67-
}
68-
}

src/traces/treemap/flip_tree.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
module.exports = function flipTree(node, size, opts) {
4+
var tmp;
5+
6+
if(opts.swapXY) {
7+
// swap x0 and y0
8+
tmp = node.x0;
9+
node.x0 = node.y0;
10+
node.y0 = tmp;
11+
12+
// swap x1 and y1
13+
tmp = node.x1;
14+
node.x1 = node.y1;
15+
node.y1 = tmp;
16+
}
17+
18+
if(opts.flipX) {
19+
tmp = node.x0;
20+
node.x0 = size[0] - node.x1;
21+
node.x1 = size[0] - tmp;
22+
}
23+
24+
if(opts.flipY) {
25+
tmp = node.y0;
26+
node.y0 = size[1] - node.y1;
27+
node.y1 = size[1] - tmp;
28+
}
29+
30+
var children = node.children;
31+
if(children) {
32+
for(var i = 0; i < children.length; i++) {
33+
flipTree(children[i], size, opts);
34+
}
35+
}
36+
};

src/traces/treemap/partition.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var d3Hierarchy = require('d3-hierarchy');
4+
var flipTree = require('./flip_tree');
45

56
module.exports = function partition(entry, size, opts) {
67
var flipX = opts.flipX;
@@ -59,38 +60,3 @@ function getTilingMethod(key, squarifyratio) {
5960
return d3Hierarchy.treemapSliceDice;
6061
}
6162
}
62-
63-
function flipTree(node, size, opts) {
64-
var tmp;
65-
66-
if(opts.swapXY) {
67-
// swap x0 and y0
68-
tmp = node.x0;
69-
node.x0 = node.y0;
70-
node.y0 = tmp;
71-
72-
// swap x1 and y1
73-
tmp = node.x1;
74-
node.x1 = node.y1;
75-
node.y1 = tmp;
76-
}
77-
78-
if(opts.flipX) {
79-
tmp = node.x0;
80-
node.x0 = size[0] - node.x1;
81-
node.x1 = size[0] - tmp;
82-
}
83-
84-
if(opts.flipY) {
85-
tmp = node.y0;
86-
node.y0 = size[1] - node.y1;
87-
node.y1 = size[1] - tmp;
88-
}
89-
90-
var children = node.children;
91-
if(children) {
92-
for(var i = 0; i < children.length; i++) {
93-
flipTree(children[i], size, opts);
94-
}
95-
}
96-
}

0 commit comments

Comments
 (0)