From 9e32b31ae24d894f4798ed2c400fa9fca03b3cb1 Mon Sep 17 00:00:00 2001 From: rkyle35242 Date: Thu, 2 May 2024 09:50:34 -0500 Subject: [PATCH] draw segments in two strokes --- .../__snapshots__/RangesDisplay.spec.js.snap | 8 +++--- .../__snapshots__/Segment.spec.js.snap | 4 +-- .../__snapshots__/arcHelpers.spec.js.snap | 5 ++++ src/utils/__tests__/arcHelpers.spec.js | 8 ++---- src/utils/arcHelpers.js | 26 ++++++++++++++++--- 5 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 src/utils/__tests__/__snapshots__/arcHelpers.spec.js.snap diff --git a/src/components/__tests__/__snapshots__/RangesDisplay.spec.js.snap b/src/components/__tests__/__snapshots__/RangesDisplay.spec.js.snap index 0ad23df..efa55ed 100644 --- a/src/components/__tests__/__snapshots__/RangesDisplay.spec.js.snap +++ b/src/components/__tests__/__snapshots__/RangesDisplay.spec.js.snap @@ -11,7 +11,7 @@ exports[`RangesDisplay renders default 1`] = ` > { }); it('returns d path for an arc', () => { - expect(drawArc(152, 152, 104, 136.5, 158)).toEqual( - 'M 248.4271208749459 113.04091428474516 A 104 104 0 0 0 227.43893458527793 80.41112412784959' - ); + expect(drawArc(152, 152, 104, 136.5, 158)).toMatchSnapshot(); }); it('returns d path for an arc - opposite angle needed for ratings range display', () => { - expect(drawArc(152, 152, 104, 136.5, 158, true)).toEqual( - 'M 248.4271208749459 113.04091428474516 A 104 104 0 0 1 227.43893458527793 80.41112412784959' - ); + expect(drawArc(152, 152, 104, 136.5, 158, true)).toMatchSnapshot(); }); }); diff --git a/src/utils/arcHelpers.js b/src/utils/arcHelpers.js index 4246906..934aded 100644 --- a/src/utils/arcHelpers.js +++ b/src/utils/arcHelpers.js @@ -9,13 +9,31 @@ export const polarToCartesian = (centerX, centerY, radius, angleInDegrees) => { export const drawArc = (x, y, radius, startAngle, endAngle, range = false) => { const start = polarToCartesian(x, y, radius, endAngle); + const midPoint = polarToCartesian(x, y, radius, (startAngle + endAngle) / 2); const end = polarToCartesian(x, y, radius, startAngle); - const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1'; - const sweepFlag = range ? 1 : 0; - const d = ['M', start.x, start.y, 'A', radius, radius, 0, largeArcFlag, sweepFlag, end.x, end.y].join(' '); - + const d = [ + 'M', + start.x, + start.y, + 'A', + radius, + radius, + 0, + 0, + sweepFlag, + midPoint.x, + midPoint.y, + 'A', + radius, + radius, + 0, + 0, + sweepFlag, + end.x, + end.y + ].join(' '); return d; };