diff --git a/CHANGELOG.md b/CHANGELOG.md index e9703c3..7c4dceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +* [Fix blank page when resizing gantt to minimum width](https://github.com/flower-platform/react-timeline-10000/pull/116) + * [ContextMenu: scrollable and always visible](https://github.com/flower-platform/react-timeline-10000/pull/114/changes) ## v2.15.0 diff --git a/src/components/BackgroundLayer.js b/src/components/BackgroundLayer.js index 472a3e3..1d16760 100644 --- a/src/components/BackgroundLayer.js +++ b/src/components/BackgroundLayer.js @@ -222,7 +222,7 @@ export class BackgroundLayer extends React.Component { */ calculateHorizontalPosition(start, end) { const intervalMillis = this.props.endDateTimeline.diff(this.props.startDateTimeline, 'milliseconds'); - const pixelsPerMillis = (this.props.width - this.props.leftOffset) / intervalMillis; + const pixelsPerMillis = intervalMillis === 0 ? 0 : (this.props.width - this.props.leftOffset) / intervalMillis; const startAsMoment = convertDateToMoment(start); const endAsMoment = convertDateToMoment(end); if (endAsMoment.isBefore(this.props.startDateTimeline) || startAsMoment.isAfter(this.props.endDateTimeline)) { diff --git a/src/components/Scrollbar.tsx b/src/components/Scrollbar.tsx index 8948fe6..74a4d60 100644 --- a/src/components/Scrollbar.tsx +++ b/src/components/Scrollbar.tsx @@ -168,9 +168,9 @@ export class Scrollbar extends React.Component 1s - if (durationMilliSecs <= 1000) this.setState({resolution: {top: 'second', bottom: 'millisecond'}}); + if (durationMilliSecs <= 1000) this.setResolutionIfNeeded({top: 'second', bottom: 'millisecond'}); // 1s -> 2m - else if (durationMilliSecs <= 60 * 2 * 1000) this.setState({resolution: {top: 'minute', bottom: 'second'}}); + else if (durationMilliSecs <= 60 * 2 * 1000) this.setResolutionIfNeeded({top: 'minute', bottom: 'second'}); // 2m -> 2h - else if (durationMilliSecs <= 60 * 60 * 2 * 1000) this.setState({resolution: {top: 'hour', bottom: 'minute'}}); + else if (durationMilliSecs <= 60 * 60 * 2 * 1000) this.setResolutionIfNeeded({top: 'hour', bottom: 'minute'}); // 2h -> 3d - else if (durationMilliSecs <= 24 * 60 * 60 * 3 * 1000) this.setState({resolution: {top: 'day', bottom: 'hour'}}); + else if (durationMilliSecs <= 24 * 60 * 60 * 3 * 1000) this.setResolutionIfNeeded({top: 'day', bottom: 'hour'}); // 1d -> 30d - else if (durationMilliSecs <= 30 * 24 * 60 * 60 * 1000) this.setState({resolution: {top: 'month', bottom: 'day'}}); + else if (durationMilliSecs <= 30 * 24 * 60 * 60 * 1000) this.setResolutionIfNeeded({top: 'month', bottom: 'day'}); //30d -> 1y - else if (durationMilliSecs <= 365 * 24 * 60 * 60 * 1000) - this.setState({resolution: {top: 'year', bottom: 'month'}}); + else if (durationMilliSecs <= 365 * 24 * 60 * 60 * 1000) this.setResolutionIfNeeded({top: 'year', bottom: 'month'}); // 1y -> - else this.setState({resolution: {top: 'year', bottom: 'year'}}); + else this.setResolutionIfNeeded({top: 'year', bottom: 'year'}); } /** diff --git a/src/timeline.js b/src/timeline.js index 6d6fa85..1bca37f 100644 --- a/src/timeline.js +++ b/src/timeline.js @@ -2274,7 +2274,9 @@ export default class Timeline extends React.Component { * @param { object } verticalGridLines */ setVerticalGridLines(verticalGridLines) { - this.setState({verticalGridLines}); + if (!_.isEqual(this.state.verticalGridLines, verticalGridLines)) { + this.setState({verticalGridLines}); + } } handleScrollTable = scrollPos => { diff --git a/src/utils/timeUtils.js b/src/utils/timeUtils.js index 83dff6b..aa4b94c 100644 --- a/src/utils/timeUtils.js +++ b/src/utils/timeUtils.js @@ -27,7 +27,7 @@ export function timeSnap(time, snapMilliseconds) { */ export function pixelsPerMillisecond(vis_start, vis_end, total_width) { const start_end_ms = vis_end.diff(vis_start, 'milliseconds'); - return total_width / start_end_ms; + return start_end_ms === 0 ? 0 : total_width / start_end_ms; } /** @@ -53,7 +53,8 @@ export function getSnapPixelFromDelta(delta, vis_start, vis_end, total_width, sn * @returns {moment} Moment object */ export function getTimeAtPixel(pixel_location, vis_start, vis_end, total_width, snapMilliseconds = 0) { - let min_offset = pixel_location / pixelsPerMillisecond(vis_start, vis_end, total_width); + let pixels_per_ms = pixelsPerMillisecond(vis_start, vis_end, total_width); + let min_offset = pixels_per_ms == 0 ? 0 : pixel_location / pixels_per_ms; let timeAtPix = vis_start.clone().add(min_offset, 'milliseconds'); if (snapMilliseconds !== 0) timeAtPix = timeSnap(timeAtPix, snapMilliseconds); return timeAtPix; @@ -84,7 +85,7 @@ export function getDurationFromPixels(pixels, vis_start, vis_end, total_width) { const start_end_ms = vis_end.diff(vis_start, 'milliseconds'); if (start_end_ms === 0) return moment.duration(0, 'milliseconds'); const pixels_per_ms = total_width / start_end_ms; - let millis = pixels / pixels_per_ms; + let millis = pixels_per_ms === 0 ? 0 : pixels / pixels_per_ms; return moment.duration(millis, 'milliseconds'); }