Hi,
I am trying to get these columns and rows to align clean but am running into issues. The top sample id field doesn't matter. Below is my current Arcade:
// User can define fields specific to their data here
// Sample ID Fields - this is the field that includes the sample IDs
var sampleid_fields = [$feature.SampleID];
// Set the column width for the tables
// You can define multiple widths or a single width for all
var clmwdth_s = 28; // Column width for Sample ID
var clmwdth_d = 8; // Column width for Depth
var clmwdth_r = 10; // Column width for Result
// Set up for color definitions - these do not need to be changed unless you would like to vary the colors
// Adjust the rgba values for these or add additional colors, the first three are RGB colors and the last number is the transparency
var yellow = [252,202,70,100];
var orange = [254,127,45,100];
var red = [164,22,26,100];
var blue = [3,83,164,100];
var ltblue = [95,168,211,100];
var green = [76,149,108,100];
var ltgreen= [97,155,138,100];
var black = [0,0,0,100];
var white = [255,255,255,100];
var none = [0,0,0,0];
// Set default text for use across all label cells
// Var textFontName = "Consolas"; is used as it correctly displays monospace fonts - recommend using Consolas font as everything lines up better
var textFontName = "Consolas";
var textFontStyle = "Regular";
var textFontSize = "8";
function ljust(string, width) {
if (count(string) > width ) {
string = left(string, width)
} else {
for (var i = count(string); i < width; i++) {
string += ' '
}
}
return string
}
// Configure base functions for the font color, style, background and outline - this does not need to be updated unless deliverable requires different formatting
function FormatBO(background, outline, width, padding, txt){
var attr = ""
if(background != none && count(background) == 4){
attr += " red='" + background[0] + "'"
attr += " green='" + background[1] + "'"
attr += " blue='" + background[2] + "'"
attr += " alpha='" + background[3] + "'"
}
if(outline != none && count(outline) == 4){
attr += " outline_red='" + outline[0] + "'"
attr += " outline_green='" + outline[1] + "'"
attr += " outline_blue='" + outline[2] + "'"
attr += " outline_alpha='" + outline[3] + "'"
attr += " width='" + width + "'"
attr += " padding='" + padding + "'"
}
return "<BGD" + attr + ">" + txt + "</BGD>"
}
function SetTextColor(rgba, txt)
{
var r = rgba[0]
var g = rgba[1]
var b = rgba[2]
var a = rgba[3]
return "<CLR red='" + r + "' green='" + g + "' blue='" + b + "' alpha='" + a + "'>" + txt + "</CLR>";
}
// This can be used to override the default font setting for a particular cell
function FormatFont(label, name, style, size)
{
var tagName = iif(name=="", "", " NAME='"+name+"'")
var tagStyle = iif(style=="", "", " STYLE='"+style+"'")
var tagSize = iif(size==0, "", " SIZE='"+size+"'")
return "<FNT" + tagName + tagStyle + tagSize + ">" + label + "</FNT>"
}
// Setup the items for the table heading
// You can add additonal lines using "\n"
// This is only needed if you would like headers for each of your columns - in this case I used the column headers to give the units for the depths and then the two sampling periods)
var h1 = SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" (ft) bgs ", clmwdth_d), textFontName, textFontStyle, 0)))
var h2 = SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" PCE ", clmwdth_r), textFontName, textFontStyle, 0)))
var h3 = SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" TCE ", clmwdth_r), textFontName, textFontStyle, 0)))
var h4 = SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" VC ", clmwdth_r), textFontName, textFontStyle, 0)))
var h5 = SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" Benzene ", clmwdth_r), textFontName, textFontStyle, 0)))
// Create the style for each row
// Repeat for each set of columns you have to create the text for each row
// This section creates the first row of data, it refers to the D1 and D1 result fields
var counter = 0;
var table_result1 = ""
for (var sampleid in sampleid_fields){
table_result1 +=
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.D1, clmwdth_d), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test1Result_D1, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test2Result_D1, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test3Result_D1, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test4Result_D1, clmwdth_r), textFontName, textFontStyle, 0)))
counter+=1
}
// This section creates the second row of data, it refers to the D2 and D2 result fields
var counter = 0;
var table_result2 = ""
for (var sampleid in sampleid_fields){
table_result2 +=
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.D2, clmwdth_d), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test1Result_D2, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test2Result_D2, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test3Result_D2, clmwdth_r), textFontName, textFontStyle, 0))) +
SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust(" " + $feature.Test4Result_D2, clmwdth_r), textFontName, textFontStyle, 0)))
counter+=1
}
// Final concatenated string
// This is where everything is pulled together for the final table - sample ID, column headers, iif statement is used to include multiple depths - if D2 is null only table results 1 (row 1) are included, if D2 is not null table results 1 (row 1) and table results 2 (row 2) are included
// Add a "\n" (carrige return) between each table row
// The LIN -3 is needed when using the 'Consolas' font to account for row height.
// The LIN leading value can be adjusted based on the type of font and font size selected.
"<LIN leading = '-3' leading_type = 'extra'>" + SetTextColor(black, FormatBO(white, black, 1, 0, FormatFont(ljust($feature.SampleID, clmwdth_s), textFontName, textFontStyle, 0))) + "\n" + h1 + h2 + h3 + h4 + h5 + "\n" + IIF(IsEmpty($feature.D2), table_result1, table_result1 + "\n" + table_result2) + "</LIN>"
This is how the label looks:
The first field is depth (shallowest and deepest), the others are results. I would like it to look clean.
One other thing I would like is for it to highlight a field if it has a Y or N for a field called Test1Result_D1_Exceed, Test1Result_D2_Exceed, Test2Result_D1_Exceed, Test2Result_D2_Exceed, etc....
Thanks in advance.
Solved! Go to Solution.
Was able to figure it out.
Oh, this is sweet. I’ve never seen a table get constructed for a label before.
Could you post your code snippet that you used to achieve it?