Skip to content

Commit

Permalink
Fixes to the play slider (apache#5675)
Browse files Browse the repository at this point in the history
* Fixes to the play slider

* Address comments

* Make CSS rules more strict

* Fix CSS and improve code

(cherry picked from commit bcc0954)
  • Loading branch information
betodealmeida committed Aug 22, 2018
1 parent b0fc3b2 commit 80b784d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
8 changes: 6 additions & 2 deletions superset/assets/src/visualizations/PlaySlider.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.play-slider {
position: absolute;
bottom: -16px;
position: relative;
height: 20px;
width: 100%;
margin: 0;
}

.slider-selection {
Expand All @@ -21,3 +21,7 @@
color: #b3b3b3;
margin-right: 5px;
}

div.slider > div.tooltip.tooltip-main.top.in {
margin-left: 0 !important;
}
34 changes: 20 additions & 14 deletions superset/assets/src/visualizations/PlaySlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const propTypes = {
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
reversed: PropTypes.bool,
disabled: PropTypes.bool,
range: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -30,6 +31,7 @@ const defaultProps = {
orientation: 'horizontal',
reversed: false,
disabled: false,
range: true,
};

export default class PlaySlider extends React.PureComponent {
Expand Down Expand Up @@ -84,15 +86,17 @@ export default class PlaySlider extends React.PureComponent {
this.setState({ intervalId: null });
}
step() {
if (this.props.disabled) {
const { start, end, step, values, disabled } = this.props;

if (disabled) {
return;
}
let values = this.props.values.map(value => value + this.increment);
if (values[1] > this.props.end) {
const cr = values[0] - this.props.start;
values = values.map(value => value - cr);
}
this.props.onChange(values);

const currentValues = Array.isArray(values) ? values : [values, values + step];
const nextValues = currentValues.map(value => value + this.increment);
const carriageReturn = (nextValues[1] > end) ? (nextValues[0] - start) : 0;

this.props.onChange(nextValues.map(value => value - carriageReturn));
}
formatter(values) {
if (this.props.disabled) {
Expand All @@ -108,6 +112,7 @@ export default class PlaySlider extends React.PureComponent {
return parts.map(value => (new Date(value)).toUTCString()).join(' : ');
}
render() {
const { start, end, step, orientation, reversed, disabled, range, values } = this.props;
return (
<Row className="play-slider">
<Col md={1} className="padded">
Expand All @@ -116,15 +121,16 @@ export default class PlaySlider extends React.PureComponent {
</Col>
<Col md={11} className="padded">
<ReactBootstrapSlider
value={this.props.values}
value={range ? values : values[0]}
range={range}
formatter={this.formatter}
change={this.onChange}
min={this.props.start}
max={this.props.end}
step={this.props.step}
orientation={this.props.orientation}
reversed={this.props.reversed}
disabled={this.props.disabled ? 'disabled' : 'enabled'}
min={start}
max={end}
step={step}
orientation={orientation}
reversed={reversed}
disabled={disabled ? 'disabled' : 'enabled'}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const propTypes = {
end: PropTypes.number.isRequired,
step: PropTypes.number.isRequired,
values: PropTypes.array.isRequired,
aggregation: PropTypes.bool,
disabled: PropTypes.bool,
viewport: PropTypes.object.isRequired,
children: PropTypes.node,
};

const defaultProps = {
aggregation: false,
disabled: false,
step: 1,
};
Expand All @@ -26,30 +28,41 @@ export default class AnimatableDeckGLContainer extends React.Component {
const { getLayers, start, end, step, values, disabled, viewport, ...other } = props;
this.state = { values, viewport };
this.other = other;
this.onChange = this.onChange.bind(this);
}
componentWillReceiveProps(nextProps) {
this.setState({ values: nextProps.values, viewport: nextProps.viewport });
}
onChange(newValues) {
this.setState({
values: Array.isArray(newValues)
? newValues
: [newValues, newValues + this.props.step],
});
}
render() {
const layers = this.props.getLayers(this.state.values);
const { start, end, step, disabled, aggregation, children, getLayers } = this.props;
const { values, viewport } = this.state;
const layers = getLayers(values);
return (
<div>
<DeckGLContainer
{...this.other}
viewport={this.state.viewport}
viewport={viewport}
layers={layers}
onViewportChange={newViewport => this.setState({ viewport: newViewport })}
/>
{!this.props.disabled &&
{!disabled &&
<PlaySlider
start={this.props.start}
end={this.props.end}
step={this.props.step}
values={this.state.values}
onChange={newValues => this.setState({ values: newValues })}
start={start}
end={end}
step={step}
values={values}
range={!aggregation}
onChange={this.onChange}
/>
}
{this.props.children}
{children}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class DeckGLScreenGrid extends React.PureComponent {
mapboxApiAccessToken={this.props.payload.data.mapboxApiKey}
mapStyle={this.props.slice.formData.mapbox_style}
setControlValue={this.props.setControlValue}
aggregation
/>
</div>
);
Expand Down

0 comments on commit 80b784d

Please sign in to comment.