Skip to content

Commit 33e2f7a

Browse files
authored
Merge pull request #493 from plotly/fit-transform-adjustments
Fit transform adjustments
2 parents 2da1309 + d860655 commit 33e2f7a

File tree

8 files changed

+586
-429
lines changed

8 files changed

+586
-429
lines changed

scripts/translationKeys/combined-translation-keys.txt

Lines changed: 255 additions & 209 deletions
Large diffs are not rendered by default.

scripts/translationKeys/translation-keys.txt

Lines changed: 255 additions & 209 deletions
Large diffs are not rendered by default.

src/components/containers/PlotlyFold.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export class Fold extends Component {
1111
this.foldVisible = true;
1212
}
1313

14+
getChildContext() {
15+
return {
16+
foldInfo: this.props.foldInfo ? this.props.foldInfo : null,
17+
};
18+
}
19+
1420
render() {
1521
if (!this.foldVisible && !this.props.messageIfEmpty) {
1622
return null;
@@ -21,6 +27,7 @@ export class Fold extends Component {
2127
children,
2228
className,
2329
folded,
30+
foldInfo,
2431
toggleFold,
2532
hideHeader,
2633
icon: Icon,
@@ -56,7 +63,7 @@ export class Fold extends Component {
5663
className="fold__top__delete js-fold__delete"
5764
onClick={e => {
5865
e.stopPropagation();
59-
deleteContainer(e);
66+
deleteContainer(foldInfo);
6067
}}
6168
>
6269
<CloseIcon />
@@ -105,13 +112,22 @@ Fold.propTypes = {
105112
children: PropTypes.node,
106113
className: PropTypes.string,
107114
folded: PropTypes.bool,
115+
foldInfo: PropTypes.object,
108116
toggleFold: PropTypes.func,
109117
hideHeader: PropTypes.bool,
110118
icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
111119
messageIfEmpty: PropTypes.string,
112120
name: PropTypes.string,
113121
};
114122

123+
Fold.contextTypes = {
124+
deleteContainer: PropTypes.func,
125+
};
126+
127+
Fold.childContextTypes = {
128+
foldInfo: PropTypes.object,
129+
};
130+
115131
class PlotlyFold extends Fold {
116132
constructor(props, context) {
117133
super(props, context);

src/components/containers/PlotlyPanel.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export class Panel extends Component {
3737
this.toggleFold = this.toggleFold.bind(this);
3838
}
3939

40+
getChildContext() {
41+
return {
42+
deleteContainer: this.props.deleteAction ? this.props.deleteAction : null,
43+
};
44+
}
45+
4046
componentDidCatch() {
4147
this.setState({hasError: true});
4248
}
@@ -124,10 +130,11 @@ export class Panel extends Component {
124130
}
125131

126132
Panel.propTypes = {
127-
children: PropTypes.node,
128133
addAction: PropTypes.object,
129-
showExpandCollapse: PropTypes.bool,
134+
children: PropTypes.node,
135+
deleteAction: PropTypes.func,
130136
noPadding: PropTypes.bool,
137+
showExpandCollapse: PropTypes.bool,
131138
};
132139

133140
Panel.defaultProps = {
@@ -138,6 +145,10 @@ Panel.contextTypes = {
138145
localize: PropTypes.func,
139146
};
140147

148+
Panel.childContextTypes = {
149+
deleteContainer: PropTypes.func,
150+
};
151+
141152
class PlotlyPanel extends Panel {}
142153

143154
PlotlyPanel.plotly_editor_traits = {

src/components/containers/TraceAccordion.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,25 @@ const TraceFold = connectTraceToPlot(PlotlyFold);
1212
class TraceAccordion extends Component {
1313
render() {
1414
const {data = [], localize: _} = this.context;
15-
const {canAdd, canGroup, children, messageIfEmptyFold} = this.props;
15+
const {
16+
canAdd,
17+
canGroup,
18+
children,
19+
messageIfEmptyFold,
20+
excludeFits,
21+
} = this.props;
22+
23+
// we don't want to include analysis transforms when we're in the create panel
24+
const filteredData = data.filter(t => {
25+
if (excludeFits) {
26+
return !(t.transforms && t.transforms.every(tr => tr.type === 'fit'));
27+
}
28+
return true;
29+
});
1630

1731
const individualTraces =
18-
data.length &&
19-
data.map((d, i) => {
32+
filteredData.length &&
33+
filteredData.map((d, i) => {
2034
return (
2135
<TraceFold
2236
key={i}
@@ -46,7 +60,7 @@ class TraceAccordion extends Component {
4660
</PlotlyPanel>
4761
);
4862
}
49-
const tracesByGroup = data.reduce((allTraces, nextTrace, index) => {
63+
const tracesByGroup = filteredData.reduce((allTraces, nextTrace, index) => {
5064
const traceType = plotlyTraceToCustomTrace(nextTrace);
5165
if (!allTraces[traceType]) {
5266
allTraces[traceType] = [];
@@ -67,7 +81,7 @@ class TraceAccordion extends Component {
6781
);
6882
});
6983

70-
if (canGroup && data.length > 1 && groupedTraces.length > 0) {
84+
if (canGroup && filteredData.length > 1 && groupedTraces.length > 0) {
7185
return (
7286
<TraceRequiredPanel noPadding>
7387
<Tabs>
@@ -102,9 +116,10 @@ TraceAccordion.contextTypes = {
102116
};
103117

104118
TraceAccordion.propTypes = {
105-
children: PropTypes.node,
106119
canAdd: PropTypes.bool,
107120
canGroup: PropTypes.bool,
121+
children: PropTypes.node,
122+
excludeFits: PropTypes.bool,
108123
messageIfEmptyFold: PropTypes.string,
109124
};
110125

src/default_panels/GraphCreatePanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121

2222
const GraphCreatePanel = (props, {localize: _}) => {
2323
return (
24-
<TraceAccordion canAdd>
24+
<TraceAccordion canAdd excludeFits>
2525
<TextEditor label={_('Name')} attr="name" richTextOnly />
2626
<TraceSelector label={_('Type')} attr="type" show />
2727

src/lib/connectTraceToPlot.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,30 @@ export default function connectTraceToPlot(WrappedComponent) {
3232
let fullTrace = {};
3333
for (let i = 0; i < fullData.length; i++) {
3434
if (trace.uid === fullData[i]._fullInput._input.uid) {
35+
/*
36+
* Fit transforms are custom transforms in our custom plotly.js bundle,
37+
* they are different from others as they create an extra trace in the
38+
* data array. When plotly.js runs supplyTraceDefaults (before the
39+
* transforms code executes) it stores the result in _fullInput,
40+
* so that we have a reference to what the original, corrected input was.
41+
* Then the transform code runs, our figure changes accordingly, but
42+
* we're still able to use the original input as it's in _fullInput.
43+
* This is the desired behaviour for our transforms usually,
44+
* but it is not useful for fits, as the transform code adds some styles
45+
* that are useful for the trace, so really for fits we'd like to read
46+
* from _fullData, not _fullInput. Here we're setting _fullInput to
47+
* _fullData as that is where the rest of our code expects to find its
48+
* values.
49+
*/
50+
if (
51+
trace.transforms &&
52+
trace.transforms.every(t => t.type === 'fit')
53+
) {
54+
fullData[i]._fullInput = fullData[i];
55+
}
56+
3557
fullTrace = fullData[i]._fullInput;
58+
3659
break;
3760
}
3861
}

src/styles/components/widgets/_numeric-input.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
.numeric-input__wrapper {
1919
line-height: 20px;
2020
max-width: 100%;
21-
width: 100%;
21+
flex: 1;
2222
display: flex;
2323
align-items: center;
2424
color: var(--color-text-base);

0 commit comments

Comments
 (0)