Skip to content

Commit 03ff977

Browse files
author
Tobias W. Harvey
committed
added option for vertex number and field value to hover over menu
1 parent b2ce7bd commit 03ff977

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/m/plot/applyoptions.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ function applyoptions(md,data,options)
439439
set(gca,'pos',Axis);
440440
end
441441

442+
if exist(options,'datatip')
443+
datatip = getfieldvalue(options, 'datatip')
444+
p = findobj(gcf, 'Type', 'patch');
445+
dcm = datacursormode(gcf);
446+
set(dcm, 'Enable', 'on');
447+
set(dcm, 'UpdateFcn', {@plot_datatip, p.Vertices(:, 1), p.Vertices(:, 2), p.FaceVertexCData, datatip});
448+
end
449+
442450
%showregion
443451
if strcmpi(getfieldvalue(options,'showregion','off'),'on'),
444452
%Keep pointer of main axis
@@ -621,3 +629,6 @@ function applyoptions(md,data,options)
621629

622630
%clipping off always:
623631
set(gca,'Clipping',getfieldvalue(options,'clipping','on'));
632+
633+
end
634+

src/m/plot/plot_datatip.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function output_txt = plot_datatip(~, event_obj, x, y, field, datatip)
2+
3+
pos = event_obj.Position;
4+
[~, idx] = min( (x - pos(1)).^2 + (y - pos(2)).^2 );
5+
6+
if strcmp(datatip, 'vertex-field')
7+
output_txt = {
8+
['X: ', num2str(pos(1))], ...
9+
['Y: ', num2str(pos(2))], ...
10+
['Vertex #: ', num2str(idx)], ...
11+
['Field: ', num2str(field(idx))]
12+
};
13+
else
14+
output_txt = {
15+
['X: ', num2str(pos(1))], ...
16+
['Y: ', num2str(pos(2))], ...
17+
['Value: ', num2str(datatip(idx))]
18+
};
19+
end
20+
21+
end

src/m/plot/plotdoc.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function plotdoc()
6666
disp(' ''contourticks'': ''on'' or ''off'' to display the ticks of the contours');
6767
disp(' ''contouronly'': ''on'' or ''off'' to display the contours on a white background');
6868
disp(' ''contourcolor'': ticks and contour color');
69+
disp(' ''datatip'': an additional datatip entry (''vertex-field'' for vertex number and field value, or any md.mesh.numberofvertices length array');
6970
disp(' ''density'': density of quivers (one arrow every N nodes, N integer)');
7071
disp(' ''inset'': add an inset (zoom) of the current figure if 1 (use ''insetx'', ''insety'' and ''insetpos'' to determine the inset position and content)');
7172
disp(' ''insetx'': [min(x) max(x)] where min(x) and max(x) are values determining the inset content');

0 commit comments

Comments
 (0)