problem timeline: resize with container
This commit is contained in:
@@ -20,7 +20,6 @@ interface ProblemTimelineState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class ProblemTimeline extends PureComponent<ProblemTimelineProps, ProblemTimelineState> {
|
export default class ProblemTimeline extends PureComponent<ProblemTimelineProps, ProblemTimelineState> {
|
||||||
rootWidth: number;
|
|
||||||
rootRef: any;
|
rootRef: any;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -39,7 +38,7 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
|
|||||||
|
|
||||||
setRootRef = ref => {
|
setRootRef = ref => {
|
||||||
this.rootRef = ref;
|
this.rootRef = ref;
|
||||||
const width = this.rootRef && this.rootRef.clientWidth || 0;
|
const width = ref && ref.clientWidth || 0;
|
||||||
this.setState({ width });
|
this.setState({ width });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +50,13 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
|
|||||||
this.setState({ showEventInfo: false });
|
this.setState({ showEventInfo: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||||
|
if (this.rootRef && prevState.width !== this.rootRef.clientWidth) {
|
||||||
|
const width = this.rootRef.clientWidth;
|
||||||
|
this.setState({ width });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.rootRef) {
|
if (!this.rootRef) {
|
||||||
return <div className="event-timeline" ref={this.setRootRef} />;
|
return <div className="event-timeline" ref={this.setRootRef} />;
|
||||||
@@ -95,22 +101,6 @@ export default class ProblemTimeline extends PureComponent<ProblemTimelineProps,
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const eventsItems = events.map(event => {
|
|
||||||
const ts = Number(event.clock);
|
|
||||||
const posLeft = (ts - timeFrom) / range * width - EVENT_ITEM_SIZE / 2;
|
|
||||||
const eventColor = event.value === '1' ? this.props.problemColor : this.props.okColor;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TimelinePoint
|
|
||||||
key={event.eventid}
|
|
||||||
className="problem-event-item"
|
|
||||||
x={posLeft}
|
|
||||||
r={10}
|
|
||||||
color={eventColor}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="event-timeline" ref={this.setRootRef}>
|
<div className="event-timeline" ref={this.setRootRef}>
|
||||||
<TimelineInfoContainer className="timeline-info-container"
|
<TimelineInfoContainer className="timeline-info-container"
|
||||||
|
|||||||
@@ -338,7 +338,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.event-timeline {
|
.event-timeline {
|
||||||
display: flex;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 0.6rem;
|
margin-bottom: 0.6rem;
|
||||||
padding-top: 1.6rem;
|
padding-top: 1.6rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user