From e6a74eb1a274e3f655ebc4f61d8c08a8bf4eb013 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Sun, 24 Feb 2019 10:01:50 -0800 Subject: [PATCH] Explore: Make sure line graphs get different colors - lines for graphs from different query rows end up in different transactions - within each transaction the color distribution resets leading to color overlap - this change takes existing transaction colors into account --- public/app/core/utils/explore.ts | 22 ++++++++++++++++---- public/app/features/explore/state/actions.ts | 3 ++- public/app/types/explore.ts | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 619391d46d1..31e5a392050 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -20,6 +20,7 @@ import { ResultType, QueryIntervals, QueryOptions, + ResultGetter, } from 'app/types/explore'; import { LogsDedupStrategy } from 'app/core/logs_model'; @@ -301,11 +302,24 @@ export function getIntervals(range: RawTimeRange, lowLimit: string, resolution: return kbn.calculateInterval(absoluteRange, resolution, lowLimit); } -export function makeTimeSeriesList(dataList) { - return dataList.map((seriesData, index) => { +export const makeTimeSeriesList: ResultGetter = (dataList, transaction, allTransactions) => { + // Prevent multiple Graph transactions to have the same colors + let colorIndexOffset = 0; + for (const other of allTransactions) { + // Only need to consider transactions that came before the current one + if (other === transaction) { + break; + } + // Count timeseries of previous query results + if (other.resultType === 'Graph' && other.done) { + colorIndexOffset += other.result.length; + } + } + + return dataList.map((seriesData, index: number) => { const datapoints = seriesData.datapoints || []; const alias = seriesData.target; - const colorIndex = index % colors.length; + const colorIndex = (colorIndexOffset + index) % colors.length; const color = colors[colorIndex]; const series = new TimeSeries({ @@ -317,7 +331,7 @@ export function makeTimeSeriesList(dataList) { return series; }); -} +}; /** * Update the query history. Side-effect: store history in local storage diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index b84a0534836..e0b84320fa7 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -597,7 +597,8 @@ function runQueriesForType( const res = await datasourceInstance.query(transaction.options); eventBridge.emit('data-received', res.data || []); const latency = Date.now() - now; - const results = resultGetter ? resultGetter(res.data) : res.data; + const { queryTransactions } = getState().explore[exploreId]; + const results = resultGetter ? resultGetter(res.data, transaction, queryTransactions) : res.data; dispatch(queryTransactionSuccess(exploreId, transaction.id, results, latency, queries, datasourceId)); } catch (response) { eventBridge.emit('data-error', response); diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index 7a6af04b2ee..fadea49b7a4 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -322,6 +322,8 @@ export interface QueryTransaction { export type RangeScanner = () => RawTimeRange; +export type ResultGetter = (result: any, transaction: QueryTransaction, allTransactions: QueryTransaction[]) => any; + export interface TextMatch { text: string; start: number;