GnuplotGraphView.st
author Claus Gittinger <cg@exept.de>
Wed, 16 May 2018 12:49:32 +0200
changeset 5765 57796607f252
parent 5762 13f699b3e47c
child 5781 38948bac30f3
permissions -rw-r--r--
#REFACTORING by cg class: GnuplotGraphView changed: #generateImage (send #remove instead of #delete)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5750
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
     1
"{ Encoding: utf8 }"
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
     2
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ Package: 'stx:libwidg2' }"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
"{ NameSpace: Smalltalk }"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
ImageView subclass:#GnuplotGraphView
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
     8
	instanceVariableNames:'script data title formatHolder'
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	classVariableNames:''
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
	poolDictionaries:''
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
	category:'Views-Misc'
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
!GnuplotGraphView class methodsFor:'documentation'!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
documentation
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
    displays the graph of the data (in model) using a gnuplot script
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    19
    Now also shown in the collection-inspector tab.
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
    [author:]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
        cg
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
    [instance variables:]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
    [class variables:]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
    [see also:]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
examples
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 Notice that everything between [exBegin] and [exEnd] is extracted by the html-doc generator
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 to create nicely formatted and clickable executable examples in the generated html-doc.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 (see the browsers class-documentation menu items for more)
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 trying the widget as standAlone view:
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
                                                        [exBegin]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    GnuplotGraphView new 
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
        script:(GnuplotGraphView defaultScript);
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
        model:(ValueHolder with:(Random new next:100));
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
        open
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
                                                        [exEnd]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 embedded in another view:
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
                                                        [exBegin]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    |top v|
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    top := StandardSystemView new.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    top extent:300@300.
5755
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    53
    v := GnuplotGraphView new.  
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    54
    v data:(Random new next:100).
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    55
    v origin:0.0@0.0 corner:1.0@1.0.
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    top add:v.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    top open
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
                                                        [exEnd]
5755
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    59
 use as inspect tab:
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    60
                                                        [exBegin]
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    61
    (Random new next:100) inspect.
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
    62
                                                        [exEnd]
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
! !
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!GnuplotGraphView class methodsFor:'defaults'!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
defaultScript
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    "return a default initial gnuplot script"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    ^ self defaultScriptForHistogram
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    74
defaultScriptForDots
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    75
    "a default initial gnuplot script to show a dots diagram"
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    76
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    77
    ^ '
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
    78
set term %(outputFormat) size %(width),%(height)
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    79
set output "%(outputFile)"
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    80
set title "%(title)"
5762
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
    81
plot [-10:110] ''%(data)''
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    82
'
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    83
!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    84
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
defaultScriptForHistogram
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "a default initial gnuplot script to show a histogram"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    ^ '
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
    89
set term %(outputFormat) size %(width),%(height) 
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
set output "%(outputFile)"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
set title "%(title)"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
plot [-10:110] ''%(data)'' with histogram 
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
'
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    94
!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    95
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    96
defaultScriptForLines
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    97
    "a default initial gnuplot script to show a line diagram"
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    98
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
    99
    ^ '
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   100
set term %(outputFormat) size %(width),%(height) 
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   101
set output "%(outputFile)"
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   102
set title "%(title)"
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   103
plot ''%(data)'' with lines 
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   104
'
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   105
! !
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   106
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   107
!GnuplotGraphView class methodsFor:'menu specs'!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   108
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   109
middleButtonMenuExtraSlice
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   110
    "This resource specification was automatically generated
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   111
     by the MenuEditor of ST/X."
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   112
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   113
    "Do not manually edit this!! If it is corrupted,
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   114
     the MenuEditor may not be able to read the specification."
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   115
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   116
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   117
    "
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   118
     MenuEditor new openOnClass:GnuplotGraphView andSelector:#middleButtonMenuExtraSlice
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   119
     (Menu new fromLiteralArrayEncoding:(GnuplotGraphView middleButtonMenuExtraSlice)) startUp
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   120
    "
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   121
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   122
    <resource: #menu>
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   123
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   124
    ^ 
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   125
     #(Menu
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   126
        (
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   127
         (MenuItem
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   128
            label: '-'
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   129
          )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   130
         (MenuItem
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   131
            label: 'Format'
5762
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   132
            isVisible: hasNoScript
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   133
            submenu: 
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   134
           (Menu
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   135
              (
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   136
               (MenuItem
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   137
                  label: 'Histogram'
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   138
                  choice: formatHolder
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   139
                  choiceValue: histogram
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   140
                )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   141
               (MenuItem
5762
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   142
                  label: 'Line Graph'
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   143
                  choice: formatHolder
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   144
                  choiceValue: lines
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   145
                )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   146
               (MenuItem
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   147
                  label: 'Dots'
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   148
                  choice: formatHolder
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   149
                  choiceValue: dots
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   150
                )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   151
               )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   152
              nil
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   153
              nil
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   154
            )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   155
          )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   156
         )
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   157
        nil
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   158
        nil
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   159
      )
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
!GnuplotGraphView methodsFor:'accessing'!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   164
adjust:layoutSymbol
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   165
    image := nil.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   166
    super adjust:layoutSymbol.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   167
    self invalidate
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   168
!
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   169
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
data
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    ^ data
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
data:something
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    data := something.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
5762
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   178
hasNoScript
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   179
    ^ [ script isEmptyOrNil ]
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   180
!
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   181
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   182
hasScript
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   183
    ^ [ script notEmptyOrNil ]
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   184
!
13f699b3e47c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5759
diff changeset
   185
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   186
magnificationFactor:aNumber
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   187
    image := nil.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   188
    super magnificationFactor:aNumber.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   189
    self invalidate
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   190
!
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   191
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
script
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    ^ script
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
script:something
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    script := something.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
title
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    ^ title
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
title:something
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    title := something.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
! !
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   208
!GnuplotGraphView methodsFor:'aspects'!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   209
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   210
formatHolder
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   211
    formatHolder isNil ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   212
        formatHolder := #histogram asValue.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   213
        formatHolder onChangeSend:#formatChanged to:self.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   214
    ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   215
    ^ formatHolder
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   216
! !
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   217
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   218
!GnuplotGraphView methodsFor:'defaults'!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   219
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   220
defaultScript
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   221
    |format|
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   222
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   223
    format := self formatHolder value.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   224
    format == #histogram ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   225
        ^ self class defaultScriptForHistogram
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   226
    ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   227
    format == #lines ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   228
        ^ self class defaultScriptForLines
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   229
    ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   230
    format == #dots ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   231
        ^ self class defaultScriptForDots
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   232
    ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   233
    ^ self class defaultScript
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   234
! !
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   235
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
!GnuplotGraphView methodsFor:'drawing'!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
generateDataFileIn:aDirectory
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    "the format of data expected by gnuplot depends on the type of plot:
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
        regular plot: a number of values (each in a separate line)
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
        multiCol plots: a number of lines, each containing a row
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
     here, handle common situations;
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
     however, if the data does not match, the program should have prepared the 
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
     data into a string and present it as such.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
     Strings will be sent as-is to the file"
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    |dataFilename printRow|
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    dataFilename := (Filename newTemporaryIn:aDirectory) pathName.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    dataFilename := dataFilename asFilename withSuffix:'dat'.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    (data isString or:[data isByteArray]) ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
        dataFilename contents:data.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
        ^ dataFilename.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    data isCollection ifFalse:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
        dataFilename contents:data printString.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
        ^ dataFilename.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    printRow := 
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
        [:s :eachValueOrRow |
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
            eachValueOrRow isString ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                s nextPutAll:eachValueOrRow
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
            ] ifFalse:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
                eachValueOrRow isAssociation ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
                    eachValueOrRow key printOn:s.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
                    s space.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
                    eachValueOrRow value printOn:s.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
                ] ifFalse:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
                    eachValueOrRow isCollection ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
                        eachValueOrRow 
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
                            do:[:element | element printOn:s]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
                            separatedBy:[ s space]
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
                    ] ifFalse:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
                        eachValueOrRow printOn:s
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
                    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
                ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
            ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
            s cr.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    dataFilename writingFileDo:[:s |
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
        data isSequenceable ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
            data do:[:eachValueOrRow |
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
                printRow value:s value:eachValueOrRow.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
            ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
        ] ifFalse:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
            data keysAndValuesDo:[:eachKey :eachValueOrRow |
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
                eachKey printOn:s.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
                s space.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
                printRow value:s value:eachValueOrRow.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
            ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
        ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
    ^ dataFilename
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
generateImage
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   301
    "generates the magnifiedImage right away
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   302
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
     self new
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
        script:(GnuplotGraphView defaultScript);
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
        data:(RandomGenerator new next:50);
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
        open
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    "
5750
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   308
    |scriptUsed command tmpDir outStream errorStream statusCode ok
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
     dataFilename scriptFilename outFilename argsDict expandedScript
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
     stdout stderr|
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
5750
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   312
    (scriptUsed := script) isNil ifTrue:[
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   313
        scriptUsed := self defaultScript.
5750
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   314
    ].
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
    command := 'gnuplot "%1"'.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
    argsDict := Dictionary new.
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
    tmpDir := Filename tempDirectory.
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   320
    [
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   321
        data notEmptyOrNil ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   322
            dataFilename := self generateDataFileIn:tmpDir.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   323
        ] ifFalse:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   324
            dataFilename := nil.
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
        ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   327
        outFilename := (Filename newTemporaryIn:tmpDir) withSuffix:'png'.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   328
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   329
        argsDict at:'data' put:(dataFilename isNil ifTrue:[''] ifFalse:[dataFilename baseName]).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   330
        argsDict at:'dataSize' put:(data size).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   331
        argsDict at:'outputFile' put:(outFilename baseName).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   332
        argsDict at:'outputFormat' put:'png'.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   333
        argsDict at:'title' put:(title ? '').
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   334
        ((adjustHolder value ? '') includesString:'fit') not
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   335
        ifTrue:[
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   336
            argsDict at:'width' put:(640 * (self magnificationFactor)).
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   337
            argsDict at:'height' put:(400 * (self magnificationFactor)).
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   338
        ] ifFalse:[
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   339
            argsDict at:'width' put:self width.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   340
            argsDict at:'height' put:self height.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   341
        ].
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   342
        expandedScript := scriptUsed bindWithArguments:argsDict.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   343
        scriptFilename := (Filename newTemporaryIn:tmpDir).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   344
        scriptFilename := scriptFilename asFilename withSuffix:'gnuplot'.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   345
        scriptFilename contents:expandedScript.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   346
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   347
        command := command bindWith:(scriptFilename baseName).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   348
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   349
        outStream := '' writeStream.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   350
        errorStream := '' writeStream.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   351
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   352
        ok := OperatingSystem 
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   353
            executeCommand:command
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   354
            inputFrom:Stdin
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   355
            outputTo:outStream
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   356
            errorTo:errorStream
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   357
            environment:nil
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   358
            inDirectory:tmpDir
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   359
            lineWise:true
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   360
            showWindow:false
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   361
            onError:[:status | 
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   362
                statusCode := status code.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   363
                ok := false.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   364
            ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   365
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   366
        ok ifFalse:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   367
            (stderr := errorStream contents) notEmptyOrNil ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   368
                Transcript showCR:(stderr withColor:Color red).
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   369
            ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   370
        ] ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   371
            (stdout := outStream contents) notEmpty ifTrue:[
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   372
                Transcript showCR:stdout.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   373
            ].
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   374
            image := Image fromFile:outFilename.
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
        ].
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   376
    ] ensure:[
5765
57796607f252 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
   377
        dataFilename notNil ifTrue:[ dataFilename remove ]. 
57796607f252 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
   378
        outFilename notNil ifTrue:[ outFilename remove ]. 
57796607f252 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
   379
        scriptFilename notNil ifTrue:[ scriptFilename remove ]. 
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
    ].
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
generateMagnifiedImage
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    image isNil ifTrue:[
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
        self generateImage  
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
    ].
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   387
    magnifiedImage := smoothMagnifiedImage := image.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   388
"/    super generateMagnifiedImage.
5750
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   389
!
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   390
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   391
redrawX:x y:y width:w height:h
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   392
    (OperatingSystem canExecuteCommand:'gnuplot') ifFalse:[
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   393
        self clearRectangleX:x y:y width:w height:h.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   394
        self showWarning.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   395
        ^ self.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   396
    ].
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   397
    super redrawX:x y:y width:w height:h.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   398
!
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   399
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   400
showWarning
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   401
    |infoMsg wString|
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   402
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   403
    infoMsg := resources string:'No gnuplot command found'.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   404
    wString := gc font widthOf:infoMsg.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   405
    gc displayString:infoMsg x:(self width - wString) // 2 y:(self height // 2).
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   406
!
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   407
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   408
sizeChanged:how
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   409
    super sizeChanged:how.
78ef41988e39 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
   410
    self invalidate.
5759
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   411
!
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   412
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   413
updateImageAfterSizeChange
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   414
    image := nil.
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   415
    super updateImageAfterSizeChange
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   416
! !
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   417
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   418
!GnuplotGraphView methodsFor:'menu'!
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   419
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   420
smoothFitBigMenuItemVisible
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   421
    ^ false
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   422
!
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   423
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   424
smoothingMenuItemVisible
08dbdd438639 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5755
diff changeset
   425
    ^ false
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
! !
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
5754
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   428
!GnuplotGraphView methodsFor:'menu actions'!
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   429
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   430
formatChanged
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   431
    image := magnifiedImage := smoothMagnifiedImage := nil.
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   432
    self invalidate
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   433
! !
e2ff55aff529 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5750
diff changeset
   434
5755
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   435
!GnuplotGraphView methodsFor:'mvc'!
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   436
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   437
updateFromModel
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   438
    "the model changes, set my image"
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   439
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   440
    self data:model value.
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   441
! !
ab974e8d9ee5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5754
diff changeset
   442
5742
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
!GnuplotGraphView class methodsFor:'documentation'!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
version
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
    ^ '$Header$'
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
!
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
version_CVS
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    ^ '$Header$'
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
! !
5a4a11ee0b1f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452