WIP legened wont render on initial render
parent
42e59d74aa
commit
b0f00c074e
|
@ -97,24 +97,12 @@ class Dygraph extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps, nextState) {
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
const timeRangeChanged = !_.isEqual(
|
|
||||||
nextProps.timeRange,
|
|
||||||
this.props.timeRange
|
|
||||||
)
|
|
||||||
|
|
||||||
if (this.dygraph.isZoomed() && timeRangeChanged) {
|
|
||||||
this.dygraph.resetZoom()
|
|
||||||
}
|
|
||||||
|
|
||||||
const arePropsEqual = _.isEqual(this.props, nextProps)
|
const arePropsEqual = _.isEqual(this.props, nextProps)
|
||||||
const areStatesEqual = _.isEqual(this.state, nextState)
|
const areStatesEqual = _.isEqual(this.state, nextState)
|
||||||
|
return !arePropsEqual || !areStatesEqual
|
||||||
const shouldUpdate = !arePropsEqual || !areStatesEqual
|
|
||||||
|
|
||||||
return shouldUpdate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate(prevProps) {
|
||||||
const {labels, axes: {y, y2}, options, isBarGraph} = this.props
|
const {labels, axes: {y, y2}, options, isBarGraph} = this.props
|
||||||
|
|
||||||
const dygraph = this.dygraph
|
const dygraph = this.dygraph
|
||||||
|
@ -127,6 +115,15 @@ class Dygraph extends Component {
|
||||||
|
|
||||||
const timeSeries = this.timeSeries
|
const timeSeries = this.timeSeries
|
||||||
|
|
||||||
|
const timeRangeChanged = !_.isEqual(
|
||||||
|
prevProps.timeRange,
|
||||||
|
this.props.timeRange
|
||||||
|
)
|
||||||
|
|
||||||
|
if (this.dygraph.isZoomed() && timeRangeChanged) {
|
||||||
|
this.dygraph.resetZoom()
|
||||||
|
}
|
||||||
|
|
||||||
const updateOptions = {
|
const updateOptions = {
|
||||||
...options,
|
...options,
|
||||||
labels,
|
labels,
|
||||||
|
|
|
@ -9,7 +9,16 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class DygraphLegend extends Component {
|
class DygraphLegend extends Component {
|
||||||
state = {
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.props.dygraph.updateOptions({
|
||||||
|
legendFormatter: this.legendFormatter,
|
||||||
|
highlightCallback: this.highlightCallback,
|
||||||
|
unhighlightCallback: this.unhighlightCallback,
|
||||||
|
})
|
||||||
|
|
||||||
|
this.state = {
|
||||||
legend: {
|
legend: {
|
||||||
x: null,
|
x: null,
|
||||||
series: [],
|
series: [],
|
||||||
|
@ -22,13 +31,6 @@ class DygraphLegend extends Component {
|
||||||
legendStyles: {},
|
legendStyles: {},
|
||||||
pageX: null,
|
pageX: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.props.dygraph.updateOptions({
|
|
||||||
legendFormatter: this.legendFormatter,
|
|
||||||
highlightCallback: this.highlightCallback,
|
|
||||||
unhighlightCallback: this.unhighlightCallback,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -40,6 +42,53 @@ class DygraphLegend extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highlightCallback = e => {
|
||||||
|
console.log('callback firing: ', this, e, e.target)
|
||||||
|
this.setState({pageX: e.pageX})
|
||||||
|
this.props.onShow(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
legendFormatter = legend => {
|
||||||
|
if (!legend.x) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const {legend: prevLegend} = this.state
|
||||||
|
const highlighted = legend.series.find(s => s.isHighlighted)
|
||||||
|
const prevHighlighted = prevLegend.series.find(s => s.isHighlighted)
|
||||||
|
|
||||||
|
const yVal = highlighted && highlighted.y
|
||||||
|
const prevY = prevHighlighted && prevHighlighted.y
|
||||||
|
|
||||||
|
if (legend.x === prevLegend.x && yVal === prevY) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
this.legend = this.setState({legend})
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
unhighlightCallback = e => {
|
||||||
|
const {
|
||||||
|
top,
|
||||||
|
bottom,
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
} = this.legendNodeRef.getBoundingClientRect()
|
||||||
|
|
||||||
|
const mouseY = e.clientY
|
||||||
|
const mouseX = e.clientX
|
||||||
|
|
||||||
|
const mouseBuffer = 5
|
||||||
|
const mouseInLegendY = mouseY <= bottom && mouseY >= top - mouseBuffer
|
||||||
|
const mouseInLegendX = mouseX <= right && mouseX >= left
|
||||||
|
const isMouseHoveringLegend = mouseInLegendY && mouseInLegendX
|
||||||
|
|
||||||
|
if (!isMouseHoveringLegend) {
|
||||||
|
this.props.onHide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleToggleFilter = () => {
|
handleToggleFilter = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isFilterVisible: !this.state.isFilterVisible,
|
isFilterVisible: !this.state.isFilterVisible,
|
||||||
|
@ -71,52 +120,6 @@ class DygraphLegend extends Component {
|
||||||
this.setState({sortType, isAscending: !this.state.isAscending})
|
this.setState({sortType, isAscending: !this.state.isAscending})
|
||||||
}
|
}
|
||||||
|
|
||||||
unhighlightCallback = e => {
|
|
||||||
const {
|
|
||||||
top,
|
|
||||||
bottom,
|
|
||||||
left,
|
|
||||||
right,
|
|
||||||
} = this.legendNodeRef.getBoundingClientRect()
|
|
||||||
|
|
||||||
const mouseY = e.clientY
|
|
||||||
const mouseX = e.clientX
|
|
||||||
|
|
||||||
const mouseBuffer = 5
|
|
||||||
const mouseInLegendY = mouseY <= bottom && mouseY >= top - mouseBuffer
|
|
||||||
const mouseInLegendX = mouseX <= right && mouseX >= left
|
|
||||||
const isMouseHoveringLegend = mouseInLegendY && mouseInLegendX
|
|
||||||
|
|
||||||
if (!isMouseHoveringLegend) {
|
|
||||||
this.props.onHide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
highlightCallback = e => {
|
|
||||||
this.setState({pageX: e.pageX})
|
|
||||||
this.props.onShow(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
legendFormatter = legend => {
|
|
||||||
if (!legend.x) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
const {legend: prevLegend} = this.state
|
|
||||||
const highlighted = legend.series.find(s => s.isHighlighted)
|
|
||||||
const prevHighlighted = prevLegend.series.find(s => s.isHighlighted)
|
|
||||||
|
|
||||||
const yVal = highlighted && highlighted.y
|
|
||||||
const prevY = prevHighlighted && prevHighlighted.y
|
|
||||||
|
|
||||||
if (legend.x === prevLegend.x && yVal === prevY) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
this.legend = this.setState({legend})
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {dygraph, onHide, isHidden} = this.props
|
const {dygraph, onHide, isHidden} = this.props
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,6 @@ class LineGraph extends Component {
|
||||||
super(props)
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps, nextState) {
|
|
||||||
return shallowCompare(this, nextProps, nextState)
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const {data, isInDataExplorer} = this.props
|
const {data, isInDataExplorer} = this.props
|
||||||
this._timeSeries = timeSeriesToDygraph(data, isInDataExplorer)
|
this._timeSeries = timeSeriesToDygraph(data, isInDataExplorer)
|
||||||
|
|
Loading…
Reference in New Issue