Skip to content
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

ColorScales default scale is changed to latest selection #91

Open
asnyv opened this issue Mar 9, 2021 · 0 comments
Open

ColorScales default scale is changed to latest selection #91

asnyv opened this issue Mar 9, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@asnyv
Copy link
Collaborator

asnyv commented Mar 9, 2021

When using the ColorScales component, the colorscale default changes to the latest selection as the ColorscalePicker is initialized again with a colorscale prop that has been changed. The ColorscalePicker should always be initialized with the original input colorscale prop (if available). Also, the nSwatches should rather be
nSwatches || colorscale.length || DEFAULT_SCALE.length to use the input colorscale length as default if nSwatches is not defined in input, and colorscale is.

Something that works is to do change the constructor to:

constructor(props) {
    super(props);
    this.state = {
        showColorscalePicker: false,
        defaultColorscale: this.props.colorscale || DEFAULT_SCALE,
        colorscale: this.props.colorscale || DEFAULT_SCALE,
    };
}

and switch input in ColorscalePicker to

colorscale={this.state.defaultColorscale}
nSwatches={nSwatches || this.state.defaultColorscale.length}

but not sure if it is the "right" way to solve such issues in React/JS.

colorscale={colorscale || DEFAULT_SCALE}
nSwatches={nSwatches || DEFAULT_SCALE.length}

@asnyv asnyv added the bug Something isn't working label Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant