diff --git a/extra/ui/gadgets/plot/plot.factor b/extra/ui/gadgets/plot/plot.factor index 0a6f22f080..cf48c5ab9d 100644 --- a/extra/ui/gadgets/plot/plot.factor +++ b/extra/ui/gadgets/plot/plot.factor @@ -61,4 +61,77 @@ M: plot draw-slate ( plot -- plot ) ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : add-function ( plot function -- plot ) - over functions>> swap suffix >>functions ; \ No newline at end of file + over functions>> swap suffix >>functions ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: x-span ( plot -- span ) [ x-max>> ] [ x-min>> ] bi - ; +: y-span ( plot -- span ) [ y-max>> ] [ y-min>> ] bi - ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +USING: ui.gestures ui.gadgets ; + +: left ( plot -- plot ) + dup [ x-min>> ] [ x-span 1/10 * ] bi - >>x-min + dup [ x-max>> ] [ x-span 1/10 * ] bi - >>x-max + dup relayout-1 ; + +: right ( plot -- plot ) + dup [ x-min>> ] [ x-span 1/10 * ] bi + >>x-min + dup [ x-max>> ] [ x-span 1/10 * ] bi + >>x-max + dup relayout-1 ; + +: down ( plot -- plot ) + dup [ y-min>> ] [ y-span 1/10 * ] bi - >>y-min + dup [ y-max>> ] [ y-span 1/10 * ] bi - >>y-max + dup relayout-1 ; + +: up ( plot -- plot ) + dup [ y-min>> ] [ y-span 1/10 * ] bi + >>y-min + dup [ y-max>> ] [ y-span 1/10 * ] bi + >>y-max + dup relayout-1 ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: zoom-in-horizontal ( plot -- plot ) + dup [ x-min>> ] [ x-span 1/10 * ] bi + >>x-min + dup [ x-max>> ] [ x-span 1/10 * ] bi - >>x-max ; + +: zoom-in-vertical ( plot -- plot ) + dup [ y-min>> ] [ y-span 1/10 * ] bi + >>y-min + dup [ y-max>> ] [ y-span 1/10 * ] bi - >>y-max ; + +: zoom-in ( plot -- plot ) + zoom-in-horizontal + zoom-in-vertical + dup relayout-1 ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: zoom-out-horizontal ( plot -- plot ) + dup [ x-min>> ] [ x-span 1/10 * ] bi - >>x-min + dup [ x-max>> ] [ x-span 1/10 * ] bi + >>x-max ; + +: zoom-out-vertical ( plot -- plot ) + dup [ y-min>> ] [ y-span 1/10 * ] bi - >>y-min + dup [ y-max>> ] [ y-span 1/10 * ] bi + >>y-max ; + +: zoom-out ( plot -- plot ) + zoom-out-horizontal + zoom-out-vertical + dup relayout-1 ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +plot + H{ + { T{ mouse-enter } [ request-focus ] } + { T{ key-down f f "LEFT" } [ left drop ] } + { T{ key-down f f "RIGHT" } [ right drop ] } + { T{ key-down f f "DOWN" } [ down drop ] } + { T{ key-down f f "UP" } [ up drop ] } + { T{ key-down f f "a" } [ zoom-in drop ] } + { T{ key-down f f "z" } [ zoom-out drop ] } + } +set-gestures \ No newline at end of file