Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 362b053

Browse files
Merge pull request #460 from plotly/fix_issue_444
fix issue #444
2 parents bb2ca67 + b31f0fe commit 362b053

File tree

5 files changed

+181
-234
lines changed

5 files changed

+181
-234
lines changed

plotly/plotlyfig_aux/handlegraphics/updateAlternativeBoxplot.m

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,4 @@ function updateBoxplotLine(obj, axIndex, plotData, traceIndex)
9191
end
9292

9393
%-------------------------------------------------------------------------%
94-
end
95-
96-
function scatterMode = getScatterMode(plotData)
97-
98-
marker = plotData.Marker;
99-
lineStyle = plotData.LineStyle;
100-
101-
if ~strcmpi('none', marker) && ~strcmpi('none', lineStyle)
102-
scatterMode = 'lines+markers';
103-
104-
elseif ~strcmpi('none', marker)
105-
scatterMode = 'markers';
106-
107-
elseif ~strcmpi('none', lineStyle)
108-
scatterMode = 'lines';
109-
110-
else
111-
scatterMode = 'none';
112-
113-
end
11494
end

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

Lines changed: 55 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,213 +1,99 @@
11
function updateLineseries(obj, plotIndex)
22

3-
%----SCATTER FIELDS----%
4-
5-
% x - [DONE]
6-
% y - [DONE]
7-
% r - [HANDLED BY SCATTER]
8-
% t - [HANDLED BY SCATTER]
9-
% mode - [DONE]
10-
% name - [NOT SUPPORTED IN MATLAB]
11-
% text - [DONE]
12-
% error_y - [HANDLED BY ERRORBAR]
13-
% error_x - [NOT SUPPORTED IN MATLAB]
14-
% connectgaps - [NOT SUPPORTED IN MATLAB]
15-
% fill - [HANDLED BY AREA]
16-
% fillcolor - [HANDLED BY AREA]
17-
% opacity --- [TODO]
18-
% textfont - [NOT SUPPORTED IN MATLAB]
19-
% textposition - [NOT SUPPORTED IN MATLAB]
20-
% xaxis [DONE]
21-
% yaxis [DONE]
22-
% showlegend [DONE]
23-
% stream - [HANDLED BY PLOTLYSTREAM]
24-
% visible [DONE]
25-
% type [DONE]
26-
27-
% MARKER
28-
% marler.color - [DONE]
29-
% marker.size - [DONE]
30-
% marker.line.color - [DONE]
31-
% marker.line.width - [DONE]
32-
% marker.line.dash - [NOT SUPPORTED IN MATLAB]
33-
% marker.line.opacity - [NOT SUPPORTED IN MATLAB]
34-
% marker.line.smoothing - [NOT SUPPORTED IN MATLAB]
35-
% marker.line.shape - [NOT SUPPORTED IN MATLAB]
36-
% marker.opacity --- [TODO]
37-
% marker.colorscale - [NOT SUPPORTED IN MATLAB]
38-
% marker.sizemode - [NOT SUPPORTED IN MATLAB]
39-
% marker.sizeref - [NOT SUPPORTED IN MATLAB]
40-
% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB]
41-
42-
% LINE
43-
44-
% line.color - [DONE]
45-
% line.width - [DONE]
46-
% line.dash - [DONE]
47-
% line.opacity --- [TODO]
48-
% line.smoothing - [NOT SUPPORTED IN MATLAB]
49-
% line.shape - [NOT SUPPORTED IN MATLAB]
50-
513
%-------------------------------------------------------------------------%
524

53-
%-AXIS INDEX-%
54-
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
5+
%-INITIALIZATIONS-%
556

56-
%-PLOT DATA STRUCTURE- %
7+
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
578
plotData = get(obj.State.Plot(plotIndex).Handle);
589

59-
%-CHECK FOR MULTIPLE AXES-%
10+
%-check for multiple axes-%
6011
try
6112
for yax = 1:2
62-
yaxIndex(yax) = sum(plotData.Parent.YAxis(yax).Color == plotData.Color);
13+
yAxisColor = plotData.Parent.YAxis(yax).Color;
14+
yaxIndex(yax) = sum(yAxisColor == plotData.Color);
6315
end
6416

6517
[~, yaxIndex] = max(yaxIndex);
66-
[xsource, ysource] = findSourceAxis(obj, axIndex, yaxIndex);
18+
[xSource, ySource] = findSourceAxis(obj, axIndex, yaxIndex);
6719

6820
catch
69-
[xsource, ysource] = findSourceAxis(obj,axIndex);
21+
[xSource, ySource] = findSourceAxis(obj,axIndex);
7022
end
7123

72-
%-AXIS DATA-%
73-
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
74-
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
24+
%-check if polar plot-%
25+
treatAs = lower(obj.PlotOptions.TreatAs);
26+
isPolar = ismember('compass', treatAs) || ismember('ezpolar', treatAs);
7527

76-
%-------------------------------------------------------------------------%
77-
78-
%-if polar plot or not-%
79-
treatAs = obj.PlotOptions.TreatAs;
80-
isPolar = ismember('compass', lower(treatAs)) || ismember('ezpolar', lower(treatAs));
81-
82-
%-------------------------------------------------------------------------%
83-
84-
%-getting data-%
85-
xData = plotData.XData;
86-
yData = plotData.YData;
87-
88-
if isduration(xData) || isdatetime(xData), xData = datenum(xData); end
89-
if isduration(yData) || isdatetime(yData), yData = datenum(yData); end
90-
91-
%-------------------------------------------------------------------------%
28+
%-check is 3D plot-%
29+
try
30+
isPlot3D = isfield(plotData,'ZData');
31+
isPlot3D = isPlot3D & ~isempty(plotData.ZData);
32+
catch
33+
isPlot3D = false;
34+
end
9235

93-
%-scatter xaxis-%
94-
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
36+
%-get trace data-%
37+
xData = date2NumData(plotData.XData);
38+
yData = date2NumData(plotData.YData);
9539

96-
%-------------------------------------------------------------------------%
40+
if isPolar
41+
rData = sqrt(xData.^2 + yData.^2);
42+
thetaData = atan2(xData, yData);
43+
thetaData = -(rad2deg(thetaData) - 90);
44+
end
9745

98-
%-scatter yaxis-%
99-
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];
46+
if isPlot3D
47+
zData = date2NumData(plotData.ZData);
48+
end
10049

10150
%-------------------------------------------------------------------------%
10251

103-
%-scatter type-%
104-
obj.data{plotIndex}.type = 'scatter';
105-
52+
%-set trace-%
10653
if isPolar
10754
obj.data{plotIndex}.type = 'scatterpolar';
108-
end
10955

110-
%-------------------------------------------------------------------------%
56+
elseif ~isPlot3D
57+
obj.data{plotIndex}.type = 'scatter';
58+
obj.data{plotIndex}.xaxis = sprintf('x%d', xSource);
59+
obj.data{plotIndex}.yaxis = sprintf('y%d', ySource);
60+
else
61+
obj.data{plotIndex}.type = 'scatter3d';
62+
obj.data{plotIndex}.scene = sprintf('scene%d', xSource);
63+
64+
updateScene(obj, plotIndex);
65+
end
11166

112-
%-scatter visible-%
11367
obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on');
68+
obj.data{plotIndex}.name = plotData.DisplayName;
69+
obj.data{plotIndex}.mode = getScatterMode(plotData);
11470

11571
%-------------------------------------------------------------------------%
11672

117-
%-scatter x-%
118-
73+
%-set trace data-%
11974
if isPolar
120-
rData = sqrt(x.^2 + y.^2);
12175
obj.data{plotIndex}.r = rData;
76+
obj.data{plotIndex}.theta = thetaData;
12277
else
12378
obj.data{plotIndex}.x = xData;
124-
end
125-
126-
%-------------------------------------------------------------------------%
127-
128-
%-scatter y-%
129-
if isPolar
130-
thetaData = atan2(xData,yData);
131-
obj.data{plotIndex}.theta = -(rad2deg(thetaData) - 90);
132-
else
13379
obj.data{plotIndex}.y = yData;
134-
end
135-
136-
%-------------------------------------------------------------------------%
137-
138-
%-Fro 3D plots-%
139-
obj.PlotOptions.is3d = false; % by default
14080

141-
if isfield(plotData,'ZData')
142-
zData = plotData.ZData;
143-
if isduration(zData) || isdatetime(zData), zData = datenum(zData); end
144-
145-
numbset = unique(zData);
146-
147-
if any(zData) && length(numbset)>1
148-
%-scatter z-%
81+
if isPlot3D
14982
obj.data{plotIndex}.z = zData;
150-
151-
%-overwrite type-%
152-
obj.data{plotIndex}.type = 'scatter3d';
153-
obj.data{plotIndex}.scene = sprintf('scene%d', xsource);
154-
155-
updateScene(obj, plotIndex);
156-
157-
%-flag to manage 3d plots-%
15883
obj.PlotOptions.is3d = true;
15984
end
16085
end
16186

16287
%-------------------------------------------------------------------------%
16388

164-
%-scatter name-%
165-
obj.data{plotIndex}.name = plotData.DisplayName;
166-
167-
%-------------------------------------------------------------------------%
168-
169-
%-scatter mode-%
170-
if ~strcmpi('none', plotData.Marker) ...
171-
&& ~strcmpi('none', plotData.LineStyle)
172-
mode = 'lines+markers';
173-
elseif ~strcmpi('none', plotData.Marker)
174-
mode = 'markers';
175-
elseif ~strcmpi('none', plotData.LineStyle)
176-
mode = 'lines';
177-
else
178-
mode = 'none';
179-
end
180-
181-
obj.data{plotIndex}.mode = mode;
182-
183-
%-------------------------------------------------------------------------%
184-
185-
%-scatter line-%
89+
%-set trace line-%
18690
obj.data{plotIndex}.line = extractLineLine(plotData);
18791

188-
%-------------------------------------------------------------------------%
189-
190-
%-scatter marker-%
92+
%-set trace marker-%
19193
obj.data{plotIndex}.marker = extractLineMarker(plotData);
19294

193-
%-------------------------------------------------------------------------%
194-
195-
%-scatter showlegend-%
196-
leg = get(plotData.Annotation);
197-
legInfo = get(leg.LegendInformation);
198-
199-
switch legInfo.IconDisplayStyle
200-
case 'on'
201-
showLeg = true;
202-
case 'off'
203-
showLeg = false;
204-
end
205-
206-
obj.data{plotIndex}.showlegend = showLeg;
207-
208-
if isempty(obj.data{plotIndex}.name)
209-
obj.data{plotIndex}.showlegend = false;
210-
end
95+
%-set trace legend-%
96+
obj.data{plotIndex}.showlegend = getShowLegend(plotData);
21197

21298
%-------------------------------------------------------------------------%
21399
end
@@ -230,7 +116,10 @@ function updateScene(obj, dataIndex)
230116
dataAspectRatio = axisData.DataAspectRatio;
231117
cameraUpVector = axisData.CameraUpVector;
232118
cameraEye = cameraPosition./dataAspectRatio;
233-
normFac = 0.7 * abs(min(cameraEye));
119+
120+
cameraOffset = 0.5;
121+
normFac = abs(min(cameraEye));
122+
normFac = normFac / (max(aspectRatio)/min(aspectRatio) + cameraOffset);
234123

235124
%-------------------------------------------------------------------------%
236125

@@ -240,9 +129,9 @@ function updateScene(obj, dataIndex)
240129
scene.aspectratio.z = 1.0*aspectRatio(3);
241130

242131
%-camera eye-%
243-
scene.camera.eye.x = cameraEye(1) / normFac;
244-
scene.camera.eye.y = cameraEye(2) / normFac;
245-
scene.camera.eye.z = cameraEye(3) / normFac;
132+
scene.camera.eye.x = cameraEye(1)/normFac;
133+
scene.camera.eye.y = cameraEye(2)/normFac;
134+
scene.camera.eye.z = cameraEye(3)/normFac;
246135

247136
%-camera up-%
248137
scene.camera.up.x = cameraUpVector(1);

0 commit comments

Comments
 (0)