[ENHANCEMENT]: Add negative y axis support#696
Open
ibakshay wants to merge 1 commit into
Open
Conversation
Signed-off-by: Akshay Iyyadurai Balasundaram <akshay.iyyadurai.balasundaram@sap.com>
There was a problem hiding this comment.
Pull request overview
This PR adds per-query Negative Y support to the TimeSeriesChart plugin so a query’s series can be negated for display (rendering below the X axis) while keeping the original values for legend calculations and CSV export, matching the Grafana “negative-Y” transform use case (issue #3315).
Changes:
- Negate rendered datapoints when
querySettings[].negativeYis enabled, without altering underlying query results / legend calculations. - Fix percent-threshold computation to use absolute magnitudes so percent thresholds still work when series are negated.
- Extend plugin model/schema/SDK + migration and validation tests, and document the new option.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| timeserieschart/src/utils/data-transform.ts | Uses absolute values when computing max for percent thresholds (supports negated series). |
| timeserieschart/src/utils/data-transform.test.ts | Adds a unit test ensuring percent thresholds still resolve with negated (negative) inputs. |
| timeserieschart/src/TimeSeriesChartPanel.tsx | Applies negativeY by negating rendered series values while keeping original values for legend/CSV. |
| timeserieschart/src/time-series-chart-model.ts | Adds negativeY?: boolean to query settings model with docstring. |
| timeserieschart/src/QuerySettingsEditor.tsx | Adds UI controls to add/remove the per-query Negative Y setting. |
| timeserieschart/sdk/go/time-series.go | Adds NegativeY to the Go SDK query settings struct. |
| timeserieschart/schemas/time-series.cue | Extends the CUE schema to allow negativeY?: bool. |
| timeserieschart/schemas/tests/valid/time-series-negative-y.json | Adds a valid schema test fixture for negativeY. |
| timeserieschart/schemas/tests/valid/time-series-negative-y-stacked.json | Adds a valid schema test fixture for negativeY with stacking. |
| timeserieschart/schemas/migrate/migrate.cue | Migrates Grafana transform: "negative-Y" (panel default + overrides) into querySettings[].negativeY. |
| timeserieschart/schemas/migrate/tests/negative-y-panel-default/input.json | Migration test input for panel-level negative-Y transform. |
| timeserieschart/schemas/migrate/tests/negative-y-panel-default/expected.json | Expected migrated output with negativeY applied to queries. |
| timeserieschart/schemas/migrate/tests/negative-y-override/input.json | Migration test input for per-series override negative-Y transform. |
| timeserieschart/schemas/migrate/tests/negative-y-override/expected.json | Expected migrated output with negativeY applied to the overridden query only. |
| docs/timeserieschart/model.md | Documents negativeY and notes compatibility/edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+281
to
+284
| // When negativeY is set on this query, negate the rendered values so the | ||
| // series renders below the X axis. The original (positive) values are | ||
| // preserved in `timeSeries.values` (used for legend calculations) and in | ||
| // `queryResults` (used for CSV export). |
Comment on lines
+49
to
+53
| /** | ||
| * If true, the query's series values are negated for display so they render | ||
| * below the X axis. The original (positive) values are preserved for legend | ||
| * calculations and CSV export, matching Grafana's `transform: "negative-Y"` behavior. | ||
| */ |
Comment on lines
+86
to
+88
| # negativeY renders the query's series below the X axis. Values are negated for display only; | ||
| # legend calculations and CSV export keep the original (positive) values. | ||
| negativeY: <boolean> # Optional |
Comment on lines
+97
to
+98
| - **CSV export**: exports the original positive values from the query results. | ||
| - **Legend calculations (min / max / mean / …)**: computed from the original positive values. |
| lineStyle?: #lineStyle | ||
| areaOpacity?: #areaOpacity | ||
| format?: common.#format | ||
| negativeY?: bool // render the query's series below the X axis |
Comment on lines
+508
to
+510
| <Typography variant="body2" color="text.secondary" sx={{ flexGrow: 1, py: 0.5 }}> | ||
| Series rendered below the X axis | ||
| </Typography> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request resolves perses/perses#3315
Screenshots
Screenshot 1
Screenshot 2
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes