Create fraction as label in Arcade

450
2
Jump to solution
04-28-2023 08:21 AM
Labels (1)
TomGeo
by
Occasional Contributor III

I would like to use Arcade to show z-min and z_max (both are attributes of the features) in a fraction.

To get both values as a multi-line label is easy, but then I am basically missing two things.

  1. draw a horizontal line between the two values (ideally as wide as the longest value)
  2. both attribute values are of type Double, and I would like to align the numbers by the decimal seperator

Is that possible with Arcade, and/or is there any other way to achieve that with ArcGIS Pro?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

I was able to get a horizontal line between the two that is the length of the longer value, but I couldn't get them aligned with the decimal point.

When using this script, you have to unselect the "Remove extra spaces" option.

var numerator = $feature.MIN;
var denominator = $feature.MAX;

var numLength = Count(Text(numerator));
var denLength = Count(Text(denominator));
if (numLength < denLength) {
  var diff = Ceil((denLength - numLength)/2);
  for (var j=0; j <= diff; j++) {
    numerator = ` ${numerator} `
  }
}
return `<align horizontal ='center'><UND>${numerator}</UND>${TextFormatting.NewLine}${denominator}</align>`

 

minmax.png

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

I was able to get a horizontal line between the two that is the length of the longer value, but I couldn't get them aligned with the decimal point.

When using this script, you have to unselect the "Remove extra spaces" option.

var numerator = $feature.MIN;
var denominator = $feature.MAX;

var numLength = Count(Text(numerator));
var denLength = Count(Text(denominator));
if (numLength < denLength) {
  var diff = Ceil((denLength - numLength)/2);
  for (var j=0; j <= diff; j++) {
    numerator = ` ${numerator} `
  }
}
return `<align horizontal ='center'><UND>${numerator}</UND>${TextFormatting.NewLine}${denominator}</align>`

 

minmax.png

TomGeo
by
Occasional Contributor III

Thank you so much! I can see the issue with the alignment to the decimal point... Lucky enough it's not a strict requirement, but in terms of typography and cartography it would be nice if Arcade could support that.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos