-
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 4 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
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,53 @@ | ||
| # Hotel Bookings | ||
|
|
||
| This is an [Observable Framework](https://observablehq.com/framework) project. To start the local preview server, run: | ||
|
|
||
| ``` | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Then visit <http://localhost:3000> to preview your project. | ||
|
|
||
| For more, see <https://observablehq.com/framework/getting-started>. | ||
|
|
||
| ## Project structure | ||
|
|
||
| A typical Framework project looks like this: | ||
|
|
||
| ```ini | ||
| . | ||
| ├─ docs | ||
| │ ├─ components | ||
| │ │ └─ timeline.js # an importable module | ||
| │ ├─ data | ||
| │ │ ├─ launches.csv.js # a data loader | ||
| │ │ └─ events.json # a static data file | ||
| │ ├─ example-dashboard.md # a page | ||
| │ ├─ example-report.md # another page | ||
| │ └─ index.md # the home page | ||
| ├─ .gitignore | ||
| ├─ observablehq.config.js # the project config file | ||
| ├─ package.json | ||
| └─ README.md | ||
| ``` | ||
|
|
||
| **`docs`** - This is the “source root” — where your source files live. Pages go here. Each page is a Markdown file. Observable Framework uses [file-based routing](https://observablehq.com/framework/routing), which means that the name of the file controls where the page is served. You can create as many pages as you like. Use folders to organize your pages. | ||
|
|
||
| **`docs/index.md`** - This is the home page for your site. You can have as many additional pages as you’d like, but you should always have a home page, too. | ||
|
|
||
| **`docs/data`** - You can put [data loaders](https://observablehq.com/framework/loaders) or static data files anywhere in your source root, but we recommend putting them here. | ||
|
|
||
| **`docs/components`** - You can put shared [JavaScript modules](https://observablehq.com/framework/javascript/imports) anywhere in your source root, but we recommend putting them here. This helps you pull code out of Markdown files and into JavaScript modules, making it easier to reuse code across pages, write tests and run linters, and even share code with vanilla web applications. | ||
|
|
||
| **`observablehq.config.js`** - This is the [project configuration](https://observablehq.com/framework/config) file, such as the pages and sections in the sidebar navigation, and the project’s title. | ||
|
|
||
| ## Command reference | ||
|
|
||
| | Command | Description | | ||
| | ----------------- | -------------------------------------------------------- | | ||
| | `npm install` | Install or reinstall dependencies | | ||
| | `npm run dev` | Start local preview server | | ||
| | `npm run build` | Build your static site, generating `./dist` | | ||
| | `npm run deploy` | Deploy your project to Observable | | ||
| | `npm run clean` | Clear the local data loader cache | | ||
| | `npm run observable` | Run commands like `observable help` | | ||
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,28 @@ | ||
| // See https://observablehq.com/framework/config for documentation. | ||
| export default { | ||
| // The project’s title; used in the sidebar and webpage titles. | ||
| title: "Hotel Bookings", | ||
|
|
||
| // The pages and sections in the sidebar. If you don’t specify this option, | ||
| // all pages will be listed in alphabetical order. Listing pages explicitly | ||
| // lets you organize them into sections and have unlisted pages. | ||
| // pages: [ | ||
| // { | ||
| // name: "Examples", | ||
| // pages: [ | ||
| // {name: "Dashboard", path: "/example-dashboard"}, | ||
| // {name: "Report", path: "/example-report"} | ||
| // ] | ||
| // } | ||
| // ], | ||
|
|
||
| // Some additional configuration options and their defaults: | ||
| // theme: "default", // try "light", "dark", "slate", etc. | ||
| // header: "", // what to show in the header (HTML) | ||
| // footer: "Built with Observable.", // what to show in the footer (HTML) | ||
| toc: false, // whether to show the table of contents | ||
| // pager: true, // whether to show previous & next links in the footer | ||
| root: "src", // path to the source root for preview | ||
| // output: "dist", // path to the output root for build | ||
| // search: true, // activate search | ||
| }; |
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" | ||
| } | ||
| } |
allisonhorst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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,5 @@ | ||
| { | ||
| "projectId": "07692911c887d1df", | ||
| "projectSlug": "hotel-bookings", | ||
| "workspaceLogin": "sample-workspace" | ||
| } |
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 @@ | ||
| import * as Plot from "npm:@observablehq/plot"; | ||
|
|
||
| export function bigNumber(largeText, subText, borderColor, width) { | ||
| return Plot.plot({ | ||
| width, | ||
| height: 250, | ||
| marks: [ | ||
| Plot.text([largeText], { | ||
| frameAnchor: "middle", | ||
| fontSize: 100, | ||
| fontWeight: 700, | ||
| dy: -30 | ||
| }), | ||
| Plot.text([subText], { | ||
| frameAnchor: "middle", | ||
| fontSize: 60, | ||
| dy: 80, | ||
| opacity: 0.8 | ||
| }) | ||
| ] | ||
| }); | ||
| } |
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,78 @@ | ||
| // 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, colorScale) { | ||
allisonhorst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const height = width; | ||
| const radius = Math.min(width, height) / 2; | ||
|
|
||
| const arc = d3 | ||
| .arc() | ||
| .innerRadius(radius * 0.5) | ||
| .outerRadius(radius - 1); | ||
|
|
||
| const pie = d3 | ||
| .pie() | ||
| .padAngle(1 / radius) | ||
| .sort(null) | ||
| .value((d) => d.value); | ||
|
|
||
| const color = d3 | ||
| .scaleOrdinal() | ||
| .domain(data.map((d) => d.name)) | ||
| .range(colorScale); | ||
|
|
||
| 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) | ||
| .append("title") | ||
| .text((d) => `${d.data.name}: ${d.data.value.toLocaleString()}`); | ||
|
|
||
| svg | ||
| .append("g") | ||
| .attr("font-family", "sans-serif") | ||
| .attr("font-size", 11) | ||
| .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.5em") | ||
| .attr("font-weight", "bold") | ||
| .text((d) => d.data.name) | ||
| ) | ||
| .call((text) => | ||
| text | ||
| .filter((d) => d.endAngle - d.startAngle > 0.25) | ||
| .append("tspan") | ||
| .attr("x", 0) | ||
| .attr("y", "0.7em") | ||
| .attr("fill-opacity", 0.7) | ||
| .text((d) => d.data.value.toLocaleString("en-US")) | ||
| ); | ||
|
|
||
| svg | ||
| .append("text") | ||
| .attr("text-anchor", "middle") | ||
| .attr("font-family", "sans-serif") | ||
| .attr("font-size", 12) | ||
| .attr("font-weight", 700) | ||
| .text(centerText); | ||
|
|
||
| return svg.node(); | ||
| } | ||
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,27 @@ | ||
| import * as d3 from "npm:d3"; | ||
| import {FileAttachment} from "npm:@observablehq/stdlib"; | ||
|
|
||
| const hotels = await FileAttachment("../data/hotels.csv").csv({typed: true}); | ||
|
|
||
| export const hotelData = hotels.map((d) => ({ | ||
| ...d, | ||
| IsCanceled: d.IsCanceled == 0 ? "Keep" : "Cancel", | ||
| season: ["June", "July", "August"].includes(d.ArrivalDateMonth) | ||
| ? "Summer" | ||
| : ["September", "October", "November"].includes(d.ArrivalDateMonth) | ||
| ? "Fall" | ||
| : ["December", "January", "February"].includes(d.ArrivalDateMonth) | ||
| ? "Winter" | ||
| : "Spring", | ||
| Country: d.Country == "NULL" ? "Unknown" : d.Country, | ||
| Meal: d.Meal.trim(), | ||
| ReservedRoomType: d.ReservedRoomType.trim(), | ||
| AssignedRoomType: d.AssignedRoomType.trim(), | ||
allisonhorst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MarketSegment: | ||
| d.MarketSegment == "Online TA" | ||
| ? "Online travel agent" | ||
| : d.MarketSegment == "Offline TA/TO" | ||
| ? "Offline travel agent / tour operator" | ||
| : d.MarketSegment, | ||
| arrivalDate: d3.timeParse("%B %d, %Y")(d.ArrivalDateMonth + " " + d.ArrivalDateDayOfMonth + ", " + d.ArrivalDateYear) | ||
| })); | ||
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.