From 3a0fb89baabe163f4325e7b7c38098f44b27ff05 Mon Sep 17 00:00:00 2001 From: Abhinandan Kushwaha Date: Tue, 19 Oct 2021 18:39:15 +0530 Subject: [PATCH] Added props shiftTextX and shiftTextY --- docs/PieChart/PieChartProps.md | 2 ++ src/PieChart/index.tsx | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/PieChart/PieChartProps.md b/docs/PieChart/PieChartProps.md index 4c49e04..1279b94 100644 --- a/docs/PieChart/PieChartProps.md +++ b/docs/PieChart/PieChartProps.md @@ -27,6 +27,8 @@ | value | number | Value of the item, representing a section of the Pie chart | | shiftX | number | Translates (shifts) the particular section horizontally by given value | | shiftY | number | Translates (shifts) the particular section vertically by given value | +| shiftTextX | number | Translates (shifts) the position of label text horizontally | +| shiftTextY | number | Translates (shifts) the position of label text vertically | | color | ColorValue | Color (background color) of the section | | text | string | Label text for the sections | | textColor | ColorValue | Color of the text (label) inside the section | diff --git a/src/PieChart/index.tsx b/src/PieChart/index.tsx index c151404..7f09c81 100644 --- a/src/PieChart/index.tsx +++ b/src/PieChart/index.tsx @@ -42,6 +42,8 @@ type itemType = { textSize?: number; textBackgroundColor?: string; textBackgroundRadius?: number; + shiftTextX?: number; + shiftTextY?: number; }; export const PieChart = (props: propTypes) => { const {data, isThreeD} = props; @@ -144,6 +146,9 @@ export const PieChart = (props: propTypes) => { const shiftX = dataItem.shiftX || 0; const shiftY = dataItem.shiftY || 0; + const shiftTextX = dataItem.shiftTextX || 0; + const shiftTextY = dataItem.shiftTextY || 0; + /**************** This section is to prevent the shadow from ***************/ /**************** being visible inside the chart content if ***************/ /**************** the color of sections is transparent ***************/ @@ -260,6 +265,9 @@ export const PieChart = (props: propTypes) => { ctx.fill(); } + xx += shiftTextX; + yy += shiftTextY; + ctx.fillStyle = dataItem.textColor || textColor || colors[i++ % 8]; let labelText = dataItem.text || ''; if (showValuesAsLabels && !labelText) {