-
-
Notifications
You must be signed in to change notification settings - Fork 144
Omit marks that are outside of range specified by min and max. #695
Changes from 21 commits
709f46c
3bf1241
480511f
01324bf
5cb8509
9c94308
396756e
4bdaf71
1f5d15d
a93fa42
fdd296b
ad838fc
c8070d4
9e2ee6b
4d03221
5a6a845
bbb4fea
a0aad56
1261f90
e4476ea
b7dee1a
edc2784
df14f7d
b9a8fcf
dfee39a
3e32f28
473e86a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {assoc, omit} from 'ramda'; | ||
import {assoc, omit, contains, pickBy, merge} from 'ramda'; | ||
import {Range, createSliderWithTooltip} from 'rc-slider'; | ||
|
||
/** | ||
|
@@ -42,6 +42,7 @@ export default class RangeSlider extends Component { | |
tooltip, | ||
updatemode, | ||
vertical, | ||
verticalHeight, | ||
} = this.props; | ||
const value = this.state.value; | ||
|
||
|
@@ -58,14 +59,51 @@ export default class RangeSlider extends Component { | |
tipProps = tooltip; | ||
} | ||
|
||
const truncatedMarks = this.props.marks | ||
? pickBy( | ||
(k, mark) => mark >= this.props.min && mark <= this.props.max, | ||
this.props.marks | ||
) | ||
: this.props.marks; | ||
|
||
let style = { | ||
padding: '25px', | ||
}; | ||
|
||
if ( | ||
!vertical && | ||
(!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, ['top', 'topLeft', 'topRight'])) | ||
) { | ||
style = merge(style, {paddingTop: '0px'}); | ||
} | ||
|
||
if ( | ||
vertical && | ||
(!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, [ | ||
'left', | ||
'topRight', | ||
'bottomRight', | ||
])) | ||
) { | ||
style = merge(style, {paddingLeft: '0px'}); | ||
} | ||
|
||
if (vertical) { | ||
style = merge(style, {height: verticalHeight + 'px'}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return ( | ||
<div | ||
id={id} | ||
data-dash-is-loading={ | ||
(loading_state && loading_state.is_loading) || undefined | ||
} | ||
className={className} | ||
style={vertical ? {height: '100%'} : {}} | ||
style={style} | ||
> | ||
<this.DashSlider | ||
onChange={value => { | ||
|
@@ -82,8 +120,16 @@ export default class RangeSlider extends Component { | |
}} | ||
tipProps={tipProps} | ||
value={value} | ||
marks={truncatedMarks} | ||
{...omit( | ||
['className', 'value', 'setProps', 'updatemode'], | ||
[ | ||
'className', | ||
'value', | ||
'setProps', | ||
'marks', | ||
'updatemode', | ||
'verticalHeight', | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for now, but just because I'm thinking about it: I'd like us to consider moving away from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcjohnson Agreed for DCC! There's also a bit of this happening in the table fragments / d3-format wrappers that should be looked into. Due to its generated nature I'd say whether this makes sense on HTML components would have to be evaluated independently. Can you open an issue for follow up and tag it for |
||
this.props | ||
)} | ||
/> | ||
|
@@ -213,6 +259,11 @@ RangeSlider.propTypes = { | |
*/ | ||
vertical: PropTypes.bool, | ||
|
||
/** | ||
* The height, in px, of the slider if it is vertical. | ||
*/ | ||
verticalHeight: PropTypes.number, | ||
|
||
/** | ||
* Determines when the component should update | ||
* its value. If `mouseup`, then the slider | ||
|
@@ -281,4 +332,5 @@ RangeSlider.defaultProps = { | |
updatemode: 'mouseup', | ||
persisted_props: ['value'], | ||
persistence_type: 'local', | ||
verticalHeight: 400, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import React, {Component} from 'react'; | ||
import ReactSlider, {createSliderWithTooltip} from 'rc-slider'; | ||
import PropTypes from 'prop-types'; | ||
import {assoc, omit} from 'ramda'; | ||
import {assoc, omit, pickBy, contains, merge} from 'ramda'; | ||
import './css/[email protected]'; | ||
|
||
/** | ||
|
@@ -42,6 +42,7 @@ export default class Slider extends Component { | |
tooltip, | ||
updatemode, | ||
vertical, | ||
verticalHeight, | ||
} = this.props; | ||
const value = this.state.value; | ||
|
||
|
@@ -58,14 +59,51 @@ export default class Slider extends Component { | |
tipProps = tooltip; | ||
} | ||
|
||
const truncatedMarks = this.props.marks | ||
? pickBy( | ||
(k, mark) => mark >= this.props.min && mark <= this.props.max, | ||
this.props.marks | ||
) | ||
: this.props.marks; | ||
|
||
let style = { | ||
padding: '25px', | ||
}; | ||
|
||
if ( | ||
!vertical && | ||
(!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, ['top', 'topLeft', 'topRight'])) | ||
) { | ||
style = merge(style, {paddingTop: '0px'}); | ||
} | ||
|
||
if ( | ||
vertical && | ||
(!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, [ | ||
'left', | ||
'topRight', | ||
'bottomRight', | ||
])) | ||
) { | ||
style = merge(style, {paddingLeft: '0px'}); | ||
} | ||
|
||
if (vertical) { | ||
style = merge(style, {height: verticalHeight + 'px'}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
return ( | ||
<div | ||
id={id} | ||
data-dash-is-loading={ | ||
(loading_state && loading_state.is_loading) || undefined | ||
} | ||
className={className} | ||
style={vertical ? {height: '100%'} : {}} | ||
style={style} | ||
> | ||
<this.DashSlider | ||
onChange={value => { | ||
|
@@ -82,8 +120,16 @@ export default class Slider extends Component { | |
}} | ||
tipProps={tipProps} | ||
value={value} | ||
marks={truncatedMarks} | ||
{...omit( | ||
['className', 'setProps', 'updatemode', 'value'], | ||
[ | ||
'className', | ||
'setProps', | ||
'updatemode', | ||
'value', | ||
'marks', | ||
'verticalHeight', | ||
], | ||
this.props | ||
)} | ||
/> | ||
|
@@ -194,6 +240,11 @@ Slider.propTypes = { | |
*/ | ||
vertical: PropTypes.bool, | ||
|
||
/** | ||
* The height, in px, of the slider if it is vertical. | ||
*/ | ||
verticalHeight: PropTypes.number, | ||
|
||
/** | ||
* Determines when the component should update | ||
* its value. If `mouseup`, then the slider | ||
|
@@ -262,4 +313,5 @@ Slider.defaultProps = { | |
updatemode: 'mouseup', | ||
persisted_props: ['value'], | ||
persistence_type: 'local', | ||
verticalHeight: 400, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A matter of personal preference, but you can also make this more compact with
JS does not return a boolean for
&&
,||
, etc. but rather the last evaluated value.