Skip to content
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

feat: add prop to remove vertical margin between stacked items #889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __fixtures__/stateAndProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const props = {
keys: defaultKeys,
lineHeight: 30,
stackItems: true,
verticalMarginBetweenStackedItems: true,
itemHeightRatio: 0.75,
visibleTimeEnd,
visibleTimeStart,
Expand Down Expand Up @@ -57,4 +58,4 @@ export const stateResizeItemRight = {
resizingEdge: 'right',
resizeTime: items[0].end_time+timeOffset,
newGroupOrder: 0,
}
}
6 changes: 6 additions & 0 deletions __tests__/utils/calendar/stack-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('stackItems', () => {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
state.draggingItem,
state.resizingItem,
state.dragTime,
Expand All @@ -42,6 +43,7 @@ describe('stackItems', () => {
propsNoStack.lineHeight,
propsNoStack.itemHeightRatio,
propsNoStack.stackItems,
propsNoStack.verticalMarginBetweenStackedItems,
state.draggingItem,
state.resizingItem,
state.dragTime,
Expand All @@ -63,6 +65,7 @@ describe('stackItems', () => {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
stateMoveItem.draggingItem,
stateMoveItem.resizingItem,
stateMoveItem.dragTime,
Expand All @@ -84,6 +87,7 @@ describe('stackItems', () => {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
stateResizeItemLeft.draggingItem,
stateResizeItemLeft.resizingItem,
stateResizeItemLeft.dragTime,
Expand All @@ -105,6 +109,7 @@ describe('stackItems', () => {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
stateResizeItemRight.draggingItem,
stateResizeItemRight.resizingItem,
stateResizeItemRight.dragTime,
Expand All @@ -126,6 +131,7 @@ describe('stackItems', () => {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
state.draggingItem,
state.resizingItem,
state.dragTime,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-calendar-timeline",
"version": "0.28.0",
"version": "0.29.0",
"description": "react calendar timeline",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -135,7 +135,7 @@
"jest-watch-typeahead": "^0.3.1",
"jsdom": "^11.5.1",
"moment": "^2.11.1",
"node-sass": "^7.0.1",
"node-sass": "^8.0.0",
"prettier": "^1.10.2",
"prettier-eslint-cli": "^4.7.0",
"prop-types": "^15.6.2",
Expand All @@ -146,10 +146,10 @@
"react-testing-library": "^6.0.3",
"regenerator-runtime": "^0.13.2",
"rimraf": "^2.6.2",
"sass-loader": "^13.0.0",
"sass-loader": "^14.0.0",
"style-loader": "^3.3.1",
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.9.0"
}
}
}
6 changes: 6 additions & 0 deletions src/lib/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class ReactCalendarTimeline extends Component {
canSelect: PropTypes.bool,

stackItems: PropTypes.bool,
verticalMarginBetweenStackedItems: PropTypes.bool,

traditionalZoom: PropTypes.bool,

Expand Down Expand Up @@ -145,6 +146,7 @@ export default class ReactCalendarTimeline extends Component {
canSelect: true,

stackItems: false,
verticalMarginBetweenStackedItems: true,

traditionalZoom: false,

Expand Down Expand Up @@ -302,6 +304,7 @@ export default class ReactCalendarTimeline extends Component {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
this.state.draggingItem,
this.state.resizingItem,
this.state.dragTime,
Expand Down Expand Up @@ -379,6 +382,7 @@ export default class ReactCalendarTimeline extends Component {
nextProps.lineHeight,
nextProps.itemHeightRatio,
nextProps.stackItems,
nextProps.verticalMarginBetweenStackedItems,
prevState.draggingItem,
prevState.resizingItem,
prevState.dragTime,
Expand Down Expand Up @@ -450,6 +454,7 @@ export default class ReactCalendarTimeline extends Component {
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
this.state.draggingItem,
this.state.resizingItem,
this.state.dragTime,
Expand Down Expand Up @@ -987,6 +992,7 @@ export default class ReactCalendarTimeline extends Component {
this.props.lineHeight,
this.props.itemHeightRatio,
this.props.stackItems,
this.props.verticalMarginBetweenStackedItems,
this.state.draggingItem,
this.state.resizingItem,
this.state.dragTime,
Expand Down
39 changes: 26 additions & 13 deletions src/lib/utility/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export function groupStack(
group,
groupHeight,
groupTop,
itemIndex
itemIndex,
verticalMarginBetweenStackedItems
) {
// calculate non-overlapping positions
let curHeight = groupHeight
Expand All @@ -336,7 +337,11 @@ export function groupStack(

if (collidingItem != null) {
// There is a collision. Reposition the items above the colliding element
item.dimensions.top = collidingItem.dimensions.top + lineHeight
if (verticalMarginBetweenStackedItems) {
item.dimensions.top = collidingItem.dimensions.top + lineHeight
} else {
item.dimensions.top = collidingItem.dimensions.top + lineHeight - (lineHeight - collidingItem.dimensions.height)
}
curHeight = Math.max(
curHeight,
item.dimensions.top + item.dimensions.height + verticalMargin - groupTop
Expand Down Expand Up @@ -372,8 +377,9 @@ function sum(arr = []) {
* @param {*} groupOrders the groupOrders object
* @param {*} lineHeight
* @param {*} stackItems should items be stacked?
* @param {*} verticalMarginBetweenStackedItems should there be a margin between stacked items?
*/
export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems, verticalMarginBetweenStackedItems) {
var groupHeights = []
var groupTops = []

Expand All @@ -391,7 +397,8 @@ export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
itemsDimensions,
isGroupStacked,
lineHeight,
groupTop
groupTop,
verticalMarginBetweenStackedItems
)
// If group height is overridden, push new height
// Do this late as item position still needs to be calculated
Expand All @@ -402,7 +409,7 @@ export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
groupHeights.push(Math.max(groupHeight, lineHeight))
}
}

return {
height: sum(groupHeights),
groupHeights,
Expand All @@ -411,13 +418,14 @@ export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
}

/**
*
* @param {*} itemsDimensions
* @param {*} isGroupStacked
* @param {*} lineHeight
* @param {*} groupTop
*
* @param {*} itemsDimensions
* @param {*} isGroupStacked
* @param {*} lineHeight
* @param {*} groupTop
* @param {*} verticalMarginBetweenStackedItems
*/
export function stackGroup(itemsDimensions, isGroupStacked, lineHeight, groupTop) {
export function stackGroup(itemsDimensions, isGroupStacked, lineHeight, groupTop, verticalMarginBetweenStackedItems) {
var groupHeight = 0
var verticalMargin = 0
// Find positions for each item in group
Expand All @@ -430,7 +438,8 @@ export function stackGroup(itemsDimensions, isGroupStacked, lineHeight, groupTop
itemsDimensions,
groupHeight,
groupTop,
itemIndex
itemIndex,
verticalMarginBetweenStackedItems
)
} else {
r = groupNoStack(lineHeight, itemsDimensions[itemIndex], groupHeight, groupTop)
Expand All @@ -453,6 +462,7 @@ export function stackGroup(itemsDimensions, isGroupStacked, lineHeight, groupTop
* @param {number} lineHeight
* @param {number} itemHeightRatio
* @param {boolean} stackItems
* @param {boolean} verticalMarginBetweenStackedItems
* @param {*} draggingItem
* @param {*} resizingItem
* @param {number} dragTime
Expand All @@ -470,6 +480,7 @@ export function stackTimelineItems(
lineHeight,
itemHeightRatio,
stackItems,
verticalMarginBetweenStackedItems,
draggingItem,
resizingItem,
dragTime,
Expand Down Expand Up @@ -528,7 +539,8 @@ export function stackTimelineItems(
dimensionItems,
groupOrders,
lineHeight,
stackItems
stackItems,
verticalMarginBetweenStackedItems
)
return { dimensionItems, height, groupHeights, groupTops }
}
Expand Down Expand Up @@ -712,6 +724,7 @@ export function calculateScrollCanvas(
props.lineHeight,
props.itemHeightRatio,
props.stackItems,
props.verticalMarginBetweenStackedItems,
mergedState.draggingItem,
mergedState.resizingItem,
mergedState.dragTime,
Expand Down
Loading