Skip to content

Commit

Permalink
Merge pull request #224 from IDEMSInternational/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Vitalis95 authored Mar 4, 2024
2 parents 7308ecf + 7a9c114 commit 242dea5
Show file tree
Hide file tree
Showing 10 changed files with 1,646 additions and 302 deletions.
221 changes: 138 additions & 83 deletions instat/dlgBoxPlot.designer.vb

Large diffs are not rendered by default.

151 changes: 134 additions & 17 deletions instat/dlgBoxPlot.vb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ Public Class dlgBoxplot
Private clsRaesFunction As New RFunction
Private clsBaseOperator As New ROperator
Private clsLocalRaesFunction As New RFunction
Private clsWidthRaesFunction As New RFunction
Private clsStatAesFunction As New RFunction
Private clsStatSummary As New RFunction
Private clsPositionNodgeFunction As New RFunction
Private clsDummyFunction As New RFunction
'Similarly clsRgeom_boxplotFunction and clsRaesFunction (respectively the geom_boxplot function and the global aes function) are given through SetupLayer to sdgLayerOptions for edit.
Private bFirstLoad As Boolean = True
Private bReset As Boolean = True
Expand All @@ -51,6 +55,8 @@ Public Class dlgBoxplot
Private clsViolinplotFunction As New RFunction
Private clsCurrGeomFunction As New RFunction
Private clsSummaryFunction As New RFunction
Private clsCutWitdhFunction As New RFunction
Private clsGeomBoxPlotFunction As New RFunction
' Jitter function that can be added to the boxplot/violin base layer
Private clsAddedJitterFunc As New RFunction
Private clsXScaleDateFunction As New RFunction
Expand Down Expand Up @@ -111,9 +117,11 @@ Public Class dlgBoxplot
ucrPnlPlots.AddFunctionNamesCondition(rdoBoxplotTufte, {"geom_boxplot", "geom_tufteboxplot"})
ucrPnlPlots.AddFunctionNamesCondition(rdoJitter, "geom_jitter")
ucrPnlPlots.AddFunctionNamesCondition(rdoViolin, "geom_violin")
ucrPnlPlots.AddToLinkedControls(ucrChkAddPoints, {rdoBoxplotTufte, rdoViolin}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlPlots.AddToLinkedControls({ucrChkAddPoints, ucrChkWidth}, {rdoBoxplotTufte, rdoViolin}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlPlots.AddToLinkedControls({ucrChkTufte}, {rdoBoxplotTufte}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrChkTufte.AddToLinkedControls(ucrChkVarWidth, {"FALSE"}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlPlots.AddToLinkedControls(ucrChkBoxPlot, {rdoJitter, rdoViolin}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)


ucrSelectorBoxPlot.SetParameter(New RParameter("data", 0))
ucrSelectorBoxPlot.SetParameterIsrfunction()
Expand All @@ -128,8 +136,6 @@ Public Class dlgBoxplot

ucrByFactorsReceiver.SetParameter(New RParameter("x", 1))
ucrByFactorsReceiver.Selector = ucrSelectorBoxPlot
ucrByFactorsReceiver.SetIncludedDataTypes({"factor"})
ucrByFactorsReceiver.strSelectorHeading = "Factors"
ucrByFactorsReceiver.SetParameterIsString()
ucrByFactorsReceiver.bWithQuotes = False
ucrByFactorsReceiver.SetValuesToIgnore({Chr(34) & Chr(34)})
Expand Down Expand Up @@ -221,12 +227,30 @@ Public Class dlgBoxplot
ucrInputStation.SetItems({strFacetWrap, strFacetRow, strFacetCol, strNone})
ucrInputStation.SetDropDownStyleAsNonEditable()

ucrChkWidth.SetText("Width")
ucrChkWidth.AddToLinkedControls({ucrInputWidth}, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:=0.25)
ucrChkWidth.AddParameterValuesCondition(True, "cut_width", "True")
ucrChkWidth.AddParameterValuesCondition(False, "cut_width", "False")

ucrChkBoxPlot.SetText("Add Boxplot")
ucrChkBoxPlot.AddToLinkedControls({ucrNudBoxPlot}, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:=0.5)
ucrChkBoxPlot.AddParameterValuesCondition(True, "boxplot", "True")
ucrChkBoxPlot.AddParameterValuesCondition(False, "boxplot", "False")

ucrNudBoxPlot.SetParameter(New RParameter("width", 2))
ucrNudBoxPlot.SetMinMax(0, 1)
ucrNudBoxPlot.DecimalPlaces = 2
ucrNudBoxPlot.Increment = 0.01
ucrNudBoxPlot.SetLinkedDisplayControl(lblWidth)

ucrInputWidth.SetParameter(New RParameter("width"))
ucrInputWidth.SetValidationTypeAsNumeric()

ucrChkGrouptoConnect.SetText("Group to Connect")
ucrChkGrouptoConnect.AddToLinkedControls(ucrInputSummaries, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="mean")
ucrChkGrouptoConnect.AddParameterPresentCondition(True, strStatSummaryParameterName, True)
ucrChkGrouptoConnect.AddParameterPresentCondition(False, strStatSummaryParameterName, False)
'this control exists but diabled for now
ucrChkSwapParameters.SetText("swap Parameters")
DialogueSize()
End Sub

Expand All @@ -244,6 +268,11 @@ Public Class dlgBoxplot
clsFacetColOp = New ROperator
clsPipeOperator = New ROperator
clsGroupByFunction = New RFunction
clsDummyFunction = New RFunction
clsWidthRaesFunction = New RFunction
clsGeomBoxPlotFunction = New RFunction
clsStatAesFunction = New RFunction
clsPositionNodgeFunction = New RFunction

'Setting up new functions
clsBoxplotFunction = New RFunction
Expand All @@ -266,6 +295,9 @@ Public Class dlgBoxplot
bResetSubdialog = True
bResetBoxLayerSubdialog = True

clsDummyFunction.AddParameter("cut_width", "False", iPosition:=0)
clsDummyFunction.AddParameter("boxplot", "False", iPosition:=1)

'Setting current geom as boxplot
clsCurrGeomFunction.SetPackageName("ggplot2")
clsCurrGeomFunction = clsBoxplotFunction
Expand All @@ -275,6 +307,18 @@ Public Class dlgBoxplot
clsBoxplotFunction.AddParameter("varwidth", "FALSE", iPosition:=0)
clsBoxplotFunction.AddParameter("outlier.colour", Chr(34) & "red" & Chr(34), iPosition:=1)

clsWidthRaesFunction.SetPackageName("ggplot2")
clsWidthRaesFunction.SetRCommand("aes")

clsCutWitdhFunction.SetPackageName("ggplot2")
clsCutWitdhFunction.SetRCommand("cut_width")

clsStatAesFunction.SetPackageName("ggplot2")
clsStatAesFunction.SetRCommand("aes")

clsGeomBoxPlotFunction.SetPackageName("ggplot2")
clsGeomBoxPlotFunction.SetRCommand("geom_boxplot")

clsTufteBoxplotFunction.SetPackageName("ggthemes")
clsTufteBoxplotFunction.SetRCommand("geom_tufteboxplot")
clsTufteBoxplotFunction.AddParameter("stat", Chr(34) & "boxplot" & Chr(34), iPosition:=0)
Expand Down Expand Up @@ -313,8 +357,10 @@ Public Class dlgBoxplot
clsStatSummary.SetPackageName("ggplot2")
clsStatSummary.SetRCommand("stat_summary")
clsStatSummary.AddParameter("geom", Chr(34) & "line" & Chr(34), iPosition:=0)
clsStatSummary.AddParameter("group", 1, iPosition:=1)
clsStatSummary.AddParameter("color", Chr(34) & "blue" & Chr(34), iPosition:=2)

clsPositionNodgeFunction.SetPackageName("ggplot2")
clsPositionNodgeFunction.SetRCommand("position_dodge")
clsPositionNodgeFunction.AddParameter("width", 0.9, iPosition:=0)

clsFacetFunction.SetPackageName("ggplot2")
clsFacetRowOp.SetOperation("+")
Expand Down Expand Up @@ -377,8 +423,12 @@ Public Class dlgBoxplot
ucrChkLegend.SetRCode(clsThemeFunction, bReset, bCloneIfNeeded:=True)
ucrInputLegendPosition.SetRCode(clsThemeFunction, bReset, bCloneIfNeeded:=True)
ucrChkTufte.SetRCode(clsCurrGeomFunction, bReset)
ucrInputWidth.SetRCode(clsCutWitdhFunction, bReset)
ucrNudBoxPlot.SetRCode(clsGeomBoxPlotFunction, bReset)
If bReset Then
AutoFacetStation()
ucrChkBoxPlot.SetRCode(clsDummyFunction, bReset)
ucrChkWidth.SetRCode(clsDummyFunction, bReset)
End If
End Sub

Expand Down Expand Up @@ -430,6 +480,13 @@ Public Class dlgBoxplot
SetGeomPrefixFillColourAes()
DialogueSize()
EnableDisableBoxplotOptions()
If rdoBoxplotTufte.Checked Then
If ucrChkAddPoints.Checked Then
clsBoxplotFunction.AddParameter("outlier.shape", "NA", iPosition:=2)
Else
clsBoxplotFunction.RemoveParameterByName("outlier.shape")
End If
End If
End Sub

Private Sub ucrChkGrouptoConnect_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkGrouptoConnect.ControlValueChanged
Expand All @@ -438,6 +495,7 @@ Public Class dlgBoxplot
Else
clsBaseOperator.RemoveParameterByName(strStatSummaryParameterName)
End If
AddRemoveAesParm()
End Sub

Private Sub openSdgLayerOptions(clsNewGeomFunc As RFunction)
Expand Down Expand Up @@ -498,7 +556,7 @@ Public Class dlgBoxplot
clsNewThemeFunction:=clsThemeFunction, dctNewThemeFunctions:=dctThemeFunctions, clsNewGlobalAesFunction:=clsRaesFunction, ucrNewBaseSelector:=ucrSelectorBoxPlot, clsNewFacetVariablesOperator:=clsFacetVariablesOperator,
clsNewCoordPolarFunction:=clsCoordPolarFunction, clsNewCoordPolarStartOperator:=clsCoordPolarStartOperator, clsNewXScaleDateFunction:=clsXScaleDateFunction, clsNewAnnotateFunction:=clsAnnotateFunction,
clsNewScaleFillViridisFunction:=clsScaleFillViridisFunction, clsNewScaleColourViridisFunction:=clsScaleColourViridisFunction, clsNewYScaleDateFunction:=clsYScaleDateFunction,
strMainDialogGeomParameterNames:=strGeomParameterNames, bReset:=bResetSubdialog)
strMainDialogGeomParameterNames:=strGeomParameterNames, bChangeAesParameter:=True, bReset:=bResetSubdialog)
sdgPlots.ShowDialog()
bResetSubdialog = False
End Sub
Expand Down Expand Up @@ -655,6 +713,8 @@ Public Class dlgBoxplot
Private Sub ucr1stFactorReceiver_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucr1stFactorReceiver.ControlValueChanged, ucrByFactorsReceiver.ControlValueChanged
AddRemoveFacets()
AddRemoveGroupBy()
EnableDisableWidth()
AddRemoveAesParm()
End Sub

Private Sub GetParameterValue(clsOperator As ROperator)
Expand Down Expand Up @@ -719,15 +779,72 @@ Public Class dlgBoxplot
toolStripMenuItemTufteOptions.Enabled = (rdoBoxplotTufte.Checked AndAlso ucrChkTufte.Checked)
End Sub

'this code is commented out but will work once we get the feature of linking controls with the contents of a receiver
'Private Sub SwapFactors()
' If ucrChkSwapParameters.Checked Then
' ucrByFactorsReceiver.ChangeParameterName("fill")
' ucrSecondFactorReceiver.ChangeParameterName("x")
' End If
'End Sub
Private Sub ucrInputWidth_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputWidth.ControlValueChanged, ucrByFactorsReceiver.ControlValueChanged
If Not ucrInputWidth.IsEmpty Then
clsCutWitdhFunction.AddParameter("width", ucrInputWidth.GetText(), iPosition:=1)
clsCutWitdhFunction.AddParameter("var", ucrByFactorsReceiver.GetVariableNames(False), bIncludeArgumentName:=False, iPosition:=0)
Else
clsCutWitdhFunction.RemoveParameterByName("width")
clsCutWitdhFunction.RemoveParameterByName("var")
End If
EnableDisableWidth()
End Sub

'Private Sub ucrChkSwapParameters_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSwapParameters.ControlValueChanged
' SwapFactors()
'End Sub
Private Sub ucrChkWidth_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkWidth.ControlValueChanged
EnableDisableWidth()
End Sub

Private Sub EnableDisableWidth()
If ucrByFactorsReceiver.strCurrDataType = "Date" OrElse ucrByFactorsReceiver.strCurrDataType = "factor" OrElse ucrByFactorsReceiver.strCurrDataType = "orderded, factor" Then
ucrChkWidth.Enabled = False
ucrInputWidth.Enabled = False
clsBoxplotFunction.RemoveParameterByName("aes")
clsWidthRaesFunction.RemoveParameterByName("group")
clsViolinplotFunction.RemoveParameterByName("aes")
Else
ucrChkWidth.Enabled = True
ucrInputWidth.Enabled = True
If ucrChkWidth.Checked AndAlso Not ucrByFactorsReceiver.IsEmpty Then
clsWidthRaesFunction.AddParameter("group", clsRFunctionParameter:=clsCutWitdhFunction, iPosition:=1)
clsBoxplotFunction.AddParameter("aes", clsRFunctionParameter:=clsWidthRaesFunction, bIncludeArgumentName:=False, iPosition:=1)
clsViolinplotFunction.AddParameter("aes", clsRFunctionParameter:=clsWidthRaesFunction, bIncludeArgumentName:=False, iPosition:=1)
Else
clsWidthRaesFunction.RemoveParameterByName("group")
clsBoxplotFunction.RemoveParameterByName("aes")
clsViolinplotFunction.RemoveParameterByName("aes")
End If
End If
End Sub

Private Sub ucrChkBoxPlot_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkBoxPlot.ControlValueChanged, ucrNudBoxPlot.ControlValueChanged
If ucrChkBoxPlot.Checked Then
clsGeomBoxPlotFunction.AddParameter("width", ucrNudBoxPlot.GetText(), iPosition:=3)
clsBaseOperator.AddParameter("geom_boxplot", clsRFunctionParameter:=clsGeomBoxPlotFunction)
Else
clsGeomBoxPlotFunction.RemoveParameterByName("width")
clsBaseOperator.RemoveParameterByName("geom_boxplot")
End If
End Sub

Private Sub AddRemoveAesParm()
If Not ucrSecondFactorReceiver.IsEmpty AndAlso Not (ucrSecondFactorReceiver.GetVariableNames = ucrByFactorsReceiver.GetVariableNames) Then
clsStatAesFunction.AddParameter("group", ucrSecondFactorReceiver.GetVariableNames(False), iPosition:=0)
clsStatAesFunction.AddParameter("colour", ucrSecondFactorReceiver.GetVariableNames(False), iPosition:=1)
clsStatSummary.AddParameter("stat_aes", clsRFunctionParameter:=clsStatAesFunction, bIncludeArgumentName:=False)
clsStatSummary.AddParameter("position", clsRFunctionParameter:=clsPositionNodgeFunction)
clsStatSummary.RemoveParameterByName("group")
clsStatSummary.RemoveParameterByName("color")
Else
clsStatSummary.AddParameter("group", 1, iPosition:=1)
clsStatSummary.AddParameter("color", Chr(34) & "blue" & Chr(34), iPosition:=2)
clsStatAesFunction.RemoveParameterByName("group")
clsStatAesFunction.RemoveParameterByName("colour")
clsStatSummary.RemoveParameterByName("stat_aes")
clsStatSummary.RemoveParameterByName("position")
End If
End Sub

Private Sub ucrSecondFactorReceiver_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSecondFactorReceiver.ControlValueChanged
AddRemoveAesParm()
End Sub
End Class
2 changes: 1 addition & 1 deletion instat/dlgHeatMapPlot.vb
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ Public Class dlgHeatMapPlot
clsNewScaleFillViridisFunction:=clsScaleFillViridisFunction, clsNewScaleColourViridisFunction:=clsScaleColourViridisFunction, clsNewYLabTitleFunction:=clsYlabFunction, clsNewLabsFunction:=clsLabsFunction,
clsNewFacetFunction:=clsRFacetFunction, clsNewThemeFunction:=clsThemeFunction, dctNewThemeFunctions:=dctThemeFunctions, ucrNewBaseSelector:=ucrHeatMapSelector, clsNewFacetVariablesOperator:=clsFacetVariablesOperator,
strMainDialogGeomParameterNames:=strGeomParameterNames, clsNewCoordPolarFunction:=clsCoordPolarFunction, clsNewCoordPolarStartOperator:=clsCoordPolarStartOperator,
clsNewAnnotateFunction:=clsAnnotateFunction, clsNewXScaleDateFunction:=clsXScaleDateFunction, clsNewYScaleDateFunction:=clsYScaleDateFunction, bReset:=bResetSubdialog)
clsNewAnnotateFunction:=clsAnnotateFunction, clsNewXScaleDateFunction:=clsXScaleDateFunction, clsNewYScaleDateFunction:=clsYScaleDateFunction, bChangeAesParameter:=True, bReset:=bResetSubdialog)
sdgPlots.ShowDialog()
bResetSubdialog = False
End Sub
Expand Down
29 changes: 19 additions & 10 deletions instat/sdgCalculationsSummmary.vb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ Public Class sdgCalculationsSummmary

ucrManipulations.lstAvailableData.View = View.List

ucrCalcSummary.ucrReceiverForCalculation.bAttachedToPrimaryDataFrame = False

'temp until working
ucrCalcSummary.ucrSaveResultInto.Visible = False
'ucrCalcSummary.ucrTryModelling.Visible = False
Expand Down Expand Up @@ -345,16 +343,18 @@ Public Class sdgCalculationsSummmary

Private Sub ucrCalcSummary_SelectionChanged() Handles ucrCalcSummary.SelectionChanged
If {"Calculation", "Summary"}.Contains(ucrInputType.GetText()) Then
Dim strExpression As String = ucrCalcSummary.ucrReceiverForCalculation.GetText()
If Not ucrCalcSummary.ucrReceiverForCalculation.IsEmpty Then
clsCalculationFunction.AddParameter("function_exp", Chr(34) & ucrCalcSummary.ucrReceiverForCalculation.GetText() & Chr(34))
clsCalculationFunction.AddParameter("function_exp", Chr(34) & strExpression & Chr(34))
Else
clsCalculationFunction.RemoveParameterByName("function_exp")
End If

If Not ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.IsEmpty Then
clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(
ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.GetVariableNamesList(bWithQuotes:=False),
ucrCalcSummary.ucrSelectorForCalculations))
If ucrCalcSummary.ucrSelectorForCalculations.lstAvailableVariable.Items.Count > 0 AndAlso
Not ucrCalcSummary.ucrReceiverForCalculation.IsEmpty Then
Dim lstItems As String() = ucrCalcSummary.ucrSelectorForCalculations.lstAvailableVariable.Items.Cast(Of ListViewItem)().Select(Function(item) item.Text).ToArray()
Dim strSelectedVariables As String() = lstItems.Where(Function(variable) strExpression.Contains(variable)).ToArray()
clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(strSelectedVariables, ucrCalcSummary.ucrSelectorForCalculations))
Else
clsCalculationFunction.RemoveParameterByName("calculated_from")
End If
Expand All @@ -374,14 +374,23 @@ Public Class sdgCalculationsSummmary

'Need to do this instead of with RFunctions because the calculated_from list can have multiple items with the same label
Private Function CreateCalcFromList(lstVariables As String(), ucrCurrentSelector As ucrSelectorByDataFrame) As String

If lstVariables Is Nothing Then
Return ""
End If

Dim strCalcFromList As String

strCalcFromList = "list("
For i = 0 To lstVariables.Count - 1
If i > 0 Then
strCalcFromList = strCalcFromList & ","
Dim strDataName As String = lstVariables(i)
If Not String.IsNullOrEmpty(strDataName) Then
If i > 0 Then
strCalcFromList = strCalcFromList & ","
End If

strCalcFromList = strCalcFromList & ucrCurrentSelector.strCurrentDataFrame & " = " & Chr(34) & strDataName & Chr(34)
End If
strCalcFromList = strCalcFromList & ucrCurrentSelector.strCurrentDataFrame & " = " & Chr(34) & lstVariables(i) & Chr(34)
Next
strCalcFromList = strCalcFromList & ")"
Return strCalcFromList
Expand Down
Loading

0 comments on commit 242dea5

Please sign in to comment.