From ef857da026ba3b61339693452e2d2c5c86146d90 Mon Sep 17 00:00:00 2001 From: Bryon Williams Date: Fri, 14 Nov 2025 10:19:03 -0800 Subject: [PATCH] Add optional custom label fields for From and To nodes * Add CategoryLabel and SeriesLabel data roles to capabilities * Allow users to provide custom display labels for From/To nodes * Falls back to original data values when custom labels not provided * Update data extraction logic to handle label fields * Custom labels apply to node labels, tooltips, and chord connections --- capabilities.json | 50 ++++++++++++++++++++++++++++++++++++++++++++--- src/chordChart.ts | 11 ++++++++++- src/columns.ts | 2 ++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/capabilities.json b/capabilities.json index 72602f2..acdaf0e 100644 --- a/capabilities.json +++ b/capabilities.json @@ -17,6 +17,18 @@ "displayNameKey": "Role_Values", "name": "Y", "kind": "Measure" + }, + { + "displayName": "From Label", + "displayNameKey": "Role_FromLabel", + "name": "CategoryLabel", + "kind": "Grouping" + }, + { + "displayName": "To Label", + "displayNameKey": "Role_ToLabel", + "name": "SeriesLabel", + "kind": "Grouping" } ], "dataViewMappings": [ @@ -28,6 +40,12 @@ }, "Series": { "max": 0 + }, + "CategoryLabel": { + "max": 1 + }, + "SeriesLabel": { + "max": 1 } }, { @@ -40,6 +58,12 @@ }, "Y": { "max": 1 + }, + "CategoryLabel": { + "max": 1 + }, + "SeriesLabel": { + "max": 1 } }, { @@ -52,14 +76,29 @@ "Y": { "min": 0, "max": 1 + }, + "CategoryLabel": { + "max": 1 + }, + "SeriesLabel": { + "max": 1 } } ], "categorical": { "categories": { - "for": { - "in": "Category" - }, + "select": [ + { + "for": { + "in": "Category" + } + }, + { + "for": { + "in": "CategoryLabel" + } + } + ], "dataReductionAlgorithm": { "top": {} } @@ -72,6 +111,11 @@ "bind": { "to": "Y" } + }, + { + "for": { + "in": "SeriesLabel" + } } ], "dataReductionAlgorithm": { diff --git a/src/chordChart.ts b/src/chordChart.ts index f45f40c..4ab26fa 100644 --- a/src/chordChart.ts +++ b/src/chordChart.ts @@ -358,12 +358,16 @@ export class ChordChart implements IVisual { let isCategory: boolean = false; let index: number; - const label: string = + let label: string = sources.Series && i < categoricalValues.Series.length ? seriesColumnFormatter.format(totalFields[i]) : categoryColumnFormatter.format(totalFields[i]); if ((index = catIndex[totalFields[i]]) !== undefined) { + // This is a Category (From) - check if custom label is provided + if (categoricalValues.CategoryLabel && categoricalValues.CategoryLabel[index] != null) { + label = String(categoricalValues.CategoryLabel[index]); + } selectionId = host .createSelectionIdBuilder() .withCategory(columns.Category, index) @@ -380,6 +384,11 @@ export class ChordChart implements IVisual { categoricalValues.Category[index] ); } else if ((index = seriesIndex[totalFields[i]]) !== undefined) { + // This is a Series (To) - check if custom label is provided + if (categoricalValues.SeriesLabel && categoricalValues.SeriesLabel[index] != null) { + label = String(categoricalValues.SeriesLabel[index]); + } + const seriesObjects: DataViewObjects = grouped ? grouped[index].objects : null; diff --git a/src/columns.ts b/src/columns.ts index 732eed3..aa2a003 100644 --- a/src/columns.ts +++ b/src/columns.ts @@ -124,4 +124,6 @@ export class ChordChartColumns { public Category: T = null; public Series: T = null; public Y: T = null; + public CategoryLabel: T = null; + public SeriesLabel: T = null; }