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

Stutter fix #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions examples/example_resize.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Resize</title>
<link href="https://fonts.googleapis.com/css?family=Lora:700|Open+Sans" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", "sans-serif";
}
</style>
</head>
<body>
<div id="react-app">
</div>
<script src="static/example_resize.bundle.js" type="text/javascript"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/example_resize.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react"
import ReactDOM from "react-dom"
import {Resize} from "../src/index.jsx"


class ExampleApp extends React.Component {

render(){
return(
<div>
<Resize width="50%">
<svg>
<rect x={0} y={0} width={2000} height={100} />
</svg>
</Resize>
</div>
)
}
}

ReactDOM.render(
<ExampleApp />,
document.getElementById("react-app")
)
3 changes: 2 additions & 1 deletion examples/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = function () {
example3: "./example3.jsx",
example_loading: "./example_loading.jsx",
example_legend: "./example_legend.jsx",
example_axis: "./example_axis.jsx"
example_axis: "./example_axis.jsx",
example_resize: "./example_resize.jsx"
},
output: {
path: __dirname + "/static",
Expand Down
24 changes: 17 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ var YStep = function (_React$Component3) {
x2: this.props.x - this.props.length, y2: this.props.y,
stroke: this.props.color }));
step.push(_react2.default.createElement(YTickLabel, { key: "label" + this.props.y, x: this.props.x - 10, y: this.props.y,
value: this.props.value, color: this.props.color }));
value: this.props.value, yScale: this.props.yScale, color: this.props.color }));

return _react2.default.createElement(
"g",
Expand Down Expand Up @@ -1268,7 +1268,7 @@ var YAxis = function (_React$Component4) {
if (this.props.showYLabels) {
yAxis.push(_react2.default.createElement(YStep, { key: "yStep" + i, x: this.props.x, y: tickPos,
value: yVal, length: 10, color: this.props.style.labelColor,
showYLabels: this.props.showYLabels }));
showYLabels: this.props.showYLabels, yScale: this.props.yScale }));
}

if (this.props.showGrid) {
Expand Down Expand Up @@ -1373,7 +1373,7 @@ var XStep = function (_React$Component6) {
x2: this.props.x, y2: this.props.y + this.props.length,
stroke: this.props.color }));
step.push(_react2.default.createElement(XTickLabel, { key: "label" + this.props.x, x: this.props.x, y: this.props.y,
value: this.props.value, color: this.props.color }));
value: this.props.value, xScale: this.props.xScale, color: this.props.color }));

return _react2.default.createElement(
"g",
Expand Down Expand Up @@ -1439,7 +1439,7 @@ var XAxisContinuous = function (_React$Component7) {
}
xAxis.push(_react2.default.createElement(XStep, { key: "xStep" + i, x: tickPos, y: this.props.y,
value: xVal, length: 10, color: this.props.style.labelColor,
showXLabels: this.props.showXLabels }));
showXLabels: this.props.showXLabels, xScale: this.props.xScale }));
}
}

Expand Down Expand Up @@ -1810,6 +1810,10 @@ var _react = __webpack_require__(1);

var _react2 = _interopRequireDefault(_react);

var _propTypes = __webpack_require__(2);

var _propTypes2 = _interopRequireDefault(_propTypes);

var _LoadingIcon = __webpack_require__(15);

var _LoadingIcon2 = _interopRequireDefault(_LoadingIcon);
Expand All @@ -1834,6 +1838,7 @@ var Resize = function (_React$Component) {
width: parseInt(_this.props.width),
resizing: false
};
_this.timeouts = [];
return _this;
}

Expand All @@ -1857,9 +1862,10 @@ var Resize = function (_React$Component) {
resizing: true,
width: this.elem.parentNode.clientWidth * parseInt(this.props.width) / 100
});
var updateFunction;
clearTimeout(updateFunction);
updateFunction = setTimeout(this.updateDimensions.bind(this), 1200);
for (var i = 0; i < this.timeouts.length; i++) {
clearTimeout(this.timeouts[i]);
}
this.timeouts.push(setTimeout(this.updateDimensions.bind(this), 1200));
}
}
}, {
Expand Down Expand Up @@ -1929,6 +1935,10 @@ var Resize = function (_React$Component) {
return Resize;
}(_react2.default.Component);

Resize.propTypes = {
width: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]).isRequired
};

exports.default = Resize;

/***/ }),
Expand Down
8 changes: 4 additions & 4 deletions src/Axis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class YStep extends React.Component {
)
step.push(
<YTickLabel key={"label"+this.props.y} x={this.props.x-10} y={this.props.y}
value={this.props.value} color={this.props.color} />
value={this.props.value} yScale={this.props.yScale} color={this.props.color} />
)

return(
Expand Down Expand Up @@ -131,7 +131,7 @@ class YAxis extends React.Component {
yAxis.push(
<YStep key={"yStep"+i} x={this.props.x} y={tickPos}
value={yVal} length={10} color={this.props.style.labelColor}
showYLabels={this.props.showYLabels}/>
showYLabels={this.props.showYLabels} yScale={this.props.yScale}/>
)
}

Expand Down Expand Up @@ -217,7 +217,7 @@ class XStep extends React.Component {
)
step.push(
<XTickLabel key={"label"+this.props.x} x={this.props.x} y={this.props.y}
value={this.props.value} color={this.props.color} />
value={this.props.value} xScale={this.props.xScale} color={this.props.color} />
)

return(
Expand Down Expand Up @@ -274,7 +274,7 @@ class XAxisContinuous extends React.Component {
xAxis.push(
<XStep key={"xStep"+i} x={tickPos} y={this.props.y}
value={xVal} length={10} color={this.props.style.labelColor}
showXLabels={this.props.showXLabels}/>
showXLabels={this.props.showXLabels} xScale={this.props.xScale}/>
)
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/Resize.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import PropTypes from "prop-types"
import LoadingIcon from "./LoadingIcon.jsx"


Expand All @@ -10,6 +11,7 @@ class Resize extends React.Component {
width: parseInt(this.props.width),
resizing: false
}
this.timeouts = []
}

parseWidth(width) {
Expand All @@ -29,9 +31,10 @@ class Resize extends React.Component {
resizing: true,
width: this.elem.parentNode.clientWidth * parseInt(this.props.width) / 100
})
var updateFunction
clearTimeout(updateFunction)
updateFunction = setTimeout(this.updateDimensions.bind(this), 1200)
for (let i = 0; i < this.timeouts.length; i++) {
clearTimeout(this.timeouts[i])
}
this.timeouts.push(setTimeout(this.updateDimensions.bind(this), 1200))
}
}

Expand Down Expand Up @@ -90,4 +93,8 @@ class Resize extends React.Component {

}

Resize.propTypes = {
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired
}

export default Resize