-
Notifications
You must be signed in to change notification settings - Fork 16
Timeline concept #17
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
captainbrosset
wants to merge
5
commits into
main
Choose a base branch
from
timeline
base: main
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
Timeline concept #17
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b7409f
Timeline concept
captainbrosset b07db98
Merge branch 'main' of github.com:web-platform-dx/web-features-explor…
captainbrosset 271aace
Merge branch 'main' of github.com:web-platform-dx/web-features-explor…
captainbrosset 42ac774
Merge branch 'main' of github.com:web-platform-dx/web-features-explor…
captainbrosset cbb01c5
Merge branch 'main' of github.com:web-platform-dx/web-features-explor…
captainbrosset 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,110 @@ | ||
<div class="feature-timeline" id="{{ feature.id }}-timeline"> | ||
</div> | ||
<script type="module" defer> | ||
const featureTimelineContainer = document.getElementById("{{ feature.id }}-timeline"); | ||
|
||
const featureData = [ | ||
{% if feature.status.baseline === "low" %} | ||
{ | ||
"event": "low", | ||
"date": new Date("{{ feature.status.baseline_low_date }}"), | ||
"datestring": "{{ feature.status.baseline_low_date }}" | ||
}, | ||
{% endif %} | ||
{% if feature.status.baseline === "high" %} | ||
{ | ||
"event": "high", | ||
"date": new Date("{{ feature.status.baseline_high_date }}"), | ||
"datestring": "{{ feature.status.baseline_high_date }}" | ||
}, | ||
{% endif %} | ||
{% for browser in browsers %} | ||
{% set version = feature.status.support[browser.id] %} | ||
{% if version %} | ||
{ | ||
"event": "{{ browser.id }}", | ||
"date": new Date("{{ browser.releases[version].release_date }}"), | ||
"datestring": "{{ browser.releases[version].release_date }}" | ||
}, | ||
{% endif %} | ||
{% endfor %} | ||
]; | ||
|
||
function getFeatureTimeline(timelineStart, timelineEnd) { | ||
let data = [...featureData]; | ||
|
||
data.push({ | ||
"event": "start", | ||
"date": new Date(timelineStart), | ||
"datestring": timelineStart | ||
}); | ||
|
||
data.push({ | ||
"event": "end", | ||
"date": new Date(timelineEnd), | ||
"datestring": timelineEnd | ||
}); | ||
|
||
// Add year start events between start and end. | ||
const startYear = new Date(timelineStart).getFullYear() + 1; | ||
const endYear = new Date(timelineEnd).getFullYear(); | ||
|
||
for (let year = startYear; year <= endYear; year++) { | ||
data.push({ | ||
"event": "year", | ||
"date": new Date(year, 0, 1), | ||
"datestring": year | ||
}); | ||
} | ||
|
||
data = data.sort((a, b) => a.date - b.date); | ||
|
||
// Calculate the total time span. | ||
const oneDay = 1000 * 60 * 60 * 24; | ||
const firstDate = data[0].date; | ||
const lastDate = data[data.length - 1].date; | ||
const totalDays = (lastDate - firstDate) / oneDay; | ||
|
||
// Calculate the position of each event. | ||
return data.map(event => { | ||
const days = (event.date - firstDate) / oneDay; | ||
event.position = days / totalDays * 100; | ||
return event; | ||
}); | ||
} | ||
|
||
function renderTimeline(timelineStart, timelineEnd) { | ||
getFeatureTimeline(timelineStart, timelineEnd).forEach(event => { | ||
if (event.event === "start" || event.event === "end") { | ||
return; | ||
} | ||
|
||
const div = document.createElement("div"); | ||
|
||
div.classList.add("event", event.event); | ||
if (event.event !== "year") { | ||
div.dataset.event = event.event; | ||
div.dataset.date = new Date(event.date).toLocaleDateString("en-US", { month: "long", year: "numeric" }); | ||
} else { | ||
div.dataset.date = event.datestring; | ||
} | ||
|
||
div.style.left = event.position + "%"; | ||
|
||
featureTimelineContainer.appendChild(div); | ||
}); | ||
} | ||
|
||
// Render the initial timeline with, by default, a time span of | ||
// 6 months before the first impl, and 6 months after the last event. | ||
const [start, ...rest] = featureData.sort((a, b) => a.date - b.date); | ||
const end = rest.splice(-1)[0]; | ||
|
||
const startDate = new Date(start.date); | ||
startDate.setMonth(startDate.getMonth() - 6); | ||
|
||
const endDate = new Date(end.date); | ||
endDate.setMonth(endDate.getMonth() + 6); | ||
|
||
renderTimeline(startDate.toISOString().split("T")[0], endDate.toISOString().split("T")[0]); | ||
</script> |
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
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.
This will need fixing with the recent change where certain versions can contain the
≤
character. For example thesub-sup
feature.Uh oh!
There was an error while loading. Please reload this page.
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.
See acafc29.