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
30 changes: 24 additions & 6 deletions src/components/containers/SubplotAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
connectTraceToPlot,
connectCartesianSubplotToLayout,
connectNonCartesianSubplotToLayout,
getSubplotTitle,
} from 'lib';
import {TRACE_TO_AXIS, SUBPLOT_TO_ATTR} from 'lib/constants';

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

class SubplotAccordion extends Component {
render() {
const {data = [], layout = {}} = this.context;
const {data = [], layout = {}, localize: _} = this.context;
const {children, messageIfEmptyFold} = this.props;
const subplotFolds = [];

Expand All @@ -31,8 +32,12 @@ class SubplotAccordion extends Component {
acc.push({
xaxis: xaxis,
yaxis: yaxis,
xaxisName: curVal.xaxis || 'x1',
yaxisName: curVal.yaxis || 'y1',
xaxisName: curVal.xaxis
? getSubplotTitle(curVal.xaxis, 'x', _)
: 'X 1',
yaxisName: curVal.yaxis
? getSubplotTitle(curVal.yaxis, 'y', _)
: 'Y 1',
index: [inx],
});
} else {
Expand All @@ -52,7 +57,7 @@ class SubplotAccordion extends Component {
messageIfEmpty={messageIfEmptyFold}
xaxis={d.xaxis}
yaxis={d.yaxis}
name={`${d.xaxisName} ${d.yaxisName}`}
name={`${d.xaxisName} | ${d.yaxisName}`}
>
{children}
</CartesianSubplotFold>
Expand Down Expand Up @@ -87,8 +92,10 @@ class SubplotAccordion extends Component {

Object.keys(layout).forEach(layoutKey => {
const traceIndexes = [];
let subplotName;
if (
['geo', 'mapbox', 'polar', 'gl3d', 'ternary'].some(subplotType => {
subplotName = getSubplotTitle(layoutKey, subplotType, _);
const trIndex =
SUBPLOT_TO_ATTR[subplotType].layout === layoutKey
? data.findIndex(trace =>
Expand All @@ -111,23 +118,34 @@ class SubplotAccordion extends Component {
canDelete={false}
messageIfEmpty={messageIfEmptyFold}
subplot={layoutKey}
name={layoutKey}
name={subplotName}
>
{children}
</NonCartesianSubplotFold>
);
}
});

let pieCounter = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

hehe OK, we'll refactor that next time, when we add a third :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's what I was thinking when I was writing it lol

let tableCounter = 0;
data.forEach((d, i) => {
if ((d.type === 'pie' && d.values) || d.type === 'table') {
if (d.type === 'pie') {
pieCounter++;
} else if (d.type === 'table') {
tableCounter++;
}
subplotFolds[i] = (
<TraceFold
key={i}
traceIndexes={[i]}
canDelete={false}
messageIfEmpty={messageIfEmptyFold}
name={`${d.type} ${i}`}
name={
d.type === 'pie'
? `${_('Pie')} ${pieCounter > 1 ? pieCounter : ''}`
: `${_('Table')} ${tableCounter > 1 ? tableCounter : ''}`
}
>
{children}
</TraceFold>
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/SubplotCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class UnconnectedSubplotCreator extends Component {

function getOptions(subplotType) {
return fullLayout._subplots[subplotType].map(subplotId => ({
label: getSubplotTitle(subplotId, subplotType),
label: getSubplotTitle(subplotId, subplotType, _),
value: subplotId,
}));
}
Expand Down
18 changes: 16 additions & 2 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export const TRACE_TO_AXIS = {
// Note: scene, and xaxis/yaxis were added for convenience sake even though they're not subplot types
export const SUBPLOT_TO_ATTR = {
cartesian: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
xaxis: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
yaxis: {data: ['xaxis', 'yaxis'], layout: ['x', 'y']},
xaxis: {data: 'xaxis', layout: 'x'},
yaxis: {data: 'yaxis', layout: 'y'},
x: {data: 'xaxis', layout: 'x'},
y: {data: 'yaxis', layout: 'y'},
ternary: {data: 'subplot', layout: 'ternary'},
gl3d: {data: 'scene', layout: 'scene'},
scene: {data: 'scene', layout: 'scene'},
Expand All @@ -89,6 +91,18 @@ export const SUBPLOT_TO_ATTR = {
polar: {data: 'subplot', layout: 'polar'},
};

export const subplotName = (type, _) =>
({
x: _('X'),
y: _('Y'),
ternary: _('Ternary'),
gl3d: _('Scene'),
scene: _('Scene'),
geo: _('Geo'),
mapbox: _('Mapbox'),
polar: _('Polar'),
}[type]);

export const TRANSFORMS_LIST = ['filter', 'groupby', 'aggregate'];

export const COLORS = {
Expand Down
18 changes: 15 additions & 3 deletions src/lib/getAllAxes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TRACE_TO_AXIS} from 'lib/constants';
import {TRACE_TO_AXIS, SUBPLOT_TO_ATTR, subplotName} from 'lib/constants';
import {capitalize, striptags} from 'lib';

export default function getAllAxes(fullLayout) {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function axisIdToAxisName(id) {
return id.charAt(0) + 'axis' + id.slice(1);
}

function getSubplotNumber(axis) {
function getAxisNumber(axis) {
const splitSubplot = axis._subplot
? axis._subplot.split(axis._axisGroup)
: [];
Expand All @@ -83,9 +83,21 @@ function getSubplotNumber(axis) {

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

return axis._input && axis._input.title
? striptags(`${axisType}: ${axis._input.title}`)
: striptags(`${axisType} ${subplotNumber}`);
}

function getSubplotNumber(subplot, type) {
return Number(subplot.split(type)[1]);
}

export function getSubplotTitle(subplot, type, _) {
const axisName = subplotName(type, _);
const subplotNumber =
getSubplotNumber(subplot, SUBPLOT_TO_ATTR[type].layout) || '';

return `${axisName} ${subplotNumber}`;
}
81 changes: 0 additions & 81 deletions src/lib/getAllSubplots.js

This file was deleted.

18 changes: 11 additions & 7 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import getAllAxes, {
axisIdToAxisName,
traceTypeToAxisType,
getAxisTitle,
} from './getAllAxes';
import getAllSubplots, {
traceTypeToSubplotType,
getSubplotTitle,
} from './getAllSubplots';
} from './getAllAxes';
import localize, {localizeString} from './localize';
import tinyColor from 'tinycolor2';
import unpackPlotProps from './unpackPlotProps';
Expand Down Expand Up @@ -66,9 +63,18 @@ function renderTraceIcon(trace, prefix = 'Plot') {
return null;
}
const gl = 'gl';

let tempTrace = trace;
if (tempTrace === 'cone') {
tempTrace = 'scatter3d';
} else if (tempTrace === 'streamtube') {
tempTrace = 'line3d';
}

const componentName = `${prefix}${pascalCase(
trace.endsWith(gl) ? trace.slice(0, -gl.length) : trace
tempTrace.endsWith(gl) ? tempTrace.slice(0, -gl.length) : tempTrace
)}Icon`;

return PlotlyIcons[componentName]
? PlotlyIcons[componentName]
: PlotlyIcons.PlotLineIcon;
Expand Down Expand Up @@ -242,8 +248,6 @@ export {
dereference,
getAllAxes,
getAxisTitle,
getAllSubplots,
traceTypeToSubplotType,
getSubplotTitle,
getDisplayName,
isPlainObject,
Expand Down