Skip to content

Commit ef368c1

Browse files
Merge pull request #488 from plotly/support-xline
Add support for 'xline' and 'yline'
2 parents a9c9f9c + d6edb56 commit ef368c1

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
function updateConstantLine(obj,plotIndex)
2+
%---------------------------------------------------------------------%
3+
4+
%-AXIS INDEX-%
5+
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
6+
7+
%-PLOT DATA STRUCTURE- %
8+
plotData = obj.State.Plot(plotIndex).Handle;
9+
10+
%-CHECK FOR MULTIPLE AXES-%
11+
[xsource, ysource] = findSourceAxis(obj,axIndex);
12+
13+
%---------------------------------------------------------------------%
14+
15+
%-scatter xaxis-%
16+
obj.data{plotIndex}.xaxis = ["x" num2str(xsource)];
17+
18+
%---------------------------------------------------------------------%
19+
20+
%-scatter yaxis-%
21+
obj.data{plotIndex}.yaxis = ["y" num2str(ysource)];
22+
23+
%---------------------------------------------------------------------%
24+
25+
%-scatter type-%
26+
obj.data{plotIndex}.type = "scatter";
27+
28+
%---------------------------------------------------------------------%
29+
30+
%-scatter visible-%
31+
obj.data{plotIndex}.visible = strcmp(plotData.Visible,"on");
32+
33+
%---------------------------------------------------------------------%
34+
35+
%-scatter-%
36+
37+
xaxis = obj.layout.("xaxis"+xsource);
38+
yaxis = obj.layout.("yaxis"+ysource);
39+
value = [plotData.Value plotData.Value];
40+
if plotData.InterceptAxis == "y"
41+
obj.data{plotIndex}.x = xaxis.range;
42+
obj.data{plotIndex}.y = value;
43+
else
44+
obj.data{plotIndex}.x = value;
45+
obj.data{plotIndex}.y = yaxis.range;
46+
end
47+
48+
%---------------------------------------------------------------------%
49+
50+
%-Fro 3D plots-%
51+
obj.PlotOptions.is3d = false; % by default
52+
53+
if isfield(plotData,"ZData")
54+
55+
numbset = unique(plotData.ZData);
56+
57+
if any(plotData.ZData) && length(numbset)>1
58+
%-scatter z-%
59+
obj.data{plotIndex}.z = plotData.ZData;
60+
61+
%-overwrite type-%
62+
obj.data{plotIndex}.type = "scatter3d";
63+
64+
%-flag to manage 3d plots-%
65+
obj.PlotOptions.is3d = true;
66+
end
67+
end
68+
69+
%---------------------------------------------------------------------%
70+
71+
%-scatter name-%
72+
obj.data{plotIndex}.name = plotData.DisplayName;
73+
74+
%---------------------------------------------------------------------%
75+
76+
%-scatter mode-%
77+
if plotData.Type ~= "constantline" ...
78+
&& ~strcmpi("none", plotData.Marker) ...
79+
&& ~strcmpi("none", plotData.LineStyle)
80+
mode = "lines+markers";
81+
elseif plotData.Type ~= "constantline" ...
82+
&& ~strcmpi("none", plotData.Marker)
83+
mode = "markers";
84+
elseif ~strcmpi("none", plotData.LineStyle)
85+
mode = "lines";
86+
else
87+
mode = "none";
88+
end
89+
90+
obj.data{plotIndex}.mode = mode;
91+
92+
%---------------------------------------------------------------------%
93+
94+
%-scatter line-%
95+
obj.data{plotIndex}.line = extractLineLine(plotData);
96+
97+
%---------------------------------------------------------------------%
98+
99+
%-scatter marker-%
100+
if plotData.Type ~= "constantline"
101+
obj.data{plotIndex}.marker = extractLineMarker(plotData);
102+
end
103+
104+
%---------------------------------------------------------------------%
105+
106+
%-scatter showlegend-%
107+
leg = get(plotData.Annotation);
108+
legInfo = get(leg.LegendInformation);
109+
110+
switch legInfo.IconDisplayStyle
111+
case "on"
112+
showleg = true;
113+
case "off"
114+
showleg = false;
115+
end
116+
117+
obj.data{plotIndex}.showlegend = showleg;
118+
end

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
else
7373
updateLineseries(obj, dataIndex);
7474
end
75+
case 'constantline'
76+
updateConstantLine(obj, dataIndex);
7577
case 'categoricalhistogram'
7678
updateCategoricalHistogram(obj, dataIndex);
7779
case 'histogram'

0 commit comments

Comments
 (0)