Skip to content

Commit 9d0d3fd

Browse files
authored
Merge pull request namespace-ee#463 from namespace-ee/develop
0.21.0
2 parents ff77391 + 696e5e6 commit 9d0d3fd

File tree

6 files changed

+209
-58
lines changed

6 files changed

+209
-58
lines changed

CHANGELOG.md

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

88
## Unreleased
99

10+
### 0.21.0
11+
12+
#### fixes
13+
14+
* fix item dimensions not being rendered on zoom in/out @ilaiwi + @acemac
15+
* correct `right_sidebar` to `rightTitle` in readme @maxlibin
16+
17+
#### breaking changes
18+
19+
* add `rct` to `.top-header` and `.bottom-header` to become `.rct-top-header` and `.rct-bottom-header` @Simek
20+
* upgrade dev dependance `[email protected]` @acemac
21+
1022
### 0.20.0
1123

1224
### improvements
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { calculateScrollCanvas } from 'lib/utility/calendar'
2+
import moment from 'moment'
3+
4+
const keys = {
5+
groupIdKey: 'id',
6+
groupTitleKey: 'title',
7+
groupRightTitleKey: 'rightTitle',
8+
itemIdKey: 'id',
9+
itemTitleKey: 'title',
10+
itemDivTitleKey: 'title',
11+
itemGroupKey: 'group',
12+
itemTimeStartKey: 'start',
13+
itemTimeEndKey: 'end'
14+
}
15+
const props = {
16+
keys,
17+
lineHeight: 30,
18+
stackItems: true,
19+
itemHeightRatio: 0.75
20+
}
21+
22+
const visibleTimeStart = moment('2018-10-26T00:00:00.000')
23+
const visibleTimeEnd = moment('2018-10-27T00:00:00.000')
24+
25+
const state = {
26+
draggingItem: undefined,
27+
dragTime: null,
28+
resizingItem: null,
29+
resizingEdge: null,
30+
resizeTime: null,
31+
newGroupOrder: null,
32+
canvasTimeStart: moment('2018-10-25T00:00:00.000').valueOf(),
33+
visibleTimeEnd: visibleTimeEnd.valueOf(),
34+
visibleTimeStart: visibleTimeStart.valueOf()
35+
}
36+
37+
const items = [
38+
{
39+
id: '0',
40+
group: '1',
41+
start: moment('2018-10-26T10:46:40.000').valueOf(),
42+
end: moment('2018-10-26T12:40:03.877').valueOf(),
43+
canMove: false,
44+
canResize: false
45+
},
46+
{
47+
id: '1',
48+
group: '1',
49+
start: moment('2018-10-26T19:06:40.000').valueOf(),
50+
end: moment('2018-10-26T23:14:35.919').valueOf(),
51+
canMove: true,
52+
canResize: 'both'
53+
},
54+
{
55+
id: '2',
56+
group: '1',
57+
start: moment('2018-10-27T08:00:00.000').valueOf(),
58+
end: moment('2018-10-27T13:39:57.548').valueOf(),
59+
canMove: false,
60+
canResize: false,
61+
className: ''
62+
}
63+
]
64+
65+
const groups = [{ id: '1' }, { id: '2' }]
66+
67+
describe('calculateScrollCanvas', () => {
68+
it('should calculate new scroll state', () => {
69+
const newStartTime = visibleTimeStart.clone().add(13, 'h')
70+
const newEndTime = visibleTimeEnd.clone().add(13, 'h')
71+
const result = calculateScrollCanvas(
72+
newStartTime.valueOf(),
73+
newEndTime.valueOf(),
74+
false,
75+
items,
76+
groups,
77+
props,
78+
state
79+
)
80+
expect(result).toHaveProperty('visibleTimeStart')
81+
expect(result).toHaveProperty('visibleTimeEnd')
82+
expect(result).toHaveProperty('dimensionItems')
83+
})
84+
it('should skip new calculation if new visible start and visible end in canvas', () => {
85+
const newStartTime = visibleTimeStart.clone().add(1, 'h')
86+
const newEndTime = visibleTimeEnd.clone().add(1, 'h')
87+
const result = calculateScrollCanvas(
88+
newStartTime.valueOf(),
89+
newEndTime.valueOf(),
90+
false,
91+
items,
92+
groups,
93+
props,
94+
state
95+
)
96+
expect(result).toHaveProperty('visibleTimeStart')
97+
expect(result).toHaveProperty('visibleTimeEnd')
98+
expect(result).not.toHaveProperty('dimensionItems')
99+
})
100+
it('should force new calculation', () => {
101+
const newStartTime = visibleTimeStart.clone().add(1, 'h')
102+
const newEndTime = visibleTimeEnd.clone().add(1, 'h')
103+
const result = calculateScrollCanvas(
104+
newStartTime.valueOf(),
105+
newEndTime.valueOf(),
106+
true,
107+
items,
108+
groups,
109+
props,
110+
state
111+
)
112+
expect(result).toHaveProperty('visibleTimeStart')
113+
expect(result).toHaveProperty('visibleTimeEnd')
114+
expect(result).toHaveProperty('dimensionItems')
115+
})
116+
it('should calculate new state if zoom changed ', () => {
117+
const newStartTime = visibleTimeStart.clone()
118+
const newEndTime = visibleTimeEnd.clone().add(1, 'h')
119+
const result = calculateScrollCanvas(
120+
newStartTime.valueOf(),
121+
newEndTime.valueOf(),
122+
false,
123+
items,
124+
groups,
125+
props,
126+
state
127+
)
128+
expect(result).toHaveProperty('visibleTimeStart')
129+
expect(result).toHaveProperty('visibleTimeEnd')
130+
expect(result).toHaveProperty('dimensionItems')
131+
})
132+
})

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-calendar-timeline",
3-
"version": "0.20.0",
3+
"version": "0.21.0",
44
"description": "react calendar timeline",
55
"main": "lib/index.js",
66
"scripts": {
@@ -11,7 +11,8 @@
1111
"lint:fix": "prettier-eslint --parser babylon --write \"src/**/*.js\"",
1212
"prepublish": "npm run build:lib",
1313
"start": "webpack-dev-server --hot --host 0.0.0.0 --display-modules",
14-
"test": "jest"
14+
"test": "jest",
15+
"test:watch": "jest --watch"
1516
},
1617
"files": [
1718
"lib",

src/lib/Timeline.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ $weekend: rgba(250, 246, 225, 0.5);
7676
overflow-x: hidden;
7777
z-index: 90;
7878

79-
.top-header,
80-
.bottom-header {
79+
.rct-top-header,
80+
.rct-bottom-header {
8181
position: relative;
8282
}
8383

@@ -126,7 +126,7 @@ $weekend: rgba(250, 246, 225, 0.5);
126126
}
127127
}
128128
}
129-
129+
130130
.rct-sidebar-header {
131131
margin: 0;
132132
color: $sidebar-color;

src/lib/layout/TimelineElementsHeader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ export default class TimelineElementsHeader extends Component {
232232
ref={this.props.scrollHeaderRef}
233233
>
234234
<div
235-
className="top-header"
235+
className="rct-top-header"
236236
style={{ height: twoHeaders ? headerLabelGroupHeight : 0, width: canvasWidth }}
237237
>
238238
{topHeaderLabels}
239239
</div>
240240
<div
241-
className="bottom-header"
241+
className="rct-bottom-header"
242242
style={{ height: headerLabelHeight, width: canvasWidth }}
243243
>
244244
{bottomHeaderLabels}

src/lib/utility/calendar.js

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function iterateTimes(start, end, unit, timeSteps, callback) {
6464

6565
if (timeSteps[unit] && timeSteps[unit] > 1) {
6666
let value = time.get(unit)
67-
time.set(unit, value - value % timeSteps[unit])
67+
time.set(unit, value - (value % timeSteps[unit]))
6868
}
6969

7070
while (time.valueOf() < end) {
@@ -258,7 +258,7 @@ export function stack(items, groupOrders, lineHeight, groups) {
258258
var groupedItems = getGroupedItems(items, groupOrders)
259259

260260
groupedItems.forEach(function(group) {
261-
var groupVal = groups[k++];
261+
var groupVal = groups[k++]
262262

263263
// calculate new, non-overlapping positions
264264
groupTops.push(totalHeight)
@@ -317,7 +317,9 @@ export function stack(items, groupOrders, lineHeight, groups) {
317317
}
318318

319319
export function nostack(items, groupOrders, lineHeight, groups) {
320-
var i, j=0, iMax
320+
var i,
321+
j = 0,
322+
iMax
321323

322324
var totalHeight = 0
323325

@@ -327,7 +329,7 @@ export function nostack(items, groupOrders, lineHeight, groups) {
327329
var groupedItems = getGroupedItems(items, groupOrders)
328330

329331
groupedItems.forEach(function(group) {
330-
var groupVal = groups[j++];
332+
var groupVal = groups[j++]
331333

332334
// calculate new, non-overlapping positions
333335
groupTops.push(totalHeight)
@@ -344,8 +346,8 @@ export function nostack(items, groupOrders, lineHeight, groups) {
344346
}
345347

346348
if (groupVal.height) {
347-
groupHeights.push(groupVal.height);
348-
totalHeight += groupVal.height;
349+
groupHeights.push(groupVal.height)
350+
totalHeight += groupVal.height
349351
} else {
350352
groupHeights.push(Math.max(groupHeight, lineHeight))
351353
totalHeight += Math.max(groupHeight, lineHeight)
@@ -361,24 +363,24 @@ export function nostack(items, groupOrders, lineHeight, groups) {
361363
/**
362364
* Stack the items that will be visible
363365
* within the canvas area
364-
* @param {item[]} items
365-
* @param {group[]} groups
366-
* @param {number} canvasTimeStart
367-
* @param {number} visibleTimeStart
368-
* @param {number} visibleTimeEnd
369-
* @param {number} width
370-
* @param {*} props
371-
* @param {*} state
366+
* @param {item[]} items
367+
* @param {group[]} groups
368+
* @param {number} canvasTimeStart
369+
* @param {number} visibleTimeStart
370+
* @param {number} visibleTimeEnd
371+
* @param {number} width
372+
* @param {*} props
373+
* @param {*} state
372374
*/
373375
export function stackItems(
374-
items,
375-
groups,
376-
canvasTimeStart,
377-
visibleTimeStart,
378-
visibleTimeEnd,
379-
width,
380-
props,
381-
state
376+
items,
377+
groups,
378+
canvasTimeStart,
379+
visibleTimeStart,
380+
visibleTimeEnd,
381+
width,
382+
props,
383+
state
382384
) {
383385
// if there are no groups return an empty array of dimensions
384386
if (groups.length === 0) {
@@ -416,13 +418,11 @@ state
416418
// Get the order of groups based on their id key
417419
const groupOrders = getGroupOrders(groups, keys)
418420

419-
420421
let dimensionItems = visibleItems.reduce((memo, item) => {
421422
const itemId = _get(item, keys.itemIdKey)
422423
const isDragging = itemId === draggingItem
423424
const isResizing = itemId === resizingItem
424425

425-
426426
let dimension = calculateDimensions({
427427
itemTimeStart: _get(item, keys.itemTimeStartKey),
428428
itemTimeEnd: _get(item, keys.itemTimeEndKey),
@@ -471,47 +471,53 @@ state
471471
* Get the the canvas area for a given visible time
472472
* Will shift the start/end of the canvas if the visible time
473473
* does not fit within the existing
474-
* @param {number} visibleTimeStart
475-
* @param {number} visibleTimeEnd
476-
* @param {boolean} forceUpdateDimensions
477-
* @param {*} items
478-
* @param {*} groups
479-
* @param {*} props
480-
* @param {*} state
474+
* @param {number} visibleTimeStart
475+
* @param {number} visibleTimeEnd
476+
* @param {boolean} forceUpdateDimensions
477+
* @param {*} items
478+
* @param {*} groups
479+
* @param {*} props
480+
* @param {*} state
481481
*/
482482
export function calculateScrollCanvas(
483-
visibleTimeStart,
484-
visibleTimeEnd,
485-
forceUpdateDimensions,
486-
items,
487-
groups,
488-
props,
489-
state) {
483+
visibleTimeStart,
484+
visibleTimeEnd,
485+
forceUpdateDimensions,
486+
items,
487+
groups,
488+
props,
489+
state
490+
) {
490491
const oldCanvasTimeStart = state.canvasTimeStart
491492
const oldZoom = state.visibleTimeEnd - state.visibleTimeStart
492-
493+
const newZoom = visibleTimeEnd - visibleTimeStart
493494
const newState = { visibleTimeStart, visibleTimeEnd }
494495

495496
// Check if the current canvas covers the new times
496497
const canKeepCanvas =
498+
newZoom === oldZoom &&
497499
visibleTimeStart >= oldCanvasTimeStart + oldZoom * 0.5 &&
498500
visibleTimeStart <= oldCanvasTimeStart + oldZoom * 1.5 &&
499501
visibleTimeEnd >= oldCanvasTimeStart + oldZoom * 1.5 &&
500502
visibleTimeEnd <= oldCanvasTimeStart + oldZoom * 2.5
501-
503+
502504
if (!canKeepCanvas || forceUpdateDimensions) {
503-
newState.canvasTimeStart = visibleTimeStart - (visibleTimeEnd - visibleTimeStart)
505+
newState.canvasTimeStart =
506+
visibleTimeStart - (visibleTimeEnd - visibleTimeStart)
504507
// The canvas cannot be kept, so calculate the new items position
505-
Object.assign(newState, stackItems(
506-
items,
507-
groups,
508-
newState.canvasTimeStart,
509-
visibleTimeStart,
510-
visibleTimeEnd,
511-
state.width,
512-
props,
513-
state
514-
))
508+
Object.assign(
509+
newState,
510+
stackItems(
511+
items,
512+
groups,
513+
newState.canvasTimeStart,
514+
visibleTimeStart,
515+
visibleTimeEnd,
516+
state.width,
517+
props,
518+
state
519+
)
520+
)
515521
}
516522
return newState
517523
}

0 commit comments

Comments
 (0)