Compare commits

..

No commits in common. "main" and "master" have entirely different histories.
main ... master

5 changed files with 44 additions and 44 deletions

View File

@ -8,18 +8,3 @@
# 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

View File

@ -3,16 +3,16 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@cubetiq/react-chart-js": "^1.1.9", "@cubetiq/react-chart-js": "^1.0.0",
"@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": "^17.0.2", "@types/react": "^16.9.0",
"@types/react-dom": "^17.0.2", "@types/react-dom": "^16.9.0",
"react": "^17.0.2", "react": "^16.14.0",
"react-dom": "^17.0.2", "react-dom": "^16.14.0",
"react-scripts": "3.4.3", "react-scripts": "3.4.3",
"typescript": "~3.7.2" "typescript": "~3.7.2"
}, },

View File

@ -5,17 +5,38 @@ function LineChartExample(props: any) {
return ( return (
<ReactChartJs <ReactChartJs
chartConfig={{ chartConfig={{
type: 'pie', type: 'line',
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: 'My First Dataset', label: 'Part-time',
data: [300, 50, 100], data: [5, 10, 30],
backgroundColor: ['rgb(255, 99, 132)', 'rgb(54, 162, 235)', 'rgb(255, 205, 86)'], fill: false,
hoverOffset: 4, borderColor: '#ff6384',
},
{
label: 'Full-time',
data: [10, 15, 45],
fill: false,
borderColor: '#36a2eb',
}, },
], ],
labels: ['Jan', 'Feb', 'Mar'],
}, },
}} }}
/> />

View File

@ -1,6 +1,6 @@
{ {
"name": "@cubetiq/react-chart-js", "name": "@cubetiq/react-chart-js",
"version": "1.1.9", "version": "1.1.5",
"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,7 +30,7 @@
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"test": "jest", "test": "jest",
"pub": "npm publish --access public --registry https://registry.npmjs.org", "pub": "npm publish --access public",
"build:test": "yarn jest && yarn build", "build:test": "yarn jest && yarn build",
"run:example": "cd examples/line-chart-example && yarn start" "run:example": "cd examples/line-chart-example && yarn start"
}, },
@ -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": "^17.0.34", "@types/react": "^16.9.52",
"@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": "^17.0.2", "react": "^16.14.0",
"ts-jest": "^26.3.0", "ts-jest": "^26.3.0",
"tsc": "^1.20150623.0", "tsc": "^1.20150623.0",
"typescript": "^4.4.4" "typescript": "^4.0.2"
}, },
"husky": { "husky": {
"hooks": { "hooks": {
@ -71,6 +71,6 @@
] ]
}, },
"dependencies": { "dependencies": {
"chart.js": "^3.6.0" "chart.js": "^2.9.3"
} }
} }

View File

@ -1,13 +1,8 @@
import Chart from 'chart.js/auto'; import { Chart, ChartConfiguration } from 'chart.js';
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 {
@ -15,7 +10,7 @@ interface RefForChartInstance {
} }
const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => { const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => {
const { chartConfig, containerProps, canvasProps } = props; const { chartConfig } = props;
const canvasDomRef = useRef<HTMLCanvasElement>(); const canvasDomRef = useRef<HTMLCanvasElement>();
@ -32,14 +27,13 @@ const ReactChartJs: FunctionComponent<ReactChartJSProps> = (props: any) => {
}, [chartConfig]); }, [chartConfig]);
return ( return (
<div {...containerProps}> <div>
<canvas <canvas
ref={(instance: any) => { ref={(instance: any) => {
canvasDomRef.current = instance!; canvasDomRef.current = instance!;
}} }}
width={props.width || 'auto'} width="400"
height={props.height || 'auto'} height="200"
{...canvasProps}
/> />
</div> </div>
); );