Skip to content

Commit 44bed94

Browse files
authored
Merge pull request #676 from hckr/feature/unit-in-onZoom-and-onTimeChange-callbacks
2 parents db8fdb9 + 8e4063d commit 44bed94

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o
77

88
## Unreleased
99

10+
* Add unit argument to onZoom and onTimeChange callbacks
1011
* Add `className` prop to Timeline component to override `react-calendar-timeline` class #682
1112
* Fix injecting custom vertical line's class names for time periods longer than day
1213

@@ -50,11 +51,11 @@ Using controlled scroll and react-spring to trigger scrolling and create an anim
5051

5152
* add documentation for `onItemDeselect` #350 @ilaiwi
5253
* solve a bug where `onItemDeselect` is not triggered as expected for several item clicks #350 @ilaiwi
53-
* fix row height on browser scaling #615 @gaston-niglia
54+
* fix row height on browser scaling #615 @gaston-niglia
5455

5556
### Packages
5657

57-
update to `[email protected]` for newer versions of node.
58+
update to `[email protected]` for newer versions of node.
5859

5960
## 0.26.2
6061

@@ -86,7 +87,7 @@ you can as well solve the issue without upgrading by adding the following style
8687

8788
#### Breaking
8889

89-
* Removed `<InfoLabel />` in favour of allowing for custom component to be rendered on move or resize. Check out the demo in `demo/app/demo-custom-info-label` for an example on how to display your own custom info label or [this example](https://codesandbox.io/s/timeline-demo-info-label-neec9).
90+
* Removed `<InfoLabel />` in favour of allowing for custom component to be rendered on move or resize. Check out the demo in `demo/app/demo-custom-info-label` for an example on how to display your own custom info label or [this example](https://codesandbox.io/s/timeline-demo-info-label-neec9).
9091

9192

9293
## 0.25.4

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Called when an empty spot on the canvas was double clicked. Get the group ID and
312312

313313
Called when the canvas is clicked by the right button of the mouse. Note: If this property is set the default context menu doesn't appear
314314

315-
## onZoom(timelineContext)
315+
## onZoom(timelineContext, unit)
316316

317317
Called when the timeline is zoomed, either via mouse/pinch zoom or clicking header to change timeline units
318318

@@ -342,7 +342,7 @@ function (action, item, time, resizeEdge) {
342342
```
343343

344344

345-
## onTimeChange(visibleTimeStart, visibleTimeEnd, updateScrollCanvas)
345+
## onTimeChange(visibleTimeStart, visibleTimeEnd, updateScrollCanvas, unit)
346346

347347
A function that's called when the user tries to scroll. Call the passed `updateScrollCanvas(start, end)` with the updated visibleTimeStart and visibleTimeEnd (as unix timestamps in milliseconds) to change the scroll behavior, for example to limit scrolling.
348348

demo/app/demo-main/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export default class App extends Component {
135135
}
136136
}
137137

138+
handleZoom = (timelineContext, unit) => {
139+
console.log('Zoomed', timelineContext, unit)
140+
}
141+
138142
moveResizeValidator = (action, item, time) => {
139143
if (time < new Date().getTime()) {
140144
var newTime =
@@ -174,6 +178,7 @@ export default class App extends Component {
174178
onItemResize={this.handleItemResize}
175179
onItemDoubleClick={this.handleItemDoubleClick}
176180
onTimeChange={this.handleTimeChange}
181+
onZoom={this.handleZoom}
177182
moveResizeValidator={this.moveResizeValidator}
178183
>
179184
<TimelineMarkers>

src/lib/Timeline.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ export default class ReactCalendarTimeline extends Component {
266266
}
267267
}
268268

269+
getTimelineUnit = () => {
270+
const {
271+
width,
272+
visibleTimeStart,
273+
visibleTimeEnd
274+
} = this.state
275+
276+
const { timeSteps } = this.props
277+
278+
const zoom = visibleTimeEnd - visibleTimeStart
279+
const minUnit = getMinUnit(zoom, width, timeSteps)
280+
281+
return minUnit
282+
}
283+
269284
constructor(props) {
270285
super(props)
271286

@@ -421,7 +436,7 @@ export default class ReactCalendarTimeline extends Component {
421436

422437
// are we changing zoom? Report it!
423438
if (this.props.onZoom && newZoom !== oldZoom) {
424-
this.props.onZoom(this.getTimelineContext())
439+
this.props.onZoom(this.getTimelineContext(), this.getTimelineUnit())
425440
}
426441

427442
// The bounds have changed? Report it!
@@ -511,7 +526,8 @@ export default class ReactCalendarTimeline extends Component {
511526
this.props.onTimeChange(
512527
visibleTimeStart,
513528
visibleTimeStart + zoom,
514-
this.updateScrollCanvas
529+
this.updateScrollCanvas,
530+
this.getTimelineUnit()
515531
)
516532
}
517533
}
@@ -555,7 +571,8 @@ export default class ReactCalendarTimeline extends Component {
555571
this.props.onTimeChange(
556572
newVisibleTimeStart,
557573
newVisibleTimeStart + newZoom,
558-
this.updateScrollCanvas
574+
this.updateScrollCanvas,
575+
this.getTimelineUnit()
559576
)
560577
}
561578

@@ -572,7 +589,8 @@ export default class ReactCalendarTimeline extends Component {
572589
this.props.onTimeChange(
573590
visibleTimeStart,
574591
visibleTimeStart + zoom,
575-
this.updateScrollCanvas
592+
this.updateScrollCanvas,
593+
this.getTimelineUnit()
576594
)
577595
}
578596

0 commit comments

Comments
 (0)