From 85b07b0091634663d81b1932c8d026fe0a3d3704 Mon Sep 17 00:00:00 2001 From: dv4mp1r3 Date: Thu, 28 Apr 2022 19:35:23 +0300 Subject: [PATCH] fix getTrianglePath and getBarOpacity return value --- src/index.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 65fbe48..9141a73 100755 --- a/src/index.ts +++ b/src/index.ts @@ -101,9 +101,30 @@ export class ChartwerkBarPod extends ChartwerkPod { // (x, y) - top left corner const Y_OFFSET = 2; const correctedY = Math.max(y, Y_OFFSET); - return `M ${x - Y_OFFSET} ${correctedY - Y_OFFSET} - L ${x + length + Y_OFFSET} ${correctedY - Y_OFFSET} - L ${x + length / 2} ${correctedY + length - Y_OFFSET} z`; + const correctedLength = length <= 10 ? length : 10; + + let x1 = x - Y_OFFSET; + let x2 = x + length + Y_OFFSET; + let x1x2Len = x2 - x1; + + let y1 = correctedY - Y_OFFSET; + let yM = correctedY + length - Y_OFFSET; + if (x1x2Len > correctedLength) { + const xDiff = x1x2Len - correctedLength; + x1 += xDiff / 2; + x2 -= xDiff / 2; + + const yDiff = yM - y1; + + if (xDiff < yDiff) { + y1 += (yDiff - xDiff) + Y_OFFSET*3; + } + } + const x3 = x + length / 2; + + return `M ${x1} ${y1} + L ${x2} ${y1} + L ${x3} ${yM} z`; } getBarOpacity(rowValues: RowValues): number { @@ -164,7 +185,7 @@ export class ChartwerkBarPod extends ChartwerkPod { const tagrets = _.map(series, serie => serie.target); const zippedData = _.zip(keysColumn, zippedValuesColumn, zippedAdditionalValuesColumn, tagrets); const data = _.map(zippedData, row => { return { key: row[0], values: row[1], additionalValues: row[2], colors, serieTarget: tagrets } }); - return data; + return data.filter(v => v.key !== undefined); } public renderSharedCrosshair(values: { x?: number, y?: number }): void {