-
Notifications
You must be signed in to change notification settings - Fork 0
#42121 blank page when gantt was resize to minimum #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master-flower-platform
Are you sure you want to change the base?
Changes from all commits
1f1d8ae
2c5b38f
78f20b4
8a8b72c
f4252aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,13 +35,19 @@ export default class Timebar extends React.Component { | |
| this.setState({topBarComponent, bottomBarComponent}); | ||
| } | ||
|
|
||
| setResolutionIfNeeded(resolution) { | ||
| if (this.state.resolution.top !== resolution.top || this.state.resolution.bottom !== resolution.bottom) { | ||
| this.setState({resolution}); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * On new props we check if a resolution is given, and if not we guess one | ||
| * @param {Object} nextProps Props coming in | ||
| */ | ||
| componentWillReceiveProps(nextProps) { | ||
| if (nextProps.top_resolution && nextProps.bottom_resolution) { | ||
| this.setState({resolution: {top: nextProps.top_resolution, bottom: nextProps.bottom_resolution}}); | ||
| this.setResolutionIfNeeded({top: nextProps.top_resolution, bottom: nextProps.bottom_resolution}); | ||
| } else { | ||
| this.guessResolution(nextProps.start, nextProps.end); | ||
| } | ||
|
|
@@ -59,7 +65,12 @@ export default class Timebar extends React.Component { | |
| ) { | ||
| const bottomBarComponent = this.getBottomBar(); | ||
| const topBarComponent = this.getTopBar(); | ||
|
Comment on lines
66
to
67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are conditie inainte de a fi apelat |
||
| this.setState({topBarComponent, bottomBarComponent}); | ||
| if ( | ||
| !_.isEqual(this.state.bottomBarComponent, bottomBarComponent) || | ||
| !_.isEqual(this.state.topBarComponent, topBarComponent) | ||
| ) { | ||
| this.setState({topBarComponent, bottomBarComponent}); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -76,20 +87,19 @@ export default class Timebar extends React.Component { | |
| } | ||
| const durationMilliSecs = end.diff(start); | ||
| /// 1ms -> 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'}); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While returning
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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'); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure defensive programming, it is safer to guard against
this.state.resolutionbeing undefined or null before accessing its properties. Using a fallback object prevents potential runtimeTypeErrors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nu e nevoie