Skip to content

Commit cf106f6

Browse files
Refactor extractBarMarker.m
1 parent 3d937ba commit cf106f6

File tree

1 file changed

+29
-61
lines changed

1 file changed

+29
-61
lines changed

plotly/plotlyfig_aux/helpers/extractBarMarker.m

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,38 @@
22
% EXTRACTS THE FACE STYLE USED FOR MATLAB OBJECTS
33
% OF TYPE "bar". THESE OBJECTS ARE USED BARGRAPHS.
44

5-
%-AXIS STRUCTURE-%
6-
axis_data = ancestor(bar_data.Parent,'axes');
7-
8-
%-FIGURE STRUCTURE-%
9-
figure_data = ancestor(bar_data.Parent,'figure');
10-
11-
%-INITIALIZE OUTPUT-%
12-
marker = struct();
13-
14-
%-bar EDGE WIDTH-%
15-
marker.line.width = bar_data.LineWidth;
16-
17-
%-bar FACE COLOR-%
18-
19-
colormap = figure_data.Colormap;
20-
21-
if isnumeric(bar_data.FaceColor)
22-
%-paper_bgcolor-%
23-
col = round(255*bar_data.FaceColor);
24-
marker.color = getStringColor(col);
25-
else
26-
switch bar_data.FaceColor
27-
case 'none'
28-
marker.color = 'rgba(0,0,0,0)';
29-
case 'flat'
30-
switch bar_data.CDataMapping
31-
case 'scaled'
32-
capCD = max(min(bar_data.FaceVertexCData(1,1), ...
33-
axis_data.CLim(2)), axis_data.CLim(1));
34-
scalefactor = (capCD - axis_data.CLim(1)) ...
35-
/ diff(axis_data.CLim);
36-
col = round(255*(colormap(1+ floor(scalefactor ...
37-
* (length(colormap)-1)),:)));
38-
case 'direct'
39-
col = round(255*(colormap( ...
40-
bar_data.FaceVertexCData(1,1),:)));
41-
end
42-
marker.color = getStringColor(col);
43-
end
44-
end
45-
46-
%-bar EDGE COLOR-%
5+
cLim = ancestor(bar_data.Parent, "axes").CLim;
6+
colormap = ancestor(bar_data.Parent, "figure").Colormap;
7+
cDataMapping = bar_data.CDataMapping;
8+
faceVertexCData = bar_data.FaceVertexCData(1,1);
9+
10+
marker = struct( ...
11+
"line", struct( ...
12+
"width", bar_data.LineWidth, ...
13+
"color", extractColor(bar_data.EdgeColor, cDataMapping, colormap, cLim, faceVertexCData) ...
14+
), ...
15+
"color", extractColor(bar_data.FaceColor, cDataMapping, colormap, cLim, faceVertexCData) ...
16+
);
17+
end
4718

48-
if isnumeric(bar_data.EdgeColor)
49-
col = round(255*bar_data.EdgeColor);
50-
marker.line.color = getStringColor(col);
19+
function out = extractColor(color, cDataMapping, colormap, cLim, faceVertexCData)
20+
if isnumeric(color)
21+
out = getStringColor(round(255*color));
5122
else
52-
switch bar_data.EdgeColor
53-
case 'none'
54-
marker.line.color = 'rgba(0,0,0,0)';
55-
case 'flat'
56-
switch bar_data.CDataMapping
57-
case 'scaled'
58-
capCD = max(min(bar_data.FaceVertexCData(1,1), ...
59-
axis_data.CLim(2)), axis_data.CLim(1));
60-
scalefactor = (capCD - axis_data.CLim(1)) ...
61-
/ diff(axis_data.CLim);
62-
col = round(255*(colormap(1+floor(scalefactor ...
63-
* (length(colormap)-1)),:)));
64-
case 'direct'
65-
col = round(255*(colormap( ...
66-
bar_data.FaceVertexCData(1,1),:)));
23+
switch color
24+
case "none"
25+
out = "rgba(0,0,0,0)";
26+
case "flat"
27+
switch cDataMapping
28+
case "scaled"
29+
capCD = max(min(faceVertexCData, cLim(2)), cLim(1));
30+
scalefactor = (capCD - cLim(1)) / diff(cLim);
31+
col = colormap(1+floor(scalefactor ...
32+
* (length(colormap)-1)),:);
33+
case "direct"
34+
col = colormap(faceVertexCData,:);
6735
end
68-
marker.line.color = getStringColor(col);
36+
out = getStringColor(round(255*col));
6937
end
7038
end
7139
end

0 commit comments

Comments
 (0)