Skip to content

Commit b2dd160

Browse files
committed
initial poc
0 parents  commit b2dd160

File tree

11 files changed

+2125
-0
lines changed

11 files changed

+2125
-0
lines changed

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
# Dependencies
11+
node_modules
12+
dist
13+
dist-ssr
14+
*.local
15+
16+
# Editor directories and files
17+
.vscode/*
18+
!.vscode/extensions.json
19+
.idea
20+
.DS_Store
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?
26+
27+
# Build output
28+
build
29+
out
30+
31+
# Environment variables
32+
.env
33+
.env.local
34+
.env.development.local
35+
.env.test.local
36+
.env.production.local
37+
38+
# Testing
39+
coverage
40+
*.lcov
41+
42+
# Misc
43+
.cache
44+
.temp
45+
temp
46+
*.tmp

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Observable Plot Scatter with Brush Selection
2+
3+
A React + Vite + TypeScript app demonstrating an Observable Plot scatter plot with rectangular brush selection using a D3 brush overlay.
4+
5+
## Features
6+
7+
- 📊 Observable Plot for declarative data visualization
8+
- 🖱️ Interactive brush selection – drag to select data points
9+
- 🎨 Live visual feedback – selected points highlighted, non-selected dimmed
10+
- 📈 Real-time counter showing number of selected points
11+
12+
## Tech Stack
13+
14+
- Vite 5
15+
- React 18 + TypeScript 5
16+
- @observablehq/plot – declarative plotting library
17+
- d3-brush – rectangular selection interaction
18+
19+
## Getting Started
20+
21+
```sh
22+
pnpm install
23+
pnpm dev
24+
```
25+
26+
Open your browser and navigate to the local dev server (typically `http://localhost:5173`).
27+
28+
## Usage
29+
30+
- **Drag** within the chart area to create a rectangular selection
31+
- **Selected points** remain fully visible; non-selected points are dimmed
32+
- The **"Selected: N"** counter updates in real-time
33+
- **Click outside** the selection or brush over empty area to clear
34+
35+
## Implementation Notes
36+
37+
The key challenge was correctly identifying the main SVG when Plot wraps charts in a `<figure>` with multiple SVG elements (chart + legend swatches). The code selects the **largest SVG by area** to ensure the brush overlays the main plot.
38+
39+
The brush is appended inside the **same parent group** as the circle elements, ensuring coordinate alignment. The extent is computed from the marks group's bounding box.
40+
41+
## Project Structure
42+
43+
- `src/components/PlotScatterBrush.tsx` – Main chart component with brush logic
44+
- `src/App.tsx` – Page layout
45+
- `src/main.tsx` – React entry point
46+
- `src/styles.css` – Styles including `.hidden` class for dimming

index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Observable Plot Scatter (Brush)</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "observable-plot-scatter-poc",
3+
"private": true,
4+
"version": "0.0.1",
5+
"type": "module",
6+
"packageManager": "[email protected]",
7+
"scripts": {
8+
"dev": "vite",
9+
"build": "tsc -b && vite build",
10+
"preview": "vite preview --open",
11+
"typecheck": "tsc -b --pretty"
12+
},
13+
"dependencies": {
14+
"@observablehq/plot": "^0.6.16",
15+
"d3": "^7.9.0",
16+
"react": "^18.3.1",
17+
"react-dom": "^18.3.1"
18+
},
19+
"devDependencies": {
20+
"@types/d3": "^7.4.3",
21+
"@types/react": "^18.3.12",
22+
"@types/react-dom": "^18.3.1",
23+
"@vitejs/plugin-react": "^4.3.3",
24+
"typescript": "^5.6.2",
25+
"vite": "^5.4.9"
26+
}
27+
}

0 commit comments

Comments
 (0)