Compare commits
12 Commits
3070e058f8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
24d3fe60f4
|
|||
|
ab50c04230
|
|||
|
e3d5cedc1d
|
|||
|
55e9969a8c
|
|||
| 6fa5c18049 | |||
| c2929bc130 | |||
| c0ea356afd | |||
| ced3c05e88 | |||
| 0e2859e825 | |||
| a5014fa5f4 | |||
| eafcd57cc8 | |||
| 43570ccdda |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -10,4 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
# Error File
|
# Error File
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
|
||||||
|
build
|
||||||
|
dist
|
||||||
15
.npmignore
15
.npmignore
@@ -8,3 +8,18 @@
|
|||||||
# Lock File
|
# Lock File
|
||||||
yarn.lock
|
yarn.lock
|
||||||
package.lock.json
|
package.lock.json
|
||||||
|
examples
|
||||||
|
test
|
||||||
|
jest.config.js
|
||||||
|
yarn-error.log
|
||||||
|
.eslintrc.js
|
||||||
|
.prettierrc.js
|
||||||
|
.stylelintrc.js
|
||||||
|
.babelrc
|
||||||
|
.eslintignore
|
||||||
|
.prettierignore
|
||||||
|
.stylelintignore
|
||||||
|
.gitignore
|
||||||
|
.gitattributes
|
||||||
|
.editorconfig
|
||||||
|
.env
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
Using NPM
|
Using NPM
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
npm add @cubetiq/react-chart-js
|
npm install @cubetiq/react-chart-js
|
||||||
```
|
```
|
||||||
|
|
||||||
OR using Yarn
|
OR using Yarn
|
||||||
@@ -14,7 +14,8 @@ OR using Yarn
|
|||||||
yarn add @cubetiq/react-chart-js
|
yarn add @cubetiq/react-chart-js
|
||||||
```
|
```
|
||||||
|
|
||||||
### Link to examples: [https://git.cubetiqs.com/CUBETIQ/react-chart-js/src/branch/master/examples/line-chart-example](https://git.cubetiqs.com/CUBETIQ/react-chart-js/src/branch/master/examples/line-chart-example)
|
|
||||||
|
### View a [Demo](https://cubetiq.github.io/chartjs-demos)
|
||||||
|
|
||||||
### Line Chart Example
|
### Line Chart Example
|
||||||
```typescript
|
```typescript
|
||||||
|
|||||||
8
dist/ReactChartJs.d.ts
vendored
8
dist/ReactChartJs.d.ts
vendored
@@ -1,8 +0,0 @@
|
|||||||
import { ChartConfiguration } from 'chart.js';
|
|
||||||
import { FunctionComponent } from 'react';
|
|
||||||
interface ReactChartJSProps {
|
|
||||||
chartConfig?: ChartConfiguration;
|
|
||||||
}
|
|
||||||
declare const ReactChartJs: FunctionComponent<ReactChartJSProps>;
|
|
||||||
export default ReactChartJs;
|
|
||||||
//# sourceMappingURL=ReactChartJs.d.ts.map
|
|
||||||
1
dist/ReactChartJs.d.ts.map
vendored
1
dist/ReactChartJs.d.ts.map
vendored
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"ReactChartJs.d.ts","sourceRoot":"","sources":["../src/ReactChartJs.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAc,EAAE,iBAAiB,EAAqB,MAAM,OAAO,CAAC;AAEpE,UAAU,iBAAiB;IACvB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAMD,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA4BtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
||||||
41
dist/ReactChartJs.js
vendored
41
dist/ReactChartJs.js
vendored
@@ -1,41 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
||||||
}) : (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
o[k2] = m[k];
|
|
||||||
}));
|
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
||||||
}) : function(o, v) {
|
|
||||||
o["default"] = v;
|
|
||||||
});
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
var chart_js_1 = require("chart.js");
|
|
||||||
var react_1 = __importStar(require("react"));
|
|
||||||
var ReactChartJs = function (props) {
|
|
||||||
var chartConfig = props.chartConfig;
|
|
||||||
var canvasDomRef = react_1.useRef();
|
|
||||||
var chartInstanceRef = react_1.useRef({});
|
|
||||||
react_1.useEffect(function () {
|
|
||||||
var canvasDom = canvasDomRef.current;
|
|
||||||
var chartInstance = chartInstanceRef.current.chartInstance;
|
|
||||||
if (chartInstance) {
|
|
||||||
chartInstance.destroy();
|
|
||||||
}
|
|
||||||
chartInstanceRef.current.chartInstance = new chart_js_1.Chart(canvasDom, chartConfig);
|
|
||||||
}, [chartConfig]);
|
|
||||||
return (react_1.default.createElement("div", null,
|
|
||||||
react_1.default.createElement("canvas", { ref: function (instance) {
|
|
||||||
canvasDomRef.current = instance;
|
|
||||||
}, width: "400", height: "200" })));
|
|
||||||
};
|
|
||||||
exports.default = ReactChartJs;
|
|
||||||
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@@ -1,2 +0,0 @@
|
|||||||
export { default as ReactChartJs } from "./ReactChartJs";
|
|
||||||
//# sourceMappingURL=index.d.ts.map
|
|
||||||
1
dist/index.d.ts.map
vendored
1
dist/index.d.ts.map
vendored
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
|
|
||||||
8
dist/index.js
vendored
8
dist/index.js
vendored
@@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.ReactChartJs = void 0;
|
|
||||||
var ReactChartJs_1 = require("./ReactChartJs");
|
|
||||||
Object.defineProperty(exports, "ReactChartJs", { enumerable: true, get: function () { return __importDefault(ReactChartJs_1).default; } });
|
|
||||||
3
examples/line-chart-example/.gitignore
vendored
3
examples/line-chart-example/.gitignore
vendored
@@ -21,3 +21,6 @@
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
|
build
|
||||||
|
dist
|
||||||
@@ -3,16 +3,16 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cubetiq/react-chart-js": "^1.0.0",
|
"@cubetiq/react-chart-js": "^1.1.9",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^9.3.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
"@types/jest": "^24.0.0",
|
"@types/jest": "^24.0.0",
|
||||||
"@types/node": "^12.0.0",
|
"@types/node": "^12.0.0",
|
||||||
"@types/react": "^16.9.0",
|
"@types/react": "^17.0.2",
|
||||||
"@types/react-dom": "^16.9.0",
|
"@types/react-dom": "^17.0.2",
|
||||||
"react": "^16.14.0",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^16.14.0",
|
"react-dom": "^17.0.2",
|
||||||
"react-scripts": "3.4.3",
|
"react-scripts": "3.4.3",
|
||||||
"typescript": "~3.7.2"
|
"typescript": "~3.7.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,38 +5,17 @@ function LineChartExample(props: any) {
|
|||||||
return (
|
return (
|
||||||
<ReactChartJs
|
<ReactChartJs
|
||||||
chartConfig={{
|
chartConfig={{
|
||||||
type: 'line',
|
type: 'pie',
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'Monthly Payments',
|
|
||||||
},
|
|
||||||
tooltips: {
|
|
||||||
mode: 'index',
|
|
||||||
intersect: false,
|
|
||||||
},
|
|
||||||
hover: {
|
|
||||||
mode: 'nearest',
|
|
||||||
intersect: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
|
labels: ['Red', 'Blue', 'Yellow'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Part-time',
|
label: 'My First Dataset',
|
||||||
data: [5, 10, 30],
|
data: [300, 50, 100],
|
||||||
fill: false,
|
backgroundColor: ['rgb(255, 99, 132)', 'rgb(54, 162, 235)', 'rgb(255, 205, 86)'],
|
||||||
borderColor: '#ff6384',
|
hoverOffset: 4,
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Full-time',
|
|
||||||
data: [10, 15, 45],
|
|
||||||
fill: false,
|
|
||||||
borderColor: '#36a2eb',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
labels: ['Jan', 'Feb', 'Mar'],
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cubetiq/react-chart-js",
|
"name": "@cubetiq/react-chart-js",
|
||||||
"version": "1.1.0",
|
"version": "1.1.9",
|
||||||
"description": "Chart.js for React and TypeScript",
|
"description": "Chart.js for React and TypeScript",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
"pub": "npm publish --access public --registry https://registry.npmjs.org",
|
||||||
"build:test": "yarn jest && yarn build",
|
"build:test": "yarn jest && yarn build",
|
||||||
"publish": "npm publish --access public",
|
|
||||||
"run:example": "cd examples/line-chart-example && yarn start"
|
"run:example": "cd examples/line-chart-example && yarn start"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
"@types/chart.js": "^2.9.25",
|
"@types/chart.js": "^2.9.25",
|
||||||
"@types/jest": "^26.0.10",
|
"@types/jest": "^26.0.10",
|
||||||
"@types/node": "^14.6.1",
|
"@types/node": "^14.6.1",
|
||||||
"@types/react": "^16.9.52",
|
"@types/react": "^17.0.34",
|
||||||
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
||||||
"@typescript-eslint/parser": "^3.10.1",
|
"@typescript-eslint/parser": "^3.10.1",
|
||||||
"babel-jest": "^26.3.0",
|
"babel-jest": "^26.3.0",
|
||||||
@@ -52,10 +52,10 @@
|
|||||||
"jest": "^26.4.2",
|
"jest": "^26.4.2",
|
||||||
"lint-staged": "^10.2.13",
|
"lint-staged": "^10.2.13",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"react": "^16.14.0",
|
"react": "^17.0.2",
|
||||||
"ts-jest": "^26.3.0",
|
"ts-jest": "^26.3.0",
|
||||||
"tsc": "^1.20150623.0",
|
"tsc": "^1.20150623.0",
|
||||||
"typescript": "^4.0.2"
|
"typescript": "^4.4.4"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
@@ -71,6 +71,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chart.js": "^2.9.3"
|
"chart.js": "^3.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { Chart, ChartConfiguration } from 'chart.js';
|
import Chart from 'chart.js/auto';
|
||||||
|
import { ChartConfiguration } from 'chart.js';
|
||||||
import React, { FunctionComponent, useEffect, useRef } from 'react';
|
import React, { FunctionComponent, useEffect, useRef } from 'react';
|
||||||
|
|
||||||
interface ReactChartJSProps {
|
interface ReactChartJSProps {
|
||||||
chartConfig?: ChartConfiguration;
|
chartConfig: ChartConfiguration;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
containerProps?: any;
|
||||||
|
canvasProps?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RefForChartInstance {
|
interface RefForChartInstance {
|
||||||
@@ -10,7 +15,7 @@ interface RefForChartInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => {
|
const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => {
|
||||||
const { chartConfig } = props;
|
const { chartConfig, containerProps, canvasProps } = props;
|
||||||
|
|
||||||
const canvasDomRef = useRef<HTMLCanvasElement>();
|
const canvasDomRef = useRef<HTMLCanvasElement>();
|
||||||
|
|
||||||
@@ -27,13 +32,14 @@ const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => {
|
|||||||
}, [chartConfig]);
|
}, [chartConfig]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div {...containerProps}>
|
||||||
<canvas
|
<canvas
|
||||||
ref={(instance: any) => {
|
ref={(instance: any) => {
|
||||||
canvasDomRef.current = instance!;
|
canvasDomRef.current = instance!;
|
||||||
}}
|
}}
|
||||||
width="400"
|
width={props.width || 'auto'}
|
||||||
height="200"
|
height={props.height || 'auto'}
|
||||||
|
{...canvasProps}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user