diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index b96462c6da6..76c2baca7d9 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -824,15 +824,8 @@ Public Class RLink End If ElseIf iCallType = 5 Then 'else if script comes from script window - Dim bSuccess As Boolean = Evaluate(strScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) - - 'if not an assignment operation, then capture the output - If Not strScript.Contains("<-") AndAlso bSuccess Then - Dim strScriptAsSingleLine As String = strScript.Replace(vbCrLf, String.Empty) - strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbCr, String.Empty) - strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbLf, String.Empty) - strOutput = GetFileOutput("view_object_data(object = " & strScriptAsSingleLine & " , object_format = 'text' )", bSilent, bSeparateThread, bShowWaitDialogOverride) - End If + 'wrap command inside view_object_data just incase there is an output object + strOutput = GetFileOutput("view_object_data(object = " & strScript & " , object_format = 'text' )", bSilent, bSeparateThread, bShowWaitDialogOverride) Else 'else if script output should not be ignored or not stored as an object or variable @@ -883,7 +876,8 @@ Public Class RLink Dim expTemp As RDotNet.SymbolicExpression Dim strNewAssignedToScript As String = ConstructAssignTo(strTempAssignTo, strScript) Evaluate(strNewAssignedToScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) - expTemp = GetSymbol(strTempAssignTo, bSilent:=bSilent) + 'get file path. If not found then silently return nothing + expTemp = GetSymbol(strTempAssignTo, bSilent:=True) Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True) If expTemp IsNot Nothing Then 'get the file path name, check if it exists and whether it has contents diff --git a/instat/dlgBarAndPieChart.Designer.vb b/instat/dlgBarAndPieChart.Designer.vb index 5048b0ad6ff..7e857d855c2 100644 --- a/instat/dlgBarAndPieChart.Designer.vb +++ b/instat/dlgBarAndPieChart.Designer.vb @@ -68,7 +68,7 @@ Partial Class dlgBarAndPieChart Me.toolStripMenuItemPlotOptions = New System.Windows.Forms.ToolStripMenuItem() Me.toolStripMenuItemBarchartOptions = New System.Windows.Forms.ToolStripMenuItem() Me.toolStripMenuItemLollipopOptions = New System.Windows.Forms.ToolStripMenuItem() - Me.toolStripMenuItemPointOptions = New System.Windows.Forms.ToolStripMenuItem() + Me.toolStripMenuItemTextOptions = New System.Windows.Forms.ToolStripMenuItem() Me.toolStripMenuItemTreemapOptions = New System.Windows.Forms.ToolStripMenuItem() Me.toolStripMenuItemWordcloudOptions = New System.Windows.Forms.ToolStripMenuItem() Me.cmdOptions = New instat.ucrSplitButton() @@ -97,7 +97,6 @@ Partial Class dlgBarAndPieChart Me.ucrReceiverWordcloudColor = New instat.ucrReceiverSingle() Me.ucrReceiverX = New instat.ucrReceiverSingle() Me.ucrInputReorderX = New instat.ucrInputComboBox() - Me.ucrChkIncreaseSize = New instat.ucrCheck() Me.ucrInputAddReorder = New instat.ucrInputComboBox() Me.ucrPnlPolar = New instat.UcrPanel() Me.ucrInputLabelColour = New instat.ucrInputComboBox() @@ -105,12 +104,14 @@ Partial Class dlgBarAndPieChart Me.ucrInputStart = New instat.ucrInputComboBox() Me.ucrChkLayout = New instat.ucrCheck() Me.ucrChkFlipCoordinates = New instat.ucrCheck() - Me.ucrChkBacktoback = New instat.ucrCheck() Me.ucrChkPolarCoordinates = New instat.ucrCheck() Me.ucrVariablesAsFactorForBarChart = New instat.ucrVariablesAsFactor() Me.ucrReceiverWordcloudAngle = New instat.ucrReceiverSingle() Me.ucrChkAddLabelsText = New instat.ucrCheck() Me.ucrChkAddLabelsTreemap = New instat.ucrCheck() + Me.ucrChkBacktoback = New instat.ucrCheck() + Me.ucrChkIncreaseSize = New instat.ucrCheck() + Me.toolStripMenuItemTreemapTextOptionsOptions = New System.Windows.Forms.ToolStripMenuItem() Me.contextMenuStripOptions.SuspendLayout() Me.SuspendLayout() ' @@ -387,44 +388,44 @@ Partial Class dlgBarAndPieChart ' 'contextMenuStripOptions ' - Me.contextMenuStripOptions.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.toolStripMenuItemPlotOptions, Me.toolStripMenuItemBarchartOptions, Me.toolStripMenuItemLollipopOptions, Me.toolStripMenuItemPointOptions, Me.toolStripMenuItemTreemapOptions, Me.toolStripMenuItemWordcloudOptions}) + Me.contextMenuStripOptions.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.toolStripMenuItemPlotOptions, Me.toolStripMenuItemBarchartOptions, Me.toolStripMenuItemTextOptions, Me.toolStripMenuItemLollipopOptions, Me.toolStripMenuItemTreemapOptions, Me.toolStripMenuItemTreemapTextOptionsOptions, Me.toolStripMenuItemWordcloudOptions}) Me.contextMenuStripOptions.Name = "contextMenuStripOk" - Me.contextMenuStripOptions.Size = New System.Drawing.Size(179, 136) + Me.contextMenuStripOptions.Size = New System.Drawing.Size(189, 180) ' 'toolStripMenuItemPlotOptions ' Me.toolStripMenuItemPlotOptions.Name = "toolStripMenuItemPlotOptions" - Me.toolStripMenuItemPlotOptions.Size = New System.Drawing.Size(178, 22) + Me.toolStripMenuItemPlotOptions.Size = New System.Drawing.Size(188, 22) Me.toolStripMenuItemPlotOptions.Text = "Plot Options" ' 'toolStripMenuItemBarchartOptions ' Me.toolStripMenuItemBarchartOptions.Name = "toolStripMenuItemBarchartOptions" - Me.toolStripMenuItemBarchartOptions.Size = New System.Drawing.Size(178, 22) + Me.toolStripMenuItemBarchartOptions.Size = New System.Drawing.Size(188, 22) Me.toolStripMenuItemBarchartOptions.Text = "BarChart Options" ' 'toolStripMenuItemLollipopOptions ' Me.toolStripMenuItemLollipopOptions.Name = "toolStripMenuItemLollipopOptions" - Me.toolStripMenuItemLollipopOptions.Size = New System.Drawing.Size(178, 22) + Me.toolStripMenuItemLollipopOptions.Size = New System.Drawing.Size(188, 22) Me.toolStripMenuItemLollipopOptions.Text = "Lollipop Options" ' - 'toolStripMenuItemPointOptions + 'toolStripMenuItemTextOptions ' - Me.toolStripMenuItemPointOptions.Name = "toolStripMenuItemPointOptions" - Me.toolStripMenuItemPointOptions.Size = New System.Drawing.Size(178, 22) - Me.toolStripMenuItemPointOptions.Text = "Point Options" + Me.toolStripMenuItemTextOptions.Name = "toolStripMenuItemTextOptions" + Me.toolStripMenuItemTextOptions.Size = New System.Drawing.Size(188, 22) + Me.toolStripMenuItemTextOptions.Text = "Text Options" ' 'toolStripMenuItemTreemapOptions ' Me.toolStripMenuItemTreemapOptions.Name = "toolStripMenuItemTreemapOptions" - Me.toolStripMenuItemTreemapOptions.Size = New System.Drawing.Size(178, 22) + Me.toolStripMenuItemTreemapOptions.Size = New System.Drawing.Size(188, 22) Me.toolStripMenuItemTreemapOptions.Text = "Treemap Options" ' 'toolStripMenuItemWordcloudOptions ' Me.toolStripMenuItemWordcloudOptions.Name = "toolStripMenuItemWordcloudOptions" - Me.toolStripMenuItemWordcloudOptions.Size = New System.Drawing.Size(178, 22) + Me.toolStripMenuItemWordcloudOptions.Size = New System.Drawing.Size(188, 22) Me.toolStripMenuItemWordcloudOptions.Text = "Wordcloud Options" ' 'cmdOptions @@ -723,15 +724,6 @@ Partial Class dlgBarAndPieChart Me.ucrInputReorderX.Size = New System.Drawing.Size(93, 21) Me.ucrInputReorderX.TabIndex = 12 ' - 'ucrChkIncreaseSize - ' - Me.ucrChkIncreaseSize.AutoSize = True - Me.ucrChkIncreaseSize.Checked = False - Me.ucrChkIncreaseSize.Location = New System.Drawing.Point(10, 317) - Me.ucrChkIncreaseSize.Name = "ucrChkIncreaseSize" - Me.ucrChkIncreaseSize.Size = New System.Drawing.Size(88, 23) - Me.ucrChkIncreaseSize.TabIndex = 63 - ' 'ucrInputAddReorder ' Me.ucrInputAddReorder.AddQuotesIfUnrecognised = True @@ -766,9 +758,9 @@ Partial Class dlgBarAndPieChart ' Me.ucrChkStart.AutoSize = True Me.ucrChkStart.Checked = False - Me.ucrChkStart.Location = New System.Drawing.Point(10, 317) + Me.ucrChkStart.Location = New System.Drawing.Point(10, 316) Me.ucrChkStart.Name = "ucrChkStart" - Me.ucrChkStart.Size = New System.Drawing.Size(108, 23) + Me.ucrChkStart.Size = New System.Drawing.Size(83, 23) Me.ucrChkStart.TabIndex = 28 ' 'ucrInputStart @@ -777,7 +769,7 @@ Partial Class dlgBarAndPieChart Me.ucrInputStart.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink Me.ucrInputStart.GetSetSelectedIndex = -1 Me.ucrInputStart.IsReadOnly = False - Me.ucrInputStart.Location = New System.Drawing.Point(79, 315) + Me.ucrInputStart.Location = New System.Drawing.Point(104, 315) Me.ucrInputStart.Name = "ucrInputStart" Me.ucrInputStart.Size = New System.Drawing.Size(93, 21) Me.ucrInputStart.TabIndex = 30 @@ -800,15 +792,6 @@ Partial Class dlgBarAndPieChart Me.ucrChkFlipCoordinates.Size = New System.Drawing.Size(166, 23) Me.ucrChkFlipCoordinates.TabIndex = 29 ' - 'ucrChkBacktoback - ' - Me.ucrChkBacktoback.AutoSize = True - Me.ucrChkBacktoback.Checked = False - Me.ucrChkBacktoback.Location = New System.Drawing.Point(10, 293) - Me.ucrChkBacktoback.Name = "ucrChkBacktoback" - Me.ucrChkBacktoback.Size = New System.Drawing.Size(166, 23) - Me.ucrChkBacktoback.TabIndex = 27 - ' 'ucrChkPolarCoordinates ' Me.ucrChkPolarCoordinates.AutoSize = True @@ -862,6 +845,30 @@ Partial Class dlgBarAndPieChart Me.ucrChkAddLabelsTreemap.Size = New System.Drawing.Size(129, 24) Me.ucrChkAddLabelsTreemap.TabIndex = 61 ' + 'ucrChkBacktoback + ' + Me.ucrChkBacktoback.AutoSize = True + Me.ucrChkBacktoback.Checked = False + Me.ucrChkBacktoback.Location = New System.Drawing.Point(10, 293) + Me.ucrChkBacktoback.Name = "ucrChkBacktoback" + Me.ucrChkBacktoback.Size = New System.Drawing.Size(93, 23) + Me.ucrChkBacktoback.TabIndex = 27 + ' + 'ucrChkIncreaseSize + ' + Me.ucrChkIncreaseSize.AutoSize = True + Me.ucrChkIncreaseSize.Checked = False + Me.ucrChkIncreaseSize.Location = New System.Drawing.Point(10, 317) + Me.ucrChkIncreaseSize.Name = "ucrChkIncreaseSize" + Me.ucrChkIncreaseSize.Size = New System.Drawing.Size(88, 23) + Me.ucrChkIncreaseSize.TabIndex = 63 + ' + 'toolStripMenuItemTreemapTextOptionsOptions + ' + Me.toolStripMenuItemTreemapTextOptionsOptions.Name = "toolStripMenuItemTreemapTextOptionsOptions" + Me.toolStripMenuItemTreemapTextOptionsOptions.Size = New System.Drawing.Size(188, 22) + Me.toolStripMenuItemTreemapTextOptionsOptions.Text = "Treemap Text Options" + ' 'dlgBarAndPieChart ' Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!) @@ -913,7 +920,6 @@ Partial Class dlgBarAndPieChart Me.Controls.Add(Me.ucrReceiverX) Me.Controls.Add(Me.lblWordcloudAngle) Me.Controls.Add(Me.ucrInputReorderX) - Me.Controls.Add(Me.ucrChkIncreaseSize) Me.Controls.Add(Me.ucrInputAddReorder) Me.Controls.Add(Me.lblLabelPosition) Me.Controls.Add(Me.ucrPnlPolar) @@ -922,7 +928,6 @@ Partial Class dlgBarAndPieChart Me.Controls.Add(Me.ucrInputStart) Me.Controls.Add(Me.ucrChkLayout) Me.Controls.Add(Me.ucrChkFlipCoordinates) - Me.Controls.Add(Me.ucrChkBacktoback) Me.Controls.Add(Me.ucrChkPolarCoordinates) Me.Controls.Add(Me.lblWordcloudLabel) Me.Controls.Add(Me.lblArea) @@ -931,6 +936,8 @@ Partial Class dlgBarAndPieChart Me.Controls.Add(Me.ucrReceiverWordcloudAngle) Me.Controls.Add(Me.ucrChkAddLabelsText) Me.Controls.Add(Me.ucrChkAddLabelsTreemap) + Me.Controls.Add(Me.ucrChkBacktoback) + Me.Controls.Add(Me.ucrChkIncreaseSize) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False @@ -1011,9 +1018,10 @@ Partial Class dlgBarAndPieChart Friend WithEvents contextMenuStripOptions As ContextMenuStrip Friend WithEvents toolStripMenuItemPlotOptions As ToolStripMenuItem Friend WithEvents toolStripMenuItemBarchartOptions As ToolStripMenuItem - Friend WithEvents toolStripMenuItemPointOptions As ToolStripMenuItem + Friend WithEvents toolStripMenuItemTextOptions As ToolStripMenuItem Friend WithEvents toolStripMenuItemTreemapOptions As ToolStripMenuItem Friend WithEvents toolStripMenuItemWordcloudOptions As ToolStripMenuItem Friend WithEvents cmdOptions As ucrSplitButton Friend WithEvents toolStripMenuItemLollipopOptions As ToolStripMenuItem + Friend WithEvents toolStripMenuItemTreemapTextOptionsOptions As ToolStripMenuItem End Class \ No newline at end of file diff --git a/instat/dlgBarAndPieChart.vb b/instat/dlgBarAndPieChart.vb index 3884518ab16..d8162bacf49 100644 --- a/instat/dlgBarAndPieChart.vb +++ b/instat/dlgBarAndPieChart.vb @@ -59,7 +59,7 @@ Public Class dlgBarAndPieChart Private clsScaleFillViridisFunction As New RFunction Private clsScaleColourViridisFunction As New RFunction Private clsGeomTextFunction As New RFunction - Private clsLabelAesFunction As New RFunction + Private clsTextAesFunction As New RFunction Private clsAnnotateFunction As New RFunction Private clsForecatsInfreq As New RFunction Private clsForecatsReverse As New RFunction @@ -77,6 +77,7 @@ Public Class dlgBarAndPieChart Private clsScaleSizeAreaFunction As New RFunction Private clsDummyFunction As New RFunction Private clsPointsFunction As New RFunction + Private clsGeomLollipopAesFunction As New RFunction Private ReadOnly strAscending As String = "Ascending" Private ReadOnly strDescending As String = "Descending" @@ -89,7 +90,6 @@ Public Class dlgBarAndPieChart Private strAdditionalPointsParameterName As String = "add_jitter" Private strGeomParameterNames() As String = {strFirstParameterName, strStatSummaryParameterName, strAdditionalPointsParameterName} - Private Sub dlgBarAndPieChart_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then InitialiseDialog() @@ -133,8 +133,8 @@ Public Class dlgBarAndPieChart ucrPnlOptions.AddFunctionNamesCondition(rdoWordCloud, {"geom_text_wordcloud", "scale_size_area"}) ucrPnlOptions.AddToLinkedControls({ucrChkFlipCoordinates, ucrChkPolarCoordinates, ucrReceiverByFactor, ucrInputBarChartPositions, ucrChkAddLabelsText, ucrVariablesAsFactorForBarChart, ucrChkBacktoback}, {rdoFrequency, rdoValue}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrPnlOptions.AddToLinkedControls({ucrReceiverX, ucrChkReorderValue, ucrChkLollipop}, {rdoValue}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrPnlOptions.AddToLinkedControls(ucrChkReorderFrequency, {rdoFrequency}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlOptions.AddToLinkedControls({ucrReceiverX, ucrChkReorderValue, ucrInputAddReorder, ucrChkLollipop}, {rdoValue}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlOptions.AddToLinkedControls({ucrChkReorderFrequency, ucrInputAddReorder}, {rdoFrequency}, bNewLinkedHideIfParameterMissing:=True) ucrPnlOptions.AddToLinkedControls({ucrReceiverArea, ucrReceiverFill, ucrChkLayout, ucrChkStart, ucrChkAddLabelsTreemap}, {rdoTreeMap}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlOptions.AddToLinkedControls({ucrReceiverWordcloudAngle, ucrReceiverWordcloudColor, ucrReceiverWordcloudLabel, ucrReceiverWordcloudSize, ucrChkIncreaseSize}, {rdoWordCloud}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrReceiverByFactor.SetLinkedDisplayControl(lblByFactor) @@ -165,7 +165,6 @@ Public Class dlgBarAndPieChart ucrReceiverByFactor.Selector = ucrBarChartSelector ucrReceiverByFactor.SetIncludedDataTypes({"factor"}) ucrReceiverByFactor.strSelectorHeading = "Factors" - ucrReceiverByFactor.SetParameter(New RParameter("fill", 2)) ucrReceiverByFactor.bWithQuotes = False ucrReceiverByFactor.SetParameterIsString() @@ -391,7 +390,7 @@ Public Class dlgBarAndPieChart clsScaleXdiscretFunction = New RFunction clsExpansionFunction = New RFunction clsGeomTextFunction = New RFunction - clsLabelAesFunction = New RFunction + clsTextAesFunction = New RFunction clsForecatsInfreq = New RFunction clsForecatsReverse = New RFunction clsForecatsInfreqValue = New RFunction @@ -408,6 +407,7 @@ Public Class dlgBarAndPieChart clsScaleSizeAreaFunction = New RFunction clsDummyFunction = New RFunction clsPointsFunction = New RFunction + clsGeomLollipopAesFunction = New RFunction ucrBarChartSelector.Reset() ucrBarChartSelector.SetGgplotFunction(clsBaseOperator) @@ -417,11 +417,14 @@ Public Class dlgBarAndPieChart bResetBarLayerSubdialog = True ucrInputAddReorder.SetText(strNone) + ucrInputAddReorder.bUpdateRCodeFromControl = True ucrInputReorderX.SetText(strNone) ucrInputReorderX.bUpdateRCodeFromControl = True ucrInputReorderValue.SetText(strNone) + ucrInputReorderValue.bUpdateRCodeFromControl = True + 'Temp fix: Set panel conditions properly! rdoPie.Checked = True rdoFrequency.Checked = True @@ -455,13 +458,14 @@ Public Class dlgBarAndPieChart clsGeomLollipopFunction.AddParameter("point.colour", "steelblue", iPosition:=0) clsGeomLollipopFunction.AddParameter("point.size", "1", iPosition:=1) + clsGeomLollipopAesFunction.SetPackageName("ggplot2") + clsGeomLollipopAesFunction.SetRCommand("aes") + clsBarAesFunction.SetPackageName("ggplot2") clsBarAesFunction.SetRCommand("aes") clsPieAesFunction.SetPackageName("ggplot2") clsPieAesFunction.SetRCommand("aes") - clsPieAesFunction.AddParameter("x", Chr(34) & Chr(34)) - clsPieAesFunction.AddParameter("y", Chr(34) & Chr(34)) clsForecatsReverse.SetPackageName("forcats") clsForecatsReverse.SetRCommand("fct_rev") @@ -487,8 +491,8 @@ Public Class dlgBarAndPieChart clsPointsFunction.SetPackageName("ggplot2") clsPointsFunction.SetRCommand("geom_point") - clsPointsFunction.AddParameter("size", "3") - clsPointsFunction.AddParameter("colour", Chr(34) & "red" & Chr(34)) + clsPointsFunction.AddParameter("size", "3", iPosition:=0) + clsPointsFunction.AddParameter("colour", Chr(34) & "red" & Chr(34), iPosition:=1) clsIsEqualToOperator1.SetOperation("==") clsIsEqualToOperator1.AddParameter("right", clsROperatorParameter:=clsOpeningSubsetOperator1, iPosition:=1) @@ -524,16 +528,17 @@ Public Class dlgBarAndPieChart clsScaleYSymmetricFunction.SetPackageName("lemon") clsScaleYSymmetricFunction.SetRCommand("scale_y_symmetric") + clsTextAesFunction.SetPackageName("ggplot2") + clsTextAesFunction.SetRCommand("aes") + clsTextAesFunction.AddParameter("label", "..count..", iPosition:=0) + clsGeomTextFunction.SetPackageName("ggplot2") clsGeomTextFunction.SetRCommand("geom_text") - clsGeomTextFunction.AddParameter("mapping", clsRFunctionParameter:=clsLabelAesFunction, iPosition:=1) + clsGeomTextFunction.AddParameter("mapping", clsRFunctionParameter:=clsTextAesFunction, iPosition:=1) clsGeomTextFunction.AddParameter("colour", "black", iPosition:=4) clsGeomTextFunction.AddParameter("vjust", "-0.25", iPosition:=2) clsGeomTextFunction.AddParameter("size", "4", iPosition:=5) - clsLabelAesFunction.SetPackageName("ggplot2") - clsLabelAesFunction.SetRCommand("aes") - clsGeomTreemapFunction.SetPackageName("treemapify") clsGeomTreemapFunction.SetRCommand("geom_treemap") clsGeomTreemapFunction.AddParameter("layout", Chr(34) & "squarified" & Chr(34), iPosition:=0) @@ -554,7 +559,6 @@ Public Class dlgBarAndPieChart clsGeomTreemapTextAesFunction.SetPackageName("ggplot2") clsGeomTreemapTextAesFunction.SetRCommand("aes") - clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsGeomTreemapAesFunction, iPosition:=0) clsGeomTextWordcloudAesFunction.SetPackageName("ggplot2") clsGeomTextWordcloudAesFunction.SetRCommand("aes") @@ -592,19 +596,13 @@ Public Class dlgBarAndPieChart Private Sub SetRCodeForControls(bReset As Boolean) ucrBarChartSelector.AddAdditionalCodeParameterPair(clsSubsetFunction1, ucrBarChartSelector.GetParameter(), iAdditionalPairNo:=1) ucrBarChartSelector.AddAdditionalCodeParameterPair(clsSubsetFunction2, ucrBarChartSelector.GetParameter(), iAdditionalPairNo:=2) - ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsPieAesFunction, ucrReceiverByFactor.GetParameter(), iAdditionalPairNo:=1) - ucrVariablesAsFactorForBarChart.AddAdditionalCodeParameterPair(clsPieAesFunction, ucrVariablesAsFactorForBarChart.GetParameter(), iAdditionalPairNo:=1) - ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsIsEqualToOperator1, New RParameter("left", 0), iAdditionalPairNo:=2) - ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsIsEqualToOperator2, New RParameter("left", 0), iAdditionalPairNo:=3) - ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsLevelsFunction, New RParameter("x", 0), iAdditionalPairNo:=4) - ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsReorderFunctionValue, New RParameter("x", 0), iAdditionalPairNo:=5) + ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsIsEqualToOperator1, New RParameter("left", 0), iAdditionalPairNo:=1) + ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsIsEqualToOperator2, New RParameter("left", 0), iAdditionalPairNo:=2) + ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsLevelsFunction, New RParameter("x", 0), iAdditionalPairNo:=3) + ucrReceiverByFactor.AddAdditionalCodeParameterPair(clsReorderFunctionValue, New RParameter("x", 0), iAdditionalPairNo:=4) ucrReceiverX.AddAdditionalCodeParameterPair(clsReorderFunction, New RParameter("x", 0), iAdditionalPairNo:=1) - ucrReceiverFill.AddAdditionalCodeParameterPair(clsGeomTreemapTextAesFunction, New RParameter("label", 0), iAdditionalPairNo:=1) ucrInputLayout.AddAdditionalCodeParameterPair(clsGeomTreemapTextFunction, New RParameter("layout", 1), iAdditionalPairNo:=1) - ucrVariablesAsFactorForBarChart.SetRCode(clsBarAesFunction, bReset) - ucrReceiverX.SetRCode(clsBarAesFunction, bReset) - ucrReceiverByFactor.SetRCode(clsBarAesFunction, bReset) ucrSaveBar.SetRCode(clsBaseOperator, bReset) ucrBarChartSelector.SetRCode(clsRggplotFunction, bReset) ucrChkPolarCoordinates.SetRCode(clsPolarCoordFunction, bReset) @@ -623,9 +621,7 @@ Public Class dlgBarAndPieChart ucrReceiverFill.SetRCode(clsGeomTreemapAesFunction, bReset) ucrReceiverLabel.SetRCode(clsGeomTreemapTextAesFunction, bReset) ucrInputLayout.SetRCode(clsGeomTreemapFunction, bReset) - ucrChkLayout.SetRCode(clsGeomTreemapFunction, bReset) ucrInputStart.SetRCode(clsGeomTreemapFunction, bReset) - ucrChkStart.SetRCode(clsGeomTreemapFunction, bReset) ucrInputPlace.SetRCode(clsGeomTreemapTextFunction, bReset) ucrReceiverWordcloudLabel.SetRCode(clsGeomTextWordcloudAesFunction, bReset) ucrReceiverWordcloudSize.SetRCode(clsGeomTextWordcloudAesFunction, bReset) @@ -633,8 +629,13 @@ Public Class dlgBarAndPieChart ucrReceiverWordcloudAngle.SetRCode(clsGeomTextWordcloudAesFunction, bReset) ucrChkAddLabelsTreemap.SetRCode(clsBaseOperator, bReset) ucrNudMaxSize.SetRCode(clsScaleSizeAreaFunction, bReset) - ucrChkIncreaseSize.SetRCode(clsScaleSizeAreaFunction, bReset) ucrChkReorderFrequency.SetRCode(clsDummyFunction, bReset) + + If bReset Then + ucrChkStart.SetRCode(clsGeomTreemapFunction, bReset) + ucrChkLayout.SetRCode(clsGeomTreemapFunction, bReset) + ucrChkIncreaseSize.SetRCode(clsScaleSizeAreaFunction, bReset) + End If End Sub Private Sub TestOkEnabled() @@ -671,50 +672,54 @@ Public Class dlgBarAndPieChart TestOkEnabled() End Sub - Private Sub openSdgLayerOptions(clsNewGeomFunc As RFunction) + Private Sub openSdgLayerOptions(clsNewGeomFunc As RFunction, clsNewAesFunction As RFunction) sdgLayerOptions.SetupLayer(clsNewGgPlot:=clsRggplotFunction, clsNewGeomFunc:=clsNewGeomFunc, - clsNewGlobalAesFunc:=clsLabelAesFunction, clsNewLocalAes:=clsLocalRaesFunction, + clsNewGlobalAesFunc:=clsNewAesFunction, clsNewLocalAes:=clsLocalRaesFunction, bFixGeom:=True, ucrNewBaseSelector:=ucrBarChartSelector, bApplyAesGlobally:=True, bReset:=bResetLineLayerSubdialog) sdgLayerOptions.ShowDialog() bResetLineLayerSubdialog = False 'Coming from the sdgLayerOptions, clsRaesFunction and others have 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 clsLabelAesFunction.clsParameters - 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 value stored in the clsReasFunction in the multiple variables - ' 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 ucrVariablesAsFactorForBarChart.bSingleVariable) Then - 'Still might be in the case of bSingleVariable with mapping y="". - If clsParam.strArgumentValue = Chr(34) & Chr(34) Then - ucrVariablesAsFactorForBarChart.Clear() - Else - ucrReceiverWordcloudSize.Add(clsParam.strArgumentValue) + Try + 'The aesthetics parameters on the main dialog are repopulated as required. + For Each clsParam In clsNewAesFunction.clsParameters + 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 value stored in the clsReasFunction in the multiple variables + ' 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 ucrVariablesAsFactorForBarChart.bSingleVariable) Then + 'Still might be in the case of bSingleVariable with mapping y="". + If clsParam.strArgumentValue = Chr(34) & Chr(34) Then + ucrVariablesAsFactorForBarChart.Clear() + Else + ucrReceiverWordcloudSize.Add(clsParam.strArgumentValue) + End If + ElseIf clsParam.strArgumentName = "colour" Then + ucrReceiverByFactor.Add(clsParam.strArgumentValue) End If - ElseIf clsParam.strArgumentName = "colour" Then - ucrReceiverByFactor.Add(clsParam.strArgumentValue) - End If - Next + Next + Catch ex As Exception + MsgBox(ex.Message) + End Try + SetGeomTextOptions() TestOkEnabled() End Sub Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click, toolStripMenuItemPlotOptions.Click sdgPlots.SetRCode(clsNewOperator:=ucrBase.clsRsyntax.clsBaseOperator, clsNewYScalecontinuousFunction:=clsYScalecontinuousFunction, clsNewXScalecontinuousFunction:=clsXScalecontinuousFunction, clsNewXLabsTitleFunction:=clsXlabFunction, clsNewYLabTitleFunction:=clsYlabFunction, clsNewLabsFunction:=clsLabsFunction, clsNewFacetFunction:=clsRFacetFunction, - clsNewThemeFunction:=clsThemeFuction, dctNewThemeFunctions:=dctThemeFunctions, clsNewGlobalAesFunction:=clsLabelAesFunction, ucrNewBaseSelector:=ucrBarChartSelector, + clsNewThemeFunction:=clsThemeFuction, dctNewThemeFunctions:=dctThemeFunctions, clsNewGlobalAesFunction:=clsTextAesFunction, ucrNewBaseSelector:=ucrBarChartSelector, clsNewCoordPolarFunction:=clsCoordPolarFunction, clsNewCoordPolarStartOperator:=clsCoordPolarStartOperator, clsNewXScaleDateFunction:=clsXScaleDateFunction, clsNewAnnotateFunction:=clsAnnotateFunction, clsNewScaleFillViridisFunction:=clsScaleFillViridisFunction, clsNewScaleColourViridisFunction:=clsScaleColourViridisFunction, clsNewYScaleDateFunction:=clsYScaleDateFunction, strMainDialogGeomParameterNames:=strGeomParameterNames, bReset:=bResetSubdialog) @@ -723,23 +728,27 @@ Public Class dlgBarAndPieChart End Sub Private Sub toolStripMenuItemBarchartOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemBarchartOptions.Click - openSdgLayerOptions(clsRgeomBarFunction1) + openSdgLayerOptions(clsRgeomBarFunction1, clsBarAesFunction) End Sub Private Sub toolStripMenuItemLollipopOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemLollipopOptions.Click - openSdgLayerOptions(clsGeomLollipopFunction) + openSdgLayerOptions(clsGeomLollipopFunction, clsGeomLollipopAesFunction) End Sub Private Sub toolStripMenuItemTreemapOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemTreemapOptions.Click - openSdgLayerOptions(clsGeomTreemapFunction) + openSdgLayerOptions(clsGeomTreemapFunction, clsGeomTreemapAesFunction) End Sub Private Sub toolStripMenuItemWordcloudOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemWordcloudOptions.Click - openSdgLayerOptions(clsGeomTextWordcloudFunction) + openSdgLayerOptions(clsGeomTextWordcloudFunction, clsGeomTextWordcloudAesFunction) + End Sub + + Private Sub toolStripMenuItemTreemapTextOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemTreemapTextOptionsOptions.Click + openSdgLayerOptions(clsGeomTreemapTextFunction, clsGeomTreemapTextAesFunction) End Sub - Private Sub toolStripMenuItemPointOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemPointOptions.Click - openSdgLayerOptions(clsPointsFunction) + Private Sub toolStripMenuItemPointOptions_Click(sender As Object, e As EventArgs) Handles toolStripMenuItemTextOptions.Click + openSdgLayerOptions(clsGeomTextFunction, clsTextAesFunction) End Sub Private Sub SetDialogOptions() @@ -752,21 +761,20 @@ Public Class dlgBarAndPieChart End If ucrVariablesAsFactorForBarChart.RemoveIncludedMetadataProperty("class") ucrVariablesAsFactorForBarChart.strSelectorHeading = "Variables" - ucrInputBarChartPositions.Visible = Not ucrReceiverByFactor.IsEmpty() - ElseIf rdoTreeMap.Checked Then clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTreemapAesFunction, iPosition:=1) Else clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTextWordcloudAesFunction, iPosition:=1) End If - ucrChkLollipop.Enabled = If(rdoValue.Checked, True, False) If rdoFrequency.Checked Then If ucrVariablesAsFactorForBarChart.bSingleVariable Then - ucrInputAddReorder.Visible = Not ucrReceiverByFactor.IsEmpty() - If Not ucrInputAddReorder.Visible Then + If ucrReceiverByFactor.IsEmpty Then + ucrInputAddReorder.Visible = False ucrInputAddReorder.SetText(strNone) + Else + ucrInputAddReorder.Visible = True End If Else ucrInputReorderX.SetText(strNone) @@ -775,9 +783,6 @@ Public Class dlgBarAndPieChart If ucrVariablesAsFactorForBarChart.bSingleVariable Then ucrChkReorderValue.Visible = True ucrInputAddReorder.Visible = Not ucrReceiverByFactor.IsEmpty() - If Not ucrInputAddReorder.Visible Then - ucrInputAddReorder.SetText(strNone) - End If Else ucrChkReorderValue.Visible = False End If @@ -791,69 +796,162 @@ Public Class dlgBarAndPieChart If rdoFrequency.Checked Then clsForecatsInfreq.AddParameter("f", "as.factor(" & ucrVariablesAsFactorForBarChart.GetVariableNames(False) & ")", iPosition:=0) clsForecatsInfreqValue.AddParameter("f", "as.factor(" & ucrReceiverByFactor.GetVariableNames(False) & ")", iPosition:=0) - Select Case strChangedTextFreq - Case strAscending - clsForecatsReverse.AddParameter("f", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) - Case strDescending - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) - Case strReverse - clsForecatsReverse.AddParameter("f", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) - End Select - Select Case strChangedTextValue - Case strAscending - clsForecatsReverseValue.AddParameter("f", clsRFunctionParameter:=clsForecatsInfreqValue, iPosition:=0) - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=1) - Case strDescending - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsInfreqValue, iPosition:=1) - Case strReverse - clsForecatsReverseValue.AddParameter("f", ucrReceiverByFactor.GetVariableNames(False), iPosition:=0) - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=1) - End Select - - Else - Select Case strChangeTextReorder - Case strAscending - clsReorderFunction.AddParameter("X", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) - Case strDescending - clsReorderFunction.AddParameter("X", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) - Case strReverse - clsForecatsReverse.AddParameter("f", ucrReceiverX.GetVariableNames(False), iPosition:=0) - clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) - End Select - Select Case strChangedTextValue - Case strAscending - clsReorderFunctionValue.AddParameter("X", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) - Case strDescending - clsReorderFunctionValue.AddParameter("X", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) - Case strReverse - clsForecatsReverseValue.AddParameter("f", ucrReceiverByFactor.GetVariableNames(False), iPosition:=0) - clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) - End Select + If ucrChkReorderFrequency.Checked Then + Select Case strChangedTextFreq + Case strAscending + clsForecatsReverse.AddParameter("f", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + Case strDescending + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) + Case strReverse + clsForecatsReverse.AddParameter("f", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + Case strNone + clsBarAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + clsPieAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + End Select + Else + clsBarAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + clsPieAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + End If + If ucrChkPolarCoordinates.Checked Then + If rdoPie.Checked OrElse rdoDonut.Checked Then + If ucrReceiverByFactor.IsEmpty Then + clsPieAesFunction.AddParameter("x", "1", iPosition:=0) + Select Case strChangedTextFreq + Case strAscending + clsForecatsReverse.AddParameter("f", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=0) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverse, iPosition:=2) + Case strDescending + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsInfreq, iPosition:=2) + Case strReverse + clsForecatsReverse.AddParameter("f", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverse, iPosition:=2) + Case strNone + clsPieAesFunction.AddParameter("fill", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=2) + End Select + End If + End If + End If + If Not ucrReceiverByFactor.IsEmpty Then + Select Case strChangedTextValue + Case strAscending + clsForecatsReverseValue.AddParameter("f", clsRFunctionParameter:=clsForecatsInfreqValue, iPosition:=0) + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=1) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) + Case strDescending + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsInfreqValue, iPosition:=1) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsInfreqValue, iPosition:=2) + Case strReverse + clsForecatsReverseValue.AddParameter("f", ucrReceiverByFactor.GetVariableNames(False), iPosition:=0) + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=1) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) + Case strNone + clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) + End Select + End If + ElseIf rdoValue.Checked Then + clsReorderFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + clsReorderFunctionValue.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + If ucrChkReorderValue.Checked Then + Select Case strChangeTextReorder + Case strAscending + clsReorderFunction.AddParameter("X", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) + Case strDescending + clsReorderFunction.AddParameter("X", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsReorderFunction, iPosition:=0) + Case strReverse + clsForecatsReverse.AddParameter("f", ucrReceiverX.GetVariableNames(False), iPosition:=0) + clsBarAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + clsPieAesFunction.AddParameter("x", clsRFunctionParameter:=clsForecatsReverse, iPosition:=0) + Case strNone + clsBarAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + clsPieAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + End Select + Else + clsBarAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + End If + If ucrChkPolarCoordinates.Checked Then + If rdoPie.Checked OrElse rdoDonut.Checked Then + If ucrReceiverByFactor.IsEmpty Then + clsPieAesFunction.AddParameter("x", "1", iPosition:=0) + Select Case strChangeTextReorder + Case strAscending + clsReorderFunctionValue.AddParameter("X", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + Case strDescending + clsReorderFunctionValue.AddParameter("X", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + Case strReverse + clsForecatsReverseValue.AddParameter("f", ucrReceiverX.GetVariableNames(False), iPosition:=0) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) + Case strNone + clsPieAesFunction.AddParameter("fill", ucrReceiverX.GetVariableNames(False), iPosition:=2) + End Select + End If + End If + End If + If Not ucrReceiverByFactor.IsEmpty Then + Select Case strChangedTextValue + Case strAscending + clsReorderFunctionValue.AddParameter("X", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + Case strDescending + clsReorderFunctionValue.AddParameter("X", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsReorderFunctionValue, iPosition:=2) + Case strReverse + clsForecatsReverseValue.AddParameter("f", ucrReceiverByFactor.GetVariableNames(False), iPosition:=0) + clsBarAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) + clsPieAesFunction.AddParameter("fill", clsRFunctionParameter:=clsForecatsReverseValue, iPosition:=2) + Case strNone + clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) + End Select + End If End If End Sub Private Sub ChangeParameterName() + clsBaseOperator.RemoveParameterByName("geom_lollipop") clsBarAesFunction.RemoveParameterByName("x") clsBarAesFunction.RemoveParameterByName("y") clsPieAesFunction.RemoveParameterByName("x") clsPieAesFunction.RemoveParameterByName("y") - clsBaseOperator.RemoveParameterByName("geom_lollipop") + clsPieAesFunction.RemoveParameterByName("fill") + clsRggplotFunction.RemoveParameterByName("mapping") + clsRggplotFunction.RemoveParameterByName("aes") + clsGeomLollipopAesFunction.RemoveParameterByName("x") + clsGeomLollipopAesFunction.RemoveParameterByName("y") + clsGeomLollipopAesFunction.RemoveParameterByName("fill") If rdoValue.Checked Then clsBarAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) clsBarAesFunction.AddParameter("y", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) clsPieAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) clsPieAesFunction.AddParameter("y", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) - clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) clsPieAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) + clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsBarAesFunction, iPosition:=1) + If ucrChkPolarCoordinates.Checked Then + clsRggplotFunction.RemoveParameterByName("mapping") + clsRggplotFunction.AddParameter("aes", clsRFunctionParameter:=clsPieAesFunction, iPosition:=1, bIncludeArgumentName:=False) + End If + clsGeomLollipopAesFunction.AddParameter("x", ucrReceiverX.GetVariableNames(False), iPosition:=0) + clsGeomLollipopAesFunction.AddParameter("y", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsGeomLollipopAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=2) clsRgeomBarFunction1.AddParameter("stat", Chr(34) & "identity" & Chr(34), iPosition:=2) clsRgeomBarFunction2.AddParameter("stat", Chr(34) & "identity" & Chr(34), iPosition:=1) clsRgeomBarFunction.AddParameter("stat", Chr(34) & "identity" & Chr(34), iPosition:=1) + clsBaseOperator.AddParameter("geom_bar", clsRFunctionParameter:=clsRgeomBarFunction, iPosition:=2) clsBaseOperator.RemoveParameterByName("geom_treemap") clsBaseOperator.RemoveParameterByName("geom_treemap_text") clsBaseOperator.RemoveParameterByName("geom_text_wordcloud") @@ -868,43 +966,53 @@ Public Class dlgBarAndPieChart If ucrReceiverByFactor.IsEmpty Then clsBarAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=2) clsPieAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=2) + clsRgeomBarFunction.RemoveParameterByName("position") End If If ucrChkLollipop.Checked Then + clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomLollipopAesFunction, iPosition:=1) clsBaseOperator.AddParameter("geom_lollipop", clsRFunctionParameter:=clsGeomLollipopFunction, iPosition:=2) clsBaseOperator.RemoveParameterByName("geom_bar") End If - If ucrChkBacktoback.Checked Then - clsBaseOperator.RemoveParameterByName("geom_bar") - Else - clsBaseOperator.AddParameter("geom_bar", clsRFunctionParameter:=clsRgeomBarFunction, iPosition:=2) - End If ElseIf rdoFrequency.Checked Then - If ucrVariablesAsFactorForBarChart.IsEmpty Then - clsBarAesFunction.AddParameter("x", Chr(34) & Chr(34), iPosition:=0) - clsPieAesFunction.AddParameter("x", Chr(34) & Chr(34), iPosition:=0) - End If - If ucrReceiverByFactor.IsEmpty Then - clsBarAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=1) - clsPieAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=1) + clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsBarAesFunction, iPosition:=1) + If ucrChkPolarCoordinates.Checked Then + clsRggplotFunction.RemoveParameterByName("mapping") + clsRggplotFunction.AddParameter("aes", clsRFunctionParameter:=clsPieAesFunction, iPosition:=1, bIncludeArgumentName:=False) + Else + If ucrVariablesAsFactorForBarChart.IsEmpty Then + clsBarAesFunction.AddParameter("x", Chr(34) & Chr(34), iPosition:=0) + clsPieAesFunction.AddParameter("x", Chr(34) & Chr(34), iPosition:=0) + Else + clsBarAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=1) + End If + If ucrReceiverByFactor.IsEmpty Then + clsBarAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=1) + clsPieAesFunction.AddParameter("fill", Chr(34) & Chr(34), iPosition:=1) + clsRgeomBarFunction.RemoveParameterByName("position") + Else + clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) + clsPieAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) + End If + clsRgeomBarFunction1.AddParameter("stat", Chr(34) & "count" & Chr(34), iPosition:=2) + clsRgeomBarFunction.AddParameter("stat", Chr(34) & "count" & Chr(34), iPosition:=1) + clsRgeomBarFunction2.RemoveParameterByName("stat") End If - clsBarAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) - clsPieAesFunction.AddParameter("x", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) - clsBarAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) - clsPieAesFunction.AddParameter("fill", ucrReceiverByFactor.GetVariableNames(False), iPosition:=1) - clsRgeomBarFunction1.AddParameter("stat", Chr(34) & "count" & Chr(34), iPosition:=2) clsRgeomBarFunction.AddParameter("stat", Chr(34) & "count" & Chr(34), iPosition:=1) - clsRgeomBarFunction2.RemoveParameterByName("stat") + clsBaseOperator.AddParameter("geom_bar", clsRFunctionParameter:=clsRgeomBarFunction, iPosition:=2) clsBaseOperator.RemoveParameterByName("geom_treemap") clsBaseOperator.RemoveParameterByName("geom_text_wordcloud") ElseIf rdoTreeMap.Checked Then clsBaseOperator.RemoveParameterByName("geom_bar") clsBaseOperator.RemoveParameterByName("geom_text") clsBaseOperator.RemoveParameterByName("geom_text_wordcloud") + clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTreemapAesFunction, iPosition:=1) clsBaseOperator.AddParameter("geom_treemap", clsRFunctionParameter:=clsGeomTreemapFunction, iPosition:=2) ElseIf rdoWordCloud.Checked Then clsBaseOperator.RemoveParameterByName("geom_treemap") clsBaseOperator.RemoveParameterByName("geom_treemap_text") clsBaseOperator.RemoveParameterByName("geom_bar") + clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTextWordcloudAesFunction, iPosition:=1) clsBaseOperator.AddParameter("geom_text_wordcloud", clsRFunctionParameter:=clsGeomTextWordcloudFunction, iPosition:=2) If ucrChkIncreaseSize.Checked Then clsBaseOperator.AddParameter("scale_size_area", clsRFunctionParameter:=clsScaleSizeAreaFunction, iPosition:=3) @@ -924,8 +1032,7 @@ Public Class dlgBarAndPieChart ChangeParameterName() If rdoTreeMap.Checked Then ucrReceiverArea.SetMeAsReceiver() - End If - If rdoWordCloud.Checked Then + ElseIf rdoWordCloud.Checked Then ucrReceiverWordcloudLabel.SetMeAsReceiver() End If End Sub @@ -941,7 +1048,7 @@ Public Class dlgBarAndPieChart End Sub Private Sub ucrChkBacktoback_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkBacktoback.ControlValueChanged, - ucrVariablesAsFactorForBarChart.ControlValueChanged, ucrReceiverX.ControlValueChanged + ucrVariablesAsFactorForBarChart.ControlValueChanged, ucrReceiverX.ControlValueChanged, ucrPnlOptions.ControlValueChanged If rdoFrequency.Checked OrElse rdoValue.Checked Then clsBaseOperator.RemoveParameterByName("geom_bar1") clsBaseOperator.RemoveParameterByName("geom_bar2") @@ -966,11 +1073,11 @@ Public Class dlgBarAndPieChart If rdoValue.Checked Then clsAesFunction1.AddParameter("y", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) clsAesFunction2.AddParameter("y", "-" & ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) - clsRgeomBarFunction2.AddParameter("aes", clsRFunctionParameter:=clsAesFunction1, iPosition:=1, bIncludeArgumentName:=False) - clsRgeomBarFunction1.AddParameter("aes", clsRFunctionParameter:=clsAesFunction2, iPosition:=1, bIncludeArgumentName:=False) + clsRgeomBarFunction2.AddParameter("aes", clsRFunctionParameter:=clsAesFunction1, iPosition:=1) + clsRgeomBarFunction1.AddParameter("aes", clsRFunctionParameter:=clsAesFunction2, iPosition:=1) Else clsAesFunction1.AddParameter("y", "..count..*(-1)", iPosition:=0) - clsRgeomBarFunction1.AddParameter("aes", clsRFunctionParameter:=clsAesFunction1, iPosition:=1, bIncludeArgumentName:=False) + clsRgeomBarFunction1.AddParameter("aes", clsRFunctionParameter:=clsAesFunction1, iPosition:=1) End If End If End If @@ -978,19 +1085,16 @@ Public Class dlgBarAndPieChart SetGeomTextOptions() End Sub - Private Sub ucrChkPolarCoordinates_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkPolarCoordinates.ControlValueChanged, ucrPnlPolar.ControlValueChanged + Private Sub ucrChkPolarCoordinates_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkPolarCoordinates.ControlValueChanged, ucrPnlPolar.ControlValueChanged, + ucrChkReorderValue.ControlValueChanged, ucrChkReorderFrequency.ControlValueChanged, ucrChkAddLabelsText.ControlValueChanged + ' adding coordpolar geom clsBaseOperator.RemoveParameterByName("coordpolar") ChangeParameterName() If Not rdoDonut.Checked OrElse Not ucrChkPolarCoordinates.Checked Then clsBaseOperator.RemoveParameterByName("scale") End If - If Not rdoDonut.Checked OrElse Not rdoPie.Checked Then - ChangeParameterName() - End If If ucrChkPolarCoordinates.Checked Then ucrChkBacktoback.Checked = Not ucrChkPolarCoordinates.Checked - clsRggplotFunction.RemoveParameterByName("mapping") - clsRggplotFunction.AddParameter("aes", clsRFunctionParameter:=clsPieAesFunction, iPosition:=1, bIncludeArgumentName:=False) If rdoDonut.Checked Then clsBaseOperator.AddParameter("scale", clsRFunctionParameter:=clsScaleXdiscretFunction, iPosition:=4, bIncludeArgumentName:=False) End If @@ -1024,10 +1128,13 @@ Public Class dlgBarAndPieChart End If If rdoFrequency.Checked Then clsGeomTextFunction.AddParameter("stat", Chr(34) & "count" & Chr(34), iPosition:=0) - clsLabelAesFunction.AddParameter("label", "..count..", iPosition:=0) + If ucrChkAddLabelsText.Checked AndAlso + clsTextAesFunction.clsParameters.FindIndex(Function(x) x.strArgumentName = "label") < 0 Then + clsTextAesFunction.AddParameter("label", "..count..", iPosition:=0) + End If Else clsGeomTextFunction.RemoveParameterByName("stat") - clsLabelAesFunction.AddParameter("label", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) + clsTextAesFunction.AddParameter("label", ucrVariablesAsFactorForBarChart.GetVariableNames(False), iPosition:=0) End If End Sub @@ -1052,5 +1159,4 @@ Public Class dlgBarAndPieChart clsBaseOperator.RemoveParameterByName("geom_treemap_text") End If End Sub - End Class \ No newline at end of file diff --git a/instat/dlgDeleteDataFrames.vb b/instat/dlgDeleteDataFrames.vb index c9a6bc31797..008e12be7fe 100644 --- a/instat/dlgDeleteDataFrames.vb +++ b/instat/dlgDeleteDataFrames.vb @@ -31,13 +31,12 @@ Public Class dlgDeleteDataFrames SetDefaults() End If ReopenDialog() + SetRCodeForControls(bReset) If bUseSelectedDataFrame Then SetDefaultDataFrame() End If - SetRCodeForControls(bReset) bReset = False TestOKEnabled() - CountLevels() autoTranslate(Me) End Sub @@ -64,7 +63,7 @@ Public Class dlgDeleteDataFrames End Sub Private Sub SetRCodeForControls(bReset As Boolean) - SetRCode(Me, ucrBase.clsRsyntax.clsBaseFunction, bReset) + ucrReceiverDataFrames.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset) End Sub Private Sub TestOKEnabled() @@ -110,11 +109,5 @@ Public Class dlgDeleteDataFrames Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverDataFrames.ControlContentsChanged TestOKEnabled() - CountLevels() - End Sub - - Private Sub CountLevels() - lblDeleteNumber.Text = " " & ucrReceiverDataFrames.Count - lblDeleteNumber.Visible = ucrReceiverDataFrames.Count > 0 End Sub End Class \ No newline at end of file diff --git a/instat/dlgOneVariableSummarise.vb b/instat/dlgOneVariableSummarise.vb index 2085628dc26..056dd0c575f 100644 --- a/instat/dlgOneVariableSummarise.vb +++ b/instat/dlgOneVariableSummarise.vb @@ -270,7 +270,6 @@ Public Class dlgOneVariableSummarise ucrChkOmitMissing.AddAdditionalCodeParameterPair(clsSummaryTableFunction, New RParameter("na.rm", iNewPosition:=2), iAdditionalPairNo:=1) ucrSaveSummary.AddAdditionalRCode(clsSummaryFunction, iAdditionalPairNo:=1) ucrSaveSummary.AddAdditionalRCode(clsJoiningPipeOperator, iAdditionalPairNo:=2) - ucrNudMaxSum.SetRCode(clsSummaryFunction, bReset) ucrReceiverOneVarSummarise.SetRCode(clsSummaryFunction, bReset) ucrChkOmitMissing.SetRCode(clsSummaryFunction, bReset) @@ -282,6 +281,7 @@ Public Class dlgOneVariableSummarise If bReset Then ucrChkDisplayMissing.SetRCode(clsDummyFunction, bReset) ucrPnlColumnFactor.SetRCode(clsDummyFunction, bReset) + ucrNudMaxSum.SetRCode(clsSummaryFunction, bReset) End If bRCodeSet = True FillListView() diff --git a/instat/dlgRownamesOrNumbers.vb b/instat/dlgRownamesOrNumbers.vb index 71b4ef06d77..dee1a9c4e04 100644 --- a/instat/dlgRownamesOrNumbers.vb +++ b/instat/dlgRownamesOrNumbers.vb @@ -22,8 +22,10 @@ Public Class dlgRowNamesOrNumbers Private clsGetRowNamesFunction As New RFunction Private clsSetRowNamesFunction As New RFunction Private clsAddKeyFunction As New RFunction - Private clsAsNumericFunction As New RFunction Private clsDummyFunction As New RFunction + Private clsGetVectorFunction As New RFunction + Private clsHmiscFunction As New RFunction + Private Sub dlgRowNamesOrNumbers_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then @@ -33,7 +35,6 @@ Public Class dlgRowNamesOrNumbers If bReset Then SetDefaults() - IdentifyKey() End If SetRCodeForControls(bReset) bReset = False @@ -66,7 +67,7 @@ Public Class dlgRowNamesOrNumbers ucrPnlOverallOptions.AddParameterValuesCondition(rdoResetintoPositiveIntegers, "checked_rdo", "reset_row") ucrPnlOverallOptions.AddParameterValuesCondition(rdoSortbyRowNames, "checked_rdo", "sort_row") - ucrPnlOverallOptions.AddToLinkedControls({ucrNewColumnName, ucrChkMakeColumnIntoKey}, {rdoCopyRowNamesIntoFirstColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlOverallOptions.AddToLinkedControls({ucrNewColumnName, ucrChkMakeColumnIntoKey}, {rdoCopyRowNamesIntoFirstColumn}, bNewLinkedHideIfParameterMissing:=True) ucrPnlOverallOptions.AddToLinkedControls(ucrReceiverRowNames, {rdoSetRowNamesFromColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlOverallOptions.AddToLinkedControls(ucrPnlSortOptions, {rdoSortbyRowNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlOverallOptions.AddToLinkedControls(ucrChkAsNumeric, {rdoSortbyRowNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) @@ -92,7 +93,7 @@ Public Class dlgRowNamesOrNumbers ucrChkMakeColumnIntoKey.SetText("Make the Column a Key for the Data Frame") ucrChkMakeColumnIntoKey.AddParameterValuesCondition(True, "add_key", "TRUE") ucrChkMakeColumnIntoKey.AddParameterValuesCondition(False, "add_key", "FALSE") - IdentifyKey() + 'ucrNewColumnName ucrNewColumnName.SetIsComboBox() ucrNewColumnName.SetPrefix("row") @@ -106,25 +107,31 @@ Public Class dlgRowNamesOrNumbers clsAddKeyFunction = New RFunction clsDummyFunction = New RFunction clsSetRowNamesFunction = New RFunction - clsAsNumericFunction = New RFunction + clsGetVectorFunction = New RFunction + clsHmiscFunction = New RFunction + ucrNewColumnName.Reset() ucrSelectorRowNames.Reset() ucrBase.clsRsyntax.lstAfterCodes.Clear() clsDummyFunction.AddParameter("checked_rdo", "copy_row", iPosition:=1) - clsDummyFunction.AddParameter("add_key", "FALSE", iPosition:=2) + clsDummyFunction.AddParameter("add_key", "TRUE", iPosition:=2) clsAddKeyFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_key") - clsAsNumericFunction.SetRCommand("as.numeric") - clsAsNumericFunction.AddParameter("x", clsRFunctionParameter:=clsGetRowNamesFunction, iPosition:=0) + clsGetVectorFunction.SetRCommand("what=c") + clsGetVectorFunction.AddParameter("vector", Chr(34) & "vector" & Chr(34), bIncludeArgumentName:=False) + + clsHmiscFunction.SetPackageName("Hmisc") + clsHmiscFunction.SetRCommand("all.is.numeric") + clsHmiscFunction.AddParameter("row", clsRFunctionParameter:=clsGetRowNamesFunction, bIncludeArgumentName:=False, iPosition:=0) + clsHmiscFunction.AddParameter("vector", clsRFunctionParameter:=clsGetVectorFunction, bIncludeArgumentName:=False, iPosition:=1) clsGetRowNamesFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_row_names") clsGetRowNamesFunction.SetAssignTo(strTemp:=ucrNewColumnName.GetText(), strTempDataframe:=ucrSelectorRowNames.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrNewColumnName.GetText()) clsSetRowNamesFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$set_row_names") - ucrBase.clsRsyntax.SetBaseRFunction(clsGetRowNamesFunction) End Sub @@ -137,9 +144,9 @@ Public Class dlgRowNamesOrNumbers ucrChkMakeColumnIntoKey.SetRCode(clsDummyFunction, bReset) ucrPnlOverallOptions.SetRCode(clsDummyFunction, bReset) ucrNewColumnName.AddAdditionalRCode(clsGetRowNamesFunction, bReset) - ucrNewColumnName.SetRCode(clsAsNumericFunction, bReset) + ucrNewColumnName.SetRCode(clsHmiscFunction, bReset) ucrChkAsNumeric.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset) - IdentifyKey() + End Sub Private Sub TestOKEnabled() @@ -165,7 +172,7 @@ Public Class dlgRowNamesOrNumbers Else ucrSelectorRowNames.SetVariablesVisible(False) If rdoCopyRowNamesIntoFirstColumn.Checked Then - ucrBase.clsRsyntax.SetBaseRFunction(clsAsNumericFunction) + ucrBase.clsRsyntax.SetBaseRFunction(clsHmiscFunction) clsDummyFunction.AddParameter("checked_rdo", "copy_row", iPosition:=1) ElseIf rdoResetintoPositiveIntegers.Checked Then ucrBase.clsRsyntax.SetBaseRFunction(clsSetRowNamesFunction) @@ -190,13 +197,8 @@ Public Class dlgRowNamesOrNumbers End If End Sub - Private Sub IdentifyKey() - ucrChkMakeColumnIntoKey.Checked = Not frmMain.clsRLink.IsVariablesMetadata(ucrSelectorRowNames.ucrAvailableDataFrames.cboAvailableDataFrames.Text, "Is_Key") - End Sub - Private Sub ucrChkMakeColumnIntoKey_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkMakeColumnIntoKey.ControlValueChanged AddRemoveKeyFromAfterCodes() - IdentifyKey() End Sub Private Sub ucrNewColumnName_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrNewColumnName.ControlValueChanged @@ -210,6 +212,5 @@ Public Class dlgRowNamesOrNumbers End Sub Private Sub ucrSelectorRowNames_DataFrameChanged() Handles ucrSelectorRowNames.DataFrameChanged - IdentifyKey() End Sub End Class \ No newline at end of file diff --git a/instat/dlgTransposeColumns.vb b/instat/dlgTransposeColumns.vb index a5b04a50f6a..0673dacc656 100644 --- a/instat/dlgTransposeColumns.vb +++ b/instat/dlgTransposeColumns.vb @@ -137,19 +137,24 @@ Public Class dlgTransposeColumns ucrSelectorTransposeColumns.lstAvailableVariable.Columns.Add("Variables") End Sub Private Sub ucrReceiverVariableNames_Enter(sender As Object, e As EventArgs) Handles ucrReceiverVariableNames.Enter - Dim grps As New ListViewGroup ClearSelector() If Not ucrReceiverColumnsToTranspose.IsEmpty Then - If ucrReceiverColumnsToTranspose.GetVariableNamesList(False).Count > 1 Then - grps = New ListViewGroup(key:=ucrSelectorTransposeColumns.ucrAvailableDataFrames.cboAvailableDataFrames.Text, - headerText:=ucrSelectorTransposeColumns.ucrAvailableDataFrames.cboAvailableDataFrames.Text) - ucrSelectorTransposeColumns.lstAvailableVariable.Groups.Add(grps) + '------------------------- + 'todo. this code block below requires more refactoring. + 'it should use the selector functions for adding items instead of accessing the selector controls + Dim arrItems As String() = ucrReceiverColumnsToTranspose.GetVariableNamesList(False) + If arrItems.Count > 1 Then + ucrSelectorTransposeColumns.lstAvailableVariable.Groups.Add(New ListViewGroup( + key:=ucrSelectorTransposeColumns.ucrAvailableDataFrames.cboAvailableDataFrames.Text, + headerText:=ucrSelectorTransposeColumns.ucrAvailableDataFrames.cboAvailableDataFrames.Text)) End If - For j = 0 To ucrReceiverColumnsToTranspose.GetVariableNamesList(False).Count - 1 - ucrSelectorTransposeColumns.lstAvailableVariable.Items.Add(ucrReceiverColumnsToTranspose.GetVariableNamesList(False)(j)) + + For j = 0 To arrItems.Count - 1 + ucrSelectorTransposeColumns.lstAvailableVariable.Items.Add(arrItems(j)) ucrSelectorTransposeColumns.lstAvailableVariable.Items(j).Tag = ucrSelectorTransposeColumns.ucrAvailableDataFrames.cboAvailableDataFrames.Text - ucrSelectorTransposeColumns.lstAvailableVariable.Items(j).ToolTipText = ucrReceiverColumnsToTranspose.GetVariableNamesList(False)(0) + ucrSelectorTransposeColumns.lstAvailableVariable.Items(j).ToolTipText = arrItems(j) Next + '------------------------- End If End Sub Private Sub ucrSelectorTransposeColumns_DataFrameChanged() Handles ucrSelectorTransposeColumns.DataFrameChanged diff --git a/instat/frmMain.vb b/instat/frmMain.vb index 08b5707786c..c65e42af663 100644 --- a/instat/frmMain.vb +++ b/instat/frmMain.vb @@ -80,6 +80,10 @@ Public Class frmMain InitializeComponent() ' Add any initialization after the InitializeComponent() call. + + 'set controls layout + SetupInitialLayout() + clsOutputLogger = New clsOutputLogger clsRLink = New RLink(clsOutputLogger) If RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then @@ -128,8 +132,6 @@ Public Class frmMain ucrOutput.SetLogger(clsOutputLogger) - SetToDefaultLayout() - '--------------------------------------- 'set up R-Instat options (settings) 'load any saved options if available @@ -218,6 +220,114 @@ Public Class frmMain isMaximised = True 'Need to get the windowstate when the application is loaded End Sub + Private Sub SetupInitialLayout() + 'splOverall has 2 panels + 'splOverall.Panel1 contains splExtraWindows + 'splOverall.Panel2 contains splDataOutput + + 'splExtraWindows has 2 panels + 'splExtraWindows.Panel1 contains splMetadata + 'splExtraWindows.Panel2 contains script window + + 'splMetadata has 2 panels + 'splMetadata.Panel1 contains data frame + 'splMetadata.Panel2 contains column metadata + + 'splDataOutput has 2 panels + 'splDataOutput.Panel1 contains data viewer window + 'splDataOutput.Panel2 contains output window + + 'collaspe all the panels initially (on application startup) + splOverall.Panel1Collapsed = True + splOverall.Panel2Collapsed = True + + splExtraWindows.Panel1Collapsed = True + splExtraWindows.Panel2Collapsed = True + + splMetadata.Panel1Collapsed = True + splMetadata.Panel2Collapsed = True + + splDataOutput.Panel1Collapsed = True + splDataOutput.Panel2Collapsed = True + + SetToDefaultLayout() + End Sub + + Private Sub SetToDefaultLayout() + splOverall.SplitterDistance = splOverall.Height / 4 + splDataOutput.SplitterDistance = splDataOutput.Width / 2 + splExtraWindows.SplitterDistance = splExtraWindows.Width / 2 + splMetadata.SplitterDistance = splMetadata.Width / 2 + + mnuViewDataView.Checked = True + mnuViewOutput.Checked = True + mnuViewDataFrameMetadata.Checked = False + mnuViewColumnMetadata.Checked = False + mnuViewLogScript.Checked = False + mnuViewSwapDataAndMetadata.Checked = False + mnuColumnMetadat.Checked = False + mnuDataFrameMetadat.Checked = False + + mnuTbDataView.Checked = True + mnuOutputWindow.Checked = True + mnuLogScript.Checked = False + UpdateLayout() + End Sub + + Public Sub UpdateLayout() + + If Not mnuViewDataView.Checked _ + AndAlso Not mnuViewOutput.Checked _ + AndAlso Not mnuViewColumnMetadata.Checked _ + AndAlso Not mnuViewDataFrameMetadata.Checked _ + AndAlso Not mnuViewLogScript.Checked _ + AndAlso Not mnuViewSwapDataAndMetadata.Checked Then + splOverall.Hide() + Else + splOverall.Show() + + 'determine splOverall contents visibility + + '------------------------------- + 'determine splOverall.Panel1 and it's contents visibility + + If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked OrElse mnuViewLogScript.Checked Then + 'expand panel 1 + splOverall.Panel1Collapsed = False + 'change splOverall.Panel1Collapsed contents visibilty + If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked Then + splMetadata.Panel1Collapsed = Not mnuViewColumnMetadata.Checked + splMetadata.Panel2Collapsed = Not mnuViewDataFrameMetadata.Checked + splExtraWindows.Panel1Collapsed = False + Else + splExtraWindows.Panel1Collapsed = True + End If + 'expand panel 2 based on log script menu item checked status + splExtraWindows.Panel2Collapsed = Not mnuViewLogScript.Checked + Else + splOverall.Panel1Collapsed = True + End If + '------------------------------- + + '------------------------------- + 'determine splOverall.Panel2 and it's contents visibility + + If mnuViewDataView.Checked OrElse mnuViewOutput.Checked Then + splDataOutput.Panel1Collapsed = Not mnuViewDataView.Checked + splDataOutput.Panel2Collapsed = Not mnuViewOutput.Checked + splOverall.Panel2Collapsed = False + Else + splOverall.Panel2Collapsed = True + End If + '------------------------------- + + + End If + mnuTbDataView.Checked = mnuViewDataView.Checked + mnuOutputWindow.Checked = mnuViewOutput.Checked + mnuLogScript.Checked = mnuViewLogScript.Checked + End Sub + Private Function GetSavedRInstatOptions() As InstatOptions Dim clsInstatOptions As InstatOptions = Nothing Dim strFilePath As String = Path.Combine(strAppDataPath, strInstatOptionsFile) @@ -426,29 +536,21 @@ Public Class frmMain End If End Sub - - - Private Sub SetToDefaultLayout() - splOverall.SplitterDistance = splOverall.Height / 4 - splDataOutput.SplitterDistance = splDataOutput.Width / 2 - splExtraWindows.SplitterDistance = splExtraWindows.Width / 2 - splMetadata.SplitterDistance = splMetadata.Width / 2 - - mnuViewDataView.Checked = True - mnuViewOutput.Checked = True - mnuViewDataFrameMetadata.Checked = False - mnuViewColumnMetadata.Checked = False - mnuViewLogScript.Checked = False - mnuViewSwapDataAndMetadata.Checked = False - mnuColumnMetadat.Checked = False - mnuDataFrameMetadat.Checked = False - - mnuTbDataView.Checked = True - mnuOutputWindow.Checked = True - mnuLogScript.Checked = False - UpdateLayout() + Private Sub UpdateSwapDataAndMetadata() + If mnuViewSwapDataAndMetadata.Checked Then + splDataOutput.Panel1.Controls.Add(ucrColumnMeta) + splMetadata.Panel1.Controls.Add(ucrDataViewer) + mnuViewColumnMetadata.Text = "Data View" + mnuViewDataView.Text = "Column Metadata" + Else + splDataOutput.Panel1.Controls.Add(ucrDataViewer) + splMetadata.Panel1.Controls.Add(ucrColumnMeta) + mnuViewColumnMetadata.Text = "Column Metadata" + mnuViewDataView.Text = "Data View" + End If End Sub + Public Sub SaveInstatOptions(strFilePath As String) Dim serializer As New BinaryFormatter() @@ -550,62 +652,6 @@ Public Class frmMain dlgName.ShowDialog() End Sub - Public Sub UpdateLayout() - If Not mnuViewDataView.Checked _ - AndAlso Not mnuViewOutput.Checked _ - AndAlso Not mnuViewColumnMetadata.Checked _ - AndAlso Not mnuViewDataFrameMetadata.Checked _ - AndAlso Not mnuViewLogScript.Checked _ - AndAlso Not mnuViewSwapDataAndMetadata.Checked Then - splOverall.Hide() - Else - splOverall.Show() - If mnuViewDataView.Checked OrElse mnuViewOutput.Checked Then - splOverall.Panel2Collapsed = False - splDataOutput.Panel1Collapsed = Not mnuViewDataView.Checked - splDataOutput.Panel2Collapsed = Not mnuViewOutput.Checked - Else - splOverall.Panel2Collapsed = True - End If - If mnuViewColumnMetadata.Checked _ - OrElse mnuViewDataFrameMetadata.Checked _ - OrElse mnuViewLogScript.Checked Then - splOverall.Panel1Collapsed = False - If mnuViewColumnMetadata.Checked OrElse mnuViewDataFrameMetadata.Checked Then - splExtraWindows.Panel1Collapsed = False - splMetadata.Panel1Collapsed = Not mnuViewColumnMetadata.Checked - splMetadata.Panel2Collapsed = Not mnuViewDataFrameMetadata.Checked - Else - splExtraWindows.Panel1Collapsed = True - End If - If mnuViewLogScript.Checked Then - splExtraWindows.Panel2Collapsed = False - Else - splExtraWindows.Panel2Collapsed = True - End If - Else - splOverall.Panel1Collapsed = True - End If - End If - mnuTbDataView.Checked = mnuViewDataView.Checked - mnuOutputWindow.Checked = mnuViewOutput.Checked - mnuLogScript.Checked = mnuViewLogScript.Checked - End Sub - - Private Sub UpdateSwapDataAndMetadata() - If mnuViewSwapDataAndMetadata.Checked Then - splDataOutput.Panel1.Controls.Add(ucrColumnMeta) - splMetadata.Panel1.Controls.Add(ucrDataViewer) - mnuViewColumnMetadata.Text = "Data View" - mnuViewDataView.Text = "Column Metadata" - Else - splDataOutput.Panel1.Controls.Add(ucrDataViewer) - splMetadata.Panel1.Controls.Add(ucrColumnMeta) - mnuViewColumnMetadata.Text = "Column Metadata" - mnuViewDataView.Text = "Data View" - End If - End Sub - Private Sub mnuWindowDataFrame_Click(sender As Object, e As EventArgs) Handles mnuViewDataFrameMetadata.Click mnuViewDataFrameMetadata.Checked = Not mnuViewDataFrameMetadata.Checked mnuDataFrameMetadat.Checked = mnuViewDataFrameMetadata.Checked @@ -640,7 +686,7 @@ Public Class frmMain End Sub Private Sub mnuPrepareSheetColumnMetadata_Click(sender As Object, e As EventArgs) Handles mnuViewColumnMetadata.Click - mnuViewColumnMetadata.Checked = True + mnuViewColumnMetadata.Checked = Not mnuViewColumnMetadata.Checked UpdateLayout() End Sub diff --git a/instat/sdgCalculationsSummmary.vb b/instat/sdgCalculationsSummmary.vb index 8d4d9683fe7..499067c9172 100644 --- a/instat/sdgCalculationsSummmary.vb +++ b/instat/sdgCalculationsSummmary.vb @@ -351,8 +351,10 @@ Public Class sdgCalculationsSummmary clsCalculationFunction.RemoveParameterByName("function_exp") End If - If ucrCalcSummary.ucrSelectorForCalculations.lstVariablesInReceivers.Count > 0 Then - clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(ucrCalcSummary.ucrSelectorForCalculations.lstVariablesInReceivers, ucrCalcSummary.ucrSelectorForCalculations)) + If Not ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.IsEmpty Then + clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList( + ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.GetVariableNamesList(bWithQuotes:=False), + ucrCalcSummary.ucrSelectorForCalculations)) Else clsCalculationFunction.RemoveParameterByName("calculated_from") End If @@ -364,29 +366,22 @@ Public Class sdgCalculationsSummmary If ucrReceiverByOrSort.IsEmpty Then clsCalculationFunction.RemoveParameterByName("calculated_from") Else - clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(ucrSelectorBy.lstVariablesInReceivers, ucrSelectorBy)) + clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList( + ucrSelectorBy.CurrentReceiver.GetVariableNamesList(bWithQuotes:=False), ucrSelectorBy)) End If End If End Sub '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 List(Of Tuple(Of String, String)), ucrCurrentSelector As ucrSelectorByDataFrame) As String + Private Function CreateCalcFromList(lstVariables As String(), ucrCurrentSelector As ucrSelectorByDataFrame) As String Dim strCalcFromList As String - Dim strColumn As String - Dim strDataFrame As String strCalcFromList = "list(" For i = 0 To lstVariables.Count - 1 - strColumn = lstVariables(i).Item1 - If lstVariables(i).Item1 = "" Then - strDataFrame = ucrCurrentSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text - Else - strDataFrame = lstVariables(i).Item2 - End If If i > 0 Then strCalcFromList = strCalcFromList & "," End If - strCalcFromList = strCalcFromList & strDataFrame & " = " & Chr(34) & strColumn & Chr(34) + strCalcFromList = strCalcFromList & ucrCurrentSelector.strCurrentDataFrame & " = " & Chr(34) & lstVariables(i) & Chr(34) Next strCalcFromList = strCalcFromList & ")" Return strCalcFromList @@ -399,7 +394,9 @@ Public Class sdgCalculationsSummmary clsCalculationFunction.RemoveParameterByName("calculated_from") Else clsCalculationFunction.AddParameter("function_exp", Chr(34) & ucrDefineFilter.ucrFilterPreview.GetText() & Chr(34)) - clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(ucrDefineFilter.ucrSelectorForFitler.lstVariablesInReceivers, ucrDefineFilter.ucrSelectorForFitler)) + clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList( + ucrDefineFilter.ucrSelectorForFitler.CurrentReceiver.GetVariableNamesList(bWithQuotes:=False), + ucrDefineFilter.ucrSelectorForFitler)) End If End If End Sub diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 14f4f823c73..1d2fdc62855 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1125,12 +1125,17 @@ DataSheet$set("public", "append_to_variables_metadata", function(col_names, prop DataSheet$set("public", "append_to_changes", function(value) { - if(missing(value)) { - stop("value arguements must be specified.") - } - else { - private$changes[[length(private$changes)+1]] <- value - } + #functionality disabled temporarily + #see PR #8465 and issue #7161 comments + + #if(missing(value)) { + # stop("value arguements must be specified.") + #}else { + #see comments in issue #7161 that explain more about why list() was used + #primary reason was because of performance when it comes to wide data sets + #private$changes[[length(private$changes)+1]] <- value + #private$changes<-list(private$changes, value) + #} } ) diff --git a/instat/ucrColumnMetadata.vb b/instat/ucrColumnMetadata.vb index c56717bbd3b..775d1a1b6c4 100644 --- a/instat/ucrColumnMetadata.vb +++ b/instat/ucrColumnMetadata.vb @@ -31,6 +31,54 @@ Public Class ucrColumnMetadata Private strDataTypeLabel As String = "DataType" Private strLabelsLabel As String = "labels" Private strLabelsScientific As String = "Scientific" + Private _Refreshed As Boolean = False + Private bWideDataSetPromptResponse As DialogResult = DialogResult.None + + Public Sub New() + + ' This call is required by the designer. + InitializeComponent() + + ' Add any initialization after the InitializeComponent() call. + SetupInitialLayoutAndGrid() + End Sub + + Private Sub ucrColumnMetadata_Load(sender As Object, e As EventArgs) Handles Me.Load + mnuInsertColsAfter.Visible = False + mnuInsertColsBefore.Visible = False + autoTranslate(Me) + End Sub + + Private Sub ucrColumnMetadata_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged + 'todo. a temporary useful fix because of wide data sets + 'the grid may not have the latest contents because of being hidden + 'once 'paging' feature is implemented, this block can be removed. + RefreshGridData() + End Sub + + Private Sub SetupInitialLayoutAndGrid() + lstNonEditableColumns.AddRange({"class", "labels", "Is_Hidden", "Is_Key", "Is_Calculated", "Has_Dependants", "Dependent_Columns", "Calculated_By", "Dependencies", "Colour"}) + + 'DEBUG + ' If True Then + If RuntimeInformation.IsOSPlatform(OSPlatform.Linux) Then + _grid = ucrLinuxGrid + tlpTableContainer.ColumnStyles(0).SizeType = SizeType.Percent + tlpTableContainer.ColumnStyles(0).Width = 100 + tlpTableContainer.ColumnStyles(1).SizeType = SizeType.Absolute + tlpTableContainer.ColumnStyles(1).Width = 0 + Else + _grid = ucrReoGrid + tlpTableContainer.ColumnStyles(0).SizeType = SizeType.Absolute + tlpTableContainer.ColumnStyles(0).Width = 0 + tlpTableContainer.ColumnStyles(1).SizeType = SizeType.Percent + tlpTableContainer.ColumnStyles(1).Width = 100 + End If + _grid.SetNonEditableColumns(lstNonEditableColumns) + _grid.SetContextmenuStrips(Nothing, cellContextMenuStrip, columnContextMenuStrip, statusColumnMenu) + AddHandler _grid.EditValue, AddressOf EditValue + AddHandler _grid.DeleteLabels, AddressOf DeleteLables + End Sub Public WriteOnly Property DataBook() As clsDataBook Set(ByVal value As clsDataBook) @@ -39,12 +87,6 @@ Public Class ucrColumnMetadata End Set End Property - Private Sub frmVariables_Load(sender As Object, e As EventArgs) Handles Me.Load - loadForm() - mnuInsertColsAfter.Visible = False - mnuInsertColsBefore.Visible = False - End Sub - Private Function GetCurrentDataFrameFocus() As clsDataFrame Return _clsDataBook.GetDataFrame(_grid.CurrentWorksheet.Name) End Function @@ -54,10 +96,32 @@ Public Class ucrColumnMetadata Exit Sub End If - _grid.CurrentWorksheet = fillWorksheet - _grid.UpdateWorksheetStyle(fillWorksheet) - _grid.AddColumns(dataFrame.clsColumnMetaData) - _grid.AddRowData(dataFrame.clsColumnMetaData) + Dim bFillData As Boolean = True + + 'check for wide data sets and prompt users about it + 'todo. this check is necessary for wide data sets + 'once the "paging" feature is implemented, then the check can be removed. + 'see issue #7161 and PR #8465 for more discussions + If dataFrame.clsColumnMetaData.iRowCount > 1000 Then + 'if not asked or no response before then prompt for a response + If bWideDataSetPromptResponse = DialogResult.None Then + bWideDataSetPromptResponse = MessageBox.Show(Me, "Are you sure you need wide data set(s) column metadata? If so, be patient. It, will be slow to load the first time", "Wide Data Set(s) Detected", + MessageBoxButtons.YesNo, MessageBoxIcon.Warning) + End If + + 'if response is no or no response given then don't fill the worksheet with data + If bWideDataSetPromptResponse = DialogResult.No Then + bFillData = False + End If + End If + + If bFillData Then + _grid.CurrentWorksheet = fillWorksheet + _grid.UpdateWorksheetStyle(fillWorksheet) + _grid.AddColumns(dataFrame.clsColumnMetaData) + _grid.AddRowData(dataFrame.clsColumnMetaData) + End If + dataFrame.clsColumnMetaData.HasChanged = False End Sub @@ -87,38 +151,17 @@ Public Class ucrColumnMetadata End Sub Public Sub RefreshGridData() - If _clsDataBook IsNot Nothing Then + 'todo. a temporary useful fix because of wide data sets + 'only refresh the grid when the data book is initialised and the grid is visible + 'displaying more than a 1000 rows takes a lot of time + 'in the long term, this window should have 'paging' feature similar to the data viewer to display 11000 rows only. + If _clsDataBook IsNot Nothing And Visible Then _grid.RemoveOldWorksheets() AddAndUpdateWorksheets() _grid.bVisible = _clsDataBook.DataFrames.Count > 0 End If End Sub - Private Sub loadForm() - lstNonEditableColumns.AddRange({"class", "labels", "Is_Hidden", "Is_Key", "Is_Calculated", "Has_Dependants", "Dependent_Columns", "Calculated_By", "Dependencies", "Colour"}) - - 'DEBUG - ' If True Then - If RuntimeInformation.IsOSPlatform(OSPlatform.Linux) Then - _grid = ucrLinuxGrid - tlpTableContainer.ColumnStyles(0).SizeType = SizeType.Percent - tlpTableContainer.ColumnStyles(0).Width = 100 - tlpTableContainer.ColumnStyles(1).SizeType = SizeType.Absolute - tlpTableContainer.ColumnStyles(1).Width = 0 - Else - _grid = ucrReoGrid - tlpTableContainer.ColumnStyles(0).SizeType = SizeType.Absolute - tlpTableContainer.ColumnStyles(0).Width = 0 - tlpTableContainer.ColumnStyles(1).SizeType = SizeType.Percent - tlpTableContainer.ColumnStyles(1).Width = 100 - End If - _grid.SetNonEditableColumns(lstNonEditableColumns) - _grid.SetContextmenuStrips(Nothing, cellContextMenuStrip, columnContextMenuStrip, statusColumnMenu) - AddHandler _grid.EditValue, AddressOf EditValue - AddHandler _grid.DeleteLabels, AddressOf DeleteLables - autoTranslate(Me) - End Sub - Public Sub SetCurrentDataFrame(strDataName As String) _grid.SetCurrentDataFrame(strDataName) End Sub @@ -131,7 +174,7 @@ Public Class ucrColumnMetadata Dim clsDeleteLabelsFunction As New RFunction If strColumnName = strLabelsLabel Then - If MsgBox("This will delete the selected label(s) and replace with (NA)." & + If MsgBox("This will delete the selected label(s) and replace them with (NA)." & Environment.NewLine & "Continue?", MessageBoxButtons.YesNo, "Delete Labels") = DialogResult.Yes Then @@ -307,7 +350,7 @@ Public Class ucrColumnMetadata Return selectedDataframeColumns End Function - Private Function IsOnlyOneDataframeColumnSeleted() As Boolean + Private Function IsOnlyOneDataframeColumnSelected() As Boolean Return _grid.GetSelectedRows().Count = 1 End Function @@ -370,7 +413,7 @@ Public Class ucrColumnMetadata End Sub Private Sub columnContextMenuStrip_Opening(sender As Object, e As CancelEventArgs) Handles columnContextMenuStrip.Opening - If IsOnlyOneDataFrameColumnSeleted() Then + If IsOnlyOneDataframeColumnSelected() Then mnuLevelsLabels.Enabled = IsFirstSelectedDataFrameColumnAFactor() mnuDeleteCol.Text = GetTranslation("Delete Column") mnuInsertColsBefore.Text = GetTranslation("Insert 1 Column Before") @@ -468,4 +511,5 @@ Public Class ucrColumnMetadata Private Sub mnuHelp1_Click(sender As Object, e As EventArgs) Handles mnuHelp1.Click, mnuHelp2.Click Help.ShowHelp(Me, frmMain.strStaticPath & "\" & frmMain.strHelpFilePath, HelpNavigator.TopicId, "543") End Sub + End Class \ No newline at end of file diff --git a/instat/ucrDataFrameMetadata.vb b/instat/ucrDataFrameMetadata.vb index c8be6e85a97..821ff413084 100644 --- a/instat/ucrDataFrameMetadata.vb +++ b/instat/ucrDataFrameMetadata.vb @@ -30,6 +30,20 @@ Public Class ucrDataFrameMetadata Private clsViewDataFrame As New RFunction Private clsGetDataFrame As New RFunction + Public Sub New() + ' This call is required by the designer. + InitializeComponent() + + ' Add any initialization after the InitializeComponent() call. + SetupInitialLayoutAndGrid() + End Sub + Private Sub ucrDataFrameMetadata_Load(sender As Object, e As EventArgs) Handles Me.Load + clsViewDataFrame.SetRCommand("View") + clsGetDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") + clsHideDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$append_to_dataframe_metadata") + End Sub + + Public WriteOnly Property DataBook() As clsDataBook Set(ByVal value As clsDataBook) _clsDataBook = value @@ -37,14 +51,7 @@ Public Class ucrDataFrameMetadata End Set End Property - Private Sub frmMetaData_Load(sender As Object, e As EventArgs) Handles Me.Load - LoadForm() - clsViewDataFrame.SetRCommand("View") - clsGetDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") - clsHideDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$append_to_dataframe_metadata") - End Sub - - Private Sub LoadForm() + Private Sub SetupInitialLayoutAndGrid() lstNonEditableColumns.AddRange({"class", "Is_Hidden", "Row_Count", "Column_Count", "Is_Linkable", "Is_Calculated"}) 'Debug diff --git a/instat/ucrReceiver.vb b/instat/ucrReceiver.vb index 1e6affcfddd..8594abe6044 100644 --- a/instat/ucrReceiver.vb +++ b/instat/ucrReceiver.vb @@ -14,6 +14,7 @@ ' You should have received a copy of the GNU General Public License ' along with this program. If not, see . +Imports System.Windows.Documents Imports instat Imports instat.Translations Imports RDotNet @@ -98,7 +99,7 @@ Public Class ucrReceiver bUpdateRCodeFromControl = True End Sub - Public Overridable Sub AddSelected() + Public Overridable Sub AddSelectedSelectorVariables() End Sub @@ -133,7 +134,7 @@ Public Class ucrReceiver End Sub 'This refers to the selector list of columns - Public Overridable Sub RemoveAnyVariablesNotInList() + Public Overridable Sub RemoveAnyVariablesNotInSelector() End Sub @@ -150,18 +151,15 @@ Public Class ucrReceiver End Property Public Overridable Function GetVariables(Optional bForceAsDataFrame As Boolean = False) As RFunction - Dim clsGetVariablesFunc As New RFunction - Return clsGetVariablesFunc + Return New RFunction End Function Public Overridable Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String - Dim strVarNames As String = "" - Return strVarNames + Return "" End Function Public Overridable Function GetVariableNamesList(Optional bWithQuotes As Boolean = True, Optional strQuotes As String = Chr(34)) As String() - Dim strVarNames As String() = Nothing - Return strVarNames + Return Nothing End Function Public Overridable Sub SetMeAsReceiver() @@ -456,7 +454,7 @@ Public Class ucrReceiver If clsTempParameter IsNot Nothing Then If bChangeParameterValue Then If bParameterIsString AndAlso clsTempParameter.bIsString Then - If strValuesToIgnore Is Nothing OrElse (Not strValuesToIgnore.Contains(clsTempParameter.strArgumentValue)) Then + If (strValuesToIgnore IsNot Nothing AndAlso strValuesToIgnore.Contains(clsTempParameter.strArgumentValue)) OrElse Not String.IsNullOrEmpty(clsTempParameter.strArgumentValue) Then lstCurrentVariables = ExtractItemsFromRList(clsTempParameter.strArgumentValue, strPackageName:=strVariablesListPackageName, strFunctionName:=strVariablesListFunctionName) End If 'TODO how to recover the data frame name in this case @@ -475,16 +473,30 @@ Public Class ucrReceiver End If Clear() If lstCurrentVariables IsNot Nothing Then - For Each strTemp As String In lstCurrentVariables + If Selector IsNot Nothing Then + strTempDataName = Selector.strCurrentDataFrame + End If + If TypeOf Me Is ucrReceiverMultiple Then + 'TODO This only works if the selector is updated before receivers and dialog only uses one data frame! ' Needs to change eventually. - If Selector IsNot Nothing AndAlso strTemp <> "" Then - If strTempDataName = "" Then - strTempDataName = Selector.strCurrentDataFrame - End If + Dim lstItems As New List(Of KeyValuePair(Of String, String)) + For Each strTemp As String In lstCurrentVariables + lstItems.Add(New KeyValuePair(Of String, String)(strTempDataName, strTemp)) + Next + + DirectCast(Me, ucrReceiverMultiple).AddMultiple(lstItems) + RemoveAnyVariablesNotInSelector() 'needed due to the Autofill option + Else + For Each strTemp As String In lstCurrentVariables + 'TODO This only works if the selector is updated before receivers and dialog only uses one data frame! + ' Needs to change eventually. Add(strTemp, strTempDataName) - End If - Next + Next + + End If + + End If End If End If diff --git a/instat/ucrReceiverExpression.vb b/instat/ucrReceiverExpression.vb index a881dd26c51..6916cdf0e80 100644 --- a/instat/ucrReceiverExpression.vb +++ b/instat/ucrReceiverExpression.vb @@ -14,79 +14,78 @@ ' You should have received a copy of the GNU General Public License ' along with this program. If not, see . -Imports RDotNet - -Public Class ucrReceiverExpression - Private lstItemsInExpression As List(Of KeyValuePair(Of String, String)) - Private lstDataFrames As List(Of String) +Imports RDotNet + +Public Class ucrReceiverExpression + Private lstItemsInExpression As List(Of KeyValuePair(Of String, String)) + Private lstDataFrames As List(Of String) Private iCurrentPosition As Integer = 0 - Public Sub New() - ' This call is required by the designer. - InitializeComponent() - - ' Add any initialization after the InitializeComponent() call. - lstItemsInExpression = New List(Of KeyValuePair(Of String, String)) - lstDataFrames = New List(Of String) - End Sub - - Public Overrides Sub AddSelected() - If Selector.lstAvailableVariable.SelectedItems.Count = 1 Then - Add(Selector.lstAvailableVariable.SelectedItems.Item(0).Text, Selector.lstAvailableVariable.SelectedItems.Item(0).Tag) - Else - 'Error? - End If - End Sub - - Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "", Optional bFixReceiver As Boolean = False) - Dim strCurrentItemType As String - Dim kvpItem As KeyValuePair(Of String, String) - - MyBase.Add(strItem, strDataFrame) - - If bTypeSet Then - strCurrentItemType = strType - Else - strCurrentItemType = Selector.GetItemType() - End If - - If cboExpression.Enabled Then - If strCurrentItemType = "column" Then - If strDataFrame = "" Then - SetMeAsReceiver() - For i = 0 To Selector.lstAvailableVariable.Items.Count - 1 - If Selector.lstAvailableVariable.Items(i).Text = strItem Then - strDataFrame = Selector.lstAvailableVariable.Items(i).Tag - End If - Next - End If - End If - If Not lstDataFrames.Contains(strDataFrame) Then - lstDataFrames.Add(strDataFrame) - End If - kvpItem = New KeyValuePair(Of String, String)(strDataFrame, strItem) - AddToItemsInExpressionList(kvpItem) - AddToReceiverAtCursorPosition(strItem) - Selector.AddToVariablesList(strItem, strDataFrame) + Public Sub New() + ' This call is required by the designer. + InitializeComponent() + + ' Add any initialization after the InitializeComponent() call. + lstItemsInExpression = New List(Of KeyValuePair(Of String, String)) + lstDataFrames = New List(Of String) + End Sub + + Public Overrides Sub AddSelectedSelectorVariables() + If Selector.lstAvailableVariable.SelectedItems.Count = 1 Then + Add(Selector.lstAvailableVariable.SelectedItems.Item(0).Text, Selector.lstAvailableVariable.SelectedItems.Item(0).Tag) + Else + 'Error? + End If + End Sub + + Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "", Optional bFixReceiver As Boolean = False) + Dim strCurrentItemType As String + Dim kvpItem As KeyValuePair(Of String, String) + + MyBase.Add(strItem, strDataFrame) + + If bTypeSet Then + strCurrentItemType = strType + Else + strCurrentItemType = Selector.GetItemType() + End If + + If cboExpression.Enabled Then + If strCurrentItemType = "column" Then + If strDataFrame = "" Then + SetMeAsReceiver() + For i = 0 To Selector.lstAvailableVariable.Items.Count - 1 + If Selector.lstAvailableVariable.Items(i).Text = strItem Then + strDataFrame = Selector.lstAvailableVariable.Items(i).Tag + End If + Next + End If + End If + If Not lstDataFrames.Contains(strDataFrame) Then + lstDataFrames.Add(strDataFrame) + End If + kvpItem = New KeyValuePair(Of String, String)(strDataFrame, strItem) + AddToItemsInExpressionList(kvpItem) + AddToReceiverAtCursorPosition(strItem) OnSelectionChanged() 'we need this to run when everything else has run cboExpression.Enabled = Not bFixReceiver - End If + End If End Sub - Private Sub AddToItemsInExpressionList(kvpItem As KeyValuePair(Of String, String)) - If Not lstItemsInExpression.Contains(kvpItem) Then - lstItemsInExpression.Add(kvpItem) - End If - End Sub - - Public Sub AddToReceiverAtPosition(strText As String, iPosition As Integer, Optional iSetCursorBackCharacters As Integer = 0) - cboExpression.Text = cboExpression.Text.Insert(iPosition, strText) + Private Sub AddToItemsInExpressionList(kvpItem As KeyValuePair(Of String, String)) + If Not lstItemsInExpression.Contains(kvpItem) Then + lstItemsInExpression.Add(kvpItem) + End If + End Sub + + Public Sub AddToReceiverAtPosition(strText As String, iPosition As Integer, Optional iSetCursorBackCharacters As Integer = 0) + cboExpression.Text = cboExpression.Text.Insert(iPosition, strText) iCurrentPosition = iPosition + strText.Length - iSetCursorBackCharacters - cboExpression.SelectionStart = iCurrentPosition - cboExpression.SelectedText = "" - 'Adding focus to the function in the Receiver Expreession - cboExpression.Focus() + cboExpression.SelectionStart = iCurrentPosition + cboExpression.SelectedText = "" + 'Adding focus to the function in the Receiver Expreession + cboExpression.Focus() End Sub Public Sub Backspace() @@ -94,25 +93,18 @@ Public Class ucrReceiverExpression cboExpression.Text = Mid(cboExpression.Text, 1, iCurrentPosition - 1) & Mid(cboExpression.Text, iCurrentPosition + 1, Len(cboExpression.Text) - iCurrentPosition + 1) iCurrentPosition = iCurrentPosition - 1 End If - End Sub - - Public Sub AddToReceiverAtCursorPosition(strText As String, Optional iSetCursorBackCharacters As Integer = 0) - AddToReceiverAtPosition(strText, iCurrentPosition, iSetCursorBackCharacters) - End Sub - - Public Overrides Sub RemoveSelected() - Dim kvpItem As KeyValuePair(Of String, String) - - If cboExpression.Enabled Then - If Selector IsNot Nothing Then - For Each kvpItem In lstItemsInExpression - Selector.RemoveFromVariablesList(kvpItem.Value, kvpItem.Key) - Next - End If - cboExpression.Text = "" - cboExpression.Focus() - End If - MyBase.RemoveSelected() + End Sub + + Public Sub AddToReceiverAtCursorPosition(strText As String, Optional iSetCursorBackCharacters As Integer = 0) + AddToReceiverAtPosition(strText, iCurrentPosition, iSetCursorBackCharacters) + End Sub + + Public Overrides Sub RemoveSelected() + If cboExpression.Enabled Then + cboExpression.Text = "" + cboExpression.Focus() + End If + MyBase.RemoveSelected() End Sub Public Function GetText() As String @@ -120,12 +112,12 @@ Public Class ucrReceiverExpression End Function Public Overrides Sub Clear() - RemoveSelected() - iCurrentPosition = 0 - End Sub - - Public Overrides Function IsEmpty() As Boolean - Return cboExpression.Text = "" + RemoveSelected() + iCurrentPosition = 0 + End Sub + + Public Overrides Function IsEmpty() As Boolean + Return cboExpression.Text = "" End Function Public Sub AddtoCombobox(strNew As String) @@ -134,24 +126,20 @@ Public Class ucrReceiverExpression End If End Sub - Private Sub cboExpression_KeyUp(sender As Object, e As KeyEventArgs) Handles cboExpression.KeyUp - iCurrentPosition = cboExpression.SelectionStart - End Sub - - Private Sub cboExpression_MouseDown(sender As Object, e As MouseEventArgs) Handles cboExpression.MouseDown - iCurrentPosition = cboExpression.SelectionStart - End Sub - - Private Sub cboExpression_TextChanged(sender As Object, e As EventArgs) Handles cboExpression.TextChanged - OnSelectionChanged() - End Sub - - Public Overrides Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String - If bWithQuotes Then - Return Chr(34) & cboExpression.Text & Chr(34) - Else - Return cboExpression.Text - End If + Private Sub cboExpression_KeyUp(sender As Object, e As KeyEventArgs) Handles cboExpression.KeyUp + iCurrentPosition = cboExpression.SelectionStart + End Sub + + Private Sub cboExpression_MouseDown(sender As Object, e As MouseEventArgs) Handles cboExpression.MouseDown + iCurrentPosition = cboExpression.SelectionStart + End Sub + + Private Sub cboExpression_TextChanged(sender As Object, e As EventArgs) Handles cboExpression.TextChanged + OnSelectionChanged() + End Sub + + Public Overrides Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String + Return If(bWithQuotes, Chr(34) & cboExpression.Text & Chr(34), cboExpression.Text) End Function Private Sub cboExpression_GotFocus(sender As Object, e As EventArgs) Handles cboExpression.GotFocus diff --git a/instat/ucrReceiverMultiple.vb b/instat/ucrReceiverMultiple.vb index a2badd92b0a..16063dcb64e 100644 --- a/instat/ucrReceiverMultiple.vb +++ b/instat/ucrReceiverMultiple.vb @@ -34,85 +34,148 @@ Public Class ucrReceiverMultiple End If End Sub - Public Overrides Sub AddSelected() - Dim lstItems(Selector.lstAvailableVariable.SelectedItems.Count - 1) As KeyValuePair(Of String, String) - Dim lviTemp As ListViewItem - Dim i As Integer = 0 - - For Each lviTemp In Selector.lstAvailableVariable.SelectedItems - lstItems(i) = New KeyValuePair(Of String, String)(lviTemp.Tag, lviTemp.Text) - i = i + 1 + Public Overrides Sub AddSelectedSelectorVariables() + Dim lstItems As New List(Of KeyValuePair(Of String, String)) + For Each lviTemp As ListViewItem In Selector.lstAvailableVariable.SelectedItems + lstItems.Add(New KeyValuePair(Of String, String)(lviTemp.Tag, lviTemp.Text)) Next AddMultiple(lstItems) End Sub - Private Function GetCurrItemNames() As List(Of String) - Dim strItemNames As New List(Of String) - Dim currItem As ListViewItem + Public Sub AddMultiple(lstItems As IEnumerable(Of KeyValuePair(Of String, String))) + Dim lstActualItemsToAdd As New List(Of KeyValuePair(Of String, String)) + 'first eliminate all items that already exist + 'this improves perfomance significantly for wide data sets + For Each kvpTempItem As KeyValuePair(Of String, String) In lstItems + If lstSelectedVariables.FindItemWithText(kvpTempItem.Value) Is Nothing Then + lstActualItemsToAdd.Add(kvpTempItem) + End If + Next + + If lstActualItemsToAdd.Count = 0 Then + Exit Sub + End If - For Each currItem In lstSelectedVariables.Items - strItemNames.Add(currItem.Text) + 'then add the new items + For Each kvpTempItem As KeyValuePair(Of String, String) In lstActualItemsToAdd + lstSelectedVariables.Items.Add(New ListViewItem With { + .Name = kvpTempItem.Value, + .Text = kvpTempItem.Value, + .ToolTipText = kvpTempItem.Value, + .Tag = kvpTempItem.Key, + .Group = AddGroupName(kvpTempItem.Key) + }) Next - Return strItemNames - End Function - Private Function GetCurrGroupNames() As List(Of String) - Dim strHeaders As New List(Of String) - Dim grpTemp As ListViewGroup + SetGroupHeaderVariablesCount() - For Each grpTemp In lstSelectedVariables.Groups - strHeaders.Add(grpTemp.Name) + OnSelectionChanged() + End Sub + + 'add new group if it exist and return it + 'support of multiple groups assumes that the receiver may have variables from more than one data frame + 'this feature is not yet supported fully + Private Function AddGroupName(strNewGroupName As String) As ListViewGroup + For Each grp In lstSelectedVariables.Groups + If grp.Name = strNewGroupName Then + Return grp + End If Next - Return strHeaders + Dim newGrp As New ListViewGroup(key:=strNewGroupName, headerText:=strNewGroupName) + lstSelectedVariables.Groups.Add(newGrp) + Return newGrp End Function - Public Overrides Sub RemoveSelected() - Dim objItem As ListViewItem - Dim tempObjects(lstSelectedVariables.SelectedItems.Count - 1) As Object - - If lstSelectedVariables.SelectedItems.Count > 0 Then - lstSelectedVariables.SelectedItems.CopyTo(tempObjects, 0) - For Each objItem In tempObjects - lstSelectedVariables.Items.Remove(objItem) - Selector.RemoveFromVariablesList(objItem.Text, objItem.Tag) - Next + Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "", Optional bFixreceiver As Boolean = False) + Dim kvpItems(0) As KeyValuePair(Of String, String) + If strDataFrame = "" Then + Dim lvi As ListViewItem = Selector.lstAvailableVariable.FindItemWithText(strItem) + If lvi IsNot Nothing Then + strDataFrame = lvi.Tag + End If End If + kvpItems(0) = New KeyValuePair(Of String, String)(strDataFrame, strItem) + AddMultiple(kvpItems) + + RemoveAnyVariablesNotInSelector() 'needed due to the Autofill option + + lstSelectedVariables.Enabled = Not bFixreceiver + End Sub + + Public Overrides Sub RemoveSelected() + For Each lvi As ListViewItem In lstSelectedVariables.SelectedItems + lstSelectedVariables.Items.Remove(lvi) + Next + SetGroupHeaderVariablesCount() OnSelectionChanged() MyBase.RemoveSelected() End Sub Public Overrides Sub Remove(strItems() As String) - MyBase.Remove(strItems) + For Each strTempItem In strItems + lstSelectedVariables.Items.RemoveByKey(strTempItem) + Next + SetGroupHeaderVariablesCount() + OnSelectionChanged() + MyBase.RemoveSelected() + End Sub - If strItems.Count > 0 Then - For Each strTempItem In strItems - lstSelectedVariables.Items.RemoveByKey(strTempItem) - 'TODO pass data frame for variables - Selector.RemoveFromVariablesList(strTempItem) - Next - OnSelectionChanged() - MyBase.RemoveSelected() + Public Overrides Sub Clear() + 'as of 23/08/2023. this block can be called several times. to prevent recursive events just exit sub if already empty + If lstSelectedVariables.Items.Count = 0 AndAlso lstSelectedVariables.Groups.Count = 0 Then + Exit Sub End If + lstSelectedVariables.Items.Clear() + lstSelectedVariables.Groups.Clear() + OnSelectionChanged() + MyBase.RemoveSelected() End Sub - Public Overrides Sub Clear() - Dim lviVar As ListViewItem - Dim strItems As New List(Of String) - For Each lviVar In lstSelectedVariables.Items - strItems.Add(lviVar.Text) + ''' + ''' Removes any variable in the multiple receiver + ''' that is not in the list of variables of the selector + ''' + Public Overrides Sub RemoveAnyVariablesNotInSelector() + Dim lstItemsToRemove As New List(Of ListViewItem) + For Each lvi As ListViewItem In lstSelectedVariables.Items + If Selector.lstAvailableVariable.FindItemWithText(lvi.Text) Is Nothing Then + lstItemsToRemove.Add(lvi) + End If + Next + + 'as of 23/08/2023. this subroutine can be called several times. to prevent recursive events just exit sub if there is nothing to remove + If lstItemsToRemove.Count = 0 Then + Exit Sub + End If + + For Each lvi As ListViewItem In lstItemsToRemove + lstSelectedVariables.Items.Remove(lvi) Next - Remove(strItems.ToArray()) + + OnSelectionChanged() + MyBase.RemoveSelected() End Sub - Public Overrides Function IsEmpty() As Boolean + Private Sub SetGroupHeaderVariablesCount() - If lstSelectedVariables.Items.Count > 0 Then - Return False - Else - Return True + If lstSelectedVariables.Groups.Count = 0 Then + Exit Sub End If + 'show count selection at the header of the receiver + 'todo. support this feature for receivers that may have more than 1 data frame later + 'it's not clear when the receiver will ever have more than one data frame + + 'reset the header text with the name + lstSelectedVariables.Groups(0).Header = lstSelectedVariables.Groups(0).Name + If lstSelectedVariables.Groups.Count = 1 AndAlso lstSelectedVariables.Items.Count > 0 Then + lstSelectedVariables.Groups(0).Header = lstSelectedVariables.Groups(0).Header & " (" & lstSelectedVariables.Items.Count & ")" + End If + End Sub + + Public Overrides Function IsEmpty() As Boolean + Return lstSelectedVariables.Items.Count = 0 End Function Public Function Count() As Integer @@ -196,6 +259,8 @@ Public Class ucrReceiverMultiple Return clsGetVariablesFunc End Function + 'todo. this function is used by dlgCombineText dialog only. + 'after refactoring the dialog, remove it from here. Public Function GetVariablesAsList() As List(Of RFunction) Dim lstColumnFunctions As New List(Of RFunction) Dim strColumn As String @@ -225,70 +290,45 @@ Public Class ucrReceiverMultiple End Function Public Overrides Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String - Dim strTemp As String = "" - Dim i As Integer + Dim strTempBuilder As New Text.StringBuilder + Dim strQuoteHolder As String = If(bWithQuotes, Chr(34), "") + If lstSelectedVariables.Items.Count = 1 AndAlso Not bForceVariablesAsList Then - If bWithQuotes Then - strTemp = Chr(34) & lstSelectedVariables.Items(0).Text & Chr(34) - Else - strTemp = lstSelectedVariables.Items(0).Text - End If + strTempBuilder.Append(strQuoteHolder).Append(lstSelectedVariables.Items(0).Text).Append(strQuoteHolder) ElseIf lstSelectedVariables.Items.Count > 1 OrElse bForceVariablesAsList Then - If strVariablesListPackageName <> "" Then - strTemp = strVariablesListPackageName & "::" - End If - strTemp = strTemp & strVariablesListFunctionName & "(" - For i = 0 To lstSelectedVariables.Items.Count - 1 - If i > 0 Then - strTemp = strTemp & "," - End If - If lstSelectedVariables.Items(i).Text <> "" Then - If bWithQuotes Then - strTemp = strTemp & Chr(34) & lstSelectedVariables.Items(i).Text & Chr(34) - Else - strTemp = strTemp & lstSelectedVariables.Items(i).Text - End If - End If + strTempBuilder.Append(If(strVariablesListPackageName <> "", strVariablesListPackageName & "::", "")) + strTempBuilder.Append(strVariablesListFunctionName).Append("(") + For Each lvi As ListViewItem In lstSelectedVariables.Items + strTempBuilder.Append(strQuoteHolder).Append(lvi.Text).Append(strQuoteHolder).Append(",") Next - strTemp = strTemp & ")" + strTempBuilder.Length -= 1 'remove last comma + strTempBuilder.Append(")") End If - - Return strTemp + Return strTempBuilder.ToString() End Function Public Overrides Function GetVariableNamesList(Optional bWithQuotes As Boolean = True, Optional strQuotes As String = Chr(34)) As String() - Dim lstItems As String() - - ReDim lstItems(0 To lstSelectedVariables.Items.Count - 1) + Dim arrItems(lstSelectedVariables.Items.Count) As String + Dim strQuoteHolder As String = If(bWithQuotes, strQuotes, "") For i = 0 To lstSelectedVariables.Items.Count - 1 - If bWithQuotes Then - lstItems(i) = strQuotes & lstSelectedVariables.Items(i).Text & strQuotes - Else - lstItems(i) = lstSelectedVariables.Items(i).Text - End If + arrItems(i) = strQuoteHolder & lstSelectedVariables.Items(i).Text & strQuoteHolder Next - Return lstItems + Return arrItems End Function Public Function GetVariableNamesAsList() As List(Of String) - Dim lstItems As New List(Of String) - - For i = 0 To lstSelectedVariables.Items.Count - 1 - lstItems.Add(lstSelectedVariables.Items(i).Text) + Dim lstItems As New List(Of String)(lstSelectedVariables.Items.Count) + For Each lvi As ListViewItem In lstSelectedVariables.Items + lstItems.Add(lvi.Text) Next Return lstItems End Function Public Function GetDataFrameNames() As List(Of String) Dim strDataFrames As New List(Of String) - Dim CurrObj As ListViewItem - - For Each CurrObj In lstSelectedVariables.Items - If Not strDataFrames.Contains(CurrObj.Group.Header) Then - strDataFrames.Add(CurrObj.Group.Header) - End If + For Each CurrObj As ListViewGroup In lstSelectedVariables.Groups + strDataFrames.Add(CurrObj.Name) Next - Return strDataFrames End Function @@ -300,17 +340,6 @@ Public Class ucrReceiverMultiple lstSelectedVariables.BackColor = Color.White End Sub - ''' - ''' Removes any variable in the multiple receiver - ''' that is not in the list of variables of the selector - ''' - Public Overrides Sub RemoveAnyVariablesNotInList() - For Each strVar In GetVariableNamesAsList() - If Selector.lstAvailableVariable.FindItemWithText(strVar) Is Nothing Then - Remove({strVar}) - End If - Next - End Sub Private Sub lstSelectedVariables_KeyDown(sender As Object, e As KeyEventArgs) Handles lstSelectedVariables.KeyDown If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Then @@ -338,45 +367,6 @@ Public Class ucrReceiverMultiple End If End Function - Public Sub AddMultiple(lstItems As KeyValuePair(Of String, String)()) - Dim kvpTempItem As KeyValuePair(Of String, String) - Dim grpCurr As New ListViewGroup - - For Each kvpTempItem In lstItems - If Not GetCurrItemNames().Contains(kvpTempItem.Value) Then - If Not GetCurrGroupNames().Contains(kvpTempItem.Key) Then - grpCurr = New ListViewGroup(key:=kvpTempItem.Key, headerText:=kvpTempItem.Key) - lstSelectedVariables.Groups.Add(grpCurr) - Else - grpCurr = lstSelectedVariables.Groups(GetCurrGroupNames().IndexOf(kvpTempItem.Key)) - End If - lstSelectedVariables.Items.Add(kvpTempItem.Value).Group = grpCurr - lstSelectedVariables.Items(lstSelectedVariables.Items.Count - 1).Tag = kvpTempItem.Key - lstSelectedVariables.Items(lstSelectedVariables.Items.Count - 1).Name = kvpTempItem.Value - lstSelectedVariables.Items(lstSelectedVariables.Items.Count - 1).ToolTipText = kvpTempItem.Value - Selector.AddToVariablesList(kvpTempItem.Value, kvpTempItem.Key) - End If - Next - OnSelectionChanged() - End Sub - - Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "", Optional bFixreceiver As Boolean = False) - Dim kvpItems(0) As KeyValuePair(Of String, String) - If strDataFrame = "" Then - For i = 0 To Selector.lstAvailableVariable.Items.Count - 1 - If Selector.lstAvailableVariable.Items(i).Text = strItem Then - strDataFrame = Selector.lstAvailableVariable.Items(i).Tag - End If - Next - End If - kvpItems(0) = New KeyValuePair(Of String, String)(strDataFrame, strItem) - AddMultiple(kvpItems) - - RemoveAnyVariablesNotInList() 'needed due to the Autofill option - - lstSelectedVariables.Enabled = Not bFixreceiver - End Sub - Public Function GetCurrentItemTypes(Optional bUnique As Boolean = False, Optional bIsCategoricalNumeric As Boolean = False) As List(Of String) Dim clsGetDataType As New RFunction Dim strDataTypes As New List(Of String) @@ -517,7 +507,13 @@ Public Class ucrReceiverMultiple End Sub Public Overrides Function GetItemsDataFrames() As List(Of String) - Return GetCurrGroupNames() + Dim strHeaders As New List(Of String) + Dim grpTemp As ListViewGroup + + For Each grpTemp In lstSelectedVariables.Groups + strHeaders.Add(grpTemp.Name) + Next + Return strHeaders End Function End Class \ No newline at end of file diff --git a/instat/ucrReceiverSingle.vb b/instat/ucrReceiverSingle.vb index e600bd5732e..6ae7be192e6 100644 --- a/instat/ucrReceiverSingle.vb +++ b/instat/ucrReceiverSingle.vb @@ -35,7 +35,7 @@ Public Class ucrReceiverSingle strCurrDataType = "" End Sub - Public Overrides Sub AddSelected() + Public Overrides Sub AddSelectedSelectorVariables() 'Dim tempObjects(Selector.lstAvailableVariable.SelectedItems.Count - 1) As ListViewItem If Selector.lstAvailableVariable.SelectedItems.Count = 1 Then @@ -53,16 +53,6 @@ Public Class ucrReceiverSingle Dim expColumnType As SymbolicExpression Dim bRemove As Boolean = False - 'Would prefer to have remove selected but that will first clear the receiver - 'This has issues when reading RSyntax and filling receivers e.g. in Specific plot dialogs - 'Because it modifies the list of parameters it is looping through when clearing first, crashing - 'Below is the part from RemoveSelected() that is needed - 'This is only an issue with single receiver - 'If RemoveSelected() later contains other things, this may need to be updated. - 'RemoveSelected() - If Selector IsNot Nothing Then - Selector.RemoveFromVariablesList(txtReceiverSingle.Text, strDataFrame) - End If MyBase.Add(strItem, strDataFrame) strCurrentItemType = If(bTypeSet, strType, Selector?.GetItemType()) @@ -118,9 +108,6 @@ Public Class ucrReceiverSingle End If strDataFrameName = strDataFrame txtReceiverSingle.Text = strItem - If Selector IsNot Nothing Then - Selector.AddToVariablesList(strItem, strDataFrameName) - End If If bRemove Then RemoveSelected() End If @@ -130,9 +117,6 @@ Public Class ucrReceiverSingle Public Overrides Sub RemoveSelected() If txtReceiverSingle.Enabled Then - If Selector IsNot Nothing Then - Selector.RemoveFromVariablesList(txtReceiverSingle.Text, strDataFrameName) - End If txtReceiverSingle.Text = "" strDataFrameName = "" End If @@ -235,21 +219,15 @@ Public Class ucrReceiverSingle End Function Public Overrides Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String - Dim strTemp As String = "" - If txtReceiverSingle.Text <> "" Then - If bWithQuotes Then - strTemp = Chr(34) & txtReceiverSingle.Text & Chr(34) - Else - strTemp = txtReceiverSingle.Text - End If - End If - Return strTemp + Return If(bWithQuotes, Chr(34) & txtReceiverSingle.Text & Chr(34), txtReceiverSingle.Text) End Function Public Overrides Function GetVariableNameslist(Optional bWithQuotes As Boolean = True, Optional strQuotes As String = Chr(34)) As String() - Dim arrTemp As String() = Nothing - arrTemp = {GetVariableNames()} - Return arrTemp + If bWithQuotes Then + Return {strQuotes & txtReceiverSingle.Text & strQuotes} + Else + Return {txtReceiverSingle.Text} + End If End Function Public Function GetDataName() As String @@ -281,7 +259,6 @@ Public Class ucrReceiverSingle If bDisableReceiver Then Add("variable", "") Me.Enabled = False - Selector.RemoveFromVariablesList("variable") Else Me.Enabled = True If txtReceiverSingle.Text = "variable" Then diff --git a/instat/ucrScript.vb b/instat/ucrScript.vb index 2f2740ba87b..18ed4a10d54 100644 --- a/instat/ucrScript.vb +++ b/instat/ucrScript.vb @@ -29,6 +29,56 @@ Public Class ucrScript Friend WithEvents clsScriptActive As Scintilla Friend WithEvents clsScriptLog As Scintilla + Public Sub New() + ' This call is required by the designer. + InitializeComponent() + + + ' Add any initialization after the InitializeComponent() call. + SetupInitialLayout() + + End Sub + + Private Sub ucrScript_Load(sender As Object, e As EventArgs) Handles Me.Load + + toolTipScriptWindow.SetToolTip(cmdRunLineSelection, "Run the current line or selection. (Ctrl+Enter)") + toolTipScriptWindow.SetToolTip(cmdRunAll, "Run all the text in the tab. (Ctrl+Alt+R)") + toolTipScriptWindow.SetToolTip(cmdLoadScript, "Load a script from file into the current tab.") + toolTipScriptWindow.SetToolTip(cmdSave, "Save the script in the current tab to a file.") + toolTipScriptWindow.SetToolTip(cmdAddTab, "Add a new tab.") + toolTipScriptWindow.SetToolTip(cmdRemoveTab, "Delete the current tab.") + toolTipScriptWindow.SetToolTip(cmdClear, "Clear the contents of the current tab. (Ctrl+L)") + toolTipScriptWindow.SetToolTip(cmdHelp, "Display the Script Window help information.") + + mnuUndo.ToolTipText = "Undo the last change. (Ctrl+Z)" + mnuRedo.ToolTipText = "Redo the last change. (Ctrl+Y)" + mnuCut.ToolTipText = "Copy the selected text to the clipboard, then delete the text. (Ctrl+X)" + mnuCopy.ToolTipText = "Copy the selected text to the clipboard. (Ctrl+C)" + mnuPaste.ToolTipText = "Paste the contents of the clipboard into the current tab. (Ctrl+V)" + mnuSelectAll.ToolTipText = "Select all the contents of the current tab. (Ctrl+A)" + mnuClear.ToolTipText = "Clear the contents of the current tab. (Ctrl+L)" + mnuRunCurrentLineSelection.ToolTipText = "Run the current line or selection. (Ctrl+Enter)" + mnuRunAllText.ToolTipText = "Run all the text in the tab. (Ctrl+Alt+R)" + mnuOpenScriptasFile.ToolTipText = "Save file to log folder and open file in external editor." + mnuLoadScriptFromFile.ToolTipText = "Load script from file into the current tab." + mnuSaveScript.ToolTipText = "Save the script in the current tab to a file." + mnuHelp.ToolTipText = "Display the Script Window help information." + + 'normally we would do this in the designer, but designer doesn't allow enter key as shortcut + mnuRunCurrentLineSelection.ShortcutKeys = Keys.Enter Or Keys.Control + + 'Make the log tab the selected tab + TabControl.SelectTab(iTabIndexLog) + End Sub + + Private Sub SetupInitialLayout() + 'Create log tab + AddTab(bIsLogTab:=True) + + 'Create script tab + AddTab() + End Sub + ''' ''' The current text in the active tab. ''' @@ -823,42 +873,4 @@ Public Class ucrScript End If End Sub - Private Sub ucrScript_Load(sender As Object, e As EventArgs) Handles MyBase.Load - - toolTipScriptWindow.SetToolTip(cmdRunLineSelection, "Run the current line or selection. (Ctrl+Enter)") - toolTipScriptWindow.SetToolTip(cmdRunAll, "Run all the text in the tab. (Ctrl+Alt+R)") - toolTipScriptWindow.SetToolTip(cmdLoadScript, "Load a script from file into the current tab.") - toolTipScriptWindow.SetToolTip(cmdSave, "Save the script in the current tab to a file.") - toolTipScriptWindow.SetToolTip(cmdAddTab, "Add a new tab.") - toolTipScriptWindow.SetToolTip(cmdRemoveTab, "Delete the current tab.") - toolTipScriptWindow.SetToolTip(cmdClear, "Clear the contents of the current tab. (Ctrl+L)") - toolTipScriptWindow.SetToolTip(cmdHelp, "Display the Script Window help information.") - - mnuUndo.ToolTipText = "Undo the last change. (Ctrl+Z)" - mnuRedo.ToolTipText = "Redo the last change. (Ctrl+Y)" - mnuCut.ToolTipText = "Copy the selected text to the clipboard, then delete the text. (Ctrl+X)" - mnuCopy.ToolTipText = "Copy the selected text to the clipboard. (Ctrl+C)" - mnuPaste.ToolTipText = "Paste the contents of the clipboard into the current tab. (Ctrl+V)" - mnuSelectAll.ToolTipText = "Select all the contents of the current tab. (Ctrl+A)" - mnuClear.ToolTipText = "Clear the contents of the current tab. (Ctrl+L)" - mnuRunCurrentLineSelection.ToolTipText = "Run the current line or selection. (Ctrl+Enter)" - mnuRunAllText.ToolTipText = "Run all the text in the tab. (Ctrl+Alt+R)" - mnuOpenScriptasFile.ToolTipText = "Save file to log folder and open file in external editor." - mnuLoadScriptFromFile.ToolTipText = "Load script from file into the current tab." - mnuSaveScript.ToolTipText = "Save the script in the current tab to a file." - mnuHelp.ToolTipText = "Display the Script Window help information." - - 'normally we would do this in the designer, but designer doesn't allow enter key as shortcut - mnuRunCurrentLineSelection.ShortcutKeys = Keys.Enter Or Keys.Control - - 'Create log tab - AddTab(bIsLogTab:=True) - - 'Create script tab - AddTab() - - 'Make the log tab the selected tab - TabControl.SelectTab(iTabIndexLog) - End Sub - End Class diff --git a/instat/ucrSelector.vb b/instat/ucrSelector.vb index 22e8c9f50fd..19c21d3620b 100644 --- a/instat/ucrSelector.vb +++ b/instat/ucrSelector.vb @@ -17,9 +17,8 @@ Public Class ucrSelector Public CurrentReceiver As ucrReceiver Public Event ResetAll() Public Event ResetReceivers() - Public Event VariablesInReceiversChanged() Public Event DataFrameChanged() - Public lstVariablesInReceivers As List(Of Tuple(Of String, String)) + Public bFirstLoad As Boolean Public strCurrentDataFrame As String = "" ' If a dialog has receivers which can have columns from multiple data frames @@ -50,7 +49,6 @@ Public Class ucrSelector InitializeComponent() ' Add any initialization after the InitializeComponent() call. - lstVariablesInReceivers = New List(Of Tuple(Of String, String)) bFirstLoad = True 'bIncludeOverall = False lstIncludedMetadataProperties = New List(Of KeyValuePair(Of String, String())) @@ -115,7 +113,7 @@ Public Class ucrSelector lstCombinedMetadataLists = CombineMetadataLists(CurrentReceiver.lstIncludedMetadataProperties, CurrentReceiver.lstExcludedMetadataProperties) If CurrentReceiver.bExcludeFromSelector Then - arrStrExclud = GetVariablesInReceiver().ToArray + arrStrExclud = CurrentReceiver.GetVariableNamesList(bWithQuotes:=False) End If 'set the type of 'elements' to show. If current receiver is set to a particular 'element' type then use it @@ -151,7 +149,7 @@ Public Class ucrSelector strHeading:=CurrentReceiver.strSelectorHeading, strDataFrameName:=strCurrentDataFrame, strExcludedItems:=arrStrExclud, strDatabaseQuery:=CurrentReceiver.strDatabaseQuery, strNcFilePath:=CurrentReceiver.strNcFilePath) If Not CurrentReceiver.bExcludeFromSelector Then - CurrentReceiver.RemoveAnyVariablesNotInList() 'this needed for the multiple receiver(s) where the autofill is not applied + CurrentReceiver.RemoveAnyVariablesNotInSelector() 'this needed for the multiple receiver(s) where the autofill is not applied End If EnableDataOptions(strCurrentType) @@ -202,20 +200,9 @@ Public Class ucrSelector Return strSelectorFillCondition End Function - Private Function GetVariablesInReceiver() As List(Of String) - Dim lstVars As New List(Of String) - - For Each tplTemp As Tuple(Of String, String) In lstVariablesInReceivers - lstVars.Add(tplTemp.Item1) - Next - Return lstVars - End Function - Public Overridable Sub Reset() RaiseEvent ResetReceivers() - lstVariablesInReceivers.Clear() LoadList() - 'lstItemsInReceivers.Clear() End Sub Public Sub SetCurrentReceiver(conReceiver As ucrReceiver) @@ -261,7 +248,7 @@ Public Class ucrSelector Public Sub Add() If CurrentReceiver IsNot Nothing AndAlso (lstAvailableVariable.SelectedItems.Count > 0) Then - CurrentReceiver.AddSelected() + CurrentReceiver.AddSelectedSelectorVariables() 'sets current focus enabling correct tab navigation CurrentReceiver.Focus() 'check if autoswitching from the receiver is allowed before doing an autoswitch. @@ -329,27 +316,7 @@ Public Class ucrSelector ucrLinkedSelector = ucrNewLinkedSelector End Sub - Public Sub AddToVariablesList(strVariable As String, Optional strDataFrame As String = "") - If strDataFrame = "" OrElse strDataFrame = strCurrentDataFrame Then - lstVariablesInReceivers.Add(New Tuple(Of String, String)(strVariable, strDataFrame)) - If ucrLinkedSelector IsNot Nothing Then - ucrLinkedSelector.AddToVariablesList(strVariable, strCurrentDataFrame) - End If - RaiseEvent VariablesInReceiversChanged() - End If - End Sub - Public Sub RemoveFromVariablesList(strVariable As String, Optional strDataFrame As String = "") - For i As Integer = lstVariablesInReceivers.Count - 1 To 0 Step -1 - If lstVariablesInReceivers(i).Item1 = strVariable AndAlso (strDataFrame = "" OrElse lstVariablesInReceivers(i).Item2 = strDataFrame) Then - lstVariablesInReceivers.RemoveAt(i) - End If - Next - If ucrLinkedSelector IsNot Nothing Then - ucrLinkedSelector.RemoveFromVariablesList(strVariable, strCurrentDataFrame) - End If - RaiseEvent VariablesInReceiversChanged() - End Sub Public Sub AddIncludedMetadataProperty(strProperty As String, strInclude As String()) Dim iIncludeIndex As Integer