Cleanup charts code
This commit is contained in:
parent
9b0149c07a
commit
8412412b05
|
@ -10,7 +10,11 @@ var ChartAnimationMixin = {
|
||||||
anim.setAttributeNS(null, 'values', from +';'+ to);
|
anim.setAttributeNS(null, 'values', from +';'+ to);
|
||||||
anim.setAttributeNS(null, 'dur', this.animDuration +'ms');
|
anim.setAttributeNS(null, 'dur', this.animDuration +'ms');
|
||||||
anim.setAttributeNS(null, 'calcMode', 'spline');
|
anim.setAttributeNS(null, 'calcMode', 'spline');
|
||||||
anim.setAttributeNS(null, 'keySplines', this.easing);
|
// Easings to consider:
|
||||||
|
// easeOutCirc: 0.075 0.82 0.165 1
|
||||||
|
// easeOutBack: 0.175 0.885 0.32 1.275
|
||||||
|
// easeInOutCubic: 0.645 0.045 0.355 1
|
||||||
|
anim.setAttributeNS(null, 'keySplines', '0.175 0.885 0.32 1.275');
|
||||||
anim.setAttributeNS(null, 'repeatCount', '1');
|
anim.setAttributeNS(null, 'repeatCount', '1');
|
||||||
anim.addEventListener('endEvent', function() {
|
anim.addEventListener('endEvent', function() {
|
||||||
node.setAttributeNS(null, attr, to);
|
node.setAttributeNS(null, attr, to);
|
||||||
|
|
|
@ -75,7 +75,6 @@ var BarChart = React.createClass({
|
||||||
points.push(point);
|
points.push(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("Setting points!");
|
|
||||||
this.setState({
|
this.setState({
|
||||||
points: points,
|
points: points,
|
||||||
min: _.min(points, this.state.sort)[this.state.sort],
|
min: _.min(points, this.state.sort)[this.state.sort],
|
||||||
|
@ -97,7 +96,6 @@ var BarChart = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
// console.log("Render barchart!", this.state);
|
|
||||||
return (
|
return (
|
||||||
<div className="barchart-container">
|
<div className="barchart-container">
|
||||||
<div className="filters">
|
<div className="filters">
|
||||||
|
@ -150,9 +148,6 @@ var BarChart = React.createClass({
|
||||||
var Bar = React.createClass({
|
var Bar = React.createClass({
|
||||||
mixins: [ReactRouter.Navigation, ChartAnimationMixin],
|
mixins: [ReactRouter.Navigation, ChartAnimationMixin],
|
||||||
|
|
||||||
// easing: '0.075 0.82 0.165 1', // easeOutCirc
|
|
||||||
easing: '0.175 0.885 0.32 1.275', // easeOutBack
|
|
||||||
|
|
||||||
height: 30,
|
height: 30,
|
||||||
labelPaddingH: 5, // Label horizontal padding
|
labelPaddingH: 5, // Label horizontal padding
|
||||||
labelPaddingV: 2, // Label vertical padding
|
labelPaddingV: 2, // Label vertical padding
|
||||||
|
@ -176,7 +171,6 @@ var Bar = React.createClass({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("New bar props!", newProps.item, newProps.x, newProps.width);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastBarX: (this.props.x !== undefined ? this.props.x : newProps.x),
|
lastBarX: (this.props.x !== undefined ? this.props.x : newProps.x),
|
||||||
lastBarWidth: (this.props.width !== undefined ? this.props.width : newProps.width),
|
lastBarWidth: (this.props.width !== undefined ? this.props.width : newProps.width),
|
||||||
|
@ -187,16 +181,11 @@ var Bar = React.createClass({
|
||||||
calculateLabelPosition: function() {
|
calculateLabelPosition: function() {
|
||||||
var val = this.props.value,
|
var val = this.props.value,
|
||||||
offset = this.props.offset,
|
offset = this.props.offset,
|
||||||
width = this.props.width,
|
|
||||||
label = this.props.item + ': ' + val,
|
label = this.props.item + ': ' + val,
|
||||||
labelWidth = textWidth(label),
|
labelWidth = textWidth(label),
|
||||||
labelOuterWidth = labelWidth + 2*this.labelPaddingH,
|
labelOuterWidth = labelWidth + 2*this.labelPaddingH,
|
||||||
labelOffsetWidth = labelOuterWidth + 2*this.labelPaddingH,
|
labelOffsetWidth = labelOuterWidth + 2*this.labelPaddingH,
|
||||||
labelMarginV = (this.props.height - this.labelOuterHeight)/2,
|
labelX;
|
||||||
labelX,
|
|
||||||
labelY = this.props.y + this.labelOuterHeight + 1, // 1 is magic
|
|
||||||
barX = this.props.x,
|
|
||||||
barX2 = barX + width;
|
|
||||||
|
|
||||||
if (offset === 0) {
|
if (offset === 0) {
|
||||||
labelX = 2*this.labelPaddingH;
|
labelX = 2*this.labelPaddingH;
|
||||||
|
@ -222,30 +211,34 @@ var Bar = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
animateAll: function() {
|
animateAll: function() {
|
||||||
// console.log("animate bar!", this.state, this.props);
|
|
||||||
this.clearAnimations(this.refs.bar);
|
this.clearAnimations(this.refs.bar);
|
||||||
this.clearAnimations(this.refs.underlay);
|
this.clearAnimations(this.refs.underlay);
|
||||||
this.animate(this.refs.bar, 'width', this.state.lastBarWidth, this.props.width);
|
this.animate(this.refs.bar, 'width', this.state.lastBarWidth, this.props.width);
|
||||||
this.animate(this.refs.bar, 'x', this.state.lastBarX, this.props.x);
|
this.animate(this.refs.bar, 'x', this.state.lastBarX, this.props.x);
|
||||||
var ph = this.labelPaddingH;
|
var ph = this.labelPaddingH;
|
||||||
this.animate(this.refs.underlay, 'x', this.state.lastLabelX - ph, this.state.labelX - ph);
|
this.animate(this.refs.underlay, 'x', this.state.lastLabelX - ph, this.state.labelX - ph);
|
||||||
// this.animate(this.refs.label, 'x', this.state.lastLabelX, this.state.labelX);
|
this.animate(this.refs.label, 'x', this.state.lastLabelX, this.state.labelX);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var label = this.props.item ? (this.props.item + ': ' + this.props.value) : '',
|
var label = this.props.item ? (this.props.item + ': ' + this.props.value) : '',
|
||||||
labelWidth = textWidth(label),
|
labelWidth = textWidth(label),
|
||||||
labelOuterWidth = labelWidth + 2*this.labelPaddingH;
|
labelOuterWidth = (labelWidth == 0 ? 0 : labelWidth + 2*this.labelPaddingH),
|
||||||
|
barX = (this.state.lastBarX && this.state.lastBarX !== this.props.x
|
||||||
|
? this.state.lastBarX
|
||||||
|
: this.props.x),
|
||||||
|
barWidth = (this.state.lastBarWidth && this.state.lastBarWidth !== this.props.width
|
||||||
|
? this.state.lastBarWidth
|
||||||
|
: this.props.width);
|
||||||
|
|
||||||
// var width = this.state.lastBarWidth === 0 ? this.props.width : this.state.lastBarWidth;
|
|
||||||
return (
|
return (
|
||||||
<g onClick={this.props.onClick}>
|
<g onClick={this.props.onClick}>
|
||||||
<rect ref="bar"
|
<rect ref="bar"
|
||||||
className="bar"
|
className="bar"
|
||||||
fill={this.props.color}
|
fill={this.props.color}
|
||||||
width={this.props.width}
|
width={barWidth}
|
||||||
height={this.props.height}
|
height={this.props.height}
|
||||||
x={this.props.x}
|
x={barX}
|
||||||
y={this.props.y}
|
y={this.props.y}
|
||||||
rx="2"
|
rx="2"
|
||||||
ry="2" />
|
ry="2" />
|
||||||
|
|
|
@ -205,7 +205,6 @@ var StackedAreaChart = React.createClass({
|
||||||
|
|
||||||
var StackedArea = React.createClass({
|
var StackedArea = React.createClass({
|
||||||
mixins: [ChartAnimationMixin],
|
mixins: [ChartAnimationMixin],
|
||||||
easing: '0.175 0.885 0.32 1.275', // easeOutBack
|
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {};
|
return {};
|
||||||
|
|
Loading…
Reference in New Issue