]> gitweb.factorcode.org Git - factor.git/commitdiff
charts: scale the chart to the gadget size
authorAlexander Iljin <ajsoft@yandex.ru>
Fri, 20 Jan 2017 12:43:38 +0000 (15:43 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 17 Apr 2017 20:54:51 +0000 (13:54 -0700)
charts.factor

index 306f8ab85528e2682dfbfeed2fd0a05be5f8869b..b6486f1816953c8ad2c7ead39e7bec946bc9a8a3 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2016-2017 Alexander Ilin.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel ui.gadgets ;
+USING: accessors kernel ui.gadgets ;
 IN: charts
 
 TUPLE: chart < gadget ;
@@ -11,13 +11,12 @@ M: chart pref-dim* drop { 300 300 } ;
 : chart-axes ( chart -- seq )
     drop { { 0 300 } { 0 300 } } ;
 
-! Return the width and height of the visible area, in pixels.
-: chart-dim ( chart -- seq )
-    drop { 300 300 } ;
+! Return the { width height } of the visible area, in pixels.
+: chart-dim ( chart -- seq ) dim>> ;
 
 ! There are several things to do to present data on the screen.
 ! Map the data coordinates to the screen coordinates.
 ! Cut off data outside the presentation window. When cutting off vertically, split the line into segments and add new points if necessary. Return an array of line segments.
 ! Remove redundant points from the drawing pass.
 
-! chart new line new COLOR: blue >>color { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } } >>data add-gadget gadget.
+! chart new line new COLOR: blue >>color { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } } >>data add-gadget "Chart" open-window