Skip to content

Commit f45f92d

Browse files
committed
BinSize adjustments
1 parent 915159e commit f45f92d

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

src/EditorControls.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
shamefullyAdjustSplitStyleTargetContainers,
1212
shamefullyDeleteRelatedAnalysisTransforms,
1313
shamefullyAdjustSizeref,
14+
shamefullyAdjustBinSize,
1415
} from './shame';
1516
import {EDITOR_ACTIONS} from './lib/constants';
1617
import isNumeric from 'fast-isnumeric';
@@ -72,6 +73,7 @@ class EditorControls extends Component {
7273
}
7374

7475
shamefullyAdjustSizeref(graphDiv, payload);
76+
7577
shamefullyClearAxisTypes(graphDiv, payload);
7678
shamefullyAdjustAxisRef(graphDiv, payload);
7779
shamefullyAddTableColumns(graphDiv, payload);
@@ -80,6 +82,9 @@ class EditorControls extends Component {
8082
for (let i = 0; i < payload.traceIndexes.length; i++) {
8183
for (const attr in payload.update) {
8284
const traceIndex = payload.traceIndexes[i];
85+
86+
shamefullyAdjustBinSize(graphDiv, payload, traceIndex);
87+
8388
const splitTraceGroup = payload.splitTraceGroup
8489
? payload.splitTraceGroup.toString()
8590
: null;

src/components/fields/derived.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,15 @@ export const HoverColor = connectToContainer(UnconnectedColorPicker, {
679679
return plotProps;
680680
},
681681
});
682+
683+
export const BinSize = connectToContainer(UnconnectedNumeric, {
684+
modifyPlotProps: (props, context, plotProps) => {
685+
const {localize: _} = context;
686+
if (typeof plotProps.fullValue === 'string' && plotProps.fullValue[0] === 'M') {
687+
plotProps.fullValue = plotProps.fullValue.substring(1);
688+
plotProps.min = 1;
689+
plotProps.max = 12;
690+
plotProps.units = parseInt(plotProps.fullValue, 10) === 1 ? _('Month') : _('Months');
691+
}
692+
},
693+
});

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
HoveronDropdown,
5656
HovermodeDropdown,
5757
TickFormat,
58+
BinSize,
5859
NumericOrDate,
5960
} from './derived';
6061
import {LineDashSelector, LineShapeSelector} from './LineSelectors';
@@ -119,5 +120,6 @@ export {
119120
LocationSelector,
120121
HoveronDropdown,
121122
HovermodeDropdown,
123+
BinSize,
122124
NumericOrDate,
123125
};

src/default_panels/StyleTracesPanel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
ShowInLegend,
4040
TextInfo,
4141
HoveronDropdown,
42+
BinSize,
4243
} from '../components/fields/derived';
4344

4445
const StyleTracesPanel = (props, {localize: _}) => (
@@ -194,14 +195,14 @@ const StyleTracesPanel = (props, {localize: _}) => (
194195
/>
195196
</PlotlySection>
196197
<PlotlySection name={_('Binning')}>
197-
<Numeric label={_('X Bin Size')} attr="xbins.size" axis="x" />
198198
<NumericOrDate label={_('X Bin Start')} attr="xbins.start" axis="x" />
199199
<NumericOrDate label={_('X Bin End')} attr="xbins.end" axis="x" />
200+
<BinSize label={_('X Bin Size')} attr="xbins.size" axis="x" />
200201
<Numeric label={_('Max X Bins')} attr="nbinsx" />
201202

202203
<NumericOrDate label={_('Y Bin Start')} attr="ybins.start" axis="y" />
203204
<NumericOrDate label={_('Y Bin End')} attr="ybins.end" axis="y" />
204-
<Numeric label={_('Y Bin Size')} attr="ybins.size" axis="y" />
205+
<BinSize label={_('Y Bin Size')} attr="ybins.size" axis="y" />
205206
<Numeric label={_('Max Y Bins')} attr="nbinsy" />
206207
</PlotlySection>
207208
<PlotlySection label={_('Bar Position')}>

src/shame.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import {getFromId} from 'plotly.js/src/plots/cartesian/axis_ids';
55
import nestedProperty from 'plotly.js/src/lib/nested_property';
6+
import {isDateTime} from 'plotly.js/src/lib';
67

78
// Temporary fix for:
89
// https://github.com/plotly/react-chart-editor/issues/103
@@ -212,3 +213,22 @@ export const shamefullyAdjustSizeref = (gd, {update}) => {
212213
update['marker.sizemode'] = 'area';
213214
}
214215
};
216+
217+
export const shamefullyAdjustBinSize = (gd, {update}, traceIndexInDataArray) => {
218+
const traceIndexInFullDataArray = gd._fullData.filter(t => t.index === traceIndexInDataArray)[0]
219+
._expandedIndex;
220+
const binSizeAttrs = Object.keys(update).filter(attr => attr.includes('bins.size'));
221+
222+
binSizeAttrs.forEach(attr => {
223+
const attrHead = attr.split('.')[0];
224+
if (
225+
gd._fullData[traceIndexInFullDataArray] &&
226+
gd._fullData[traceIndexInFullDataArray][attrHead] &&
227+
gd._fullData[traceIndexInFullDataArray][attrHead].start &&
228+
isDateTime(gd._fullData[traceIndexInFullDataArray][attrHead].start)
229+
) {
230+
const monthNum = update[attr];
231+
update[attr] = 'M' + monthNum;
232+
}
233+
});
234+
};

0 commit comments

Comments
 (0)