|
8 | 8 | traceTypeToAxisType, |
9 | 9 | } from '../lib'; |
10 | 10 | import {deepCopyPublic, setMultiValuedContainer} from './multiValues'; |
11 | | -import {EDITOR_ACTIONS, AXIS_TO_ATTR} from 'lib/constants'; |
| 11 | +import {EDITOR_ACTIONS, SUBPLOT_TO_ATTR} from 'lib/constants'; |
12 | 12 |
|
13 | 13 | export default function connectTraceToPlot(WrappedComponent) { |
14 | 14 | class TraceConnectedComponent extends Component { |
@@ -143,37 +143,40 @@ export default function connectTraceToPlot(WrappedComponent) { |
143 | 143 | }); |
144 | 144 | return; |
145 | 145 | } |
146 | | - const subplotType = traceTypeToAxisType(currentTrace.type); |
147 | | - const subplotNames = |
148 | | - subplotType === 'cartesian' |
149 | | - ? [currentTrace.xaxis || 'xaxis', currentTrace.yaxis || 'yaxis'] |
150 | | - : currentTrace[AXIS_TO_ATTR[subplotType]] || |
151 | | - AXIS_TO_ATTR[subplotType]; |
152 | 146 | const axesToBeGarbageCollected = []; |
153 | 147 | let subplotToBeGarbageCollected = null; |
| 148 | + const subplotType = traceTypeToAxisType(currentTrace.type); |
154 | 149 |
|
155 | | - const isSubplotUsedAnywhereElse = (subplotType, subplotName) => |
156 | | - this.context.fullData.some( |
157 | | - trace => |
158 | | - (trace[AXIS_TO_ATTR[subplotType]] === subplotName || |
159 | | - (((subplotType === 'xaxis' || subplotType === 'yaxis') && |
160 | | - subplotName.charAt(1)) === '' || |
161 | | - (subplotName.split(subplotType)[1] === '' && |
162 | | - trace[AXIS_TO_ATTR[subplotType]] === null))) && |
163 | | - trace.index !== this.props.traceIndexes[0] |
164 | | - ); |
165 | | - |
166 | | - // When we delete a subplot, make sure no unused axes/subplots are left |
167 | | - if (subplotType === 'cartesian') { |
168 | | - if (!isSubplotUsedAnywhereElse('xaxis', subplotNames[0])) { |
169 | | - axesToBeGarbageCollected.push(subplotNames[0]); |
170 | | - } |
171 | | - if (!isSubplotUsedAnywhereElse('yaxis', subplotNames[1])) { |
172 | | - axesToBeGarbageCollected.push(subplotNames[1]); |
173 | | - } |
174 | | - } else { |
175 | | - if (!isSubplotUsedAnywhereElse(subplotType, subplotNames)) { |
176 | | - subplotToBeGarbageCollected = subplotNames; |
| 150 | + if (subplotType) { |
| 151 | + const subplotNames = |
| 152 | + subplotType === 'cartesian' |
| 153 | + ? [currentTrace.xaxis || 'xaxis', currentTrace.yaxis || 'yaxis'] |
| 154 | + : currentTrace[SUBPLOT_TO_ATTR[subplotType].data] || |
| 155 | + SUBPLOT_TO_ATTR[subplotType].data; |
| 156 | + |
| 157 | + const isSubplotUsedAnywhereElse = (subplotType, subplotName) => |
| 158 | + this.context.fullData.some( |
| 159 | + trace => |
| 160 | + (trace[SUBPLOT_TO_ATTR[subplotType].data] === subplotName || |
| 161 | + (((subplotType === 'xaxis' || subplotType === 'yaxis') && |
| 162 | + subplotName.charAt(1)) === '' || |
| 163 | + (subplotName.split(subplotType)[1] === '' && |
| 164 | + trace[SUBPLOT_TO_ATTR[subplotType].data] === null))) && |
| 165 | + trace.index !== this.props.traceIndexes[0] |
| 166 | + ); |
| 167 | + |
| 168 | + // When we delete a subplot, make sure no unused axes/subplots are left |
| 169 | + if (subplotType === 'cartesian') { |
| 170 | + if (!isSubplotUsedAnywhereElse('xaxis', subplotNames[0])) { |
| 171 | + axesToBeGarbageCollected.push(subplotNames[0]); |
| 172 | + } |
| 173 | + if (!isSubplotUsedAnywhereElse('yaxis', subplotNames[1])) { |
| 174 | + axesToBeGarbageCollected.push(subplotNames[1]); |
| 175 | + } |
| 176 | + } else { |
| 177 | + if (!isSubplotUsedAnywhereElse(subplotType, subplotNames)) { |
| 178 | + subplotToBeGarbageCollected = subplotNames; |
| 179 | + } |
177 | 180 | } |
178 | 181 | } |
179 | 182 |
|
|
0 commit comments