diff --git a/src/panel-triggers/components/ProblemTimeline.tsx b/src/panel-triggers/components/ProblemTimeline.tsx index 9fd8c7f..2f1f1d1 100644 --- a/src/panel-triggers/components/ProblemTimeline.tsx +++ b/src/panel-triggers/components/ProblemTimeline.tsx @@ -4,13 +4,18 @@ import { GFTimeRange, ZBXEvent } from 'panel-triggers/types'; const DEFAULT_OK_COLOR = 'rgb(56, 189, 113)'; const DEFAULT_PROBLEM_COLOR = 'rgb(215, 0, 0)'; -const EVENT_ITEM_SIZE = 16; +const EVENT_POINT_SIZE = 20; +const INNER_POINT_SIZE = 0.6; +const HIGHLIGHTED_POINT_SIZE = 1.2; +const EVENT_REGION_HEIGHT = Math.round(EVENT_POINT_SIZE * 0.6); export interface ProblemTimelineProps { events: ZBXEvent[]; timeRange: GFTimeRange; okColor?: string; problemColor?: string; + eventRegionHeight?: number; + eventPointSize?: number; } interface ProblemTimelineState { @@ -25,6 +30,8 @@ export default class ProblemTimeline extends PureComponent; } - const { events, timeRange, problemColor, okColor } = this.props; - const width = this.state.width; + const { events, timeRange, eventPointSize, eventRegionHeight, problemColor, okColor } = this.props; + const boxWidth = this.state.width; + const boxHeight = eventPointSize * 2; + const width = boxWidth - eventPointSize; + const padding = Math.round(eventPointSize / 2); + const pointsYpos = Math.round(eventRegionHeight / 2); + const timelineYpos = Math.round(boxHeight / 2); return (
- + left={padding} + /> + @@ -103,21 +116,23 @@ export default class ProblemTimeline extends PureComponent - + - + { + static defaultProps = { + left: 0, + className: '', + show: false, + }; + render() { - const { show, className } = this.props; + const { show, className, left } = this.props; const event = this.props.event; let infoItems; if (event) { @@ -152,6 +174,7 @@ class TimelineInfoContainer extends PureComponent { } const containerStyle: React.CSSProperties = { opacity: show ? 1 : 0, + left, }; return (
@@ -165,26 +188,28 @@ interface TimelineRegionsProps { events: ZBXEvent[]; timeRange: GFTimeRange; width: number; + height: number; okColor: string; problemColor: string; } class TimelineRegions extends PureComponent { render() { - const { events, timeRange, width, okColor, problemColor } = this.props; + const { events, timeRange, width, height, okColor, problemColor } = this.props; const { timeFrom, timeTo } = timeRange; const range = timeTo - timeFrom; - let firstItem; + let firstItem: React.ReactNode; if (events.length) { const firstTs = events.length ? Number(events[0].clock) : timeTo; const duration = (firstTs - timeFrom) / range; + const regionWidth = Math.round(duration * width); const firstEventColor = events[0].value !== '1' ? problemColor : okColor; const firstEventAttributes = { x: 0, y: 0, - width: duration * width, - height: 12, + width: regionWidth, + height: height, fill: firstEventColor, }; firstItem = ( @@ -196,13 +221,14 @@ class TimelineRegions extends PureComponent { const ts = Number(event.clock); const nextTs = index < events.length - 1 ? Number(events[index + 1].clock) : timeTo; const duration = (nextTs - ts) / range; - const posLeft = (ts - timeFrom) / range * width; + const regionWidth = Math.round(duration * width); + const posLeft = Math.round((ts - timeFrom) / range * width); const eventColor = event.value === '1' ? problemColor : okColor; const attributes = { x: posLeft, y: 0, - width: duration * width, - height: 12, + width: regionWidth, + height: height, fill: eventColor, }; @@ -222,6 +248,7 @@ interface TimelinePointsProps { events: ZBXEvent[]; timeRange: GFTimeRange; width: number; + pointSize: number; okColor: string; problemColor: string; onPointHighlight?: (event: ZBXEvent) => void; @@ -264,12 +291,13 @@ class TimelinePoints extends PureComponent { const ts = Number(event.clock); - const posLeft = (ts - timeFrom) / range * width - EVENT_ITEM_SIZE / 2; + const posLeft = Math.round((ts - timeFrom) / range * width - pointR); const eventColor = event.value === '1' ? problemColor : okColor; return ( @@ -277,7 +305,7 @@ class TimelinePoints extends PureComponent