Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Jan 21, 2022
1 parent 67194be commit 6aa3aa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/plugins/charts/public/services/palettes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function findColorSegment(
// what about values in range
const index = colors.findIndex((c, i) => comparison(value, rangeMin + (1 + i) * step) <= 0);
return (
colors[index] ||
colors[index] ??
(value > rangeMin + colors.length * step ? colors[colors.length - 1] : colors[0])
);
}
Expand All @@ -34,14 +34,13 @@ function findColorsByStops(
stops: number[]
) {
const index = stops.findIndex((s) => comparison(value, s) < 0);
return colors[index] || value > stops[stops.length - 1] ? colors[colors.length - 1] : colors[0];
return colors[index] ?? (value > stops[stops.length - 1] ? colors[colors.length - 1] : colors[0]);
}

function getNormalizedValueByRange(
value: number,
{ range, rangeMax, rangeMin }: CustomPaletteState,
minMax: { min: number; max: number },
isMaxContinuity: boolean
{ range, rangeMin }: CustomPaletteState,
minMax: { min: number; max: number }
) {
let result = value;
if (range === 'percent') {
Expand Down Expand Up @@ -103,7 +102,7 @@ export function workoutColorForValue(
const isMaxContinuity = checkIsMaxContinuity(continuity);
// ranges can be absolute numbers or percentages
// normalized the incoming value to the same format as range to make easier comparisons
const normalizedValue = getNormalizedValueByRange(value, params, minMax, isMaxContinuity);
const normalizedValue = getNormalizedValueByRange(value, params, minMax);

const [min, max]: [number, number] = range === 'percent' ? [0, 100] : [minMax.min, minMax.max];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('palette panel', () => {
describe('percentage / number modes', () => {
beforeEach(() => {
props = {
activePalette: { type: 'palette', name: 'positive' },
activePalette: { type: 'palette', name: 'custom' },
palettes: paletteRegistry,
setPalette: jest.fn(),
dataBounds: { min: 5, max: 200 },
Expand Down

0 comments on commit 6aa3aa8

Please sign in to comment.