Skip to content

Add granularity (step) selector to override query step#773

Merged
thinkingfish merged 3 commits intomainfrom
claude/chart-scaling-tool-YdArW
Apr 14, 2026
Merged

Add granularity (step) selector to override query step#773
thinkingfish merged 3 commits intomainfrom
claude/chart-scaling-tool-YdArW

Conversation

@thinkingfish
Copy link
Copy Markdown
Member

Problem

When querying time-series data, the viewer automatically calculates an appropriate query step based on the time window duration. However, users may want to override this auto-calculated step to get finer or coarser granularity in their results for better analysis or performance tuning.

Solution

Added a granularity selector control that allows users to override the auto-calculated query step:

  1. New UI Component (GranularitySelector): A dropdown control in the top navigation bar that lets users select from predefined step options (Auto, 1s, 15s, 1m, 15m) or use the auto-calculated value.

  2. Step Override Mechanism (data.js): Introduced setStepOverride() and getStepOverride() functions to manage the user-selected step value. When a step override is set, it takes precedence over the auto-calculated step in range queries.

  3. State Management (script.js): Added currentGranularity state and changeGranularity() handler that:

    • Updates the step override
    • Clears relevant caches to force fresh data fetches
    • Reloads the current section with the new step value
    • Triggers UI redraw
  4. Styling (style.css): Added CSS classes for the granularity selector with proper styling, hover/focus states, and responsive adjustments for mobile views.

  5. Integration: Connected the granularity selector to the top navigation bar, making it visible only when time range data is available and hiding it on system info and report pages.

Result

Users can now manually adjust the query step granularity via a dropdown selector in the top navigation bar. This provides more control over the data resolution and can help with performance optimization or detailed analysis of specific time ranges. The selector is only shown when appropriate (time-range queries) and integrates seamlessly with the existing viewer interface.

https://claude.ai/code/session_01Dd3LpTREvfoscZdtSjqLc4

@thinkingfish thinkingfish force-pushed the claude/chart-scaling-tool-YdArW branch from a9ce8ca to 6eeb249 Compare April 13, 2026 04:32
@thinkingfish thinkingfish marked this pull request as draft April 13, 2026 04:33
@thinkingfish thinkingfish force-pushed the claude/chart-scaling-tool-YdArW branch from 6eeb249 to ba45125 Compare April 13, 2026 20:58
claude and others added 2 commits April 13, 2026 17:04
Add a Step dropdown to the TopNav bar that lets users override the
auto-calculated PromQL query step, enabling coarser time aggregation
(e.g. 1s, 15s, 1m, 15m) across all charts. Changing the granularity
invalidates cached data and re-fetches all sections at the new
resolution. Works in both the server-based viewer and the WASM site
viewer.

https://claude.ai/code/session_01Dd3LpTREvfoscZdtSjqLc4
Rewrite PromQL queries when a coarser step is selected so values are
properly smoothed over the wider window:
- Counter: irate(m[5m]) → rate(m[Ns]) for true windowed average
- Gauge: wrap simple selectors with avg_over_time(m[Ns])
- Histogram: pass stride to histogram_percentiles / histogram_heatmap

Fix insertGapNulls breaking chart lines at step-aligned intervals by
using the step override as the effective gap detection interval.

Remove frontend downsampler (backend VectorSelector now respects step).

Tighten responsive topnav layout: reduce row gap, right-align
granularity selector and theme toggle on narrow viewports, remove
asymmetric time-range-bar margin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thinkingfish thinkingfish force-pushed the claude/chart-scaling-tool-YdArW branch from 7d9b326 to 61d9593 Compare April 14, 2026 00:06
Remove avg_over_time rewrite for gauge queries — gauges are
instantaneous values that don't need windowed aggregation. Also add
5s option to the granularity step selector. Bump metriken-query and
update README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thinkingfish thinkingfish marked this pull request as ready for review April 14, 2026 16:43
@thinkingfish thinkingfish merged commit 95d459e into main Apr 14, 2026
25 checks passed
@thinkingfish thinkingfish deleted the claude/chart-scaling-tool-YdArW branch April 17, 2026 20:21
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.

2 participants