Skip to content

Commit 3a5a80e

Browse files
committed
update README.md
update demo fix: case1.mdx update png
1 parent ed153f4 commit 3a5a80e

4 files changed

Lines changed: 31 additions & 41 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
- [@gridsheet/preact-core](https://github.com/walkframe/gridsheet/tree/master/packages/preact-core)
1010
- [@gridsheet/vue-core](https://github.com/walkframe/gridsheet/tree/master/packages/vue-core)
11+
- [@gridsheet/svelte-core](https://github.com/walkframe/gridsheet/tree/master/packages/svelte-core)
12+
1113
## Docs
1214

1315
- [Gridsheet document](https://gridsheet.walkframe.com/)

gridsheet.png

16.2 KB
Loading
Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
import Case1 from './case1.component';
22

3-
# 📊 Sales Dashboard with Data Visualization
3+
# Sales Dashboard with Sparkline & Cross-Sheet Formulas
44

5-
This demo showcases data visualization and chart functionality in GridSheet.
5+
This demo showcases a two-sheet sales dashboard built with GridSheet.
66

7-
It demonstrates a sales dashboard with formula-based calculations, custom chart rendering, and statistical analysis.
8-
9-
The grid includes custom chart renderers, dynamic calculations, and trend analysis using formulas.
7+
The first sheet holds monthly metrics with sparkline charts rendered via a custom policy. The second sheet pulls KPIs from the first using cross-sheet formulas and uses `ARRAYFORMULA` with `IF` to spill status and gap values across multiple rows.
108

119
<Case1 />
1210

1311
## Implementation Guide
1412

15-
<a href="https://github.com/walkframe/gridsheet/tree/master/packages/docs/pages/examples/case1.component.tsx" target="_blank" rel="noopener noreferrer" style={{display: 'inline-block', background: '#007bff', color: 'white', padding: '8px 16px', textDecoration: 'none', borderRadius: '4px', fontWeight: '500', margin: '10px 0'}}>📄 View Source Code</a>
13+
<a href="https://github.com/walkframe/gridsheet/tree/master/packages/docs/pages/examples/case1.component.tsx" target="_blank" rel="noopener noreferrer" style={{display: 'inline-block', background: '#007bff', color: 'white', padding: '8px 16px', textDecoration: 'none', borderRadius: '4px', fontWeight: '500', margin: '10px 0'}}>View Source Code</a>
1614

17-
### Receiving a Range Reference with `renderSheet`
15+
### Rendering Sparklines with `renderSheet`
1816

19-
The `renderSheet` method on `PolicyMixinType` is called when a cell's resolved value is a `Sheet` object — that is, when a formula that returns a range (e.g. `=C1:F1`) has been evaluated.
17+
The `renderSheet` method on `PolicyMixinType` is called when a cell's resolved value is a `Sheet` object — that is, when a formula that returns a range (e.g. `=C1:H1`) has been evaluated.
2018

2119
By setting a range formula on a cell and implementing `renderSheet` on that cell's policy, you can visualize multiple columns of data within a single cell.
2220

2321
```tsx
24-
const LineChartPolicyMixin: PolicyMixinType = {
22+
const SparklinePolicyMixin: PolicyMixinType = {
2523
renderSheet({ value }: RenderProps<UserSheet>) {
2624
const matrix = toValueMatrix(value);
2725
const values: number[] = matrix.flatMap(
2826
(row) => row.filter((v): v is number => typeof v === 'number')
2927
);
30-
// values will be something like [30, 50, 78, 95] for Q1–Q4
3128
return <Line data={...} options={...} />;
3229
},
3330
};
@@ -37,28 +34,28 @@ const LineChartPolicyMixin: PolicyMixinType = {
3734

3835
### Pairing a Range Formula with a Policy
3936

40-
On the cell definition side, set a range formula such as `=C1:F1` on column B cells and assign a custom policy to that column.
37+
On the cell definition side, set a range formula such as `=C1:H1` on column B cells and assign a custom policy to that column.
4138

4239
```tsx
4340
matrices: {
4441
A1: [
45-
['Widget A', '=C1:F1', 30, 50, 78, 95, '=SUM(C1:F1)', ...],
42+
['Revenue', '=C1:H1', 42, 51, 48, 67, 73, 89, '=ROUND((H1-C1)/C1,3)'],
4643
...
4744
],
4845
},
4946
cells: {
50-
B: { policy: 'lineChart', style: { backgroundColor: '#f8f9fa' } },
47+
B: { policy: 'sparkline', style: { backgroundColor: '#fafbfc' } },
5148
}
5249
```
5350

54-
The resolved result of `=C1:F1` is passed to `renderSheet` as a `Sheet`, letting you build a Chart.js data source directly from it.
51+
The resolved result of `=C1:H1` is passed to `renderSheet` as a `Sheet`, letting you build a Chart.js data source directly from it.
5552

5653
### Sharing the Same `book` Across Multiple `GridSheet` Instances
5754

5855
The `book` returned by `useSpellbook` can be passed to multiple `GridSheet` components. Sharing the same `book` enables cross-sheet formula references between them.
5956

6057
```tsx
61-
const book = useSpellbook({ policies: { lineChart: new Policy({ mixins: [...] }) } });
58+
const book = useSpellbook({ policies: { sparkline: new Policy({ mixins: [...] }) } });
6259

6360
<GridSheet book={book} sheetName={sheetName1} initialCells={...} />
6461
<GridSheet book={book} sheetName={sheetName2} initialCells={...} />
@@ -68,26 +65,25 @@ By giving each component a different `sheetName`, multiple sheets coexist inside
6865

6966
### Cross-Sheet Formula References
7067

71-
To reference data from the `sales` sheet inside the `summary` sheet, use the `SheetName!Range` syntax.
68+
To reference data from the `metrics` sheet inside the `dashboard` sheet, use the `SheetName!Range` syntax.
7269

7370
```
74-
=SUM(sales!G1:G4)
75-
=INDEX(sales!A1:A4, MATCH(MAX(sales!G1:G4), sales!G1:G4, 0))
71+
=SUM(metrics!C1:H1)
72+
=ROUND(AVERAGE(metrics!C3:H3),1)
7673
```
7774

7875
When `sheetName` changes, these references update automatically. Try editing the sheet name inputs in the demo to see this in action.
7976

80-
### Write Protection with `prevention`
77+
### Spilling with ARRAYFORMULA + IF
8178

82-
Setting `operations.Write` on `prevention` prevents users from editing that cell, column, or row.
79+
The dashboard sheet uses `ARRAYFORMULA` to compute values that spill across multiple rows from a single formula cell.
8380

84-
```tsx
85-
cells: {
86-
H: { prevention: operations.Write },
87-
}
81+
```
82+
=ARRAYFORMULA(IF(B1:B5>=C1:C5,"✓ On Track","✗ Behind"))
83+
=ARRAYFORMULA(B1:B5-C1:C5)
8884
```
8985

90-
In this example, the Trend column (H) is formula-driven, so writes are blocked to keep the calculations intact.
86+
The first formula compares each KPI value against its target and spills a status label into D1:D5. The second computes the gap between value and target, spilling into E1:E5. Only the origin cell (D1, E1) holds the formula — the remaining cells are filled automatically.
9187

9288
### Bulk Data Entry with `matrices` in `buildInitialCells`
9389

@@ -97,24 +93,16 @@ Use the `matrices` key to set data in matrix form. The key is the address of the
9793
buildInitialCells({
9894
matrices: {
9995
A1: [
100-
['Widget A', '=C1:F1', 30, 50, 78, 95, '=SUM(C1:F1)', '=IF(...)'],
101-
['Widget B', '=C2:F2', 90, 88, 91, 64, ...],
96+
['Revenue', '=C1:H1', 42, 51, 48, 67, 73, 89, '=ROUND((H1-C1)/C1,3)'],
97+
['New Users', '=C2:H2', 120, 185, 210, 340, 295, 410, '=ROUND((H2-C2)/C2,3)'],
10298
],
10399
},
104100
cells: {
105-
defaultCol: { width: 120 },
106-
defaultRow: { height: 60 },
107-
'C:F': { alignItems: 'center', justifyContent: 'right' },
101+
defaultCol: { width: 55 },
102+
defaultRow: { height: 50 },
103+
'C:H': { style: numStyle, alignItems: 'center' },
108104
},
109105
})
110106
```
111107

112-
`defaultCol` / `defaultRow` set the default width and height for all columns and rows. A range key like `'C:F'` applies styles to multiple columns at once.
113-
114-
### Dynamic Trend Display with IF
115-
116-
```
117-
=IF((F1-E1)/E1>0.1,"📈 Up",IF((F1-E1)/E1<-0.1,"📉 Down","➡️ Stable"))
118-
```
119-
120-
This formula evaluates the quarter-over-quarter change as a percentage and displays an emoji for the trend. Excel-style conditional logic like this works natively in GridSheet's formula engine.
108+
`defaultCol` / `defaultRow` set the default width and height for all columns and rows. A range key like `'C:H'` applies styles to multiple columns at once.

packages/docs/public/demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<script type="module">
2424
import { h, render } from "https://cdn.jsdelivr.net/npm/preact@10.29.0/+esm";
2525
import htm from "https://cdn.jsdelivr.net/npm/htm@3/+esm";
26-
import { GridSheet, useBook } from "https://cdn.jsdelivr.net/npm/@gridsheet/preact-core@3.0.1/+esm";
27-
import { allFunctions } from "https://cdn.jsdelivr.net/npm/@gridsheet/functions@3.0.1/+esm";
26+
import { GridSheet, useBook } from "https://cdn.jsdelivr.net/npm/@gridsheet/preact-core@3.0.2/+esm";
27+
import { allFunctions } from "https://cdn.jsdelivr.net/npm/@gridsheet/functions@3.0.2/+esm";
2828

2929
const html = htm.bind(h);
3030

0 commit comments

Comments
 (0)