Skip to content

Commit 7139241

Browse files
Merge pull request #510 from plotly/support-single-point-line-plots
Support single point line plots
2 parents 4d07882 + d691c57 commit 7139241

36 files changed

+147
-494
lines changed

plotly/plotly_offline_aux/plotlyoffline.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
if plotlyfig.PlotOptions.IncludePlotlyjs
88
% grab the bundled dependencies
99
userHome = getuserdir();
10-
plotlyConfigFolder = fullfile(userHome,'.plotly');
10+
plotlyConfigFolder = fullfile(userHome,'.plotly');
1111
plotlyJSFolder = fullfile(plotlyConfigFolder, 'plotlyjs');
1212
bundleName = 'plotly-matlab-offline-bundle.js';
1313
bundleFile = fullfile(plotlyJSFolder, bundleName);
@@ -30,8 +30,8 @@
3030

3131
% handle plot div specs
3232
id = char(java.util.UUID.randomUUID);
33-
width = [num2str(plotlyfig.layout.width) 'px'];
34-
height = [num2str(plotlyfig.layout.height) 'px'];
33+
width = plotlyfig.layout.width + "px";
34+
height = plotlyfig.layout.height + "px";
3535

3636
if plotlyfig.PlotOptions.ShowLinkText
3737
linkText = plotlyfig.PlotOptions.LinkText;

plotly/plotlyfig_aux/core/updateAxis.m

+13-40
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,26 @@
6969

7070
%---------------------------------------------------------------------%
7171

72-
%-xaxis-%
7372
if isHeatmapAxis
7473
xaxis = extractHeatmapAxisData(obj,axisData, 'X');
7574
xExponentFormat = 0;
7675
else
7776
[xaxis, xExponentFormat] = extractAxisData(obj,axisData, 'X');
7877
end
79-
80-
%---------------------------------------------------------------------%
81-
82-
%-yaxis-%
8378
if isHeatmapAxis
8479
yaxis = extractHeatmapAxisData(obj,axisData, 'Y');
8580
yExponentFormat = 0;
8681
else
8782
[yaxis, yExponentFormat] = extractAxisData(obj,axisData, 'Y');
8883
end
8984

90-
%---------------------------------------------------------------------%
91-
92-
%-get position data-%
9385
axisPos = axisData.Position .* obj.PlotOptions.DomainFactor;
9486
if obj.PlotOptions.AxisEqual
9587
axisPos(3:4) = min(axisPos(3:4));
9688
end
9789

98-
%---------------------------------------------------------------------%
99-
100-
%-xaxis domain-%
10190
xaxis.domain = min([axisPos(1) sum(axisPos([1,3]))], 1);
10291
scene.domain.x = xaxis.domain;
103-
104-
%---------------------------------------------------------------------%
105-
106-
%-yaxis domain-%
10792
yaxis.domain = min([axisPos(2) sum(axisPos([2,4]))], 1);
10893
scene.domain.y = yaxis.domain;
10994

@@ -122,8 +107,8 @@
122107
exponentText = sprintf('x10^%d', yExponentFormat);
123108

124109
obj.layout.annotations{anIndex}.text = exponentText;
125-
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
126-
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
110+
obj.layout.annotations{anIndex}.xref = "x" + xsource;
111+
obj.layout.annotations{anIndex}.yref = "y" + ysource;
127112
obj.layout.annotations{anIndex}.xanchor = 'left';
128113
obj.layout.annotations{anIndex}.yanchor = 'bottom';
129114
obj.layout.annotations{anIndex}.font.size = yaxis.tickfont.size;
@@ -142,8 +127,8 @@
142127
exponentText = sprintf('x10^%d', xExponentFormat);
143128

144129
obj.layout.annotations{anIndex}.text = exponentText;
145-
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
146-
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
130+
obj.layout.annotations{anIndex}.xref = "x" + xsource;
131+
obj.layout.annotations{anIndex}.yref = "y" + ysource;
147132
obj.layout.annotations{anIndex}.xanchor = 'left';
148133
obj.layout.annotations{anIndex}.yanchor = 'bottom';
149134
obj.layout.annotations{anIndex}.font.size = xaxis.tickfont.size;
@@ -159,50 +144,38 @@
159144

160145
%---------------------------------------------------------------------%
161146

162-
%-xaxis anchor-%
163-
xaxis.anchor = ['y' num2str(ysource)];
164-
165-
%---------------------------------------------------------------------%
147+
xaxis.anchor = "y" + ysource;
148+
yaxis.anchor = "x" + xsource;
166149

167-
%-yaxis anchor-%
168-
yaxis.anchor = ['x' num2str(xsource)];
169-
170-
%---------------------------------------------------------------------%
171-
172-
%-xaxis overlaying-%
173150
if xoverlay
174-
xaxis.overlaying = ['x' num2str(xoverlay)];
151+
xaxis.overlaying = "x" + xoverlay;
175152
end
176-
177-
%---------------------------------------------------------------------%
178-
179-
%-yaxis overlaying-%
180153
if yoverlay
181-
yaxis.overlaying = ['y' num2str(yoverlay)];
154+
yaxis.overlaying = "y" + yoverlay;
182155
end
183156

184157
%---------------------------------------------------------------------%
185158

186159
% update the layout field (do not overwrite source)
187160
if xsource == axIndex
188-
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
189-
obj.layout = setfield(obj.layout,['scene' num2str(xsource)],scene);
161+
obj.layout = setfield(obj.layout, "xaxis" + xsource, xaxis);
162+
obj.layout = setfield(obj.layout, "scene" + xsource, scene);
190163
end
191164

192165
%---------------------------------------------------------------------%
193166

194167
% update the layout field (do not overwrite source)
195168
if ysource == axIndex
196-
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);
169+
obj.layout = setfield(obj.layout, "yaxis" + ysource, yaxis);
197170
end
198171

199172
%---------------------------------------------------------------------%
200173

201174
%-REVERT UNITS-%
202-
set(obj.State.Axis(axIndex).Handle,'Units',axisUnits);
175+
set(obj.State.Axis(axIndex).Handle, 'Units', axisUnits);
203176

204177
try
205-
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits);
178+
set(obj.State.Axis(axIndex).Handle, 'FontUnits', fontUnits);
206179
catch
207180
% TODO
208181
end

plotly/plotlyfig_aux/core/updateAxisMultipleYAxes.m

+8-32
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818
%---------------------------------------------------------------------%
1919

20-
%-xaxis-%
2120
xaxis = extractAxisData(obj,axisData, 'X');
22-
23-
%---------------------------------------------------------------------%
24-
25-
%-yaxis-%
2621
[yaxis, yAxisLim] = extractAxisDataMultipleYAxes(obj, axisData, yaxIndex);
2722

2823
%---------------------------------------------------------------------%
@@ -42,13 +37,8 @@
4237

4338
%---------------------------------------------------------------------%
4439

45-
%-xaxis domain-%
4640
xaxis.domain = min([xo xo + w],1);
4741
scene.domain.x = min([xo xo + w],1);
48-
49-
%---------------------------------------------------------------------%
50-
51-
%-yaxis domain-%
5242
yaxis.domain = min([yo yo + h],1);
5343
scene.domain.y = min([yo yo + h],1);
5444

@@ -58,39 +48,27 @@
5848

5949
%---------------------------------------------------------------------%
6050

61-
%-xaxis anchor-%
62-
xaxis.anchor = ['y' num2str(ysource)];
63-
64-
%---------------------------------------------------------------------%
51+
xaxis.anchor = "y" + ysource;
52+
yaxis.anchor = "x" + xsource;
6553

66-
%-yaxis anchor-%
67-
yaxis.anchor = ['x' num2str(xsource)];
68-
69-
%---------------------------------------------------------------------%
70-
71-
%-xaxis overlaying-%
7254
if xoverlay
73-
xaxis.overlaying = ['x' num2str(xoverlay)];
55+
xaxis.overlaying = "x" + xoverlay;
7456
end
75-
76-
%---------------------------------------------------------------------%
77-
78-
%-yaxis overlaying-%
7957
if yoverlay
80-
yaxis.overlaying = ['y' num2str(yoverlay)];
58+
yaxis.overlaying = "y" + yoverlay;
8159
end
8260

8361
%---------------------------------------------------------------------%
8462

8563
% update the layout field (do not overwrite source)
8664
if xsource == axIndex
87-
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
65+
obj.layout = setfield(obj.layout, "xaxis" + xsource, xaxis);
8866
end
8967

9068
%---------------------------------------------------------------------%
9169

9270
% update the layout field (do not overwrite source)
93-
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);
71+
obj.layout = setfield(obj.layout, "yaxis" + ysource, yaxis);
9472

9573
%---------------------------------------------------------------------%
9674

@@ -110,8 +88,6 @@
11088
plotIndex = obj.PlotOptions.nPlots;
11189

11290
obj.data{plotIndex}.type = 'scatter';
113-
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
114-
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];
115-
116-
%---------------------------------------------------------------------%
91+
obj.data{plotIndex}.xaxis = "x" + xsource;
92+
obj.data{plotIndex}.yaxis = "y" + ysource;
11793
end

plotly/plotlyfig_aux/core/updateConstantLine.m

+2-16
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,14 @@ function updateConstantLine(obj,plotIndex)
1010

1111
%---------------------------------------------------------------------%
1212

13-
%-scatter xaxis-%
14-
obj.data{plotIndex}.xaxis = ["x" num2str(xsource)];
15-
16-
%---------------------------------------------------------------------%
17-
18-
%-scatter yaxis-%
19-
obj.data{plotIndex}.yaxis = ["y" num2str(ysource)];
20-
21-
%---------------------------------------------------------------------%
22-
23-
%-scatter type-%
13+
obj.data{plotIndex}.xaxis = "x" + xsource;
14+
obj.data{plotIndex}.yaxis = "y" + ysource;
2415
obj.data{plotIndex}.type = "scatter";
25-
26-
%---------------------------------------------------------------------%
27-
28-
%-scatter visible-%
2916
obj.data{plotIndex}.visible = strcmp(plotData.Visible, "on");
3017

3118
%---------------------------------------------------------------------%
3219

3320
%-scatter-%
34-
3521
xaxis = obj.layout.("xaxis"+xsource);
3622
yaxis = obj.layout.("yaxis"+ysource);
3723
value = [plotData.Value plotData.Value];

0 commit comments

Comments
 (0)