Skip to content

Commit bdcd409

Browse files
authored
Merge pull request #561 from plotly/missing-fields
add fields in multiple traces, bugfixes, percy tests
2 parents db36b54 + 6b341f6 commit bdcd409

File tree

12 files changed

+267
-28
lines changed

12 files changed

+267
-28
lines changed

dev/mocks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"/percy/box.json",
66
"/percy/histogram.json",
77
"/percy/histogram2d.json",
8+
"/percy/pie.json",
89
"/percy/violin.json",
910
"0.json",
1011
"1.json",

dev/percy/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import panelTest from './panelTest.json';
22
import histogram from './histogram.json';
33
import histogram2d from './histogram2d.json';
4+
import pie from './pie.json';
45
import violin from './violin.json';
56
import bar from './bar.json';
67
import box from './box.json';
78

8-
export {panelTest, histogram, histogram2d, violin, bar, box};
9+
export {panelTest, histogram, histogram2d, pie, violin, bar, box};

dev/percy/panelTest.json

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@
3636
"color": [
3737
1,
3838
2,
39-
3,
40-
4,
41-
5,
42-
6
39+
3
4340
],
44-
"colorsrc": "ints",
41+
"colorsrc": "x1",
4542
"cmin": 1,
46-
"cmax": 6,
43+
"cmax": 3,
4744
"cauto": true,
4845
"colorscale": [
4946
[
@@ -67,8 +64,24 @@
6764
"showscale": true,
6865
"colorbar": {
6966
"ticks": "inside"
70-
}
71-
}
67+
},
68+
"size": [
69+
1,
70+
2,
71+
3
72+
],
73+
"sizesrc": "x1",
74+
"sizemode": "diameter"
75+
},
76+
"fill": "tozerox",
77+
"mode": "lines+markers+text",
78+
"line": {
79+
"dash": "solid",
80+
"shape": "spline",
81+
"color": "rgb(31, 119, 180)"
82+
},
83+
"hoveron": "fills+points",
84+
"uid": "3102ee"
7285
},
7386
{
7487
"x": [
@@ -106,22 +119,34 @@
106119
"transforms": [
107120
{
108121
"type": "groupby",
109-
"groupssrc": "ints",
122+
"groupssrc": "x1",
110123
"groups": [],
111124
"enabled": true
112125
},
113126
{
114127
"enabled": true,
115128
"type": "filter",
116129
"target": "x",
117-
"targetsrc": "ints",
130+
"targetsrc": "x1",
118131
"operation": "[]",
119132
"value": [
120133
"0",
121134
"1"
122135
]
123136
}
124-
]
137+
],
138+
"fill": "tozerox",
139+
"mode": "lines+markers+text",
140+
"marker": {
141+
"sizemode": "diameter"
142+
},
143+
"line": {
144+
"dash": "solid",
145+
"shape": "spline",
146+
"color": "rgb(31, 119, 180)"
147+
},
148+
"hoveron": "fills+points",
149+
"uid": "f4d7ad"
125150
}
126151
],
127152
"layout": {
@@ -135,7 +160,13 @@
135160
"color": "rgb(148, 103, 189)"
136161
},
137162
"overlaying": "y",
138-
"side": "right"
163+
"side": "right",
164+
"type": "linear",
165+
"range": [
166+
17.77777777777778,
167+
22.22222222222222
168+
],
169+
"autorange": true
139170
},
140171
"annotations": [
141172
{
@@ -148,8 +179,8 @@
148179
"xaxis": {
149180
"type": "date",
150181
"range": [
151-
0.6919103739269605,
152-
6.3080896260730395
182+
"1969-12-31 19:00:00.001",
183+
"1969-12-31 19:00:00.0011"
153184
],
154185
"autorange": true,
155186
"showline": true,
@@ -163,9 +194,12 @@
163194
},
164195
"autorange": true,
165196
"range": [
166-
0.6919103739269605,
167-
6.3080896260730395
168-
]
197+
"1969-12-31 19:00:00.001",
198+
"1969-12-31 19:00:00.0011"
199+
],
200+
"yaxis2": {
201+
"rangemode": "match"
202+
}
169203
},
170204
"rangeselector": {
171205
"visible": true,
@@ -184,10 +218,11 @@
184218
},
185219
"yaxis": {
186220
"range": [
187-
-0.32971827474445276,
188-
5.329718274744453
221+
1.9863013698630136,
222+
4.013698630136986
189223
],
190-
"autorange": true
224+
"autorange": true,
225+
"type": "linear"
191226
},
192227
"autosize": true,
193228
"shapes": [
@@ -285,5 +320,6 @@
285320
"active": 1
286321
}
287322
]
288-
}
323+
},
324+
"frames": []
289325
}

dev/percy/pie.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"data": [
3+
{
4+
"type": "pie",
5+
"mode": "markers",
6+
"uid": "3e343a",
7+
"labels": [
8+
1,
9+
2,
10+
3
11+
],
12+
"labelssrc": "x1",
13+
"values": [
14+
1,
15+
2,
16+
3
17+
],
18+
"valuessrc": "x1",
19+
"text": [
20+
1,
21+
2,
22+
3
23+
],
24+
"textsrc": "x1"
25+
}
26+
],
27+
"layout": {
28+
"xaxis": {
29+
"range": [
30+
0.5699530516431925,
31+
6.917370892018779
32+
],
33+
"autorange": true,
34+
"type": "linear"
35+
},
36+
"yaxis": {
37+
"range": [
38+
-0.3055555555555556,
39+
5.805555555555555
40+
],
41+
"autorange": true
42+
},
43+
"autosize": true,
44+
"hovermode": "closest"
45+
},
46+
"frames": []
47+
}

src/__percy__/panels.percy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import './percy.css';
1616
const panelsToTest = {
1717
bar: ['GraphCreatePanel', 'StyleTracesPanel'],
1818
box: ['GraphCreatePanel', 'StyleTracesPanel'],
19+
pie: ['GraphCreatePanel', 'StyleTracesPanel'],
1920
histogram: ['GraphCreatePanel', 'StyleTracesPanel'],
2021
histogram2d: ['GraphCreatePanel', 'StyleTracesPanel'],
2122
violin: ['GraphCreatePanel', 'StyleTracesPanel'],
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import Field from './Field';
2+
import PropTypes from 'prop-types';
3+
import React, {Component} from 'react';
4+
import {connectToContainer} from 'lib';
5+
import RadioBlocks from '../widgets/RadioBlocks';
6+
import Numeric from './Numeric';
7+
import DataSelector from './DataSelector';
8+
9+
const getType = value => (Array.isArray(value) ? 'variable' : 'constant');
10+
11+
class UnconnectedMarkerSize extends Component {
12+
constructor(props, context) {
13+
super(props, context);
14+
15+
const type = getType(props.fullValue);
16+
this.state = {
17+
type,
18+
value: {
19+
constant: type === 'constant' ? props.fullValue : '6',
20+
variable: type === 'variable' ? props.fullValue : null,
21+
},
22+
};
23+
24+
this.setType = this.setType.bind(this);
25+
this.setValue = this.setValue.bind(this);
26+
}
27+
28+
setType(type) {
29+
this.setState({type: type});
30+
this.props.updatePlot(this.state.value[type]);
31+
if (type === 'constant') {
32+
this.context.updateContainer({['marker.sizesrc']: null});
33+
}
34+
}
35+
36+
setValue(inputValue) {
37+
const {type} = this.state;
38+
39+
this.setState(
40+
type === 'constant'
41+
? {value: {constant: inputValue}}
42+
: {value: {variable: inputValue}}
43+
);
44+
this.props.updatePlot(inputValue);
45+
}
46+
47+
render() {
48+
const {attr} = this.props;
49+
const {localize: _} = this.context;
50+
const options = [
51+
{label: _('Constant'), value: 'constant'},
52+
{label: _('Variable'), value: 'variable'},
53+
];
54+
55+
return (
56+
<div>
57+
<Field {...this.props} attr={attr}>
58+
<RadioBlocks
59+
options={options}
60+
activeOption={this.state.type}
61+
onOptionChange={this.setType}
62+
/>
63+
{this.state.type === 'constant' ? (
64+
<Numeric
65+
attr="marker.size"
66+
updatePlot={this.setValue}
67+
fullValue={this.state.value.constant}
68+
/>
69+
) : (
70+
<DataSelector
71+
attr="marker.size"
72+
updatePlot={this.setValue}
73+
fullValue={this.state.value.variable}
74+
/>
75+
)}
76+
</Field>
77+
</div>
78+
);
79+
}
80+
}
81+
82+
UnconnectedMarkerSize.propTypes = {
83+
fullValue: PropTypes.any,
84+
updatePlot: PropTypes.func,
85+
...Field.propTypes,
86+
};
87+
88+
UnconnectedMarkerSize.contextTypes = {
89+
localize: PropTypes.func,
90+
updateContainer: PropTypes.func,
91+
};
92+
93+
export default connectToContainer(UnconnectedMarkerSize);

src/components/fields/derived.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ export const NumericFractionInverse = connectToContainer(
308308
}
309309
);
310310

311+
export const NumericReciprocal = connectToContainer(UnconnectedNumeric, {
312+
modifyPlotProps: (props, context, plotProps) => {
313+
const {fullValue, updatePlot} = plotProps;
314+
315+
if (isNumeric(fullValue)) {
316+
plotProps.fullValue = Math.round(1 / fullValue);
317+
}
318+
319+
plotProps.updatePlot = v => {
320+
if (isNumeric(v)) {
321+
updatePlot(1 / v);
322+
} else {
323+
updatePlot(v);
324+
}
325+
};
326+
327+
plotProps.min = 1;
328+
},
329+
});
330+
311331
export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
312332
modifyPlotProps: (props, context, plotProps) => {
313333
if (!context.fullContainer) {
@@ -490,6 +510,10 @@ export const HoverInfo = connectToContainer(UnconnectedFlaglist, {
490510
{label: _('Name'), value: 'name'},
491511
];
492512

513+
if (context.container.text && context.container.text.length > 0) {
514+
options.push({label: _('Text'), value: 'text'});
515+
}
516+
493517
if (
494518
[
495519
'heatmap',

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ErrorBars from './ErrorBars';
1919
import AxisCreator from './AxisCreator';
2020
import UpdateMenuButtons from './UpdateMenuButtons';
2121
import {FilterOperation, FilterValue} from './FilterOperation';
22+
import MarkerSize from './MarkerSize';
2223
import {
2324
AnnotationArrowRef,
2425
AnnotationRef,
@@ -88,4 +89,5 @@ export {
8889
UpdateMenuButtons,
8990
Dropzone,
9091
TextPosition,
92+
MarkerSize,
9193
};

src/components/fields/lineSelectors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ const strokeShapes = [
3535
];
3636

3737
const strokeStyle = {fill: 'none', strokeWidth: '4px'};
38-
const computeOptions = (strokeData, stroke) =>
38+
39+
const mutedBlue = '#1f77b4';
40+
41+
const computeOptions = (strokeData, stroke = mutedBlue) =>
3942
strokeData.map(({value, strokeDasharray, d = 'M0,8h100'}) => ({
4043
label: <path d={d} style={{...strokeStyle, stroke, strokeDasharray}} />,
4144
value,

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
UpdateMenuButtons,
4444
Dropzone,
4545
TextPosition,
46+
MarkerSize,
4647
} from './fields';
4748

4849
import {
@@ -141,4 +142,5 @@ export {
141142
UpdateMenuButtons,
142143
Dropzone,
143144
TextPosition,
145+
MarkerSize,
144146
};

0 commit comments

Comments
 (0)