Text Panel Content Guidelines: Difference between revisions
No edit summary |
|||
| (17 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Timeout-Safe Authoring Workflow== | |||
Large panel text payloads can be sensitive to session timeouts. A timeout before the `set_text` call completes can leave a panel with correct metadata but empty content. | |||
Recommended timeout-safe workflow: | |||
# Create the panel. | |||
# Set name, size, and overlay. | |||
# Persist a small placeholder text immediately. | |||
# Verify that the placeholder text is stored. | |||
# Prepare the full panel content locally. | |||
# Send the full `set_text` payload. | |||
# Verify the raw text. | |||
# Verify the rendered HTML. | |||
# Only then perform optional polish updates. | |||
Additional guidance: | |||
* batch independent read requests, | |||
* avoid unnecessary sequential API calls before the main write, | |||
* validate the payload shape before sending, | |||
* keep the payload as compact as practical, | |||
* treat empty panel text as a failure, | |||
* retry idempotent writes only when the panel state is known. | |||
===Verification=== | |||
After setting text, retrieve the panel text again (HTTP): | |||
<syntaxhighlight copy> | |||
GET /api/session/items/panels/{panelID}/text | |||
</syntaxhighlight> | |||
Confirm that: | |||
* the text is not empty, | |||
* the text belongs to the intended panel ID, | |||
* the panel name is correct, | |||
* the panel size is correct, | |||
* the overlay association is correct, | |||
* the rendered panel in the viewer is the intended panel. | |||
==Safe DOM Order and Initialization== | ==Safe DOM Order and Initialization== | ||
The recommended DOM order for a chart panel is: | The recommended DOM order for a chart panel is: | ||
# title, | |||
# subtitle, | |||
# chart container, | |||
# footnote, | |||
# script. | |||
HTML Example: | HTML Example: | ||
| Line 23: | Line 64: | ||
Placing the chart container before the title can push the title below the visible area in fixed-height panels. Even if a screenshot appears correct, the stored DOM order should still be reviewed. | Placing the chart container before the title can push the title below the visible area in fixed-height panels. Even if a screenshot appears correct, the stored DOM order should still be reviewed. | ||
== Encoding Special Characters in JavaScript Strings== | |||
JavaScript strings are not HTML. HTML entities are not decoded inside JavaScript string literals. | |||
===Incorrect Encoding=== | |||
In javascript: | |||
<syntaxhighlight copy> | |||
const unit = "°C"; | |||
const yAxisTitle = "Average PET (°C)"; | |||
const hoverTemplate = "%{x}: %{y:.1f} °C<extra></extra>"; | |||
</syntaxhighlight> | |||
This can render literally as: | |||
<syntaxhighlight copy> | |||
41.8 °C | |||
Average PET (°C) | |||
</syntaxhighlight> | |||
===Correct Encoding=== | |||
Use a Unicode escape: | |||
<syntaxhighlight copy> | |||
const degree = "\u00B0"; | |||
const unit = degree + "C"; | |||
const yAxisTitle = "Average PET (" + unit + ")"; | |||
const hoverTemplate = "%{x}: %{y:.1f} " + unit + "C<extra></extra>"; | |||
</syntaxhighlight> | |||
Or use the literal UTF-8 character: | |||
<syntaxhighlight copy> | |||
const unit = "°C"; | |||
</syntaxhighlight> | |||
=== Where HTML entities are allowed=== | |||
HTML entities are appropriate in HTML text nodes: | |||
<syntaxhighlight copy> | |||
<p>Average PET, °C, last timeframe.</p> | |||
</syntaxhighlight> | |||
They are not appropriate inside JavaScript strings that will be passed to Plotly. | |||
=== Verification=== | |||
After rendering, check: | |||
* bar labels, | |||
* tooltip text, | |||
* y-axis title, | |||
* colorbar title, | |||
* subtitle, | |||
* footnote. | |||
Any visible `°`, `°`, or similar entity text indicates an encoding defect. | |||
==Choosing X and Y Clauses for Chart Series== | ==Choosing X and Y Clauses for Chart Series== | ||
| Line 42: | Line 141: | ||
|} | |} | ||
Mixing an `X`-clause name array with a `Y`-clause value array can produce a flat category array and a nested value array. This can cause the chart to render blank or produce unexpected trace shapes. | |||
Some query previews may display nested results in a flattened form. Always check the documented substitution semantics, not only the preview appearance. | |||
Static tags are reliable because the platform evaluates them as part of the normal calculation pipeline. | |||
Dynamically constructed queries bypass that pipeline and can fail silently or produce inconsistent results. | |||
===Correct Pattern=== | |||
For a simple bar chart with one value per category, use the same clause family for both the category names and the values, in javascript: | For a simple bar chart with one value per category, use the same clause family for both the category names and the values, in javascript: | ||
| Line 49: | Line 157: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Incorrect pattern=== | |||
Do not build TQL queries dynamically in JavaScript. | |||
<syntaxhighlight> | |||
const query = "SELECT_NAME_WHERE_NEIGHBORHOOD_IS_" + id; | |||
fetch("/api/session/query/", { method: "POST", body: query }); | |||
</syntaxhighlight> | |||
=== Keeping names and values aligned === | |||
Query names and values separately, then combine them by index: | |||
<syntaxhighlight copy> | |||
const names = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X]; | |||
const values = [$SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_HEAT_STRESS_AND_RESULTTYPE_IS_PET_AND_TIMEFRAME_IS_0]; | |||
const rows = []; | |||
names.forEach((name, i) => { | |||
const value = Number(values[i]); | |||
if (name !== undefined && name !== null && Number.isFinite(value)) { | |||
rows.push({ name: name, value: value }); | |||
} | |||
}); | |||
</syntaxhighlight> | |||
This preserves alignment and avoids the common defect where a bar receives the wrong category label. | |||
===Sorting safely=== | |||
In javascript, if sorting by value, sort paired objects, not separate arrays: | |||
<syntaxhighlight copy> | |||
rows.sort((a, b) => b.value - a.value); | |||
const chartNames = rows.map(r => r.name); | |||
const chartValues = rows.map(r => r.value); | |||
</syntaxhighlight> | |||
This prevents label/value desynchronization. | |||
==Preferring Stable Grid Identifiers== | ==Preferring Stable Grid Identifiers== | ||
| Line 107: | Line 252: | ||
Before creating a panel: | Before creating a panel: | ||
# check whether a panel with the requested name already exists, | |||
# determine whether the existing panel is stale, empty, or still in use, | |||
# remove or rename the stale panel if appropriate, | |||
# create or rename the new panel, | |||
# re-read the panel and verify that the final name matches the requested name. | |||
A panel that renders correctly but has the wrong name should still be treated as a defect when an exact name was required. | A panel that renders correctly but has the wrong name should still be treated as a defect when an exact name was required. | ||
| Line 174: | Line 319: | ||
A panel that requires scrolling to reveal axis labels or values should be resized or simplified. | A panel that requires scrolling to reveal axis labels or values should be resized or simplified. | ||
== | ==Error Handling and No-Data Messages== | ||
Panel JavaScript should fail visibly, not silently. | |||
In javascript, wrap chart initialization in a `try/catch` block : | |||
<syntaxhighlight copy> | |||
const container = document.getElementById("chart"); | |||
try { | |||
if (!rows.length) { | |||
throw new Error("No data available"); | |||
} | |||
Plotly.newPlot(container, [trace], layout); | |||
} catch (error) { | |||
container.innerHTML = | |||
"<p class=\"panel-error\">Unable to render chart. Please check the data source.</p>"; | |||
} | |||
</syntaxhighlight> | |||
Before plotting, validate: | |||
* the container exists, | |||
* the category array is not empty, | |||
* the value array is not empty, | |||
* category and value arrays have the same length, | |||
* values are finite numbers, | |||
* axis minima and maxima are finite. | |||
A no-data state should be a designed part of the panel, not an accidental blank box. | |||
==Quality assurance== | ==Quality assurance== | ||
| Line 329: | Line 481: | ||
* [[Select (TQL)]] | * [[Select (TQL)]] | ||
* [[Panel properties]] | * [[Panel properties]] | ||
* [[Plotly Chart Quality Guidelines]] | |||
|howtos= | |howtos= | ||
* [[How to insert a Plotly Graph]] | * [[How to insert a Plotly Graph]] | ||
Latest revision as of 10:47, 1 December 2026
Timeout-Safe Authoring Workflow
Large panel text payloads can be sensitive to session timeouts. A timeout before the `set_text` call completes can leave a panel with correct metadata but empty content.
Recommended timeout-safe workflow:
- Create the panel.
- Set name, size, and overlay.
- Persist a small placeholder text immediately.
- Verify that the placeholder text is stored.
- Prepare the full panel content locally.
- Send the full `set_text` payload.
- Verify the raw text.
- Verify the rendered HTML.
- Only then perform optional polish updates.
Additional guidance:
- batch independent read requests,
- avoid unnecessary sequential API calls before the main write,
- validate the payload shape before sending,
- keep the payload as compact as practical,
- treat empty panel text as a failure,
- retry idempotent writes only when the panel state is known.
Verification
After setting text, retrieve the panel text again (HTTP):
GET /api/session/items/panels/{panelID}/textConfirm that:
- the text is not empty,
- the text belongs to the intended panel ID,
- the panel name is correct,
- the panel size is correct,
- the overlay association is correct,
- the rendered panel in the viewer is the intended panel.
Safe DOM Order and Initialization
The recommended DOM order for a chart panel is:
- title,
- subtitle,
- chart container,
- footnote,
- script.
HTML Example:
<h2>Title</h2>
<p>Subtitle</p>
<div id="chart"></div>
<p class="footnote">Footnote</p>
<script>
// initialization code
</script>Placing the chart container before the title can push the title below the visible area in fixed-height panels. Even if a screenshot appears correct, the stored DOM order should still be reviewed.
Encoding Special Characters in JavaScript Strings
JavaScript strings are not HTML. HTML entities are not decoded inside JavaScript string literals.
Incorrect Encoding
In javascript:
const unit = "°C";
const yAxisTitle = "Average PET (°C)";
const hoverTemplate = "%{x}: %{y:.1f} °C<extra></extra>";This can render literally as:
41.8 °C
Average PET (°C)Correct Encoding
Use a Unicode escape:
const degree = "\u00B0";
const unit = degree + "C";
const yAxisTitle = "Average PET (" + unit + ")";
const hoverTemplate = "%{x}: %{y:.1f} " + unit + "C<extra></extra>";Or use the literal UTF-8 character:
const unit = "°C";Where HTML entities are allowed
HTML entities are appropriate in HTML text nodes:
<p>Average PET, °C, last timeframe.</p>They are not appropriate inside JavaScript strings that will be passed to Plotly.
Verification
After rendering, check:
- bar labels,
- tooltip text,
- y-axis title,
- colorbar title,
- subtitle,
- footnote.
Any visible `°`, `°`, or similar entity text indicates an encoding defect.
Choosing X and Y Clauses for Chart Series
The choice between `X` and `Y` clauses affects the shape of the JavaScript array received by the panel.
| Clause family | Result shape | Typical use |
|---|---|---|
| `X`, `XA`, `XK`, `XC` | flat array | simple bar charts, category lists, one value per item |
| `Y`, `YA`, `YK`, `YC` | array of arrays | matrices, per-item time series, heatmaps |
Mixing an `X`-clause name array with a `Y`-clause value array can produce a flat category array and a nested value array. This can cause the chart to render blank or produce unexpected trace shapes.
Some query previews may display nested results in a flattened form. Always check the documented substitution semantics, not only the preview appearance.
Static tags are reliable because the platform evaluates them as part of the normal calculation pipeline.
Dynamically constructed queries bypass that pipeline and can fail silently or produce inconsistent results.
Correct Pattern
For a simple bar chart with one value per category, use the same clause family for both the category names and the values, in javascript:
const names = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];
const values = [$SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_EXAMPLE_AND_RESULTTYPE_IS_METRIC];Incorrect pattern
Do not build TQL queries dynamically in JavaScript.
const query = "SELECT_NAME_WHERE_NEIGHBORHOOD_IS_" + id;
fetch("/api/session/query/", { method: "POST", body: query });Keeping names and values aligned
Query names and values separately, then combine them by index:
const names = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];
const values = [$SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_HEAT_STRESS_AND_RESULTTYPE_IS_PET_AND_TIMEFRAME_IS_0];
const rows = [];
names.forEach((name, i) => {
const value = Number(values[i]);
if (name !== undefined && name !== null && Number.isFinite(value)) {
rows.push({ name: name, value: value });
}
});This preserves alignment and avoids the common defect where a bar receives the wrong category label.
Sorting safely
In javascript, if sorting by value, sort paired objects, not separate arrays:
rows.sort((a, b) => b.value - a.value);
const chartNames = rows.map(r => r.name);
const chartValues = rows.map(r => r.value);This prevents label/value desynchronization.
Preferring Stable Grid Identifiers
When querying Grid Overlays, prefer stable semantic clauses over raw numeric IDs where possible.
Preferred pattern:
GRIDTYPE_IS_EXAMPLE_AND_RESULTTYPE_IS_METRICLess stable pattern:
GRID_IS_3Raw grid IDs can remain correct for a specific project snapshot but become brittle when overlays are recreated, reordered, or duplicated. Semantic clauses make the panel easier to review and less prone to silent source mismatches.
If a raw grid ID must be used, document why and verify that the grid ID still refers to the intended overlay and result type.
Timeframe Behavior in Panels
Grid-based TQL queries may use a specific timeframe or fall back to a default behavior when no timeframe clause is present.
For panel content:
- pin the timeframe explicitly when the panel refers to a specific date or simulation step,
- or clearly state that the panel uses the last timeframe by default,
- show the resolved date or time when available,
- keep the subtitle consistent with the TQL query.
Example explicit timeframe:
$SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_EXAMPLE_AND_RESULTTYPE_IS_METRIC_AND_TIMEFRAME_IS_0$Example of implicit last timeframe:
$SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_EXAMPLE_AND_RESULTTYPE_IS_METRIC$If no timeframe clause is used, the subtitle should not imply a specific date unless the default last-timeframe date is also shown. Example of querying the names of each timeframe of a Grid Overlay with a specific type (EXAMPLE):
$SELECT_NAME_WHERE_TIMEFRAME_IS_X_AND_GRIDTYPE_IS_EXAMPLE$Unique Names and Collision Handling
Panel names should be stable and unambiguous. If a panel with the same name already exists, the platform may append a suffix such as `(2)` to enforce uniqueness.
Before creating a panel:
- check whether a panel with the requested name already exists,
- determine whether the existing panel is stale, empty, or still in use,
- remove or rename the stale panel if appropriate,
- create or rename the new panel,
- re-read the panel and verify that the final name matches the requested name.
A panel that renders correctly but has the wrong name should still be treated as a defect when an exact name was required.
Also check for stale empty panels with the same name. An empty panel can shadow the intended panel in the viewer, causing the user to see a blank panel even though the correct content exists on another panel ID.
Overlay Coupling
A panel can be coupled to an overlay so that the overlay is activated when the panel is opened.
Couple the panel to the overlay when:
- the panel content refers to that overlay,
- the chart values come from that overlay,
- the user is expected to compare the panel with the map visualization,
- the subtitle mentions the overlay name or result type.
If the panel is not coupled to the overlay, either:
- set the panel’s overlay property, or
- reword the subtitle so it does not imply a live overlay connection.
The TQL query, the coupled overlay, and the subtitle should all refer to the same source.
Comparing Grid Overlay Values Between Areas or Neighborhoods
Grid overlay values are often compared between neighborhoods, areas, or other spatial units. Because grid values can fall within a relatively narrow band, panels comparing these values need careful axis and color design.
Recommended panel design:
- use `GRIDAVG` when showing an average value per spatial unit,
- use `GRIDTYPE_IS_<GRID_OVERLAY_TYPE>` and `RESULTTYPE_IS_<RESULT_TYPE>` in TQL filters to specify the source overlay and result type for clarity,
- pin the timeframe explicitly or disclose the default last-timeframe behavior,
- show the date or time associated with the timeframe,
- use a y-axis range fitted to the plotted values,
- avoid a zero baseline when it hides meaningful differences,
- add value labels,
- use a value-driven color scale,
- add a colorbar with the unit,
- couple the panel to the source grid overlay when the panel refers to it.
Example TQL pattern (replace `<GRID_OVERLAY_TYPE>` and `<RESULT_TYPE>` with the actual values, e.g. `HEAT_STRESS` and `PET`):
SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X
SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_X_AND_GRIDTYPE_IS_<GRIDOVERLAYTYPE>ANDRESULTTYPEIS_<RESULTTYPE>The subtitle should state the metric name, its unit, the source grid overlay, and the timeframe or date being shown.
Size and Content Fit
The panel size should be large enough to show the content without clipping, but not so large that important information is lost in empty space.
When configuring size:
- account for title, subtitle, chart, footnote, and padding,
- recalculate the layout after changing the panel height,
- verify that axis labels remain visible,
- verify that footnotes remain visible,
- test with the longest expected labels.
A panel that requires scrolling to reveal axis labels or values should be resized or simplified.
Error Handling and No-Data Messages
Panel JavaScript should fail visibly, not silently.
In javascript, wrap chart initialization in a `try/catch` block :
const container = document.getElementById("chart");
try {
if (!rows.length) {
throw new Error("No data available");
}
Plotly.newPlot(container, [trace], layout);
} catch (error) {
container.innerHTML =
"<p class=\"panel-error\">Unable to render chart. Please check the data source.</p>";
}Before plotting, validate:
- the container exists,
- the category array is not empty,
- the value array is not empty,
- category and value arrays have the same length,
- values are finite numbers,
- axis minima and maxima are finite.
A no-data state should be a designed part of the panel, not an accidental blank box.
Quality assurance
This checklist describes how to verify that a Panel, especially a Text Panel containing HTML, JavaScript, and Plotly, has been created, persisted, and rendered correctly.
The checklist is intended for:
- manual review,
- automated validation,
- AI-assisted panel authoring,
- regression testing after project recalculation.
Pre-Flight Checks
Before rendering the panel, verify:
- the panel exists,
- the panel type is correct,
- the panel name is exact,
- no stale empty panel shadows the intended panel,
- the panel size matches the intended layout,
- the panel text is not empty,
- the panel is coupled to the correct overlay when required,
- stakeholder visibility is configured as intended,
- TQL queries validate successfully,
- TQL tags are static and not constructed in JavaScript,
- array-producing TQL tags are wrapped in square brackets,
- category and value arrays use compatible clause families,
- the Plotly library is provided by the platform,
- no public CDN Plotly script is included,
- the chart initialization is wrapped in error handling.
Data Accuracy Checks
Verify that the chart data matches the project data:
- category names come from the project, not from a hardcoded list,
- values come from the intended TQL query,
- category and value arrays have the same length,
- category and value arrays are aligned index-by-index,
- no values are accidentally shifted by one position,
- missing or non-finite values are filtered or handled explicitly,
- the aggregate type matches the intended metric, for example `GRIDAVG` for an average,
- the grid type and result type match the intended overlay,
- the timeframe matches the subtitle,
- units are consistent with the metric.
Rendered-Image Checks
Inspect the rendered panel image or rendered HTML:
- the chart is visible,
- the title is visible and not duplicated,
- the subtitle is visible and readable,
- all category labels are visible,
- x-axis labels are not clipped,
- y-axis labels are not clipped,
- bar value labels are not clipped,
- the footnote is visible if present,
- the background is readable over the 3D map,
- text colors have sufficient contrast,
- bars are colored according to the intended encoding,
- the minimum and maximum categories are visually distinguishable,
- the colorbar or legend is present when color encodes a value,
- units are shown in the axis, labels, tooltip, and colorbar where relevant,
- the timeframe or date is shown,
- no JavaScript error message is visible,
- no blank chart container is present.
Metadata Checks
Verify panel metadata:
- the panel name matches the requested name,
- the panel ID being inspected is the intended panel,
- the panel size matches the layout assumptions,
- the overlay coupling matches the data source,
- the panel visibility matches the stakeholder requirements,
- the panel location or popup configuration is correct when used in the map,
- the rendered panel corresponds to the stored panel text,
- screenshots are not older than the stored text version.
Common Failure Signatures
| Symptom | Likely cause |
|---|---|
| Empty panel body | Panel text was not persisted |
| Blank chart container | JavaScript error, missing container, or bad trace shape |
| Visible JavaScript error | Invalid syntax, bad TQL substitution, or runtime exception |
| All bars same default color | Missing or misspelled `marker.color` |
| Smallest bar appears gray or white | `cmin` pinned to data minimum on a near-white sequential scale |
| Bars look almost identical | Zero baseline over a narrow value band |
| x-axis labels missing | Chart too tall for panel or insufficient bottom margin |
| Title missing or below chart | Chart container placed before title in DOM |
| Literal `°` in labels | HTML entity used inside JavaScript string |
| Wrong panel name with `(2)` | Name collision with existing panel |
| Panel shows blank map but content exists elsewhere | Stale empty panel with same name shadows intended panel |
| Subtitle date does not match chart | Timeframe not pinned or subtitle not updated |