Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements notification for Levels/Labels #7625

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions instat/dlgLabelsLevels.Designer.vb

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

62 changes: 58 additions & 4 deletions instat/dlgLabelsLevels.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Imports RDotNet
Public Class dlgLabelsLevels
Private bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private clsViewLabelsFunction, clsSumCountMissingFunction As New RFunction
Private clsViewLabelsFunction, clsSumCountMissingFunction, clsTableOperation, clsUnusedLevels, clstable, clsFactorColumn, clsSum As New RFunction
Public strSelectedDataFrame As String = ""
Private bUseSelectedColumn As Boolean = False
Private strSelectedColumn As String = ""
'Private clsTableOperation As New ROperator

Private Sub dlgLabels_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
Expand Down Expand Up @@ -67,23 +68,43 @@ Public Class dlgLabelsLevels

ucrChkIncludeLevelNumbers.SetText("Include Level Numbers")

ucrChkRemovelabels.SetText("Remove Unused Levels")
ucrChkRemovelabels.AddToLinkedControls(ucrInputUnusedLevels, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrInputUnusedLevels.SetLinkedDisplayControl(lblUnusedLevels)
ucrChkRemovelabels.SetParameter(New RParameter("check"))
ucrChkRemovelabels.SetValuesCheckedAndUnchecked("TRUE", "FALSE")

lblNaValue.ForeColor = Color.Red
lblLevelNumber.ForeColor = Color.Red
End Sub

Private Sub SetDefaults()
clsViewLabelsFunction = New RFunction
clsSumCountMissingFunction = New RFunction
clsUnusedLevels = New RFunction
clstable = New RFunction
clsFactorColumn = New RFunction
clsSum = New RFunction

cmdAddLevel.Enabled = False
ucrSelectorForLabels.Reset()
ucrInputUnusedLevels.SetName("")
ucrInputUnusedLevels.Reset()
ucrSelectorForLabels.Focus()

clstable.SetRCommand("table")
clsSum.SetRCommand("sum")
clsFactorColumn.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_columns_from_data")
clsUnusedLevels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$drop_unused_factor_levels")

clsSumCountMissingFunction.SetRCommand("summary_count_missing")

clsViewLabelsFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$set_factor_levels")
ucrBase.clsRsyntax.SetBaseRFunction(clsViewLabelsFunction)

If bReset Then
ucrChkRemovelabels.SetRCode(clsUnusedLevels, bReset)
End If
End Sub

Public Sub SetCurrentColumn(strColumn As String, strDataFrame As String)
Expand Down Expand Up @@ -148,7 +169,41 @@ Public Class dlgLabelsLevels
lblLevelNumber.Visible = ucrFactorLabels.RowCount > 0
End Sub

Private Sub ucrReceiverLabels_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverLabels.ControlValueChanged
Private Sub ucrReceiverLabels_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverLabels.ControlValueChanged, ucrChkRemovelabels.ControlValueChanged
Dim iNumOutput As Integer
Dim expNum As SymbolicExpression
Dim bClear As Boolean = False

If Not ucrReceiverLabels.IsEmpty Then
clstable.AddParameter("x", clsRFunctionParameter:=clsFactorColumn)
'clsTableOperation.SetOperation("==")
clsTableOperation.AddParameter(clsRFunctionParameter:=clstable, iPosition:=0)
clsTableOperation.AddParameter("threshhold", 0, iPosition:=1)

'clsSum.AddParameter("x", clsROperatorParameter:=clsTableOperation)

expNum = frmMain.clsRLink.RunInternalScriptGetValue(clsSum.ToScript, bSilent:=True)
If expNum IsNot Nothing AndAlso expNum.Type <> Internals.SymbolicExpressionType.Null Then
iNumOutput = expNum.AsNumeric(0)
ucrInputUnusedLevels.txtInput.BackColor = Color.Green
If iNumOutput = 0 Then
ucrInputUnusedLevels.SetName("No unused levels to remove")
ucrInputUnusedLevels.txtInput.BackColor = Color.LightCoral
Else
ucrInputUnusedLevels.SetName(iNumOutput & " unused level(s) will be removed")
ucrInputUnusedLevels.txtInput.BackColor = Color.LightGreen
End If
Else
bClear = True
End If
Else
bClear = True
End If
If bClear Then
ucrInputUnusedLevels.txtInput.BackColor = Color.White
clstable.RemoveParameterByName("x")
ucrInputUnusedLevels.ResetText()
End If
'check if the variable selected has value labels.
'If it has then disable ucrChkIncludeLevelNumbers and set it as checked
'because it already has level number, so just show them to user
Expand All @@ -157,7 +212,7 @@ Public Class dlgLabelsLevels
ucrChkIncludeLevelNumbers.Enabled = Not ucrChkIncludeLevelNumbers.Checked
End Sub

Private Sub ucrFactorLabels_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrFactorLabels.ControlValueChanged, ucrChkIncludeLevelNumbers.ControlValueChanged
Private Sub ucrFactorLabels_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrFactorLabels.ControlValueChanged, ucrChkIncludeLevelNumbers.ControlValueChanged, ucrChkRemovelabels.ControlValueChanged

'only add levels if indicated by the user
Dim bAddParam As Boolean
Expand Down Expand Up @@ -186,5 +241,4 @@ Public Class dlgLabelsLevels
CountLevels()
TestOKEnabled()
End Sub

End Class