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

Commit 609c458

Browse files
authored
Merge e3718d3 into 9a47ac9
2 parents 9a47ac9 + e3718d3 commit 609c458

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/worldmap.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,33 @@ 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+
it('shouldnt break if only numbers are added', () => {
433+
const input = '1000';
434+
const output = worldMap.replaceThousandsAndMillions(input);
435+
expect(output).toEqual(input);
436+
});
437+
it('should replace K with 1000', () => {
438+
const input = '1k';
439+
const output = worldMap.replaceThousandsAndMillions(input);
440+
expect(output).not.toEqual(input);
441+
expect(output).toEqual('1000');
442+
})
443+
it('should replace M with 1000000', () => {
444+
const input = '1m';
445+
const output = worldMap.replaceThousandsAndMillions(input);
446+
expect(output).not.toEqual(input);
447+
expect(output).toEqual('1000000');
448+
})
449+
it('should replace Ks,Ms correctly', () => {
450+
const input = '1km';
451+
const output = worldMap.replaceThousandsAndMillions(input);
452+
expect(output).not.toEqual(input);
453+
expect(output).toEqual('1000000000');
454+
})
455+
});
427456
});

src/worldmap.ts

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

124+
replaceThousandsAndMillions(value) {
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')));
135+
console.log(minValue, maxValue);
127136
return _.filter(data, o => {
128137
return !(this.ctrl.panel.hideEmpty && _.isNil(o.value))
129138
&& !(this.ctrl.panel.hideZero && o.value === 0)

0 commit comments

Comments
 (0)