Skip to content

[FEATURE] BarChart: turn field data links into category anchors - #908

Open
colivi wants to merge 22 commits into
perses:mainfrom
colivi:feat/barchart-category-links
Open

colivi wants to merge 22 commits into
perses:mainfrom
colivi:feat/barchart-category-links

Conversation

@colivi

@colivi colivi commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Description

A horizontal bar chart cannot put an anchor on a canvas axis label. When a panel link contains ${__field.labels.}, hide those labels and overlay one link per category. Dashboard variables and the current time range are filled in, all stays $__all.

Screenshots

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

A horizontal bar chart cannot put an anchor on a canvas axis label.
When a panel link contains ${__field.labels.<name>}, hide those labels
and overlay one link per category. Dashboard variables and the current
time range are filled in. All stays $__all.

Signed-off-by: colivi <charles.olivi@gmail.com>
@colivi
colivi requested a review from a team as a code owner November 1, 2026 14:20
@colivi
colivi requested review from shahrokni and removed request for a team November 1, 2026 14:20
@Gladorme

Gladorme commented Nov 2, 2026

Copy link
Copy Markdown
Member

Hello, I think for links inside panel, it can't be based on spec.links. This field is only for panel header links. Or spec of links need to be updated to flag which one should be used in panel header or inside chart. Doing a check on a template looks wrong to me.
And we probably want to do something supporting by all panels and not only barchart 👀

@colivi

colivi commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Hello, I think for links inside panel, it can't be based on spec.links. This field is only for panel header links. Or spec of links need to be updated to flag which one should be used in panel header or inside chart. Doing a check on a template looks wrong to me. And we probably want to do something supporting by all panels and not only barchart 👀

Hi Guillaume, agreed that sniffing ${__field.labels.*} inside spec.links is the wrong signal: those entries are the panel header menu. The bar chart only needs one link per category, filled with the category label. A placement flag on the link spec would keep header links unchanged and let a panel opt in. I would rather not special-case BarChart if you want the same behavior on other charts. Happy to follow whichever shape you prefer for that flag.

oxlint rejects a module imported more than once. The value import
and the two type imports are now one statement.

Signed-off-by: colivi <charles.olivi@gmail.com>
Inline type specifiers fail oxlint. Both types stay on one import type,
next to the value import.

Signed-off-by: colivi <charles.olivi@gmail.com>
v0.55.0-beta.4 vendors CUE dependencies one module at a time. A parallel
plugin build then runs cue mod tidy while cue.mod/pkg already contains
github.com/perses/shared/cue/common, and tidy fails with an ambiguous
import. v0.55.0 downloads every missing dependency before copying any
of them.

Signed-off-by: colivi <charles.olivi@gmail.com>
The caret range also matches 0.56.0-beta.1. That release peers
@tanstack/react-query 5, so the React 19 job fails while resolving
npm install against the locked react-query 4.

Signed-off-by: colivi <charles.olivi@gmail.com>
@AntoineThebaud AntoineThebaud changed the title [FEATURE] (barchart): turn field data links into category anchors [FEATURE] BarChart: turn field data links into category anchors Nov 14, 2026
@AntoineThebaud
AntoineThebaud requested a balanced review from Copilot November 14, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The URL helpers discard destination origins and fragments and overwrite configured or field-specific filters with dashboard values, even when interpolation is disabled.

3 open issues
What changed in this PR

Adds category links to horizontal bar charts by overlaying HTML anchors where canvas axis labels cannot be clickable.

Changes:

  • Builds per-series links from field labels and dashboard variables, preserving the All selection and carrying time-range parameters.
  • Positions category anchors alongside bars and supports opening links in a new tab.
  • Adds unit tests for link interpolation and URL helpers.
File Description
barchart/​src/​utils.ts Adds link interpolation and URL parameter helpers.
barchart/​src/​utils.test.ts Tests field labels, dashboard variables, All selections, and time parameters.
barchart/​src/​BarChartPanel.tsx Generates per-series URLs from panel link configuration.
barchart/​src/​BarChartBase.tsx Replaces horizontal axis labels with positioned category anchors.

Review effort: Balanced

Comment thread barchart/src/utils.ts Outdated
}
const live = current.get(key);
if (live !== null) {
base.searchParams.set(key, live);
Comment thread barchart/src/utils.ts Outdated
Comment on lines +73 to +86
return `${base.pathname}${base.search}`.replace(/%24/g, '$');
}

// withLocationTime keeps the current dashboard range on an in-app link.
export function withLocationTime(url: string, search: string): string {
const current = new URLSearchParams(search);
const base = new URL(url, 'http://perses.local');
for (const key of ['start', 'end', 'tz']) {
const value = current.get(key);
if (value && !base.searchParams.has(key)) {
base.searchParams.set(key, value);
}
}
return `${base.pathname}${base.search}`.replace(/%24/g, '$');
Comment thread barchart/src/utils.ts Outdated

export function calculatePercentages(data: BarChartData[]): Array<{ label: string; value: number }> {
const fieldLabelPattern = /\$\{__field\.labels\.([A-Za-z_][A-Za-z0-9_]*)\}/g;
const fieldParamPattern = /[?&]([^=&]+)=\$\{__field\.labels\.[^}]+\}/g;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address-bar overwrite is intentional for a dashboard variable: interpolation turns All into .* and a one-element list into (Value), so the live query string is what the next dashboard must receive. I will limit that restore to parameters whose template value is that same variable, and skip it when renderVariables is false, so a literal or a mapping to another variable stays as written.

Relative dashboard links must stay on the current host, which is why the parse base is dropped whereas absolute links will keep their origin, and both helpers will keep the fragment.

A field placeholder will protect the parameter wherever it sits in the value, not only when it is the whole value.

Live query values replace only the dashboard variable of the same name,
and only when variable interpolation is on. Absolute links keep their
origin, and both helpers keep the fragment. A field placeholder protects
its parameter anywhere in the value.

Signed-off-by: colivi <charles.olivi@gmail.com>
} = props;

const variables = useAllVariableValues();
const seriesLink = definition?.spec.links?.find((link) => link.url.includes('__field.labels'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about determining the link's behavior based on its URL content. This creates an implicit coupling between the URL and the link type. Wouldn't it be cleaner to explicitly distinguish between panel and the data links at the spec level? This would also allow us to reuse the same mechanism across other panel plugins in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants