Skip to content

Commit

Permalink
Adds missing setMarkerOpacity fn and updates call, closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
djoshea committed Nov 22, 2021
1 parent ae56e18 commit 505b1bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions +Neuropixel/+Utils/setMarkerOpacity.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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')
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
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

4 changes: 2 additions & 2 deletions +Neuropixel/KilosortMetrics.m
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ function plotClusterDriftmap(m, varargin)

if showIndividual && (~onlyGaps || hasGaps)
h = plot(x, y, '.', 'Color', cmap(iC,:), 'MarkerSize', sz, 'UserData', ud);
TrialDataUtilities.Plotting.setMarkerOpacity(h, alpha);
Neuropixel.Utils.setMarkerOpacity(h, alpha);

hold on;
end
Expand Down Expand Up @@ -2668,4 +2668,4 @@ function multiple_plotDriftmap(mSet, varargin)
end
end

end
end

0 comments on commit 505b1bf

Please sign in to comment.