Skip to content

Commit 1bebf70

Browse files
implementation specific naming for Box* + min max transformation
1 parent cd37d4c commit 1bebf70

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

src/DefaultEditor.js

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

27-
import {BoxWidth, BoxPad} from './shame';
27+
import {LayoutNumericFractionInverse, LayoutNumericFraction} from './shame';
2828

2929
const LayoutPanel = connectLayoutToPlot(Panel);
3030
const AxesFold = connectAxesToLayout(Fold);
@@ -148,10 +148,22 @@ class DefaultEditor extends Component {
148148
</TraceMarkerSection>
149149

150150
<Section name={_('Size and Spacing')}>
151-
<BoxWidth label={_('Bar Width')} attr="bargap" />
152-
<BoxWidth label={_('Box Width')} attr="boxgap" />
153-
<BoxPad label={_('Bar Padding')} attr="bargroupgap" />
154-
<BoxPad label={_('Box Padding')} attr="boxgroupgap" />
151+
<LayoutNumericFractionInverse
152+
label={_('Bar Width')}
153+
attr="bargap"
154+
/>
155+
<LayoutNumericFractionInverse
156+
label={_('Box Width')}
157+
attr="boxgap"
158+
/>
159+
<LayoutNumericFraction
160+
label={_('Bar Padding')}
161+
attr="bargroupgap"
162+
/>
163+
<LayoutNumericFraction
164+
label={_('Box Padding')}
165+
attr="boxgroupgap"
166+
/>
155167
</Section>
156168

157169
<Section name={_('Lines')}>

src/shame.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ const supplyLayoutPlotProps = (props, context) => {
3636
});
3737
};
3838

39-
export const BoxWidth = connectLayoutToPlot(
39+
export const LayoutNumericFractionInverse = connectLayoutToPlot(
4040
connectToContainer(NumericNoArrows, {
4141
supplyPlotProps: supplyLayoutPlotProps,
4242
modifyPlotProps: (props, context, plotProps) => {
43-
const {fullValue, updatePlot} = plotProps;
43+
const {attrMeta, fullValue, updatePlot} = plotProps;
4444
plotProps.fullValue = () => {
4545
let fv = fullValue();
4646
if (isNumeric(fv)) {
@@ -57,16 +57,25 @@ export const BoxWidth = connectLayoutToPlot(
5757
}
5858
};
5959

60-
plotProps.max = 100;
60+
// Also take the inverse of max and min.
61+
if (attrMeta) {
62+
if (isNumeric(attrMeta.min)) {
63+
plotProps.max = (1 - attrMeta.min) * 100;
64+
}
65+
66+
if (isNumeric(attrMeta.max)) {
67+
plotProps.min = (1 - attrMeta.max) * 100;
68+
}
69+
}
6170
},
6271
})
6372
);
6473

65-
export const BoxPad = connectLayoutToPlot(
74+
export const LayoutNumericFraction = connectLayoutToPlot(
6675
connectToContainer(NumericNoArrows, {
6776
supplyPlotProps: supplyLayoutPlotProps,
6877
modifyPlotProps: (props, context, plotProps) => {
69-
const {fullValue, updatePlot} = plotProps;
78+
const {attrMeta, fullValue, updatePlot} = plotProps;
7079
plotProps.fullValue = () => {
7180
let fv = fullValue();
7281
if (isNumeric(fv)) {
@@ -83,7 +92,15 @@ export const BoxPad = connectLayoutToPlot(
8392
}
8493
};
8594

86-
plotProps.max = 100;
95+
if (attrMeta) {
96+
if (isNumeric(attrMeta.max)) {
97+
plotProps.max = attrMeta.max * 100;
98+
}
99+
100+
if (isNumeric(attrMeta.max)) {
101+
plotProps.min = attrMeta.min * 100;
102+
}
103+
}
87104
},
88105
})
89106
);

0 commit comments

Comments
 (0)