view scripts/plot/appearance/__clabel__.m @ 24423:1d52db450db4

Change ishandle to return true for Java objects for Matlab compatibility. Add new function isgraphics() for Matlab compatibility. Change over existing instances of ishandle to ishghandle. * NEWS: Announce changes. * scripts/plot/util/isgraphics.m: New function. * scripts/plot/util/ishandle.m: New function. * scripts/plot/util/module.mk: Add isgraphics.m and ishandle.m to build system. * plot.txi: Change documentation around ishandle. Add isgraphics DOCSTRING to manual. * graphics.cc (Fishghandle): Rename function from ishandle to ishghandle. Add seealso links in docstring. * graphics.cc: Rename all instances of is_handle to is_hghandle. * genpropdoc.m, voronoi.m, guidata.m, guihandles.m, __uiobject_split_args__.m, uibuttongroup.m, uicontrol.m, uiwait.m, waitbar.m, brighten.m, delete.m, getappdata.m, isappdata.m, rmappdata.m, setappdata.m, __clabel__.m, camlookat.m, clabel.m, legend.m, material.m, thetaticks.m, whitebg.m, camlight.m, colorbar.m, isocolors.m, isonormals.m, plotmatrix.m, plotyy.m, reducepatch.m, shrinkfaces.m, __actual_axis_position__.m, __opengl_info__.m, __plt_get_axis_arg__.m, ancestor.m, copyobj.m, findobj.m, hdl2struct.m, hgsave.m, hold.m, isaxes.m, isfigure.m, ishold.m, isprop.m, linkprop.m, newplot.m, print.m, __gnuplot_draw_axes__.m, __gnuplot_draw_figure__.m, rotate.m, saveas.m, struct2hdl.m, subplot.m: Replace instances of ishandle with ishghandle in existing code.
author Rik <rik@octave.org>
date Sun, 17 Dec 2017 07:04:31 -0800
parents 092078913d54
children 59041be1994b
line wrap: on
line source

## Copyright (C) 2008-2017 David Bateman
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {@var{h} =} __clabel__ (@var{c}, @var{v}, @var{hparent}, @var{label_spacing}, @var{z}, @var{varargin})
## Undocumented internal function.
## @end deftypefn

function h = __clabel__ (c, v, hparent, label_spacing, z, varargin)

  hax = ancestor (hparent, "axes");
  units = get (hax, "units");
  set (hax, "units", "points");
  axpos = get (hax, "position");
  set (hax, "units", units);
  lims = axis ();
  xspacing = axpos(3) / (lims(2) - lims (1));
  yspacing = axpos(4) / (lims(4) - lims (3));

  if (isscalar (hparent) && ishghandle (hparent)
      && strcmp (get (hparent, "type"), "hggroup"))
    x = get (hparent, "xdata");
    xmin = min (x(:));
    xmax = max (x(:));
    y = get (hparent, "ydata");
    ymin = min (y(:));
    ymax = max (y(:));
  else
    xmin = xmax = ymin = ymax = NaN;
    i = 1;
    while (i < length (c))
      clen = c(2,i);
      data = c(:, i+(1:clen));

      xmin = min ([xmin, data(1,:)]);
      xmax = max ([xmax, data(1,:)]);
      ymin = min ([ymin, data(2,:)]);
      ymax = max ([ymax, data(2,:)]);

      i += clen+1;
    endwhile
  endif

  ## Decode contourc output format and place labels.
  h = [];
  i = 1;
  while (i < length (c))
    clev = c(1,i);
    clen = c(2,i);

    if (! isempty (v) && ! any (v == clev))
      i += clen+1;
      continue;
    endif

    p = bsxfun (@times, c(:, i+(1:clen)), [xspacing; yspacing]);
    d = sqrt (sumsq (diff (p, 1, 2)));
    cumd = cumsum (d);
    td = cumd(end);
    ntag = ceil (td / label_spacing);

    if (all (c(:,i+1) == c(:,i+clen)))
      ## Closed contour
      ## FIXME: This spreads the tags uniformly around the contour which
      ## looks nice, but it does not respect the label_spacing attribute.
      ## Should we follow user input, which can result in two labels being
      ## quite close to each other?
      spacing = td / ntag;
      pos = spacing/2 + spacing*[0:ntag-1];
    else
      ## Open contour
      pos = zeros (1, ntag);
      pos(1) = (td - label_spacing*(ntag - 1)) / 2;
      pos(2:ntag) = pos(1) + label_spacing*[1:ntag-1];
    endif

    tlabel = sprintf ("%.5g", clev);

    for tagpos = pos

      j = find (cumd > tagpos, 1);
      if (isempty (j))
        j = clen;
      endif
      tpos = sum (c(:,i+j-1:i+j), 2) / 2;

      if (   tpos(1) != xmin && tpos(1) != xmax
          && tpos(2) != ymin && tpos(2) != ymax)
        trot = 180 / pi * atan2 (diff (c(2,i+j-1:i+j)) * yspacing,
                                 diff (c(1,i+j-1:i+j)) * xspacing);
        if (abs (trot) > 90)
          trot += 180;
        endif
        if (ischar (z))
          ht = text (tpos(1), tpos(2), clev, tlabel, "rotation", trot,
                     "horizontalalignment", "center", "userdata", clev,
                     "parent", hparent, varargin{:});
        elseif (! isempty (z))
          ht = text (tpos(1), tpos(2), z, tlabel, "rotation", trot,
                     "horizontalalignment", "center", "userdata", clev,
                     "parent", hparent, varargin{:});
        else
          ht = text (tpos(1), tpos(2), tlabel, "rotation", trot,
                     "horizontalalignment", "center", "userdata", clev,
                     "parent", hparent, varargin{:});
        endif
        h = [h; ht];
      endif
    endfor
    i += clen+1;
  endwhile

endfunction


## No test needed for internal helper function.
%!assert (1)