Skip to content
Merged
Show file tree
Hide file tree
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
May 14, 2024
894e278
tooltips, chart color updates
May 14, 2024
75f1590
remove displays for troubleshooting
May 14, 2024
a3643f7
Merge branch 'main' into allison/hotel-example
May 14, 2024
f15215e
edits
May 22, 2024
6922b49
save edits
May 23, 2024
6843890
save changes
May 23, 2024
fcf9cf4
format date in line chart
May 23, 2024
d7b4c44
reorder seasons in faceted histogram
May 23, 2024
29a9bcd
move data prep to loader
May 24, 2024
34556c2
minor data loader updates
May 24, 2024
f0fbede
update readme and config file
May 24, 2024
778d6fd
Merge branch 'main' into allison/hotel-example
May 24, 2024
169845b
reorg code and add comments
May 24, 2024
3fd2a2a
Move table prep to Inputs.table options
May 24, 2024
57382e4
line chart tooltip
May 24, 2024
d678a45
tooltip and chart tweaks
May 24, 2024
6a412cc
spelling
May 24, 2024
4679321
Update examples/hotel-bookings/README.md
allisonhorst May 27, 2024
4df2462
Update examples/hotel-bookings/observablehq.config.js
allisonhorst May 27, 2024
e9f47a5
Merge branch 'main' into allison/hotel-example
May 27, 2024
69249fe
update DonutChart API
May 27, 2024
72af691
add to readme, config to match other examples, minor updates to dashb…
allisonhorst Jun 4, 2024
7e43e26
examples readme
allisonhorst Jun 4, 2024
5c5940c
readme
allisonhorst Jun 4, 2024
abe695f
add .webp assets
allisonhorst Jun 4, 2024
c5d8f8a
remove duplicate input-2d in readme
allisonhorst Jun 4, 2024
7d71bb1
updates donut color and config file
allisonhorst Jun 14, 2024
fada07d
Merge branch 'main' into allison/hotel-example
allisonhorst Jun 14, 2024
dfcd5c6
update line chart tip format
allisonhorst Jun 14, 2024
f72bbd0
testing text stroke in donuts
allisonhorst Jun 14, 2024
c15030d
update big number to html from Plot
allisonhorst Jun 14, 2024
1c7c841
clean up donutChart component
allisonhorst Jun 14, 2024
7014c82
replace bubble grid with faceted bar chart room type
allisonhorst Jun 14, 2024
9ae7954
Merge branch 'main' into allison/hotel-example
allisonhorst Jun 14, 2024
f436c4d
Merge branch 'main' into allison/hotel-example
allisonhorst Jun 14, 2024
79ec11a
Merge branch 'allison/hotel-example' of https://github.com/observable…
allisonhorst Jun 14, 2024
3ecd0f1
update webp images to new version
allisonhorst Jun 14, 2024
cac8e6a
Merge branch 'main' into allison/hotel-example
Fil Jun 18, 2024
803ffd9
remove cruft
Fil Jun 18, 2024
02361d7
no dot
Fil Jun 18, 2024
f077328
rename variables
Fil Jun 18, 2024
3d1a876
nicer
Fil Jun 18, 2024
4df64b7
variable color line (reflecting season)
Fil Jun 18, 2024
14b5407
force the complete facet domain
Fil Jun 18, 2024
63dd5dc
removes data loader, use static simplified file
allisonhorst Jun 18, 2024
b363bf4
Clean up tooltip labels
allisonhorst Jun 18, 2024
7000221
Update examples/hotel-bookings/src/components/donutChart.js
allisonhorst Jun 18, 2024
a4d202b
updated webp thumbnails
allisonhorst Jun 18, 2024
099d4de
updates README
allisonhorst Jun 18, 2024
21fa922
resize dark thumbnail
allisonhorst Jun 18, 2024
1cea26b
fix the color line when getting into empty bins.
Fil Jun 18, 2024
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
Binary file added docs/assets/hotel-bookings-dark.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/hotel-bookings.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

[Source](./eia) · This dashboard visualizes electricity generation and demand across the U.S. electricity grid. The included data loaders demonstrate how to retrieve live data from the U.S. Energy Information Administration (EIA) API, while the dashboard demonstrates how to produce interactive maps, bar charts, and time-series charts with Observable Plot. A range input allows the user to rewind time to any point in the previous 24 hours, and a table shows details.

### [`hotel-bookings`](https://observablehq.observablehq.cloud/framework-example-hotel-bookings) - Resort hotel bookings

<a href="https://observablehq.observablehq.cloud/framework-example-hotel-bookings/"><img src="../docs/assets/hotel-bookings.webp" alt="Resort hotel bookings" width="312" height="237"></a>

[Source](./hotel-bookings) · This dashboard visualizes hotel bookings by market segment for a Portuguese resort from 2015 to 2017. The dashboard demonstrates how to produce interactive charts with D3 and Observable Plot, either created as JavaScript components or directly within a markdown file. Donut charts, histograms, a bubble chart and a line chart reveal patterns in room bookings, prices, guest nationalities, and cancellations across different market segments and seasons.

### [`plot`](https://observablehq.observablehq.cloud/framework-example-plot/) - Observable Plot downloads

<a href="https://observablehq.observablehq.cloud/framework-example-plot/"><img src="../docs/assets/plot.webp" alt="Observable Plot downloads" width="312" height="237"></a>
Expand Down
4 changes: 4 additions & 0 deletions examples/hotel-bookings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/dist/
node_modules/
yarn-error.log
36 changes: 36 additions & 0 deletions examples/hotel-bookings/README.md
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
└── 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/).
3 changes: 3 additions & 0 deletions examples/hotel-bookings/observablehq.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
root: "src"
};
22 changes: 22 additions & 0 deletions examples/hotel-bookings/package.json
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"
}
}
11 changes: 11 additions & 0 deletions examples/hotel-bookings/src/components/bigNumber.js
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>`;
}
75 changes: 75 additions & 0 deletions examples/hotel-bookings/src/components/donutChart.js
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)

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();
}
Loading