#! ngraph

set +e

ID=${gra:viewer:id}

cd "${system::data_dir}/demo/"

new sarray name="FILE"
for demo in demo1 demo2 demo3 demo4 demo5a demo5b demo5c demo5d demo5e demo6 demo7 demo8 demo9
do
    sarray::add $demo
done

new sarray name="CAPTION"
sarray::add "Demo #_1: color(), rgb(), hsb() and marksize() FUNCTION"
sarray::add "Demo #_2: LEAST SQUARE FIT"
sarray::add "Demo #_3: AXIS DIVISION"
sarray::add "Demo #_4: MULTI GRAPH"
sarray::add "Demo #5_A: ARROW"
sarray::add "Demo #5_B: MARK"
sarray::add "Demo #5_C: TEXT"
sarray::add "Demo #5_D: CURVE"
sarray::add "Demo #5_E: AXIS"
sarray::add "Demo #_6: POLYGON PLOT"
sarray::add "Demo #_7: FUNCTION PLOT"
sarray::add 'Demo #_8: draw__rect(), draw__line() and col[]'
sarray::add 'Demo #_9: draw__rect() and draw__arc() FUNCTION'
sarray::add "_Quit demonstration"

caption="'${sarray::join="' '"}'"
caption_num="${sarray:CAPTION:num}"

del sarray:CAPTION

new dialog
dialog::title="demo"
dialog::caption="select demonstration"
dialog::select="0"

while true
do
    FILE_INDEX=`get dialog: -field radio:"$caption"`
    if [ -z "$FILE_INDEX" ]
    then
	break
    fi

    if [ "$FILE_INDEX" -ge ${sarray:FILE:num} ]
    then
	break
    fi

    demo=`get sarray:FILE -field get:$FILE_INDEX`
    for drawrable in `derive -instance draw parameter`
    do
	del ${drawrable}:0-!
    done
    gra:$ID:clear

    . ./${demo}.ngp
    ID2=${gra::id}
    if [ $ID != $ID2 ]
    then
	gra:$ID:close
	for field in top_margin left_margin zoom draw_obj decimalsign
	do
	    cpy gra:$ID2,$ID $field
	done
	gra:$ID:open
	del gra:$ID2
    fi

    menu::draw
    dialog::select=`iexpr "($FILE_INDEX + 1) \\ $caption_num"`
done

del dialog
del sarray:FILE

set -e
