Skip to content

Commit

Permalink
fix: fix pie chart alignment (carbon-design-system#716)
Browse files Browse the repository at this point in the history
Co-authored-by: Fei <[email protected]>
  • Loading branch information
2 people authored and linhenry0417 committed Jul 23, 2020
1 parent ac83743 commit 6a0480b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/core/src/components/graphs/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a0480b

Please sign in to comment.