diff --git a/package.json b/package.json index b485744f4..d35a4f3a9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-chartjs-2", "type": "module", "version": "6.0.0", - "description": "React components for Chart.js.", + "description": "React components for Chart.js, the most popular charting library.", "author": "Jeremy Ayerst", "license": "MIT", "homepage": "https://react-chartjs-2.js.org", @@ -15,12 +15,28 @@ "url": "https://github.com/reactchartjs/react-chartjs-2/issues" }, "keywords": [ + "react", + "react-component", "chart", - "chart-js", + "charts", + "charting", "chart.js", + "chartjs", + "chart-js", "react-chartjs-2", "react chart.js", - "react-chart.js" + "react-chart.js", + "graph", + "visualization", + "data-visualization", + "bar-chart", + "line-chart", + "pie-chart", + "doughnut-chart", + "polar-area-chart", + "radar-chart", + "scatter-chart", + "bubble-chart" ], "sideEffects": false, "types": "./dist/index.d.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66c56f7dd..19ba28f41 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -657,9 +657,18 @@ importers: '@astrojs/starlight': specifier: ^0.43.2 version: 0.43.2(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(astro@7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1))(supports-color@7.2.0)(typescript@6.0.3) + '@fontsource/inter': + specifier: ^5.3.0 + version: 5.3.0 astro: specifier: ^7.4.13 version: 7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1) + astro-og-canvas: + specifier: ^0.13.3 + version: 0.13.3(astro@7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1)) + canvaskit-wasm: + specifier: ^0.42.0 + version: 0.42.0 react-docgen-typescript: specifier: ^2.4.0 version: 2.4.0(typescript@6.0.3) @@ -1476,6 +1485,9 @@ packages: resolution: {integrity: sha512-3RQHgEtvL1Frl/d1cSreo7qhJ3Gk1OdNUai/CtZ8G+wYeRQnJih3s9xJ9/kgYekPQRdwgh0HXRPqMlzWGwivIQ==} engines: {node: ^20.19.0 || ^22.13.0 || ^23.5.0 || >=24.0.0, npm: '>=10'} + '@fontsource/inter@5.3.0': + resolution: {integrity: sha512-RofMylZmjlJEfELXeNHFWBRcSs75rGU/6bV2S2jfnvv/3rPXPGe0LgUJTklcHZ9lM4OZmAVFhcJPnACfb91A3g==} + '@humanfs/core@0.19.2': resolution: {integrity: sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==} engines: {node: '>=18.18.0'} @@ -3258,6 +3270,9 @@ packages: '@webcontainer/env@1.1.1': resolution: {integrity: sha512-6aN99yL695Hi9SuIk1oC88l9o0gmxL1nGWWQ/kNy81HigJ0FoaoTXpytCj6ItzgyCEwA9kF1wixsTuv5cjsgng==} + '@webgpu/types@0.1.21': + resolution: {integrity: sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow==} + acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -3364,6 +3379,11 @@ packages: peerDependencies: astro: ^4.0.0-beta || ^5.0.0-beta || ^3.3.0 || ^6.0.0-beta || ^7.0.0 + astro-og-canvas@0.13.3: + resolution: {integrity: sha512-OenE+M/rrSnrCtniqg5vhq9+047UIjdqgEqbZgk+F3oU6JZ7V1Icmc9DzPN2XHGc/i1m4FH+S4zPotHd3NmB3A==} + peerDependencies: + astro: ^5.0.0 || ^6.0.0 || ^7.0.0 + astro@7.4.13: resolution: {integrity: sha512-tcpMXEB9jypYzbnzT/g6yxL0jRkFlj3WsvxcWgsxRjPBUE6r81qLo/7kN5GMWz6hC7spzrg6fvCeL2HG0Bl68g==} engines: {node: '>=22.23.4', npm: '>=9.6.5', pnpm: '>=7.1.0'} @@ -3395,6 +3415,9 @@ packages: resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==} engines: {node: 18 || 20 || >=22} + base-64@1.0.0: + resolution: {integrity: sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==} + base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} @@ -3458,6 +3481,9 @@ packages: caniuse-lite@1.0.30001690: resolution: {integrity: sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==} + canvaskit-wasm@0.42.0: + resolution: {integrity: sha512-N3ikotmzYwDVAcpQKDMptBT2P5pIEWS9ywdmrQA2awwaMF9cxKEFuxZZHv9ay1Em9kDjxDsPtwUzDm1uNj136g==} + ccount@2.0.1: resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==} @@ -3783,6 +3809,10 @@ packages: resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} engines: {node: '>=8'} + deterministic-object-hash@2.0.2: + resolution: {integrity: sha512-KxektNH63SrbfUyDiwXqRb1rLwKt33AmMv+5Nhsw1kqZ13SJBRTgZHtGbE+hH3a1mVW1cz+4pqSWVPAtLVXTzQ==} + engines: {node: '>=18'} + devalue@6.0.4: resolution: {integrity: sha512-8L3d5HaKt6/wnWKRtwmJu7qrLM6YiGb6mxktIFfgjQzQzIAR5vAZdHioZv/252Pp4SN/xu47oxe7RlwoZzWTTA==} engines: {node: '>=18'} @@ -7142,6 +7172,8 @@ snapshots: '@faker-js/faker@10.6.0': {} + '@fontsource/inter@5.3.0': {} + '@humanfs/core@0.19.2': dependencies: '@humanfs/types': 0.15.0 @@ -8498,6 +8530,8 @@ snapshots: '@webcontainer/env@1.1.1': {} + '@webgpu/types@0.1.21': {} + acorn-jsx@5.3.2(acorn@8.19.0): dependencies: acorn: 8.19.0 @@ -8590,6 +8624,13 @@ snapshots: rehype-expressive-code: 0.44.4 url-extras: 0.1.0 + astro-og-canvas@0.13.3(astro@7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1)): + dependencies: + astro: 7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1) + canvaskit-wasm: 0.42.0 + deterministic-object-hash: 2.0.2 + entities: 9.0.0 + astro@7.4.13(@astrojs/markdown-remark@7.3.10(supports-color@7.2.0))(@types/node@26.6.11)(jiti@2.4.2)(terser@5.37.0)(yaml@2.9.1): dependencies: '@astrojs/compiler-rs': 0.5.3 @@ -8693,6 +8734,8 @@ snapshots: balanced-match@4.0.4: {} + base-64@1.0.0: {} + base64-js@1.5.1: {} bcp-47-match@2.0.3: {} @@ -8767,6 +8810,10 @@ snapshots: caniuse-lite@1.0.30001690: {} + canvaskit-wasm@0.42.0: + dependencies: + '@webgpu/types': 0.1.21 + ccount@2.0.1: {} chai@5.3.3: @@ -9086,6 +9133,10 @@ snapshots: detect-libc@2.1.2: {} + deterministic-object-hash@2.0.2: + dependencies: + base-64: 1.0.0 + devalue@6.0.4: {} devlop@1.1.0: diff --git a/website/astro.config.js b/website/astro.config.js index d7f2f0d08..5ede80458 100644 --- a/website/astro.config.js +++ b/website/astro.config.js @@ -106,6 +106,7 @@ export default defineConfig({ PageSidebar: './src/components/PageSidebar.astro', Footer: './src/components/Footer.astro' }, + routeMiddleware: './src/routeData.ts', plugins: [ llmsTxt({ projectName: 'react-chartjs-2', diff --git a/website/oxlint.config.ts b/website/oxlint.config.ts index 44931ea00..37ca2628d 100644 --- a/website/oxlint.config.ts +++ b/website/oxlint.config.ts @@ -18,6 +18,13 @@ export default defineConfig({ 'eslint/no-implicit-globals': 'off' } }, + { + // The design of the social images: colors and sizes are data + files: ['src/pages/og/**'], + rules: { + 'eslint/no-magic-numbers': 'off' + } + }, { // Served as is: a classic service worker script, not a module files: ['public/**'], diff --git a/website/package.json b/website/package.json index cac180d5c..6d248ff16 100644 --- a/website/package.json +++ b/website/package.json @@ -28,7 +28,10 @@ "@astrojs/check": "^0.9.12", "@astrojs/markdown-remark": "^7.3.10", "@astrojs/starlight": "^0.43.2", + "@fontsource/inter": "^5.3.0", "astro": "^7.4.13", + "astro-og-canvas": "^0.13.3", + "canvaskit-wasm": "^0.42.0", "react-docgen-typescript": "^2.4.0", "starlight-llms-txt": "^0.12.0" }, diff --git a/website/src/assets/og-logo.png b/website/src/assets/og-logo.png new file mode 100644 index 000000000..c7ebf8ced Binary files /dev/null and b/website/src/assets/og-logo.png differ diff --git a/website/src/content/docs/components/bar.mdx b/website/src/content/docs/components/bar.mdx index e82e65daa..7ee7a7509 100644 --- a/website/src/content/docs/components/bar.mdx +++ b/website/src/content/docs/components/bar.mdx @@ -1,6 +1,9 @@ --- title: "Bar" -description: "Description of Bar component from react-chartjs-2." +description: "The Bar component of react-chartjs-2 renders a Chart.js bar chart in React: vertical, horizontal, stacked or grouped. See how to use it, its props and examples." +head: + - tag: title + content: "Bar: React Bar Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/bubble.mdx b/website/src/content/docs/components/bubble.mdx index e4685764c..b4caddb2c 100644 --- a/website/src/content/docs/components/bubble.mdx +++ b/website/src/content/docs/components/bubble.mdx @@ -1,6 +1,9 @@ --- title: "Bubble" -description: "Description of Bubble component from react-chartjs-2." +description: "The Bubble component of react-chartjs-2 renders a Chart.js bubble chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "Bubble: React Bubble Chart Component | react-chartjs-2" next: false --- diff --git a/website/src/content/docs/components/chart.mdx b/website/src/content/docs/components/chart.mdx index aaef14878..52f8bcaad 100644 --- a/website/src/content/docs/components/chart.mdx +++ b/website/src/content/docs/components/chart.mdx @@ -1,6 +1,9 @@ --- title: "Chart" -description: "Description of Chart component from react-chartjs-2." +description: "The Chart component of react-chartjs-2 renders a Chart.js chart of any type in React, mixed charts included. See how to use it, its props and examples." +head: + - tag: title + content: "Chart: React Component for Any Chart Type | react-chartjs-2" prev: Components --- diff --git a/website/src/content/docs/components/doughnut.mdx b/website/src/content/docs/components/doughnut.mdx index bc4605a6a..450a3ab5e 100644 --- a/website/src/content/docs/components/doughnut.mdx +++ b/website/src/content/docs/components/doughnut.mdx @@ -1,6 +1,9 @@ --- title: "Doughnut" -description: "Description of Doughnut component from react-chartjs-2." +description: "The Doughnut component of react-chartjs-2 renders a Chart.js doughnut chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "Doughnut: React Doughnut Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/index.md b/website/src/content/docs/components/index.md index 9d57111a9..c39908ab5 100644 --- a/website/src/content/docs/components/index.md +++ b/website/src/content/docs/components/index.md @@ -1,6 +1,9 @@ --- title: "Components" -description: "List of react-chartjs-2 components." +description: "react-chartjs-2 has a Chart component for any Chart.js chart and typed components for bar, line, pie, doughnut, polar area, radar, scatter and bubble charts." +head: + - tag: title + content: "React Chart Components | react-chartjs-2" prev: false --- diff --git a/website/src/content/docs/components/line.mdx b/website/src/content/docs/components/line.mdx index 142a54f2a..c08175d44 100644 --- a/website/src/content/docs/components/line.mdx +++ b/website/src/content/docs/components/line.mdx @@ -1,6 +1,9 @@ --- title: "Line" -description: "Description of Line component from react-chartjs-2." +description: "The Line component of react-chartjs-2 renders a Chart.js line chart in React, area and multi-axis charts included. See how to use it, its props and examples." +head: + - tag: title + content: "Line: React Line Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/pie.mdx b/website/src/content/docs/components/pie.mdx index d16a570df..9beba4637 100644 --- a/website/src/content/docs/components/pie.mdx +++ b/website/src/content/docs/components/pie.mdx @@ -1,6 +1,9 @@ --- title: "Pie" -description: "Description of Pie component from react-chartjs-2." +description: "The Pie component of react-chartjs-2 renders a Chart.js pie chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "Pie: React Pie Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/polar-area.mdx b/website/src/content/docs/components/polar-area.mdx index 2e450d1cb..e3592580b 100644 --- a/website/src/content/docs/components/polar-area.mdx +++ b/website/src/content/docs/components/polar-area.mdx @@ -1,6 +1,9 @@ --- title: "PolarArea" -description: "Description of PolarArea component from react-chartjs-2." +description: "The PolarArea component of react-chartjs-2 renders a Chart.js polar area chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "PolarArea: React Polar Area Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/radar.mdx b/website/src/content/docs/components/radar.mdx index 9b204b943..037a8c31f 100644 --- a/website/src/content/docs/components/radar.mdx +++ b/website/src/content/docs/components/radar.mdx @@ -1,6 +1,9 @@ --- title: "Radar" -description: "Description of Radar component from react-chartjs-2." +description: "The Radar component of react-chartjs-2 renders a Chart.js radar chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "Radar: React Radar Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/components/scatter.mdx b/website/src/content/docs/components/scatter.mdx index cc3dabcef..965a83772 100644 --- a/website/src/content/docs/components/scatter.mdx +++ b/website/src/content/docs/components/scatter.mdx @@ -1,6 +1,9 @@ --- title: "Scatter" -description: "Description of Scatter component from react-chartjs-2." +description: "The Scatter component of react-chartjs-2 renders a Chart.js scatter chart in React. See how to use it, its props and an example." +head: + - tag: title + content: "Scatter: React Scatter Chart Component | react-chartjs-2" --- import PropsTable from '../../../components/PropsTable.astro' diff --git a/website/src/content/docs/docs/chartjs-v2.mdx b/website/src/content/docs/docs/chartjs-v2.mdx index e0ec5bc69..3402621ea 100644 --- a/website/src/content/docs/docs/chartjs-v2.mdx +++ b/website/src/content/docs/docs/chartjs-v2.mdx @@ -1,6 +1,6 @@ --- title: "Using with Chart.js v2" -description: "Using react-chartjs-2 with Chart.js v2" +description: "Install the react-chartjs-2 version that works with Chart.js v2, or upgrade to Chart.js v3 and react-chartjs-2 v4." next: false --- diff --git a/website/src/content/docs/docs/chartjs-v3.mdx b/website/src/content/docs/docs/chartjs-v3.mdx index a3ad7b02a..ff9fa31ca 100644 --- a/website/src/content/docs/docs/chartjs-v3.mdx +++ b/website/src/content/docs/docs/chartjs-v3.mdx @@ -1,6 +1,6 @@ --- title: "Using with Chart.js v3" -description: "Using react-chartjs-2 with Chart.js v3" +description: "Install the react-chartjs-2 version that works with Chart.js v3, or upgrade to Chart.js v4 and react-chartjs-2 v5." --- import { Tabs, TabItem } from '@astrojs/starlight/components' diff --git a/website/src/content/docs/docs/migration-to-v4.md b/website/src/content/docs/docs/migration-to-v4.md index 37d8d4b6a..0f49d250e 100644 --- a/website/src/content/docs/docs/migration-to-v4.md +++ b/website/src/content/docs/docs/migration-to-v4.md @@ -1,6 +1,6 @@ --- title: "Migration to v4" -description: "react-chartjs-2 migration guide to v4" +description: "Migrate to react-chartjs-2 v4 for Chart.js v3: new exports, tree-shaking, gradients without a data function and helpers for click events." --- With v4, this library introduces a number of breaking changes. In order to improve performance, offer new features, and improve maintainability, it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit. diff --git a/website/src/content/docs/docs/migration-to-v5.md b/website/src/content/docs/docs/migration-to-v5.md index f4fd3fb39..13d0c866a 100644 --- a/website/src/content/docs/docs/migration-to-v5.md +++ b/website/src/content/docs/docs/migration-to-v5.md @@ -1,6 +1,6 @@ --- title: "Migration to v5" -description: "react-chartjs-2 migration guide to v5" +description: "Migrate to react-chartjs-2 v5 for Chart.js v4: v5.0 is ESM only, and v5.1 supports CommonJS again." --- ## v5.0 diff --git a/website/src/content/docs/docs/working-with-datasets.md b/website/src/content/docs/docs/working-with-datasets.md index dd1e91fdc..0ce7a11da 100644 --- a/website/src/content/docs/docs/working-with-datasets.md +++ b/website/src/content/docs/docs/working-with-datasets.md @@ -1,6 +1,6 @@ --- title: "Working with datasets" -description: "Working with datasets in react-chartjs-2" +description: "Keep the datasets of a react-chartjs-2 chart from merging on updates: give each dataset a label, or a key of your own with the datasetIdKey prop." --- You will find that any event which causes the chart to re-render, such as hover tooltips, etc., will cause the first dataset to be copied over to other datasets, causing your lines and bars to merge together. diff --git a/website/src/content/docs/docs/working-with-events.md b/website/src/content/docs/docs/working-with-events.md index 082ccf2a1..82c4c6763 100644 --- a/website/src/content/docs/docs/working-with-events.md +++ b/website/src/content/docs/docs/working-with-events.md @@ -1,6 +1,6 @@ --- title: "Working with events" -description: "Working with events in react-chartjs-2" +description: "Get the dataset or the elements under a click on a react-chartjs-2 chart with the getDatasetAtEvent, getElementAtEvent and getElementsAtEvent helpers." --- There are three helper methods to get data from click event. diff --git a/website/src/content/docs/examples/area-chart.mdx b/website/src/content/docs/examples/area-chart.mdx index be91a13e5..8913076b9 100644 --- a/website/src/content/docs/examples/area-chart.mdx +++ b/website/src/content/docs/examples/area-chart.mdx @@ -1,6 +1,9 @@ --- title: "Area Chart" -description: "Example of area chart in react-chartjs-2." +description: "An area chart in React with react-chartjs-2 and Chart.js: a line chart with the area under the line filled. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Area Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/bubble-chart.mdx b/website/src/content/docs/examples/bubble-chart.mdx index 63be582e4..8fbb8b88e 100644 --- a/website/src/content/docs/examples/bubble-chart.mdx +++ b/website/src/content/docs/examples/bubble-chart.mdx @@ -1,6 +1,9 @@ --- title: "Bubble Chart" -description: "Example of bubble chart in react-chartjs-2." +description: "A bubble chart in React with react-chartjs-2 and Chart.js: two datasets of points with x, y and a radius. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Bubble Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/chart-events.mdx b/website/src/content/docs/examples/chart-events.mdx index dc9950595..582880a1a 100644 --- a/website/src/content/docs/examples/chart-events.mdx +++ b/website/src/content/docs/examples/chart-events.mdx @@ -1,6 +1,9 @@ --- title: "Chart Events" -description: "Example of events in react-chartjs-2." +description: "Handle clicks on a chart in React with react-chartjs-2: get the dataset and the elements under the click with getElementAtEvent and other helpers." +head: + - tag: title + content: "React Chart Click Events Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/chart-ref.mdx b/website/src/content/docs/examples/chart-ref.mdx index c4fe07b0a..54c148734 100644 --- a/website/src/content/docs/examples/chart-ref.mdx +++ b/website/src/content/docs/examples/chart-ref.mdx @@ -2,7 +2,10 @@ title: "Get Chart Ref" sidebar: label: "Chart Ref" -description: "Example of getting ref in react-chartjs-2." +description: "Get the Chart.js instance of a chart in React with a ref and react-chartjs-2, and show a tooltip from code. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Chart Ref Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/doughnut-chart.mdx b/website/src/content/docs/examples/doughnut-chart.mdx index 4db2cd4fd..9136e1676 100644 --- a/website/src/content/docs/examples/doughnut-chart.mdx +++ b/website/src/content/docs/examples/doughnut-chart.mdx @@ -1,6 +1,9 @@ --- title: "Doughnut Chart" -description: "Example of doughnut chart in react-chartjs-2." +description: "A doughnut chart in React with react-chartjs-2 and Chart.js: one dataset with a color for each segment. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Doughnut Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/gradient-chart.mdx b/website/src/content/docs/examples/gradient-chart.mdx index 75b6a6691..872740b66 100644 --- a/website/src/content/docs/examples/gradient-chart.mdx +++ b/website/src/content/docs/examples/gradient-chart.mdx @@ -1,6 +1,9 @@ --- title: "Gradient Chart" -description: "Example of creating gradient chart in react-chartjs-2." +description: "Gradient lines on a line chart in React with react-chartjs-2, made from the canvas context and the chart area. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Gradient Line Chart Example | react-chartjs-2" next: false --- diff --git a/website/src/content/docs/examples/grouped-bar-chart.mdx b/website/src/content/docs/examples/grouped-bar-chart.mdx index 7fae037aa..a45339e35 100644 --- a/website/src/content/docs/examples/grouped-bar-chart.mdx +++ b/website/src/content/docs/examples/grouped-bar-chart.mdx @@ -1,6 +1,9 @@ --- title: "Grouped Bar Chart" -description: "Example of grouped bar chart in react-chartjs-2." +description: "A grouped bar chart in React with react-chartjs-2 and Chart.js: the stack option of datasets puts the bars into groups. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Grouped Bar Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/horizontal-bar-chart.mdx b/website/src/content/docs/examples/horizontal-bar-chart.mdx index aa0cd8893..2e9e3c46c 100644 --- a/website/src/content/docs/examples/horizontal-bar-chart.mdx +++ b/website/src/content/docs/examples/horizontal-bar-chart.mdx @@ -1,6 +1,9 @@ --- title: "Horizontal Bar Chart" -description: "Example of horizontal bar chart in react-chartjs-2." +description: "A horizontal bar chart in React with react-chartjs-2 and Chart.js: the indexAxis option lays the bars along the y-axis. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Horizontal Bar Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/index.md b/website/src/content/docs/examples/index.md index b59665019..f5717d930 100644 --- a/website/src/content/docs/examples/index.md +++ b/website/src/content/docs/examples/index.md @@ -1,6 +1,9 @@ --- title: "Examples" -description: "List of react-chartjs-2 usage examples." +description: "Live examples of react-chartjs-2: bar, line, area, pie, doughnut, polar area, radar, scatter, bubble and mixed charts in React, with code to edit in StackBlitz." +head: + - tag: title + content: "React Chart Examples | react-chartjs-2" prev: false --- diff --git a/website/src/content/docs/examples/line-chart.mdx b/website/src/content/docs/examples/line-chart.mdx index 17f4c241b..95c9f0f7d 100644 --- a/website/src/content/docs/examples/line-chart.mdx +++ b/website/src/content/docs/examples/line-chart.mdx @@ -1,6 +1,9 @@ --- title: "Line Chart" -description: "Example of line chart in react-chartjs-2." +description: "A line chart in React with react-chartjs-2 and Chart.js: two datasets by month, a legend and a title. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Line Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/multiaxis-line-chart.mdx b/website/src/content/docs/examples/multiaxis-line-chart.mdx index 5430a0d3a..e990772ab 100644 --- a/website/src/content/docs/examples/multiaxis-line-chart.mdx +++ b/website/src/content/docs/examples/multiaxis-line-chart.mdx @@ -1,6 +1,9 @@ --- title: "Multiaxis Line Chart" -description: "Example of multiaxis line chart in react-chartjs-2." +description: "A line chart with two y-axes in React with react-chartjs-2 and Chart.js: each dataset has a scale of its own. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Multi-Axis Line Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/multitype-chart.mdx b/website/src/content/docs/examples/multitype-chart.mdx index 09214bac2..b80bb6175 100644 --- a/website/src/content/docs/examples/multitype-chart.mdx +++ b/website/src/content/docs/examples/multitype-chart.mdx @@ -1,6 +1,9 @@ --- title: "Multitype Chart" -description: "Example of multitype chart in react-chartjs-2." +description: "A mixed chart in React with react-chartjs-2 and Chart.js: a line dataset and two bar datasets in one chart. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Mixed Chart Example: Bar and Line | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/pie-chart.mdx b/website/src/content/docs/examples/pie-chart.mdx index 6339f6f1d..fd8332b39 100644 --- a/website/src/content/docs/examples/pie-chart.mdx +++ b/website/src/content/docs/examples/pie-chart.mdx @@ -1,6 +1,9 @@ --- title: "Pie Chart" -description: "Example of pie chart in react-chartjs-2." +description: "A pie chart in React with react-chartjs-2 and Chart.js: one dataset with a color for each slice. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Pie Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/polar-area-chart.mdx b/website/src/content/docs/examples/polar-area-chart.mdx index 8b0a9ee10..64ce538a7 100644 --- a/website/src/content/docs/examples/polar-area-chart.mdx +++ b/website/src/content/docs/examples/polar-area-chart.mdx @@ -1,6 +1,9 @@ --- title: "Polar Area Chart" -description: "Example of polar area chart in react-chartjs-2." +description: "A polar area chart in React with react-chartjs-2 and Chart.js: segments of the same angle with a radius by value. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Polar Area Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/radar-chart.mdx b/website/src/content/docs/examples/radar-chart.mdx index ed581a2eb..55a2ce877 100644 --- a/website/src/content/docs/examples/radar-chart.mdx +++ b/website/src/content/docs/examples/radar-chart.mdx @@ -1,6 +1,9 @@ --- title: "Radar Chart" -description: "Example of radar chart in react-chartjs-2." +description: "A radar chart in React with react-chartjs-2 and Chart.js: one dataset over six labels. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Radar Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/scatter-chart.mdx b/website/src/content/docs/examples/scatter-chart.mdx index a5b2aa647..ca325e1ca 100644 --- a/website/src/content/docs/examples/scatter-chart.mdx +++ b/website/src/content/docs/examples/scatter-chart.mdx @@ -1,6 +1,9 @@ --- title: "Scatter Chart" -description: "Example of scatter chart in react-chartjs-2." +description: "A scatter chart in React with react-chartjs-2 and Chart.js: a hundred points with x and y values. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Scatter Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/stacked-bar-chart.mdx b/website/src/content/docs/examples/stacked-bar-chart.mdx index 0771c5194..17e782ff4 100644 --- a/website/src/content/docs/examples/stacked-bar-chart.mdx +++ b/website/src/content/docs/examples/stacked-bar-chart.mdx @@ -1,6 +1,9 @@ --- title: "Stacked Bar Chart" -description: "Example of stacked bar chart in react-chartjs-2." +description: "A stacked bar chart in React with react-chartjs-2 and Chart.js: three datasets stacked on both scales. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Stacked Bar Chart Example | react-chartjs-2" --- import Example from '../../../components/Example.astro' diff --git a/website/src/content/docs/examples/vertical-bar-chart.mdx b/website/src/content/docs/examples/vertical-bar-chart.mdx index e04a128e7..33a4e1186 100644 --- a/website/src/content/docs/examples/vertical-bar-chart.mdx +++ b/website/src/content/docs/examples/vertical-bar-chart.mdx @@ -1,6 +1,9 @@ --- title: "Vertical Bar Chart" -description: "Example of vertical bar chart in react-chartjs-2." +description: "A vertical bar chart in React with react-chartjs-2 and Chart.js: two datasets by month, a legend and a title. See it live and edit it in StackBlitz." +head: + - tag: title + content: "React Vertical Bar Chart Example | react-chartjs-2" prev: Examples --- diff --git a/website/src/content/docs/faq/index.md b/website/src/content/docs/faq/index.md index 7128e5603..2cac5c6c3 100644 --- a/website/src/content/docs/faq/index.md +++ b/website/src/content/docs/faq/index.md @@ -1,6 +1,6 @@ --- title: "FAQ" -description: "Frequently asked questions about react-chartjs-2." +description: "Answers to frequent questions about react-chartjs-2: the size of a chart, the Chart.js instance, plugins, registration errors, TypeScript and ES modules." prev: false --- diff --git a/website/src/pages/og/[...slug].png.ts b/website/src/pages/og/[...slug].png.ts new file mode 100644 index 000000000..c11a8ce04 --- /dev/null +++ b/website/src/pages/og/[...slug].png.ts @@ -0,0 +1,48 @@ +import { getCollection } from 'astro:content' +import { OGImageRoute } from 'astro-og-canvas' + +const font = './node_modules/@fontsource/inter/files/inter-latin' +const pages = await getCollection('docs') + +// Word joiners keep the name of the package on one line: Inter has no non-breaking hyphen +function keepName(text: string) { + return text.replaceAll('react-chartjs-2', 'react\u2060-\u2060chartjs\u2060-\u20602') +} + +// The image that social networks and chats show for a link to a page, at /og/.png +export const { getStaticPaths, GET } = await OGImageRoute({ + pages: Object.fromEntries(pages.map(({ id, data }) => [id, data])), + // The route has the extension, so `trailingSlash` does not apply to it + getSlug: id => id, + getImageOptions: (_id, { title, description = '' }) => ({ + title: keepName(title), + description: keepName(description), + // CanvasKit draws no SVG, so this is src/assets/logo.svg at the size the image shows it + logo: { + path: './src/assets/og-logo.png' + }, + // The background and the accent of the dark theme + bgGradient: [[23, 24, 28], [31, 29, 92]], + border: { + color: [122, 119, 255], + width: 12 + }, + // The longest titles of the FAQ with their descriptions fit in the image with these sizes + padding: 64, + font: { + title: { + size: 64, + lineHeight: 1.15, + weight: 'Bold', + families: ['Inter'] + }, + description: { + color: [191, 193, 201], + size: 32, + lineHeight: 1.4, + families: ['Inter'] + } + }, + fonts: [`${font}-700-normal.woff2`, `${font}-400-normal.woff2`] + }) +}) diff --git a/website/src/routeData.ts b/website/src/routeData.ts new file mode 100644 index 000000000..f674c3a52 --- /dev/null +++ b/website/src/routeData.ts @@ -0,0 +1,21 @@ +import { defineRouteMiddleware } from '@astrojs/starlight/route-data' + +export const onRequest = defineRouteMiddleware(({ locals, site }) => { + const { id, head } = locals.starlightRoute + + // The 404 page of Starlight is not in the collection, so src/pages/og has no image for it + if (id === '404') { + return + } + + // The home page has the id `index` in the collection + const image = new URL(`/og/${id || 'index'}.png`, site).href + + head.push({ + tag: 'meta', + attrs: { + property: 'og:image', + content: image + } + }) +})