Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#8385 from MeSophie/NewNewClimat…
Browse files Browse the repository at this point in the history
…icMenu8348

Split the Climatic > Tidy and Examine menu
  • Loading branch information
lloyddewit authored Jun 22, 2023
2 parents c7c54c6 + e339627 commit e192859
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 156 deletions.
12 changes: 6 additions & 6 deletions instat/dlgThreeVariablePivotTable.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 89 additions & 33 deletions instat/dlgThreeVariablePivotTable.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ Public Class dlgThreeVariablePivotTable
Private bFirstLoad As Boolean = True
Private bRcodeSet As Boolean = False
Private bReset As Boolean = True

Public enumPivotMode As PivotMode = PivotMode.Describe

Public Enum PivotMode
Describe
Climatic
End Enum

Private clsConcatenateFunction, clsFlattenFunction,
clsLevelsFunction, clsPasteFunction,
clsRelevelPasteFunction, clsRPivotTableFunction,
clsSelectFunction As New RFunction
clsSelectFunction, clsDummyFunction As New RFunction
Private clsPipeOperator, clsLevelsDollarOperator As New ROperator


Private Sub dlgThreeVariablePivotTable_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
InitialiseDialog()
Expand All @@ -36,6 +43,7 @@ Public Class dlgThreeVariablePivotTable
End If
SetRCodeForControls(bReset)
bReset = False
AutofillMode()
autoTranslate(Me)
TestOkEnabled()
End Sub
Expand All @@ -49,6 +57,8 @@ Public Class dlgThreeVariablePivotTable

ucrReceiverInitialRowFactors.SetParameter(New RParameter("rows", iNewPosition:=1))
ucrReceiverInitialRowFactors.SetParameterIsString()
ucrReceiverInitialRowFactors.strSelectorHeading = "Numerics"
ucrReceiverInitialRowFactors.SetIncludedDataTypes({"numeric"})
ucrReceiverInitialRowFactors.Selector = ucrSelectorPivot

ucrReceiverInitialColumnFactor.SetParameter(New RParameter("cols", iNewPosition:=2))
Expand All @@ -59,15 +69,12 @@ Public Class dlgThreeVariablePivotTable

ucrReceiverAdditionalRowFactor.SetParameter(New RParameter("val", iNewPosition:=4))
ucrReceiverAdditionalRowFactor.SetParameterIsString()
ucrReceiverAdditionalRowFactor.SetIncludedDataTypes({"numeric", "Date", "logical"})
ucrReceiverAdditionalRowFactor.Selector = ucrSelectorPivot

ucrChkSelectedVariable.AddParameterIsRFunctionCondition(False, "data", True)
ucrChkSelectedVariable.AddParameterIsRFunctionCondition(True, "data", False)


ucrReceiverFactorLevels.SetParameter(New RParameter("variable", iNewPosition:=1))
ucrReceiverFactorLevels.SetDataType("factor")
ucrReceiverFactorLevels.SetParameterIsString()
ucrReceiverFactorLevels.bWithQuotes = False
ucrReceiverFactorLevels.Selector = ucrSelectorPivot
Expand All @@ -84,8 +91,9 @@ Public Class dlgThreeVariablePivotTable
ucrChkIncludeSubTotals.SetRDefault("FALSE")

ucrChkNumericVariable.SetText("Numeric Variable (Optional):")
ucrChkNumericVariable.AddParameterPresentCondition(True, "rendererName")
ucrChkNumericVariable.AddParameterPresentCondition(False, "rendererName", False)
ucrChkNumericVariable.SetParameter(New RParameter("subtotals", iNewPosition:=0))
ucrChkNumericVariable.SetValuesCheckedAndUnchecked("TRUE", "FALSE")
ucrChkNumericVariable.SetRDefault("TRUE")
ucrChkNumericVariable.AddToLinkedControls({ucrReceiverAdditionalRowFactor}, {True}, bNewLinkedHideIfParameterMissing:=True,
bNewLinkedAddRemoveParameter:=True, bNewLinkedUpdateFunction:=True)
ucrChkNumericVariable.AddToLinkedControls({ucrInputTableChart}, {True}, bNewLinkedHideIfParameterMissing:=True,
Expand All @@ -99,6 +107,7 @@ Public Class dlgThreeVariablePivotTable
ucrInputTableChart.SetItems({"Table", "Table Barchart", "Heatmap", "Row Heatmap", "Col Heatmap",
"Treemap", "Horizontal Bar Chart", "Horizontal Stacked Barchart", "Bar Chart", "Stacked Bar Chart",
"Line Chart", "Area chart", "Scatter Chart"}, bAddConditions:=True)
ucrInputTableChart.SetText("Table")
ucrInputTableChart.SetLinkedDisplayControl(lblTableChart)

ucrInputSummary.SetParameter(New RParameter("aggregatorName", iNewPosition:=6))
Expand All @@ -107,6 +116,7 @@ Public Class dlgThreeVariablePivotTable
"Maximum", "First", "Last", "Sum over Sum", "80% Upper Bound", "80% Lower Bound",
"Sum as Fraction of Totals", "Sum as Fraction of Rows", "Sum as Fraction of Columns",
"Count as Fraction of Total", "Count as Fraction of Rows", "Count as Fraction of Columns"}, bAddConditions:=True)
ucrInputSummary.SetText("Average")
ucrInputSummary.SetLinkedDisplayControl(lblSummary)

ucrSavePivot.SetPrefix("pivot_table")
Expand All @@ -125,6 +135,7 @@ Public Class dlgThreeVariablePivotTable
clsRelevelPasteFunction = New RFunction
clsRPivotTableFunction = New RFunction
clsSelectFunction = New RFunction
clsDummyFunction = New RFunction

clsLevelsDollarOperator = New ROperator
clsPipeOperator = New ROperator
Expand All @@ -133,6 +144,7 @@ Public Class dlgThreeVariablePivotTable
ucrSelectorPivot.Reset()
ucrSavePivot.Reset()

clsDummyFunction.AddParameter("subtotals", "TRUE", iPosition:=0)

clsLevelsDollarOperator.SetOperation("$")

Expand All @@ -152,13 +164,11 @@ Public Class dlgThreeVariablePivotTable
clsFlattenFunction.AddParameter("string", clsRFunctionParameter:=clsPasteFunction, iPosition:=0)
clsFlattenFunction.SetAssignTo("survey_levels")


clsRelevelPasteFunction.SetRCommand("paste0")
clsRelevelPasteFunction.AddParameter("first_paramete", Chr(34) & "function(attr) { var sortAs = $.pivotUtilities.sortAs; return sortAs([" & Chr(34) & ", survey_levels," & Chr(34) & "]); }" & Chr(34),
bIncludeArgumentName:=False, iPosition:=0)
clsRelevelPasteFunction.SetAssignTo("relevel_variables")


clsConcatenateFunction.SetRCommand("c")

clsSelectFunction.SetPackageName("dplyr")
Expand Down Expand Up @@ -190,7 +200,7 @@ Public Class dlgThreeVariablePivotTable
ucrSelectorPivot.SetRCode(clsPipeOperator, bReset)
ucrReceiverInitialColumnFactor.SetRCode(clsRPivotTableFunction, bReset)
ucrReceiverFactorLevels.SetRCode(clsLevelsDollarOperator, bReset)
ucrChkNumericVariable.SetRCode(clsRPivotTableFunction, bReset)
ucrChkNumericVariable.SetRCode(clsDummyFunction, bReset)
ucrReceiverInitialRowFactors.SetRCode(clsRPivotTableFunction, bReset)
ucrSavePivot.SetRCode(clsRPivotTableFunction, bReset)
ucrChkSelectedVariable.SetRCode(clsRPivotTableFunction, bReset)
Expand All @@ -208,6 +218,7 @@ Public Class dlgThreeVariablePivotTable

Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
AutofillMode()
SetRCodeForControls(True)
TestOkEnabled()
End Sub
Expand All @@ -216,17 +227,14 @@ Public Class dlgThreeVariablePivotTable
If ucrChkSelectedVariable.Checked Then
ucrReceiverSelectedVariable.SetMeAsReceiver()
Else
If ucrChkNumericVariable.Checked Then
ucrReceiverAdditionalRowFactor.SetMeAsReceiver()
Else
ucrReceiverInitialRowFactors.SetMeAsReceiver()
End If
ucrReceiverInitialRowFactors.SetMeAsReceiver()
End If
ChangeDataParameterValue()
End Sub

Private Sub ucrSelectorPivot_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorPivot.ControlValueChanged
ChangeDataParameterValue()
AutofillMode()
clsRPivotTableFunction._strDataFrameNameToAddAssignToObject = ucrSelectorPivot.strCurrentDataFrame
End Sub

Expand All @@ -239,10 +247,7 @@ Public Class dlgThreeVariablePivotTable
End Sub

Private Sub ReceiversChanged(ucrChangedControls As ucrCore) Handles ucrReceiverInitialColumnFactor.ControlValueChanged, ucrReceiverSelectedVariable.ControlValueChanged,
ucrReceiverInitialRowFactors.ControlValueChanged, ucrReceiverAdditionalRowFactor.ControlValueChanged, ucrReceiverFactorLevels.ControlValueChanged
If Not bRcodeSet Then
Exit Sub
End If
ucrReceiverInitialRowFactors.ControlValueChanged, ucrReceiverAdditionalRowFactor.ControlValueChanged, ucrReceiverFactorLevels.ControlValueChanged, ucrChkNumericVariable.ControlValueChanged

If ucrChkSelectedVariable.Checked Then
Dim lstColumns As New List(Of String)
Expand Down Expand Up @@ -274,17 +279,27 @@ Public Class dlgThreeVariablePivotTable
Not lstColumns.Contains(strFactorLevelsVariable) Then
clsConcatenateFunction.AddParameter("factor_level", strFactorLevelsVariable,
bIncludeArgumentName:=False, iPosition:=iPosition)

End If
End If

If ucrChangedControls Is ucrReceiverFactorLevels Then
If ucrReceiverFactorLevels.IsEmpty Then
ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsFlattenFunction)
clsRPivotTableFunction.RemoveParameterByName("sorters")
Else
ucrBase.clsRsyntax.AddToBeforeCodes(clsFlattenFunction, 0)
clsRPivotTableFunction.AddParameter(strParameterName:="sorters", clsRFunctionParameter:=clsRelevelPasteFunction, iPosition:=3)
End If
If enumPivotMode = PivotMode.Climatic Then
clsRPivotTableFunction.RemoveParameterByName("sorters")
ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsFlattenFunction)

Else
ucrBase.clsRsyntax.AddToBeforeCodes(clsFlattenFunction, 0)
clsRPivotTableFunction.AddParameter(strParameterName:="sorters", clsRFunctionParameter:=clsRelevelPasteFunction, iPosition:=3)
End If

If ucrChkNumericVariable.Checked AndAlso enumPivotMode = PivotMode.Climatic Then
clsRPivotTableFunction.AddParameter("val", ucrReceiverAdditionalRowFactor.GetVariableNames(), iPosition:=3)
clsRPivotTableFunction.AddParameter("rendererName", Chr(34) & ucrInputTableChart.GetText() & Chr(34), iPosition:=4)
clsRPivotTableFunction.AddParameter("aggregatorName", Chr(34) & ucrInputSummary.GetText() & Chr(34), iPosition:=5)
Else
clsRPivotTableFunction.RemoveParameterByName("val")
clsRPivotTableFunction.RemoveParameterByName("rendererName")
clsRPivotTableFunction.RemoveParameterByName("aggregatorName")
End If
End Sub

Expand All @@ -299,18 +314,59 @@ Public Class dlgThreeVariablePivotTable
Next
End Sub

Private Sub AutofillMode()
Select Case enumPivotMode
Case PivotMode.Describe
ucrReceiverInitialRowFactors.bAutoFill = False

ucrReceiverInitialColumnFactor.bAutoFill = False

ucrReceiverFactorLevels.SetDataType("factor")
ucrReceiverFactorLevels.bAutoFill = False

ucrReceiverAdditionalRowFactor.SetIncludedDataTypes({"numeric", "Date", "logical"})
ucrReceiverAdditionalRowFactor.bAutoFill = False
Case PivotMode.Climatic
Dim strMonthCol As String
Dim strDataFrame As String
Dim strRainCol As String
Dim strYearCol As String
Dim strDayCol As String

strDataFrame = ucrSelectorPivot.ucrAvailableDataFrames.cboAvailableDataFrames.Text
strMonthCol = frmMain.clsRLink.GetClimaticColumnOfType(strDataFrame, "month_label")
strRainCol = frmMain.clsRLink.GetClimaticColumnOfType(strDataFrame, "rain_label")
strYearCol = frmMain.clsRLink.GetClimaticColumnOfType(strDataFrame, "year_label")
strDayCol = frmMain.clsRLink.GetClimaticColumnOfType(strDataFrame, "day_label")
If Not String.IsNullOrEmpty(strRainCol) Then
ucrReceiverAdditionalRowFactor.Add(strRainCol, strDataFrame)
End If

If Not String.IsNullOrEmpty(strMonthCol) Then
ucrReceiverFactorLevels.Add(strMonthCol, strDataFrame)
ucrReceiverInitialColumnFactor.Add(strMonthCol, strDataFrame)
End If
End Select
End Sub

Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverSelectedVariable.ControlContentsChanged,
ucrReceiverInitialColumnFactor.ControlContentsChanged, ucrChkSelectedVariable.ControlContentsChanged, ucrSavePivot.ControlContentsChanged
TestOkEnabled()
End Sub

Private Sub ucrChkNumericVariable_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkNumericVariable.ControlValueChanged
If ucrChkNumericVariable.Checked Then
ucrReceiverAdditionalRowFactor.SetMeAsReceiver()
ElseIf Not ucrChkNumericVariable.Checked AndAlso ucrChkSelectedVariable.Checked Then
ucrReceiverSelectedVariable.SetMeAsReceiver()
Private Sub ucrInputSummary_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputSummary.ControlValueChanged
If ucrChkNumericVariable.Checked AndAlso Not ucrInputSummary.IsEmpty Then
clsRPivotTableFunction.AddParameter("aggregatorName", Chr(34) & ucrInputSummary.GetText() & Chr(34), iPosition:=5)
Else
ucrReceiverInitialRowFactors.SetMeAsReceiver()
clsRPivotTableFunction.RemoveParameterByName("aggregatorName")
End If
End Sub

Private Sub ucrInputTableChart_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputTableChart.ControlValueChanged
If ucrChkNumericVariable.Checked AndAlso Not ucrInputTableChart.IsEmpty Then
clsRPivotTableFunction.AddParameter("rendererName", Chr(34) & ucrInputTableChart.GetText() & Chr(34), iPosition:=4)
Else
clsRPivotTableFunction.RemoveParameterByName("rendererName")
End If
End Sub
End Class
Loading

0 comments on commit e192859

Please sign in to comment.