diff --git a/packages/charts/src/coordinates/EdgeCoordinateV3.tsx b/packages/charts/src/coordinates/EdgeCoordinateV3.tsx index a061fe31c..057d7f6a8 100644 --- a/packages/charts/src/coordinates/EdgeCoordinateV3.tsx +++ b/packages/charts/src/coordinates/EdgeCoordinateV3.tsx @@ -202,7 +202,10 @@ export function drawOnCanvas(ctx: CanvasRenderingContext2D, props) { ctx.font = `${fontSize}px ${fontFamily}`; ctx.textBaseline = "middle"; - const width = Math.round(ctx.measureText(coordinate).width + 10); + let width = props.rectWidth; + if (props.fitToText) { + width = Math.round(ctx.measureText(coordinate).width + 10); + } const edge = helper({ ...props, rectWidth: width }); if (edge === null) { diff --git a/packages/charts/src/coordinates/EdgeIndicator.tsx b/packages/charts/src/coordinates/EdgeIndicator.tsx index 572d57ffc..236ced70c 100644 --- a/packages/charts/src/coordinates/EdgeIndicator.tsx +++ b/packages/charts/src/coordinates/EdgeIndicator.tsx @@ -13,6 +13,7 @@ interface EdgeIndicatorProps { readonly displayFormat?: any; // func readonly edgeAt?: "left" | "right"; readonly fill?: string | any; // func + readonly fitToText?: boolean; readonly itemType: "first" | "last"; readonly lineStroke?: string | any; // func readonly lineStrokeDasharray?: strokeDashTypes; @@ -29,6 +30,7 @@ export class EdgeIndicator extends React.Component { public static defaultProps = { className: "react-financial-charts-edgeindicator", type: "horizontal", + fitToText: false, orient: "right", edgeAt: "right", textFill: "#FFFFFF", diff --git a/packages/charts/src/coordinates/MouseCoordinateX.tsx b/packages/charts/src/coordinates/MouseCoordinateX.tsx index 8dafda85b..5529931e8 100644 --- a/packages/charts/src/coordinates/MouseCoordinateX.tsx +++ b/packages/charts/src/coordinates/MouseCoordinateX.tsx @@ -11,6 +11,7 @@ interface MouseCoordinateXProps { readonly customX: any; // func readonly displayFormat: any; // func readonly fill?: string; + readonly fitToText?: boolean; readonly fontFamily?: string; readonly fontSize?: number; readonly opacity?: number; @@ -47,6 +48,7 @@ export class MouseCoordinateX extends React.Component { at: "bottom", customX: defaultCustomX, fill: "#37474F", + fitToText: true, fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif", fontSize: 13, opacity: 1, @@ -99,7 +101,7 @@ export class MouseCoordinateX extends React.Component { const { customX, orient, at } = props; const { stroke, strokeOpacity, strokeWidth } = props; const { rectRadius, rectWidth, rectHeight } = props; - const { fill, opacity, fontFamily, fontSize, textFill } = props; + const { fill, opacity, fitToText, fontFamily, fontSize, textFill } = props; const edgeAt = (at === "bottom") ? height : 0; @@ -115,6 +117,7 @@ export class MouseCoordinateX extends React.Component { const coordinateProps = { coordinate, + fitToText, show, type, orient, diff --git a/packages/charts/src/coordinates/MouseCoordinateY.tsx b/packages/charts/src/coordinates/MouseCoordinateY.tsx index 0ffd9e207..0a44bd1b9 100644 --- a/packages/charts/src/coordinates/MouseCoordinateY.tsx +++ b/packages/charts/src/coordinates/MouseCoordinateY.tsx @@ -15,6 +15,7 @@ interface MouseCoordinateYProps { readonly fontFamily?: string; readonly fontSize?: number; readonly fill?: string; + readonly fitToText?: boolean; readonly opacity?: number; readonly orient?: "left" | "right"; readonly rectWidth?: number; @@ -32,6 +33,7 @@ export class MouseCoordinateY extends React.Component { at: "right", dx: 0, fill: "#37474F", + fitToText: false, fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif", fontSize: 13, opacity: 1, @@ -103,7 +105,7 @@ export function getYCoordinate(y, displayValue, props, moreProps) { const { width } = moreProps; const { orient, at, rectWidth, rectHeight, dx } = props; - const { fill, opacity, fontFamily, fontSize, textFill, arrowWidth } = props; + const { fill, opacity, fitToText, fontFamily, fontSize, textFill, arrowWidth } = props; const { stroke, strokeOpacity, strokeWidth } = props; const x1 = 0; @@ -116,6 +118,7 @@ export function getYCoordinate(y, displayValue, props, moreProps) { const coordinateProps = { coordinate: displayValue, show: true, + fitToText, type, orient, edgeAt, diff --git a/packages/stories/src/features/stockChart.tsx b/packages/stories/src/features/stockChart.tsx index 212016d8f..baaadd8cf 100644 --- a/packages/stories/src/features/stockChart.tsx +++ b/packages/stories/src/features/stockChart.tsx @@ -113,9 +113,12 @@ class StockChart extends React.Component { - + { - +