Skip to content

Commit 7476cfa

Browse files
committed
Even better
1 parent ffbc5ff commit 7476cfa

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

plotly/plotlyfig_aux/handlegraphics/updateBubblecloud.m

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,30 @@ function updateBubblecloud(obj,bcIndex)
1010
[xsource, ysource] = findSourceAxis(obj,axIndex);
1111

1212
% %-AXIS DATA-%
13-
% eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
14-
% eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
13+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
14+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
1515

16-
% obj.layout.xaxis.side = 'bottom';
17-
obj.layout.xaxis1.showline = false;
16+
obj.layout.xaxis1.showline = true;
1817
obj.layout.xaxis1.zeroline = false;
19-
% obj.layout.xaxis.autorange = false;
20-
% % obj.layout.xaxis.linecolor='rgb(0,0,0)';
21-
% obj.layout.xaxis.showgrid = true;
22-
% obj.layout.xaxis.linewidth = 1;
23-
% obj.layout.xaxis.type = 'linear';
24-
% obj.layout.xaxis.anchor = 'y1';
18+
obj.layout.xaxis1.autorange = false;
2519
obj.layout.xaxis1.mirror = true;
26-
%
27-
%
28-
% obj.layout.yaxis.side = 'left';
29-
obj.layout.yaxis1.showline = false;
20+
21+
obj.layout.yaxis1.showline = true;
3022
obj.layout.yaxis1.zeroline = false;
31-
% obj.layout.yaxis.autorange = false;
32-
% % obj.layout.yaxis.linecolor='rgb(0,0,0)';
33-
% obj.layout.yaxis.showgrid = true;
34-
% obj.layout.yaxis.linewidth = 1;
35-
% obj.layout.yaxis.type = 'linear';
36-
% obj.layout.yaxis.anchor = 'x1';
23+
obj.layout.yaxis1.autorange = false;
3724
obj.layout.yaxis1.mirror = true;
3825

39-
obj.layout.title.text='<b><b></b></b>';
26+
%%%%%%%%%%%%%%%
27+
%Useful for debugging!!!
28+
obj.layout.xaxis1.tickmode='auto';
29+
obj.layout.xaxis1.nticks=11;
30+
obj.layout.xaxis1.showticklabels=0;
31+
obj.layout.yaxis1.tickmode='auto';
32+
obj.layout.yaxis1.nticks=11;
33+
obj.layout.yaxis1.showticklabels=0;
34+
%%%%%%%%%%%%%%%
35+
36+
% obj.layout.title.text='<b><b></b></b>';
4037
obj.layout.margin.t=80;
4138
obj.layout.annotations{1}.text='';
4239

@@ -72,39 +69,49 @@ function updateBubblecloud(obj,bcIndex)
7269

7370
%-------------------------------------------------------------------------%
7471

75-
[sortedradii,sortind]=sort(sqrt(real(bcData.SizeData)),'descend');
76-
validind=isfinite(sortedradii) & sortedradii>0;
77-
sortind=sortind(validind);
78-
sortedradii=sortedradii(validind);
72+
[sortedradii,RadiusIndex]=sort(sqrt(bcData.SizeData),'descend');
7973

80-
if bcData.MaxDisplayBubbles < numel(sortind)
81-
sortind=sortind(1:bcData.MaxDisplayBubbles);
82-
sortedradii=sortedradii(1:bcData.MaxDisplayBubbles);
83-
end
84-
RadiusIndex=sortind;
74+
sortedradii=sortedradii/max(sortedradii);
8575

86-
% Normalize radii so that the largest bubble has a radius of 1
87-
if ~isempty(sortedradii)
88-
sortedradii=sortedradii/max(sortedradii);
89-
end
76+
ar = obj.layout.width/obj.layout.height;
77+
78+
xIN = xaxis.domain(2) - xaxis.domain(1);
79+
yIN = yaxis.domain(2) - yaxis.domain(1);
80+
axAR = ar*xIN/yIN;
9081

91-
ar = 840/630;
9282
xy = matlab.graphics.internal.layoutBubbleCloud(sortedradii,ar);
93-
fac=2*ar;
94-
rads = 2*sortedradii * (840 / ( fac*max(xy(1,:)) - fac*min(xy(1,:))));
95-
% xy = matlab.graphics.internal.layoutBubbleCloud(rads,ar);
9683

97-
obj.layout.xaxis1.range=[fac*min(xy(1,:)), fac*max(xy(1,:))];
98-
obj.layout.yaxis1.range=[(fac/ar)*min(xy(2,:)), (fac/ar)*max(xy(2,:))];
84+
xR = [min(xy(1,:)-sortedradii), max(xy(1,:)+sortedradii)];
85+
yR = [min(xy(2,:)-sortedradii), max(xy(2,:)+sortedradii)];
86+
87+
xR = xR + [-0.025, 0.025]*abs(diff(xR));
88+
yR = yR + [-0.025, 0.025]*abs(diff(yR));
89+
90+
dataAR = abs(diff(xR))/abs(diff(yR));
91+
92+
if dataAR > axAR
93+
amounttopad = abs(diff(yR)) * dataAR/axAR - abs(diff(yR));
94+
yR = yR + [-amounttopad/2, amounttopad/2];
95+
else
96+
amounttopad = abs(diff(xR)) * axAR/dataAR - abs(diff(xR));
97+
xR = xR + [-amounttopad/2, amounttopad/2];
98+
end
99+
100+
radX = (2*sortedradii * (xIN*840) / abs(diff(xR)));
101+
% yR = [(yR(1)+yR(2))/2 - abs(diff(xR))/2, (yR(1)+yR(2))/2 + abs(diff(xR))/2];
102+
103+
% radY = (2*sortedradii * (yIN*630) / abs(diff(yR)));
99104

100-
% rads = 2*rads * (840 / ( fac*max(xy(1,:)) - fac*min(xy(1,:))));
105+
obj.layout.xaxis1.range=xR;
106+
obj.layout.yaxis1.range=yR + [0.32,-0.32];
107+
rads=radX;
101108

102109
%-------------------------------------------------------------------------%
103110

104111
labels = bcData.LabelData(RadiusIndex);
105112
obj.data{bcIndex}.text = arrayfun(@(x) {char(x)}, labels);
106113

107-
obj.data{bcIndex}.textfont = matlab2plotlyfont(bcData.FontName);
114+
% obj.data{bcIndex}.textfont = matlab2plotlyfont(bcData.FontName);
108115

109116
%-------------------------------------------------------------------------%
110117

0 commit comments

Comments
 (0)