@awesomephant/reactcake 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ - package-ecosystem: "npm"
8
+ directory: "/site"
9
+ schedule:
10
+ interval: "monthly"
11
+ - package-ecosystem: "npm"
12
+ directory: "/lib"
13
+ schedule:
14
+ interval: "monthly"
@@ -0,0 +1,40 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ permissions:
7
+ contents: read
8
+
9
+ jobs:
10
+ verify:
11
+ name: verify
12
+ runs-on: ubuntu-slim
13
+ steps:
14
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
15
+ with:
16
+ fetch-depth: 0
17
+ - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
18
+ - run: npm ci
19
+ - run: npm audit signatures
20
+ - run: npm run test
21
+
22
+ release:
23
+ name: release
24
+ runs-on: ubuntu-slim
25
+ needs: verify
26
+ permissions:
27
+ contents: write
28
+ issues: write
29
+ pull-requests: write
30
+ id-token: write
31
+ steps:
32
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
33
+ with:
34
+ fetch-depth: 0
35
+ - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
36
+ - run: npm ci
37
+ - run: npm audit signatures
38
+ - run: npx semantic-release
39
+ env:
40
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Max Köhler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Readme.md ADDED
@@ -0,0 +1,12 @@
1
+ # ReactCake
2
+
3
+ A headless chart framework for React inspired by [Layercake](https://layercake.graphics/). See [documentation](https://reactcake.maxkohler.com/) for usage and motivation.
4
+
5
+ [![release](https://github.com/awesomephant/reactcake/actions/workflows/release.yml/badge.svg)](https://github.com/awesomephant/reactcake/actions/workflows/release.yml)
6
+
7
+ ## Contributing
8
+
9
+ This project uses [esbuild](https://esbuild.github.io/) and Node's [built-in test runner](https://nodejs.org/api/test.html).
10
+
11
+ - `npm i` to install dependencies
12
+ - `npm run test` to run unit tests
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+
3
+ interface HtmlProps {
4
+ children?: ReactNode;
5
+ }
6
+
7
+ const Html = ({ children }: HtmlProps) => {
8
+ return (
9
+ <div
10
+ className="reactcake-html"
11
+ style={{
12
+ position: "absolute",
13
+ height: "100%",
14
+ width: "100%",
15
+ top: 0,
16
+ left: 0,
17
+ right: 0,
18
+ bottom: 0,
19
+ }}
20
+ >
21
+ {children}
22
+ </div>
23
+ );
24
+ };
25
+
26
+ export default Html;
@@ -0,0 +1,126 @@
1
+ import { createContext, useContext, type CSSProperties, type ReactNode } from "react";
2
+ import { extent } from "d3-array";
3
+
4
+ import { useDimensions } from "../hooks/useDimensions";
5
+ import type { DatumValue, Padding, ScaleLike, ContextValue } from "../types";
6
+
7
+ const ReactCakeContext = createContext<ContextValue>(null);
8
+
9
+ interface ReactCakeProps {
10
+ x?: string | ((d: unknown, i: number) => Datum);
11
+ x2?: string | ((d: unknown, i: number) => Datum);
12
+ y?: string | ((d: unknown, i: number) => Datum);
13
+ data?: unknown[];
14
+ flatData?: unknown[];
15
+ padding?: Padding;
16
+ xScale?: ScaleLike;
17
+ yDomain?: [DatumValue | null, DatumValue | null];
18
+ yScale?: ScaleLike;
19
+ zScale?: ScaleLike;
20
+ style?: CSSProperties;
21
+ percentRange?: boolean;
22
+ children?: ReactNode;
23
+ }
24
+
25
+ const ReactCake = ({
26
+ data = [],
27
+ flatData,
28
+ x,
29
+ x2,
30
+ y,
31
+ z,
32
+ xDomain,
33
+ xRange,
34
+ yDomain,
35
+ zDomain,
36
+ yRange,
37
+ zRange,
38
+ xScale,
39
+ yScale,
40
+ zScale,
41
+ padding = { left: 0, right: 0, top: 0, bottom: 0 },
42
+ children,
43
+ percentRange = false,
44
+ style,
45
+ }: ReactCakeProps) => {
46
+ const { ref: containerRef, width: containerWidth, height: containerHeight } = useDimensions();
47
+
48
+ const _padding = { left: 0, top: 0, right: 0, bottom: 0, ...padding };
49
+
50
+ const _x = typeof x === "string" ? (d) => d[x] : x;
51
+ const _x2 = typeof x2 === "string" ? (d) => d[x2] : x2;
52
+ const _y = typeof y === "string" ? (d) => d[y] : y;
53
+ const _z = typeof y === "string" ? (d) => d[z] : z;
54
+
55
+ const xIsBandscale = xScale && typeof xScale.bandwidth === "function";
56
+ const yIsBandscale = yScale && typeof yScale.bandwidth === "function";
57
+ const zIsBandscale = zScale && typeof zScale.bandwidth === "function";
58
+
59
+ const width = Math.max(0, percentRange ? 100 : containerWidth - _padding.left - _padding.right);
60
+ const height = Math.max(0, percentRange ? 100 : containerHeight - _padding.top - _padding.bottom);
61
+
62
+ const extentX = xIsBandscale
63
+ ? Array.from(new Set(data.map((d) => _x(d))))
64
+ : extent(flatData || data, _x);
65
+
66
+ const extentY = yIsBandscale
67
+ ? Array.from(new Set(data.map((d) => _y(d))))
68
+ : extent(flatData || data, _y);
69
+
70
+ const extentZ = zIsBandscale
71
+ ? Array.from(new Set(data.map((d) => _z(d))))
72
+ : extent(flatData || data, _z);
73
+
74
+ const _xScale = xScale?.range([0, width]).domain(xDomain || extentX);
75
+
76
+ const _yScale = yScale
77
+ ?.range([0, height])
78
+ .domain([
79
+ yDomain[0] !== null ? yDomain[0] : extentY[0],
80
+ yDomain[1] !== null ? yDomain[1] : extentY[1],
81
+ ]);
82
+
83
+ const _zScale = zScale?.range(zRange).domain(zDomain || extentZ);
84
+
85
+ const context = {
86
+ data: data,
87
+ x: _x,
88
+ x2: _x2,
89
+ y: _y,
90
+ z: _z,
91
+ xScale: _xScale,
92
+ yScale: _yScale,
93
+ zScale: _zScale,
94
+ xGet: (d: unknown) => _xScale(_x(d)),
95
+ yGet: (d: unknown) => _yScale(_y(d)),
96
+ zGet: (d: unknown) => _zScale(_z(d)),
97
+ height: height || 0,
98
+ width: width || 0,
99
+ containerWidth: containerWidth || 0,
100
+ containerHeight: containerHeight || 0,
101
+ padding: _padding,
102
+ viewBox: [0, 0, width, height],
103
+ };
104
+
105
+ return (
106
+ <div
107
+ ref={containerRef}
108
+ style={{
109
+ ...style,
110
+ position: "relative",
111
+ width: "100%",
112
+ height: "100%",
113
+ }}
114
+ >
115
+ <ReactCakeContext.Provider value={context}>{children}</ReactCakeContext.Provider>
116
+ </div>
117
+ );
118
+ };
119
+
120
+ function useReactCake() {
121
+ const context = useContext(ReactCakeContext);
122
+ if (!context) throw new Error("Must be used inside ReactCake");
123
+ return context;
124
+ }
125
+
126
+ export { ReactCake, useReactCake };
@@ -0,0 +1,33 @@
1
+ import { type ReactNode } from "react";
2
+ import { useReactCake } from "../ReactCake";
3
+
4
+ interface SvgProps {
5
+ overflow?: "visible" | "hidden";
6
+ children?: ReactNode;
7
+ }
8
+
9
+ const ScaledSvg = ({ children, overflow = "visible" }: SvgProps) => {
10
+ const { padding } = useReactCake();
11
+ return (
12
+ <>
13
+ <style>{`svg * { vector-effect: non-scaling-stroke;}`}</style>
14
+ <svg
15
+ className="reactcake-svg"
16
+ preserveAspectRatio="none"
17
+ height={`calc(100% - ${padding.top}px - ${padding.bottom}px`}
18
+ width={`calc(100% - ${padding.left}px - ${padding.right}px`}
19
+ viewBox="0 0 100 100"
20
+ style={{
21
+ position: "absolute",
22
+ top: `${padding.top}px`,
23
+ left: `${padding.left}px`,
24
+ overflow: overflow,
25
+ }}
26
+ >
27
+ {children}
28
+ </svg>
29
+ </>
30
+ );
31
+ };
32
+
33
+ export default ScaledSvg;
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from "react";
2
+ import { useReactCake } from "../ReactCake";
3
+
4
+ interface SvgProps {
5
+ overflow?: "visible" | "hidden";
6
+ children?: ReactNode;
7
+ }
8
+
9
+ const Svg = ({ children, overflow = "hidden" }: SvgProps) => {
10
+ const { padding } = useReactCake();
11
+ return (
12
+ <svg
13
+ className="reactcake-svg"
14
+ preserveAspectRatio="none"
15
+ height="100%"
16
+ width="100%"
17
+ viewBox={`0 0 100 100`}
18
+ style={{
19
+ position: "absolute",
20
+ top: 0,
21
+ left: 0,
22
+ bottom: 0,
23
+ right: 0,
24
+ overflow: overflow,
25
+ }}
26
+ >
27
+ <g transform={`translate(${padding.left} ${padding.top})`}>{children}</g>
28
+ </svg>
29
+ );
30
+ };
31
+
32
+ export default Svg;
@@ -0,0 +1,27 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ type Dimensions = { width: number; height: number };
4
+
5
+ export function useDimensions<T extends HTMLDivElement>() {
6
+ const ref = useRef<T | null>(null);
7
+
8
+ const [dimensions, setDimensions] = useState<Dimensions>({
9
+ width: 0,
10
+ height: 0,
11
+ });
12
+
13
+ useEffect(() => {
14
+ const element = ref.current;
15
+ if (!element) return;
16
+
17
+ const observer = new ResizeObserver(([entry]) => {
18
+ const { width, height } = entry.contentRect;
19
+ setDimensions({ width, height });
20
+ });
21
+
22
+ observer.observe(element);
23
+ return () => observer.disconnect();
24
+ }, []);
25
+
26
+ return { ref, width: dimensions.width, height: dimensions.height };
27
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import Html from "./Html/index.tsx";
2
+ import Svg from "./Svg";
3
+ import ScaledSvg from "./ScaledSvg"
4
+ import { ReactCake , useReactCake} from "./ReactCake";
5
+
6
+ export {ReactCake, useReactCake, Html, Svg, ScaledSvg};
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "reactcake",
3
+ "dependencies": {
4
+ "d3-array": "^3.2.4"
5
+ },
6
+ "release": {
7
+ "branches": [
8
+ "main"
9
+ ]
10
+ },
11
+ "devDependencies": {
12
+ "@types/d3-array": "^3.2.2",
13
+ "@types/react": "^19.3.0",
14
+ "@types/react-dom": "^19.3.0",
15
+ "semantic-release": "^25.0.9",
16
+ "semantic-release-monorepo": "^8.0.2"
17
+ }
18
+ }
package/lib/types.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type ReactNode } from "react";
2
+
3
+ export type DatumValue = number | Date | string;
4
+ export type TickFormatter<TValue = DatumValue> = (value: TValue) => ReactNode;
5
+
6
+ export type Padding = {
7
+ top?: number;
8
+ left?: number;
9
+ right?: number;
10
+ bottom?: number;
11
+ };
12
+
13
+ export interface ScaleLike<T = DatumValue> {
14
+ (value: unknown): number;
15
+ domain: () => T[];
16
+ range: (range: [number, number]) => ScaleLike<T>;
17
+ ticks?: (count?: number) => T[];
18
+ tickFormat?: (count?: number) => TickFormatter<T>;
19
+ bandwidth?: () => number;
20
+ invert?: (d: number) => ScaleLike;
21
+ }
22
+
23
+ type Accessor = (x: DatumValue) => number
24
+
25
+ export interface ContextValue {
26
+ width: number;
27
+ height: number;
28
+ xScale: ScaleLike;
29
+ yScale: ScaleLike;
30
+ zScale?: ScaleLike;
31
+ x: Accessor;
32
+ x2: Accessor;
33
+ y: Accessor;
34
+ data: unknown[];
35
+ xGet?: (d: unknown) => number;
36
+ yGet?: (d: unknown) => number;
37
+ zGet?: (d: unknown) => number | string;
38
+ padding: Padding;
39
+ }
package/notes.md ADDED
@@ -0,0 +1 @@
1
+ - Anything you draw past the edges shows up in the padding, the way it does on the other layouts. (https://layercake.graphics/guide#canvas)
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@awesomephant/reactcake",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A headless chart framework for React inspired by Layercake",
5
+ "keywords": [
6
+ "react",
7
+ "layercake",
8
+ "d3"
9
+ ],
10
+ "homepage": "https://reactcake.maxkohler.com",
11
+ "bugs": {
12
+ "url": "https://github.com/awesomephant/reactcake/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/awesomephant/reactcake.git"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Max Köhler",
20
+ "type": "module",
21
+ "main": "index.js",
22
+ "scripts": {
23
+ "prepublishOnly": "npm run build:lib",
24
+ "test": "node --import tsx --test",
25
+ "test:watch": "node --import tsx --test --watch",
26
+ "test:update-snapshots": "node --import tsx --test --test-update-snapshots",
27
+ "build:ts": "esbuild lib/index.ts --outdir=./dist --bundle",
28
+ "build:min": "esbuild lib/index.ts --outdir=./dist --entry-names=[dir]/[name].min --bundle --minify",
29
+ "build:types": "tsc",
30
+ "build:lib": "run-p 'build:ts' 'build:min'",
31
+ "build:demo": "esbuild src/index.ts src/index.html --loader:.html=copy --outdir=./_site --minify"
32
+ },
33
+ "devDependencies": {
34
+ "esbuild": "^0.28.0",
35
+ "npm-run-all": "^4.1.5",
36
+ "tsx": "^4.21.0",
37
+ "typescript": "^7.0.2"
38
+ },
39
+ "workspaces": [
40
+ "site",
41
+ "lib"
42
+ ],
43
+ "allowScripts": {
44
+ "esbuild@0.28.2": true,
45
+ "fsevents@2.3.3": true
46
+ }
47
+ }
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+ import { defineConfig } from 'astro/config';
3
+
4
+ import mdx from '@astrojs/mdx';
5
+
6
+ import react from '@astrojs/react';
7
+
8
+ export default defineConfig({
9
+ markdown: {
10
+ shikiConfig: {
11
+ theme: 'github-light-high-contrast',
12
+ }
13
+ },
14
+
15
+ integrations: [mdx(), react()]
16
+ });
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "site",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "engines": {
6
+ "node": ">=22.23.4"
7
+ },
8
+ "scripts": {
9
+ "start": "astro dev",
10
+ "build": "astro build",
11
+ "preview": "astro preview",
12
+ "astro": "astro"
13
+ },
14
+ "dependencies": {
15
+ "@astrojs/markdown-satteri": "^0.4.6",
16
+ "@astrojs/mdx": "^8.1.2",
17
+ "@astrojs/react": "^7.1.2",
18
+ "astro": "^7.4.4",
19
+ "d3-scale": "^4.0.2",
20
+ "react": "^19.3.1",
21
+ "react-dom": "^19.3.1"
22
+ },
23
+ "devDependencies": {
24
+ "@types/d3-scale": "^4.0.9",
25
+ "@types/react": "^19.3.0",
26
+ "@types/react-dom": "^19.3.0"
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 16 16"><text class="e" x="0" y="14" font-size="14">🍰</text></svg>
@@ -0,0 +1,16 @@
1
+ ---
2
+
3
+ const {height, width = "100%"} = Astro.props
4
+
5
+ ---
6
+
7
+ <div class="container" style={{height, width}}>
8
+ <slot/>
9
+ </div>
10
+
11
+ <style>
12
+ .container {
13
+ margin: 1rem 0;
14
+ border: 1px solid #2b598a;
15
+ }
16
+ </style>
@@ -0,0 +1 @@
1
+ // TKTK
@@ -0,0 +1,26 @@
1
+ import { ReactCake, ScaledSvg, Html } from "../../../lib";
2
+ import Columns from "./Columns";
3
+ import { scaleLinear, scaleBand } from "d3-scale"
4
+
5
+ const data = [
6
+ {year: 2022, value: 12},
7
+ {year: 2023, value: 22},
8
+ {year: 2024, value: 32},
9
+ {year: 2025, value: 15},
10
+ {year: 2026, value: 52}
11
+ ]
12
+
13
+ const xScale = scaleBand().paddingInner(.1)
14
+
15
+ export default function ColumnChart() {
16
+ return (
17
+ <ReactCake data={data} x="year" y="value" yScale={scaleLinear()} xScale={xScale} percentRange={true} yDomain={[0, null]} padding={{ top: 10, left: 10, right: 10, bottom: 10 }}>
18
+ <ScaledSvg>
19
+ <Columns/>
20
+ </ScaledSvg>
21
+ <Html>
22
+
23
+ </Html>
24
+ </ReactCake>
25
+ )
26
+ }
@@ -0,0 +1,30 @@
1
+ import { useReactCake } from '../../../lib';
2
+
3
+ export default function Columns() {
4
+ const { data, x, xGet, yGet, xScale } = useReactCake();
5
+
6
+ console.log(data)
7
+
8
+ return (
9
+ <g className="column-group">
10
+ {data?.map((d) => {
11
+
12
+ const valueY = yGet(d)
13
+ const xGot = xGet(d)
14
+ const xPos = Array.isArray(xGot) ? xGot[0] : xGot
15
+ const colWidth = xScale.bandwidth ? xScale.bandwidth() : 20
16
+
17
+ return <rect
18
+ key={x(d)}
19
+ x={xPos}
20
+ y={100 - valueY}
21
+ width={colWidth}
22
+ height={valueY}
23
+ stroke="#196c9e"
24
+ fill="none"
25
+ />
26
+ })}
27
+ </g>
28
+
29
+ )
30
+ }
@@ -0,0 +1,69 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width" />
6
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
+ <meta name="generator" content={Astro.generator} />
8
+ <title>ReactCake</title>
9
+ </head>
10
+ <body>
11
+ <main class="content">
12
+ <slot />
13
+ </main>
14
+ </body>
15
+ </html>
16
+
17
+ <style is:global>
18
+ * {
19
+ box-sizing: border-box;
20
+ margin: 0;
21
+ padding: 0;
22
+ }
23
+
24
+ body {
25
+ margin: 0;
26
+ width: 100%;
27
+ padding: 2rem 0;
28
+ font-family: sans-serif;
29
+ }
30
+
31
+ .content {
32
+ max-width: 40rem;
33
+ line-height: 1.4;
34
+ margin: 0 auto;
35
+ }
36
+
37
+ p, li {
38
+ letter-spacing: .002em;
39
+ }
40
+
41
+ h2 {
42
+ margin-top: 2rem;
43
+ margin-bottom: .25rem;
44
+ }
45
+ h3 {
46
+ margin-top: 1.25rem;
47
+ margin-bottom: 0.1rem;
48
+ font-weight: 600;
49
+ }
50
+
51
+ p, ul, ol {
52
+ margin-bottom: 1rem;
53
+ }
54
+
55
+ ul, ol {
56
+ margin-left: 1em;
57
+ }
58
+
59
+
60
+ .astro-code {
61
+ border-top: 1px solid lightgray;
62
+ border-bottom: 1px solid lightgray;
63
+ margin: 1rem 0;
64
+ padding: 1em 0;
65
+ line-height: 1.25;
66
+ font-family: monospace;
67
+ }
68
+
69
+ </style>
@@ -0,0 +1,73 @@
1
+ ---
2
+ layout: "../layouts/Base.astro"
3
+
4
+ ---
5
+
6
+ import Example from "../components/Example.astro"
7
+ import ColumnChart from "../examples/ColumnChart.tsx"
8
+
9
+ # ReactCake
10
+
11
+ A headless chart framework for React inspired by [Layercake](https://layercake.graphics/).
12
+
13
+ <Example height="12rem" width="20rem">
14
+ <ColumnChart></ColumnChart>
15
+ </Example>
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install --save reactcake
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```tsx
26
+ import { ReactCake, Html, Svg } from "reactcake";
27
+ import { scaleLinear, scaleBand } from "d3-scale"
28
+
29
+ // Chart components live in your project
30
+ import { xScale, yScale, Bars } from "./lib";
31
+
32
+ const data = [
33
+ {year: 2024, value: 32},
34
+ {year: 2025, value: 15},
35
+ {year: 2026, value: 52}
36
+ ];
37
+
38
+ const xKey = "date";
39
+ const yKey = "value";
40
+ const xScale = scaleTime();
41
+ const xScale = scaleBand();
42
+
43
+ return (
44
+ <ReactCake data={data} x="year" y="value" xScale={xScale} yScale={yScale}>
45
+ <Html>
46
+ <AxisX />
47
+ <AxisY />
48
+ </Html>
49
+ <Svg>
50
+ <Bars/>
51
+ </Svg>
52
+ </ReactCake>
53
+ );
54
+ ```
55
+
56
+ ## Concepts
57
+
58
+ ReactCake provides useful context for drawing data-driven charts, like a coordinate system, data extents and shared margins. Components that draw actual chart elements, like bars and lines, live in your project (or maybe a local component library), ReactCake is completely agnostic to what you render with it.
59
+
60
+ It provides sensible defaults and infers as much information as possible from your data, but also exposes fine-grained props to configure things yourself.
61
+
62
+ ReactCake is built on [D3](https://d3js.org/what-is-d3).
63
+
64
+ ### Relationship to Layercake
65
+
66
+ This project is an attempt to translate the overall approach and development ergonomics of the Layercake framework from Svelte to React. It does not aim for feature parity or identical API surfaces.
67
+
68
+
69
+ ### Prior work
70
+
71
+ - [A new technique for making responsive, JavaScript-free charts](https://dev.to/richharris/a-new-technique-for-making-responsive-javascript-free-charts-gmp)
72
+ - [Layercake](https://layercake.graphics/)
73
+ - [pancake](https://github.com/Rich-Harris/pancake)
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "astro/tsconfigs/strict",
3
+ "include": [
4
+ ".astro/types.d.ts",
5
+ "**/*"
6
+ ],
7
+ "exclude": [
8
+ "dist"
9
+ ],
10
+ "compilerOptions": {
11
+ "jsx": "react-jsx",
12
+ "jsxImportSource": "react"
13
+ }
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": false,
4
+ "target": "ESNext",
5
+ "module": "Preserve",
6
+ "moduleResolution": "bundler",
7
+ "noUncheckedIndexedAccess": true,
8
+ "noImplicitOverride": true,
9
+ "outDir": "dist",
10
+ "rootDir": "./lib",
11
+ "declaration": true,
12
+ "emitDeclarationOnly": true,
13
+ "allowImportingTsExtensions": true,
14
+ "lib": ["es2022", "dom"],
15
+ "skipLibCheck": true,
16
+ "jsx": "react-jsx",
17
+ },
18
+ "files": ["./lib/index.ts"],
19
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.