-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annotations): render line annotations via LineAnnotation spec (#126
- Loading branch information
1 parent
34d676a
commit 98ff170
Showing
20 changed files
with
2,773 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.elasticChartsAnnotation { | ||
@include euiFontSizeXS; | ||
pointer-events: none; | ||
position: absolute; | ||
z-index: $euiZLevel9; | ||
max-width: $euiSizeXL * 10; | ||
overflow: hidden; | ||
overflow-wrap: break-word; | ||
transition: opacity $euiAnimSpeedNormal; | ||
user-select: none; | ||
} | ||
|
||
.elasticChartsAnnotation--hidden, .elasticChartsAnnotation__tooltip--hidden { | ||
opacity: 0; | ||
} | ||
|
||
.elasticChartsAnnotation__tooltip { | ||
@include euiBottomShadow($color: $euiColorFullShade); | ||
@include euiFontSizeXS; | ||
pointer-events: none; | ||
position: absolute; | ||
z-index: $euiZLevel9; | ||
background-color: rgba(tintOrShade($euiColorFullShade, 25%, 80%), 0.9); | ||
color: $euiColorGhost; | ||
border-radius: $euiBorderRadius; | ||
max-width: $euiSizeXL * 10; | ||
overflow: hidden; | ||
overflow-wrap: break-word; | ||
transition: opacity $euiAnimSpeedNormal; | ||
user-select: none; | ||
} | ||
|
||
.elasticChartsAnnotation__header { | ||
margin: 0; | ||
background: rgba(shade($euiColorGhost, 20%), 0.9); | ||
color: $euiColorFullShade; | ||
padding: 0 8px; | ||
} | ||
|
||
.elasticChartsAnnotation__details { | ||
margin: 0; | ||
padding: 0 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import 'tooltip'; | ||
@import 'crosshair'; | ||
@import 'highlighter'; | ||
@import 'annotation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { inject, observer } from 'mobx-react'; | ||
import React from 'react'; | ||
import { AnnotationTypes } from '../lib/series/specs'; | ||
import { AnnotationId } from '../lib/utils/ids'; | ||
import { AnnotationLineProps } from '../state/annotation_utils'; | ||
import { ChartStore } from '../state/chart_state'; | ||
|
||
interface AnnotationTooltipProps { | ||
chartStore?: ChartStore; | ||
} | ||
|
||
class AnnotationTooltipComponent extends React.Component<AnnotationTooltipProps> { | ||
static displayName = 'AnnotationTooltip'; | ||
|
||
renderTooltip() { | ||
const annotationTooltipState = this.props.chartStore!.annotationTooltipState.get(); | ||
if (!annotationTooltipState || !annotationTooltipState.isVisible) { | ||
return <div className="elasticChartsAnnotation__tooltip elasticChartsAnnotation__tooltip--hidden" />; | ||
} | ||
|
||
const transform = annotationTooltipState.transform; | ||
const chartDimensions = this.props.chartStore!.chartDimensions; | ||
|
||
const style = { | ||
transform, | ||
top: chartDimensions.top, | ||
left: chartDimensions.left, | ||
}; | ||
|
||
return ( | ||
<div className="elasticChartsAnnotation__tooltip" style={{ ...style }}> | ||
<p className="elasticChartsAnnotation__header">{annotationTooltipState.header}</p> | ||
<div className="elasticChartsAnnotation__details"> | ||
{annotationTooltipState.details} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
renderAnnotationLineMarkers(annotationLines: AnnotationLineProps[], id: AnnotationId): JSX.Element[] { | ||
const { chartDimensions } = this.props.chartStore!; | ||
|
||
const markers: JSX.Element[] = []; | ||
|
||
annotationLines.forEach((line: AnnotationLineProps, index: number) => { | ||
if (!line.marker) { | ||
return; | ||
} | ||
|
||
const { transform, icon, color } = line.marker; | ||
|
||
const style = { | ||
color, | ||
transform, | ||
top: chartDimensions.top, | ||
left: chartDimensions.left, | ||
}; | ||
|
||
const markerElement = ( | ||
<div className="elasticChartsAnnotation" style={{ ...style }} key={`annotation-${id}-${index}`}> | ||
{icon} | ||
</div> | ||
); | ||
|
||
markers.push(markerElement); | ||
}); | ||
|
||
return markers; | ||
} | ||
|
||
renderAnnotationMarkers(): JSX.Element[] { | ||
const { annotationDimensions, annotationSpecs } = this.props.chartStore!; | ||
const markers: JSX.Element[] = []; | ||
|
||
annotationDimensions.forEach((annotationLines: AnnotationLineProps[], id: AnnotationId) => { | ||
const annotationSpec = annotationSpecs.get(id); | ||
if (!annotationSpec) { | ||
return; | ||
} | ||
|
||
switch (annotationSpec.annotationType) { | ||
case AnnotationTypes.Line: | ||
const lineMarkers = this.renderAnnotationLineMarkers(annotationLines, id); | ||
markers.push(...lineMarkers); | ||
break; | ||
} | ||
}); | ||
|
||
return markers; | ||
} | ||
|
||
render() { | ||
return ( | ||
<React.Fragment> | ||
{this.renderAnnotationMarkers()} | ||
{this.renderTooltip()} | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
export const AnnotationTooltip = inject('chartStore')(observer(AnnotationTooltipComponent)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { Group, Line } from 'react-konva'; | ||
import { AnnotationLineStyle } from '../../lib/themes/theme'; | ||
import { Dimensions } from '../../lib/utils/dimensions'; | ||
import { AnnotationLineProps } from '../../state/annotation_utils'; | ||
|
||
interface AnnotationProps { | ||
chartDimensions: Dimensions; | ||
debug: boolean; | ||
lines: AnnotationLineProps[]; | ||
lineStyle: AnnotationLineStyle; | ||
} | ||
|
||
export class Annotation extends React.PureComponent<AnnotationProps> { | ||
render() { | ||
return this.renderAnnotation(); | ||
} | ||
private renderAnnotationLine = (lineConfig: AnnotationLineProps, i: number) => { | ||
const { line } = this.props.lineStyle; | ||
const { position } = lineConfig; | ||
|
||
const lineProps = { | ||
points: position, | ||
...line, | ||
}; | ||
|
||
return <Line key={`tick-${i}`} {...lineProps} />; | ||
} | ||
|
||
private renderAnnotation = () => { | ||
const { chartDimensions, lines } = this.props; | ||
|
||
return ( | ||
<Group x={chartDimensions.left} y={chartDimensions.top}> | ||
{lines.map(this.renderAnnotationLine)} | ||
</Group> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.