function updateDataCursor(this,hDataCursor,target)

% Specify datatip position based on mouse click

% Copyright 2004 The MathWorks, Inc.

hpatch = [];
is_horz = strcmpi(get(this,'Horizontal'),'on');

%TBD check all bar peers so mouse dragging doesn't stay 
% on the same patch
%hpeers = get(this,'BarPeers');

hpatch = get(this,'children');
[p,v,ind,pfactor,barface,faceiout] = vertexpicker(hpatch,target,'-force');

% Specify bar face if we are mouse dragging off the bar plot
if isempty(barface)
   faces = get(hpatch,'Faces');
   verts = get(hpatch,'Vertices');
   [m,n] = find(faces==ind);
   if ~isempty(m)
      barface = verts(faces(m(1),:),:)';
   end
end

% Specify cursor position
if ~isempty(barface)
   x_max = max(barface(1,:));
   x_min = min(barface(1,:));
   y_max = max(barface(2,:));
   y_min = min(barface(2,:));
   %ToDo: Check orientation
   if is_horz
       set(hDataCursor,'Position',[x_max, (y_min+y_max)/2, 0]);
   else
       set(hDataCursor,'Position',[(x_max+x_min)/2, y_max, 0]);
   end
   % Specify index into bar series
   ind = floor((ind-1)/5)+1; % 4 patch vertices for each bar
   len = length(this.xdata);
   if ind>len, 
       ind = len; 
   elseif ind==0
       ind = 1;
   end
   set(hDataCursor,'DataIndex',ind);

end