Skip to content

Feat/enable expressing overlap distance in step #210

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

Merged
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
9 changes: 7 additions & 2 deletions MultiSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ export default class MultiSlider extends React.Component {
snapped: false,
vertical: false,
minMarkerOverlapDistance: 0,
minMarkerOverlapStepDistance: 0,
};

constructor(props) {
super(props);

if(this.props.minMarkerOverlapDistance > 0 && this.props.minMarkerOverlapStepDistance > 0) {
console.error('You should provide either "minMarkerOverlapDistance" or "minMarkerOverlapStepDistance", not both. Expect unreliable results.');
}

this.optionsArray =
this.props.optionsArray ||
createArray(this.props.min, this.props.max, this.props.step);
Expand Down Expand Up @@ -161,7 +166,7 @@ export default class MultiSlider extends React.Component {
? 0
: this.props.minMarkerOverlapDistance > 0
? this.props.minMarkerOverlapDistance
: this.stepLength);
: (this.props.minMarkerOverlapStepDistance || 1) * this.stepLength);
var top =
trueTop === 0
? 0
Expand Down Expand Up @@ -233,7 +238,7 @@ export default class MultiSlider extends React.Component {
? 0
: this.props.minMarkerOverlapDistance > 0
? this.props.minMarkerOverlapDistance
: this.stepLength);
: (this.props.minMarkerOverlapStepDistance || 1) * this.stepLength);
var top = this.props.sliderLength - this.props.markerSize / 2;
var confined =
unconfined < bottom ? bottom : unconfined > top ? top : unconfined;
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ Feel free to contribute to this part of the documentation.
| markerOffsetX | 0 | number | Offset the cursor(s) on the X axis |
| markerOffsetY | 0 | number | Offset the cursor(s) on the Y axis |
| markerSize | 0 | number | It determines the marker margin from the edges of the track, useful to avoid the markers to overflow out of the track. |
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. |
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapDistance |
| minMarkerOverlapStepDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in steps, not pixels). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapStepDistance |
| imageBackgroundSource | undefined | string | Specifies the source as required by [ImageBackground](https://facebook.github.io/react-native/docs/imagebackground)|
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface MultiSliderProps {
markerOffsetX?: number;
markerOffsetY?: number;
minMarkerOverlapDistance?: number;
minMarkerOverlapStepDistance?: number;
imageBackgroundSource?: string;
enableLabel?: boolean;
vertical?: boolean;
Expand Down