Skip to content
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
1 change: 0 additions & 1 deletion dev/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Inspector from 'react-inspector';
import tips from './tips';
import 'brace/mode/json';
import 'brace/theme/textmate';
import {categoryLayout, traceTypes, chartCategory} from 'lib/traceTypes';

// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
import ACCESS_TOKENS from '../accessTokens';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prop-types": "^15.5.10",
"raf": "^3.4.0",
"react-color": "^2.13.8",
"react-colorscales": "^0.4.2",
"react-colorscales": "0.5.7",
"react-dropzone": "^4.2.9",
"react-plotly.js": "^2.2.0",
"react-rangeslider": "^2.2.0",
Expand Down
8 changes: 7 additions & 1 deletion src/components/fields/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Field extends Component {
suppressMultiValuedMessage,
units,
extraComponent,
fieldContainerClassName,
} = this.props;

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

const containerClassName = classnames(bem('field'), {
[fieldContainerClassName]: Boolean(fieldContainerClassName),
});

return (
<div className={bem('field')}>
<div className={containerClassName}>
{label ? (
<div className={bem('field', 'title')}>
{this.context.showFieldTooltips ? (
Expand Down Expand Up @@ -98,6 +103,7 @@ Field.propTypes = {
suppressMultiValuedMessage: PropTypes.bool,
children: PropTypes.node,
extraComponent: PropTypes.any,
fieldContainerClassName: PropTypes.string,
};

Field.contextTypes = {
Expand Down
84 changes: 69 additions & 15 deletions src/components/widgets/ColorscalePicker.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,95 @@
import ColorscalePicker, {Colorscale} from 'react-colorscales';
import ColorscalePicker, {
Colorscale,
COLOR_PICKER_CONSTANTS,
} from 'react-colorscales';
import Dropdown from './Dropdown';
import Info from '../fields/Info';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import React, {Component, Fragment} from 'react';

class Scale extends Component {
constructor(props) {
super(props);
constructor() {
super();

this.state = {
selectedColorscaleType: 'sequential',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: in a group of traces, this default makes less sense, and should be overrideable to categorical

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, will look at how to select the initial state better in a subsequent pr..
but the structure is there to add it easily now :)

showColorscalePicker: false,
};
this.toggle = this.toggle.bind(this);

this.onChange = this.onChange.bind(this);
this.onClick = this.onClick.bind(this);
}

toggle() {
onClick() {
this.setState({
showColorscalePicker: !this.state.showColorscalePicker,
});
}

onChange(selectedColorscaleType) {
this.setState({selectedColorscaleType});
}

render() {
const {selected, onColorscaleChange} = this.props;
const {onColorscaleChange, selected} = this.props;
const {selectedColorscaleType, showColorscalePicker} = this.state;
const description =
COLOR_PICKER_CONSTANTS.COLORSCALE_DESCRIPTIONS[selectedColorscaleType];
const colorscaleOptions = COLOR_PICKER_CONSTANTS.COLORSCALE_TYPES.map(
type => ({
label: type + ' scales',
value: type,
})
);
const _ = this.context.localize;

return (
<div>
<Colorscale colorscale={selected} onClick={this.toggle} />
{this.state.showColorscalePicker ? (
<ColorscalePicker
onChange={onColorscaleChange}
colorscale={selected}
/>
<Fragment>
<Colorscale colorscale={selected} onClick={this.onClick} />

{showColorscalePicker ? (
<div className="customPickerContainer">
<Dropdown
options={colorscaleOptions}
value={selectedColorscaleType}
onChange={this.onChange}
clearable={false}
searchable={false}
placeholder={_('Select a Colorscale Type')}
/>
{description ? (
<Fragment>
<ColorscalePicker
onChange={onColorscaleChange}
colorscale={selected}
width={215}
colorscaleType={this.state.selectedColorscaleType}
onColorscaleTypeChange={this.onColorscaleTypeChange}
disableSwatchControls
scaleLength={7}
/>
<Info>{description}</Info>
</Fragment>
) : null}
</div>
) : null}
</div>
</Fragment>
);
}
}

Scale.propTypes = {
onColorscaleChange: PropTypes.func,
selected: PropTypes.array,
label: PropTypes.string,
};

Scale.contextTypes = {
localize: PropTypes.func,
};

Scale.contextTypes = {
localize: PropTypes.func,
};

export default Scale;
22 changes: 12 additions & 10 deletions src/styles/components/widgets/_colorscalepicker.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
.colorscalePickerContainer {
min-width: 215px;
position: relative;
width: 300px;
margin-left: -76px;
padding: 0;
resize: none;
border: none;
background: none;
}

.colorscalePickerContainer::-webkit-scrollbar {
width: 5px;
}

.colorscale-selected {
.colorscalePickerTopContainer {
display: none;
}

.rc-slider {
width: 254px !important;
.colorscaleDescription {
display: none;
}

.colorscaleControlPanel {
padding: 6px;
width: 94%;
.colorscalePickerContainer input:focus {
outline: none;
}

.colorscale-block {
margin: 0 20px !important;
.customPickerContainer {
margin-top: 10px;
}