CRT-1071 Fix waterfall total/subtotal tooltip renderers#6489
CRT-1071 Fix waterfall total/subtotal tooltip renderers#6489
Conversation
…erfall The `ag-charts-types` library defines the `params.datum` value (of `tooltip.renderer`) as a type that matches the `TDatum` of `AgChartsOptions`. Total and Subtotal do have such a TDatum in the raw into data, therefore we need to calculate one on-the-fly. Examples tested: - https://ag-grid.com/charts/archive/13.2.0/gallery/horizontal-waterfall/ - https://ag-grid.com/charts/archive/13.2.0/gallery/customised-waterfall/
| ...total.toJson(), | ||
| [xKey]: total.axisLabel, | ||
| externalDatum: { ...data?.data.at(total.index) }, | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
For synthetic total/subtotal nodes, externalDatum is copied from data.at(total.index) and later only yKey is overridden. The displayed bar label comes from total.axisLabel, but that label is not written into externalDatum. As a result, custom tooltip renderers reading params.datum[xKey] may see a stale category (copied from another datum) or no category at all (e.g. when total.index points past the data array for end totals). This leaves total/subtotal tooltip renderer data inconsistent with the rendered bar.
There was a problem hiding this comment.
Well done! Indeed, the tooltip.renderer does indeed provide datum[xKey]: Oct 31, which is incorrect, this should be datum[xKey]: 'Monthly Net'.
We could update the code to set data[xKey] to 'Monthly Net'. But if we do that, then this will create another problem where now we're violating the declared type of data[xKey], which is meant to be a Date not a string.
The developer could in theory do something like this in their tooltip renderer and run into the exact same problem:
tooltip.render: (params) => {
const xKey: string = params.xKey;
const date: Date = params.datum[xKey];
const timeString: string = date.toTimeString(); // error - .toTimeString() does not exist on string types
}
|
❌ Codex review complete; 1 issue found (P0: 0 | P1: 1 | P2: 0 | P3: 0) View full reviewCRT-1071 Fix waterfall total/subtotal tooltip renderersPR: #6489 SummaryThis PR introduces a dedicated FindingsP0: 0 | P1: 1 | P2: 0 | P3: 0 1 inline comments posted. VerdictAssessment: incorrect The patch improves total/subtotal tooltip handling, but it still produces inconsistent callback datum shape for x-axis context on synthetic bars, which can break or mislead custom tooltip renderers. Required Actions:
|
|
Snapshots automatically updated, please review before merge: |
https://ag-grid.atlassian.net/browse/CRT-1071