Skip to content

Commit 84a47f8

Browse files
Marc-Andre-RivetJHSaunders
authored andcommitted
Async Slider and RangeSlider (plotly#739)
1 parent 07a0e18 commit 84a47f8

File tree

11 files changed

+308
-570
lines changed

11 files changed

+308
-570
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6-
76
### Changed
7+
- [#739](https://github.com/plotly/dash-core-components/pull/739) Async Slider and RangeSlider
88
- [#729](https://github.com/plotly/dash-core-components/pull/729) Handle case where dcc fails to load when used inside an iframe with a sandbox attribute that only has allow-scripts
99

10+
### Fixed
11+
- [#730](https://github.com/plotly/dash-core-components/pull/730) Fixed bug in which input components with type `number` did not correctly update their values.
12+
- [#731](https://github.com/plotly/dash-core-components/pull/731) Fixed bug where non-clearable dropdowns could still be cleared by typing backspace
13+
1014
## [1.7.1] - 2020-01-15 (JS-only)
1115
### Fixed
1216
- [#734](https://github.com/plotly/dash-core-components/pull/734) Fix JS-facing release bug where `Plotly.js` was listed in `devDependencies` instead of `dependencies`
@@ -19,10 +23,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1923
- Added responsiveness on graph parent element resize (previously only worked on window.resize)
2024
- Added new `dash-graph--pending` class to dcc.Graph, present while resizing, (re-)rendering, loading
2125

22-
### Fixed
23-
- [#730](https://github.com/plotly/dash-core-components/pull/730) Fixed bug in which input components with type `number` did not correctly update their values.
24-
- [#731](https://github.com/plotly/dash-core-components/pull/731) Fixed bug where non-clearable dropdowns could still be cleared by typing backspace
25-
2626
### Changed
2727
- [#723](https://github.com/plotly/dash-core-components/pull/723) Changed npm package content to allow source code inclusion from other projects
2828
- [#725](https://github.com/plotly/dash-core-components/pull/725) Improve async graph performance by parallelizing resource fetching instead of fetching sequentially

dash_core_components_base/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
'graph',
4646
'highlight',
4747
'markdown',
48+
'slider',
4849
'upload'
4950
]
5051

package-lock.json

Lines changed: 37 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
"plotly.js": "1.52.1",
4242
"prop-types": "^15.6.0",
4343
"ramda": "^0.26.1",
44-
"rc-slider": "^8.6.11",
44+
"rc-slider": "^9.1.0",
4545
"react-addons-shallow-compare": "^15.6.0",
4646
"react-dates": "^20.1.0",
4747
"react-docgen": "^3.0.0",
4848
"react-dropzone": "^4.1.2",
4949
"react-markdown": "^4.0.6",
50+
"react-resize-detector": "^4.2.1",
5051
"react-select-fast-filter-options": "^0.2.3",
5152
"react-virtualized-select": "^3.1.3",
52-
"react-resize-detector": "^4.2.1",
5353
"uniqid": "^5.0.3"
5454
},
5555
"devDependencies": {

src/components/RangeSlider.react.js

Lines changed: 10 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,19 @@
1-
import React, {Component} from 'react';
1+
import React, {Component, lazy, Suspense} from 'react';
22
import PropTypes from 'prop-types';
3-
import {assoc, omit, pickBy} from 'ramda';
4-
import {Range, createSliderWithTooltip} from 'rc-slider';
5-
import computeSliderStyle from '../utils/computeSliderStyle';
3+
import rangeSlider from '../utils/LazyLoader/rangeSlider';
4+
5+
const RealRangeSlider = lazy(rangeSlider);
66

77
/**
88
* A double slider with two handles.
99
* Used for specifying a range of numerical values.
1010
*/
1111
export default class RangeSlider extends Component {
12-
constructor(props) {
13-
super(props);
14-
this.propsToState = this.propsToState.bind(this);
15-
this.DashSlider = props.tooltip
16-
? createSliderWithTooltip(Range)
17-
: Range;
18-
this._computeStyle = computeSliderStyle();
19-
}
20-
21-
propsToState(newProps) {
22-
this.setState({value: newProps.value});
23-
}
24-
25-
componentWillReceiveProps(newProps) {
26-
if (newProps.tooltip !== this.props.tooltip) {
27-
this.DashSlider = newProps.tooltip
28-
? createSliderWithTooltip(Range)
29-
: Range;
30-
}
31-
this.propsToState(newProps);
32-
}
33-
34-
componentWillMount() {
35-
this.propsToState(this.props);
36-
}
37-
3812
render() {
39-
const {
40-
className,
41-
id,
42-
loading_state,
43-
setProps,
44-
tooltip,
45-
updatemode,
46-
vertical,
47-
verticalHeight,
48-
} = this.props;
49-
const value = this.state.value;
50-
51-
let tipProps;
52-
if (tooltip && tooltip.always_visible) {
53-
/**
54-
* clone `tooltip` but with renamed key `always_visible` -> `visible`
55-
* the rc-tooltip API uses `visible`, but `always_visible is more semantic
56-
* assigns the new (renamed) key to the old key and deletes the old key
57-
*/
58-
tipProps = assoc('visible', tooltip.always_visible, tooltip);
59-
delete tipProps.always_visible;
60-
} else {
61-
tipProps = tooltip;
62-
}
63-
64-
const truncatedMarks =
65-
this.props.marks &&
66-
pickBy(
67-
(k, mark) => mark >= this.props.min && mark <= this.props.max,
68-
this.props.marks
69-
);
70-
7113
return (
72-
<div
73-
id={id}
74-
data-dash-is-loading={
75-
(loading_state && loading_state.is_loading) || undefined
76-
}
77-
className={className}
78-
style={this._computeStyle(vertical, verticalHeight, tooltip)}
79-
>
80-
<this.DashSlider
81-
onChange={value => {
82-
if (updatemode === 'drag') {
83-
setProps({value});
84-
} else {
85-
this.setState({value});
86-
}
87-
}}
88-
onAfterChange={value => {
89-
if (updatemode === 'mouseup') {
90-
setProps({value});
91-
}
92-
}}
93-
tipProps={tipProps}
94-
value={value}
95-
marks={truncatedMarks}
96-
{...omit(
97-
[
98-
'className',
99-
'value',
100-
'setProps',
101-
'marks',
102-
'updatemode',
103-
'verticalHeight',
104-
],
105-
this.props
106-
)}
107-
/>
108-
</div>
14+
<Suspense fallback={null}>
15+
<RealRangeSlider {...this.props} />
16+
</Suspense>
10917
);
11018
}
11119
}
@@ -306,3 +214,6 @@ RangeSlider.defaultProps = {
306214
persistence_type: 'local',
307215
verticalHeight: 400,
308216
};
217+
218+
export const propTypes = RangeSlider.propTypes;
219+
export const defaultProps = RangeSlider.defaultProps;

0 commit comments

Comments
 (0)