function envelope_scatter_plot( envelopes, reverse_flag, point_style, row_label, col_label, title_str );
%
% ENVELOPE_SCATTER_PLOT  Make a scatter plot of the m and n values of the given envelopes.
%
% row_label is the label for the rows, col_label is the label for the columns, 
% and title_str is the title string. 
%
% The reverse_flag flips the roles of the rows and columns. This is useful since, if the number of rows is
% less than the number of columns, it is more efficient to transform the matrix and then find the lattice
% or boundary. 
%
% The point_style determines how the points are filled. Options are 'plain', i.e., no fill, 'density', 
% the fraction of 1's, and 'tightness', m/mm * n/nn. 
%
% envelope_scatter_plot( envelopes, reverse_flag, point_style, row_label, col_label, title_str );

% Copyright © Regents of the University of Minnesota. All rights reserved.

% Handle missing labels and title
if nargin < 6
    title_str = 'Support Envelopes';
end;
if nargin < 5
    col_label = '\bf n \rm( min items)';
end;
if nargin < 4 
    row_label = '\bf m \rm(min transactions)';
end;

% Handle missing reverse_flag and density flag
if nargin < 3
    point_style = 'density';
end;
if nargin < 2
    reverse_flag = 0;
end;

% Compute either the density or the tightness of the envelope
s = ones( 1, length( envelopes ));
if strcmp( point_style, 'density' ) == 1
    s = [envelopes(:).density];
elseif strcmp( point_style, 'tightness' ) == 1
    s = [envelopes(:).tightness];
end
    
% Plot the figure
figure;
if reverse_flag
    scatter( [envelopes(:).m], -[envelopes(:).n], 30, s, 'filled'  );
else
    scatter( [envelopes(:).n], -[envelopes(:).m], 30, s, 'filled'  );
end
set( gcf, 'color', 'white' );
set( gca, 'fontsize', 14 );
set( gca, 'yticklabel', -get( gca, 'ytick' ));
ylabel( row_label, 'fontsize', 14 );
xlabel( col_label, 'fontsize', 14 );
title( title_str, 'fontsize', 14 );
grid;
hold on;scatter(1,-1,1, 0);scatter(1,-1,1, 1);hold off;

% Create the colorbar
if ~strcmp( point_style, 'plain' );
    h = colorbar;
    axes(h);
    xlabel( 'Density', 'fontsize', 12);
end
