-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetMarkerOpacity.m
51 lines (44 loc) · 1.76 KB
/
setMarkerOpacity.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
function setMarkerOpacity(s, faceAlpha, edgeAlpha)
% stores information in UserData struct to cause saveFigure to render
% marker points as translucent when exporting to svg
if nargin < 3
edgeAlpha = faceAlpha;
end
for i = 1:length(s)
% old version, simply tag it as translucent for saveFigure to pick
% up during SVG authoring
% userdata = get(s(i),'UserData');
% userdata.svg.MarkerFaceAlpha = faceAlpha;
% userdata.svg.MarkerEdgeAlpha = edgeAlpha;
% set(s(i),'UserData', userdata);
if ~verLessThan('matlab', '8.4')
mh = s.MarkerHandle;
if ~isa(mh, 'matlab.graphics.GraphicsPlaceholder')
% do update now if we can, otherwise wait for MarkedClean
mh = s.MarkerHandle;
if ~isempty(mh.EdgeColorData)
mh.EdgeColorType = 'truecoloralpha';
mh.EdgeColorData(4) = uint8(edgeAlpha*255);
end
if ~isempty(mh.FaceColorData)
mh.FaceColorType = 'truecoloralpha';
mh.FaceColorData(4) = uint8(faceAlpha*255);
end
end
% keep transparent on each MarkedClean, otherwise gets lost
addlistener(s(i),'MarkedClean',...
@(ObjH, EventData) keepAlpha(ObjH, EventData, faceAlpha, edgeAlpha));
end
end
end
function keepAlpha(src, ~, faceAlpha, edgeAlpha)
mh = src.MarkerHandle;
if ~isempty(mh.EdgeColorData)
mh.EdgeColorType = 'truecoloralpha';
mh.EdgeColorData(4) = uint8(edgeAlpha*255);
end
if ~isempty(mh.FaceColorData)
mh.FaceColorType = 'truecoloralpha';
mh.FaceColorData(4) = uint8(faceAlpha*255);
end
end