@awesomephant/reactcake 1.1.0 → 1.1.1
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.
- package/lib/Html/index.tsx +8 -6
- package/lib/ScaledSvg/index.tsx +2 -2
- package/lib/Svg/index.tsx +2 -2
- package/lib/types.ts +4 -0
- package/notes.md +10 -0
- package/package.json +1 -1
- package/site/astro.config.mjs +9 -3
- package/site/package.json +1 -0
- package/site/src/components/Example.astro +1 -0
- package/site/src/examples/AxisX/{index.tsx → AxisX.tsx} +1 -1
- package/site/src/examples/AxisX/styles.module.css +5 -0
- package/site/src/examples/ColumnChart.tsx +4 -2
- package/site/src/examples/DebugPadding.tsx +17 -0
- package/site/src/layouts/Base.astro +22 -18
- package/site/src/layouts/code.css +37 -0
- package/site/src/pages/index.mdx +5 -3
package/lib/Html/index.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { useReactCake } from "../ReactCake";
|
|
3
|
+
import { LayoutProps } from "../types";
|
|
3
4
|
|
|
4
|
-
interface HtmlProps {
|
|
5
|
+
interface HtmlProps extends LayoutProps {
|
|
5
6
|
children?: ReactNode;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
const Html = ({ children }: HtmlProps) => {
|
|
9
|
+
const Html = ({ overflow = "visible", children }: HtmlProps) => {
|
|
9
10
|
const { padding } = useReactCake();
|
|
10
11
|
|
|
11
12
|
return (
|
|
@@ -13,10 +14,11 @@ const Html = ({ children }: HtmlProps) => {
|
|
|
13
14
|
className="reactcake-html"
|
|
14
15
|
style={{
|
|
15
16
|
position: "absolute",
|
|
16
|
-
top: padding.top
|
|
17
|
-
left: padding.left
|
|
18
|
-
right: padding.right
|
|
19
|
-
bottom: padding.bottom
|
|
17
|
+
top: `${padding.top}px`,
|
|
18
|
+
left: `${padding.left}px`,
|
|
19
|
+
right: `${padding.right}px`,
|
|
20
|
+
bottom: `${padding.bottom}px`,
|
|
21
|
+
overflow,
|
|
20
22
|
}}
|
|
21
23
|
>
|
|
22
24
|
{children}
|
package/lib/ScaledSvg/index.tsx
CHANGED
package/lib/Svg/index.tsx
CHANGED
package/lib/types.ts
CHANGED
package/notes.md
CHANGED
|
@@ -1 +1,11 @@
|
|
|
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)
|
|
2
|
+
|
|
3
|
+
from: https://layercake.graphics/guide
|
|
4
|
+
|
|
5
|
+
- it reverses the default range from [0, height] to [height, 0] in order to match the DOM coordinate system and make drawing easier out of the box.
|
|
6
|
+
- The default ranges for each dimension are:
|
|
7
|
+
|
|
8
|
+
x: [0, width]
|
|
9
|
+
y: [height, 0], unless using a scaleBand or scalePoint and it is [0, height]
|
|
10
|
+
r: [1, 25]. The min is 1 and not zero because this is a scaleSqrt by default and 0 is not allowed in that type of chart.
|
|
11
|
+
z: [0, width]
|
package/package.json
CHANGED
package/site/astro.config.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { defineConfig } from 'astro/config';
|
|
3
|
+
import {transformerRenderIndentGuides, transformerRenderLineNumber} from "@shikijs/transformers"
|
|
3
4
|
|
|
4
5
|
import mdx from '@astrojs/mdx';
|
|
5
6
|
|
|
@@ -7,9 +8,14 @@ import react from '@astrojs/react';
|
|
|
7
8
|
|
|
8
9
|
export default defineConfig({
|
|
9
10
|
markdown: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
shikiConfig: {
|
|
12
|
+
theme: 'css-variables',
|
|
13
|
+
defaultColor: false,
|
|
14
|
+
transformers:[transformerRenderLineNumber(), transformerRenderIndentGuides()]
|
|
15
|
+
},
|
|
16
|
+
syntaxHighlight: {
|
|
17
|
+
type: 'shiki',
|
|
18
|
+
},
|
|
13
19
|
},
|
|
14
20
|
|
|
15
21
|
integrations: [mdx(), react()]
|
package/site/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ReactCake, ScaledSvg, Html } from "../../../lib";
|
|
2
|
-
import AxisX from "./AxisX/
|
|
2
|
+
import AxisX from "./AxisX/AxisX";
|
|
3
3
|
import AxisY from "./AxisY";
|
|
4
4
|
import Columns from "./Columns";
|
|
5
5
|
import { scaleLinear, scaleBand } from "d3-scale";
|
|
6
6
|
import { max } from "d3-array";
|
|
7
|
+
import DebugPadding from "./DebugPadding";
|
|
7
8
|
|
|
8
9
|
const data = [
|
|
9
10
|
{ year: 2021, value: 18 },
|
|
@@ -29,7 +30,8 @@ export default function ColumnChart() {
|
|
|
29
30
|
yDomain={[0, max(data, (d) => d[yKey]) + 5]}
|
|
30
31
|
padding={{ top: 10, left: 35, right: 10, bottom: 30 }}
|
|
31
32
|
>
|
|
32
|
-
<Html>
|
|
33
|
+
<Html overflow="visible">
|
|
34
|
+
<DebugPadding />
|
|
33
35
|
<AxisX grid ticks />
|
|
34
36
|
<AxisY grid ticks={3} />
|
|
35
37
|
</Html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useReactCake } from "../../../lib";
|
|
2
|
+
|
|
3
|
+
export default function DebugPadding() {
|
|
4
|
+
const { padding } = useReactCake();
|
|
5
|
+
return (
|
|
6
|
+
<div
|
|
7
|
+
style={{
|
|
8
|
+
position: "absolute",
|
|
9
|
+
left: 0,
|
|
10
|
+
right: 0,
|
|
11
|
+
top: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
boxShadow: `${padding.right}px 0 var(--blue-20), 0 ${padding.bottom}px var(--blue-20), 0 ${-padding.top}px var(--blue-20), -${padding.left}px 0 var(--blue-20)`,
|
|
14
|
+
}}
|
|
15
|
+
></div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
import "./code.css"
|
|
3
|
+
---
|
|
4
|
+
|
|
1
5
|
<!doctype html>
|
|
2
6
|
<html lang="en">
|
|
3
7
|
<head>
|
|
@@ -24,12 +28,13 @@
|
|
|
24
28
|
body {
|
|
25
29
|
margin: 0;
|
|
26
30
|
width: 100%;
|
|
27
|
-
padding:
|
|
28
|
-
font-family:
|
|
29
|
-
--blue-70: hsl(
|
|
30
|
-
--blue-50: hsl(
|
|
31
|
-
--blue-30: hsl(
|
|
32
|
-
--blue-
|
|
31
|
+
padding: .5rem;
|
|
32
|
+
font-family: Georgia, 'Times New Roman', Times, serif;
|
|
33
|
+
--blue-70: hsl(220, 0%, 20%);
|
|
34
|
+
--blue-50: hsl(220, 0%, 36%);
|
|
35
|
+
--blue-30: hsl(220, 0%, 76%);
|
|
36
|
+
--blue-20: hsl(220, 0%, 92%);
|
|
37
|
+
--blue-10: hsl(220, 0%, 97%);
|
|
33
38
|
--ms--1: .8rem
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -38,17 +43,23 @@
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
.content {
|
|
46
|
+
border: 1px solid var(--blue-70);
|
|
41
47
|
max-width: 40rem;
|
|
42
48
|
line-height: 1.4;
|
|
43
|
-
|
|
49
|
+
padding: 1rem;
|
|
50
|
+
border-right: 1px solid var(--blue-70);
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
p, li {
|
|
47
54
|
letter-spacing: .002em;
|
|
48
55
|
}
|
|
49
56
|
|
|
57
|
+
h1 {
|
|
58
|
+
font-weight: 900;
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
h2 {
|
|
51
|
-
margin-top:
|
|
62
|
+
margin-top: 1rem;
|
|
52
63
|
margin-bottom: .25rem;
|
|
53
64
|
}
|
|
54
65
|
h3 {
|
|
@@ -59,20 +70,13 @@
|
|
|
59
70
|
|
|
60
71
|
p, ul, ol {
|
|
61
72
|
margin-bottom: 1rem;
|
|
73
|
+
&:last-child {
|
|
74
|
+
margin-bottom: 0;
|
|
75
|
+
}
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
ul, ol {
|
|
65
79
|
margin-left: 1em;
|
|
66
80
|
}
|
|
67
81
|
|
|
68
|
-
|
|
69
|
-
.astro-code {
|
|
70
|
-
border-top: 1px solid lightgray;
|
|
71
|
-
border-bottom: 1px solid lightgray;
|
|
72
|
-
margin: 1rem 0;
|
|
73
|
-
padding: 1em 0;
|
|
74
|
-
line-height: 1.25;
|
|
75
|
-
font-family: monospace;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
82
|
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.astro-code {
|
|
2
|
+
--astro-code-background: hsl(51, 62.5%, 93.7%);
|
|
3
|
+
--astro-code-token-comment: #666;
|
|
4
|
+
margin: 1em 0;
|
|
5
|
+
margin-top: .5em;
|
|
6
|
+
padding: .5em;
|
|
7
|
+
font-size: 12px;
|
|
8
|
+
line-height: 1.25;
|
|
9
|
+
font-family: monospace;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
pre.astro-code .indent {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
position: relative;
|
|
16
|
+
left: var(--indent-offset);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pre.astro-code .indent:empty {
|
|
20
|
+
height: 1lh;
|
|
21
|
+
vertical-align: bottom;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pre.astro-code .indent::before {
|
|
25
|
+
content: '';
|
|
26
|
+
position: absolute;
|
|
27
|
+
opacity: 0.5;
|
|
28
|
+
width: 1px;
|
|
29
|
+
height: 100%;
|
|
30
|
+
background-color: red;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pre.astro-code .line-number {
|
|
34
|
+
user-select: none;
|
|
35
|
+
color: #666;
|
|
36
|
+
margin-right: 2ch;
|
|
37
|
+
}
|
package/site/src/pages/index.mdx
CHANGED
|
@@ -17,13 +17,13 @@ A headless chart framework for React inspired by [Layercake](https://layercake.g
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npm install --save reactcake
|
|
20
|
+
npm install --save @awesomephant/reactcake
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
25
|
```tsx
|
|
26
|
-
import { ReactCake, Html, Svg } from "reactcake";
|
|
26
|
+
import { ReactCake, Html, Svg } from "@awesomephant/reactcake";
|
|
27
27
|
import { scaleLinear, scaleBand } from "d3-scale"
|
|
28
28
|
|
|
29
29
|
// Chart components live in your project
|
|
@@ -35,9 +35,11 @@ const data = [
|
|
|
35
35
|
{year: 2026, value: 52}
|
|
36
36
|
];
|
|
37
37
|
|
|
38
|
+
// Use any d3 scale
|
|
38
39
|
const xScale = scaleTime();
|
|
39
40
|
const xScale = scaleBand();
|
|
40
41
|
|
|
42
|
+
// Build charts declaratively
|
|
41
43
|
return (
|
|
42
44
|
<ReactCake data={data} x="year" y="value" xScale={xScale} yScale={yScale}>
|
|
43
45
|
<Html>
|
|
@@ -61,7 +63,7 @@ ReactCake is built on [D3](https://d3js.org/what-is-d3).
|
|
|
61
63
|
|
|
62
64
|
### Relationship to Layercake
|
|
63
65
|
|
|
64
|
-
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.
|
|
66
|
+
This project is an attempt to carefully 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.
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
### Prior work
|