Skip to content

Commit 42555c7

Browse files
committed
Add tooltips and client.js again.
1 parent 1c01e64 commit 42555c7

File tree

5 files changed

+80
-23
lines changed

5 files changed

+80
-23
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
/* Client-side code disabled to illustrate pure server-side rendering. */
1+
import React from 'react';
2+
import {hydrateRoot} from 'react-dom/client';
3+
4+
const pageComponentName = Micronaut.rootComponent;
5+
6+
import(`./components/${pageComponentName}.js`).then(module => {
7+
const PageComponent = module[pageComponentName] ?? module['default'];
8+
hydrateRoot(document, <PageComponent {...Micronaut.rootProps}/>)
9+
})

graaljs/graaljs-micronaut-react-ssr/src/main/js/components/SimpleAreaChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Original Recharts example at: https://recharts.org/en-US/examples/SimpleAreaChart */
22

33
import React from 'react';
4-
import { AreaChart, Area, XAxis, YAxis, CartesianGrid } from 'recharts';
4+
import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts';
55

66
const data = [
77
{
@@ -64,6 +64,7 @@ const SimpleAreaChart = ({width, height}) => {
6464
<CartesianGrid strokeDasharray="3 3" />
6565
<XAxis dataKey="name" />
6666
<YAxis />
67+
<Tooltip />
6768
<Area type="monotone" dataKey="uv" stroke="#8884d8" fill="#8884d8" />
6869
</AreaChart>
6970
);

graaljs/graaljs-micronaut-react-ssr/src/main/js/components/SimpleBarChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Original Recharts example at: https://recharts.org/en-US/examples/SimpleBarChart */
22

33
import React from 'react';
4-
import { BarChart, Bar, Rectangle, XAxis, YAxis, CartesianGrid, Legend } from 'recharts';
4+
import { BarChart, Bar, Rectangle, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
55

66
const data = [
77
{
@@ -64,6 +64,7 @@ const SimpleBarChart = ({width, height}) => {
6464
<CartesianGrid strokeDasharray="3 3" />
6565
<XAxis dataKey="name" />
6666
<YAxis />
67+
<Tooltip />
6768
<Legend />
6869
<Bar dataKey="pv" fill="#8884d8" activeBar={<Rectangle fill="pink" stroke="blue" />} />
6970
<Bar dataKey="uv" fill="#82ca9d" activeBar={<Rectangle fill="gold" stroke="purple" />} />

graaljs/graaljs-micronaut-react-ssr/src/main/js/components/SimpleLineChart.js

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,72 @@
11
/* Original Recharts example at: https://recharts.org/en-US/examples/SimpleLineChart */
22

3-
import React from 'react';
4-
import { LineChart, Line, CartesianGrid, XAxis, YAxis } from 'recharts';
3+
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
54

65
const data = [
7-
{ name: 'A', uv: 400, pv: 240 },
8-
{ name: 'B', uv: 300, pv: 456 },
9-
{ name: 'C', uv: 300, pv: 139 },
10-
{ name: 'D', uv: 200, pv: 980 },
11-
{ name: 'E', uv: 278, pv: 390 },
12-
{ name: 'F', uv: 189, pv: 480 },
6+
{
7+
name: 'Page A',
8+
uv: 4000,
9+
pv: 2400,
10+
amt: 2400,
11+
},
12+
{
13+
name: 'Page B',
14+
uv: 3000,
15+
pv: 1398,
16+
amt: 2210,
17+
},
18+
{
19+
name: 'Page C',
20+
uv: 2000,
21+
pv: 9800,
22+
amt: 2290,
23+
},
24+
{
25+
name: 'Page D',
26+
uv: 2780,
27+
pv: 3908,
28+
amt: 2000,
29+
},
30+
{
31+
name: 'Page E',
32+
uv: 1890,
33+
pv: 4800,
34+
amt: 2181,
35+
},
36+
{
37+
name: 'Page F',
38+
uv: 2390,
39+
pv: 3800,
40+
amt: 2500,
41+
},
42+
{
43+
name: 'Page G',
44+
uv: 3490,
45+
pv: 4300,
46+
amt: 2100,
47+
},
1348
];
1449

15-
function SimpleLineChart({width, height}) {
16-
return (
17-
<LineChart width={width} height={height} data={data}>
18-
<XAxis dataKey="name" />
19-
<YAxis />
20-
<CartesianGrid stroke="#eee" strokeDasharray="5 5" />
21-
<Line type="monotone" dataKey="uv" stroke="#ff7300" />
22-
<Line type="monotone" dataKey="pv" stroke="#387908" />
23-
</LineChart>
24-
);
50+
export default function SimpleLineChart({width, height}) {
51+
return (
52+
<LineChart
53+
width={width}
54+
height={height}
55+
data={data}
56+
margin={{
57+
top: 5,
58+
right: 30,
59+
left: 20,
60+
bottom: 5,
61+
}}
62+
>
63+
<CartesianGrid strokeDasharray="3 3" />
64+
<XAxis dataKey="name" />
65+
<YAxis />
66+
<Tooltip />
67+
<Legend />
68+
<Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
69+
<Line type="monotone" dataKey="uv" stroke="#82ca9d" />
70+
</LineChart>
71+
);
2572
}
26-
27-
export default SimpleLineChart;

graaljs/graaljs-micronaut-react-ssr/src/main/js/components/VerticalComposedChart.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
XAxis,
1010
YAxis,
1111
CartesianGrid,
12+
Tooltip,
1213
Legend,
1314
} from 'recharts';
1415

@@ -68,6 +69,7 @@ const VerticalComposedChart = ({width, height}) => {
6869
<CartesianGrid stroke="#f5f5f5" />
6970
<XAxis type="number" />
7071
<YAxis dataKey="name" type="category" scale="band" />
72+
<Tooltip />
7173
<Legend />
7274
<Area dataKey="amt" fill="#8884d8" stroke="#8884d8" />
7375
<Bar dataKey="pv" barSize={20} fill="#413ea0" />

0 commit comments

Comments
 (0)