#! ngraph
# legend.nsc written by S. ISHIZAKA. 1997/12
#
# This script generates a legend box.
#
# Please edit the following X, Y, and WIDTH variables as you like.
#
# Description: _Legend...,automatic legend generator,

X=5000      # top-left of the legend to be inserted.
Y=5000      # top-left of the legend to be inserted.
WIDTH=2000  # width of "type" field.

if [ `object data -instance` != 0 ]
then
    DATALIST=${system:0:temp_file}
    object data -instance > "$DATALIST"
    get data:0-! -id -field -escape source file array id hidden x y type mark_type mark_size line_width line_style R G B R2 G2 B2 math_x math_y >> "$DATALIST"
    if [ `get menu -field configuration:use_dark_theme` = "true" ]
    then
	DARK_THEME="-d"
    else
	DARK_THEME=""
    fi
    SCRIPT=${system:0:temp_file}
    "${NGRAPHLIB}/legend" $DARK_THEME -x ${X} -y ${Y} -w ${WIDTH} "$DATALIST" "$SCRIPT"
    if [ -s "$SCRIPT" ];
    then
	new shell
	shell::shell "$SCRIPT"
	del shell
	gra::clear
	gra::draw
	gra::flush
    fi
    system:0:unlink_temp_file "$DATALIST"
    system:0:unlink_temp_file "$SCRIPT"
else
    new dialog
    dialog::beep
    dialog::message "No data file."
    del dialog
fi
