function figure_graph_color(adj,vertices, f)
%
% figure_graph_color(adj,vertices, f)
% 
% it colors a graph (adj matrix) with given value f.
% 
% adj     : adjacency matrix consisting of 0 and 1 indentifying which point
%           is connected to which point.
% vertices: node coordinates in a matrix form. For 3D points, p x 3. For 2D points p x 2
% f       : function value on a node 
%
% 
%
% (c) Moo K. Chung 
%     mkchung@wisc.edu    http://www.stat.wisc.edu/~mchung
%     Univeristy of Wisconsin
%
% 2009 October 12: Created
% 2010 July 10   :  A new argument edgecolor is introduced. 
% 2017 March 27  : Codes cleaned up for distribution.

% uncomment to draw edges. 

n_vertices = size(vertices,1);

if isempty(f)
    f=1*ones(n_vertices,1);
end
    
set(gcf,'Color','white','InvertHardcopy','off');

if n_vertices==2 %2D case
    hold on;
    %scatter(vertices(:,1),vertices(:,2), 50, f,'filled')
  
    for i=1:size(vertices,1)
        hold on;
        %     scatter3(vertices(i,1),vertices(i,2),vertices(i,3), degree, degree) %'.r');
        % uncomment line below to remove node indexing in figure
        %text(vertices(i,1)+0.5,vertices(i,2)+0.5,vertices(i,3)+0.5,num2str(i),'Color','k');
    end;

    k=1;
    for i=1:n_vertices
        for j=1:n_vertices
            if adj(i,j)==1
                hold on;
                %pause;

                plot(vertices([i j],1),vertices([i j],2),'-c','LineWidth',1, 'Color',[.5 .5 .5]);
                %axis equal
                % uncomment to get a movie
                %M(k) = getframe;
                %k=k+1;
            end;
        end;
    end;
    
   %print('-dtiff', '-r300',strcat('rips-end.tif'))

    hold on;

    % 4th argument 10*f is the radius of a ball we are drawing. this is not the
    % actual radius of the ball in mm but rather MATLAB convention.
    % The size of balls are proportional to the color scheme.
  


else %3D case
    %k=1;
    for i=1:n_vertices
        for j=1:n_vertices
            if adj(i,j)==1
                hold on;
                %pause;

                plot3(vertices([i j],1),vertices([i j],2),vertices([i j],3),'-c','LineWidth',1.5, 'Color',[.5 .5 .5]);
                %axis equal
                % uncomment to get a movie
                %M(k) = getframe;
                %k=k+1;
            end;
        end;
    end;
    hold on;

    % 4th argument 10*f is the radius of a ball we are drawing. this is not the
    % actual radius of the ball in mm but rather MATLAB convention.
    % The size of balls are proportional to the color scheme.
    
    scatter3(vertices(:,1),vertices(:,2),vertices(:,3), 50*f, f,'filled')


    %for i=1:n_vertices
    %    hold on;
        %   scatter3(vertices(i,1),vertices(i,2),vertices(i,3), degree, degree) %'.r');

        % uncomment line below to remove node indexing in figure
        %text(vertices(i,1)+0.5,vertices(i,2)+0.5,vertices(i,3)+0.5,num2str(i),'Color','k');
    %end;


end;








