pi-generative-ui 0.1.0 → 0.2.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.
@@ -3,13 +3,16 @@
3
3
  <div style="position: relative; width: 100%; height: 300px;">
4
4
  <canvas id="myChart"></canvas>
5
5
  </div>
6
- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"></script>
6
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
7
7
  <script>
8
- new Chart(document.getElementById('myChart'), {
9
- type: 'bar',
10
- data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Revenue', data: [12,19,8,15] }] },
11
- options: { responsive: true, maintainAspectRatio: false }
12
- });
8
+ function initChart() {
9
+ new Chart(document.getElementById('myChart'), {
10
+ type: 'bar',
11
+ data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Revenue', data: [12,19,8,15] }] },
12
+ options: { responsive: true, maintainAspectRatio: false }
13
+ });
14
+ }
15
+ if (window.Chart) initChart();
13
16
  </script>
14
17
  ```
15
18
 
@@ -19,6 +22,7 @@
19
22
  - **Canvas sizing**: set height ONLY on the wrapper div, never on the canvas element itself. Use position: relative on the wrapper and responsive: true, maintainAspectRatio: false in Chart.js options. Never set CSS height directly on canvas — this causes wrong dimensions, especially for horizontal bar charts.
20
23
  - For horizontal bar charts: wrapper div height should be at least (number_of_bars * 40) + 80 pixels.
21
24
  - Load UMD build via `<script src="https://cdnjs.cloudflare.com/ajax/libs/...">` — sets `window.Chart` global. Follow with plain `<script>` (no `type="module"`).
25
+ - **Script load ordering**: CDN scripts may not be loaded when the next `<script>` runs (especially during streaming). Always use `onload="initChart()"` on the CDN script tag, define your chart init in a named function, and add `if (window.Chart) initChart();` as a fallback at the end of your inline script. This guarantees charts render regardless of load order.
22
26
  - Multiple charts: use unique IDs (`myChart1`, `myChart2`). Each gets its own canvas+div pair.
23
27
  - For bubble and scatter charts: bubble radii extend past their center points, so points near axis boundaries get clipped. Pad the scale range — set `scales.y.min` and `scales.y.max` ~10% beyond your data range (same for x). Or use `layout: { padding: 20 }` as a blunt fallback.
24
28
  - Chart.js auto-skips x-axis labels when they'd overlap. If you have ≤12 categories and need all labels visible (waterfall, monthly series), set `scales.x.ticks: { autoSkip: false, maxRotation: 45 }` — missing labels make bars unidentifiable.
@@ -107,13 +107,16 @@ const CHARTS_CHART_JS = `## Charts (Chart.js)
107
107
  <div style="position: relative; width: 100%; height: 300px;">
108
108
  <canvas id="myChart"></canvas>
109
109
  </div>
110
- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"></script>
110
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
111
111
  <script>
112
- new Chart(document.getElementById('myChart'), {
113
- type: 'bar',
114
- data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Revenue', data: [12,19,8,15] }] },
115
- options: { responsive: true, maintainAspectRatio: false }
116
- });
112
+ function initChart() {
113
+ new Chart(document.getElementById('myChart'), {
114
+ type: 'bar',
115
+ data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Revenue', data: [12,19,8,15] }] },
116
+ options: { responsive: true, maintainAspectRatio: false }
117
+ });
118
+ }
119
+ if (window.Chart) initChart();
117
120
  </script>
118
121
  \`\`\`
119
122
 
@@ -123,6 +126,7 @@ const CHARTS_CHART_JS = `## Charts (Chart.js)
123
126
  - **Canvas sizing**: set height ONLY on the wrapper div, never on the canvas element itself. Use position: relative on the wrapper and responsive: true, maintainAspectRatio: false in Chart.js options. Never set CSS height directly on canvas — this causes wrong dimensions, especially for horizontal bar charts.
124
127
  - For horizontal bar charts: wrapper div height should be at least (number_of_bars * 40) + 80 pixels.
125
128
  - Load UMD build via \`<script src="https://cdnjs.cloudflare.com/ajax/libs/...">\` — sets \`window.Chart\` global. Follow with plain \`<script>\` (no \`type="module"\`).
129
+ - **Script load ordering**: CDN scripts may not be loaded when the next \`<script>\` runs (especially during streaming). Always use \`onload="initChart()"\` on the CDN script tag, define your chart init in a named function, and add \`if (window.Chart) initChart();\` as a fallback at the end of your inline script. This guarantees charts render regardless of load order.
126
130
  - Multiple charts: use unique IDs (\`myChart1\`, \`myChart2\`). Each gets its own canvas+div pair.
127
131
  - For bubble and scatter charts: bubble radii extend past their center points, so points near axis boundaries get clipped. Pad the scale range — set \`scales.y.min\` and \`scales.y.max\` ~10% beyond your data range (same for x). Or use \`layout: { padding: 20 }\` as a blunt fallback.
128
132
  - Chart.js auto-skips x-axis labels when they'd overlap. If you have ≤12 categories and need all labels visible (waterfall, monthly series), set \`scales.x.ticks: { autoSkip: false, maxRotation: 45 }\` — missing labels make bars unidentifiable.
package/README.md CHANGED
@@ -4,7 +4,15 @@ Claude.ai's generative UI - reverse-engineered, rebuilt for [pi](https://github.
4
4
 
5
5
  Ask pi to "show me how compound interest works" and get a live interactive widget - sliders, charts, animations - rendered in a native macOS window. Not a screenshot. Not a code block. A real HTML application with JavaScript, streaming live as the LLM generates it.
6
6
 
7
- https://github.com/user-attachments/assets/placeholder-demo-video
7
+ <p align="center">
8
+ <img src="media/dashboard.gif" width="700" alt="SaaS dashboard with metric cards and Chart.js">
9
+ </p>
10
+ <p align="center">
11
+ <img src="media/simulator.gif" width="700" alt="Projectile motion simulator with planet selection">
12
+ </p>
13
+ <p align="center">
14
+ <img src="media/diagram.gif" width="700" alt="Architecture diagram streaming live">
15
+ </p>
8
16
 
9
17
  ## How it works
10
18
 
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-generative-ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Generative UI for pi — render interactive HTML/SVG widgets in native macOS windows via Glimpse",
5
5
  "type": "commonjs",
6
6
  "keywords": ["pi-package"],