diff --git a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-small-multiples-alpha-sunbursts-visually-looks-correct-1-snap.png b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-small-multiples-alpha-sunbursts-visually-looks-correct-1-snap.png index ed602a081b..5632a4e71f 100644 Binary files a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-small-multiples-alpha-sunbursts-visually-looks-correct-1-snap.png and b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-small-multiples-alpha-sunbursts-visually-looks-correct-1-snap.png differ diff --git a/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts b/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts index e0f8dc7204..7a2c5f5526 100644 --- a/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts +++ b/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts @@ -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, @@ -265,7 +268,7 @@ 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( @@ -273,11 +276,13 @@ export function renderPartitionCanvas2d( 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