From 9419d8aa62e46aff6da15e7b0e26941f684b0b5d Mon Sep 17 00:00:00 2001 From: robertsavian Date: Tue, 24 Nov 2020 22:03:53 -0600 Subject: [PATCH 01/16] Add Anychart --- next-env.d.ts | 1 + next.config.js | 7 ++ package.json | 2 + src/components/pages/about-page/AboutPage.tsx | 2 + src/components/pages/index-page/IndexPage.tsx | 2 + .../ui/pie-chart/PieChart.dynamic.tsx | 6 + src/components/ui/pie-chart/PieChart.tsx | 26 ++++ .../SimpleBarChart.dynamic.tsx | 7 ++ .../ui/simple-bar-chart/SimpleBarChart.tsx | 28 +++++ .../simple-bar-chart/SimpleBarChart.utils.ts | 15 +++ src/pages/_document.tsx | 1 + src/types/anychart-react.d.ts | 1 + yarn.lock | 116 +++++++++++++++++- 13 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 src/components/ui/pie-chart/PieChart.dynamic.tsx create mode 100644 src/components/ui/pie-chart/PieChart.tsx create mode 100644 src/components/ui/simple-bar-chart/SimpleBarChart.dynamic.tsx create mode 100644 src/components/ui/simple-bar-chart/SimpleBarChart.tsx create mode 100644 src/components/ui/simple-bar-chart/SimpleBarChart.utils.ts create mode 100644 src/types/anychart-react.d.ts diff --git a/next-env.d.ts b/next-env.d.ts index 7b7aa2c..ab21f42 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,2 +1,3 @@ /// /// +/// diff --git a/next.config.js b/next.config.js index 2507e1b..553e63b 100644 --- a/next.config.js +++ b/next.config.js @@ -20,6 +20,13 @@ module.exports = withPlugins( // https://blog.usejournal.com/my-awesome-custom-react-environment-variables-setup-8ebb0797d8ac config.resolve.alias['environment'] = path.join(__dirname, 'src', 'environments', clientEnv); + config.externals = [ + ...config.externals, + { + anychart: 'anychart', + }, + ]; + return config; }, } diff --git a/package.json b/package.json index c9ec0d6..462a39c 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "-----------------------------------------------------------------------": "" }, "dependencies": { + "anychart": "8.9.0", + "anychart-react": "1.4.1", "axios": "0.21.0", "next": "10.0.2", "react": "17.0.1", diff --git a/src/components/pages/about-page/AboutPage.tsx b/src/components/pages/about-page/AboutPage.tsx index dc81af1..b59ba8f 100644 --- a/src/components/pages/about-page/AboutPage.tsx +++ b/src/components/pages/about-page/AboutPage.tsx @@ -1,6 +1,7 @@ import React from 'react'; import Link from 'next/link'; import { Routes } from '../../../constants/Routes'; +import { PieChartDynamic } from '../../ui/pie-chart/PieChart.dynamic'; interface IProps {} @@ -14,6 +15,7 @@ export const AboutPage: React.FC = (props) => { Go home

+ ); }; diff --git a/src/components/pages/index-page/IndexPage.tsx b/src/components/pages/index-page/IndexPage.tsx index 5f38c4e..757d27d 100644 --- a/src/components/pages/index-page/IndexPage.tsx +++ b/src/components/pages/index-page/IndexPage.tsx @@ -1,6 +1,7 @@ import React from 'react'; import Link from 'next/link'; import { Routes } from '../../../constants/Routes'; +import { SimpleBarChartDynamic } from '../../ui/simple-bar-chart/SimpleBarChart.dynamic'; interface IProps {} @@ -13,6 +14,7 @@ export const IndexPage: React.FC = (props) => { About

+ ); }; diff --git a/src/components/ui/pie-chart/PieChart.dynamic.tsx b/src/components/ui/pie-chart/PieChart.dynamic.tsx new file mode 100644 index 0000000..5d811a7 --- /dev/null +++ b/src/components/ui/pie-chart/PieChart.dynamic.tsx @@ -0,0 +1,6 @@ +import dynamic from 'next/dynamic'; +import { PieChart } from './PieChart'; + +export const PieChartDynamic = dynamic(() => import('./PieChart').then((mod) => mod.PieChart as any), { + ssr: false, +}) as typeof PieChart; diff --git a/src/components/ui/pie-chart/PieChart.tsx b/src/components/ui/pie-chart/PieChart.tsx new file mode 100644 index 0000000..c0100de --- /dev/null +++ b/src/components/ui/pie-chart/PieChart.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import AnyChart from 'anychart-react'; + +interface IProps { + chartId: string; + data: number[]; + height?: number | string; + title: string; + width?: number | string; +} + +export const PieChart: React.FC = (props) => { + return ( + + ); +}; + +PieChart.defaultProps = {}; diff --git a/src/components/ui/simple-bar-chart/SimpleBarChart.dynamic.tsx b/src/components/ui/simple-bar-chart/SimpleBarChart.dynamic.tsx new file mode 100644 index 0000000..85471e8 --- /dev/null +++ b/src/components/ui/simple-bar-chart/SimpleBarChart.dynamic.tsx @@ -0,0 +1,7 @@ +import dynamic from 'next/dynamic'; +import { SimpleBarChart } from './SimpleBarChart'; + +export const SimpleBarChartDynamic = dynamic( + () => import('./SimpleBarChart').then((mod) => mod.SimpleBarChart as any), + { ssr: false } +) as typeof SimpleBarChart; diff --git a/src/components/ui/simple-bar-chart/SimpleBarChart.tsx b/src/components/ui/simple-bar-chart/SimpleBarChart.tsx new file mode 100644 index 0000000..670afa2 --- /dev/null +++ b/src/components/ui/simple-bar-chart/SimpleBarChart.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { getChart } from './SimpleBarChart.utils'; +import AnyChart from 'anychart-react'; + +interface IProps { + chartId: string; + // data: number[]; + height?: number | string; + title: string; + width?: number | string; +} + +export const SimpleBarChart: React.FC = (props) => { + const chart = getChart(); + + return ( + + ); +}; diff --git a/src/components/ui/simple-bar-chart/SimpleBarChart.utils.ts b/src/components/ui/simple-bar-chart/SimpleBarChart.utils.ts new file mode 100644 index 0000000..af1af15 --- /dev/null +++ b/src/components/ui/simple-bar-chart/SimpleBarChart.utils.ts @@ -0,0 +1,15 @@ +export const getChart = () => { + const stage = anychart.graphics.create(); + + const chart1 = anychart.line([1, 2, 3]); + + chart1.bounds(0, 0, '100%', '50%'); + + const chart2 = anychart.column(); + + chart2.column([3, 2, 1]); + chart2.line([3, 5, 6]); + chart2.bounds(0, '50%', '100%', '50%'); + + return { stage, data: [chart1, chart2] }; +}; diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 68fd3b8..a07129e 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -15,6 +15,7 @@ class MyDocument extends Document { +