Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 3eea065

Browse files
author
sluger
committed
addressed feedback
1 parent 480eeeb commit 3eea065

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/scale/hierarchical.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,31 @@ const HierarchicalScale = Scale.extend({
9090
// max 5 levels for now
9191
const ratios = [1, Math.pow(ratio, 1), Math.pow(ratio, 2), Math.pow(ratio, 3), Math.pow(ratio, 4)];
9292

93-
const distances = []; {
94-
let prev = nodes[0];
95-
let prevParents = parentsOf(prev, flat);
96-
distances.push(0.5); // half top level distance before and after
97-
98-
for (let i = 1; i < nodes.length; ++i) {
99-
const n = nodes[i];
100-
const parents = parentsOf(n, flat);
101-
if (prev.parent === n.parent) {
102-
// same parent -> can use the level distance
103-
distances.push(ratios[n.level]);
104-
} else {
105-
// differnt level -> use the distance of the common parent
106-
// find level of common parent
107-
let common = 0;
108-
while (parents[common] === prevParents[common]) {
109-
common++;
110-
}
111-
distances.push(ratios[common]);
93+
const distances = [];
94+
95+
let prev = nodes[0];
96+
let prevParents = parentsOf(prev, flat);
97+
distances.push(0.5); // half top level distance before and after
98+
99+
for (let i = 1; i < nodes.length; ++i) {
100+
const n = nodes[i];
101+
const parents = parentsOf(n, flat);
102+
if (prev.parent === n.parent) {
103+
// same parent -> can use the level distance
104+
distances.push(ratios[n.level]);
105+
} else {
106+
// differnt level -> use the distance of the common parent
107+
// find level of common parent
108+
let common = 0;
109+
while (parents[common] === prevParents[common]) {
110+
common++;
112111
}
113-
prev = n;
114-
prevParents = parents;
112+
distances.push(ratios[common]);
115113
}
116-
distances.push(0.5);
114+
prev = n;
115+
prevParents = parents;
117116
}
117+
distances.push(0.5);
118118

119119
const distance = distances.reduce((acc, s) => acc + s, 0);
120120
const factor = total / distance;
@@ -172,20 +172,21 @@ const HierarchicalScale = Scale.extend({
172172
return this._nodes[0].width;
173173
}
174174

175-
return this._centerBase(index);
175+
return this._centerBase(index + this.minIndex);
176176
},
177177

178178
_centerBase(index) {
179179
const centerTick = this.options.offset;
180180
const base = this.isHorizontal() ? this.left : this.top;
181-
const node = this._nodes[index + this.minIndex];
181+
const node = this._nodes[index];
182182

183183
if (node == null) {
184184
return base;
185185
}
186186

187187
const nodeCenter = node.center != null ? node.center : 0;
188-
return base + nodeCenter - (centerTick ? 0 : node.width / 2);
188+
const nodeWidth = node.width != null ? node.width : 0;
189+
return base + nodeCenter - (centerTick ? 0 : nodeWidth / 2);
189190
},
190191

191192
getValueForPixel(pixel) {

0 commit comments

Comments
 (0)