MapInfo Pro

 View Only
  • 1.  MapInfo Monday: Labelling Large Numbers

    Employee
    Posted 20 days ago

    I used MapInfo Pro in combination with Snowflake to aggregate business points into hexagons. I aggregated the count of businesses in each hexagon and also summarized the sales in each hexagon.

    You can, of course, create a thematic map, helping you to understand the sales across the area. I decided to label the sales amount on top of the hexagons.

    As you can see above, with overlap set to allow overlap, it is a bit hard to make sense of these numbers.
    What can you do to be able to better read the important/buíggest numbers?
    We'll investigate a couple of approaches in this article. Happy #MapInfoMonday!

    Omit the Smaller Values

    Instead of showing every value, you can write a label expression that ignores the smaller values and only displays the values over 1000:
    IIf(SALES_sum>1000, Round(SALES_sum, 1), "")
    Besides using the IIf() function to filter out the smaller values, the expression above also uses the Round() function to round the value to the nearest integer/whole number.
    The resulting map looks like this
    Depending on your data, your limit may be changed to 10,000 ...
    ... 25,000 ...
    ... 50,000 ...
    ... or even more.
    This workaround will work in some cases. But I think you can see that it doesn't always work.

    Number Abbreviation or Numeric Shorthand

    Another workaround is often seen in finance, data visualization, and dashboards. It's called number abbreviation or number shorthand. The idea is to make large numbers easier to read and interpret.

    You do this by replacing part of larger numbers with a letter describing the size of the number. Examples of this are: 1,000 is changed to 1K, 1,000,000 is changed to 1M, and 1,000,000,000 is changed to 1B.

    It really would require a function to implement this correctly, but an expression can be used if you know your values to some extent and don't have to handle edge cases.

    Your map could look like this after applying the Numerical Shorthand to the labels

    As you can see, the long numbers have now been replaced by short 2-4 number/letter combinations.
    The expression used looks like this:
    IIf(SALES_sum < 1000, "", IIf(SALES_sum < 1000000, Round(SALES_sum/1000, 1)+"K", IIf(SALES_sum < 1000000000, Round(SALES_sum/1000000, 1)+"M", "")))
    The expression ignores values under 1,000, and it rounds the Numeric Shorthands to whole numbers. You could decide to round them to one or two decimals for more precision. And finally, the expression doesn't handle values larger than 1 billion; however, support for that could have been added to the function. Also note that the expression doesn't support negative values very well: all negative values will not be displayed.
    Would you find it useful to display numbers with the Numeric Shorthand method?


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------


  • 2.  RE: MapInfo Monday: Labelling Large Numbers

    Employee
    Posted 19 days ago

    If you'd like to use the Numeric Shorthand in your MapBasic applications, I have created a function for this in the STRINGLib module of the MapBasic Common Libraries.

    The function looks like this:

    '**********************************************************************************************''
    'Created by Peter Horsbøll Møller, Precisely
    'Parameters:
    '	:
    'Return value:
    '
    '**********************************************************************************************''
    Function STRINGNumericShorthand(	  ByVal fValue As Float		'Value to show as "1K", "50M", and similar
    							, ByVal fRoundTo As Float	'Controls how to round the shortened number. If > 1, no decimals. Similar to the form used in Round.
    							) As String
    
    Dim	nSign As Integer,
    	fDivisor, fCompact As Float,
    	sSuffix As String
    
    OnError GoTo ErrorOccured
    
    ' Examples:
    '   STRINGNumericShorthand(1534, 0.1)   -> "1.5K"
    '   STRINGNumericShorthand(1250000, 0.01)-> "1.25M"
    '   STRINGNumericShorthand(-2000000000, 1)-> "-2B"
    '   STRINGNumericShorthand(999, 1)	-> "999"
    '   STRINGNumericShorthand(1000000000000, 1)-> "1T"
    
    	' Sign management
    	If fValue < 0 Then
    		nSign = -1
    		fValue = Abs(fValue)
    	Else
    		nSign = 1
    	End If
    
    	' Choose scale and suffix (short scale)
    	If fValue >= 1000000000000 Then	'trillions / 1e12
    		fDivisor = 1000000000000
    		sSuffix = "T"
    	ElseIf fValue >= 1000000000 Then	'billions / 1e9
    		fDivisor = 1000000000
    		sSuffix = "B"
    	ElseIf fValue >= 1000000 Then		'millions / 1e6
    		fDivisor = 1000000
    		sSuffix = "M"
    	ElseIf fValue >= 1000 Then		'thousands / 1e3
    		fDivisor = 1000
    		sSuffix = "K"
    	Else
    		fDivisor = 1
    		sSuffix = ""
    	End If
    
    	fCompact = fValue / fDivisor
    
    	' Optional threshold bump: avoid outputs like 1000K -> show 1M
    	If Round(fCompact, fRoundTo) >= 1000 Then
    		Do Case sSuffix
    			Case ""
    				fCompact = fCompact / 1000
    				sSuffix = "K"
    			Case "K"
    				fCompact = fCompact / 1000
    				sSuffix = "M"
    			Case "M"
    				fCompact = fCompact / 1000
    				sSuffix = "B"
    			Case "B"
    				fCompact = fCompact / 1000
    				sSuffix = "T"
    		End Case
    	End If
    
    	STRINGNumericShorthand = FormatNumber$(Round((nSign * fCompact), fRoundTo)) + sSuffix
    
    	Exit Function
    '-------------------------
    ErrorOccured:
    	Call ERRCreate(Err(), Error$(), "STRINGNumericShorthand")
    	Call ERRPrint()
    
    End Function



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------