problems timeline: bring highlighted items to front

This commit is contained in:
Alexander Zobnin
2018-12-16 12:01:26 +03:00
parent c115be1dee
commit 883bae85b1
2 changed files with 98 additions and 7 deletions

View File

@@ -43,7 +43,7 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
return <div className="event-timeline" ref={this.setRootRef} />; return <div className="event-timeline" ref={this.setRootRef} />;
} }
const { events, timeRange } = this.props; const { events, timeRange, problemColor, okColor } = this.props;
const { timeFrom, timeTo } = timeRange; const { timeFrom, timeTo } = timeRange;
const range = timeTo - timeFrom; const range = timeTo - timeFrom;
const width = this.state.width; const width = this.state.width;
@@ -100,6 +100,9 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
return ( return (
<div className="event-timeline" ref={this.setRootRef}> <div className="event-timeline" ref={this.setRootRef}>
<div className="timeline-info-container">
<span>Info:</span>
</div>
<svg className="event-timeline-canvas" viewBox={`0 0 ${width} 40`}> <svg className="event-timeline-canvas" viewBox={`0 0 ${width} 40`}>
<defs> <defs>
<filter id="dropShadow" x="-50%" y="-50%" width="200%" height="200%"> <filter id="dropShadow" x="-50%" y="-50%" width="200%" height="200%">
@@ -127,7 +130,13 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
{eventsIntervalItems} {eventsIntervalItems}
</g> </g>
<g className="timeline-points" transform={`translate(0, 6)`}> <g className="timeline-points" transform={`translate(0, 6)`}>
{eventsItems} <TimelinePoints
events={events}
timeRange={timeRange}
width={width}
okColor={okColor}
problemColor={problemColor}
/>
</g> </g>
</g> </g>
</svg> </svg>
@@ -142,30 +151,106 @@ function TimelineRegion(props) {
); );
} }
interface TimelinePointsProps {
events: ZBXEvent[];
timeRange: GFTimeRange;
width: number;
okColor: string;
problemColor: string;
}
interface TimelinePointsState {
order: number[];
}
class TimelinePoints extends PureComponent<TimelinePointsProps, TimelinePointsState> {
constructor(props) {
super(props);
this.state = { order: [] };
}
bringToFront = index => {
const length = this.props.events.length;
const order = this.props.events.map((v, i) => i);
order.splice(index, 1);
order.push(index);
this.setState({ order });
}
highlightPoint = index => () => {
this.bringToFront(index);
}
unHighlightPoint = index => () => {
const order = this.props.events.map((v, i) => i);
this.setState({ order });
}
render() {
const { events, timeRange, width, okColor, problemColor } = this.props;
const { timeFrom, timeTo } = timeRange;
const range = timeTo - timeFrom;
const eventsItems = events.map((event, index) => {
const ts = Number(event.clock);
const posLeft = (ts - timeFrom) / range * width - EVENT_ITEM_SIZE / 2;
const eventColor = event.value === '1' ? problemColor : okColor;
return (
<TimelinePoint
key={event.eventid}
className="problem-event-item"
x={posLeft}
r={10}
color={eventColor}
onHighlightPoint={this.highlightPoint(index)}
onUnHighlightPoint={this.unHighlightPoint(index)}
/>
);
});
if (this.state.order.length) {
return this.state.order.map(i => eventsItems[i]);
}
return eventsItems;
}
}
interface TimelinePointProps { interface TimelinePointProps {
x: number; x: number;
r: number; r: number;
color: string; color: string;
className?: string; className?: string;
onHighlightPoint?: () => void;
onUnHighlightPoint?: () => void;
} }
class TimelinePoint extends PureComponent<TimelinePointProps, any> { interface TimelinePointState {
highlighted?: boolean;
}
class TimelinePoint extends PureComponent<TimelinePointProps, TimelinePointState> {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { r: this.props.r }; this.state = { highlighted: false };
} }
handleMouseOver = () => { handleMouseOver = () => {
this.setState({ r: this.props.r * 1.2 }); if (this.props.onHighlightPoint) {
this.props.onHighlightPoint();
}
this.setState({ highlighted: true });
} }
handleMouseLeave = () => { handleMouseLeave = () => {
this.setState({ r: this.props.r }); if (this.props.onUnHighlightPoint) {
this.props.onUnHighlightPoint();
}
this.setState({ highlighted: false });
} }
render() { render() {
const { x, color, className } = this.props; const { x, color, className } = this.props;
const r = this.state.r; const r = this.state.highlighted ? this.props.r * 1.2 : this.props.r;
const cx = x + this.props.r; const cx = x + this.props.r;
const rInner = Math.floor(r * 0.6); const rInner = Math.floor(r * 0.6);
return ( return (

View File

@@ -343,6 +343,12 @@
margin: 1.6rem 0; margin: 1.6rem 0;
// margin-top: auto; // margin-top: auto;
.timeline-info-container {
position: absolute;
top: 0;
left: 0;
}
svg.event-timeline-canvas { svg.event-timeline-canvas {
height: 40px; height: 40px;