-
Notifications
You must be signed in to change notification settings - Fork 684
Custom timescale #961
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
Open
valix25
wants to merge
10
commits into
namespace-ee:master
Choose a base branch
from
valix25:time-units
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Custom timescale #961
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d7712a5
Make a simple demo for further test use
822da38
Use directly number type instead of dateType
5a13abf
Added custom date type! Wooo! Not too bad.
7746cbb
Use number type instead of dayjs in showPeriod for simplicity
4280141
Customize demo example and formatting in Timeline.tsx
a9d0b0a
Add multiple custom types
964052b
Introduce custom made types from nsec to hour
7ea79bc
Add cursors to demo
722f0d8
Extend onZoom to return time dividers
f63d36c
Uncomment demo examples in App.tsx
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { faker } from '@faker-js/faker' | ||
| import randomColor from "randomcolor"; | ||
| import dayjs from 'dayjs'; | ||
|
|
||
| export default function (groupCount = 30, itemCount = 1000, daysInPast = 30) { | ||
| let randomSeed = Math.floor(Math.random() * 1000); | ||
| let groups = []; | ||
| for (let i = 0; i < groupCount; i++) { | ||
| groups.push({ | ||
| id: `${i + 1}`, | ||
| title: faker.name.firstName(), | ||
| rightTitle: faker.name.lastName(), | ||
| bgColor: randomColor({ luminosity: "light", seed: randomSeed + i }) | ||
| }); | ||
| } | ||
|
|
||
| let items = []; | ||
| for (let i = 0; i < itemCount; i++) { | ||
| const startDate = faker.date.recent({ days: daysInPast }).valueOf() + daysInPast * 0.3 * 86400 * 1000 | ||
| const startValue = Math.floor(dayjs(startDate).valueOf() / 10000000) * 10000000 | ||
| const endValue = dayjs(startDate + faker.number.int({ min: 2, max: 20 }) * 15 * 60 * 1000).valueOf() | ||
|
|
||
| items.push({ | ||
| id: i + "", | ||
| group: faker.number.int({ min: 1, max: groups.length }) + '', | ||
| title: faker.hacker.phrase(), | ||
| start: startValue, | ||
| end: endValue, | ||
| // canMove: startValue > new Date().getTime(), | ||
| // canResize: 'both', | ||
| className: dayjs(startDate).day() === 6 || dayjs(startDate).day() === 0 ? "item-weekend" : "", | ||
| itemProps: { | ||
| "data-tip": faker.hacker.phrase() | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| items = items.sort((a, b) => b - a); | ||
|
|
||
| return { groups, items }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| [ | ||
| { | ||
| "id": 10, | ||
| "title": "U.S. President" | ||
| }, | ||
| { | ||
| "id": 20, | ||
| "title": "Windows" | ||
| }, | ||
| { | ||
| "id": 21, | ||
| "title": "Android" | ||
| }, | ||
| { | ||
| "id": 22, | ||
| "title": "RPG Maker" | ||
| }, | ||
| { | ||
| "id": 40, | ||
| "title": "Pokemon game" | ||
| }, | ||
| { | ||
| "id": 30, | ||
| "title": "Nintendo console" | ||
| }, | ||
| { | ||
| "id": 31, | ||
| "title": "Nintendo handheld" | ||
| }, | ||
| { | ||
| "id": 32, | ||
| "title": "Sony console" | ||
| }, | ||
| { | ||
| "id": 33, | ||
| "title": "Sony handheld" | ||
| }, | ||
| { | ||
| "id": 34, | ||
| "title": "Microsoft console" | ||
| }, | ||
| { | ||
| "id": 35, | ||
| "title": "Sega console" | ||
| }, | ||
| { | ||
| "id": 41, | ||
| "title": "Mario game" | ||
| }, | ||
| { | ||
| "id": 42, | ||
| "title": "Zelda game" | ||
| }, | ||
| { | ||
| "id": 49, | ||
| "title": "GTA game" | ||
| }, | ||
| { | ||
| "id": 50, | ||
| "title": "Best Picture" | ||
| }, | ||
| { | ||
| "id": 51, | ||
| "title": "Star Wars movies" | ||
| }, | ||
| { | ||
| "id": 52, | ||
| "title": "Marvel movies (MCU)" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| import React from 'react' | ||
| import { Component } from 'react' | ||
| import dayjs from 'dayjs' | ||
| import randomColor from "randomcolor"; | ||
|
|
||
| import Timeline, { TimelineMarkers, TodayMarker, CustomMarker, CursorMarker } from '../../../src/index' | ||
|
|
||
| import generateFakeData from './generate-fake-data' | ||
|
|
||
| var keys = { | ||
| groupIdKey: "id", | ||
| groupTitleKey: "title", | ||
| groupRightTitleKey: "rightTitle", | ||
| itemIdKey: "id", | ||
| itemTitleKey: "title", | ||
| itemDivTitleKey: "title", | ||
| itemGroupKey: "group", | ||
| itemTimeStartKey: "start", | ||
| itemTimeEndKey: "end", | ||
| groupLabelKey: "title" | ||
| }; | ||
|
|
||
| function customData() { | ||
| let randomSeed = Math.floor(Math.random() * 1000); | ||
| let groups = [ | ||
| { id: 1, title: "G1", rightTitle: "Right Title 1", bgColor: randomColor({ luminosity: "light", seed: randomSeed + 0 }) }, | ||
| { id: 2, title: "G2", rightTitle: "Right Title 2", bgColor: randomColor({ luminosity: "light", seed: randomSeed + 1 }) }, | ||
| { id: 3, title: "G3", rightTitle: "Right Title 3", bgColor: randomColor({ luminosity: "light", seed: randomSeed + 2 }) }, | ||
| ] | ||
|
|
||
| let items = []; | ||
| items.push({ | ||
| id: "0", | ||
| group: "1", | ||
| title: "Hercules", | ||
| start: 0, | ||
| end: 16 * 10, | ||
| canChangeGroup: false, | ||
| className: "", | ||
| itemProps: { "data-tip": "GO" } | ||
| }); | ||
| items.push({ | ||
| id: "1", | ||
| group: "1", | ||
| title: "Ares", | ||
| start: 16 * 12, | ||
| end: 16 * 30, | ||
| canChangeGroup: false, | ||
| className: "", | ||
| itemProps: { "data-tip": "GO" } | ||
| }); | ||
| items.push({ | ||
| id: "2", | ||
| group: "2", | ||
| title: "Artemis", | ||
| start: 16 * 4, | ||
| end: 16 * 124, | ||
| canMove: true, | ||
| canChangeGroup: false, | ||
| className: "", | ||
| itemProps: { "data-tip": "GO" } | ||
| }); | ||
| items.push({ | ||
| id: "3", | ||
| group: "3", | ||
| title: "Athena", | ||
| start: 16 * 1, | ||
| end: 16 * 60, | ||
| canChangeGroup: false, | ||
| canResize: "both", | ||
| className: "", | ||
| itemProps: { "data-tip": "GO" } | ||
| }); | ||
|
|
||
| return { groups, items }; | ||
| } | ||
|
|
||
| export default class App extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| // const { groups, items } = generateFakeData(3, 6, 1); | ||
| const { groups, items } = customData(); | ||
| // const defaultTimeStart = dayjs(items[0].start_time).startOf('day').toDate().valueOf() | ||
| const defaultTimeStart = 1 | ||
| // const defaultTimeEnd = dayjs(items[0].end_time).startOf('day').add(1, 'day').toDate().valueOf() | ||
| const defaultTimeEnd = 10000 | ||
|
|
||
| this.state = { | ||
| groups, | ||
| items, | ||
| defaultTimeStart, | ||
| defaultTimeEnd | ||
| }; | ||
| } | ||
|
|
||
| handleItemClick = (itemId, _, time) => { | ||
| console.log('Clicked: ' + itemId, dayjs(time).format()) | ||
| } | ||
|
|
||
| handleItemSelect = (itemId, _, time) => { | ||
| console.log('Selected: ' + itemId, dayjs(time).format()) | ||
| } | ||
|
|
||
| handleItemMove = (itemId, dragTime, newGroupOrder) => { | ||
| const { items, groups } = this.state; | ||
|
|
||
| const group = groups[newGroupOrder]; | ||
|
|
||
| this.setState({ | ||
| items: items.map(item => | ||
| item.id === itemId | ||
| ? Object.assign({}, item, { | ||
| start: dragTime, | ||
| end: dragTime + (item.end - item.start), | ||
| group: group.id | ||
| }) | ||
| : item | ||
| ) | ||
| }); | ||
|
|
||
| console.log("Moved", itemId, dragTime, newGroupOrder); | ||
| }; | ||
|
|
||
| handleItemResize = (itemId, time, edge) => { | ||
| const { items } = this.state; | ||
|
|
||
| this.setState({ | ||
| items: items.map(item => | ||
| item.id === itemId | ||
| ? Object.assign({}, item, { | ||
| start: edge === "left" ? time : item.start, | ||
| end: edge === "left" ? item.end : time | ||
| }) | ||
| : item | ||
| ) | ||
| }); | ||
|
|
||
| console.log("Resized", itemId, time, edge); | ||
| }; | ||
|
|
||
| handleZoom = (timelineContext, unit, dividers) => { | ||
| console.log("Unit: ", unit, dividers[unit]); | ||
| } | ||
|
|
||
| render() { | ||
| const { groups, items, defaultTimeStart, defaultTimeEnd } = this.state; | ||
|
|
||
| return ( | ||
| <Timeline | ||
| groups={groups} | ||
| items={items} | ||
| keys={keys} | ||
| fullUpdate | ||
| itemTouchSendsClick={false} | ||
| minZoom={5} | ||
| maxZoom={8 * 2 * 50 * 25 * 50 * 25} | ||
| dragSnap={16} | ||
| stackItems | ||
| itemHeightRatio={0.75} | ||
| canMove={true} | ||
| canResize={"both"} | ||
| defaultTimeStart={defaultTimeStart} | ||
| defaultTimeEnd={defaultTimeEnd} | ||
| onItemMove={this.handleItemMove} | ||
| onItemResize={this.handleItemResize} | ||
| onItemClick={this.handleItemClick} | ||
| onItemSelect={this.handleItemSelect} | ||
| onTimeChange={(visibleStartTime, visibleEndTime, updateScrollCanvas) => { | ||
| if (visibleStartTime > defaultTimeStart) { | ||
| updateScrollCanvas(visibleStartTime, visibleEndTime); | ||
| } | ||
| } | ||
| } | ||
| onZoom={this.handleZoom} | ||
| > | ||
| <TimelineMarkers> | ||
| <CursorMarker /> | ||
| <CustomMarker date={16 * 60} /> | ||
| </TimelineMarkers> | ||
| </Timeline> | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does the rest not work?
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.
You mean the other demo examples? They do, I commented them temporarily as I found the development easier. I'll uncomment them.