Skip to content

Commit ae96824

Browse files
authored
Merge pull request #832 from plotly/colorscalepicker-adj
allow disabling colorscale dropdown
2 parents d36623d + 7d36408 commit ae96824

File tree

11 files changed

+143
-55
lines changed

11 files changed

+143
-55
lines changed

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.7.2",
22+
"react-colorscales": "0.7.3",
2323
"react-day-picker": "^7.2.4",
2424
"react-dropzone": "^5.0.1",
2525
"react-plotly.js": "^2.2.0",

src/components/fields/ColorscalePicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {connectToContainer} from 'lib';
66
import {EDITOR_ACTIONS} from 'lib/constants';
77

88
export class UnconnectedColorscalePicker extends Component {
9-
constructor(props) {
10-
super(props);
9+
constructor() {
10+
super();
1111
this.onUpdate = this.onUpdate.bind(this);
1212
}
1313

@@ -43,13 +43,15 @@ export class UnconnectedColorscalePicker extends Component {
4343
selected={colorscale}
4444
onColorscaleChange={this.onUpdate}
4545
initialCategory={this.props.initialCategory}
46+
disableCategorySwitch={this.props.disableCategorySwitch}
4647
/>
4748
</Field>
4849
);
4950
}
5051
}
5152

5253
UnconnectedColorscalePicker.propTypes = {
54+
labelWidth: PropTypes.number,
5355
fullValue: PropTypes.any,
5456
fullContainer: PropTypes.object,
5557
updatePlot: PropTypes.func,

src/components/fields/ColorwayPicker.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import React, {Component} from 'react';
55
import {connectToContainer} from 'lib';
66

77
class UnconnectedColorwayPicker extends Component {
8-
constructor(props) {
9-
super(props);
10-
}
11-
128
render() {
139
return (
1410
<Field {...this.props}>
1511
<ColorscalePickerWidget
1612
selected={this.props.fullValue}
1713
onColorscaleChange={this.props.updatePlot}
1814
initialCategory="categorical"
15+
disableCategorySwitch={this.props.disableCategorySwitch}
1916
/>
2017
</Field>
2118
);

src/components/fields/Field.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Field extends Component {
2828
units,
2929
extraComponent,
3030
fieldContainerClassName,
31+
labelWidth,
3132
} = this.props;
3233

3334
const {localize: _} = this.context;
@@ -55,7 +56,10 @@ class Field extends Component {
5556
return (
5657
<div className={containerClassName}>
5758
{label ? (
58-
<div className={bem('field', 'title')}>
59+
<div
60+
className={bem('field', 'title')}
61+
style={labelWidth ? {minWidth: labelWidth + 'px'} : {}}
62+
>
5963
{this.context.showFieldTooltips ? (
6064
<div
6165
className={bem('field', 'title-text')}
@@ -93,6 +97,7 @@ class Field extends Component {
9397
}
9498

9599
Field.propTypes = {
100+
labelWidth: PropTypes.number,
96101
center: PropTypes.bool,
97102
label: PropTypes.any,
98103
units: PropTypes.string,

src/components/fields/Info.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export default class Info extends Component {
55
render() {
66
return (
77
<Field {...this.props}>
8-
<div className="js-test-info">{this.props.children}</div>
8+
<div className={`js-test-info ${this.props.className ? this.props.className : ''}`}>
9+
{this.props.children}
10+
</div>
911
</Field>
1012
);
1113
}

src/components/widgets/ColorscalePicker.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import ColorscalePicker, {Colorscale, COLOR_PICKER_CONSTANTS} from 'react-colors
22
import Dropdown from './Dropdown';
33
import Info from '../fields/Info';
44
import PropTypes from 'prop-types';
5-
import React, {Component, Fragment} from 'react';
5+
import React, {Component} from 'react';
6+
// CAREFUL: needs to be the same value as $colorscalepicker-width in _colorscalepicker.scss
7+
const colorscalepickerContainerWidth = 240;
68

79
class Scale extends Component {
810
constructor(props) {
@@ -28,7 +30,7 @@ class Scale extends Component {
2830
}
2931

3032
render() {
31-
const {onColorscaleChange, selected} = this.props;
33+
const {onColorscaleChange, selected, disableCategorySwitch} = this.props;
3234
const {selectedColorscaleType, showColorscalePicker} = this.state;
3335
const description = COLOR_PICKER_CONSTANTS.COLORSCALE_DESCRIPTIONS[selectedColorscaleType];
3436
const colorscaleOptions = COLOR_PICKER_CONSTANTS.COLORSCALE_TYPES.filter(
@@ -40,33 +42,36 @@ class Scale extends Component {
4042
const _ = this.context.localize;
4143

4244
return (
43-
<div className="customPickerContainer__outer">
44-
<div className="customPickerContainer__inner">
45+
<div className="customPickerContainer">
46+
<div className="customPickerContainer__clickable">
4547
<Colorscale colorscale={selected} onClick={this.onClick} />
4648
</div>
4749
{showColorscalePicker ? (
48-
<div className="customPickerContainer">
49-
<Dropdown
50-
options={colorscaleOptions}
51-
value={selectedColorscaleType}
52-
onChange={this.onChange}
53-
clearable={false}
54-
searchable={false}
55-
placeholder={_('Select a Colorscale Type')}
56-
/>
50+
<div className="customPickerContainer__expanded-content">
51+
{disableCategorySwitch ? null : (
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+
className="customPickerContainer__category-dropdown"
60+
/>
61+
)}
5762
{description ? (
58-
<Fragment>
63+
<div className="customPickerContainer__palettes">
5964
<ColorscalePicker
6065
onChange={onColorscaleChange}
6166
colorscale={selected}
62-
width={215}
67+
width={colorscalepickerContainerWidth}
6368
colorscaleType={this.state.selectedColorscaleType}
6469
onColorscaleTypeChange={this.onColorscaleTypeChange}
6570
disableSwatchControls
6671
scaleLength={7}
6772
/>
68-
<Info>{description}</Info>
69-
</Fragment>
73+
<Info className="customPickerContainer__info">{description}</Info>
74+
</div>
7075
) : null}
7176
</div>
7277
) : null}
@@ -80,6 +85,7 @@ Scale.propTypes = {
8085
selected: PropTypes.array,
8186
label: PropTypes.string,
8287
initialCategory: PropTypes.string,
88+
disableCategorySwitch: PropTypes.bool,
8389
};
8490

8591
Scale.contextTypes = {

src/default_panels/StyleLayoutPanel.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,32 @@ const StyleLayoutPanel = (props, {localize: _}) => (
2323
<PlotlyFold name={_('Defaults')}>
2424
<ColorPicker label={_('Plot Background')} attr="plot_bgcolor" />
2525
<ColorPicker label={_('Margin Color')} attr="paper_bgcolor" />
26-
<PlotlySection name={_('Color Scales')} attr="colorway">
27-
<ColorwayPicker label={_('Categorical')} attr="colorway" />
28-
<ColorscalePicker label={_('Sequential')} attr="colorscale.sequential" />
26+
<PlotlySection name={_('Colorscales')} attr="colorway">
27+
<ColorwayPicker
28+
label={_('Categorical')}
29+
attr="colorway"
30+
disableCategorySwitch
31+
labelWidth={80}
32+
/>
33+
<ColorscalePicker
34+
label={_('Sequential')}
35+
attr="colorscale.sequential"
36+
disableCategorySwitch
37+
labelWidth={80}
38+
/>
2939
<ColorscalePicker
3040
label={_('Diverging')}
3141
attr="colorscale.diverging"
3242
initialCategory="divergent"
43+
disableCategorySwitch
44+
labelWidth={80}
45+
/>
46+
<ColorscalePicker
47+
label={_('Negative Sequential')}
48+
attr="colorscale.sequentialminus"
49+
disableCategorySwitch
50+
labelWidth={80}
3351
/>
34-
<ColorscalePicker label={_('Negative Sequential')} attr="colorscale.sequentialminus" />
3552
</PlotlySection>
3653
<PlotlySection name={_('Text')} attr="font.family">
3754
<FontSelector label={_('Typeface')} attr="font.family" clearable={false} />

src/default_panels/StyleTracesPanel.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ const StyleTracesPanel = (props, {localize: _}) => (
304304
/>
305305
<NumericFraction label={_('Jitter')} attr="jitter" />
306306
<Numeric label={_('Position')} attr="pointpos" step={0.1} showSlider />
307-
<MarkerColor suppressMultiValuedMessage label={_('Color')} attr="marker.color" />
307+
<MarkerColor
308+
suppressMultiValuedMessage
309+
label={_('Color')}
310+
attr="marker.color"
311+
labelWidth={80}
312+
/>
308313
<NumericFraction label={_('Point Opacity')} attr="marker.opacity" />
309314
<MarkerSize label={_('Size')} attr="marker.size" />
310315
<NumericReciprocal

src/lib/customTraceType.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ export function traceTypeToPlotlyInitFigure(traceType, gl = '') {
9393
sizeref: 1,
9494
type: 'cone',
9595
};
96+
case 'histogram2dcontour':
97+
return {
98+
type: 'histogram2dcontour',
99+
autocolorscale: true,
100+
};
101+
case 'histogram2d':
102+
return {
103+
type: 'histogram2d',
104+
autocolorscale: true,
105+
};
106+
case 'heatmap':
107+
return {
108+
type: 'heatmap',
109+
autocolorscale: true,
110+
};
111+
case 'contour':
112+
return {
113+
type: 'contour',
114+
autocolorscale: true,
115+
};
96116
default:
97117
return {type: traceType};
98118
}
Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
$colorscalepicker-width: 215px;
2-
$colorscalepicker-height: 20px;
1+
// this width is also passed in as a prop in widgets/ColorscalePicker.js
2+
$colorscalepicker-width: 240px;
3+
$colorscale-clickable-part-width: 180px;
4+
$text-padding: 5px;
35

6+
// We're making our own custom colorscale picker to better adapt to RCE layout
7+
// so we're not displaying some parts of the original colorscalepicker (categody dropdown, description)
8+
.colorscalePickerTopContainer {
9+
display: none;
10+
}
11+
12+
.colorscaleDescription {
13+
display: none;
14+
}
15+
16+
// We're overriding some of the styles of the original css container class of react-colorscales
17+
// because we don't need this functionality
418
.colorscalePickerContainer {
519
min-width: $colorscalepicker-width;
620
position: relative;
721
padding: 0;
822
resize: none;
923
border: none;
1024
background: none;
25+
max-height: none;
1126
}
1227

13-
.colorscalePickerContainer::-webkit-scrollbar {
14-
width: 5px;
15-
}
16-
17-
.colorscalePickerTopContainer {
18-
display: none;
19-
}
20-
21-
.colorscaleDescription {
22-
display: none;
23-
}
24-
28+
// Some more styling adjustments to original react-
2529
.colorscalePickerContainer input:focus {
2630
outline: none;
2731
}
@@ -30,21 +34,49 @@ $colorscalepicker-height: 20px;
3034
display: inline;
3135
}
3236
}
33-
37+
.colorscalePickerContainer::-webkit-scrollbar {
38+
width: 5px;
39+
}
3440
.colorscalePickerBottomContainer {
35-
padding-right: 3px;
41+
padding: $text-padding 0 0 0;
42+
}
43+
// Adjustments for cubehelix controls
44+
.colorscaleControlPanel {
45+
padding: 0;
46+
margin: 0;
47+
margin-left: 27%;
48+
width: 70%;
3649
}
3750

51+
// Our custom component, containing all the colorpicker
3852
.customPickerContainer {
39-
margin-top: var(--spacing-quarter-unit);
4053
text-align: left;
54+
width: $colorscale-clickable-part-width;
55+
}
4156

42-
&__outer {
43-
width: $colorscalepicker-width;
44-
text-align: center;
45-
}
57+
.customPickerContainer__clickable {
58+
margin-top: 5px;
59+
min-height: 27px;
60+
width: $colorscale-clickable-part-width;
61+
}
4662

47-
&__inner {
48-
height: $colorscalepicker-height;
49-
}
63+
// The expandable part of the component
64+
.customPickerContainer__expanded-content {
65+
margin-top: 10px;
66+
}
67+
68+
.customPickerContainer__category-dropdown {
69+
max-width: 100%;
70+
}
71+
72+
.customPickerContainer__palettes {
73+
margin-left: -60px;
74+
}
75+
76+
.customPickerContainer__info {
77+
width: $colorscalepicker-width;
78+
}
79+
80+
.customPickerContainer__category-dropdown {
81+
width: $colorscale-clickable-part-width !important;
5082
}

0 commit comments

Comments
 (0)