mirror of
https://github.com/grafana/grafana.git
synced 2025-09-27 20:23:41 +08:00
changed how size is calcualted and propagated and added proper interval calc to DataPanel
This commit is contained in:
@ -26,6 +26,7 @@ export class Switch extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { labelClass = '', switchClass = '', label, checked, small } = this.props;
|
const { labelClass = '', switchClass = '', label, checked, small } = this.props;
|
||||||
|
|
||||||
const labelId = `check-${this.state.id}`;
|
const labelId = `check-${this.state.id}`;
|
||||||
let labelClassName = `gf-form-label ${labelClass} pointer`;
|
let labelClassName = `gf-form-label ${labelClass} pointer`;
|
||||||
let switchClassName = `gf-form-switch ${switchClass}`;
|
let switchClassName = `gf-form-switch ${switchClass}`;
|
||||||
|
@ -176,6 +176,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|||||||
|
|
||||||
renderPanels() {
|
renderPanels() {
|
||||||
const panelElements = [];
|
const panelElements = [];
|
||||||
|
console.log('render panels');
|
||||||
|
|
||||||
for (const panel of this.props.dashboard.panels) {
|
for (const panel of this.props.dashboard.panels) {
|
||||||
const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
|
const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
|
||||||
|
@ -4,6 +4,9 @@ import React, { Component } from 'react';
|
|||||||
// Services
|
// Services
|
||||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { TimeRange, LoadingState, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types';
|
import { TimeRange, LoadingState, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types';
|
||||||
|
|
||||||
@ -21,6 +24,8 @@ export interface Props {
|
|||||||
timeRange?: TimeRange;
|
timeRange?: TimeRange;
|
||||||
widthPixels: number;
|
widthPixels: number;
|
||||||
refreshCounter: number;
|
refreshCounter: number;
|
||||||
|
minInterval?: string;
|
||||||
|
maxDataPoints?: number;
|
||||||
children: (r: RenderProps) => JSX.Element;
|
children: (r: RenderProps) => JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +57,7 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
console.log('DataPanel mount');
|
this.issueQueries();
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidUpdate(prevProps: Props) {
|
async componentDidUpdate(prevProps: Props) {
|
||||||
@ -64,12 +69,11 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasPropsChanged(prevProps: Props) {
|
hasPropsChanged(prevProps: Props) {
|
||||||
return this.props.refreshCounter !== prevProps.refreshCounter || this.props.isVisible !== prevProps.isVisible;
|
return this.props.refreshCounter !== prevProps.refreshCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
issueQueries = async () => {
|
issueQueries = async () => {
|
||||||
const { isVisible, queries, datasource, panelId, dashboardId, timeRange } = this.props;
|
const { isVisible, queries, datasource, panelId, dashboardId, timeRange, widthPixels, maxDataPoints } = this.props;
|
||||||
console.log('issueQueries', this.props);
|
|
||||||
|
|
||||||
if (!isVisible) {
|
if (!isVisible) {
|
||||||
return;
|
return;
|
||||||
@ -84,16 +88,21 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const ds = await this.dataSourceSrv.get(datasource);
|
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 = {
|
const queryOptions: DataQueryOptions = {
|
||||||
timezone: 'browser',
|
timezone: 'browser',
|
||||||
panelId: panelId,
|
panelId: panelId,
|
||||||
dashboardId: dashboardId,
|
dashboardId: dashboardId,
|
||||||
range: timeRange,
|
range: timeRange,
|
||||||
rangeRaw: timeRange.raw,
|
rangeRaw: timeRange.raw,
|
||||||
interval: '1s',
|
interval: intervalRes.interval,
|
||||||
intervalMs: 60000,
|
intervalMs: intervalRes.intervalMs,
|
||||||
targets: queries,
|
targets: queries,
|
||||||
maxDataPoints: 500,
|
maxDataPoints: maxDataPoints || widthPixels,
|
||||||
scopedVars: {},
|
scopedVars: {},
|
||||||
cacheTimeout: null,
|
cacheTimeout: null,
|
||||||
};
|
};
|
||||||
@ -114,17 +123,10 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { response, loading, isFirstLoad } = this.state;
|
const { response, loading } = this.state;
|
||||||
console.log('data panel render');
|
|
||||||
const timeSeries = response.data;
|
const timeSeries = response.data;
|
||||||
|
|
||||||
// if (isFirstLoad && (loading === LoadingState.Loading || loading === LoadingState.NotStarted)) {
|
console.log('data panel render');
|
||||||
// return (
|
|
||||||
// <div className="loading">
|
|
||||||
// <p>Loading</p>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -142,7 +144,7 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
|
|
||||||
if (loading === LoadingState.Loading) {
|
if (loading === LoadingState.Loading) {
|
||||||
return (
|
return (
|
||||||
<div className="panel__loading">
|
<div className="panel-loading">
|
||||||
<i className="fa fa-spinner fa-spin" />
|
<i className="fa fa-spinner fa-spin" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -88,16 +88,14 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
console.log('panelChrome render');
|
console.log('panelChrome render');
|
||||||
return (
|
return (
|
||||||
<div className="panel-container">
|
<AutoSizer>
|
||||||
<AutoSizer>
|
{({ width, height }) => {
|
||||||
{({ width, height }) => {
|
if (width === 0) {
|
||||||
// console.log('SizeMe', size);
|
return null;
|
||||||
console.log('autosizer width', width);
|
}
|
||||||
if (width === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div className="panel-container panel-container--absolute">
|
||||||
<DataPanel
|
<DataPanel
|
||||||
datasource={datasource}
|
datasource={datasource}
|
||||||
queries={targets}
|
queries={targets}
|
||||||
@ -125,10 +123,10 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</DataPanel>
|
</DataPanel>
|
||||||
);
|
</div>
|
||||||
}}
|
);
|
||||||
</AutoSizer>
|
}}
|
||||||
</div>
|
</AutoSizer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,4 +89,6 @@ export interface DataQueryOptions {
|
|||||||
export interface DataSourceApi {
|
export interface DataSourceApi {
|
||||||
query(options: DataQueryOptions): Promise<DataQueryResponse>;
|
query(options: DataQueryOptions): Promise<DataQueryResponse>;
|
||||||
testDatasource(): Promise<any>;
|
testDatasource(): Promise<any>;
|
||||||
|
|
||||||
|
interval?: string;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ export class Graph extends PureComponent<GraphProps> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('Graph render');
|
||||||
$.plot(this.element, timeSeries, flotOptions);
|
$.plot(this.element, timeSeries, flotOptions);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Graph rendering error', err, flotOptions, timeSeries);
|
console.log('Graph rendering error', err, flotOptions, timeSeries);
|
||||||
|
@ -43,6 +43,7 @@ div.flot-text {
|
|||||||
position: relative;
|
position: relative;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
&.panel-transparent {
|
&.panel-transparent {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
@ -60,6 +61,10 @@ div.flot-text {
|
|||||||
&--is-editing {
|
&--is-editing {
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--absolute {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-content {
|
.panel-content {
|
||||||
|
Reference in New Issue
Block a user