Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit d1c628a

Browse files
authored
Merge 68f9a73 into 9a47ac9
2 parents 9a47ac9 + 68f9a73 commit d1c628a

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/worldmap.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,52 @@ describe('Worldmap', () => {
424424
expect(worldMap.circles[2]._popup._content).toBe(`United States: ${HIGH}`);
425425
});
426426
});
427+
428+
describe('when variables have M or K', () => {
429+
beforeEach(() => {
430+
setupWorldmapFixture();
431+
})
432+
433+
const getValidData = (): Array < [string, {
434+
providedInput: string,
435+
expectedOutput: string
436+
}] > => {
437+
return [
438+
['no shortcuts', {
439+
providedInput: '1000',
440+
expectedOutput: '1000'
441+
}],
442+
['only text', {
443+
providedInput: 'Something',
444+
expectedOutput: 'Something'
445+
}],
446+
['one K shortcut', {
447+
providedInput: '1k',
448+
expectedOutput: '1000'
449+
}],
450+
['one m shortcut', {
451+
providedInput: '1m',
452+
expectedOutput: '1000000'
453+
}],
454+
['uppercase shortcuts', {
455+
providedInput: '1K',
456+
expectedOutput: '1000'
457+
}],
458+
['mixed shortcuts', {
459+
providedInput: '1Km',
460+
expectedOutput: '1000000000'
461+
}],
462+
]
463+
}
464+
465+
test.each(getValidData())(
466+
'Should parse variables when it have %s', (record: { providedInput: string, expectedOutput: string }) : void => {
467+
// Act
468+
const actual = worldMap.replaceThousandsAndMillions(record.providedInput);
469+
470+
// Assert
471+
expect(actual).toEqual(record.providedInput);
472+
}
473+
)
474+
});
427475
});

src/worldmap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,17 @@ export default class WorldMap {
121121
this.valueRange = this.highestValue - this.lowestValue;
122122
}
123123

124+
replaceThousandsAndMillions(value: string) : string {
125+
if (!value || !value.match(/\d+[k|m]+/gi)){
126+
return value
127+
}
128+
value = value.replace(/k/gi, '000').replace(/m/ig,'000000')
129+
return value;
130+
}
131+
124132
filterEmptyAndZeroValues(data) {
125-
const minValue = this.ctrl.panel.minValue || parseInt(this.ctrl.panel.replaceVariables('$minDisplayValue'));
126-
const maxValue = this.ctrl.panel.maxValue || parseInt(this.ctrl.panel.replaceVariables('$maxDisplayValue'));
133+
const minValue = this.ctrl.panel.minValue || parseInt(this.replaceThousandsAndMillions(this.ctrl.panel.replaceVariables('$minDisplayValue')));
134+
const maxValue = this.ctrl.panel.maxValue || parseInt(this.replaceThousandsAndMillions(this.ctrl.panel.replaceVariables('$maxDisplayValue')));
127135
return _.filter(data, o => {
128136
return !(this.ctrl.panel.hideEmpty && _.isNil(o.value))
129137
&& !(this.ctrl.panel.hideZero && o.value === 0)

0 commit comments

Comments
 (0)