--- a/GnuplotGraphView.st Tue May 01 10:40:26 2018 +0200
+++ b/GnuplotGraphView.st Tue May 01 10:48:57 2018 +0200
@@ -5,7 +5,7 @@
"{ NameSpace: Smalltalk }"
ImageView subclass:#GnuplotGraphView
- instanceVariableNames:'script data title'
+ instanceVariableNames:'script data title formatHolder'
classVariableNames:''
poolDictionaries:''
category:'Views-Misc'
@@ -16,6 +16,7 @@
documentation
"
displays the graph of the data (in model) using a gnuplot script
+ Now also shown in the collection-inspector tab.
[author:]
cg
@@ -65,6 +66,17 @@
^ self defaultScriptForHistogram
!
+defaultScriptForDots
+ "a default initial gnuplot script to show a dots diagram"
+
+ ^ '
+set term %(outputFormat)
+set output "%(outputFile)"
+set title "%(title)"
+plot [-10:110] ''%(data)'' with dots
+'
+!
+
defaultScriptForHistogram
"a default initial gnuplot script to show a histogram"
@@ -74,6 +86,71 @@
set title "%(title)"
plot [-10:110] ''%(data)'' with histogram
'
+!
+
+defaultScriptForLines
+ "a default initial gnuplot script to show a line diagram"
+
+ ^ '
+set term %(outputFormat)
+set output "%(outputFile)"
+set title "%(title)"
+plot ''%(data)'' with lines
+'
+! !
+
+!GnuplotGraphView class methodsFor:'menu specs'!
+
+middleButtonMenuExtraSlice
+ "This resource specification was automatically generated
+ by the MenuEditor of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the MenuEditor may not be able to read the specification."
+
+
+ "
+ MenuEditor new openOnClass:GnuplotGraphView andSelector:#middleButtonMenuExtraSlice
+ (Menu new fromLiteralArrayEncoding:(GnuplotGraphView middleButtonMenuExtraSlice)) startUp
+ "
+
+ <resource: #menu>
+
+ ^
+ #(Menu
+ (
+ (MenuItem
+ label: '-'
+ )
+ (MenuItem
+ label: 'Format'
+ submenu:
+ (Menu
+ (
+ (MenuItem
+ label: 'Histogram'
+ choice: formatHolder
+ choiceValue: histogram
+ )
+ (MenuItem
+ label: 'Lines'
+ choice: formatHolder
+ choiceValue: lines
+ )
+ (MenuItem
+ label: 'Dots'
+ choice: formatHolder
+ choiceValue: dots
+ )
+ )
+ nil
+ nil
+ )
+ )
+ )
+ nil
+ nil
+ )
! !
!GnuplotGraphView methodsFor:'accessing'!
@@ -102,6 +179,34 @@
title := something.
! !
+!GnuplotGraphView methodsFor:'aspects'!
+
+formatHolder
+ formatHolder isNil ifTrue:[
+ formatHolder := #histogram asValue.
+ formatHolder onChangeSend:#formatChanged to:self.
+ ].
+ ^ formatHolder
+! !
+
+!GnuplotGraphView methodsFor:'defaults'!
+
+defaultScript
+ |format|
+
+ format := self formatHolder value.
+ format == #histogram ifTrue:[
+ ^ self class defaultScriptForHistogram
+ ].
+ format == #lines ifTrue:[
+ ^ self class defaultScriptForLines
+ ].
+ format == #dots ifTrue:[
+ ^ self class defaultScriptForDots
+ ].
+ ^ self class defaultScript
+! !
+
!GnuplotGraphView methodsFor:'drawing'!
generateDataFileIn:aDirectory
@@ -178,62 +283,67 @@
stdout stderr|
(scriptUsed := script) isNil ifTrue:[
- scriptUsed := self class defaultScript.
+ scriptUsed := self defaultScript.
].
command := 'gnuplot "%1"'.
argsDict := Dictionary new.
tmpDir := Filename tempDirectory.
-
- data notEmptyOrNil ifTrue:[
- dataFilename := self generateDataFileIn:tmpDir.
- ] ifFalse:[
- dataFilename := ''.
- ].
-
- outFilename := (Filename newTemporaryIn:tmpDir) withSuffix:'png'.
-
- argsDict at:'data' put:dataFilename.
- argsDict at:'dataSize' put:(data size).
- argsDict at:'outputFile' put:(outFilename pathName).
- argsDict at:'outputFormat' put:'png'.
- argsDict at:'title' put:(title ? '').
-
- expandedScript := scriptUsed bindWithArguments:argsDict.
- scriptFilename := (Filename newTemporaryIn:tmpDir).
- scriptFilename := scriptFilename asFilename withSuffix:'gnuplot'.
- scriptFilename contents:expandedScript.
-
- command := command bindWith:(scriptFilename pathName).
-
- outStream := '' writeStream.
- errorStream := '' writeStream.
-
- ok := OperatingSystem
- executeCommand:command
- inputFrom:Stdin
- outputTo:outStream
- errorTo:errorStream
- environment:nil
- inDirectory:tmpDir
- lineWise:true
- showWindow:false
- onError:[:status |
- statusCode := status code.
- ok := false.
+ [
+ data notEmptyOrNil ifTrue:[
+ dataFilename := self generateDataFileIn:tmpDir.
+ ] ifFalse:[
+ dataFilename := nil.
].
- ok ifFalse:[
- (stderr := errorStream contents) notEmptyOrNil ifTrue:[
- Transcript showCR:(stderr withColor:Color red).
+ outFilename := (Filename newTemporaryIn:tmpDir) withSuffix:'png'.
+
+ argsDict at:'data' put:(dataFilename isNil ifTrue:[''] ifFalse:[dataFilename baseName]).
+ argsDict at:'dataSize' put:(data size).
+ argsDict at:'outputFile' put:(outFilename baseName).
+ argsDict at:'outputFormat' put:'png'.
+ argsDict at:'title' put:(title ? '').
+
+ expandedScript := scriptUsed bindWithArguments:argsDict.
+ scriptFilename := (Filename newTemporaryIn:tmpDir).
+ scriptFilename := scriptFilename asFilename withSuffix:'gnuplot'.
+ scriptFilename contents:expandedScript.
+
+ command := command bindWith:(scriptFilename baseName).
+
+ outStream := '' writeStream.
+ errorStream := '' writeStream.
+
+ ok := OperatingSystem
+ executeCommand:command
+ inputFrom:Stdin
+ outputTo:outStream
+ errorTo:errorStream
+ environment:nil
+ inDirectory:tmpDir
+ lineWise:true
+ showWindow:false
+ onError:[:status |
+ statusCode := status code.
+ ok := false.
+ ].
+
+ ok ifFalse:[
+ (stderr := errorStream contents) notEmptyOrNil ifTrue:[
+ Transcript showCR:(stderr withColor:Color red).
+ ].
+ ] ifTrue:[
+ (stdout := outStream contents) notEmpty ifTrue:[
+ Transcript showCR:stdout.
+ ].
+ image := Image fromFile:outFilename.
].
+ ] ensure:[
+ dataFilename notNil ifTrue:[ dataFilename delete ].
+ outFilename notNil ifTrue:[ outFilename delete ].
+ scriptFilename notNil ifTrue:[ scriptFilename delete ].
].
- (stdout := outStream contents) notEmpty ifTrue:[
- Transcript showCR:stdout.
- ].
-
- image := Image fromFile:outFilename.
!
generateMagnifiedImage
@@ -265,6 +375,13 @@
self invalidate.
! !
+!GnuplotGraphView methodsFor:'menu actions'!
+
+formatChanged
+ image := magnifiedImage := smoothMagnifiedImage := nil.
+ self invalidate
+! !
+
!GnuplotGraphView class methodsFor:'documentation'!
version