forked from Mirkes/ElMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawMapInt.m
220 lines (206 loc) · 7.45 KB
/
drawMapInt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
function drawMapInt( map, data, projType, varargin )
%drawMapInt create figure and draw data and maps in the internal maps
%coordinates.
% map is object of class MapGeometry (descendant of this class).
% data is matrix of data points. each row is one point.
% projType is the type of projection:
% 0 is projection to the nearest node,
% 1 is projection to the nearest edge,
% 2 is projection to the nearest face.
% default value is 0.
% There are several additional parameters in form m'Name', value:
% 'nodeMarker' is one of the possible marker shape symbol ('o', '+',
% '*', '.', 'x', 's', 'd', '^', 'v', '<', '>', 'p', 'h') or
% 'none'. Default value is 'o'.
% 'nodeMarkerSize' is positive number which is size of node marker.
% This parameter is ignored for the projection of the first type.
% Default value is 6;
% 'nodeColour' is one of the possible Matlab colours ('r', 'g', 'b',
% 'y', 'm', 'c', 'w', 'k'). Default value is 'r';
% 'lineWidth' is non-negative number for map line width. Default
% value is 2.
if nargin<3
projType = 0;
end
% Data preprocessing
data = map.preprocessData(data);
% Parse optional parameters
classes = [];
markColour = [];
markShape = [];
markSize = [];
nodeMarker = 'o';
nodeMarkerSize = 6;
nodeColour = 'r';
lineWidth = 2;
for i=1:2:length(varargin)
switch lower(varargin{i})
case 'classes'
classes = varargin{i + 1};
case 'markcolour'
markColour = varargin{i + 1};
case 'markshape'
markShape = varargin{i + 1};
case 'marksize'
markSize = varargin{i + 1};
case 'nodemarker'
nodeMarker = varargin{i + 1};
case 'nodemarkersize'
nodeMarkerSize = varargin{i + 1};
case 'nodecolour'
nodeColour = varargin{i + 1};
case 'linewidth'
lineWidth = varargin{i + 1};
otherwise
error(['Unknown argument at position "', num2str(i + 2)]);
end
end
% N = size(data, 1);
% Sanity check of arguments.
if isempty(classes)
classes = ones(size(data, 1), 1);
cls = 1;
else
cls = unique(classes);
end
nCls = length(cls);
if isempty(markColour)
markColour = repmat('b', nCls, 1);
end
if isempty(markShape)
markShape = repmat('s', nCls, 1);
end
if isempty(markSize)
markSize = repmat(6, nCls, 1);
end
% Create figure
figure;
% Get map coordinates
maps = map.getInternalCoordinates;
% Get limits of map
lims = zeros(1, 4);
lims([1, 3]) = min(maps) - 1;
lims([2, 4]) = max(maps) + 1;
% Get map links
links = map.getLinks;
% Project data onto map
if ~isempty(data)
data = map.project(data, projType, 'internal');
end
% Get data dimension
dim = size(maps,2);
if dim > 3
elseif dim == 3
%3d data
elseif dim == 2
%two dimensional data
%Project data to map
hold on
%Draw edges
%Prepare arrays
X=[maps(links(:,1),1)';maps(links(:,2),1)'];
Y=[maps(links(:,1),2)';maps(links(:,2),2)'];
%Draw edges
plot(X, Y, nodeColour, 'LineWidth', lineWidth);
if projType == 0
if ~isempty(data)
%Search unique points
[dat, ~, ic] = unique(data,'rows');
count = accumarray(ic, 1);
ma = max(count);
%Draw map nodes
if nCls == 1 % No classes
scatter(dat(:, 1), dat(:, 2), count/ma * 400,...
nodeColour, 'filled', nodeMarker);
else
% We have classes We need to draw each marker by it's
% own colour or several colours
% First of all calculate number of points of each class
% in each node.
nDat = size(dat, 1);
props = zeros(nDat, nCls);
for k = 1:nCls
ind = classes == cls(k);
props(:, k) = accumarray(ic(ind), 1, [nDat, 1]);
end
% Now we put pie Chart in each necesssary node.
for k = 1:nDat
drawPieChart(dat(k, 1), dat(k, 2),...
0.5 * count(k) / ma, props(k, :), markColour);
end
end
end
axis(lims);
else
%Draw maps nodes
plot(maps(:,1), maps(:,2), 'Marker', nodeMarker,...
'MarkerFaceColor', nodeColour, 'MarkerEdgeColor', nodeColour,...
'MarkerSize', nodeMarkerSize, 'LineStyle', 'none');
%Draw data points
if ~isempty(data)
for k = 1:nCls
ind = classes == cls(k);
plot(data(ind, 1), data(ind, 2),...
[markColour(k), markShape(k)],...
'MarkerFaceColor', markColour(k),...
'MarkerSize', markSize(k));
hold on
end
end
end
else
%one dimensional data
hold on
%Draw edges
%Prepare arrays
X=[maps(links(:,1),1)';maps(links(:,2),1)'];
Y=zeros(2,size(links,1));
%Draw edges
plot(X, Y, nodeColour, 'LineWidth', lineWidth);
%Draw map nodes
if projType == 0
if ~isempty(data)
%Search unique points
[dat, ~, ic] = unique(data,'rows');
count = accumarray(ic,1);
ma=max(count);
%Draw map nodes
if nCls == 1 % No classes
scatter(dat(:,1), zeros(size(dat,1),1),...
count / ma * 400, nodeColour, 'filled', nodeMarker);
else
% We have classes We need to draw each marker by it's
% own colour or several colours
% First of all calculate number of points of each class
% in each node.
nDat = size(dat, 1);
props = zeros(nDat, nCls);
for k = 1:nCls
ind = classes == cls(k);
props(:, k) = accumarray(ic(ind), 1, [nDat, 1]);
end
% Now we put pie Chart in each necesssary node.
for k = 1:nDat
drawPieChart(dat(k, 1), 0,...
0.5 * count(k) / ma, props(k, :), markColour);
end
axis([lims(1:2), lims(1:2) - sum(lims(1:2)) / 2]);
end
end
else
%Draw maps nodes
plot(maps(:,1),0,'ro','MarkerFaceColor','r','MarkerSize',10);
%Draw data points
if ~isempty(data)
for k = 1:nCls
ind = classes == cls(k);
plot(data(ind, 1), 0,...
[markColour(k), markShape(k)],...
'MarkerFaceColor', markColour(k),...
'MarkerSize', markSize(k));
hold on
end
end
end
end
end