Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced findDomNode with ref in order to use react-test-renderer for snapshot testing with storybook #152

Merged
merged 3 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dist/react-chartjs-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,8 @@ var ChartComponent = function (_React$Component) {
getElementAtEvent && getElementAtEvent(instance.getElementAtEvent(event), event);
getElementsAtEvent && getElementsAtEvent(instance.getElementsAtEvent(event), event);
onElementsClick && onElementsClick(instance.getElementsAtEvent(event), event); // Backward compatibility
}, _this.ref = function (element) {
_this.element = element;
}, _temp), _possibleConstructorReturn(_this, _ret);
}

Expand Down Expand Up @@ -3041,7 +3043,7 @@ var ChartComponent = function (_React$Component) {
var data = props.data;

if (typeof data == 'function') {
var node = _reactDom2.default.findDOMNode(this);
var node = this.element;
return data(node);
} else {
return data;
Expand Down Expand Up @@ -3151,7 +3153,7 @@ var ChartComponent = function (_React$Component) {
redraw = _props2.redraw,
plugins = _props2.plugins;

var node = _reactDom2.default.findDOMNode(this);
var node = this.element;
var data = this.memoizeDataProps();

this.chart_instance = new _chart2.default(node, {
Expand All @@ -3171,6 +3173,7 @@ var ChartComponent = function (_React$Component) {


return _react2.default.createElement('canvas', {
ref: this.ref,
height: height,
width: width,
onClick: this.handleOnClick
Expand Down
2 changes: 1 addition & 1 deletion dist/react-chartjs-2.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ var ChartComponent = function (_React$Component) {
getElementAtEvent && getElementAtEvent(instance.getElementAtEvent(event), event);
getElementsAtEvent && getElementsAtEvent(instance.getElementsAtEvent(event), event);
onElementsClick && onElementsClick(instance.getElementsAtEvent(event), event); // Backward compatibility
}, _this.ref = function (element) {
_this.element = element;
}, _temp), _possibleConstructorReturn(_this, _ret);
}

Expand Down Expand Up @@ -143,7 +145,7 @@ var ChartComponent = function (_React$Component) {
var data = props.data;

if (typeof data == 'function') {
var node = _reactDom2.default.findDOMNode(this);
var node = this.element;
return data(node);
} else {
return data;
Expand Down Expand Up @@ -253,7 +255,7 @@ var ChartComponent = function (_React$Component) {
redraw = _props2.redraw,
plugins = _props2.plugins;

var node = _reactDom2.default.findDOMNode(this);
var node = this.element;
var data = this.memoizeDataProps();

this.chart_instance = new _chart2.default(node, {
Expand All @@ -273,6 +275,7 @@ var ChartComponent = function (_React$Component) {


return _react2.default.createElement('canvas', {
ref: this.ref,
height: height,
width: width,
onClick: this.handleOnClick
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ChartComponent extends React.Component {
transformDataProp(props) {
const { data } = props;
if (typeof(data) == 'function') {
const node = ReactDOM.findDOMNode(this);
const node = this.element;
return data(node);
} else {
return data;
Expand Down Expand Up @@ -201,7 +201,7 @@ class ChartComponent extends React.Component {

renderChart() {
const {options, legend, type, redraw, plugins} = this.props;
const node = ReactDOM.findDOMNode(this);
const node = this.element;
const data = this.memoizeDataProps();

this.chart_instance = new Chart(node, {
Expand All @@ -228,11 +228,16 @@ class ChartComponent extends React.Component {
onElementsClick && onElementsClick(instance.getElementsAtEvent(event), event); // Backward compatibility
}

ref = (element) => {
this.element = element
}

render() {
const {height, width, onElementsClick} = this.props;

return (
<canvas
ref={this.ref}
height={height}
width={width}
onClick={this.handleOnClick}
Expand Down