-
Notifications
You must be signed in to change notification settings - Fork 177
Hotel bookings dashboard example #1337
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
Merged
Merged
Changes from 47 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
d642e6f
update chart colors, add bubble, move reusables to components
894e278
tooltips, chart color updates
75f1590
remove displays for troubleshooting
a3643f7
Merge branch 'main' into allison/hotel-example
f15215e
edits
6922b49
save edits
6843890
save changes
fcf9cf4
format date in line chart
d7b4c44
reorder seasons in faceted histogram
29a9bcd
move data prep to loader
34556c2
minor data loader updates
f0fbede
update readme and config file
778d6fd
Merge branch 'main' into allison/hotel-example
169845b
reorg code and add comments
3fd2a2a
Move table prep to Inputs.table options
57382e4
line chart tooltip
d678a45
tooltip and chart tweaks
6a412cc
spelling
4679321
Update examples/hotel-bookings/README.md
allisonhorst 4df2462
Update examples/hotel-bookings/observablehq.config.js
allisonhorst e9f47a5
Merge branch 'main' into allison/hotel-example
69249fe
update DonutChart API
72af691
add to readme, config to match other examples, minor updates to dashb…
allisonhorst 7e43e26
examples readme
allisonhorst 5c5940c
readme
allisonhorst abe695f
add .webp assets
allisonhorst c5d8f8a
remove duplicate input-2d in readme
allisonhorst 7d71bb1
updates donut color and config file
allisonhorst fada07d
Merge branch 'main' into allison/hotel-example
allisonhorst dfcd5c6
update line chart tip format
allisonhorst f72bbd0
testing text stroke in donuts
allisonhorst c15030d
update big number to html from Plot
allisonhorst 1c7c841
clean up donutChart component
allisonhorst 7014c82
replace bubble grid with faceted bar chart room type
allisonhorst 9ae7954
Merge branch 'main' into allison/hotel-example
allisonhorst f436c4d
Merge branch 'main' into allison/hotel-example
allisonhorst 79ec11a
Merge branch 'allison/hotel-example' of https://github.com/observable…
allisonhorst 3ecd0f1
update webp images to new version
allisonhorst cac8e6a
Merge branch 'main' into allison/hotel-example
Fil 803ffd9
remove cruft
Fil 02361d7
no dot
Fil f077328
rename variables
Fil 3d1a876
nicer
Fil 4df64b7
variable color line (reflecting season)
Fil 14b5407
force the complete facet domain
Fil 63dd5dc
removes data loader, use static simplified file
allisonhorst b363bf4
Clean up tooltip labels
allisonhorst 7000221
Update examples/hotel-bookings/src/components/donutChart.js
allisonhorst a4d202b
updated webp thumbnails
allisonhorst 099d4de
updates README
allisonhorst 21fa922
resize dark thumbnail
allisonhorst 1cea26b
fix the color line when getting into empty bins.
Fil 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
| .DS_Store | ||
| /dist/ | ||
| node_modules/ | ||
| yarn-error.log |
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,36 @@ | ||
| [Framework examples →](../) | ||
|
|
||
| # Hotel bookings | ||
|
|
||
| View live: <https://observablehq.observablehq.cloud/framework-example-hotel-bookings/> | ||
|
|
||
| This dashboard explores reservation data for a resort in Portugal from Antonio _et al._ (2021), recorded between July 2015 and August 2017 to highlight differences in daily rates, visit seasons, guest nationality, and room type reserved for different booking types (_e.g._ corporate, direct, or online reservations). | ||
|
|
||
| **Data source:** Antonio et al (2021). Hotel booking demand datasets. Data in Brief (22): 41-49. https://doi.org/10.1016/j.dib.2018.11.126 | ||
|
|
||
| ## Implementation | ||
|
|
||
| ``` | ||
| . | ||
| ├── README.md | ||
| ├── observablehq.config.js | ||
| ├── package.json | ||
| └── src | ||
| ├── components | ||
| │ ├── bigNumber.js | ||
| │ └── donutChart.js | ||
| ├── data | ||
| │ ├── hotelData.csv.js | ||
| │ └── hotels.csv | ||
allisonhorst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| └── index.md | ||
| ``` | ||
|
|
||
| No dependencies other than Framework. | ||
|
|
||
| ### Data | ||
|
|
||
| Data in `hotels.csv` was downloaded directly from Antonio _et al._ (2021), then pre-processed in the `hotelData.csv.js` data loader to emit the static `hotelData.csv` file used in the dashboard. | ||
|
|
||
| ### Components | ||
|
|
||
| This example has two reusable components for building the visualizations: `bigNumber.js` and `donutChart.js`. The `bigNumber.js` component creates a simple big number box using [Observable Plot](https://observablehq.com/plot/). The `donutChart.js` component is made with [D3](https://d3js.org/). | ||
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,3 @@ | ||
| export default { | ||
| root: "src" | ||
| }; |
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,22 @@ | ||
| { | ||
| "type": "module", | ||
| "private": true, | ||
| "scripts": { | ||
| "clean": "rimraf src/.observablehq/cache", | ||
| "build": "rimraf dist && observable build", | ||
| "dev": "observable preview", | ||
| "deploy": "observable deploy", | ||
| "observable": "observable" | ||
| }, | ||
| "dependencies": { | ||
| "@observablehq/framework": "latest", | ||
| "d3-dsv": "^3.0.1", | ||
| "d3-time-format": "^4.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "rimraf": "^5.0.5" | ||
| }, | ||
| "engines": { | ||
| "node": ">=18" | ||
| } | ||
| } |
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,11 @@ | ||
| import {html} from "npm:htl"; | ||
|
|
||
| export function bigNumber(metric, dateArray, value, compare, width) { | ||
| return html` | ||
| <h2>${metric}</h2> | ||
| <div style="font-size: ${width / 250}rem"> | ||
| <h3><i>${dateArray[0]} to ${dateArray[1]}</i></h3> | ||
| <h1>${value}</h1> | ||
| <div>${compare}</div> | ||
| <div>`; | ||
| } |
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,75 @@ | ||
| // Code adapted (barely) from Mike Bostock's Donut chart notebook (https://observablehq.com/@d3/donut-chart/2) | ||
|
|
||
allisonhorst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import * as d3 from "npm:d3"; | ||
|
|
||
| export function DonutChart(data, {centerText, width, colorDomain, colorRange}) { | ||
| const height = width; | ||
| const radius = Math.min(width, height) / 2; | ||
| const arc = d3 | ||
| .arc() | ||
| .innerRadius(radius * 0.6) | ||
| .outerRadius(radius - 1); | ||
|
|
||
| const pie = d3 | ||
| .pie() | ||
| .padAngle(2 / radius) | ||
| .sort(null) | ||
| .value((d) => d.value); | ||
|
|
||
| const color = d3.scaleOrdinal().domain(colorDomain).range(colorRange); | ||
|
|
||
| const svg = d3 | ||
| .create("svg") | ||
| .attr("width", width) | ||
| .attr("height", height) | ||
| .attr("viewBox", [-width / 2, -height / 2, width, height]) | ||
| .attr("style", "max-width: 100%; height: auto;"); | ||
|
|
||
| svg | ||
| .append("g") | ||
| .selectAll() | ||
| .data(pie(data)) | ||
| .join("path") | ||
| .attr("fill", (d) => color(d.data.name)) | ||
| .attr("d", arc); | ||
|
|
||
| svg | ||
| .append("g") | ||
| .attr("font-family", "sans-serif") | ||
| .attr("font-size", 10) | ||
| .attr("text-anchor", "middle") | ||
| .selectAll() | ||
| .data(pie(data)) | ||
| .join("text") | ||
| .attr("transform", (d) => `translate(${arc.centroid(d)})`) | ||
| .call((text) => | ||
| text | ||
| .append("tspan") | ||
| .filter((d) => d.endAngle - d.startAngle > 0.1) | ||
| .attr("y", "-0.3em") | ||
| .attr("font-weight", "bold") | ||
| .attr("fill", "white") | ||
| .text((d) => d.data.name) | ||
| ) | ||
| .call((text) => | ||
| text | ||
| .filter((d) => d.endAngle - d.startAngle > 0.15) | ||
| .append("tspan") | ||
| .attr("x", 0) | ||
| .attr("y", "0.8em") | ||
| .attr("fill", "white") | ||
| .attr("fill-opacity", 1) | ||
| .text((d) => d.data.value.toLocaleString("en-US")) | ||
| ); | ||
|
|
||
| svg | ||
| .append("text") | ||
| .attr("text-anchor", "middle") | ||
| .attr("font-family", "sans-serif") | ||
| .attr("font-size", "0.9rem") | ||
| .attr("fill", "currentColor") | ||
| .attr("font-weight", 600) | ||
| .text(centerText); | ||
|
|
||
| return svg.node(); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.