diff --git a/ui/src/shared/components/Annotation.js b/ui/src/shared/components/Annotation.js
index aec41fded9..26d6fbfb4a 100644
--- a/ui/src/shared/components/Annotation.js
+++ b/ui/src/shared/components/Annotation.js
@@ -9,8 +9,8 @@ import * as schema from 'shared/schemas'
const Annotation = ({
mode,
dygraph,
+ dWidth,
annotation,
- lastUpdated,
staticLegendHeight,
}) => (
@@ -19,7 +19,7 @@ const Annotation = ({
mode={mode}
dygraph={dygraph}
annotation={annotation}
- lastUpdated={lastUpdated}
+ dWidth={dWidth}
staticLegendHeight={staticLegendHeight}
/>
) : (
@@ -27,7 +27,7 @@ const Annotation = ({
mode={mode}
dygraph={dygraph}
annotation={annotation}
- lastUpdated={lastUpdated}
+ dWidth={dWidth}
staticLegendHeight={staticLegendHeight}
/>
)}
@@ -38,7 +38,7 @@ const {number, shape, string} = PropTypes
Annotation.propTypes = {
mode: string,
- lastUpdated: number,
+ dWidth: number,
annotation: schema.annotation.isRequired,
dygraph: shape({}).isRequired,
staticLegendHeight: number,
diff --git a/ui/src/shared/components/Annotations.js b/ui/src/shared/components/Annotations.js
index 5e105396dd..1e904365f6 100644
--- a/ui/src/shared/components/Annotations.js
+++ b/ui/src/shared/components/Annotations.js
@@ -19,25 +19,10 @@ import {
import {visibleAnnotations} from 'src/shared/annotations/helpers'
class Annotations extends Component {
- state = {
- lastUpdated: null,
- }
-
- componentDidMount() {
- this.props.dygraph.updateOptions({
- drawCallback: this.redraw,
- })
- }
-
- redraw = () => {
- // force a redraw of annotations
- this.setState({lastUpdated: Date.now()})
- }
-
render() {
- const {lastUpdated} = this.state
const {
mode,
+ dWidth,
dygraph,
isTempHovering,
handleUpdateAnnotation,
@@ -70,7 +55,7 @@ class Annotations extends Component {
mode={mode}
annotation={a}
dygraph={dygraph}
- lastUpdated={lastUpdated}
+ dWidth={dWidth}
staticLegendHeight={staticLegendHeight}
/>
))}
@@ -94,7 +79,8 @@ const {arrayOf, bool, func, number, shape, string} = PropTypes
Annotations.propTypes = {
annotations: arrayOf(schema.annotation),
- dygraph: shape({}),
+ dygraph: shape({}).isRequired,
+ dWidh: number.isRequired,
mode: string,
isTempHovering: bool,
handleUpdateAnnotation: func.isRequired,
diff --git a/ui/src/shared/components/Dygraph.js b/ui/src/shared/components/Dygraph.js
index 36405bd20e..ca68b3e8ec 100644
--- a/ui/src/shared/components/Dygraph.js
+++ b/ui/src/shared/components/Dygraph.js
@@ -288,6 +288,15 @@ class Dygraph extends Component {
this.setState({staticLegendHeight})
}
+ get areAnnotationsVisible() {
+ if (!this.dygraph) {
+ return false
+ }
+
+ const [start, end] = this.dygraph && this.dygraph.xAxisRange()
+ return !!start && !!end
+ }
+
render() {
const {isHidden, staticLegendHeight} = this.state
const {staticLegend, children, hoverTime} = this.props
@@ -305,10 +314,11 @@ class Dygraph extends Component {
return (
- {this.dygraph && (
+ {this.areAnnotationsVisible && (