commit
fd52a65263
|
@ -67,7 +67,6 @@ interface Props {
|
||||||
isBarGraph?: boolean
|
isBarGraph?: boolean
|
||||||
staticLegend?: boolean
|
staticLegend?: boolean
|
||||||
setResolution?: (w: number) => void
|
setResolution?: (w: number) => void
|
||||||
dygraphRef?: (r: HTMLDivElement) => void
|
|
||||||
onZoom?: (u: number | string, l: number | string) => void
|
onZoom?: (u: number | string, l: number | string) => void
|
||||||
mode?: string
|
mode?: string
|
||||||
}
|
}
|
||||||
|
@ -96,14 +95,13 @@ class Dygraph extends Component<Props, State> {
|
||||||
},
|
},
|
||||||
containerStyle: {},
|
containerStyle: {},
|
||||||
isGraphFilled: true,
|
isGraphFilled: true,
|
||||||
dygraphRef: () => {},
|
|
||||||
onZoom: () => {},
|
onZoom: () => {},
|
||||||
handleSetHoverTime: () => {},
|
|
||||||
staticLegend: false,
|
staticLegend: false,
|
||||||
setResolution: () => {},
|
setResolution: () => {},
|
||||||
|
handleSetHoverTime: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
private graphRef: HTMLDivElement
|
private graphRef: React.RefObject<HTMLDivElement>
|
||||||
private dygraph: DygraphClass
|
private dygraph: DygraphClass
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
|
@ -112,6 +110,8 @@ class Dygraph extends Component<Props, State> {
|
||||||
staticLegendHeight: null,
|
staticLegendHeight: null,
|
||||||
isMounted: false,
|
isMounted: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.graphRef = React.createRef<HTMLDivElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
|
@ -124,7 +124,6 @@ class Dygraph extends Component<Props, State> {
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const timeSeries = this.timeSeries
|
const timeSeries = this.timeSeries
|
||||||
const graphRef = this.graphRef
|
|
||||||
|
|
||||||
let defaultOptions = {
|
let defaultOptions = {
|
||||||
...options,
|
...options,
|
||||||
|
@ -163,7 +162,7 @@ class Dygraph extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dygraph = new Dygraphs(graphRef, timeSeries, {
|
this.dygraph = new Dygraphs(this.graphRef.current, timeSeries, {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
...OPTIONS,
|
...OPTIONS,
|
||||||
...options,
|
...options,
|
||||||
|
@ -248,7 +247,7 @@ class Dygraph extends Component<Props, State> {
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {staticLegendHeight} = this.state
|
const {staticLegendHeight} = this.state
|
||||||
const {staticLegend, children, cellID} = this.props
|
const {staticLegend, cellID} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dygraph-child">
|
<div className="dygraph-child">
|
||||||
|
@ -274,13 +273,9 @@ class Dygraph extends Component<Props, State> {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
onMouseEnter={this.handleShowLegend}
|
|
||||||
ref={r => {
|
|
||||||
this.graphRef = r
|
|
||||||
this.props.dygraphRef(r)
|
|
||||||
}}
|
|
||||||
className="dygraph-child-container"
|
className="dygraph-child-container"
|
||||||
style={this.dygraphStyle}
|
style={this.dygraphStyle}
|
||||||
|
onMouseEnter={this.handleShowLegend}
|
||||||
/>
|
/>
|
||||||
{staticLegend && (
|
{staticLegend && (
|
||||||
<StaticLegend
|
<StaticLegend
|
||||||
|
@ -292,9 +287,15 @@ class Dygraph extends Component<Props, State> {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{this.isGraphNested &&
|
{this.isGraphNested &&
|
||||||
React.cloneElement(children as ReactElement<any>, {
|
React.cloneElement(this.nestedGraph, {
|
||||||
staticLegendHeight,
|
staticLegendHeight,
|
||||||
})}
|
})}
|
||||||
|
<div
|
||||||
|
className="dygraph-child-container"
|
||||||
|
ref={this.graphRef}
|
||||||
|
style={this.dygraphStyle}
|
||||||
|
onMouseEnter={this.handleShowLegend}
|
||||||
|
/>
|
||||||
<ReactResizeDetector
|
<ReactResizeDetector
|
||||||
handleWidth={true}
|
handleWidth={true}
|
||||||
handleHeight={true}
|
handleHeight={true}
|
||||||
|
@ -304,10 +305,17 @@ class Dygraph extends Component<Props, State> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get nestedGraph(): ReactElement<any> {
|
||||||
|
const {children} = this.props
|
||||||
|
const kids = Children.toArray(children)
|
||||||
|
|
||||||
|
return _.get(kids, '0', null)
|
||||||
|
}
|
||||||
|
|
||||||
private get isGraphNested(): boolean {
|
private get isGraphNested(): boolean {
|
||||||
const {children} = this.props
|
const {children} = this.props
|
||||||
|
|
||||||
return Children.count(children) > 0
|
return children && Children.count(children) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private get dygraphStyle(): CSSProperties {
|
private get dygraphStyle(): CSSProperties {
|
||||||
|
@ -362,7 +370,9 @@ class Dygraph extends Component<Props, State> {
|
||||||
private eventToTimestamp = ({
|
private eventToTimestamp = ({
|
||||||
pageX: pxBetweenMouseAndPage,
|
pageX: pxBetweenMouseAndPage,
|
||||||
}: MouseEvent<HTMLDivElement>): string => {
|
}: MouseEvent<HTMLDivElement>): string => {
|
||||||
const {left: pxBetweenGraphAndPage} = this.graphRef.getBoundingClientRect()
|
const {
|
||||||
|
left: pxBetweenGraphAndPage,
|
||||||
|
} = this.graphRef.current.getBoundingClientRect()
|
||||||
const graphXCoordinate = pxBetweenMouseAndPage - pxBetweenGraphAndPage
|
const graphXCoordinate = pxBetweenMouseAndPage - pxBetweenGraphAndPage
|
||||||
const timestamp = this.dygraph.toDataXCoord(graphXCoordinate)
|
const timestamp = this.dygraph.toDataXCoord(graphXCoordinate)
|
||||||
const [xRangeStart] = this.dygraph.xAxisRange()
|
const [xRangeStart] = this.dygraph.xAxisRange()
|
||||||
|
@ -415,6 +425,15 @@ class Dygraph extends Component<Props, State> {
|
||||||
return coloredDygraphSeries
|
return coloredDygraphSeries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get areAnnotationsVisible() {
|
||||||
|
if (!this.dygraph) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const [start, end] = this.dygraph && this.dygraph.xAxisRange()
|
||||||
|
return !!start && !!end
|
||||||
|
}
|
||||||
|
|
||||||
private getLabel = (axis: string): string => {
|
private getLabel = (axis: string): string => {
|
||||||
const {axes, queries} = this.props
|
const {axes, queries} = this.props
|
||||||
const label = getDeep<string>(axes, `${axis}.label`, '')
|
const label = getDeep<string>(axes, `${axis}.label`, '')
|
||||||
|
@ -444,15 +463,6 @@ class Dygraph extends Component<Props, State> {
|
||||||
private handleReceiveStaticLegendHeight = (staticLegendHeight: number) => {
|
private handleReceiveStaticLegendHeight = (staticLegendHeight: number) => {
|
||||||
this.setState({staticLegendHeight})
|
this.setState({staticLegendHeight})
|
||||||
}
|
}
|
||||||
|
|
||||||
private get areAnnotationsVisible() {
|
|
||||||
if (!this.dygraph) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const [start, end] = this.dygraph && this.dygraph.xAxisRange()
|
|
||||||
return !!start && !!end
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = ({annotations: {mode}}) => ({
|
const mapStateToProps = ({annotations: {mode}}) => ({
|
||||||
|
|
Loading…
Reference in New Issue