Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b73aa2

Browse files
Refactor extractPatchLine.m
1 parent 6cff239 commit 7b73aa2

File tree

2 files changed

+42
-49
lines changed

2 files changed

+42
-49
lines changed

plotly/Test_plotlyfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ function testPieChartPlotData(tc)
696696
line = struct( ...
697697
color = "rgb(0,0,0)", ...
698698
width = 0.5, ...
699-
dash = 'solid' ...
699+
dash = "solid" ...
700700
), ...
701701
fillcolor = "rgba(62,38,168,1.000000)", ...
702702
showlegend = false ...

plotly/plotlyfig_aux/helpers/extractPatchLine.m

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

6-
%-AXIS STRUCTURE-%
7-
axis_data = ancestor(patch_data.Parent,'axes');
8-
9-
%-FIGURE STRUCTURE-%
10-
figure_data = ancestor(patch_data.Parent,'figure');
11-
12-
%-INITIALIZE OUTPUT-%
136
line = struct();
7+
if patch_data.LineStyle == "none"
8+
return
9+
end
1410

15-
%-PATCH LINE COLOR-%
11+
cLim = ancestor(patch_data.Parent, "axes").CLim;
12+
colormap = ancestor(patch_data.Parent, "figure").Colormap;
13+
faceVertexCData = patch_data.FaceVertexCData(1,1);
14+
cDataMapping = patch_data.CDataMapping;
1615

17-
colormap = figure_data.Colormap;
16+
line.color = extractColor(patch_data.EdgeColor, cDataMapping, colormap, cLim, faceVertexCData);
17+
line.width = patch_data.LineWidth;
18+
line.dash = extractLineStyle(patch_data.LineStyle);
19+
end
1820

19-
if (~strcmp(patch_data.LineStyle,'none'))
20-
if isnumeric(patch_data.EdgeColor)
21-
col = round(255*patch_data.EdgeColor);
22-
line.color = getStringColor(col);
23-
else
24-
switch patch_data.EdgeColor
25-
case 'none'
26-
line.color = 'rgba(0,0,0,0)';
27-
case 'flat'
28-
switch patch_data.CDataMapping
29-
case 'scaled'
30-
capCD = max(min( ...
31-
patch_data.FaceVertexCData(1,1), ...
32-
axis_data.CLim(2)), axis_data.CLim(1));
33-
scalefactor = (capCD - axis_data.CLim(1)) ...
34-
/ diff(axis_data.CLim);
35-
col = round(255*(colormap(1+floor(scalefactor ...
36-
* (length(colormap)-1)),:)));
37-
case 'direct'
38-
col = round(255*(colormap( ...
39-
patch_data.FaceVertexCData(1,1),:)));
40-
end
41-
line.color = getStringColor(col);
42-
end
21+
function out = extractColor(color, cDataMapping, colormap, cLim, faceVertexCData)
22+
if isnumeric(color)
23+
out = getStringColor(round(255*color));
24+
else
25+
switch color
26+
case "none"
27+
out = "rgba(0,0,0,0)";
28+
case "flat"
29+
switch cDataMapping
30+
case "scaled"
31+
capCD = max(min(faceVertexCData, cLim(2)), cLim(1));
32+
scalefactor = (capCD - cLim(1)) / diff(cLim);
33+
col = colormap(1+floor(scalefactor ...
34+
* (length(colormap)-1)),:);
35+
case "direct"
36+
col = colormap(faceVertexCData,:);
37+
end
38+
out = getStringColor(round(255*col));
4339
end
40+
end
41+
end
4442

45-
%-PATCH LINE WIDTH (STYLE)-%
46-
line.width = patch_data.LineWidth;
47-
48-
%-PATCH LINE DASH (STYLE)-%
49-
switch patch_data.LineStyle
50-
case '-'
51-
LineStyle = 'solid';
52-
case '--'
53-
LineStyle = 'dash';
54-
case ':'
55-
LineStyle = 'dot';
56-
case '-.'
57-
LineStyle = 'dashdot';
58-
end
59-
line.dash = LineStyle;
43+
function out = extractLineStyle(lineStyle)
44+
switch lineStyle
45+
case "-"
46+
out = "solid";
47+
case "--"
48+
out = "dash";
49+
case ":"
50+
out = "dot";
51+
case "-."
52+
out = "dashdot";
6053
end
6154
end

0 commit comments

Comments
 (0)