Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 36x 172x 17x 155x 414x 155x 155x 407x 407x 155x 155x 36x 169x 169x 16x 306x 153x 153x | export const getClosestPairDiffAndRange = (data: number[] | Date[]): [number, number] | undefined => { if (data.length < 2) { return; } data = data.sort((a, b) => a instanceof Date ? (a as Date).getTime() - (b as Date).getTime() : (a as number) - (b as number), ); let minDiff = Number.MAX_VALUE; for (let i = 1; i < data.length; i++) { const diff = data[i] instanceof Date ? (data[i] as Date).getTime() - (data[i - 1] as Date).getTime() : (data[i] as number) - (data[i - 1] as number); minDiff = Math.min(minDiff, diff); } const range = data[0] instanceof Date ? (data[data.length - 1] as Date).getTime() - (data[0] as Date).getTime() : (data[data.length - 1] as number) - (data[0] as number); return [minDiff, range]; }; export const calculateAppropriateBarWidth = (data: number[] | Date[], totalWidth: number) => { const result = getClosestPairDiffAndRange(data); if (!result || result[1] === 0) { return 16; } const [closestPairDiff, range] = result; // Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes // for the derivation of the following formula. const barWidth = Math.round((totalWidth * closestPairDiff) / (2 * range + closestPairDiff)); return barWidth; }; |