|
@@ -1,7 +1,6 @@
|
|
|
import $ from 'jquery';
|
|
import $ from 'jquery';
|
|
|
import React, { PureComponent } from 'react';
|
|
import React, { PureComponent } from 'react';
|
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
|
-import { AutoSizer } from 'react-virtualized';
|
|
|
|
|
|
|
|
|
|
import 'vendor/flot/jquery.flot';
|
|
import 'vendor/flot/jquery.flot';
|
|
|
import 'vendor/flot/jquery.flot.time';
|
|
import 'vendor/flot/jquery.flot.time';
|
|
@@ -76,7 +75,8 @@ const FLOT_OPTIONS = {
|
|
|
|
|
|
|
|
interface GraphProps {
|
|
interface GraphProps {
|
|
|
data: any[];
|
|
data: any[];
|
|
|
- height?: string; // e.g., '200px'
|
|
|
|
|
|
|
+ height?: number;
|
|
|
|
|
+ width?: number;
|
|
|
id?: string;
|
|
id?: string;
|
|
|
range: RawTimeRange;
|
|
range: RawTimeRange;
|
|
|
split?: boolean;
|
|
split?: boolean;
|
|
@@ -85,10 +85,6 @@ interface GraphProps {
|
|
|
onToggleSeries?: (alias: string, hiddenSeries: Set<string>) => void;
|
|
onToggleSeries?: (alias: string, hiddenSeries: Set<string>) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-interface SizedGraphProps extends GraphProps {
|
|
|
|
|
- size: { width: number; height: number };
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
interface GraphState {
|
|
interface GraphState {
|
|
|
/**
|
|
/**
|
|
|
* Type parameter refers to the `alias` property of a `TimeSeries`.
|
|
* Type parameter refers to the `alias` property of a `TimeSeries`.
|
|
@@ -98,7 +94,7 @@ interface GraphState {
|
|
|
showAllTimeSeries: boolean;
|
|
showAllTimeSeries: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export class Graph extends PureComponent<SizedGraphProps, GraphState> {
|
|
|
|
|
|
|
+export class Graph extends PureComponent<GraphProps, GraphState> {
|
|
|
$el: any;
|
|
$el: any;
|
|
|
dynamicOptions = null;
|
|
dynamicOptions = null;
|
|
|
|
|
|
|
@@ -119,13 +115,13 @@ export class Graph extends PureComponent<SizedGraphProps, GraphState> {
|
|
|
this.$el.bind('plotselected', this.onPlotSelected);
|
|
this.$el.bind('plotselected', this.onPlotSelected);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- componentDidUpdate(prevProps: SizedGraphProps, prevState: GraphState) {
|
|
|
|
|
|
|
+ componentDidUpdate(prevProps: GraphProps, prevState: GraphState) {
|
|
|
if (
|
|
if (
|
|
|
prevProps.data !== this.props.data ||
|
|
prevProps.data !== this.props.data ||
|
|
|
prevProps.range !== this.props.range ||
|
|
prevProps.range !== this.props.range ||
|
|
|
prevProps.split !== this.props.split ||
|
|
prevProps.split !== this.props.split ||
|
|
|
prevProps.height !== this.props.height ||
|
|
prevProps.height !== this.props.height ||
|
|
|
- (prevProps.size && prevProps.size.width !== this.props.size.width) ||
|
|
|
|
|
|
|
+ prevProps.width !== this.props.width ||
|
|
|
!equal(prevState.hiddenSeries, this.state.hiddenSeries)
|
|
!equal(prevState.hiddenSeries, this.state.hiddenSeries)
|
|
|
) {
|
|
) {
|
|
|
this.draw();
|
|
this.draw();
|
|
@@ -147,8 +143,8 @@ export class Graph extends PureComponent<SizedGraphProps, GraphState> {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
getDynamicOptions() {
|
|
getDynamicOptions() {
|
|
|
- const { range, size } = this.props;
|
|
|
|
|
- const ticks = (size.width || 0) / 100;
|
|
|
|
|
|
|
+ const { range, width } = this.props;
|
|
|
|
|
+ const ticks = (width || 0) / 100;
|
|
|
let { from, to } = range;
|
|
let { from, to } = range;
|
|
|
if (!moment.isMoment(from)) {
|
|
if (!moment.isMoment(from)) {
|
|
|
from = dateMath.parse(from, false);
|
|
from = dateMath.parse(from, false);
|
|
@@ -240,7 +236,7 @@ export class Graph extends PureComponent<SizedGraphProps, GraphState> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { height = '100px', id = 'graph' } = this.props;
|
|
|
|
|
|
|
+ const { height = 100, id = 'graph' } = this.props;
|
|
|
const { hiddenSeries } = this.state;
|
|
const { hiddenSeries } = this.state;
|
|
|
const data = this.getGraphData();
|
|
const data = this.getGraphData();
|
|
|
|
|
|
|
@@ -264,20 +260,4 @@ export class Graph extends PureComponent<SizedGraphProps, GraphState> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export default (props: GraphProps) => (
|
|
|
|
|
- <div>{/* div needed for AutoSizer to calculate, https://github.com/bvaughn/react-virtualized/blob/master/docs/usingAutoSizer.md#observation */}
|
|
|
|
|
- <AutoSizer disableHeight>
|
|
|
|
|
- {({width, height}) => (
|
|
|
|
|
- <div style={{width}}>
|
|
|
|
|
- {width > 0 && <Graph
|
|
|
|
|
- size={{
|
|
|
|
|
- width: width,
|
|
|
|
|
- height: height
|
|
|
|
|
- }}
|
|
|
|
|
- {...props}
|
|
|
|
|
- />}
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- </AutoSizer>
|
|
|
|
|
- </div>
|
|
|
|
|
-);
|
|
|
|
|
|
|
+export default Graph;
|