|
1 |
| -function obj = updateHeatmap(obj,heatIndex) |
| 1 | +function data = updateHeatmap(obj,heatIndex) |
2 | 2 | %-HEATMAP DATA STRUCTURE- %
|
3 | 3 | heat_data = obj.State.Plot(heatIndex).Handle;
|
4 | 4 |
|
5 |
| - %-heatmap type-% |
6 |
| - obj.data{heatIndex}.type = 'heatmap'; |
| 5 | + data.type = "heatmap"; |
7 | 6 |
|
8 |
| - %-format data-% |
9 |
| - xdata = heat_data.XDisplayData; |
10 |
| - ydata = heat_data.YDisplayData(end:-1:1, :); |
11 | 7 | cdata = heat_data.ColorDisplayData(end:-1:1, :);
|
12 | 8 |
|
13 |
| - obj.data{heatIndex}.x = xdata; |
14 |
| - obj.data{heatIndex}.y = ydata; |
15 |
| - obj.data{heatIndex}.z = cdata; |
16 |
| - obj.data{heatIndex}.connectgaps = false; |
17 |
| - obj.data{heatIndex}.hoverongaps = false; |
| 9 | + data.x = heat_data.XDisplayData; |
| 10 | + data.y = heat_data.YDisplayData(end:-1:1, :); |
| 11 | + data.z = cdata; |
| 12 | + data.connectgaps = false; |
| 13 | + data.hoverongaps = false; |
18 | 14 |
|
19 |
| - %-heatmap colorscale-% |
20 | 15 | cmap = heat_data.Colormap;
|
21 | 16 | len = length(cmap)-1;
|
22 |
| - |
23 |
| - for c = 1: length(cmap) |
24 |
| - col = round(255 * cmap(c, :)); |
25 |
| - obj.data{heatIndex}.colorscale{c} = ... |
26 |
| - {(c-1)/len, sprintf("rgb(%d,%d,%d)", col)}; |
| 17 | + for c = 1:length(cmap) |
| 18 | + col = round(255*cmap(c, :)); |
| 19 | + data.colorscale{c} = {(c-1)/len, getStringColor(col)}; |
27 | 20 | end
|
28 | 21 |
|
29 |
| - %-setting plot-% |
30 |
| - obj.data{heatIndex}.hoverinfo = 'text'; |
31 |
| - obj.data{heatIndex}.text = heat_data.ColorData(end:-1:1, :); |
32 |
| - obj.data{heatIndex}.hoverlabel.bgcolor = 'white'; |
| 22 | + data.hoverinfo = "text"; |
| 23 | + data.text = heat_data.ColorData(end:-1:1, :); |
| 24 | + data.hoverlabel.bgcolor = "white"; |
33 | 25 |
|
34 |
| - %-show colorbar-% |
35 |
| - obj.data{heatIndex}.showscale = false; |
36 |
| - if strcmpi(heat_data.ColorbarVisible, 'on') |
37 |
| - obj.data{heatIndex}.showscale = true; |
38 |
| - obj.data{heatIndex}.colorbar.x = 0.87; |
39 |
| - obj.data{heatIndex}.colorbar.y = 0.52; |
40 |
| - obj.data{heatIndex}.colorbar.ypad = 55; |
41 |
| - obj.data{heatIndex}.colorbar.xpad = obj.PlotlyDefaults.MarginPad; |
42 |
| - obj.data{heatIndex}.colorbar.outlinecolor = 'rgb(150,150,150)'; |
| 26 | + data.showscale = false; |
| 27 | + if lower(heat_data.ColorbarVisible) == "on" |
| 28 | + data.showscale = true; |
| 29 | + data.colorbar = struct( ... |
| 30 | + "x", 0.87, ... |
| 31 | + "y", 0.52, ... |
| 32 | + "ypad", 55, ... |
| 33 | + "xpad", obj.PlotlyDefaults.MarginPad, ... |
| 34 | + "outlinecolor", "rgb(150,150,150)" ... |
| 35 | + ); |
43 | 36 | end
|
44 | 37 |
|
45 |
| - %-hist visible-% |
46 |
| - obj.data{heatIndex}.visible = strcmp(heat_data.Visible,'on'); |
47 |
| - obj.data{heatIndex}.opacity = 0.95; |
| 38 | + data.visible = heat_data.Visible == "on"; |
| 39 | + data.opacity = 0.95; |
48 | 40 |
|
49 | 41 | %-setting annotation text-%
|
50 |
| - c = 1; |
51 | 42 | maxcol = max(cdata(:));
|
52 |
| - |
53 |
| - for n = 1:size(cdata, 2) |
54 |
| - for m = 1:size(cdata, 1) |
55 |
| - %-text-% |
56 |
| - ann{c}.text = num2str(round(cdata(m,n), 2)); |
57 |
| - ann{c}.x = n-1; |
58 |
| - ann{c}.y = m-1; |
59 |
| - ann{c}.showarrow = false; |
60 |
| - |
61 |
| - %-font-% |
62 |
| - ann{c}.font.size = heat_data.FontSize*1.15; |
63 |
| - ann{c}.font.family = matlab2plotlyfont(heat_data.FontName); |
64 |
| - if cdata(m,n) < 0.925*maxcol |
| 43 | + m = size(cdata, 2); |
| 44 | + n = size(cdata, 1); |
| 45 | + annotations = cell(1,m*n); |
| 46 | + for i = 1:m |
| 47 | + for j = 1:n |
| 48 | + ann.text = num2str(round(cdata(j,i), 2)); |
| 49 | + ann.x = i-1; |
| 50 | + ann.y = j-1; |
| 51 | + ann.showarrow = false; |
| 52 | + ann.font.size = heat_data.FontSize*1.15; |
| 53 | + ann.font.family = matlab2plotlyfont(heat_data.FontName); |
| 54 | + if cdata(j,i) < 0.925*maxcol |
65 | 55 | col = [0,0,0];
|
66 | 56 | else
|
67 | 57 | col = [255,255,255];
|
68 | 58 | end
|
69 |
| - ann{c}.font.color = sprintf("rgb(%d,%d,%d)", col); |
70 |
| - c = c+1; |
| 59 | + ann.font.color = getStringColor(col); |
| 60 | + annotations{i*(m-1)+j} = ann; |
71 | 61 | end
|
72 | 62 | end
|
73 | 63 |
|
74 |
| - obj.layout.annotations = ann; |
| 64 | + obj.layout.annotations = annotations; |
75 | 65 |
|
76 | 66 | %-set background color if any NaN in cdata-%
|
77 | 67 | if any(isnan(cdata(:)))
|
78 |
| - obj.layout.plot_bgcolor = 'rgb(40,40,40)'; |
79 |
| - obj.data{heatIndex}.opacity = 1; |
| 68 | + obj.layout.plot_bgcolor = "rgb(40,40,40)"; |
| 69 | + data.opacity = 1; |
80 | 70 | end
|
81 | 71 | end
|
0 commit comments