Skip to content

Commit ad72272

Browse files
authored
Merge pull request #687 from plotly/localize-subplots
localize subplot names
2 parents fd1e4c2 + 2529960 commit ad72272

File tree

6 files changed

+67
-100
lines changed

6 files changed

+67
-100
lines changed

src/components/containers/SubplotAccordion.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
connectTraceToPlot,
77
connectCartesianSubplotToLayout,
88
connectNonCartesianSubplotToLayout,
9+
getSubplotTitle,
910
} from 'lib';
1011
import {TRACE_TO_AXIS, SUBPLOT_TO_ATTR} from 'lib/constants';
1112

@@ -15,7 +16,7 @@ const CartesianSubplotFold = connectCartesianSubplotToLayout(PlotlyFold);
1516

1617
class SubplotAccordion extends Component {
1718
render() {
18-
const {data = [], layout = {}} = this.context;
19+
const {data = [], layout = {}, localize: _} = this.context;
1920
const {children, messageIfEmptyFold} = this.props;
2021
const subplotFolds = [];
2122

@@ -31,8 +32,12 @@ class SubplotAccordion extends Component {
3132
acc.push({
3233
xaxis: xaxis,
3334
yaxis: yaxis,
34-
xaxisName: curVal.xaxis || 'x1',
35-
yaxisName: curVal.yaxis || 'y1',
35+
xaxisName: curVal.xaxis
36+
? getSubplotTitle(curVal.xaxis, 'x', _)
37+
: 'X 1',
38+
yaxisName: curVal.yaxis
39+
? getSubplotTitle(curVal.yaxis, 'y', _)
40+
: 'Y 1',
3641
index: [inx],
3742
});
3843
} else {
@@ -52,7 +57,7 @@ class SubplotAccordion extends Component {
5257
messageIfEmpty={messageIfEmptyFold}
5358
xaxis={d.xaxis}
5459
yaxis={d.yaxis}
55-
name={`${d.xaxisName} ${d.yaxisName}`}
60+
name={`${d.xaxisName} | ${d.yaxisName}`}
5661
>
5762
{children}
5863
</CartesianSubplotFold>
@@ -87,8 +92,10 @@ class SubplotAccordion extends Component {
8792

8893
Object.keys(layout).forEach(layoutKey => {
8994
const traceIndexes = [];
95+
let subplotName;
9096
if (
9197
['geo', 'mapbox', 'polar', 'gl3d', 'ternary'].some(subplotType => {
98+
subplotName = getSubplotTitle(layoutKey, subplotType, _);
9299
const trIndex =
93100
SUBPLOT_TO_ATTR[subplotType].layout === layoutKey
94101
? data.findIndex(trace =>
@@ -111,23 +118,34 @@ class SubplotAccordion extends Component {
111118
canDelete={false}
112119
messageIfEmpty={messageIfEmptyFold}
113120
subplot={layoutKey}
114-
name={layoutKey}
121+
name={subplotName}
115122
>
116123
{children}
117124
</NonCartesianSubplotFold>
118125
);
119126
}
120127
});
121128

129+
let pieCounter = 0;
130+
let tableCounter = 0;
122131
data.forEach((d, i) => {
123132
if ((d.type === 'pie' && d.values) || d.type === 'table') {
133+
if (d.type === 'pie') {
134+
pieCounter++;
135+
} else if (d.type === 'table') {
136+
tableCounter++;
137+
}
124138
subplotFolds[i] = (
125139
<TraceFold
126140
key={i}
127141
traceIndexes={[i]}
128142
canDelete={false}
129143
messageIfEmpty={messageIfEmptyFold}
130-
name={`${d.type} ${i}`}
144+
name={
145+
d.type === 'pie'
146+
? `${_('Pie')} ${pieCounter > 1 ? pieCounter : ''}`
147+
: `${_('Table')} ${tableCounter > 1 ? tableCounter : ''}`
148+
}
131149
>
132150
{children}
133151
</TraceFold>

src/components/fields/SubplotCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class UnconnectedSubplotCreator extends Component {
131131

132132
function getOptions(subplotType) {
133133
return fullLayout._subplots[subplotType].map(subplotId => ({
134-
label: getSubplotTitle(subplotId, subplotType),
134+
label: getSubplotTitle(subplotId, subplotType, _),
135135
value: subplotId,
136136
}));
137137
}

src/lib/constants.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ export const TRACE_TO_AXIS = {
7979
// Note: scene, and xaxis/yaxis were added for convenience sake even though they're not subplot types
8080
export const SUBPLOT_TO_ATTR = {
8181
cartesian: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
82-
xaxis: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
83-
yaxis: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
82+
xaxis: {data: 'xaxis', layout: 'x'},
83+
yaxis: {data: 'yaxis', layout: 'y'},
84+
x: {data: 'xaxis', layout: 'x'},
85+
y: {data: 'yaxis', layout: 'y'},
8486
ternary: {data: 'subplot', layout: 'ternary'},
8587
gl3d: {data: 'scene', layout: 'scene'},
8688
scene: {data: 'scene', layout: 'scene'},
@@ -89,6 +91,18 @@ export const SUBPLOT_TO_ATTR = {
8991
polar: {data: 'subplot', layout: 'polar'},
9092
};
9193

94+
export const subplotName = (type, _) =>
95+
({
96+
x: _('X'),
97+
y: _('Y'),
98+
ternary: _('Ternary'),
99+
gl3d: _('Scene'),
100+
scene: _('Scene'),
101+
geo: _('Geo'),
102+
mapbox: _('Mapbox'),
103+
polar: _('Polar'),
104+
}[type]);
105+
92106
export const TRANSFORMS_LIST = ['filter', 'groupby', 'aggregate'];
93107

94108
export const COLORS = {

src/lib/getAllAxes.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TRACE_TO_AXIS} from 'lib/constants';
1+
import {TRACE_TO_AXIS, SUBPLOT_TO_ATTR, subplotName} from 'lib/constants';
22
import {capitalize, striptags} from 'lib';
33

44
export default function getAllAxes(fullLayout) {
@@ -72,7 +72,7 @@ export function axisIdToAxisName(id) {
7272
return id.charAt(0) + 'axis' + id.slice(1);
7373
}
7474

75-
function getSubplotNumber(axis) {
75+
function getAxisNumber(axis) {
7676
const splitSubplot = axis._subplot
7777
? axis._subplot.split(axis._axisGroup)
7878
: [];
@@ -83,9 +83,21 @@ function getSubplotNumber(axis) {
8383

8484
export function getAxisTitle(axis) {
8585
const axisType = capitalize(axis._name.split('axis')[0]);
86-
const subplotNumber = getSubplotNumber(axis) || 1;
86+
const subplotNumber = getAxisNumber(axis) || 1;
8787

8888
return axis._input && axis._input.title
8989
? striptags(`${axisType}: ${axis._input.title}`)
9090
: striptags(`${axisType} ${subplotNumber}`);
9191
}
92+
93+
function getSubplotNumber(subplot, type) {
94+
return Number(subplot.split(type)[1]);
95+
}
96+
97+
export function getSubplotTitle(subplot, type, _) {
98+
const axisName = subplotName(type, _);
99+
const subplotNumber =
100+
getSubplotNumber(subplot, SUBPLOT_TO_ATTR[type].layout) || '';
101+
102+
return `${axisName} ${subplotNumber}`;
103+
}

src/lib/getAllSubplots.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/lib/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ import getAllAxes, {
2121
axisIdToAxisName,
2222
traceTypeToAxisType,
2323
getAxisTitle,
24-
} from './getAllAxes';
25-
import getAllSubplots, {
26-
traceTypeToSubplotType,
2724
getSubplotTitle,
28-
} from './getAllSubplots';
25+
} from './getAllAxes';
2926
import localize, {localizeString} from './localize';
3027
import tinyColor from 'tinycolor2';
3128
import unpackPlotProps from './unpackPlotProps';
@@ -66,9 +63,18 @@ function renderTraceIcon(trace, prefix = 'Plot') {
6663
return null;
6764
}
6865
const gl = 'gl';
66+
67+
let tempTrace = trace;
68+
if (tempTrace === 'cone') {
69+
tempTrace = 'scatter3d';
70+
} else if (tempTrace === 'streamtube') {
71+
tempTrace = 'line3d';
72+
}
73+
6974
const componentName = `${prefix}${pascalCase(
70-
trace.endsWith(gl) ? trace.slice(0, -gl.length) : trace
75+
tempTrace.endsWith(gl) ? tempTrace.slice(0, -gl.length) : tempTrace
7176
)}Icon`;
77+
7278
return PlotlyIcons[componentName]
7379
? PlotlyIcons[componentName]
7480
: PlotlyIcons.PlotLineIcon;
@@ -242,8 +248,6 @@ export {
242248
dereference,
243249
getAllAxes,
244250
getAxisTitle,
245-
getAllSubplots,
246-
traceTypeToSubplotType,
247251
getSubplotTitle,
248252
getDisplayName,
249253
isPlainObject,

0 commit comments

Comments
 (0)