diff --git a/ui/app/components/line-chart.js b/ui/app/components/line-chart.js index e7410683e..353c38bb8 100644 --- a/ui/app/components/line-chart.js +++ b/ui/app/components/line-chart.js @@ -290,15 +290,25 @@ export default class LineChart extends Component.extend(WindowResizable) { sortedAnnotations = sortedAnnotations.reverse(); } + let prevX = 0; + let prevHigh = false; return sortedAnnotations.map(annotation => { const x = xScale(annotation[xProp]); - const y = 0; // TODO: prevent overlap by staggering y-offset + if (prevX && !prevHigh && Math.abs(x - prevX) < 30) { + prevHigh = true; + } else if (prevHigh) { + prevHigh = false; + } + const y = prevHigh ? -15 : 0; const formattedX = this.xFormat(timeseries)(annotation[xProp]); + + prevX = x; return { annotation, style: `transform:translate(${x}px,${y}px)`, icon: iconFor[annotation.type], iconClass: iconClassFor[annotation.type], + staggerClass: prevHigh ? 'is-staggered' : '', label: `${annotation.type} event at ${formattedX}`, }; }); diff --git a/ui/app/styles/charts/chart-annotation.scss b/ui/app/styles/charts/chart-annotation.scss index 7283247b2..d5cb34df0 100644 --- a/ui/app/styles/charts/chart-annotation.scss +++ b/ui/app/styles/charts/chart-annotation.scss @@ -2,6 +2,10 @@ position: absolute; height: 100%; + &.is-staggered { + height: calc(100% + 15px); + } + .indicator { color: $grey; display: block; diff --git a/ui/app/styles/charts/line-chart.scss b/ui/app/styles/charts/line-chart.scss index cc40991e4..3b85e9262 100644 --- a/ui/app/styles/charts/line-chart.scss +++ b/ui/app/styles/charts/line-chart.scss @@ -4,7 +4,7 @@ position: relative; &.with-annotations { - margin-top: 1.5em; + margin-top: 2em; } & > svg { diff --git a/ui/app/templates/components/line-chart.hbs b/ui/app/templates/components/line-chart.hbs index d4b527e22..378f44b62 100644 --- a/ui/app/templates/components/line-chart.hbs +++ b/ui/app/templates/components/line-chart.hbs @@ -28,7 +28,7 @@
{{#each this.processedAnnotations as |annotation|}} -
+
+

{{this.activeAnnotation.info}}

+
Line Chart data with staggered annotations
+
+ {{#if (and this.data this.annotations)}} + {{/if}}
`, @@ -192,6 +204,13 @@ export let Annotations = () => { type: 'info', info: 'This is the end of the first period', }, + { + x: moment() + .add(96, 'd') + .toDate(), + type: 'info', + info: 'A close annotation for staggering purposes', + }, { x: moment() .add((90 / 4) * 3, 'd')