From e39e82949dccbc5be080a15e01b793385177295a Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Tue, 6 Nov 2018 11:07:12 +0100 Subject: [PATCH] Adaptive bar widths for log graph --- public/app/features/explore/Explore.tsx | 3 +- public/app/features/explore/Graph.tsx | 1 + public/app/features/explore/Logs.tsx | 3 ++ public/app/features/explore/TimePicker.tsx | 33 ++++++++++--------- .../plugins/datasource/logging/datasource.ts | 2 +- .../datasource/logging/result_transformer.ts | 4 +-- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 78764ab9876..896a946a85b 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -475,7 +475,7 @@ export class Explore extends React.PureComponent { from: parseDate(range.from, false), to: parseDate(range.to, true), }; - const { interval } = kbn.calculateInterval(absoluteRange, resolution, datasource.interval); + const { interval, intervalMs } = kbn.calculateInterval(absoluteRange, resolution, datasource.interval); const targets = [ { ...targetOptions, @@ -490,6 +490,7 @@ export class Explore extends React.PureComponent { return { interval, + intervalMs, targets, range: queryRange, }; diff --git a/public/app/features/explore/Graph.tsx b/public/app/features/explore/Graph.tsx index 2c1f08b871d..9e4fea0d3de 100644 --- a/public/app/features/explore/Graph.tsx +++ b/public/app/features/explore/Graph.tsx @@ -6,6 +6,7 @@ import { withSize } from 'react-sizeme'; import 'vendor/flot/jquery.flot'; import 'vendor/flot/jquery.flot.time'; import 'vendor/flot/jquery.flot.selection'; +import 'vendor/flot/jquery.flot.stack'; import { RawTimeRange } from 'app/types/series'; import * as dateMath from 'app/core/utils/datemath'; diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index ccfa96bed0b..edde5acba92 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -12,7 +12,10 @@ const graphOptions = { series: { bars: { show: true, + lineWidth: 5, + // barWidth: 10, }, + // stack: true, }, yaxis: { tickDecimals: 0, diff --git a/public/app/features/explore/TimePicker.tsx b/public/app/features/explore/TimePicker.tsx index ed2fd924c78..a3578263cea 100644 --- a/public/app/features/explore/TimePicker.tsx +++ b/public/app/features/explore/TimePicker.tsx @@ -43,7 +43,7 @@ interface TimePickerState { isUtc: boolean; rangeString: string; refreshInterval?: string; - initialRange: RawTimeRange; + initialRange?: RawTimeRange; // Input-controlled text, keep these in a shape that is human-editable fromRaw: string; @@ -53,24 +53,27 @@ interface TimePickerState { export default class TimePicker extends PureComponent { dropdownEl: any; - state = { - isOpen: false, - isUtc: false, - rangeString: '', - initialRange: DEFAULT_RANGE, - fromRaw: '', - toRaw: '', - refreshInterval: '', - }; + constructor(props) { + super(props); + + this.state = { + isOpen: props.isOpen, + isUtc: props.isUtc, + rangeString: '', + fromRaw: '', + toRaw: '', + initialRange: DEFAULT_RANGE, + refreshInterval: '', + }; + } static getDerivedStateFromProps(props, state) { - if (state.range && state.range === props.range) { - return null; + if (state.initialRange && state.initialRange === props.range) { + return state; } const from = props.range ? props.range.from : DEFAULT_RANGE.from; const to = props.range ? props.range.to : DEFAULT_RANGE.to; - const initialRange = props.range || DEFAULT_RANGE; // Ensure internal format const fromRaw = parseTime(from, props.isUtc); @@ -81,10 +84,10 @@ export default class TimePicker extends PureComponent processStream(stream, DEFAULT_LIMIT)); + const processedStreams = allStreams.map(stream => processStream(stream, DEFAULT_LIMIT, options.intervalMs)); return { data: processedStreams }; }); } diff --git a/public/app/plugins/datasource/logging/result_transformer.ts b/public/app/plugins/datasource/logging/result_transformer.ts index 8aa7ebc12e0..e1e622aeb59 100644 --- a/public/app/plugins/datasource/logging/result_transformer.ts +++ b/public/app/plugins/datasource/logging/result_transformer.ts @@ -143,7 +143,7 @@ export function mergeStreams(streams: LogsStream[], limit?: number): LogsModel { return { meta, series, rows: sortedEntries }; } -export function processStream(stream: LogsStream, limit?: number): LogsStream { +export function processStream(stream: LogsStream, limit?: number, intervalMs?: number): LogsStream { const sortedEntries: any[] = _.chain(stream.entries) .map(entry => processEntry(entry, stream)) .sortBy('timestamp') @@ -155,7 +155,7 @@ export function processStream(stream: LogsStream, limit?: number): LogsStream { let previousTime; const datapoints = sortedEntries.reduce((acc, entry, index) => { // Bucket to nearest minute - const time = Math.round(entry.timeJs / 1000 / 60) * 1000 * 60; + const time = Math.round(entry.timeJs / intervalMs / 10) * intervalMs * 10; // Entry for time if (time === previousTime) { acc[acc.length - 1][0]++;