Skip to content
Merged
Show file tree
Hide file tree
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
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
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
53 changes: 53 additions & 0 deletions examples/hotel-bookings/README.md
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` |
28 changes: 28 additions & 0 deletions examples/hotel-bookings/observablehq.config.js
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
};
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"
}
}
5 changes: 5 additions & 0 deletions examples/hotel-bookings/src/.observablehq/deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projectId": "07692911c887d1df",
"projectSlug": "hotel-bookings",
"workspaceLogin": "sample-workspace"
}
22 changes: 22 additions & 0 deletions examples/hotel-bookings/src/components/bigNumber.js
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
})
]
});
}
78 changes: 78 additions & 0 deletions examples/hotel-bookings/src/components/donutChart.js
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)

import * as d3 from "npm:d3";

export function donutChart(data, centerText, width, colorScale) {
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();
}
27 changes: 27 additions & 0 deletions examples/hotel-bookings/src/components/hotelData.js
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(),
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)
}));
Loading