Fix static legend state loop
parent
efc9fa9c7a
commit
fce58b66bc
|
@ -16,7 +16,7 @@ interface Props {
|
||||||
class Crosshair extends PureComponent<Props> {
|
class Crosshair extends PureComponent<Props> {
|
||||||
public render() {
|
public render() {
|
||||||
if (!this.isVisible) {
|
if (!this.isVisible) {
|
||||||
return null
|
return <div className="crosshair-container" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -26,7 +26,6 @@ class Crosshair extends PureComponent<Props> {
|
||||||
style={{
|
style={{
|
||||||
left: this.crosshairLeft,
|
left: this.crosshairLeft,
|
||||||
height: this.crosshairHeight,
|
height: this.crosshairHeight,
|
||||||
width: '1px',
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -47,10 +46,10 @@ class Crosshair extends PureComponent<Props> {
|
||||||
return isValidHoverTime && hoverTime !== 0 && _.isFinite(hoverTime)
|
return isValidHoverTime && hoverTime !== 0 && _.isFinite(hoverTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private get crosshairLeft(): number {
|
private get crosshairLeft(): string {
|
||||||
const {dygraph, hoverTime} = this.props
|
const {dygraph, hoverTime} = this.props
|
||||||
const cursorOffset = 16
|
const cursorOffset = 16
|
||||||
return dygraph.toDomXCoord(hoverTime) + cursorOffset
|
return `${dygraph.toDomXCoord(hoverTime) + cursorOffset}px`
|
||||||
}
|
}
|
||||||
|
|
||||||
private get crosshairHeight(): string {
|
private get crosshairHeight(): string {
|
||||||
|
|
|
@ -261,7 +261,7 @@ class Dygraph extends Component<Props, State> {
|
||||||
/>
|
/>
|
||||||
<Crosshair
|
<Crosshair
|
||||||
dygraph={this.dygraph}
|
dygraph={this.dygraph}
|
||||||
stasticLegendHeight={staticLegendHeight}
|
staticLegendHeight={staticLegendHeight}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -270,9 +270,8 @@ class Dygraph extends Component<Props, State> {
|
||||||
<StaticLegend
|
<StaticLegend
|
||||||
dygraphSeries={this.colorDygraphSeries}
|
dygraphSeries={this.colorDygraphSeries}
|
||||||
dygraph={this.dygraph}
|
dygraph={this.dygraph}
|
||||||
handleReceiveStaticLegendHeight={
|
height={staticLegendHeight}
|
||||||
this.handleReceiveStaticLegendHeight
|
onUpdateHeight={this.handleUpdateStaticLegendHeight}
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{this.nestedGraph &&
|
{this.nestedGraph &&
|
||||||
|
@ -456,7 +455,7 @@ class Dygraph extends Component<Props, State> {
|
||||||
return nanoDate.toISOString()
|
return nanoDate.toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleReceiveStaticLegendHeight = (staticLegendHeight: number) => {
|
private handleUpdateStaticLegendHeight = (staticLegendHeight: number) => {
|
||||||
this.setState({staticLegendHeight})
|
this.setState({staticLegendHeight})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,16 +29,21 @@ class StaticLegend extends Component {
|
||||||
|
|
||||||
componentDidMount = () => {
|
componentDidMount = () => {
|
||||||
const {height} = this.staticLegendRef.getBoundingClientRect()
|
const {height} = this.staticLegendRef.getBoundingClientRect()
|
||||||
this.props.handleReceiveStaticLegendHeight(height)
|
this.props.onUpdateHeight(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate = () => {
|
componentDidUpdate = prevProps => {
|
||||||
const {height} = this.staticLegendRef.getBoundingClientRect()
|
const {height} = this.staticLegendRef.getBoundingClientRect()
|
||||||
this.props.handleReceiveStaticLegendHeight(height)
|
|
||||||
|
if (prevProps.height === height) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.onUpdateHeight(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
componentWillUnmount = () => {
|
||||||
this.props.handleReceiveStaticLegendHeight(null)
|
this.props.onUpdateHeight(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick = i => e => {
|
handleClick = i => e => {
|
||||||
|
@ -96,12 +101,13 @@ class StaticLegend extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {shape, func} = PropTypes
|
const {shape, func, number} = PropTypes
|
||||||
|
|
||||||
StaticLegend.propTypes = {
|
StaticLegend.propTypes = {
|
||||||
dygraphSeries: shape({}),
|
dygraphSeries: shape({}),
|
||||||
dygraph: shape({}),
|
dygraph: shape({}),
|
||||||
handleReceiveStaticLegendHeight: func.isRequired,
|
height: number.isRequired,
|
||||||
|
onUpdateHeight: func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default StaticLegend
|
export default StaticLegend
|
||||||
|
|
|
@ -3,17 +3,12 @@
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%crosshair-styles {
|
|
||||||
position: absolute;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.crosshair {
|
.crosshair {
|
||||||
@extend %crosshair-styles;
|
|
||||||
top: 0;
|
top: 0;
|
||||||
height: calc(100% - 20px);
|
position: absolute;
|
||||||
width: 0.5px;
|
width: 1px;
|
||||||
background-color: $g14-chromium;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
|
background: linear-gradient(to bottom, fade-out($g14-chromium, 1) 0%,$g14-chromium 7%,$g14-chromium 93%,fade-out($g14-chromium, 1) 100%);
|
||||||
|
pointer-events: none;
|
||||||
|
min-height: 20px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue