Skip to content

Commit

Permalink
Merge pull request #30 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
mn
  • Loading branch information
stevenndungu authored Nov 7, 2016
2 parents 89fb022 + f2705e2 commit b9f087c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 44 deletions.
10 changes: 5 additions & 5 deletions instat/UcrGeomListWithAes.vb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Public Class UcrGeomListWithParameters
chkApplyOnAllLayers.Checked = bApplyAesGlobally
chkIgnoreGlobalAes.Checked = bIgnoreGlobalAes 'Task: check if this launches checkchanged and accordingly delete SetAes below.

bCurrentFixAes = bFixAes 'Warning/Question/Task: this is not flexible enough. Some of the aesthetics are set in the options. They cannot be editted on the main, however when coming back to options these are fixed and so cannot be editted anywhere anymore. Would need to be able to choose which aesthetics among a Layer should be fixed maybe.
'SetAes needs to be called after the IgnoreGlobalAes has been setup as it determines whether the global aes are written in the rceivers or not.
bCurrentFixAes = bFixAes
SetAes(bCurrentFixAes)
'Warning: SetAes is called three times when a layer is created... one in the load, one in the setup ... (and one in the ignoreGAes check changed ?)
End Sub
Expand All @@ -115,18 +115,18 @@ Public Class UcrGeomListWithParameters
If Not chkIgnoreGlobalAes.Checked Then
For Each clsParam In clsGgplotAesFunction.clsParameters
If clsParam.strArgumentName = lstCurrArguments(i) Then
'For some geoms like BoxPlot, when the x aes is not filled, ggplot R syntax requires to set x="". This x="" might be copied into the global aes if the ApplyOnAllLayers is set to true for a BoxPlot Layer. This might be copied from the GgplotAesFunction parameters into the aes receivers by error in subsequent layers.
If Not (clsParam.strArgumentName = "x" AndAlso clsParam.strArgumentValue = Chr(34) & Chr(34)) Then
'For some geoms like LinePlot, when the x or y aes is not filled, ggplot R syntax requires to set x="". This x="" might be copied into the global aes if the ApplyOnAllLayers is set to true for a BoxPlot Layer. This might be copied from the GgplotAesFunction parameters into the aes receivers by error in subsequent layers.
If Not ((clsParam.strArgumentName = "x" OrElse clsParam.strArgumentName = "y") AndAlso clsParam.strArgumentValue = Chr(34) & Chr(34)) Then
lstAesParameterUcr(i).Add(clsParam.strArgumentValue)
lstAesParameterUcr(i).Enabled = Not bFixAes
lstAesParameterUcr(i).Enabled = Not bFixAes 'Warning/Question/Task: this is not flexible enough. Some of the aesthetics are set in the options. They cannot be editted on the main, however when coming back to options these are fixed and so cannot be editted anywhere anymore. Would need to be able to choose which aesthetics among a Layer should be fixed maybe.
Exit For
End If
End If
Next
End If
For Each clsParam In clsGeomAesFunction.clsParameters
If clsParam.strArgumentName = lstCurrArguments(i) Then
If Not (clsParam.strArgumentName = "x" AndAlso clsParam.strArgumentValue = Chr(34) & Chr(34)) Then 'As before, check that x is not mapped to "" before putting in receivers.
If Not ((clsParam.strArgumentName = "x" OrElse clsParam.strArgumentName = "y") AndAlso clsParam.strArgumentValue = Chr(34) & Chr(34)) Then 'As before, check that x is not mapped to "" before putting in receivers.
lstAesParameterUcr(i).Add(clsParam.strArgumentValue)
lstAesParameterUcr(i).Enabled = True
Exit For
Expand Down
2 changes: 1 addition & 1 deletion instat/dlgBarAndPieChart.vb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Public Class dlgBarAndPieChart
sdgLayerOptions.ShowDialog()
For Each clsParam In clsRaesFunction.clsParameters
If clsParam.strArgumentName = "x" Then
If clsParam.strArgumentValue = "" Then
If clsParam.strArgumentValue = Chr(34) & Chr(34) Then
ucrFactorReceiver.Clear()
Else
ucrFactorReceiver.Add(clsParam.strArgumentValue)
Expand Down
95 changes: 93 additions & 2 deletions instat/dlgCompareModels.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports instat.Translations
Imports RDotNet
Public Class dlgCompareModels
Public strOutput As String
Public clsPlotDist As New RFunction
Public bFirstLoad As Boolean = True
Private Sub dlgCompareModels_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
Expand All @@ -28,15 +31,25 @@ Public Class dlgCompareModels
TestOKEnabled()
End Sub
Private Sub InitialiseDialog()

clsPlotDist.SetRCommand("plotDist")
ucrBase.clsRsyntax.SetFunction("grid.arrange")
End Sub

Private Sub TestOKEnabled()
If nudXlimMax.Value > nudXlimMin.Value AndAlso nudYlimMax.Value > nudYlimMin.Value Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If

End Sub

Private Sub SetDefaults()

rdoSingle.Checked = True
rdoDensity.Checked = True
nudNumberofColumns.Enabled = False
lblNumberofColumns.Enabled = False
rdoCombine.Enabled = False
End Sub

Private Sub ReopenDialog()
Expand All @@ -47,4 +60,82 @@ Public Class dlgCompareModels
SetDefaults()
TestOKEnabled()
End Sub

Private Sub ucrDistributionForCompareModels_ParameterChanged() Handles ucrDistributionForCompareModels.ParameterChanged
distParameters()
End Sub

Private Sub distParameters()
clsPlotDist.ClearParameters()
clsPlotDist.AddParameter("dist", Chr(34) & ucrDistributionForCompareModels.clsCurrDistribution.strRName & Chr(34))
For Each clstempparam In ucrDistributionForCompareModels.clsCurrRFunction.clsParameters
clsPlotDist.AddParameter(clstempparam.Clone())
Next
End Sub

Private Sub cmdAddNewDistributions_Click(sender As Object, e As EventArgs) Handles cmdAddNewDistributions.Click
sdgAddNewDistribution.ShowDialog()
End Sub

Private Sub nudXlimMin_ValueChanged(sender As Object, e As EventArgs) Handles nudXlimMin.ValueChanged, nudYlimMin.ValueChanged, nudNumberofColumns.ValueChanged, nudXlimMax.ValueChanged, nudYlimMax.ValueChanged
XLimits()
Ylimits()
TestOKEnabled()
End Sub

Private Sub grpPlotOptions_CheckedChanged(sender As Object, e As EventArgs) Handles rdoCDF.CheckedChanged, rdoDensity.CheckedChanged, rdoHistogram.CheckedChanged, rdoqq.CheckedChanged
kindParameters()
End Sub

Private Sub Ylimits()
If nudYlimMax.Value > nudYlimMin.Value Then
If nudYlimMax.Text <> "" AndAlso nudYlimMin.Text <> "" Then
clsPlotDist.AddParameter("ylim", "c(" & nudYlimMin.Text & "," & nudYlimMax.Text & ")")
Else
clsPlotDist.RemoveParameterByName("ylim")
End If
clsPlotDist.RemoveParameterByName("ylim")
End If
End Sub
Private Sub XLimits()
If nudXlimMax.Value > nudXlimMin.Value Then
If nudXlimMax.Text <> "" AndAlso nudXlimMin.Text <> "" Then
clsPlotDist.AddParameter("xlim", "c(" & nudXlimMin.Text & "," & nudXlimMax.Text & ")")

Else
clsPlotDist.RemoveParameterByName("xlim")
End If
Else
clsPlotDist.RemoveParameterByName("xlim")
End If

End Sub

Private Sub kindParameters()
If rdoqq.Checked Then
clsPlotDist.AddParameter("kind", Chr(34) & "qq" & Chr(34))
ElseIf rdoHistogram.Checked Then
clsPlotDist.AddParameter("kind", Chr(34) & "histogram" & Chr(34))
ElseIf rdoCDF.Checked Then
clsPlotDist.AddParameter("kind", Chr(34) & "cdf" & Chr(34))
Else
clsPlotDist.AddParameter("kind", Chr(34) & "density" & Chr(34))
End If

End Sub

Private Sub plotgraphspar()
If rdoSingle.Checked Then
cmdAddNewDistributions.Enabled = False
ucrBase.clsRsyntax.AddParameter("x", clsPlotDist.ToScript)
ucrBase.clsRsyntax.AddParameter("ncol", 1)
ElseIf rdoCombine.Checked Then
cmdAddNewDistributions.Enabled = True
nudNumberofColumns.Enabled = True
lblNumberofColumns.Enabled = True
End If
End Sub
Private Sub grpPlotGraphs_CheckedChanged(sender As Object, e As EventArgs) Handles rdoCombine.CheckedChanged, rdoSingle.CheckedChanged
plotgraphspar()
End Sub
End Class
85 changes: 53 additions & 32 deletions instat/dlgPlot.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ Public Class dlgPlot
TestOkEnabled()
End Sub

Private Sub SetDefaults()
clsRaesFunction.ClearParameters()
clsRgeom_lineplotFunction.ClearParameters()
chkPoints.Checked = False
' ucrLinePlotSelector.Focus()
ucrSaveLinePlot.strPrefix = "Line"
ucrVariablesAsFactorForLinePlot.SetMeAsReceiver()
ucrLinePlotSelector.Reset()
ucrVariablesAsFactorForLinePlot.ResetControl()
ucrSaveLinePlot.Reset()
sdgPlots.Reset()
TempOptionsDisabledInMultipleVariablesCase()
TestOkEnabled()
End Sub

Private Sub InitialiseDialog()
ucrBase.clsRsyntax.SetOperation("+")
clsRggplotFunction.SetRCommand("ggplot")
Expand Down Expand Up @@ -82,10 +67,44 @@ Public Class dlgPlot


End Sub
Private Sub SetDefaults()
clsRaesFunction.ClearParameters()
clsRgeom_lineplotFunction.ClearParameters()
chkPoints.Checked = False
' ucrLinePlotSelector.Focus()
ucrSaveLinePlot.strPrefix = "Line"
ucrVariablesAsFactorForLinePlot.SetMeAsReceiver()
ucrLinePlotSelector.Reset()
ucrVariablesAsFactorForLinePlot.ResetControl()
ucrSaveLinePlot.Reset()
sdgPlots.Reset()
SetXParameter()
SetYParameter()
TempOptionsDisabledInMultipleVariablesCase()
TestOkEnabled()
End Sub



Private Sub SetXParameter()
If Not ucrReceiverX.IsEmpty Then
clsRaesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False))
ucrFactorOptionalReceiver.SetMeAsReceiver()
Else
clsRaesFunction.AddParameter("x", Chr(34) & Chr(34))
End If
End Sub

Private Sub SetYParameter()
If Not ucrVariablesAsFactorForLinePlot.IsEmpty Then
clsRaesFunction.AddParameter("y", ucrVariablesAsFactorForLinePlot.GetVariableNames(False))
Else
clsRaesFunction.AddParameter("y", Chr(34) & Chr(34))
End If
End Sub
Private Sub TestOkEnabled()
'Both x and y aesthetics are mandatory for geom_line. However, when not filled they will be automatically populated by "".
If (ucrReceiverX.IsEmpty() OrElse ucrVariablesAsFactorForLinePlot.IsEmpty()) OrElse (ucrSaveLinePlot.chkSaveGraph.Checked AndAlso ucrSaveLinePlot.ucrInputGraphName.IsEmpty) Then
If (ucrSaveLinePlot.chkSaveGraph.Checked AndAlso ucrSaveLinePlot.ucrInputGraphName.IsEmpty) Then
ucrBase.OKEnabled(False)
Else
ucrBase.OKEnabled(True)
Expand All @@ -97,13 +116,7 @@ Public Class dlgPlot
End Sub

Private Sub ucrReceiverX_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverX.SelectionChanged

If ucrReceiverX.IsEmpty() = False Then
clsRaesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False))
ucrFactorOptionalReceiver.SetMeAsReceiver()
Else
clsRaesFunction.RemoveParameterByName("x")
End If
SetXParameter()
TestOkEnabled()
End Sub

Expand Down Expand Up @@ -134,11 +147,7 @@ Public Class dlgPlot
End Sub

Private Sub UcrVariablesAsFactor_SelectionChanged() Handles ucrVariablesAsFactorForLinePlot.SelectionChanged
If Not ucrVariablesAsFactorForLinePlot.IsEmpty() Then
clsRaesFunction.AddParameter("y", ucrVariablesAsFactorForLinePlot.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName("y")
End If
SetYParameter()
TempOptionsDisabledInMultipleVariablesCase()
TestOkEnabled()
End Sub
Expand All @@ -164,12 +173,24 @@ Public Class dlgPlot
Private Sub cmdLineOptions_Click(sender As Object, e As EventArgs) Handles cmdLineOptions.Click
sdgLayerOptions.SetupLayer(clsTempGgPlot:=clsRggplotFunction, clsTempGeomFunc:=clsRgeom_lineplotFunction, clsTempAesFunc:=clsRaesFunction, bFixAes:=True, bFixGeom:=True, strDataframe:=ucrLinePlotSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, bApplyAesGlobally:=True, bIgnoreGlobalAes:=False)
sdgLayerOptions.ShowDialog()
'Coming from the sdgLayerOptions, clsRaesFunction and others has been modified. One then needs to display these modifications on the dlgScatteredPlot.

'The aesthetics parameters on the main dialog are repopulated as required.
For Each clsParam In clsRaesFunction.clsParameters
If clsParam.strArgumentName = "y" AndAlso (clsParam.strArgumentValue <> "value" OrElse ucrVariablesAsFactorForLinePlot.bSingleVariable) Then
ucrVariablesAsFactorForLinePlot.Add(clsParam.strArgumentValue)
ElseIf clsParam.strArgumentName = "x" Then
ucrReceiverX.Add(clsParam.strArgumentValue)
If clsParam.strArgumentName = "x" Then
If clsParam.strArgumentValue = Chr(34) & Chr(34) Then
ucrReceiverX.Clear()
Else
ucrReceiverX.Add(clsParam.strArgumentValue)
End If
'In the y case, the vlue stored in the clsReasFunction in the multiplevariables case is "value", however that one shouldn't be written in the multiple variables receiver (otherwise it would stack all variables and the stack ("value") itself!).
'Warning: what if someone used the name value for one of it's variables independently from the multiple variables method ? Here if the receiver is actually in single mode, the variable "value" will still be given back, which throws the problem back to the creation of "value" in the multiple receiver case.
ElseIf clsParam.strArgumentName = "y" AndAlso (clsParam.strArgumentValue <> "value" OrElse ucrVariablesAsFactorForLinePlot.bSingleVariable) Then
'Still might be in the case of bSingleVariable with mapping y="".
If clsParam.strArgumentValue = (Chr(34) & Chr(34)) Then
ucrVariablesAsFactorForLinePlot.Clear()
Else ucrVariablesAsFactorForLinePlot.Add(clsParam.strArgumentValue)
End If
ElseIf clsParam.strArgumentName = "colour" Then
ucrFactorOptionalReceiver.Add(clsParam.strArgumentValue)
End If
Expand Down
2 changes: 1 addition & 1 deletion instat/dlgScatterPlot.vb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Public Class dlgScatterPlot
'Warning: what if someone used the name value for one of it's variables independently from the multiple variables method ? Here if the receiver is actually in single mode, the variable "value" will still be given back, which throws the problem back to the creation of "value" in the multiple receiver case.
ElseIf clsParam.strArgumentName = "y" AndAlso (clsParam.strArgumentValue <> "value" OrElse ucrVariablesAsFactorForScatter.bSingleVariable) Then
'Still might be in the case of bSingleVariable with mapping y="".
If clsParam.strArgumentValue <> (Chr(34) & Chr(34)) Then
If clsParam.strArgumentValue = (Chr(34) & Chr(34)) Then
ucrVariablesAsFactorForScatter.Clear()
Else ucrVariablesAsFactorForScatter.Add(clsParam.strArgumentValue)
End If
Expand Down
13 changes: 13 additions & 0 deletions instat/sdgAddNewDistribution.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Imports instat.Translations
Public Class sdgAddNewDistribution
Public bFirstLoad As Boolean = True
Public clsCompareDist As New RFunction
Private Sub sdgAddNewDistribution_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
InitialiseDialog()
Expand All @@ -33,4 +34,16 @@ Public Class sdgAddNewDistribution

End Sub

Private Sub ucrNewDistributions_ParameterChanged() Handles ucrNewDistributions.ParameterChanged
newDist()
End Sub

Private Sub newDist()
clsCompareDist.ClearParameters()
clsCompareDist.AddParameter("dist", Chr(34) & ucrNewDistributions.clsCurrDistribution.strRName & Chr(34))

For Each clstempparam In ucrNewDistributions.clsCurrRFunction.clsParameters
clsCompareDist.AddParameter(clstempparam.Clone())
Next
End Sub
End Class
3 changes: 2 additions & 1 deletion instat/sdgLayerOptions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Public Class sdgLayerOptions
End If
End If
If clsGeomFunction.strRCommand = "geom_bar" OrElse clsGeomFunction.strRCommand = "geom_density" OrElse clsGeomFunction.strRCommand = "geom_freqpoly" Then
'Warning: this is not working quite ok yet. Got some bad behaviour when "" comes from global aes, but is overwritten I think. Will tidy this up when introducing partially mandatory aesthetics method.
If (clsAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "y") <> -1 AndAlso ((clsGeomFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "inherit.aes") = -1) OrElse (clsGeomFunction.GetParameter("inherit.aes").strArgumentValue = "TRUE")) OrElse (ucrGeomWithAes.clsGeomAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "y") <> -1)) AndAlso (clsGeomFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "stat") = -1) Then
clsGeomFunction.AddParameter("stat", Chr(34) & "identity" & Chr(34))
End If
Expand All @@ -119,7 +120,7 @@ Public Class sdgLayerOptions
If clsAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "x") = -1 AndAlso ucrGeomWithAes.clsGeomAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "x") = -1 Then
clsAesFunction.AddParameter("x", Chr(34) & Chr(34))
End If
ElseIf clsGeomFunction.strRCommand = "geom_point" Then
ElseIf clsGeomFunction.strRCommand = "geom_point" OrElse clsGeomFunction.strRCommand = "geom_line" Then
If clsAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "x") = -1 AndAlso ucrGeomWithAes.clsGeomAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "x") = -1 Then
clsAesFunction.AddParameter("x", Chr(34) & Chr(34))
ElseIf clsAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "y") = -1 AndAlso ucrGeomWithAes.clsGeomAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "y") = -1 Then
Expand Down
5 changes: 3 additions & 2 deletions instat/ucrGeom.vb
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,9 @@ Public Class ucrGeom

clsgeom_line.strGeomName = "geom_line"
'mandatory
clsgeom_line.AddAesParameter("x", strIncludedDataTypes:={"factor", "numeric"}, bIsMandatory:=True)
clsgeom_line.AddAesParameter("y", strIncludedDataTypes:={"factor", "numeric"}, bIsMandatory:=True)
'x and y are mandatory, but these are autofilled by "" when no variable is mapped. "Partially mandatory"
clsgeom_line.AddAesParameter("x", strIncludedDataTypes:={"factor", "numeric"})
clsgeom_line.AddAesParameter("y", strIncludedDataTypes:={"factor", "numeric"})
'optional
clsgeom_line.AddAesParameter("alpha", strIncludedDataTypes:={"numeric", "factor"})
clsgeom_line.AddAesParameter("colour", strIncludedDataTypes:={"numeric", "factor"})
Expand Down

0 comments on commit b9f087c

Please sign in to comment.