Skip to content

Commit

Permalink
fix: change the baseline for more robust vertical position ht Marco
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera committed Mar 23, 2021
1 parent 5f2e3bb commit cb12f05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ function renderLinkLabels(
});
}

const midlineOffset = 0.35; // 0.35 is a [common constant](http://tavmjong.free.fr/SVG/TEXT_IN_A_BOX/index.html) representing half height
const innerPad = midlineOffset * panelTitleFontSize; // todo replace it with theme.axisPanelTitle.padding.inner

/** @internal */
export function renderPartitionCanvas2d(
ctx: CanvasRenderingContext2D,
Expand Down Expand Up @@ -265,19 +268,21 @@ export function renderPartitionCanvas2d(
// - due to using the math x/y convention (+y is up) while Canvas uses screen convention (+y is down)
// text rendering must be y-flipped, which is a bit easier this way
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.textBaseline = 'bottom';

// panel titles
ctx.fillText(
panelTitle,
isSunburst(config.partitionLayout) ? diskCenter.x : diskCenter.x + (config.width * width) / 2,
isSunburst(config.partitionLayout)
? config.linkLabel.maxCount > 0
? diskCenter.y - (config.height * height) / 2 + 12
: diskCenter.y - outerRadius - panelTitleFontSize
? diskCenter.y - (config.height * height) / 2 + panelTitleFontSize
: diskCenter.y - outerRadius - innerPad
: diskCenter.y + 12,
);

ctx.textBaseline = 'middle';

ctx.translate(diskCenter.x, diskCenter.y);
// this applies the mathematical x/y conversion (+y is North) which is easier when developing geometry
// functions - also, all renderers have flexibility (eg. SVG scale) and WebGL NDC is also +y up
Expand Down

0 comments on commit cb12f05

Please sign in to comment.