@@ -123,31 +123,40 @@ function getTimeChartDateRange(
123123export const MAX_TIME_CHART_SERIES = DEFAULT_SERIES_LIMIT ;
124124
125125/**
126- * A PromQL number tile's queried config, shared by the value and the sparkline
127- * drawn behind it.
126+ * A PromQL config's resolved granularity, and its date range aligned to that
127+ * granularity's buckets when it runs a range query, so its samples land on the
128+ * same boundaries as the timeseries charts' and stay put across refreshes.
128129 */
129- export function convertToPromqlNumberChartConfig (
130+ function getAlignedRangeAndGranularity (
130131 config : PromqlChartConfig & DateRange ,
131- { withReducer } : { withReducer : boolean } ,
132- ) : PromqlChartConfig & DateRange {
132+ ) : Pick < PromqlChartConfig & DateRange , 'granularity' | 'dateRange' > {
133133 const granularity = getTimeChartGranularity (
134134 config . granularity ,
135135 config . dateRange ,
136136 ) ;
137137 return {
138- ...config ,
139138 granularity,
140- // Align the date range with the same buckets used by the sparkline and
141- // timeseries charts, when using a (bucketed) range query. Alignment is
142- // desirable for range queries to ensure consistent bucket boundaries
143- // and sizes.
144139 dateRange : isRangeQuery ( config )
145140 ? getTimeChartDateRange (
146141 config . dateRange ,
147142 config . alignDateRangeToGranularity ,
148143 granularity ,
149144 )
150145 : config . dateRange ,
146+ } ;
147+ }
148+
149+ /**
150+ * A PromQL number tile's queried config, shared by the value and the sparkline
151+ * drawn behind it.
152+ */
153+ export function convertToPromqlNumberChartConfig (
154+ config : PromqlChartConfig & DateRange ,
155+ { withReducer } : { withReducer : boolean } ,
156+ ) : PromqlChartConfig & DateRange {
157+ return {
158+ ...config ,
159+ ...getAlignedRangeAndGranularity ( config ) ,
151160 promqlExpression : getQueriedPromqlSeries ( config ) . map ( series => ( {
152161 ...series ,
153162 reducer : withReducer
@@ -157,6 +166,13 @@ export function convertToPromqlNumberChartConfig(
157166 } ;
158167}
159168
169+ /** A PromQL table tile's queried config. */
170+ export function convertToPromqlTableChartConfig (
171+ config : PromqlChartConfig & DateRange ,
172+ ) : PromqlChartConfig & DateRange {
173+ return { ...config , ...getAlignedRangeAndGranularity ( config ) } ;
174+ }
175+
160176export function convertToTimeChartConfig (
161177 config : ChartConfigWithDateRange ,
162178) : ChartConfigWithDateRange {
0 commit comments