Skip to content

Commit c97ba16

Browse files
committed
Add Content and Data category with 10 projects (081-090)
1 parent f73be42 commit c97ba16

45 files changed

Lines changed: 5446 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Data Table in JavaScript (Free Project)
2+
3+
![Data Table JavaScript project preview](preview.png)
4+
5+
**Live demo:** https://mmrahmanbappi.github.io/vanilla-javascript-projects/11-content-data/081-data-table/demo.html
6+
**Details and code:** https://mmrahmanbappi.github.io/vanilla-javascript-projects/11-content-data/081-data-table/
7+
8+
Free data table in plain JavaScript. Click headers to sort, search every column, filter by department, choose page size, select rows and export the results to a CSV file.
9+
10+
## What is the Data Table?
11+
12+
A table of 64 team members. Click any header to sort up or down, search across every column with matches highlighted, and filter by department.
13+
14+
Choose how many rows per page, move between pages, tick rows or a whole page and export either the selection or all filtered rows as a CSV file.
15+
16+
## What it does
17+
18+
- Sortable headers with aria-sort
19+
- Search across all columns with highlights
20+
- Department filter and page size
21+
- Pagination with smart page numbers
22+
- Row selection and CSV export
23+
24+
## How it works
25+
26+
1. **Filter, sort, slice.** Every change runs the same pipeline: filter by search and department, sort by the chosen column, then take one page.
27+
2. **Sort like a human.** Intl.Collator with numeric set compares names in the right language order and sorts Item 2 before Item 10.
28+
3. **Export what you see.** CSV is built from the filtered rows, or only the ticked ones, then downloaded through a Blob link. A BOM makes Excel read accents correctly.
29+
30+
## The key JavaScript
31+
32+
```js
33+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
34+
const view = data
35+
.filter((r) => Object.values(r).join(" ").toLowerCase().includes(query))
36+
.sort((a, b) => collator.compare(a[key], b[key]) * dir)
37+
.slice((page - 1) * size, page * size);
38+
39+
const csv = [headers, ...rows.map((r) => keys.map((k) => r[k]))].map((r) => r.join(",")).join("\n");
40+
link.href = URL.createObjectURL(new Blob(["\ufeff" + csv], { type: "text/csv" }));
41+
```
42+
43+
## Browser support
44+
45+
Works in all modern browsers.
46+
47+
## How to use
48+
49+
1. Download `demo.html` from this folder.
50+
2. Serve the folder with `npx serve .` or `python -m http.server`, then open it in your browser.
51+
3. Change the text and colors, and upload it anywhere. One file, no build step.
52+
53+
## Questions
54+
55+
**How many rows can it handle?**
56+
57+
A few thousand rows sort and search instantly. For more, load pages from your server with the same sort and search values.
58+
59+
**Why add a BOM to the CSV?**
60+
61+
Excel needs it to read accented letters like ü correctly. Other apps ignore it.
62+
63+
**Is the sticky header accessible?**
64+
65+
Yes. The headers are real buttons inside th elements, and aria-sort tells screen readers the sort direction.
66+
67+
## License
68+
69+
MIT. Free for personal and commercial use.

‎11-content-data/081-data-table/demo.html‎

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.

‎11-content-data/081-data-table/index.html‎

Lines changed: 109 additions & 0 deletions
Large diffs are not rendered by default.
69.5 KB
Loading
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SVG Charts Kit in JavaScript (Free Project)
2+
3+
![SVG Charts Kit JavaScript project preview](preview.png)
4+
5+
**Live demo:** https://mmrahmanbappi.github.io/vanilla-javascript-projects/11-content-data/082-svg-charts-kit/demo.html
6+
**Details and code:** https://mmrahmanbappi.github.io/vanilla-javascript-projects/11-content-data/082-svg-charts-kit/
7+
8+
Free SVG charts in plain JavaScript. Line, bar and donut charts that scale to any width, with tooltips, keyboard focus, series toggles, animation and an accessible data table.
9+
10+
## What is the SVG Charts Kit?
11+
12+
A small dashboard with three hand-made SVG charts: monthly revenue as a line chart with two series, orders by weekday as bars, and sales by channel as a donut.
13+
14+
Hover or tab to any point for a tooltip, switch series on and off, shuffle the data to see the charts redraw with animation, and open the data as a plain table.
15+
16+
## What it does
17+
18+
- Line chart with area fill and two series
19+
- Bar chart with the best day highlighted
20+
- Donut chart with a total in the middle
21+
- Tooltips on hover and keyboard focus
22+
- Legend toggles, animation and data table
23+
24+
## How it works
25+
26+
1. **Scale data to pixels.** Each chart maps values to a viewBox with two tiny functions, x(i) and y(v). The viewBox makes the chart scale to any width.
27+
2. **Draw with paths.** The line is one path of M and L commands. Bars are rects. The donut uses circles with stroke-dasharray slices.
28+
3. **Tooltips for mouse and keyboard.** Every point is a focusable group with a label. Hover or focus shows the same tooltip, and screen readers read the label.
29+
30+
## The key JavaScript
31+
32+
```js
33+
const x = (i) => pad + i * (width - pad * 2) / (values.length - 1);
34+
const y = (v) => height - pad - (v / max) * (height - pad * 2);
35+
const d = values.map((v, i) => (i ? "L" : "M") + x(i) + " " + y(v)).join(" ");
36+
svg.innerHTML = `<path d="${d}" fill="none" stroke="#7C3AED" stroke-width="3"/>`;
37+
38+
// donut slice
39+
const len = (value / total) * 2 * Math.PI * r;
40+
circle.setAttribute("stroke-dasharray", `${len} ${circumference - len}`);
41+
```
42+
43+
## Browser support
44+
45+
Works in all modern browsers.
46+
47+
## How to use
48+
49+
1. Download `demo.html` from this folder.
50+
2. Serve the folder with `npx serve .` or `python -m http.server`, then open it in your browser.
51+
3. Change the text and colors, and upload it anywhere. One file, no build step.
52+
53+
## Questions
54+
55+
**When should I use a chart library instead?**
56+
57+
For zooming, huge datasets or many chart types. For a few simple charts, plain SVG is lighter and easier to style.
58+
59+
**Are SVG charts accessible?**
60+
61+
They can be. Here every point has a label, points are focusable and the data is also available as a table.
62+
63+
**How do I use my own data?**
64+
65+
Replace the generated arrays with numbers from your API and call the draw functions again.
66+
67+
## License
68+
69+
MIT. Free for personal and commercial use.

0 commit comments

Comments
 (0)