Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-chartjs-2

Package Overview
Dependencies
Maintainers
5
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-chartjs-2 - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

dist/typedCharts.d.ts

8

dist/chart.d.ts
import React from 'react';
import Chart from 'chart.js/auto';
import { Props } from './types';
declare const ChartComponent: React.ForwardRefExoticComponent<Props & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export default ChartComponent;
import { Props, ChartJSOrUndefined } from './types';
export declare const Chart: <TType extends keyof import("chart.js").ChartTypeRegistry = keyof import("chart.js").ChartTypeRegistry, TData = import("chart.js/types/utils").DistributiveArray<import("chart.js").ChartTypeRegistry[TType]["defaultDataPoint"]>, TLabel = unknown, TOtherType extends TType = TType>(props: Props<TType, TData, TLabel, TOtherType> & {
ref?: React.ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>> | undefined;
}) => JSX.Element;

@@ -1,15 +0,4 @@

import React from 'react';
import Chart from 'chart.js/auto';
import { defaults } from 'chart.js';
import { Props } from './types';
import ChartComponent from './chart';
export declare const Line: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Bar: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Radar: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Doughnut: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const PolarArea: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Bubble: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Pie: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export declare const Scatter: React.ForwardRefExoticComponent<Omit<Props, "type"> & React.RefAttributes<Chart<keyof import("chart.js").ChartTypeRegistry, (number | import("chart.js").ScatterDataPoint | import("chart.js").BubbleDataPoint | null)[], unknown> | undefined>>;
export { Chart, defaults };
export default ChartComponent;
export { default as Chart } from 'chart.js/auto';
export { defaults } from 'chart.js';
export { Chart as default } from './chart';
export * from './typedCharts';

@@ -5,5 +5,5 @@ 'use strict';

var ChartJS = require('chart.js/auto');
var chart_js = require('chart.js');
var React = require('react');
var Chart = require('chart.js/auto');
var chart_js = require('chart.js');
var merge = require('lodash/merge');

@@ -15,4 +15,4 @@ var assign = require('lodash/assign');

var ChartJS__default = /*#__PURE__*/_interopDefaultLegacy(ChartJS);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Chart__default = /*#__PURE__*/_interopDefaultLegacy(Chart);
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);

@@ -102,5 +102,5 @@ var assign__default = /*#__PURE__*/_interopDefaultLegacy(assign);

var ChartComponent = /*#__PURE__*/ React.forwardRef(function(props, ref) {
var id = props.id, className = props.className, _height = props.height, height = _height === void 0 ? 150 : _height, _width = props.width, width = _width === void 0 ? 300 : _width, _redraw = props.redraw, redraw = _redraw === void 0 ? false : _redraw, type = props.type, data = props.data, _options = props.options, options = _options === void 0 ? {
} : _options, _plugins = props.plugins, plugins = _plugins === void 0 ? [] : _plugins, getDatasetAtEvent = props.getDatasetAtEvent, getElementAtEvent = props.getElementAtEvent, getElementsAtEvent = props.getElementsAtEvent, fallbackContent = props.fallbackContent, rest = _objectWithoutProperties(props, ["id", "className", "height", "width", "redraw", "type", "data", "options", "plugins", "getDatasetAtEvent", "getElementAtEvent", "getElementsAtEvent", "fallbackContent"]);
function ChartComponent(_param, ref) {
var _height = _param.height, height = _height === void 0 ? 150 : _height, _width = _param.width, width = _width === void 0 ? 300 : _width, _redraw = _param.redraw, redraw = _redraw === void 0 ? false : _redraw, type = _param.type, data = _param.data, options = _param.options, _plugins = _param.plugins, plugins = _plugins === void 0 ? [] : _plugins, getDatasetAtEvent = _param.getDatasetAtEvent, getElementAtEvent = _param.getElementAtEvent, getElementsAtEvent = _param.getElementsAtEvent, fallbackContent = _param.fallbackContent, onClickProp = _param.onClick, props = _objectWithoutProperties(_param, ["height", "width", "redraw", "type", "data", "options", "plugins", "getDatasetAtEvent", "getElementAtEvent", "getElementsAtEvent", "fallbackContent", "onClick"
]);
var canvas = React.useRef(null);

@@ -122,7 +122,7 @@ var computedData = React.useMemo(function() {

}, [
chart,
chart
]);
var renderChart = function() {
if (!canvas.current) return;
setChart(new Chart__default["default"](canvas.current, {
setChart(new ChartJS__default["default"](canvas.current, {
type: type,

@@ -134,13 +134,16 @@ data: computedData,

};
var onClick = function(e) {
var onClick = function(event) {
if (onClickProp) {
onClickProp(event);
}
if (!chart) return;
getDatasetAtEvent && getDatasetAtEvent(chart.getElementsAtEventForMode(e, 'dataset', {
getDatasetAtEvent && getDatasetAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'dataset', {
intersect: true
}, false), e);
getElementAtEvent && getElementAtEvent(chart.getElementsAtEventForMode(e, 'nearest', {
}, false), event);
getElementAtEvent && getElementAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'nearest', {
intersect: true
}, false), e);
getElementsAtEvent && getElementsAtEvent(chart.getElementsAtEventForMode(e, 'index', {
}, false), event);
getElementsAtEvent && getElementsAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'index', {
intersect: true
}, false), e);
}, false), event);
};

@@ -173,4 +176,6 @@ var updateChart = function() {

if (!currentDataSet.data) {
// @ts-expect-error Need to refactor
currentDataSet.data = [];
} else {
// @ts-expect-error Need to refactor
currentDataSet.data.length = newDataSet.data.length;

@@ -207,95 +212,34 @@ }

}
}, [
props,
computedData
]);
});
return(/*#__PURE__*/ React__default["default"].createElement("canvas", Object.assign({
}, rest, {
ref: canvas,
role: "img",
height: height,
width: width,
ref: canvas,
id: id,
className: className,
onClick: onClick,
"data-testid": "canvas",
role: "img"
}), fallbackContent));
});
onClick: onClick
}, props), fallbackContent));
}
var Chart = /*#__PURE__*/ React.forwardRef(ChartComponent);
var Line = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "line",
ref: ref,
options: props.options || {
}
function createTypedChart(type) {
return(/*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(Chart, Object.assign({
}, props, {
ref: ref,
type: type
}));
}));
});
var Bar = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "bar",
ref: ref,
options: props.options || {
}
}));
});
var Radar = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "radar",
ref: ref,
options: props.options || {
}
}));
});
var Doughnut = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "doughnut",
ref: ref,
options: props.options || {
}
}));
});
var PolarArea = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "polarArea",
ref: ref,
options: props.options || {
}
}));
});
var Bubble = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "bubble",
ref: ref,
options: props.options || {
}
}));
});
var Pie = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "pie",
ref: ref,
options: props.options || {
}
}));
});
var Scatter = /*#__PURE__*/ React.forwardRef(function(props, ref) {
return React__default["default"].createElement(ChartComponent, Object.assign({
}, props, {
type: "scatter",
ref: ref,
options: props.options || {
}
}));
});
}
var Line = createTypedChart('line');
var Bar = createTypedChart('bar');
var Radar = createTypedChart('radar');
var Doughnut = createTypedChart('doughnut');
var PolarArea = createTypedChart('polarArea');
var Bubble = createTypedChart('bubble');
var Pie = createTypedChart('pie');
var Scatter = createTypedChart('scatter');
Object.defineProperty(exports, 'Chart', {
enumerable: true,
get: function () { return Chart__default["default"]; }
get: function () { return ChartJS__default["default"]; }
});

@@ -314,3 +258,3 @@ Object.defineProperty(exports, 'defaults', {

exports.Scatter = Scatter;
exports["default"] = ChartComponent;
exports["default"] = Chart;
//# sourceMappingURL=index.js.map

@@ -1,5 +0,5 @@

import React, { forwardRef, useRef, useMemo, useState, useImperativeHandle, useEffect } from 'react';
import Chart from 'chart.js/auto';
import ChartJS from 'chart.js/auto';
export { default as Chart } from 'chart.js/auto';
export { defaults } from 'chart.js';
import React, { forwardRef, useRef, useMemo, useState, useImperativeHandle, useEffect } from 'react';
import merge from 'lodash/merge';

@@ -89,5 +89,5 @@ import assign from 'lodash/assign';

var ChartComponent = /*#__PURE__*/ forwardRef(function(props, ref) {
var id = props.id, className = props.className, _height = props.height, height = _height === void 0 ? 150 : _height, _width = props.width, width = _width === void 0 ? 300 : _width, _redraw = props.redraw, redraw = _redraw === void 0 ? false : _redraw, type = props.type, data = props.data, _options = props.options, options = _options === void 0 ? {
} : _options, _plugins = props.plugins, plugins = _plugins === void 0 ? [] : _plugins, getDatasetAtEvent = props.getDatasetAtEvent, getElementAtEvent = props.getElementAtEvent, getElementsAtEvent = props.getElementsAtEvent, fallbackContent = props.fallbackContent, rest = _objectWithoutProperties(props, ["id", "className", "height", "width", "redraw", "type", "data", "options", "plugins", "getDatasetAtEvent", "getElementAtEvent", "getElementsAtEvent", "fallbackContent"]);
function ChartComponent(_param, ref) {
var _height = _param.height, height = _height === void 0 ? 150 : _height, _width = _param.width, width = _width === void 0 ? 300 : _width, _redraw = _param.redraw, redraw = _redraw === void 0 ? false : _redraw, type = _param.type, data = _param.data, options = _param.options, _plugins = _param.plugins, plugins = _plugins === void 0 ? [] : _plugins, getDatasetAtEvent = _param.getDatasetAtEvent, getElementAtEvent = _param.getElementAtEvent, getElementsAtEvent = _param.getElementsAtEvent, fallbackContent = _param.fallbackContent, onClickProp = _param.onClick, props = _objectWithoutProperties(_param, ["height", "width", "redraw", "type", "data", "options", "plugins", "getDatasetAtEvent", "getElementAtEvent", "getElementsAtEvent", "fallbackContent", "onClick"
]);
var canvas = useRef(null);

@@ -109,7 +109,7 @@ var computedData = useMemo(function() {

}, [
chart,
chart
]);
var renderChart = function() {
if (!canvas.current) return;
setChart(new Chart(canvas.current, {
setChart(new ChartJS(canvas.current, {
type: type,

@@ -121,13 +121,16 @@ data: computedData,

};
var onClick = function(e) {
var onClick = function(event) {
if (onClickProp) {
onClickProp(event);
}
if (!chart) return;
getDatasetAtEvent && getDatasetAtEvent(chart.getElementsAtEventForMode(e, 'dataset', {
getDatasetAtEvent && getDatasetAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'dataset', {
intersect: true
}, false), e);
getElementAtEvent && getElementAtEvent(chart.getElementsAtEventForMode(e, 'nearest', {
}, false), event);
getElementAtEvent && getElementAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'nearest', {
intersect: true
}, false), e);
getElementsAtEvent && getElementsAtEvent(chart.getElementsAtEventForMode(e, 'index', {
}, false), event);
getElementsAtEvent && getElementsAtEvent(chart.getElementsAtEventForMode(event.nativeEvent, 'index', {
intersect: true
}, false), e);
}, false), event);
};

@@ -160,4 +163,6 @@ var updateChart = function() {

if (!currentDataSet.data) {
// @ts-expect-error Need to refactor
currentDataSet.data = [];
} else {
// @ts-expect-error Need to refactor
currentDataSet.data.length = newDataSet.data.length;

@@ -194,93 +199,32 @@ }

}
}, [
props,
computedData
]);
});
return(/*#__PURE__*/ React.createElement("canvas", Object.assign({
}, rest, {
ref: canvas,
role: "img",
height: height,
width: width,
ref: canvas,
id: id,
className: className,
onClick: onClick,
"data-testid": "canvas",
role: "img"
}), fallbackContent));
});
onClick: onClick
}, props), fallbackContent));
}
var Chart = /*#__PURE__*/ forwardRef(ChartComponent);
var Line = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "line",
ref: ref,
options: props.options || {
}
function createTypedChart(type) {
return(/*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(Chart, Object.assign({
}, props, {
ref: ref,
type: type
}));
}));
});
var Bar = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "bar",
ref: ref,
options: props.options || {
}
}));
});
var Radar = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "radar",
ref: ref,
options: props.options || {
}
}));
});
var Doughnut = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "doughnut",
ref: ref,
options: props.options || {
}
}));
});
var PolarArea = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "polarArea",
ref: ref,
options: props.options || {
}
}));
});
var Bubble = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "bubble",
ref: ref,
options: props.options || {
}
}));
});
var Pie = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "pie",
ref: ref,
options: props.options || {
}
}));
});
var Scatter = /*#__PURE__*/ forwardRef(function(props, ref) {
return React.createElement(ChartComponent, Object.assign({
}, props, {
type: "scatter",
ref: ref,
options: props.options || {
}
}));
});
}
var Line = createTypedChart('line');
var Bar = createTypedChart('bar');
var Radar = createTypedChart('radar');
var Doughnut = createTypedChart('doughnut');
var PolarArea = createTypedChart('polarArea');
var Bubble = createTypedChart('bubble');
var Pie = createTypedChart('pie');
var Scatter = createTypedChart('scatter');
export { Bar, Bubble, Doughnut, Line, Pie, PolarArea, Radar, Scatter, ChartComponent as default };
export { Bar, Bubble, Doughnut, Line, Pie, PolarArea, Radar, Scatter, Chart as default };
//# sourceMappingURL=index.modern.js.map

@@ -1,14 +0,13 @@

import type { CanvasHTMLAttributes, ReactNode, MouseEvent } from 'react';
import type { ChartType, ChartData, ChartOptions, Plugin, InteractionItem } from 'chart.js';
export interface Props extends CanvasHTMLAttributes<HTMLCanvasElement> {
id?: string;
className?: string;
height?: number;
width?: number;
import type { CanvasHTMLAttributes, ForwardedRef, ReactNode, MouseEvent } from 'react';
import type { Chart, ChartType, ChartData, ChartOptions, DefaultDataPoint, Plugin, InteractionItem } from 'chart.js';
export interface Props<TType extends ChartType = ChartType, TData = DefaultDataPoint<TType>, TLabel = unknown, TOtherType extends TType = TType> extends CanvasHTMLAttributes<HTMLCanvasElement> {
type: TType;
data: ChartData<TOtherType, TData, TLabel> | ((canvas: HTMLCanvasElement) => ChartData<TOtherType, TData, TLabel>);
options?: ChartOptions<TOtherType>;
plugins?: Plugin<TOtherType>[];
redraw?: boolean;
type: ChartType;
data: ChartData | ((canvas: HTMLCanvasElement) => ChartData);
options?: ChartOptions;
/**
* @todo Replace with `children` prop.
*/
fallbackContent?: ReactNode;
plugins?: Plugin[];
getDatasetAtEvent?: (dataset: InteractionItem[], event: MouseEvent<HTMLCanvasElement>) => void;

@@ -18,1 +17,10 @@ getElementAtEvent?: (element: InteractionItem[], event: MouseEvent<HTMLCanvasElement>) => void;

}
/**
* @todo Replace `undefined` with `null`
*/
export declare type ChartJSOrUndefined<TType extends ChartType = ChartType, TData = DefaultDataPoint<TType>, TLabel = unknown> = Chart<TType, TData, TLabel> | undefined;
export declare type TypedChartComponent<TDefaultType extends ChartType = ChartType, TOmitType = false> = TOmitType extends true ? <TData = DefaultDataPoint<TDefaultType>, TLabel = unknown>(props: Omit<Props<TDefaultType, TData, TLabel>, 'type'> & {
ref?: ForwardedRef<ChartJSOrUndefined<TDefaultType, TData, TLabel>>;
}) => JSX.Element : <TType extends ChartType = ChartType, TData = DefaultDataPoint<TType>, TLabel = unknown, TOtherType extends TType = TType>(props: Props<TType, TData, TLabel, TOtherType> & {
ref?: ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>>;
}) => JSX.Element;
{
"name": "react-chartjs-2",
"version": "3.1.0",
"version": "3.1.1",
"description": "React components for Chart.js",
"main": "dist/index.js",
"module": "dist/index.modern.js",
"types": "dist/index.d.ts",
"author": "Jeremy Ayerst",

@@ -8,0 +9,0 @@ "homepage": "https://github.com/reactchartjs/react-chartjs-2",

@@ -52,6 +52,6 @@ [![build status](https://img.shields.io/travis/jerairrest/react-chartjs-2.svg?branch=master&style=flat-square)](https://travis-ci.org/jerairrest/react-chartjs-2)

fallbackContent?: React.ReactNode;
plugins?: Chart.PluginServiceRegistrationOptions[];
getDatasetAtEvent?: (dataset: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void;
getElementAtEvent?: (element: [{}], event: React.MouseEvent<HTMLCanvasElement>) => void;
getElementsAtEvent?: (elements: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void;
plugins?: Chart.Plugin[];
getDatasetAtEvent?: (dataset: Chart.InteractionItem[], event: React.MouseEvent<HTMLCanvasElement>) => void;
getElementAtEvent?: (element: Chart.InteractionItem[], event: React.MouseEvent<HTMLCanvasElement>) => void;
getElementsAtEvent?: (elements: Chart.InteractionItem[], event: React.MouseEvent<HTMLCanvasElement>) => void;
```

@@ -96,3 +96,3 @@

Type: `'line' | 'bar' | 'horizontalBar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'`
Type: `'bar' | 'line' | 'scatter' | 'bubble' | 'pie' | 'doughnut' | 'polarArea' | 'radar'`

@@ -99,0 +99,0 @@ Chart.js chart type (required only on ChartComponent)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc