File: graph.e

package info (click to toggle)
entity 0.7.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,352 kB
  • ctags: 5,272
  • sloc: ansic: 61,707; sh: 7,921; makefile: 732; perl: 399
file content (105 lines) | stat: -rwxr-xr-x 2,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env entity

<object>

  <window ondelete = "entity:quit" title = "Graph Test" 
   width = "500" height = "400">

    <object expand = "true" fill = "true" dragable="true">
      <menu name="test">
	<menuitem label="append?" onselect="print_selection"/>
      </menu>
      
      <graph name="mygraph" expand="true" fill="true" onselect="selection" 
	onbuttonpress="do_button_press">
        <graph-point name="foo1" x="1" y="30" size="10" type = "point" 
		color="#123445"/>
	<graph-point x="2" y="20" size="10" type = "point" color="#123445"/>
	<graph-point x="3" y="10.4" size="10" type = "point" color="#123445"/>
	<graph-point name="foo2" x="5" y="20" size="10" 
				type = "bar" color="#342050"/>
	<graph-point name="foo3" x="6" y="30" size="15" 
				type = "bar" color="#543090"/>
	<graph-point name="foo4" x="7" y="40" size="20" 
				type = "bar" color="#549090"/>
      </graph>
      <perl>
        <![CDATA[
	
	$value = 2.0;
	$color = 1;
	$num = .001;
	
	sub selection
	  {
	    my ($node, $x, $y, $x1, $x2) = @_;
            my $child;
	    
	    #print ("node is $node\n");
            my @children = $node->children_attrib ("selected", "true");
            foreach $child (@children)
              {
	         print "children_attrib selected $child\n";
              }
            my @children = $node->children_attrib_rx ("selected", "[tT].*");
            foreach $child (@children)
              {
	         print "children_attrib_rx selected $child\n";
              }
	    print ("selection - $x,$y to $x1,$x2\n");
	  }
	  
	sub set_graph
	  {

	    $value += 1.1;
	    
	    $color += 2;
	    if ($color > 99) {
	      $color = 0;
	    }
	    
	    $color_str = sprintf ("#2030%02d", $color);
	    
	    enode("graph-point.foo1")->attrib("y" => $value);
	    enode("graph-point.foo2")->attrib("y" => $value + 3);
	    enode("graph-point.foo3")->attrib("y" => $value + 5);
	    enode("graph-point.foo4")->attrib("y" => $value + 7);
	    
	    enode("graph-point.foo4")->attrib("color" => $color_str);

	    if ($value > 30) {
	      enode("timer.t")->attrib("interval" => "-1");
	    }
	  }
        sub do_button_press
          {
            my ($node, $bnum) = @_;
            
            print "bnum = $bnum\n";
            if (3 == $bnum)
              {
                my $menu = enode ("menu.test");
                $menu->attrib("popup" => "true") if $menu;
              }
           }
         sub print_selection
           {
             my $node = enode ("graph.mygraph");
             my @children = $node->children();
             my $child;
             foreach $child (@children)
               {
                if ($child->attrib_is_true ("selected") )
                  {
                    print "SELECTED $child\n\n";
                  }                             
              }
           }

        ]]>
      </perl>
      <timer name="t" interval = "100" action = "set_graph"/>
    </object>
  </window>
</object>