From 90c41bb087f7b627f8e8c76fee93fe786e50fd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 14 Nov 2018 12:03:25 +0100 Subject: [PATCH] changed how size is calcualted and propagated and added proper interval calc to DataPanel --- public/app/core/components/Switch/Switch.tsx | 1 + .../dashboard/dashgrid/DashboardGrid.tsx | 1 + .../features/dashboard/dashgrid/DataPanel.tsx | 36 ++++++++++--------- .../dashboard/dashgrid/PanelChrome.tsx | 24 ++++++------- public/app/types/series.ts | 2 ++ public/app/viz/Graph.tsx | 1 + public/sass/pages/_dashboard.scss | 5 +++ 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/public/app/core/components/Switch/Switch.tsx b/public/app/core/components/Switch/Switch.tsx index a4bb73a291b..09c5b894d3d 100644 --- a/public/app/core/components/Switch/Switch.tsx +++ b/public/app/core/components/Switch/Switch.tsx @@ -26,6 +26,7 @@ export class Switch extends PureComponent { render() { const { labelClass = '', switchClass = '', label, checked, small } = this.props; + const labelId = `check-${this.state.id}`; let labelClassName = `gf-form-label ${labelClass} pointer`; let switchClassName = `gf-form-switch ${switchClass}`; diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index 55249a4716f..84db3a2cf99 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -176,6 +176,7 @@ export class DashboardGrid extends React.Component { renderPanels() { const panelElements = []; + console.log('render panels'); for (const panel of this.props.dashboard.panels) { const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen }); diff --git a/public/app/features/dashboard/dashgrid/DataPanel.tsx b/public/app/features/dashboard/dashgrid/DataPanel.tsx index 7fb07415c0d..ecff4a7fabf 100644 --- a/public/app/features/dashboard/dashgrid/DataPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DataPanel.tsx @@ -4,6 +4,9 @@ import React, { Component } from 'react'; // Services import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; +// Utils +import kbn from 'app/core/utils/kbn'; + // Types import { TimeRange, LoadingState, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types'; @@ -21,6 +24,8 @@ export interface Props { timeRange?: TimeRange; widthPixels: number; refreshCounter: number; + minInterval?: string; + maxDataPoints?: number; children: (r: RenderProps) => JSX.Element; } @@ -52,7 +57,7 @@ export class DataPanel extends Component { } componentDidMount() { - console.log('DataPanel mount'); + this.issueQueries(); } async componentDidUpdate(prevProps: Props) { @@ -64,12 +69,11 @@ export class DataPanel extends Component { } hasPropsChanged(prevProps: Props) { - return this.props.refreshCounter !== prevProps.refreshCounter || this.props.isVisible !== prevProps.isVisible; + return this.props.refreshCounter !== prevProps.refreshCounter; } issueQueries = async () => { - const { isVisible, queries, datasource, panelId, dashboardId, timeRange } = this.props; - console.log('issueQueries', this.props); + const { isVisible, queries, datasource, panelId, dashboardId, timeRange, widthPixels, maxDataPoints } = this.props; if (!isVisible) { return; @@ -84,16 +88,21 @@ export class DataPanel extends Component { try { const ds = await this.dataSourceSrv.get(datasource); + + // TODO interpolate variables + const minInterval = this.props.minInterval || ds.interval; + const intervalRes = kbn.calculateInterval(timeRange, widthPixels, minInterval); + const queryOptions: DataQueryOptions = { timezone: 'browser', panelId: panelId, dashboardId: dashboardId, range: timeRange, rangeRaw: timeRange.raw, - interval: '1s', - intervalMs: 60000, + interval: intervalRes.interval, + intervalMs: intervalRes.intervalMs, targets: queries, - maxDataPoints: 500, + maxDataPoints: maxDataPoints || widthPixels, scopedVars: {}, cacheTimeout: null, }; @@ -114,17 +123,10 @@ export class DataPanel extends Component { }; render() { - const { response, loading, isFirstLoad } = this.state; - console.log('data panel render'); + const { response, loading } = this.state; const timeSeries = response.data; - // if (isFirstLoad && (loading === LoadingState.Loading || loading === LoadingState.NotStarted)) { - // return ( - //
- //

Loading

- //
- // ); - // } + console.log('data panel render'); return ( <> @@ -142,7 +144,7 @@ export class DataPanel extends Component { if (loading === LoadingState.Loading) { return ( -
+
); diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 05f2d1a4793..99b44e6ff72 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -88,16 +88,14 @@ export class PanelChrome extends PureComponent { console.log('panelChrome render'); return ( -
- - {({ width, height }) => { - // console.log('SizeMe', size); - console.log('autosizer width', width); - if (width === 0) { - return null; - } + + {({ width, height }) => { + if (width === 0) { + return null; + } - return ( + return ( +
{ ); }} - ); - }} - -
+
+ ); + }} + ); } } diff --git a/public/app/types/series.ts b/public/app/types/series.ts index 997090bf541..1feba9a3b53 100644 --- a/public/app/types/series.ts +++ b/public/app/types/series.ts @@ -89,4 +89,6 @@ export interface DataQueryOptions { export interface DataSourceApi { query(options: DataQueryOptions): Promise; testDatasource(): Promise; + + interval?: string; } diff --git a/public/app/viz/Graph.tsx b/public/app/viz/Graph.tsx index a809863b805..bdababb3e50 100644 --- a/public/app/viz/Graph.tsx +++ b/public/app/viz/Graph.tsx @@ -92,6 +92,7 @@ export class Graph extends PureComponent { }; try { + console.log('Graph render'); $.plot(this.element, timeSeries, flotOptions); } catch (err) { console.log('Graph rendering error', err, flotOptions, timeSeries); diff --git a/public/sass/pages/_dashboard.scss b/public/sass/pages/_dashboard.scss index 79fe0b2569b..cffbd28597e 100644 --- a/public/sass/pages/_dashboard.scss +++ b/public/sass/pages/_dashboard.scss @@ -43,6 +43,7 @@ div.flot-text { position: relative; border-radius: 3px; height: 100%; + width: 100%; &.panel-transparent { background-color: transparent; @@ -60,6 +61,10 @@ div.flot-text { &--is-editing { height: auto; } + + &--absolute { + position: absolute; + } } .panel-content {