Skip to content

Commit 3c7ac33

Browse files
Merge pull request #84 from totorotoby/twh/datatips
Twh/datatips
2 parents 0cebcd9 + debc152 commit 3c7ac33

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/m/plot/applyoptions.m

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

442+
if exist(options,'datatip'),
443+
datatip = getfieldvalue(options, 'datatip');
444+
dcm = datacursormode(gcf);
445+
set(dcm, 'Enable', 'on');
446+
set(dcm, 'UpdateFcn', {@plot_datatip, datatip});
447+
end
448+
442449
%showregion
443450
if strcmpi(getfieldvalue(options,'showregion','off'),'on'),
444451
%Keep pointer of main axis

src/m/plot/plot_datatip.m

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