Skip to content

Commit 6d3acea

Browse files
committed
chore: break up a nested ternary
1 parent 91013f9 commit 6d3acea

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License. */
1818

1919
import { wrapToTau } from '../geometry';
20-
import { Coordinate, Distance, Pixels, Radian, Radius, RingSector } from '../types/geometry_types';
20+
import { Coordinate, Distance, Pixels, Radian, Radius, Ratio, RingSector } from '../types/geometry_types';
2121
import { Config } from '../types/config_types';
2222
import { logarithm, TAU, trueBearingToStandardPositionAngle } from '../utils/math';
2323
import {
@@ -172,6 +172,26 @@ export function getSectorRowGeometry(
172172
return { rowCentroidX, rowCentroidY, maximumRowLength };
173173
}
174174

175+
function getVerticalAlignment(
176+
container: RectangleConstruction,
177+
verticalAlignment: VerticalAlignment,
178+
linePitch: Pixels,
179+
totalRowCount: number,
180+
rowIndex: number,
181+
padding: Pixels,
182+
fontSize: Pixels,
183+
overhang: Ratio,
184+
) {
185+
switch (verticalAlignment) {
186+
case VerticalAlignments.top:
187+
return -(container.y0 + linePitch * rowIndex + padding + fontSize * overhang);
188+
case VerticalAlignments.bottom:
189+
return -(container.y1 - linePitch * (totalRowCount - 1 - rowIndex) - fontSize * overhang);
190+
default:
191+
return -((container.y0 + container.y1) / 2 + (linePitch * (rowIndex - totalRowCount)) / 2);
192+
}
193+
}
194+
175195
/** @internal */
176196
export function getRectangleRowGeometry(
177197
container: RectangleConstruction,
@@ -193,12 +213,16 @@ export function getRectangleRowGeometry(
193213
maximumRowLength: 0,
194214
};
195215
}
196-
const rowCentroidY =
197-
verticalAlignment === VerticalAlignments.top
198-
? -(container.y0 + linePitch * rowIndex + padding + fontSize * overhang)
199-
: verticalAlignment === VerticalAlignments.bottom
200-
? -(container.y1 - linePitch * (totalRowCount - 1 - rowIndex) - fontSize * overhang)
201-
: -((container.y0 + container.y1) / 2 + (linePitch * (rowIndex - totalRowCount)) / 2);
216+
const rowCentroidY = getVerticalAlignment(
217+
container,
218+
verticalAlignment,
219+
linePitch,
220+
totalRowCount,
221+
rowIndex,
222+
padding,
223+
fontSize,
224+
overhang,
225+
);
202226
return {
203227
rowCentroidX: cx,
204228
rowCentroidY,

0 commit comments

Comments
 (0)