From 02f5d24bc38a4519d899b2236d12269189cd320f Mon Sep 17 00:00:00 2001 From: Fei Date: Tue, 21 Jul 2020 15:31:45 -0400 Subject: [PATCH] fix: fix pie chart alignment --- packages/core/src/components/graphs/pie.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/src/components/graphs/pie.ts b/packages/core/src/components/graphs/pie.ts index 316b4ae2b0..3c2272ce59 100644 --- a/packages/core/src/components/graphs/pie.ts +++ b/packages/core/src/components/graphs/pie.ts @@ -2,7 +2,7 @@ import { Component } from "../component"; import { DOMUtils } from "../../services"; import { Tools } from "../../tools"; -import { CalloutDirections, Roles, Events } from "../../interfaces"; +import { CalloutDirections, Roles, Events, Alignments } from "../../interfaces"; // D3 Imports import { select } from "d3-selection"; @@ -232,14 +232,25 @@ export class Pie extends Component { optionName, "alignment" ); - const alignmentOffset = DOMUtils.getAlignmentOffset(alignment, svg, this.getParent()); + + const { width } = DOMUtils.getSVGElementSize( + this.getParent(), + { useAttr: true } + ); // Position Pie - const pieTranslateX = radius + options.pie.xOffset + alignmentOffset; + let pieTranslateX = radius + options.pie.xOffset; + if (alignment === Alignments.CENTER) { + pieTranslateX = width / 2; + } else if (alignment === Alignments.RIGHT) { + pieTranslateX = width - radius - options.pie.xOffset; + } + let pieTranslateY = radius + options.pie.yOffset; if (calloutData.length > 0) { pieTranslateY += options.pie.yOffsetCallout; } + svg.attr("transform", `translate(${pieTranslateX}, ${pieTranslateY})`); // Add event listeners