|
2 | 2 | % EXTRACTS THE FACE STYLE USED FOR MATLAB OBJECTS |
3 | 3 | % OF TYPE "bar". THESE OBJECTS ARE USED BARGRAPHS. |
4 | 4 |
|
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 |
47 | 18 |
|
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)); |
51 | 22 | 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,:); |
67 | 35 | end |
68 | | - marker.line.color = getStringColor(col); |
| 36 | + out = getStringColor(round(255*col)); |
69 | 37 | end |
70 | 38 | end |
71 | 39 | end |
0 commit comments