Skip to content

Commit debba71

Browse files
committed
- update playgroud example
- update readme
1 parent d6f3066 commit debba71

File tree

4 files changed

+62
-27
lines changed

4 files changed

+62
-27
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
📊 `nuxt-plotly` module is thin Nuxt3 wrapper for [plotly.js](https://plotly.com/javascript/)
99

1010
- [ Release Notes](/CHANGELOG.md)
11-
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/nuxt-plotly?file=playground%2Fapp.vue) -->
12-
<!-- - [📖 &nbsp;Documentation](https://example.com) -->
11+
- [🏀 Online playground](https://stackblitz.com/edit/nuxt-starter-1bs1ke?file=app.vue)
12+
- [📖 &nbsp;Plotly Documentation](https://plotly.com/javascript/plotly-fundamentals/)
1313

1414
## Features
1515

@@ -22,11 +22,24 @@
2222

2323
## Require client-side
2424

25-
- run with .client.vue file
25+
There are two ways to use the `nuxt-plotly` module on the client-side in Nuxt3:
2626

27-
- run with `<client-only>` tag
27+
1. Wrap the component with the `<client-only>` tag.
2828

29-
- 🚀 &nbsp; [See Example](/playground/app.vue)
29+
```html
30+
<client-only>
31+
<nuxt-plotly
32+
:data="pieChart.data"
33+
:layout="pieChart.layout"
34+
:config="pieChart.config"
35+
style="width: 100%"
36+
></nuxt-plotly>
37+
</client-only>
38+
```
39+
40+
2. Create a file with the `.client.vue` extension, for example, `PlotlyPieChart.client.vue` and then you can use the component without the `<client-only>` tag.
41+
42+
- 🎯 &nbsp; [See Example](/playground/app.vue)
3043

3144
## Quick Setup
3245

@@ -51,9 +64,21 @@ export default defineNuxtConfig({
5164
});
5265
```
5366

67+
3. Add `plotly.js-dist-min` to the `vite.optimizeDeps.include` section of `nuxt.config.ts`
68+
69+
```js
70+
export default defineNuxtConfig({
71+
vite: {
72+
optimizeDeps: {
73+
include: ["plotly.js-dist-min"],
74+
},
75+
},
76+
});
77+
```
78+
5479
That's it! You can now use Nuxt Plotly Module in your Nuxt app ✨
5580

56-
## Development
81+
## Development: If you want to contribute
5782

5883
```bash
5984
# Install dependencies

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
"nuxt": "^3.6.5",
5555
"vitest": "^0.33.0"
5656
}
57-
}
57+
}

playground/app.vue

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,43 @@
66
<nuxt-plotly
77
:data="data"
88
:layout="layout"
9-
:config="{ scrollZoom: true, displayModeBar: false }"
9+
:config="config"
1010
style="width: 100%"
1111
></nuxt-plotly>
1212
</client-only>
1313
<pie-chart></pie-chart>
1414
</div>
1515
</template>
1616

17-
<script setup>
18-
const trace1 = {
19-
type: "scatter",
20-
mode: "lines",
21-
x: ["2018-01-01", "2018-08-31"],
22-
y: [10, 5],
23-
line: { color: "#17BECF" },
24-
};
17+
<script setup lang="ts">
18+
import {
19+
NuxtPlotlyConfig,
20+
NuxtPlotlyData,
21+
NuxtPlotlyLayout,
22+
} from "../src/module";
2523
26-
const trace2 = {
27-
type: "scatter",
28-
mode: "lines",
29-
x: ["2018-01-01", "2018-08-31"],
30-
y: [3, 7],
31-
line: { color: "#7F7F7F" },
32-
};
24+
// When you install the nuxt-plotly module please use the following syntax
25+
// import { NuxtPlotlyConfig, NuxtPlotlyData, NuxtPlotlyLayout } from 'nuxt-plotly'
3326
34-
const data = [trace1, trace2];
35-
const layout = {
27+
const data: NuxtPlotlyData = [
28+
{
29+
type: "scatter",
30+
mode: "lines",
31+
x: ["2018-01-01", "2018-08-31"],
32+
y: [10, 5],
33+
line: { color: "#17BECF" },
34+
},
35+
{
36+
type: "scatter",
37+
mode: "lines",
38+
x: ["2018-01-01", "2018-08-31"],
39+
y: [3, 7],
40+
line: { color: "#7F7F7F" },
41+
},
42+
];
43+
const layout: NuxtPlotlyLayout = {
3644
title: "My graph on app.vue with <client-only>",
3745
};
46+
47+
const config: NuxtPlotlyConfig = { scrollZoom: true, displayModeBar: false };
3848
</script>

0 commit comments

Comments
 (0)