Skip to content

Commit b27271d

Browse files
authored
Merge pull request #600 from plotly/adjust-colorscalepicker
Colorpicker adjustments
2 parents b09578a + e860bb2 commit b27271d

File tree

5 files changed

+89
-28
lines changed

5 files changed

+89
-28
lines changed

dev/App.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Inspector from 'react-inspector';
1111
import tips from './tips';
1212
import 'brace/mode/json';
1313
import 'brace/theme/textmate';
14-
import {categoryLayout, traceTypes, chartCategory} from 'lib/traceTypes';
1514

1615
// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
1716
import ACCESS_TOKENS from '../accessTokens';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"prop-types": "^15.5.10",
2020
"raf": "^3.4.0",
2121
"react-color": "^2.13.8",
22-
"react-colorscales": "^0.4.2",
22+
"react-colorscales": "0.5.7",
2323
"react-dropzone": "^4.2.9",
2424
"react-plotly.js": "^2.2.0",
2525
"react-rangeslider": "^2.2.0",

src/components/fields/Field.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Field extends Component {
2727
suppressMultiValuedMessage,
2828
units,
2929
extraComponent,
30+
fieldContainerClassName,
3031
} = this.props;
3132

3233
const {localize: _} = this.context;
@@ -48,8 +49,12 @@ class Field extends Component {
4849
' – ' + this.context.description.replace(/`/g, '"').replace(/\*/g, '"');
4950
}
5051

52+
const containerClassName = classnames(bem('field'), {
53+
[fieldContainerClassName]: Boolean(fieldContainerClassName),
54+
});
55+
5156
return (
52-
<div className={bem('field')}>
57+
<div className={containerClassName}>
5358
{label ? (
5459
<div className={bem('field', 'title')}>
5560
{this.context.showFieldTooltips ? (
@@ -98,6 +103,7 @@ Field.propTypes = {
98103
suppressMultiValuedMessage: PropTypes.bool,
99104
children: PropTypes.node,
100105
extraComponent: PropTypes.any,
106+
fieldContainerClassName: PropTypes.string,
101107
};
102108

103109
Field.contextTypes = {
Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,95 @@
1-
import ColorscalePicker, {Colorscale} from 'react-colorscales';
1+
import ColorscalePicker, {
2+
Colorscale,
3+
COLOR_PICKER_CONSTANTS,
4+
} from 'react-colorscales';
5+
import Dropdown from './Dropdown';
6+
import Info from '../fields/Info';
27
import PropTypes from 'prop-types';
3-
import React, {Component} from 'react';
8+
import React, {Component, Fragment} from 'react';
49

510
class Scale extends Component {
6-
constructor(props) {
7-
super(props);
11+
constructor() {
12+
super();
13+
814
this.state = {
15+
selectedColorscaleType: 'sequential',
916
showColorscalePicker: false,
1017
};
11-
this.toggle = this.toggle.bind(this);
18+
19+
this.onChange = this.onChange.bind(this);
20+
this.onClick = this.onClick.bind(this);
1221
}
1322

14-
toggle() {
23+
onClick() {
1524
this.setState({
1625
showColorscalePicker: !this.state.showColorscalePicker,
1726
});
1827
}
1928

29+
onChange(selectedColorscaleType) {
30+
this.setState({selectedColorscaleType});
31+
}
32+
2033
render() {
21-
const {selected, onColorscaleChange} = this.props;
34+
const {onColorscaleChange, selected} = this.props;
35+
const {selectedColorscaleType, showColorscalePicker} = this.state;
36+
const description =
37+
COLOR_PICKER_CONSTANTS.COLORSCALE_DESCRIPTIONS[selectedColorscaleType];
38+
const colorscaleOptions = COLOR_PICKER_CONSTANTS.COLORSCALE_TYPES.map(
39+
type => ({
40+
label: type + ' scales',
41+
value: type,
42+
})
43+
);
44+
const _ = this.context.localize;
45+
2246
return (
23-
<div>
24-
<Colorscale colorscale={selected} onClick={this.toggle} />
25-
{this.state.showColorscalePicker ? (
26-
<ColorscalePicker
27-
onChange={onColorscaleChange}
28-
colorscale={selected}
29-
/>
47+
<Fragment>
48+
<Colorscale colorscale={selected} onClick={this.onClick} />
49+
50+
{showColorscalePicker ? (
51+
<div className="customPickerContainer">
52+
<Dropdown
53+
options={colorscaleOptions}
54+
value={selectedColorscaleType}
55+
onChange={this.onChange}
56+
clearable={false}
57+
searchable={false}
58+
placeholder={_('Select a Colorscale Type')}
59+
/>
60+
{description ? (
61+
<Fragment>
62+
<ColorscalePicker
63+
onChange={onColorscaleChange}
64+
colorscale={selected}
65+
width={215}
66+
colorscaleType={this.state.selectedColorscaleType}
67+
onColorscaleTypeChange={this.onColorscaleTypeChange}
68+
disableSwatchControls
69+
scaleLength={7}
70+
/>
71+
<Info>{description}</Info>
72+
</Fragment>
73+
) : null}
74+
</div>
3075
) : null}
31-
</div>
76+
</Fragment>
3277
);
3378
}
3479
}
3580

3681
Scale.propTypes = {
3782
onColorscaleChange: PropTypes.func,
3883
selected: PropTypes.array,
84+
label: PropTypes.string,
85+
};
86+
87+
Scale.contextTypes = {
88+
localize: PropTypes.func,
89+
};
90+
91+
Scale.contextTypes = {
92+
localize: PropTypes.func,
3993
};
4094

4195
export default Scale;
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
.colorscalePickerContainer {
2+
min-width: 215px;
23
position: relative;
3-
width: 300px;
4-
margin-left: -76px;
4+
padding: 0;
5+
resize: none;
6+
border: none;
7+
background: none;
58
}
69

710
.colorscalePickerContainer::-webkit-scrollbar {
811
width: 5px;
912
}
1013

11-
.colorscale-selected {
14+
.colorscalePickerTopContainer {
1215
display: none;
1316
}
1417

15-
.rc-slider {
16-
width: 254px !important;
18+
.colorscaleDescription {
19+
display: none;
1720
}
1821

19-
.colorscaleControlPanel {
20-
padding: 6px;
21-
width: 94%;
22+
.colorscalePickerContainer input:focus {
23+
outline: none;
2224
}
2325

24-
.colorscale-block {
25-
margin: 0 20px !important;
26+
.customPickerContainer {
27+
margin-top: 10px;
2628
}

0 commit comments

Comments
 (0)