Giter VIP home page Giter VIP logo

Comments (9)

lukashlavacka avatar lukashlavacka commented on June 12, 2024 1

I have implemented something similar to this using the existing code. I achieved it by separating the internal value and display value. I wanted to implement exponential scaling. So lets imagine I want only to have values 1, 2, 4, 8, ..., 1024. In this case I would hold in state the "internal" value (0, ..., 10) and calculate the rest on the fly:

var ExpSlider = React.createFactory(React.createClass({
    transformFromUI(value){
        return Math.pow(2, value)
    },
    transformToUI(value){
        return Math.log(value) / Math.log(2)
    },
    handleChange(value) {
        this.setState({
            value: value
        })

        this.props.handleChange(this.transformFromUI(value));
    },
    getInitialState() {
        return {
            value: this.tranformToUI(this.props.min)
        }
    },
    getDefaultProps(){
        min: 1,
        max: 1024,
        value: 1
    },
    componentWillReceiveProps(nextProps){
        this.setState({ value: this.transformToUI(nextProps.value) })
    },
    render() {
        return (
            <ReactSlider
                value={this.state.value}
                min={this.tranformToUI(this.props.min)}
                max={this.tranformToUI(this.props.max)}
                onChange={this.handleChange}
            >
                <div>{this.tranformToUI(this.state.value)}</div>
            </ReactSlider>
        );
    }
}))

With this approach you can create slider with 100 values between 0.0 and 1.0 just by dividing and multiplying by 100 and using Math.floor or similar scaling and step you want.

Please excuse any issues as I did not have time to to create an example. But something similar works quite well in my code.

from react-slider.

stevenpetryk avatar stevenpetryk commented on June 12, 2024 1

I agree with @lukashlavacka's solution. A scaling function doesn't really need to be present in this plugin since you can just calculate that elsewhere.

from react-slider.

raulmatei avatar raulmatei commented on June 12, 2024

+1

from react-slider.

LoicUV avatar LoicUV commented on June 12, 2024

+1
has any of you come up with a solution since june @dmitry @raulmatei ?

from react-slider.

dmitry avatar dmitry commented on June 12, 2024

@alexmugford how does this related to the #40?

from react-slider.

alexmugford avatar alexmugford commented on June 12, 2024

@dmitry sorry, misunderstood the scaling being requested!

from react-slider.

mauricesvay avatar mauricesvay commented on June 12, 2024

👍

from react-slider.

joshwcomeau avatar joshwcomeau commented on June 12, 2024

Is this something that the authors would be willing to accept a PR for? I'd happily implement the scaling function if it's something the authors would like to have in their project.

from react-slider.

stale avatar stale commented on June 12, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from react-slider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.