This repository was archived by the owner on Sep 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments