Skip to content

Commit a9b2d1c

Browse files
authored
Merge branch 'master' into enable-snapshot
2 parents bfd868e + fd5c5f3 commit a9b2d1c

File tree

11 files changed

+740
-437
lines changed

11 files changed

+740
-437
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ root = true
55
[*]
66
end_of_line = lf
77
charset = utf-8
8-
trim_trailing_whitespace = false
8+
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
indent_style = tab
10+
indent_style = space
1111

1212
[*.json]
1313
indent_style = space
1414
indent_size = 2
15+
16+
[*.md]
17+
trim_trailing_whitespace = false
18+
indent_style = tab

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ componentWillMount() {
167167
}
168168
```
169169

170+
### Scatter Charts
171+
172+
If you're using Chart.js 2.6 and below, add the `showLines: false` property to your chart options. This was later [added](https://github.com/chartjs/Chart.js/commit/7fa60523599a56255cde78a49e848166bd233c6e) in the default config, so users of later versions would not need to do this extra step.
173+
170174
### Events
171175

172176
#### onElementsClick || getElementsAtEvent (function)
@@ -203,6 +207,13 @@ Looks for the element under the event point, then returns all elements from that
203207
}
204208
```
205209

210+
### Working with Multiple Datasets
211+
212+
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. This is because to track changes in the dataset series, the library needs a `key` to be specified - if none is found, it can't tell the difference between the datasets while updating. To get around this issue, you can take these two approaches:
213+
214+
1. Add a `label` property on each dataset. By default, this library uses the `label` property as the key to distinguish datasets.
215+
2. Specify a different property to be used as a key by passing a `datasetKeyProvider` prop to your chart component, which would return a unique string value for each dataset.
216+
206217
## Development (`src`, `lib` and the build process)
207218

208219
**NOTE:** The source code for the component is in `src`. A transpiled CommonJS version (generated with Babel) is available in `lib` for use with node.js, browserify and webpack. A UMD bundle is also built to `dist`, which can be included without the need for any build system.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chartjs-2",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "react-chartjs-2",
55
"main": "dist/react-chartjs-2.min.js",
66
"homepage": "https://github.com/gor181/react-chartjs-2",

dist/react-chartjs-2.js

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ emptyFunction.thatReturnsArgument = function (arg) {
3838

3939
module.exports = emptyFunction;
4040
},{}],2:[function(require,module,exports){
41+
(function (process){
4142
/**
4243
* Copyright (c) 2013-present, Facebook, Inc.
4344
* All rights reserved.
@@ -63,7 +64,7 @@ module.exports = emptyFunction;
6364

6465
var validateFormat = function validateFormat(format) {};
6566

66-
if ("production" !== 'production') {
67+
if (process.env.NODE_ENV !== 'production') {
6768
validateFormat = function validateFormat(format) {
6869
if (format === undefined) {
6970
throw new Error('invariant requires an error message argument');
@@ -93,7 +94,9 @@ function invariant(condition, format, a, b, c, d, e, f) {
9394
}
9495

9596
module.exports = invariant;
96-
},{}],3:[function(require,module,exports){
97+
}).call(this,require('_process'))
98+
},{"_process":5}],3:[function(require,module,exports){
99+
(function (process){
97100
/**
98101
* Copyright 2014-2015, Facebook, Inc.
99102
* All rights reserved.
@@ -117,7 +120,7 @@ var emptyFunction = require('./emptyFunction');
117120

118121
var warning = emptyFunction;
119122

120-
if ("production" !== 'production') {
123+
if (process.env.NODE_ENV !== 'production') {
121124
(function () {
122125
var printWarning = function printWarning(format) {
123126
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -160,7 +163,8 @@ if ("production" !== 'production') {
160163
}
161164

162165
module.exports = warning;
163-
},{"./emptyFunction":1}],4:[function(require,module,exports){
166+
}).call(this,require('_process'))
167+
},{"./emptyFunction":1,"_process":5}],4:[function(require,module,exports){
164168
(function (global){
165169
/**
166170
* Lodash (Custom Build) <https://lodash.com/>
@@ -2183,6 +2187,10 @@ process.off = noop;
21832187
process.removeListener = noop;
21842188
process.removeAllListeners = noop;
21852189
process.emit = noop;
2190+
process.prependListener = noop;
2191+
process.prependOnceListener = noop;
2192+
2193+
process.listeners = function (name) { return [] }
21862194

21872195
process.binding = function (name) {
21882196
throw new Error('process.binding is not supported');
@@ -2273,11 +2281,14 @@ module.exports = checkPropTypes;
22732281

22742282
var emptyFunction = require('fbjs/lib/emptyFunction');
22752283
var invariant = require('fbjs/lib/invariant');
2284+
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
22762285

22772286
module.exports = function() {
2278-
// Important!
2279-
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
2280-
function shim() {
2287+
function shim(props, propName, componentName, location, propFullName, secret) {
2288+
if (secret === ReactPropTypesSecret) {
2289+
// It is still safe when called from React.
2290+
return;
2291+
}
22812292
invariant(
22822293
false,
22832294
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
@@ -2289,6 +2300,8 @@ module.exports = function() {
22892300
function getShim() {
22902301
return shim;
22912302
};
2303+
// Important!
2304+
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
22922305
var ReactPropTypes = {
22932306
array: shim,
22942307
bool: shim,
@@ -2315,7 +2328,7 @@ module.exports = function() {
23152328
return ReactPropTypes;
23162329
};
23172330

2318-
},{"fbjs/lib/emptyFunction":1,"fbjs/lib/invariant":2}],8:[function(require,module,exports){
2331+
},{"./lib/ReactPropTypesSecret":10,"fbjs/lib/emptyFunction":1,"fbjs/lib/invariant":2}],8:[function(require,module,exports){
23192332
(function (process){
23202333
/**
23212334
* Copyright 2013-present, Facebook, Inc.
@@ -2639,6 +2652,20 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
26392652
return emptyFunction.thatReturnsNull;
26402653
}
26412654

2655+
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
2656+
var checker = arrayOfTypeCheckers[i];
2657+
if (typeof checker !== 'function') {
2658+
warning(
2659+
false,
2660+
'Invalid argument supplid to oneOfType. Expected an array of check functions, but ' +
2661+
'received %s at index %s.',
2662+
getPostfixForTypeWarning(checker),
2663+
i
2664+
);
2665+
return emptyFunction.thatReturnsNull;
2666+
}
2667+
}
2668+
26422669
function validate(props, propName, componentName, location, propFullName) {
26432670
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
26442671
var checker = arrayOfTypeCheckers[i];
@@ -2771,6 +2798,9 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
27712798
// This handles more types than `getPropType`. Only used for error messages.
27722799
// See `createPrimitiveTypeChecker`.
27732800
function getPreciseType(propValue) {
2801+
if (typeof propValue === 'undefined' || propValue === null) {
2802+
return '' + propValue;
2803+
}
27742804
var propType = getPropType(propValue);
27752805
if (propType === 'object') {
27762806
if (propValue instanceof Date) {
@@ -2782,6 +2812,23 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
27822812
return propType;
27832813
}
27842814

2815+
// Returns a string that is postfixed to a warning about an invalid type.
2816+
// For example, "undefined" or "of type array"
2817+
function getPostfixForTypeWarning(value) {
2818+
var type = getPreciseType(value);
2819+
switch (type) {
2820+
case 'array':
2821+
case 'object':
2822+
return 'an ' + type;
2823+
case 'boolean':
2824+
case 'date':
2825+
case 'regexp':
2826+
return 'a ' + type;
2827+
default:
2828+
return type;
2829+
}
2830+
}
2831+
27852832
// Returns class name of the object, if any.
27862833
function getClassName(propValue) {
27872834
if (!propValue.constructor || !propValue.constructor.name) {
@@ -2854,7 +2901,7 @@ module.exports = ReactPropTypesSecret;
28542901
Object.defineProperty(exports, "__esModule", {
28552902
value: true
28562903
});
2857-
exports.Chart = exports.defaults = exports.Bubble = exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = undefined;
2904+
exports.Chart = exports.defaults = exports.Scatter = exports.Bubble = exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = undefined;
28582905

28592906
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
28602907

@@ -3152,7 +3199,13 @@ ChartComponent.propTypes = {
31523199
options: _propTypes2.default.object,
31533200
plugins: _propTypes2.default.arrayOf(_propTypes2.default.object),
31543201
redraw: _propTypes2.default.bool,
3155-
type: _propTypes2.default.oneOf(['doughnut', 'pie', 'line', 'bar', 'horizontalBar', 'radar', 'polarArea', 'bubble']),
3202+
type: function type(props, propName, componentName) {
3203+
if (!Object.keys(_chart2.default.controllers).find(function (chartType) {
3204+
return chartType === props[propName];
3205+
})) {
3206+
return new Error('Invalid chart type `' + props[propName] + '` supplied to' + ' `' + componentName + '`.');
3207+
}
3208+
},
31563209
width: _propTypes2.default.number,
31573210
datasetKeyProvider: _propTypes2.default.func
31583211
};
@@ -3378,6 +3431,32 @@ var Bubble = exports.Bubble = function (_React$Component9) {
33783431
return Bubble;
33793432
}(_react2.default.Component);
33803433

3434+
var Scatter = exports.Scatter = function (_React$Component10) {
3435+
_inherits(Scatter, _React$Component10);
3436+
3437+
function Scatter() {
3438+
_classCallCheck(this, Scatter);
3439+
3440+
return _possibleConstructorReturn(this, (Scatter.__proto__ || Object.getPrototypeOf(Scatter)).apply(this, arguments));
3441+
}
3442+
3443+
_createClass(Scatter, [{
3444+
key: 'render',
3445+
value: function render() {
3446+
var _this20 = this;
3447+
3448+
return _react2.default.createElement(ChartComponent, _extends({}, this.props, {
3449+
ref: function ref(_ref10) {
3450+
return _this20.chart_instance = _ref10 && _ref10.chart_instance;
3451+
},
3452+
type: 'scatter'
3453+
}));
3454+
}
3455+
}]);
3456+
3457+
return Scatter;
3458+
}(_react2.default.Component);
3459+
33813460
var defaults = exports.defaults = _chart2.default.defaults;
33823461
exports.Chart = _chart2.default;
33833462

dist/react-chartjs-2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/components/scatter.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import {Scatter} from 'react-chartjs-2';
3+
4+
const data = {
5+
labels: ['Scatter'],
6+
datasets: [
7+
{
8+
label: 'My First dataset',
9+
fill: false,
10+
backgroundColor: 'rgba(75,192,192,0.4)',
11+
pointBorderColor: 'rgba(75,192,192,1)',
12+
pointBackgroundColor: '#fff',
13+
pointBorderWidth: 1,
14+
pointHoverRadius: 5,
15+
pointHoverBackgroundColor: 'rgba(75,192,192,1)',
16+
pointHoverBorderColor: 'rgba(220,220,220,1)',
17+
pointHoverBorderWidth: 2,
18+
pointRadius: 1,
19+
pointHitRadius: 10,
20+
data: [
21+
{ x: 65, y: 75 },
22+
{ x: 59, y: 49 },
23+
{ x: 80, y: 90 },
24+
{ x: 81, y: 29 },
25+
{ x: 56, y: 36 },
26+
{ x: 55, y: 25 },
27+
{ x: 40, y: 18 },
28+
]
29+
}
30+
]
31+
};
32+
33+
export default React.createClass({
34+
displayName: 'ScatterExample',
35+
36+
render() {
37+
return (
38+
<div>
39+
<h2>Scatter Example</h2>
40+
<Scatter data={data} />
41+
</div>
42+
);
43+
}
44+
});

example/src/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import HorizontalBarExample from './components/horizontalBar';
1010
import RadarExample from './components/radar';
1111
import PolarExample from './components/polar';
1212
import BubbleExample from './components/bubble';
13+
import ScatterExample from './components/scatter';
1314
import MixedDataExample from './components/mix';
1415
import RandomizedDataLineExample from './components/randomizedLine';
1516
import CrazyDataLineExample from './components/crazyLine';
@@ -37,6 +38,8 @@ class App extends React.Component {
3738
<hr />
3839
<BubbleExample />
3940
<hr />
41+
<ScatterExample />
42+
<hr />
4043
<MixedDataExample />
4144
<hr />
4245
<RandomizedDataLineExample />

lib/index.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.Chart = exports.defaults = exports.Bubble = exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = undefined;
6+
exports.Chart = exports.defaults = exports.Scatter = exports.Bubble = exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = undefined;
77

88
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
99

@@ -301,7 +301,13 @@ ChartComponent.propTypes = {
301301
options: _propTypes2.default.object,
302302
plugins: _propTypes2.default.arrayOf(_propTypes2.default.object),
303303
redraw: _propTypes2.default.bool,
304-
type: _propTypes2.default.oneOf(['doughnut', 'pie', 'line', 'bar', 'horizontalBar', 'radar', 'polarArea', 'bubble']),
304+
type: function type(props, propName, componentName) {
305+
if (!Object.keys(_chart2.default.controllers).find(function (chartType) {
306+
return chartType === props[propName];
307+
})) {
308+
return new Error('Invalid chart type `' + props[propName] + '` supplied to' + ' `' + componentName + '`.');
309+
}
310+
},
305311
width: _propTypes2.default.number,
306312
datasetKeyProvider: _propTypes2.default.func
307313
};
@@ -527,5 +533,31 @@ var Bubble = exports.Bubble = function (_React$Component9) {
527533
return Bubble;
528534
}(_react2.default.Component);
529535

536+
var Scatter = exports.Scatter = function (_React$Component10) {
537+
_inherits(Scatter, _React$Component10);
538+
539+
function Scatter() {
540+
_classCallCheck(this, Scatter);
541+
542+
return _possibleConstructorReturn(this, (Scatter.__proto__ || Object.getPrototypeOf(Scatter)).apply(this, arguments));
543+
}
544+
545+
_createClass(Scatter, [{
546+
key: 'render',
547+
value: function render() {
548+
var _this20 = this;
549+
550+
return _react2.default.createElement(ChartComponent, _extends({}, this.props, {
551+
ref: function ref(_ref10) {
552+
return _this20.chart_instance = _ref10 && _ref10.chart_instance;
553+
},
554+
type: 'scatter'
555+
}));
556+
}
557+
}]);
558+
559+
return Scatter;
560+
}(_react2.default.Component);
561+
530562
var defaults = exports.defaults = _chart2.default.defaults;
531563
exports.Chart = _chart2.default;

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "react-chartjs-2",
3-
"version": "2.1.0",
3+
"version": "2.3.0",
44
"description": "react-chartjs-2",
55
"main": "lib/index.js",
66
"author": "Goran Udosic",
7-
"homepage": "https://github.com/gor181/react-chartjs-2",
7+
"homepage": "https://github.com/jerairrest/react-chartjs-2",
88
"repository": {
99
"type": "git",
10-
"url": "https://github.com/gor181/react-chartjs-2.git"
10+
"url": "https://github.com/jerairrest/react-chartjs-2.git"
1111
},
1212
"bugs": {
13-
"url": "https://github.com/gor181/react-chartjs-2/issues"
13+
"url": "https://github.com/jerairrest/react-chartjs-2/issues"
1414
},
1515
"dependencies": {
1616
"lodash.isequal": "^4.4.0",

0 commit comments

Comments
 (0)