Skip to content

Commit

Permalink
Allow manual subscript on leaf nodes
Browse files Browse the repository at this point in the history
Note, this is not perfect by any means... The subscript is not
factored into the calculation for the node width properly and the
combined text (value + subscript) is not properly centered in the
node.

There is room for a future refactor to calculate the combined text width
better and then layout the text while drawing in a way that properly
centers the text again.

Fixes: #2
  • Loading branch information
int2str committed Aug 13, 2019
1 parent 0bc9804 commit d74aa1e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tree.js
Expand Up @@ -116,11 +116,9 @@ class Tree {
break;

case '_':
if (state == State.LABEL) {
state = State.SUBSCRIPT;
break;
}
// Fallthrough
state = State.SUBSCRIPT;
break;

case ' ':
if (state != State.APPENDING) {
state = State.APPENDING;
Expand Down Expand Up @@ -178,7 +176,8 @@ class Tree {

// Reset child width and calculate text width
for (let node of this.nodes) {
node.width = this.canvas.textWidth(node.value) + PADDING;
node.width = this.canvas.textWidth(node.value) +
this.canvas.textWidth(node.subscript) * 3 / 4 + PADDING;
node.child_width = 0;
}

Expand Down

0 comments on commit d74aa1e

Please sign in to comment.