Skip to content

Commit 04c83ef

Browse files
utilize trace > layout connected workaround for <BoxGap>
1 parent 1ba847d commit 04c83ef

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/DefaultEditor.js

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
import {DEFAULT_FONTS} from './constants';
2525
import {localize, connectAxesToLayout, connectLayoutToPlot} from './lib';
2626

27+
import {BoxGap} from './shame';
28+
2729
const LayoutPanel = connectLayoutToPlot(Panel);
2830
const AxesFold = connectAxesToLayout(Fold);
2931

@@ -145,6 +147,21 @@ class DefaultEditor extends Component {
145147
<ColorPicker label={_('Border Color')} attr="marker.line.color" />
146148
</TraceMarkerSection>
147149

150+
<Section name={_('Size and Spacing')}>
151+
<BoxGap label={_('Bar Width')} attr="bargap" />
152+
<BoxGap label={_('Box Width')} attr="boxgap" />
153+
<BoxGap
154+
label={_('Bar Padding')}
155+
attr="bargroupgap"
156+
showArrows={false}
157+
/>
158+
<BoxGap
159+
label={_('Box Padding')}
160+
attr="boxgroupgap"
161+
showArrows={false}
162+
/>
163+
</Section>
164+
148165
<Section name={_('Lines')}>
149166
<Numeric label={_('Width')} step={1.0} attr="line.width" />
150167
<ColorPicker label={_('Line Color')} attr="line.color" />

src/components/containers/Section.js

+4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export default class Section extends Component {
5858
} else {
5959
plotProps = {isVisible: true};
6060
}
61+
62+
// assign plotProps as a prop of children. If they are connectedToContainer
63+
// it will see plotProps and skip recomputing them.
6164
const childProps = Object.assign({plotProps}, child.props);
65+
6266
childProps.key = i;
6367
attrChildren.push(cloneElement(child, childProps));
6468
}

src/components/fields/Numeric.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
55
import {connectToContainer} from '../../lib';
66

7-
class Numeric extends Component {
7+
export class UnconnectedNumeric extends Component {
88
render() {
99
return (
1010
<Field {...this.props}>
@@ -23,7 +23,7 @@ class Numeric extends Component {
2323
}
2424
}
2525

26-
Numeric.propTypes = {
26+
UnconnectedNumeric.propTypes = {
2727
defaultValue: PropTypes.number,
2828
fullValue: PropTypes.func,
2929
min: PropTypes.number,
@@ -34,8 +34,8 @@ Numeric.propTypes = {
3434
...Field.propTypes,
3535
};
3636

37-
Numeric.defaultProps = {
37+
UnconnectedNumeric.defaultProps = {
3838
showArrows: true,
3939
};
4040

41-
export default connectToContainer(Numeric);
41+
export default connectToContainer(UnconnectedNumeric);

src/shame.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/*
2-
* DELETE THIS FILE AND EVERYTHING IN IT.
2+
* DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
33
*/
44
import {list} from 'plotly.js/src/plots/cartesian/axis_ids';
5+
import {UnconnectedNumeric} from './components/fields/Numeric';
6+
import {
7+
connectLayoutToPlot,
8+
connectToContainer,
9+
getLayoutContext,
10+
unpackPlotProps,
11+
} from './lib';
512

613
export function noShame(opts) {
714
if (opts.plotly && !opts.plotly.Axes) {
@@ -10,3 +17,27 @@ export function noShame(opts) {
1017
};
1118
}
1219
}
20+
21+
class NumericNoArrows extends UnconnectedNumeric {}
22+
NumericNoArrows.propTypes = UnconnectedNumeric.propTypes;
23+
NumericNoArrows.defaultProps = {
24+
showArrows: false,
25+
};
26+
27+
export const BoxGap = connectLayoutToPlot(
28+
connectToContainer(NumericNoArrows, {
29+
supplyPlotProps: (props, context) => {
30+
// workaround the issue with nested layouts inside trace component.
31+
// See
32+
// https://github.com/plotly/react-plotly.js-editor/issues/58#issuecomment-345492794
33+
const plotProps = unpackPlotProps(props, {
34+
...context,
35+
...getLayoutContext(context),
36+
});
37+
38+
// Full value should multiply by percentage if number.
39+
40+
return plotProps;
41+
},
42+
})
43+
);

0 commit comments

Comments
 (0)