Skip to content

Commit 1fc139c

Browse files
Refactor updateBar
1 parent 0473653 commit 1fc139c

File tree

4 files changed

+27
-51
lines changed

4 files changed

+27
-51
lines changed

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
case "animatedline"
110110
updateAnimatedLine(obj, dataIndex);
111111
case "bar"
112-
updateBar(obj, dataIndex);
112+
obj.data{dataIndex} = updateBar(obj, dataIndex);
113113
case "barseries"
114114
updateBarseries(obj, dataIndex);
115115
case "baseline"
@@ -195,7 +195,7 @@
195195
yaxis = obj.layout.("yaxis" + ysource);
196196

197197
% check for xaxis dates
198-
if strcmpi(xaxis.type, "date")
198+
if xaxis.type == "date"
199199
obj.data{dataIndex}.x = convertDate(obj.data{dataIndex}.x);
200200
elseif xaxis.type == "duration"
201201
obj.data{dataIndex}.x = convertDuration(obj.data{dataIndex}.x);

plotly/plotlyfig_aux/handlegraphics/updateBar.m

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function obj = updateBar(obj,barIndex)
1+
function data = updateBar(obj,barIndex)
22
% x: ...[DONE]
33
% y: ...[DONE]
44
% name: ...[DONE]
@@ -50,14 +50,12 @@
5050
%-CHECK FOR MULTIPLE AXES-%
5151
[xSource, ySource] = findSourceAxis(obj, axIndex);
5252

53-
%-associate axis-%
54-
obj.data{barIndex}.xaxis = "x" + xSource;
55-
obj.data{barIndex}.yaxis = "y" + ySource;
56-
obj.data{barIndex}.type = "bar";
57-
obj.data{barIndex}.name = barData.DisplayName;
58-
obj.data{barIndex}.visible = strcmp(barData.Visible,"on");
53+
data.xaxis = "x" + xSource;
54+
data.yaxis = "y" + ySource;
55+
data.type = "bar";
56+
data.name = barData.DisplayName;
57+
data.visible = barData.Visible == "on";
5958

60-
%-set plot data-%
6159
xData = barData.XData;
6260
yData = barData.YData;
6361

@@ -70,22 +68,18 @@
7068

7169
switch barData.Horizontal
7270
case "off"
73-
obj.data{barIndex}.orientation = "v";
74-
obj.data{barIndex}.x = xData;
75-
obj.data{barIndex}.y = yData;
71+
data.orientation = "v";
72+
data.x = xData;
73+
data.y = yData;
7674
case "on"
77-
obj.data{barIndex}.orientation = "h";
78-
obj.data{barIndex}.x = yData;
79-
obj.data{barIndex}.y = xData;
75+
data.orientation = "h";
76+
data.x = yData;
77+
data.y = xData;
8078
end
8179

82-
%-trace settings-%
83-
markerline = extractAreaLine(barData);
80+
data.marker = extractAreaFace(barData);
81+
data.marker.line = extractAreaLine(barData);
8482

85-
obj.data{barIndex}.marker = extractAreaFace(barData);
86-
obj.data{barIndex}.marker.line = markerline;
87-
88-
%-layout settings-%
8983
obj.layout.bargroupgap = 1-barData.BarWidth;
9084

9185
bars = findobj(obj.State.Plot(barIndex).AssociatedAxis.Children, ...
@@ -104,15 +98,10 @@
10498
obj.layout.barmode = "relative";
10599
end
106100

107-
%-bar showlegend-%
108-
leg = barData.Annotation;
109-
legInfo = leg.LegendInformation;
110-
111-
switch legInfo.IconDisplayStyle
101+
switch barData.Annotation.LegendInformation.IconDisplayStyle
112102
case "on"
113-
showleg = true;
103+
data.showlegend = true;
114104
case "off"
115-
showleg = false;
105+
data.showlegend = false;
116106
end
117-
obj.data{barIndex}.showlegend = showleg;
118107
end

plotly/plotlyfig_aux/helpers/extractAreaFace.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
% face face color
2121
MarkerColor = area_data.FaceColor;
2222
if isnumeric(MarkerColor)
23-
col = [round(255*MarkerColor) area_data.FaceAlpha];
24-
facecolor = sprintf("rgba(%d,%d,%d,%f)", col);
23+
facecolor = getStringColor(round(255*MarkerColor), ...
24+
area_data.FaceAlpha);
2525
else
2626
switch MarkerColor
2727
case "none"
@@ -32,10 +32,9 @@
3232
axis_data.CLim(1));
3333
scalefactor = (capCD - axis_data.CLim(1)) ...
3434
/ diff(axis_data.CLim);
35-
col = 255*(colormap(1 + floor(scalefactor ...
36-
* (length(colormap)-1)),:));
37-
col = [round(col) area_data.FaceAlpha];
38-
facecolor = sprintf("rgba(%d,%d,%d,%f)", col);
35+
col = round(255*(colormap(1 + floor(scalefactor ...
36+
* (length(colormap)-1)),:)));
37+
facecolor = getStringColor(col, area_data.FaceAlpha);
3938
end
4039
end
4140
face.color = facecolor;

plotly/plotlyfig_aux/helpers/extractAreaLine.m

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,20 @@
33
% OF TYPE "LINE". THESE OBJECTS ARE USED IN LINESERIES,
44
% STAIRSERIES, STEMSERIES, BASELINESERIES, AND BOXPLOTS
55

6-
%-INITIALIZE OUTPUT-%
76
line = struct();
87

9-
%-AREA LINE COLOR-%
10-
11-
if area_data.LineStyle~="none"
12-
% marker edge color
8+
if area_data.LineStyle ~= "none"
139
LineColor = area_data.EdgeColor;
14-
1510
if isnumeric(LineColor)
16-
col = [round(255*LineColor) area_data.EdgeAlpha];
17-
linecolor = sprintf("rgba(%d,%d,%d,%f)", col);
11+
linecolor = getStringColor(round(255*LineColor), ...
12+
area_data.EdgeAlpha);
1813
else
1914
linecolor = "rgba(0,0,0,0)";
2015
end
2116

2217
line.color = linecolor;
23-
24-
%-----------------------------------------------------------------%
25-
26-
%-PATCH LINE WIDTH (STYLE)-%
2718
line.width = area_data.LineWidth;
2819

29-
%-----------------------------------------------------------------%
30-
31-
%-PATCH LINE DASH (STYLE)-%
3220
switch area_data.LineStyle
3321
case "-"
3422
LineStyle = "solid";

0 commit comments

Comments
 (0)