From 90c4586fc588c6c50fc522973781331e2d321361 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Sat, 5 Oct 2019 19:32:01 +0100 Subject: [PATCH 01/10] created treemap dialog --- instat/dlgTreemap.Designer.vb | 311 +++++++++++++ instat/dlgTreemap.resx | 849 ++++++++++++++++++++++++++++++++++ instat/dlgTreemap.vb | 334 +++++++++++++ 3 files changed, 1494 insertions(+) create mode 100644 instat/dlgTreemap.Designer.vb create mode 100644 instat/dlgTreemap.resx create mode 100644 instat/dlgTreemap.vb diff --git a/instat/dlgTreemap.Designer.vb b/instat/dlgTreemap.Designer.vb new file mode 100644 index 00000000000..f3521ad9b72 --- /dev/null +++ b/instat/dlgTreemap.Designer.vb @@ -0,0 +1,311 @@ + _ +Partial Class dlgTreemap + Inherits System.Windows.Forms.Form + + 'Form overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Windows Form Designer + 'It can be modified using the Windows Form Designer. + 'Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(dlgTreemap)) + Me.lblLabel = New System.Windows.Forms.Label() + Me.ucrInputLabel = New instat.ucrInputComboBox() + Me.ucrSaveTreemap = New instat.ucrSave() + Me.ucrChkIsCurrency = New instat.ucrCheck() + Me.rdoPrimary = New System.Windows.Forms.RadioButton() + Me.rdoSummary = New System.Windows.Forms.RadioButton() + Me.cmdOptions = New System.Windows.Forms.Button() + Me.lblWeightBy = New System.Windows.Forms.Label() + Me.lblGroupByIdentifier = New System.Windows.Forms.Label() + Me.ucrReceiverWeightBy = New instat.ucrReceiverSingle() + Me.ucrReceiverIdentifier = New instat.ucrReceiverSingle() + Me.ucrSelectorTreemap = New instat.ucrSelectorByDataFrameAddRemove() + Me.ucrBase = New instat.ucrButtons() + Me.cmdBarChartOptions = New System.Windows.Forms.Button() + Me.cmdPieChartOptions = New System.Windows.Forms.Button() + Me.ucrPnlDataType = New instat.UcrPanel() + Me.lblSymbol = New System.Windows.Forms.Label() + Me.ucrInputSymbol = New instat.ucrInputTextBox() + Me.lblFill = New System.Windows.Forms.Label() + Me.ucrReceiverFill = New instat.ucrReceiverSingle() + Me.grpOptions = New System.Windows.Forms.GroupBox() + Me.lblTextColour = New System.Windows.Forms.Label() + Me.ucrColourText = New instat.ucrColors() + Me.lblBoxColour = New System.Windows.Forms.Label() + Me.ucrColourBox = New instat.ucrColors() + Me.lblSummary = New System.Windows.Forms.Label() + Me.ucrInputSummary = New instat.ucrInputComboBox() + Me.grpOptions.SuspendLayout() + Me.SuspendLayout() + ' + 'lblLabel + ' + resources.ApplyResources(Me.lblLabel, "lblLabel") + Me.lblLabel.Name = "lblLabel" + ' + 'ucrInputLabel + ' + Me.ucrInputLabel.AddQuotesIfUnrecognised = True + Me.ucrInputLabel.IsReadOnly = False + resources.ApplyResources(Me.ucrInputLabel, "ucrInputLabel") + Me.ucrInputLabel.Name = "ucrInputLabel" + ' + 'ucrSaveTreemap + ' + resources.ApplyResources(Me.ucrSaveTreemap, "ucrSaveTreemap") + Me.ucrSaveTreemap.Name = "ucrSaveTreemap" + ' + 'ucrChkIsCurrency + ' + Me.ucrChkIsCurrency.Checked = False + resources.ApplyResources(Me.ucrChkIsCurrency, "ucrChkIsCurrency") + Me.ucrChkIsCurrency.Name = "ucrChkIsCurrency" + ' + 'rdoPrimary + ' + resources.ApplyResources(Me.rdoPrimary, "rdoPrimary") + Me.rdoPrimary.BackColor = System.Drawing.SystemColors.Control + Me.rdoPrimary.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoPrimary.FlatAppearance.BorderSize = 2 + Me.rdoPrimary.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoPrimary.Name = "rdoPrimary" + Me.rdoPrimary.TabStop = True + Me.rdoPrimary.Tag = "" + Me.rdoPrimary.UseVisualStyleBackColor = False + ' + 'rdoSummary + ' + resources.ApplyResources(Me.rdoSummary, "rdoSummary") + Me.rdoSummary.BackColor = System.Drawing.SystemColors.Control + Me.rdoSummary.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoSummary.FlatAppearance.BorderSize = 2 + Me.rdoSummary.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoSummary.Name = "rdoSummary" + Me.rdoSummary.TabStop = True + Me.rdoSummary.Tag = "Pie_Chart" + Me.rdoSummary.UseVisualStyleBackColor = False + ' + 'cmdOptions + ' + resources.ApplyResources(Me.cmdOptions, "cmdOptions") + Me.cmdOptions.Name = "cmdOptions" + Me.cmdOptions.Tag = "Plot_Options..." + Me.cmdOptions.UseVisualStyleBackColor = True + ' + 'lblWeightBy + ' + resources.ApplyResources(Me.lblWeightBy, "lblWeightBy") + Me.lblWeightBy.Name = "lblWeightBy" + Me.lblWeightBy.Tag = "" + ' + 'lblGroupByIdentifier + ' + resources.ApplyResources(Me.lblGroupByIdentifier, "lblGroupByIdentifier") + Me.lblGroupByIdentifier.Name = "lblGroupByIdentifier" + Me.lblGroupByIdentifier.Tag = "Variable:" + ' + 'ucrReceiverWeightBy + ' + Me.ucrReceiverWeightBy.frmParent = Me + resources.ApplyResources(Me.ucrReceiverWeightBy, "ucrReceiverWeightBy") + Me.ucrReceiverWeightBy.Name = "ucrReceiverWeightBy" + Me.ucrReceiverWeightBy.Selector = Nothing + Me.ucrReceiverWeightBy.strNcFilePath = "" + Me.ucrReceiverWeightBy.ucrSelector = Nothing + ' + 'ucrReceiverIdentifier + ' + Me.ucrReceiverIdentifier.frmParent = Me + resources.ApplyResources(Me.ucrReceiverIdentifier, "ucrReceiverIdentifier") + Me.ucrReceiverIdentifier.Name = "ucrReceiverIdentifier" + Me.ucrReceiverIdentifier.Selector = Nothing + Me.ucrReceiverIdentifier.strNcFilePath = "" + Me.ucrReceiverIdentifier.ucrSelector = Nothing + ' + 'ucrSelectorTreemap + ' + Me.ucrSelectorTreemap.bDropUnusedFilterLevels = False + Me.ucrSelectorTreemap.bShowHiddenColumns = False + Me.ucrSelectorTreemap.bUseCurrentFilter = True + resources.ApplyResources(Me.ucrSelectorTreemap, "ucrSelectorTreemap") + Me.ucrSelectorTreemap.Name = "ucrSelectorTreemap" + ' + 'ucrBase + ' + resources.ApplyResources(Me.ucrBase, "ucrBase") + Me.ucrBase.Name = "ucrBase" + ' + 'cmdBarChartOptions + ' + resources.ApplyResources(Me.cmdBarChartOptions, "cmdBarChartOptions") + Me.cmdBarChartOptions.Name = "cmdBarChartOptions" + Me.cmdBarChartOptions.Tag = "Bar_Chart_Options" + Me.cmdBarChartOptions.UseVisualStyleBackColor = True + ' + 'cmdPieChartOptions + ' + resources.ApplyResources(Me.cmdPieChartOptions, "cmdPieChartOptions") + Me.cmdPieChartOptions.Name = "cmdPieChartOptions" + Me.cmdPieChartOptions.Tag = "Pie_Chart_Options" + Me.cmdPieChartOptions.UseVisualStyleBackColor = True + ' + 'ucrPnlDataType + ' + resources.ApplyResources(Me.ucrPnlDataType, "ucrPnlDataType") + Me.ucrPnlDataType.Name = "ucrPnlDataType" + ' + 'lblSymbol + ' + resources.ApplyResources(Me.lblSymbol, "lblSymbol") + Me.lblSymbol.Name = "lblSymbol" + ' + 'ucrInputSymbol + ' + Me.ucrInputSymbol.AddQuotesIfUnrecognised = True + Me.ucrInputSymbol.IsMultiline = False + Me.ucrInputSymbol.IsReadOnly = False + resources.ApplyResources(Me.ucrInputSymbol, "ucrInputSymbol") + Me.ucrInputSymbol.Name = "ucrInputSymbol" + ' + 'lblFill + ' + resources.ApplyResources(Me.lblFill, "lblFill") + Me.lblFill.Name = "lblFill" + Me.lblFill.Tag = "" + ' + 'ucrReceiverFill + ' + Me.ucrReceiverFill.frmParent = Me + resources.ApplyResources(Me.ucrReceiverFill, "ucrReceiverFill") + Me.ucrReceiverFill.Name = "ucrReceiverFill" + Me.ucrReceiverFill.Selector = Nothing + Me.ucrReceiverFill.strNcFilePath = "" + Me.ucrReceiverFill.ucrSelector = Nothing + ' + 'grpOptions + ' + Me.grpOptions.Controls.Add(Me.lblTextColour) + Me.grpOptions.Controls.Add(Me.ucrColourText) + Me.grpOptions.Controls.Add(Me.lblBoxColour) + Me.grpOptions.Controls.Add(Me.ucrColourBox) + resources.ApplyResources(Me.grpOptions, "grpOptions") + Me.grpOptions.Name = "grpOptions" + Me.grpOptions.TabStop = False + ' + 'lblTextColour + ' + resources.ApplyResources(Me.lblTextColour, "lblTextColour") + Me.lblTextColour.Name = "lblTextColour" + ' + 'ucrColourText + ' + Me.ucrColourText.AddQuotesIfUnrecognised = True + Me.ucrColourText.IsReadOnly = False + resources.ApplyResources(Me.ucrColourText, "ucrColourText") + Me.ucrColourText.Name = "ucrColourText" + ' + 'lblBoxColour + ' + resources.ApplyResources(Me.lblBoxColour, "lblBoxColour") + Me.lblBoxColour.Name = "lblBoxColour" + ' + 'ucrColourBox + ' + Me.ucrColourBox.AddQuotesIfUnrecognised = True + Me.ucrColourBox.IsReadOnly = False + resources.ApplyResources(Me.ucrColourBox, "ucrColourBox") + Me.ucrColourBox.Name = "ucrColourBox" + ' + 'lblSummary + ' + resources.ApplyResources(Me.lblSummary, "lblSummary") + Me.lblSummary.Name = "lblSummary" + ' + 'ucrInputSummary + ' + Me.ucrInputSummary.AddQuotesIfUnrecognised = True + Me.ucrInputSummary.IsReadOnly = False + resources.ApplyResources(Me.ucrInputSummary, "ucrInputSummary") + Me.ucrInputSummary.Name = "ucrInputSummary" + ' + 'dlgTreemap + ' + resources.ApplyResources(Me, "$this") + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.Controls.Add(Me.ucrInputSummary) + Me.Controls.Add(Me.lblSummary) + Me.Controls.Add(Me.grpOptions) + Me.Controls.Add(Me.lblFill) + Me.Controls.Add(Me.ucrReceiverFill) + Me.Controls.Add(Me.ucrInputSymbol) + Me.Controls.Add(Me.lblSymbol) + Me.Controls.Add(Me.lblLabel) + Me.Controls.Add(Me.ucrInputLabel) + Me.Controls.Add(Me.ucrSaveTreemap) + Me.Controls.Add(Me.ucrChkIsCurrency) + Me.Controls.Add(Me.rdoPrimary) + Me.Controls.Add(Me.rdoSummary) + Me.Controls.Add(Me.cmdOptions) + Me.Controls.Add(Me.lblWeightBy) + Me.Controls.Add(Me.lblGroupByIdentifier) + Me.Controls.Add(Me.ucrReceiverWeightBy) + Me.Controls.Add(Me.ucrReceiverIdentifier) + Me.Controls.Add(Me.ucrSelectorTreemap) + Me.Controls.Add(Me.ucrBase) + Me.Controls.Add(Me.cmdBarChartOptions) + Me.Controls.Add(Me.cmdPieChartOptions) + Me.Controls.Add(Me.ucrPnlDataType) + Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow + Me.MaximizeBox = False + Me.MinimizeBox = False + Me.Name = "dlgTreemap" + Me.grpOptions.ResumeLayout(False) + Me.grpOptions.PerformLayout() + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents lblLabel As Label + Friend WithEvents ucrInputLabel As ucrInputComboBox + Friend WithEvents ucrSaveTreemap As ucrSave + Friend WithEvents ucrChkIsCurrency As ucrCheck + Friend WithEvents rdoPrimary As RadioButton + Friend WithEvents rdoSummary As RadioButton + Friend WithEvents cmdOptions As Button + Friend WithEvents lblWeightBy As Label + Friend WithEvents lblGroupByIdentifier As Label + Friend WithEvents ucrReceiverWeightBy As ucrReceiverSingle + Friend WithEvents ucrReceiverIdentifier As ucrReceiverSingle + Friend WithEvents ucrSelectorTreemap As ucrSelectorByDataFrameAddRemove + Friend WithEvents ucrBase As ucrButtons + Friend WithEvents cmdBarChartOptions As Button + Friend WithEvents cmdPieChartOptions As Button + Friend WithEvents ucrPnlDataType As UcrPanel + Friend WithEvents ucrInputSymbol As ucrInputTextBox + Friend WithEvents lblSymbol As Label + Friend WithEvents lblFill As Label + Friend WithEvents ucrReceiverFill As ucrReceiverSingle + Friend WithEvents grpOptions As GroupBox + Friend WithEvents lblTextColour As Label + Friend WithEvents ucrColourText As ucrColors + Friend WithEvents lblBoxColour As Label + Friend WithEvents ucrColourBox As ucrColors + Friend WithEvents lblSummary As Label + Friend WithEvents ucrInputSummary As ucrInputComboBox +End Class diff --git a/instat/dlgTreemap.resx b/instat/dlgTreemap.resx new file mode 100644 index 00000000000..8b313e3cc67 --- /dev/null +++ b/instat/dlgTreemap.resx @@ -0,0 +1,849 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + True + + + + NoControl + + + + 251, 226 + + + 36, 13 + + + 23 + + + Label: + + + lblLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + 254, 244 + + + 21, 17, 21, 17 + + + 120, 21 + + + 25 + + + ucrInputLabel + + + instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 8 + + + 9, 380 + + + 255, 24 + + + 29 + + + ucrSaveTreemap + + + instat.ucrSave, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 9 + + + 254, 180 + + + 82, 20 + + + 28 + + + ucrChkIsCurrency + + + instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 10 + + + Button + + + Flat + + + NoControl + + + 97, 11 + + + 110, 28 + + + 16 + + + Primary data + + + MiddleCenter + + + rdoPrimary + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 11 + + + Button + + + Flat + + + NoControl + + + 205, 11 + + + 110, 28 + + + 17 + + + Summary data + + + MiddleCenter + + + rdoSummary + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 12 + + + NoControl + + + 9, 261 + + + 121, 25 + + + 27 + + + Options + + + cmdOptions + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 13 + + + True + + + NoControl + + + 254, 111 + + + 107, 13 + + + 21 + + + Weight By (Optional): + + + lblWeightBy + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 14 + + + True + + + NoControl + + + 254, 61 + + + 54, 13 + + + 19 + + + Group By: + + + lblGroupByIdentifier + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 15 + + + True + + + 6, 13 + + + 418, 464 + + + 307, 154 + + + 67, 21 + + + 37 + + + ucrInputSummary + + + instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 0 + + + True + + + NoControl + + + 252, 156 + + + 53, 13 + + + 36 + + + Summary: + + + lblSummary + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + NoControl + + + 9, 54 + + + 63, 13 + + + 38 + + + Text colour: + + + lblTextColour + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpOptions + + + 0 + + + 80, 52 + + + 137, 21 + + + 37 + + + ucrColourText + + + instat.ucrColors, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpOptions + + + 1 + + + True + + + NoControl + + + 9, 23 + + + 60, 13 + + + 36 + + + Box colour: + + + lblBoxColour + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpOptions + + + 2 + + + 80, 21 + + + 137, 21 + + + 0 + + + ucrColourBox + + + instat.ucrColors, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpOptions + + + 3 + + + 9, 293 + + + 230, 81 + + + 35 + + + Options + + + grpOptions + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + NoControl + + + 254, 277 + + + 22, 13 + + + 33 + + + Fill: + + + lblFill + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + 254, 292 + + + 0, 0, 0, 0 + + + 120, 20 + + + 34 + + + ucrReceiverFill + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 4 + + + 323, 201 + + + 51, 21 + + + 32 + + + ucrInputSymbol + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 5 + + + True + + + NoControl + + + 272, 203 + + + 44, 13 + + + 31 + + + Symbol: + + + lblSymbol + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + + + 254, 76 + + + 0, 0, 0, 0 + + + 120, 20 + + + 20 + + + ucrReceiverIdentifier + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 17 + + + 9, 40 + + + 0, 0, 0, 0 + + + 210, 180 + + + 18 + + + ucrSelectorTreemap + + + instat.ucrSelectorByDataFrameAddRemove, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 18 + + + 9, 410 + + + 410, 52 + + + 30 + + + ucrBase + + + instat.ucrButtons, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 19 + + + NoControl + + + 9, 230 + + + 121, 25 + + + 26 + + + Bar Chart Options + + + cmdBarChartOptions + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 20 + + + NoControl + + + 9, 230 + + + 121, 25 + + + 24 + + + Pie Chart Options + + + cmdPieChartOptions + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 21 + + + 86, 5 + + + 241, 36 + + + 15 + + + ucrPnlDataType + + + instat.UcrPanel, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 22 + + + CenterScreen + + + Treemap + + + dlgTreemap + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 254, 126 + + + 0, 0, 0, 0 + + + 120, 20 + + + 22 + + + ucrReceiverWeightBy + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 16 + + \ No newline at end of file diff --git a/instat/dlgTreemap.vb b/instat/dlgTreemap.vb new file mode 100644 index 00000000000..136eeb41c0f --- /dev/null +++ b/instat/dlgTreemap.vb @@ -0,0 +1,334 @@ +' R- Instat +' Copyright (C) 2015-2017 +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License +' along with this program. If not, see . + +Imports instat +Imports instat.Translations + +Public Class dlgTreemap + Private clsBaseOperator As New ROperator + + Private clsPipeOperator As New ROperator + Private clsGroupByFunction As New RFunction + Private clsSummariseFunction As New RFunction + Private clsSummaryFunction As New RFunction + + Private clsGgplotFunction As New RFunction + Private clsGeomTreemapFunction As New RFunction + Private clsGeomTreemapAesFunction As New RFunction + Private clsGeomTreemapTextFunction As New RFunction + Private clsGeomTreemapTextAesFunction As New RFunction + + Private clsPaste0Function As New RFunction + Private clsDollarFunction As New RFunction + + Private clsLocalAesFunction As New RFunction + + Private clsRCoordPolarParam As New RParameter + Private clsLabsFunction As New RFunction + Private clsXlabFunction As New RFunction + Private clsYlabFunction As New RFunction + Private clsXScalecontinuousFunction As New RFunction + Private clsYScalecontinuousFunction As New RFunction + Private clsRFacetFunction As New RFunction + Private clsThemeFuction As New RFunction + Private dctThemeFunctions As New Dictionary(Of String, RFunction) + + Private bReset As Boolean = True + Private bFirstLoad As Boolean = True + + Private Sub dlgTreemap_Load(sender As Object, e As EventArgs) Handles MyBase.Load + If bFirstLoad Then + InitialiseDialog() + bFirstLoad = False + End If + If bReset Then + SetDefaults() + End If + SetRCodeForControls(bReset) + bReset = False + autoTranslate(Me) + TestOkEnabled() + End Sub + + Private Sub InitialiseDialog() + ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False + ucrBase.clsRsyntax.iCallType = 3 + 'ucrBase.iHelpTopicID = + + ucrPnlDataType.AddRadioButton(rdoPrimary) + ucrPnlDataType.AddRadioButton(rdoSummary) + ucrPnlDataType.AddParameterPresentCondition(rdoPrimary, "group_by", False) + ucrPnlDataType.AddParameterPresentCondition(rdoSummary, "group_by", True) + + ucrSelectorTreemap.SetParameter(New RParameter("data", 0)) + ucrSelectorTreemap.SetParameterIsrfunction() + + ucrReceiverIdentifier.Selector = ucrSelectorTreemap + ucrReceiverIdentifier.SetParameter(New RParameter("0", 0, bNewIncludeArgumentName:=False)) + ucrReceiverIdentifier.bWithQuotes = False + ucrReceiverIdentifier.SetParameterIsString() + + ucrReceiverWeightBy.Selector = ucrSelectorTreemap + ucrReceiverWeightBy.SetIncludedDataTypes({"numeric"}) + ucrReceiverWeightBy.strSelectorHeading = "Numerics" + ucrReceiverWeightBy.SetParameter(New RParameter("area", 1)) + ucrReceiverWeightBy.bWithQuotes = False + ucrReceiverWeightBy.SetParameterIsString() + ucrReceiverWeightBy.SetValuesToIgnore({".n"}) + + ucrInputSummary.SetItems({"sum", "mean", "min", "max"}) + ucrInputSummary.AddQuotesIfUnrecognised = False + ucrInputSummary.SetLinkedDisplayControl(lblSummary) + + ucrChkIsCurrency.SetText("Is Currency") + ucrChkIsCurrency.SetParameter(New RParameter("weight", iNewPosition:=2, bNewIncludeArgumentName:=False), bNewChangeParameterValue:=False, bNewAddRemoveParameter:=True) + ucrChkIsCurrency.AddToLinkedControls(ucrInputSymbol, {True}, bNewLinkedHideIfParameterMissing:=True) + + ucrInputSymbol.SetParameter(New RParameter("prefix", 3)) + ucrInputSymbol.SetLinkedDisplayControl(lblSymbol) + + ucrInputLabel.SetItems({"Identifier only", "Identifier & Weight", "Weight only", "None"}) + ucrInputLabel.AddParameterPresentCondition("Identifier only", "group") + ucrInputLabel.AddParameterPresentCondition("Identifier & Weight", "\n") + ucrInputLabel.AddParameterPresentCondition("Weight only", "weight") + ucrInputLabel.AddParameterPresentCondition("None", "label", bNewIsPositive:=False) + ucrInputLabel.SetDropDownStyleAsNonEditable() + + ucrReceiverFill.Selector = ucrSelectorTreemap + ucrReceiverFill.SetParameter(New RParameter("fill", 3)) + ucrReceiverFill.bWithQuotes = False + ucrReceiverFill.SetParameterIsString() + + ucrColourBox.SetParameter(New RParameter("fill", 3)) + + ucrColourText.SetParameter(New RParameter("colour", 3)) + End Sub + + Private Sub SetDefaults() + clsBaseOperator = New ROperator + clsPipeOperator = New ROperator + clsGroupByFunction = New RFunction + clsSummariseFunction = New RFunction + clsSummaryFunction = New RFunction + clsGgplotFunction = New RFunction + clsGeomTreemapFunction = New RFunction + clsGeomTreemapAesFunction = New RFunction + clsGeomTreemapTextFunction = New RFunction + clsGeomTreemapTextAesFunction = New RFunction + clsPaste0Function = New RFunction + clsDollarFunction = New RFunction + clsLocalAesFunction = New RFunction + clsRCoordPolarParam = New RParameter + clsLabsFunction = New RFunction + clsXlabFunction = New RFunction + clsYlabFunction = New RFunction + clsXScalecontinuousFunction = New RFunction + clsYScalecontinuousFunction = New RFunction + clsRFacetFunction = New RFunction + clsThemeFuction = New RFunction + dctThemeFunctions = New Dictionary(Of String, RFunction) + + ucrSelectorTreemap.Reset() + ucrSelectorTreemap.SetGgplotFunction(clsBaseOperator) + ucrReceiverIdentifier.SetMeAsReceiver() + ucrSaveTreemap.Reset() + + clsPipeOperator.SetOperation("%>%") + + clsGroupByFunction.SetPackageName("dplyr") + clsGroupByFunction.SetRCommand("group_by") + + clsSummariseFunction.SetPackageName("dplyr") + clsSummariseFunction.SetRCommand("summarise") + clsSummariseFunction.AddParameter(".n", "n()", iPosition:=0) + + clsSummaryFunction.SetRCommand("sum") + clsSummaryFunction.AddParameter("na.rm", "TRUE", iPosition:=1) + + clsBaseOperator.SetOperation("+") + clsBaseOperator.AddParameter("ggplot", clsRFunctionParameter:=clsGgplotFunction, iPosition:=0) + clsBaseOperator.AddParameter("geomfunc", clsRFunctionParameter:=clsGeomTreemapFunction, iPosition:=2) + + clsGgplotFunction.SetPackageName("ggplot2") + clsGgplotFunction.SetRCommand("ggplot") + clsGgplotFunction.AddParameter("data", clsROperatorParameter:=clsPipeOperator, iPosition:=0) + clsGgplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTreemapAesFunction, iPosition:=1) + + clsGeomTreemapAesFunction.SetPackageName("ggplot2") + clsGeomTreemapAesFunction.SetRCommand("aes") + + clsGeomTreemapFunction.SetPackageName("treemapify") + clsGeomTreemapFunction.SetRCommand("geom_treemap") + clsGeomTreemapFunction.AddParameter("fill", Chr(34) & "brown" & Chr(34), iPosition:=2) + + clsGeomTreemapTextFunction.SetPackageName("treemapify") + clsGeomTreemapTextFunction.SetRCommand("geom_treemap_text") + clsGeomTreemapTextFunction.AddParameter("mapping", clsRFunctionParameter:=clsGeomTreemapTextAesFunction, iPosition:=0) + clsGeomTreemapTextFunction.AddParameter("colour", Chr(34) & "white" & Chr(34), iPosition:=2) + + clsGeomTreemapTextAesFunction.SetPackageName("ggplot2") + clsGeomTreemapTextAesFunction.SetRCommand("aes") + clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) + + clsPaste0Function.SetRCommand("paste0") + clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(), iPosition:=0) + + clsDollarFunction.SetPackageName("scales") + clsDollarFunction.SetRCommand("dollar") + clsDollarFunction.AddParameter("prefix", Chr(34) & "$" & Chr(34), iPosition:=3) + + clsLabsFunction = GgplotDefaults.clsDefaultLabs.Clone() + clsXlabFunction = GgplotDefaults.clsXlabTitleFunction.Clone() + clsYlabFunction = GgplotDefaults.clsYlabTitleFunction.Clone() + clsXScalecontinuousFunction = GgplotDefaults.clsXScalecontinuousFunction.Clone() + clsYScalecontinuousFunction = GgplotDefaults.clsYScalecontinuousFunction.Clone + clsRFacetFunction = GgplotDefaults.clsFacetFunction.Clone() + clsBaseOperator.AddParameter(GgplotDefaults.clsDefaultThemeParameter.Clone()) + clsThemeFuction = GgplotDefaults.clsDefaultThemeFunction.Clone + dctThemeFunctions = New Dictionary(Of String, RFunction)(GgplotDefaults.dctThemeFunctions) + clsLocalAesFunction = GgplotDefaults.clsAesFunction.Clone() + + clsBaseOperator.SetAssignTo("last_graph", strTempDataframe:=ucrSelectorTreemap.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempGraph:="last_graph") + ucrBase.clsRsyntax.SetBaseROperator(clsBaseOperator) + End Sub + + Private Sub SetRCodeForControls(bReset As Boolean) + ucrPnlDataType.SetRCode(clsPipeOperator, bReset) + ucrSelectorTreemap.SetRCode(clsPipeOperator, bReset) + ucrReceiverIdentifier.SetRCode(clsGroupByFunction, bReset) + ucrReceiverWeightBy.SetRCode(clsGeomTreemapAesFunction, bReset) + ucrReceiverWeightBy.SetRCode(clsGeomTreemapAesFunction, bReset) + ucrChkIsCurrency.SetRCode(clsPaste0Function, bReset) + ucrInputSymbol.SetRCode(clsDollarFunction, bReset) + ucrInputLabel.SetRCode(clsPaste0Function, bReset) + ucrReceiverFill.SetRCode(clsGeomTreemapAesFunction, bReset) + ucrColourBox.SetRCode(clsGeomTreemapFunction, bReset) + ucrColourText.SetRCode(clsGeomTreemapTextFunction, bReset) + + ucrInputLabel.SetText("Identifier only") + SetLabel() + End Sub + + Private Sub TestOkEnabled() + If Not ucrReceiverIdentifier.IsEmpty() AndAlso ucrSaveTreemap.IsComplete() Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If + End Sub + + Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset + SetDefaults() + SetRCodeForControls(True) + TestOkEnabled() + End Sub + + Private Sub CoreControls_ContentsChanged() Handles ucrReceiverIdentifier.ControlContentsChanged, ucrSaveTreemap.ControlContentsChanged + TestOkEnabled() + End Sub + + Private Sub ucrPnlDataType_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlDataType.ControlValueChanged + If rdoPrimary.Checked Then + lblGroupByIdentifier.Text = "Identifier:" + lblWeightBy.Text = "Weight By (Optional):" + clsPipeOperator.AddParameter("1", clsRFunctionParameter:=clsGroupByFunction, iPosition:=1) + clsPipeOperator.AddParameter("2", clsRFunctionParameter:=clsSummariseFunction, iPosition:=2) + ElseIf rdoSummary.Checked Then + lblGroupByIdentifier.Text = "Identifier (Optional):" + lblWeightBy.Text = "Weight By:" + clsPipeOperator.RemoveParameterByName("1") + clsPipeOperator.RemoveParameterByName("2") + End If + End Sub + + Private Sub ucrInputLabel_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLabel.ControlValueChanged + SetLabel() + End Sub + + Private Sub SetLabel() + clsPaste0Function.ClearParameters() + Select Case ucrInputLabel.GetText() + Case "Identifier only" + clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) + clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) + clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) + Case "Identifier & Weight", "Weight only" + clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) + clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) + clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) + clsPaste0Function.AddParameter("\n", "\n", iPosition:=1, bIncludeArgumentName:=False) + SetWeightLabel() + Case "None" + clsBaseOperator.RemoveParameterByName("geomfunc2") + clsGeomTreemapTextAesFunction.RemoveParameterByName("label") + End Select + End Sub + + Private Sub SetWeightLabel() + If ucrChkIsCurrency.Checked Then + clsPaste0Function.AddParameter("weight", clsRFunctionParameter:=clsDollarFunction, iPosition:=2, bIncludeArgumentName:=False) + Else + clsPaste0Function.AddParameter("weight", ucrReceiverIdentifier.GetVariableNames(), iPosition:=2, bIncludeArgumentName:=False) + End If + End Sub + + Private Sub ucrReceiverFill_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFill.ControlValueChanged + If ucrReceiverFill.IsEmpty() Then + clsGeomTreemapFunction.AddParameter("fill", ucrColourBox.GetText(), iPosition:=3) + ucrColourBox.Enabled = True + Else + clsGeomTreemapFunction.RemoveParameterByName("fill") + ucrColourBox.Enabled = False + End If + End Sub + + Private Sub ucrReceivers_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverIdentifier.ControlValueChanged, ucrReceiverWeightBy.ControlValueChanged, ucrPnlDataType.ControlValueChanged + If rdoPrimary.Checked Then + If ucrReceiverWeightBy.IsEmpty Then + clsGeomTreemapAesFunction.AddParameter("area", ".n", iPosition:=0) + Else + clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(), iPosition:=0) + End If + ElseIf rdoSummary.Checked Then + clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(), iPosition:=0) + End If + SetLabel() + End Sub + + Private Sub ucrReceiverWeightBy_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverWeightBy.ControlValueChanged + If ucrReceiverWeightBy.IsEmpty Then + ucrChkIsCurrency.Visible = False + Else + ucrChkIsCurrency.Visible = True + End If + End Sub + + Private Sub ucrInputSummary_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputSummary.ControlValueChanged + clsSummaryFunction.SetRCommand(ucrInputSummary.GetText()) + End Sub + + Private Sub ucrSelectorTreemap_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorTreemap.ControlValueChanged, ucrPnlDataType.ControlValueChanged + SetPipeAssignTo() + End Sub + + Private Sub SetPipeAssignTo() + If rdoPrimary.Checked Then + clsPipeOperator.SetAssignTo(ucrSelectorTreemap.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_summary") + ElseIf rdoSummary.Checked Then + clsPipeOperator.RemoveAssignTo() + End If + End Sub +End Class \ No newline at end of file From 82423fcf6dc7f7f0a2f139fc50513f1442a4b356 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Sun, 6 Oct 2019 20:39:03 +0100 Subject: [PATCH 02/10] set up sub dialog and currency and summary options --- instat/dlgTreemap.Designer.vb | 34 ++--- instat/dlgTreemap.resx | 84 +++---------- instat/dlgTreemap.vb | 227 +++++++++++++++++++++++++--------- 3 files changed, 189 insertions(+), 156 deletions(-) diff --git a/instat/dlgTreemap.Designer.vb b/instat/dlgTreemap.Designer.vb index f3521ad9b72..aebcdeec6ce 100644 --- a/instat/dlgTreemap.Designer.vb +++ b/instat/dlgTreemap.Designer.vb @@ -31,13 +31,11 @@ Partial Class dlgTreemap Me.rdoSummary = New System.Windows.Forms.RadioButton() Me.cmdOptions = New System.Windows.Forms.Button() Me.lblWeightBy = New System.Windows.Forms.Label() - Me.lblGroupByIdentifier = New System.Windows.Forms.Label() + Me.lblIdentifier = New System.Windows.Forms.Label() Me.ucrReceiverWeightBy = New instat.ucrReceiverSingle() Me.ucrReceiverIdentifier = New instat.ucrReceiverSingle() Me.ucrSelectorTreemap = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrBase = New instat.ucrButtons() - Me.cmdBarChartOptions = New System.Windows.Forms.Button() - Me.cmdPieChartOptions = New System.Windows.Forms.Button() Me.ucrPnlDataType = New instat.UcrPanel() Me.lblSymbol = New System.Windows.Forms.Label() Me.ucrInputSymbol = New instat.ucrInputTextBox() @@ -113,11 +111,11 @@ Partial Class dlgTreemap Me.lblWeightBy.Name = "lblWeightBy" Me.lblWeightBy.Tag = "" ' - 'lblGroupByIdentifier + 'lblIdentifier ' - resources.ApplyResources(Me.lblGroupByIdentifier, "lblGroupByIdentifier") - Me.lblGroupByIdentifier.Name = "lblGroupByIdentifier" - Me.lblGroupByIdentifier.Tag = "Variable:" + resources.ApplyResources(Me.lblIdentifier, "lblIdentifier") + Me.lblIdentifier.Name = "lblIdentifier" + Me.lblIdentifier.Tag = "Variable:" ' 'ucrReceiverWeightBy ' @@ -150,20 +148,6 @@ Partial Class dlgTreemap resources.ApplyResources(Me.ucrBase, "ucrBase") Me.ucrBase.Name = "ucrBase" ' - 'cmdBarChartOptions - ' - resources.ApplyResources(Me.cmdBarChartOptions, "cmdBarChartOptions") - Me.cmdBarChartOptions.Name = "cmdBarChartOptions" - Me.cmdBarChartOptions.Tag = "Bar_Chart_Options" - Me.cmdBarChartOptions.UseVisualStyleBackColor = True - ' - 'cmdPieChartOptions - ' - resources.ApplyResources(Me.cmdPieChartOptions, "cmdPieChartOptions") - Me.cmdPieChartOptions.Name = "cmdPieChartOptions" - Me.cmdPieChartOptions.Tag = "Pie_Chart_Options" - Me.cmdPieChartOptions.UseVisualStyleBackColor = True - ' 'ucrPnlDataType ' resources.ApplyResources(Me.ucrPnlDataType, "ucrPnlDataType") @@ -262,13 +246,11 @@ Partial Class dlgTreemap Me.Controls.Add(Me.rdoSummary) Me.Controls.Add(Me.cmdOptions) Me.Controls.Add(Me.lblWeightBy) - Me.Controls.Add(Me.lblGroupByIdentifier) + Me.Controls.Add(Me.lblIdentifier) Me.Controls.Add(Me.ucrReceiverWeightBy) Me.Controls.Add(Me.ucrReceiverIdentifier) Me.Controls.Add(Me.ucrSelectorTreemap) Me.Controls.Add(Me.ucrBase) - Me.Controls.Add(Me.cmdBarChartOptions) - Me.Controls.Add(Me.cmdPieChartOptions) Me.Controls.Add(Me.ucrPnlDataType) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False @@ -289,13 +271,11 @@ Partial Class dlgTreemap Friend WithEvents rdoSummary As RadioButton Friend WithEvents cmdOptions As Button Friend WithEvents lblWeightBy As Label - Friend WithEvents lblGroupByIdentifier As Label + Friend WithEvents lblIdentifier As Label Friend WithEvents ucrReceiverWeightBy As ucrReceiverSingle Friend WithEvents ucrReceiverIdentifier As ucrReceiverSingle Friend WithEvents ucrSelectorTreemap As ucrSelectorByDataFrameAddRemove Friend WithEvents ucrBase As ucrButtons - Friend WithEvents cmdBarChartOptions As Button - Friend WithEvents cmdPieChartOptions As Button Friend WithEvents ucrPnlDataType As UcrPanel Friend WithEvents ucrInputSymbol As ucrInputTextBox Friend WithEvents lblSymbol As Label diff --git a/instat/dlgTreemap.resx b/instat/dlgTreemap.resx index 8b313e3cc67..2b7995b2d1e 100644 --- a/instat/dlgTreemap.resx +++ b/instat/dlgTreemap.resx @@ -292,7 +292,7 @@ NoControl - 9, 261 + 9, 232 121, 25 @@ -345,34 +345,34 @@ 14 - + True - + NoControl - + 254, 61 - - 54, 13 + + 50, 13 - + 19 - - Group By: + + Identifier: - - lblGroupByIdentifier + + lblIdentifier - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 15 @@ -735,60 +735,6 @@ 19 - - NoControl - - - 9, 230 - - - 121, 25 - - - 26 - - - Bar Chart Options - - - cmdBarChartOptions - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 20 - - - NoControl - - - 9, 230 - - - 121, 25 - - - 24 - - - Pie Chart Options - - - cmdPieChartOptions - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 21 - 86, 5 @@ -808,7 +754,7 @@ $this - 22 + 20 CenterScreen diff --git a/instat/dlgTreemap.vb b/instat/dlgTreemap.vb index 136eeb41c0f..f3425467654 100644 --- a/instat/dlgTreemap.vb +++ b/instat/dlgTreemap.vb @@ -43,11 +43,20 @@ Public Class dlgTreemap Private clsXScalecontinuousFunction As New RFunction Private clsYScalecontinuousFunction As New RFunction Private clsRFacetFunction As New RFunction + Private clsCoordPolarFunction As New RFunction + Private clsCoordPolarStartOperator As New ROperator Private clsThemeFuction As New RFunction Private dctThemeFunctions As New Dictionary(Of String, RFunction) + Private strIdentifier As String = "Identifier" + Private strIdentifierAndWeighty As String = "Identifier & Weight" + Private strWeight As String = "Weight" + Private strNone As String = "None" + Private bReset As Boolean = True Private bFirstLoad As Boolean = True + Private bRCodeSet As Boolean = False + Private bResetSubdialog As Boolean = True Private Sub dlgTreemap_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then @@ -70,8 +79,8 @@ Public Class dlgTreemap ucrPnlDataType.AddRadioButton(rdoPrimary) ucrPnlDataType.AddRadioButton(rdoSummary) - ucrPnlDataType.AddParameterPresentCondition(rdoPrimary, "group_by", False) - ucrPnlDataType.AddParameterPresentCondition(rdoSummary, "group_by", True) + ucrPnlDataType.AddParameterPresentCondition(rdoPrimary, "group_by", True) + ucrPnlDataType.AddParameterPresentCondition(rdoSummary, "group_by", False) ucrSelectorTreemap.SetParameter(New RParameter("data", 0)) ucrSelectorTreemap.SetParameterIsrfunction() @@ -92,19 +101,23 @@ Public Class dlgTreemap ucrInputSummary.SetItems({"sum", "mean", "min", "max"}) ucrInputSummary.AddQuotesIfUnrecognised = False ucrInputSummary.SetLinkedDisplayControl(lblSummary) + ucrInputSummary.SetValidationTypeAsRVariable() ucrChkIsCurrency.SetText("Is Currency") - ucrChkIsCurrency.SetParameter(New RParameter("weight", iNewPosition:=2, bNewIncludeArgumentName:=False), bNewChangeParameterValue:=False, bNewAddRemoveParameter:=True) + ucrChkIsCurrency.SetParameter(New RParameter("dollar", iNewPosition:=2, bNewIncludeArgumentName:=False), bNewChangeParameterValue:=False, bNewAddRemoveParameter:=True) ucrChkIsCurrency.AddToLinkedControls(ucrInputSymbol, {True}, bNewLinkedHideIfParameterMissing:=True) ucrInputSymbol.SetParameter(New RParameter("prefix", 3)) ucrInputSymbol.SetLinkedDisplayControl(lblSymbol) - ucrInputLabel.SetItems({"Identifier only", "Identifier & Weight", "Weight only", "None"}) - ucrInputLabel.AddParameterPresentCondition("Identifier only", "group") - ucrInputLabel.AddParameterPresentCondition("Identifier & Weight", "\n") - ucrInputLabel.AddParameterPresentCondition("Weight only", "weight") - ucrInputLabel.AddParameterPresentCondition("None", "label", bNewIsPositive:=False) + ucrInputLabel.SetItems({strIdentifier, strIdentifierAndWeighty, strWeight, strNone}) + ucrInputLabel.AddParameterPresentCondition(strIdentifier, "identifier") + ucrInputLabel.AddParameterPresentCondition(strIdentifier, "\n", False) + ucrInputLabel.AddParameterPresentCondition(strIdentifierAndWeighty, "\n") + ucrInputLabel.AddParameterPresentCondition(strWeight, "weight") + ucrInputLabel.AddParameterPresentCondition(strWeight, "\n", False) + ucrInputLabel.AddParameterPresentCondition(strNone, "identifier", False) + ucrInputLabel.AddParameterPresentCondition(strNone, "weight", False) ucrInputLabel.SetDropDownStyleAsNonEditable() ucrReceiverFill.Selector = ucrSelectorTreemap @@ -113,8 +126,17 @@ Public Class dlgTreemap ucrReceiverFill.SetParameterIsString() ucrColourBox.SetParameter(New RParameter("fill", 3)) + ucrColourBox.SetColours() ucrColourText.SetParameter(New RParameter("colour", 3)) + ucrColourText.SetColours() + + ucrSaveTreemap.SetIsComboBox() + ucrSaveTreemap.SetCheckBoxText("Save Treemap") + ucrSaveTreemap.SetDataFrameSelector(ucrSelectorTreemap.ucrAvailableDataFrames) + ucrSaveTreemap.SetSaveTypeAsGraph() + ucrSaveTreemap.SetPrefix("treemap") + ucrSaveTreemap.SetAssignToIfUncheckedValue("last_graph") End Sub Private Sub SetDefaults() @@ -141,12 +163,16 @@ Public Class dlgTreemap clsThemeFuction = New RFunction dctThemeFunctions = New Dictionary(Of String, RFunction) + bResetSubdialog = True + ucrSelectorTreemap.Reset() ucrSelectorTreemap.SetGgplotFunction(clsBaseOperator) ucrReceiverIdentifier.SetMeAsReceiver() ucrSaveTreemap.Reset() clsPipeOperator.SetOperation("%>%") + clsPipeOperator.AddParameter("group_by", clsRFunctionParameter:=clsGroupByFunction, iPosition:=1) + clsPipeOperator.AddParameter("summarise", clsRFunctionParameter:=clsGroupByFunction, iPosition:=2) clsGroupByFunction.SetPackageName("dplyr") clsGroupByFunction.SetRCommand("group_by") @@ -184,7 +210,7 @@ Public Class dlgTreemap clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) clsPaste0Function.SetRCommand("paste0") - clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(), iPosition:=0) + clsPaste0Function.AddParameter("identifier", ucrReceiverIdentifier.GetVariableNames(), iPosition:=0) clsDollarFunction.SetPackageName("scales") clsDollarFunction.SetRCommand("dollar") @@ -196,6 +222,8 @@ Public Class dlgTreemap clsXScalecontinuousFunction = GgplotDefaults.clsXScalecontinuousFunction.Clone() clsYScalecontinuousFunction = GgplotDefaults.clsYScalecontinuousFunction.Clone clsRFacetFunction = GgplotDefaults.clsFacetFunction.Clone() + clsCoordPolarFunction = GgplotDefaults.clsCoordPolarFunction.Clone() + clsCoordPolarStartOperator = GgplotDefaults.clsCoordPolarStartOperator.Clone() clsBaseOperator.AddParameter(GgplotDefaults.clsDefaultThemeParameter.Clone()) clsThemeFuction = GgplotDefaults.clsDefaultThemeFunction.Clone dctThemeFunctions = New Dictionary(Of String, RFunction)(GgplotDefaults.dctThemeFunctions) @@ -206,27 +234,43 @@ Public Class dlgTreemap End Sub Private Sub SetRCodeForControls(bReset As Boolean) + bRCodeSet = False + ucrReceiverWeightBy.AddAdditionalCodeParameterPair(clsSummaryFunction, New RParameter("x", iNewPosition:=0, bNewIncludeArgumentName:=False)) + ucrPnlDataType.SetRCode(clsPipeOperator, bReset) ucrSelectorTreemap.SetRCode(clsPipeOperator, bReset) ucrReceiverIdentifier.SetRCode(clsGroupByFunction, bReset) ucrReceiverWeightBy.SetRCode(clsGeomTreemapAesFunction, bReset) - ucrReceiverWeightBy.SetRCode(clsGeomTreemapAesFunction, bReset) ucrChkIsCurrency.SetRCode(clsPaste0Function, bReset) ucrInputSymbol.SetRCode(clsDollarFunction, bReset) ucrInputLabel.SetRCode(clsPaste0Function, bReset) ucrReceiverFill.SetRCode(clsGeomTreemapAesFunction, bReset) ucrColourBox.SetRCode(clsGeomTreemapFunction, bReset) ucrColourText.SetRCode(clsGeomTreemapTextFunction, bReset) - - ucrInputLabel.SetText("Identifier only") + If bReset Then + ucrInputLabel.SetText(strIdentifier) + End If + bRCodeSet = True + ucrInputSummary.SetName(clsSummaryFunction.strRCommand) SetLabel() + WeightControls() + SetPipeAssignTo() + PanelSettings() End Sub Private Sub TestOkEnabled() - If Not ucrReceiverIdentifier.IsEmpty() AndAlso ucrSaveTreemap.IsComplete() Then - ucrBase.OKEnabled(True) - Else - ucrBase.OKEnabled(False) + If rdoPrimary.Checked Then + If Not ucrReceiverIdentifier.IsEmpty() AndAlso ucrSaveTreemap.IsComplete() Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If + ElseIf rdoSummary.Checked Then + If Not ucrReceiverWeightBy.IsEmpty() AndAlso ucrSaveTreemap.IsComplete() Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If End If End Sub @@ -236,21 +280,31 @@ Public Class dlgTreemap TestOkEnabled() End Sub - Private Sub CoreControls_ContentsChanged() Handles ucrReceiverIdentifier.ControlContentsChanged, ucrSaveTreemap.ControlContentsChanged + Private Sub CoreControls_ContentsChanged() Handles ucrReceiverIdentifier.ControlContentsChanged, ucrSaveTreemap.ControlContentsChanged, ucrPnlDataType.ControlContentsChanged TestOkEnabled() End Sub Private Sub ucrPnlDataType_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlDataType.ControlValueChanged - If rdoPrimary.Checked Then - lblGroupByIdentifier.Text = "Identifier:" - lblWeightBy.Text = "Weight By (Optional):" - clsPipeOperator.AddParameter("1", clsRFunctionParameter:=clsGroupByFunction, iPosition:=1) - clsPipeOperator.AddParameter("2", clsRFunctionParameter:=clsSummariseFunction, iPosition:=2) - ElseIf rdoSummary.Checked Then - lblGroupByIdentifier.Text = "Identifier (Optional):" - lblWeightBy.Text = "Weight By:" - clsPipeOperator.RemoveParameterByName("1") - clsPipeOperator.RemoveParameterByName("2") + PanelSettings() + End Sub + + Private Sub PanelSettings() + If bRCodeSet Then + If rdoPrimary.Checked Then + ' Cannot have facets in Primary data case since columns are not carried. + clsBaseOperator.RemoveParameterByName("facets") + lblIdentifier.Text = "Identifier:" + lblWeightBy.Text = "Weight By (Optional):" + clsPipeOperator.AddParameter("group_by", clsRFunctionParameter:=clsGroupByFunction, iPosition:=1) + clsPipeOperator.AddParameter("summarise", clsRFunctionParameter:=clsSummariseFunction, iPosition:=2) + ElseIf rdoSummary.Checked Then + lblIdentifier.Text = "Identifier (Optional):" + lblWeightBy.Text = "Weight By:" + clsPipeOperator.RemoveParameterByName("group_by") + clsPipeOperator.RemoveParameterByName("summarise") + End If + SetPipeAssignTo() + WeightControls() End If End Sub @@ -259,29 +313,32 @@ Public Class dlgTreemap End Sub Private Sub SetLabel() - clsPaste0Function.ClearParameters() - Select Case ucrInputLabel.GetText() - Case "Identifier only" - clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) - clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) - clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) - Case "Identifier & Weight", "Weight only" - clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) - clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) - clsPaste0Function.AddParameter("group", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) - clsPaste0Function.AddParameter("\n", "\n", iPosition:=1, bIncludeArgumentName:=False) - SetWeightLabel() - Case "None" - clsBaseOperator.RemoveParameterByName("geomfunc2") - clsGeomTreemapTextAesFunction.RemoveParameterByName("label") - End Select - End Sub - - Private Sub SetWeightLabel() - If ucrChkIsCurrency.Checked Then - clsPaste0Function.AddParameter("weight", clsRFunctionParameter:=clsDollarFunction, iPosition:=2, bIncludeArgumentName:=False) - Else - clsPaste0Function.AddParameter("weight", ucrReceiverIdentifier.GetVariableNames(), iPosition:=2, bIncludeArgumentName:=False) + If bRCodeSet Then + clsPaste0Function.ClearParameters() + Select Case ucrInputLabel.GetText() + Case strIdentifier + clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) + clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) + clsPaste0Function.AddParameter("identifier", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) + Case strIdentifierAndWeighty, strWeight + clsBaseOperator.AddParameter("geomfunc2", clsRFunctionParameter:=clsGeomTreemapTextFunction, iPosition:=3) + clsGeomTreemapTextAesFunction.AddParameter("label", clsRFunctionParameter:=clsPaste0Function, iPosition:=2) + If ucrInputLabel.GetText() = strIdentifierAndWeighty Then + clsPaste0Function.AddParameter("identifier", ucrReceiverIdentifier.GetVariableNames(False), iPosition:=0, bIncludeArgumentName:=False) + clsPaste0Function.AddParameter("\n", Chr(34) & "\n" & Chr(34), iPosition:=1, bIncludeArgumentName:=False) + End If + If ucrChkIsCurrency.Checked Then + clsPaste0Function.AddParameter("dollar", clsRFunctionParameter:=clsDollarFunction, iPosition:=2, bIncludeArgumentName:=False) + clsDollarFunction.AddParameter("x", ucrReceiverWeightBy.GetVariableNames(False), iPosition:=0) + clsPaste0Function.RemoveParameterByName("weight") + Else + clsPaste0Function.AddParameter("weight", ucrReceiverWeightBy.GetVariableNames(False), iPosition:=2, bIncludeArgumentName:=False) + clsPaste0Function.RemoveParameterByName("dollar") + End If + Case strNone + clsBaseOperator.RemoveParameterByName("geomfunc2") + clsGeomTreemapTextAesFunction.RemoveParameterByName("label") + End Select End If End Sub @@ -300,19 +357,48 @@ Public Class dlgTreemap If ucrReceiverWeightBy.IsEmpty Then clsGeomTreemapAesFunction.AddParameter("area", ".n", iPosition:=0) Else - clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(), iPosition:=0) + clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(False), iPosition:=0) End If ElseIf rdoSummary.Checked Then - clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(), iPosition:=0) + clsGeomTreemapAesFunction.AddParameter("area", ucrReceiverWeightBy.GetVariableNames(False), iPosition:=0) End If SetLabel() End Sub Private Sub ucrReceiverWeightBy_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverWeightBy.ControlValueChanged - If ucrReceiverWeightBy.IsEmpty Then - ucrChkIsCurrency.Visible = False - Else - ucrChkIsCurrency.Visible = True + WeightControls() + End Sub + + Private Sub WeightControls() + If bRCodeSet Then + If rdoPrimary.Checked Then + ucrInputSummary.Visible = True + If ucrReceiverWeightBy.IsEmpty Then + ucrChkIsCurrency.Enabled = False + ucrInputSummary.Enabled = False + ucrInputSymbol.Enabled = False + If {strIdentifierAndWeighty, strWeight}.Contains(ucrInputLabel.GetText()) Then + ucrInputLabel.SetName(strIdentifier) + End If + Else + ucrChkIsCurrency.Enabled = True + ucrInputSummary.Enabled = True + ucrInputSymbol.Enabled = True + End If + ElseIf rdoSummary.Checked Then + ucrInputSummary.Visible = False + End If + SetSummary() + End If + End Sub + + Private Sub SetSummary() + If bRCodeSet Then + clsSummariseFunction.ClearParameters() + clsSummariseFunction.AddParameter(".n", "n()", iPosition:=0) + If Not ucrReceiverWeightBy.IsEmpty Then + clsSummariseFunction.AddParameter(ucrReceiverWeightBy.GetVariableNames(False), clsRFunctionParameter:=clsSummaryFunction, iPosition:=1) + End If End If End Sub @@ -320,15 +406,36 @@ Public Class dlgTreemap clsSummaryFunction.SetRCommand(ucrInputSummary.GetText()) End Sub - Private Sub ucrSelectorTreemap_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorTreemap.ControlValueChanged, ucrPnlDataType.ControlValueChanged + Private Sub ucrSelectorTreemap_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorTreemap.ControlValueChanged SetPipeAssignTo() End Sub Private Sub SetPipeAssignTo() + If bRCodeSet Then + If rdoPrimary.Checked Then + If ucrSelectorTreemap.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" Then + clsPipeOperator.SetAssignTo(ucrSelectorTreemap.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_summary") + End If + ElseIf rdoSummary.Checked Then + clsPipeOperator.RemoveAssignTo() + End If + End If + End Sub + + Private Sub ucrChkIsCurrency_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkIsCurrency.ControlValueChanged + SetLabel() + End Sub + + Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click + sdgPlots.SetRCode(clsNewOperator:=ucrBase.clsRsyntax.clsBaseOperator, clsNewYScalecontinuousFunction:=clsYScalecontinuousFunction, clsNewXScalecontinuousFunction:=clsXScalecontinuousFunction, clsNewXLabsTitleFunction:=clsXlabFunction, clsNewYLabTitleFunction:=clsYlabFunction, clsNewLabsFunction:=clsLabsFunction, clsNewFacetFunction:=clsRFacetFunction, clsNewCoordPolarFunction:=clsCoordPolarFunction, clsNewCoordPolarStartOperator:=clsCoordPolarStartOperator, clsNewThemeFunction:=clsThemeFuction, dctNewThemeFunctions:=dctThemeFunctions, clsNewGlobalAesFunction:=clsGeomTreemapAesFunction, ucrNewBaseSelector:=ucrSelectorTreemap, bReset:=bResetSubdialog) + 'this is a temporary fix If rdoPrimary.Checked Then - clsPipeOperator.SetAssignTo(ucrSelectorTreemap.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_summary") - ElseIf rdoSummary.Checked Then - clsPipeOperator.RemoveAssignTo() + sdgPlots.tbpFacet.Enabled = False + sdgPlots.tbpLayers.Enabled = False End If + sdgPlots.ShowDialog() + sdgPlots.tbpFacet.Enabled = True + sdgPlots.tbpLayers.Enabled = True + bResetSubdialog = False End Sub End Class \ No newline at end of file From 7bde30beca6ef9dcbe98e79399cf13ce18c7b6cf Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Sun, 6 Oct 2019 20:49:01 +0100 Subject: [PATCH 03/10] corrected test ok --- instat/dlgTreemap.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgTreemap.vb b/instat/dlgTreemap.vb index f3425467654..974c4c34121 100644 --- a/instat/dlgTreemap.vb +++ b/instat/dlgTreemap.vb @@ -280,7 +280,7 @@ Public Class dlgTreemap TestOkEnabled() End Sub - Private Sub CoreControls_ContentsChanged() Handles ucrReceiverIdentifier.ControlContentsChanged, ucrSaveTreemap.ControlContentsChanged, ucrPnlDataType.ControlContentsChanged + Private Sub CoreControls_ContentsChanged() Handles ucrReceiverIdentifier.ControlContentsChanged, ucrSaveTreemap.ControlContentsChanged, ucrPnlDataType.ControlContentsChanged, ucrReceiverWeightBy.ControlContentsChanged TestOkEnabled() End Sub From ef5f75b5bb114ab2dbdb1076e5deecf924f214fa Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Tue, 12 Nov 2019 19:35:26 +0000 Subject: [PATCH 04/10] renamed box to tile on treemap dialog --- instat/dlgTreemap.Designer.vb | 208 +++++++++---------- instat/dlgTreemap.resx | 373 +++++++++++++++++----------------- instat/dlgTreemap.vb | 16 +- 3 files changed, 302 insertions(+), 295 deletions(-) diff --git a/instat/dlgTreemap.Designer.vb b/instat/dlgTreemap.Designer.vb index aebcdeec6ce..219ef142d49 100644 --- a/instat/dlgTreemap.Designer.vb +++ b/instat/dlgTreemap.Designer.vb @@ -24,30 +24,30 @@ Partial Class dlgTreemap Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(dlgTreemap)) Me.lblLabel = New System.Windows.Forms.Label() - Me.ucrInputLabel = New instat.ucrInputComboBox() - Me.ucrSaveTreemap = New instat.ucrSave() - Me.ucrChkIsCurrency = New instat.ucrCheck() Me.rdoPrimary = New System.Windows.Forms.RadioButton() Me.rdoSummary = New System.Windows.Forms.RadioButton() Me.cmdOptions = New System.Windows.Forms.Button() Me.lblWeightBy = New System.Windows.Forms.Label() Me.lblIdentifier = New System.Windows.Forms.Label() - Me.ucrReceiverWeightBy = New instat.ucrReceiverSingle() - Me.ucrReceiverIdentifier = New instat.ucrReceiverSingle() - Me.ucrSelectorTreemap = New instat.ucrSelectorByDataFrameAddRemove() - Me.ucrBase = New instat.ucrButtons() - Me.ucrPnlDataType = New instat.UcrPanel() Me.lblSymbol = New System.Windows.Forms.Label() - Me.ucrInputSymbol = New instat.ucrInputTextBox() Me.lblFill = New System.Windows.Forms.Label() - Me.ucrReceiverFill = New instat.ucrReceiverSingle() Me.grpOptions = New System.Windows.Forms.GroupBox() Me.lblTextColour = New System.Windows.Forms.Label() - Me.ucrColourText = New instat.ucrColors() - Me.lblBoxColour = New System.Windows.Forms.Label() - Me.ucrColourBox = New instat.ucrColors() + Me.lblTileColour = New System.Windows.Forms.Label() Me.lblSummary = New System.Windows.Forms.Label() Me.ucrInputSummary = New instat.ucrInputComboBox() + Me.ucrColourText = New instat.ucrColors() + Me.ucrColourTile = New instat.ucrColors() + Me.ucrReceiverFill = New instat.ucrReceiverSingle() + Me.ucrInputSymbol = New instat.ucrInputTextBox() + Me.ucrInputLabel = New instat.ucrInputComboBox() + Me.ucrSaveTreemap = New instat.ucrSave() + Me.ucrChkIsCurrency = New instat.ucrCheck() + Me.ucrReceiverWeightBy = New instat.ucrReceiverSingle() + Me.ucrReceiverIdentifier = New instat.ucrReceiverSingle() + Me.ucrSelectorTreemap = New instat.ucrSelectorByDataFrameAddRemove() + Me.ucrBase = New instat.ucrButtons() + Me.ucrPnlDataType = New instat.UcrPanel() Me.grpOptions.SuspendLayout() Me.SuspendLayout() ' @@ -56,24 +56,6 @@ Partial Class dlgTreemap resources.ApplyResources(Me.lblLabel, "lblLabel") Me.lblLabel.Name = "lblLabel" ' - 'ucrInputLabel - ' - Me.ucrInputLabel.AddQuotesIfUnrecognised = True - Me.ucrInputLabel.IsReadOnly = False - resources.ApplyResources(Me.ucrInputLabel, "ucrInputLabel") - Me.ucrInputLabel.Name = "ucrInputLabel" - ' - 'ucrSaveTreemap - ' - resources.ApplyResources(Me.ucrSaveTreemap, "ucrSaveTreemap") - Me.ucrSaveTreemap.Name = "ucrSaveTreemap" - ' - 'ucrChkIsCurrency - ' - Me.ucrChkIsCurrency.Checked = False - resources.ApplyResources(Me.ucrChkIsCurrency, "ucrChkIsCurrency") - Me.ucrChkIsCurrency.Name = "ucrChkIsCurrency" - ' 'rdoPrimary ' resources.ApplyResources(Me.rdoPrimary, "rdoPrimary") @@ -117,76 +99,23 @@ Partial Class dlgTreemap Me.lblIdentifier.Name = "lblIdentifier" Me.lblIdentifier.Tag = "Variable:" ' - 'ucrReceiverWeightBy - ' - Me.ucrReceiverWeightBy.frmParent = Me - resources.ApplyResources(Me.ucrReceiverWeightBy, "ucrReceiverWeightBy") - Me.ucrReceiverWeightBy.Name = "ucrReceiverWeightBy" - Me.ucrReceiverWeightBy.Selector = Nothing - Me.ucrReceiverWeightBy.strNcFilePath = "" - Me.ucrReceiverWeightBy.ucrSelector = Nothing - ' - 'ucrReceiverIdentifier - ' - Me.ucrReceiverIdentifier.frmParent = Me - resources.ApplyResources(Me.ucrReceiverIdentifier, "ucrReceiverIdentifier") - Me.ucrReceiverIdentifier.Name = "ucrReceiverIdentifier" - Me.ucrReceiverIdentifier.Selector = Nothing - Me.ucrReceiverIdentifier.strNcFilePath = "" - Me.ucrReceiverIdentifier.ucrSelector = Nothing - ' - 'ucrSelectorTreemap - ' - Me.ucrSelectorTreemap.bDropUnusedFilterLevels = False - Me.ucrSelectorTreemap.bShowHiddenColumns = False - Me.ucrSelectorTreemap.bUseCurrentFilter = True - resources.ApplyResources(Me.ucrSelectorTreemap, "ucrSelectorTreemap") - Me.ucrSelectorTreemap.Name = "ucrSelectorTreemap" - ' - 'ucrBase - ' - resources.ApplyResources(Me.ucrBase, "ucrBase") - Me.ucrBase.Name = "ucrBase" - ' - 'ucrPnlDataType - ' - resources.ApplyResources(Me.ucrPnlDataType, "ucrPnlDataType") - Me.ucrPnlDataType.Name = "ucrPnlDataType" - ' 'lblSymbol ' resources.ApplyResources(Me.lblSymbol, "lblSymbol") Me.lblSymbol.Name = "lblSymbol" ' - 'ucrInputSymbol - ' - Me.ucrInputSymbol.AddQuotesIfUnrecognised = True - Me.ucrInputSymbol.IsMultiline = False - Me.ucrInputSymbol.IsReadOnly = False - resources.ApplyResources(Me.ucrInputSymbol, "ucrInputSymbol") - Me.ucrInputSymbol.Name = "ucrInputSymbol" - ' 'lblFill ' resources.ApplyResources(Me.lblFill, "lblFill") Me.lblFill.Name = "lblFill" Me.lblFill.Tag = "" ' - 'ucrReceiverFill - ' - Me.ucrReceiverFill.frmParent = Me - resources.ApplyResources(Me.ucrReceiverFill, "ucrReceiverFill") - Me.ucrReceiverFill.Name = "ucrReceiverFill" - Me.ucrReceiverFill.Selector = Nothing - Me.ucrReceiverFill.strNcFilePath = "" - Me.ucrReceiverFill.ucrSelector = Nothing - ' 'grpOptions ' Me.grpOptions.Controls.Add(Me.lblTextColour) Me.grpOptions.Controls.Add(Me.ucrColourText) - Me.grpOptions.Controls.Add(Me.lblBoxColour) - Me.grpOptions.Controls.Add(Me.ucrColourBox) + Me.grpOptions.Controls.Add(Me.lblTileColour) + Me.grpOptions.Controls.Add(Me.ucrColourTile) resources.ApplyResources(Me.grpOptions, "grpOptions") Me.grpOptions.Name = "grpOptions" Me.grpOptions.TabStop = False @@ -196,6 +125,23 @@ Partial Class dlgTreemap resources.ApplyResources(Me.lblTextColour, "lblTextColour") Me.lblTextColour.Name = "lblTextColour" ' + 'lblTileColour + ' + resources.ApplyResources(Me.lblTileColour, "lblTileColour") + Me.lblTileColour.Name = "lblTileColour" + ' + 'lblSummary + ' + resources.ApplyResources(Me.lblSummary, "lblSummary") + Me.lblSummary.Name = "lblSummary" + ' + 'ucrInputSummary + ' + Me.ucrInputSummary.AddQuotesIfUnrecognised = True + Me.ucrInputSummary.IsReadOnly = False + resources.ApplyResources(Me.ucrInputSummary, "ucrInputSummary") + Me.ucrInputSummary.Name = "ucrInputSummary" + ' 'ucrColourText ' Me.ucrColourText.AddQuotesIfUnrecognised = True @@ -203,29 +149,83 @@ Partial Class dlgTreemap resources.ApplyResources(Me.ucrColourText, "ucrColourText") Me.ucrColourText.Name = "ucrColourText" ' - 'lblBoxColour + 'ucrColourTile ' - resources.ApplyResources(Me.lblBoxColour, "lblBoxColour") - Me.lblBoxColour.Name = "lblBoxColour" + Me.ucrColourTile.AddQuotesIfUnrecognised = True + Me.ucrColourTile.IsReadOnly = False + resources.ApplyResources(Me.ucrColourTile, "ucrColourTile") + Me.ucrColourTile.Name = "ucrColourTile" ' - 'ucrColourBox + 'ucrReceiverFill ' - Me.ucrColourBox.AddQuotesIfUnrecognised = True - Me.ucrColourBox.IsReadOnly = False - resources.ApplyResources(Me.ucrColourBox, "ucrColourBox") - Me.ucrColourBox.Name = "ucrColourBox" + Me.ucrReceiverFill.frmParent = Me + resources.ApplyResources(Me.ucrReceiverFill, "ucrReceiverFill") + Me.ucrReceiverFill.Name = "ucrReceiverFill" + Me.ucrReceiverFill.Selector = Nothing + Me.ucrReceiverFill.strNcFilePath = "" + Me.ucrReceiverFill.ucrSelector = Nothing ' - 'lblSummary + 'ucrInputSymbol ' - resources.ApplyResources(Me.lblSummary, "lblSummary") - Me.lblSummary.Name = "lblSummary" + Me.ucrInputSymbol.AddQuotesIfUnrecognised = True + Me.ucrInputSymbol.IsMultiline = False + Me.ucrInputSymbol.IsReadOnly = False + resources.ApplyResources(Me.ucrInputSymbol, "ucrInputSymbol") + Me.ucrInputSymbol.Name = "ucrInputSymbol" ' - 'ucrInputSummary + 'ucrInputLabel ' - Me.ucrInputSummary.AddQuotesIfUnrecognised = True - Me.ucrInputSummary.IsReadOnly = False - resources.ApplyResources(Me.ucrInputSummary, "ucrInputSummary") - Me.ucrInputSummary.Name = "ucrInputSummary" + Me.ucrInputLabel.AddQuotesIfUnrecognised = True + Me.ucrInputLabel.IsReadOnly = False + resources.ApplyResources(Me.ucrInputLabel, "ucrInputLabel") + Me.ucrInputLabel.Name = "ucrInputLabel" + ' + 'ucrSaveTreemap + ' + resources.ApplyResources(Me.ucrSaveTreemap, "ucrSaveTreemap") + Me.ucrSaveTreemap.Name = "ucrSaveTreemap" + ' + 'ucrChkIsCurrency + ' + Me.ucrChkIsCurrency.Checked = False + resources.ApplyResources(Me.ucrChkIsCurrency, "ucrChkIsCurrency") + Me.ucrChkIsCurrency.Name = "ucrChkIsCurrency" + ' + 'ucrReceiverWeightBy + ' + Me.ucrReceiverWeightBy.frmParent = Me + resources.ApplyResources(Me.ucrReceiverWeightBy, "ucrReceiverWeightBy") + Me.ucrReceiverWeightBy.Name = "ucrReceiverWeightBy" + Me.ucrReceiverWeightBy.Selector = Nothing + Me.ucrReceiverWeightBy.strNcFilePath = "" + Me.ucrReceiverWeightBy.ucrSelector = Nothing + ' + 'ucrReceiverIdentifier + ' + Me.ucrReceiverIdentifier.frmParent = Me + resources.ApplyResources(Me.ucrReceiverIdentifier, "ucrReceiverIdentifier") + Me.ucrReceiverIdentifier.Name = "ucrReceiverIdentifier" + Me.ucrReceiverIdentifier.Selector = Nothing + Me.ucrReceiverIdentifier.strNcFilePath = "" + Me.ucrReceiverIdentifier.ucrSelector = Nothing + ' + 'ucrSelectorTreemap + ' + Me.ucrSelectorTreemap.bDropUnusedFilterLevels = False + Me.ucrSelectorTreemap.bShowHiddenColumns = False + Me.ucrSelectorTreemap.bUseCurrentFilter = True + resources.ApplyResources(Me.ucrSelectorTreemap, "ucrSelectorTreemap") + Me.ucrSelectorTreemap.Name = "ucrSelectorTreemap" + ' + 'ucrBase + ' + resources.ApplyResources(Me.ucrBase, "ucrBase") + Me.ucrBase.Name = "ucrBase" + ' + 'ucrPnlDataType + ' + resources.ApplyResources(Me.ucrPnlDataType, "ucrPnlDataType") + Me.ucrPnlDataType.Name = "ucrPnlDataType" ' 'dlgTreemap ' @@ -284,8 +284,8 @@ Partial Class dlgTreemap Friend WithEvents grpOptions As GroupBox Friend WithEvents lblTextColour As Label Friend WithEvents ucrColourText As ucrColors - Friend WithEvents lblBoxColour As Label - Friend WithEvents ucrColourBox As ucrColors + Friend WithEvents lblTileColour As Label + Friend WithEvents ucrColourTile As ucrColors Friend WithEvents lblSummary As Label Friend WithEvents ucrInputSummary As ucrInputComboBox End Class diff --git a/instat/dlgTreemap.resx b/instat/dlgTreemap.resx index 2b7995b2d1e..c5ad0ac0ca3 100644 --- a/instat/dlgTreemap.resx +++ b/instat/dlgTreemap.resx @@ -150,72 +150,6 @@ 7 - - 254, 244 - - - 21, 17, 21, 17 - - - 120, 21 - - - 25 - - - ucrInputLabel - - - instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 8 - - - 9, 380 - - - 255, 24 - - - 29 - - - ucrSaveTreemap - - - instat.ucrSave, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 9 - - - 254, 180 - - - 82, 20 - - - 28 - - - ucrChkIsCurrency - - - instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 10 - Button @@ -375,65 +309,65 @@ 15 - + True - - - 6, 13 - - 418, 464 + + NoControl - - 307, 154 + + 272, 203 - - 67, 21 + + 44, 13 - - 37 + + 31 - - ucrInputSummary + + Symbol: - - instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + lblSymbol - + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this - - 0 + + 6 - + True - + NoControl - - 252, 156 + + 254, 277 - - 53, 13 + + 22, 13 - - 36 + + 33 - - Summary: + + Fill: - - lblSummary + + lblFill - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 1 + + 3 True @@ -486,55 +420,55 @@ 1 - + True - + NoControl - + 9, 23 - - 60, 13 + + 59, 13 - + 36 - - Box colour: + + Tile colour: - - lblBoxColour + + lblTileColour - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + grpOptions - + 2 - + 80, 21 - + 137, 21 - + 0 - - ucrColourBox + + ucrColourTile - + instat.ucrColors, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + grpOptions - + 3 @@ -561,59 +495,65 @@ 2 - + True - + NoControl - - 254, 277 + + 252, 156 - - 22, 13 + + 53, 13 - - 33 + + 36 - - Fill: + + Summary: - - lblFill + + lblSummary - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 3 - - - 254, 292 + + 1 - - 0, 0, 0, 0 + + 307, 154 - - 120, 20 + + 67, 21 - - 34 + + 37 - - ucrReceiverFill + + ucrInputSummary - - instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - - 4 + + 0 + + + True + + + 6, 13 + + + 418, 464 323, 201 @@ -636,35 +576,95 @@ 5 - - True + + 254, 244 - - NoControl + + 21, 17, 21, 17 - - 272, 203 + + 120, 21 - - 44, 13 + + 25 - - 31 + + ucrInputLabel - - Symbol: + + instat.ucrInputComboBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - lblSymbol + + $this - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 8 - + + 9, 380 + + + 255, 24 + + + 29 + + + ucrSaveTreemap + + + instat.ucrSave, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + $this - - 6 + + 9 + + + 254, 180 + + + 82, 20 + + + 28 + + + ucrChkIsCurrency + + + instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 10 + + + 254, 126 + + + 0, 0, 0, 0 + + + 120, 20 + + + 22 + + + ucrReceiverWeightBy + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 16 254, 76 @@ -756,6 +756,9 @@ 20 + + NoControl + CenterScreen @@ -768,28 +771,28 @@ System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 254, 126 + + 254, 292 - + 0, 0, 0, 0 - + 120, 20 - - 22 + + 34 - - ucrReceiverWeightBy + + ucrReceiverFill - + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - - 16 + + 4 \ No newline at end of file diff --git a/instat/dlgTreemap.vb b/instat/dlgTreemap.vb index 974c4c34121..d46f2f09fb5 100644 --- a/instat/dlgTreemap.vb +++ b/instat/dlgTreemap.vb @@ -125,8 +125,8 @@ Public Class dlgTreemap ucrReceiverFill.bWithQuotes = False ucrReceiverFill.SetParameterIsString() - ucrColourBox.SetParameter(New RParameter("fill", 3)) - ucrColourBox.SetColours() + ucrColourTile.SetParameter(New RParameter("fill", 3)) + ucrColourTile.SetColours() ucrColourText.SetParameter(New RParameter("colour", 3)) ucrColourText.SetColours() @@ -245,7 +245,7 @@ Public Class dlgTreemap ucrInputSymbol.SetRCode(clsDollarFunction, bReset) ucrInputLabel.SetRCode(clsPaste0Function, bReset) ucrReceiverFill.SetRCode(clsGeomTreemapAesFunction, bReset) - ucrColourBox.SetRCode(clsGeomTreemapFunction, bReset) + ucrColourTile.SetRCode(clsGeomTreemapFunction, bReset) ucrColourText.SetRCode(clsGeomTreemapTextFunction, bReset) If bReset Then ucrInputLabel.SetText(strIdentifier) @@ -344,11 +344,11 @@ Public Class dlgTreemap Private Sub ucrReceiverFill_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFill.ControlValueChanged If ucrReceiverFill.IsEmpty() Then - clsGeomTreemapFunction.AddParameter("fill", ucrColourBox.GetText(), iPosition:=3) - ucrColourBox.Enabled = True + clsGeomTreemapFunction.AddParameter("fill", ucrColourTile.GetText(), iPosition:=3) + ucrColourTile.Enabled = True Else clsGeomTreemapFunction.RemoveParameterByName("fill") - ucrColourBox.Enabled = False + ucrColourTile.Enabled = False End If End Sub @@ -438,4 +438,8 @@ Public Class dlgTreemap sdgPlots.tbpLayers.Enabled = True bResetSubdialog = False End Sub + + Private Sub CoreControls_ContentsChanged(ucrChangedControl As ucrCore) Handles ucrSaveTreemap.ControlContentsChanged, ucrReceiverWeightBy.ControlContentsChanged, ucrReceiverIdentifier.ControlContentsChanged, ucrPnlDataType.ControlContentsChanged + + End Sub End Class \ No newline at end of file From 30301ab4cb958e2c3c6faa7acc06d7627704218d Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Wed, 13 Nov 2019 18:14:24 +0000 Subject: [PATCH 05/10] fixes #5466 dialog design modified improved display of names of summaries in output removed scientific notation of summaries corrected summaries for Dates corrected error for invalid summaries on some data type ordered summaries in output by size and groupings --- instat/dlgOneVariableSummarise.Designer.vb | 120 ++++---- instat/dlgOneVariableSummarise.resx | 258 ++++++++++++------ instat/dlgOneVariableSummarise.vb | 46 ++-- .../R/Backend_Components/summary_functions.R | 114 ++++---- 4 files changed, 314 insertions(+), 224 deletions(-) diff --git a/instat/dlgOneVariableSummarise.Designer.vb b/instat/dlgOneVariableSummarise.Designer.vb index 079260b1ffe..0ab09420470 100644 --- a/instat/dlgOneVariableSummarise.Designer.vb +++ b/instat/dlgOneVariableSummarise.Designer.vb @@ -40,15 +40,17 @@ Partial Class dlgOneVariableSummarise Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(dlgOneVariableSummarise)) Me.lblSelectedVariable = New System.Windows.Forms.Label() - Me.ucrBase = New instat.ucrButtons() - Me.ucrReceiverOneVarSummarise = New instat.ucrReceiverMultiple() - Me.ucrSelectorOneVarSummarise = New instat.ucrSelectorByDataFrameAddRemove() - Me.ucrChkOmitMissing = New instat.ucrCheck() - Me.ucrChkSaveResult = New instat.ucrCheck() - Me.ucrChkCustomise = New instat.ucrCheck() Me.lblMaxSum = New System.Windows.Forms.Label() - Me.ucrNudMaxSum = New instat.ucrNud() Me.cmdSummaries = New System.Windows.Forms.Button() + Me.lblSummaries = New System.Windows.Forms.Label() + Me.rdoDefault = New System.Windows.Forms.RadioButton() + Me.rdoCustomised = New System.Windows.Forms.RadioButton() + Me.ucrNudMaxSum = New instat.ucrNud() + Me.ucrChkOmitMissing = New instat.ucrCheck() + Me.ucrSelectorOneVarSummarise = New instat.ucrSelectorByDataFrameAddRemove() + Me.ucrReceiverOneVarSummarise = New instat.ucrReceiverMultiple() + Me.ucrBase = New instat.ucrButtons() + Me.ucrPnlSummaries = New instat.UcrPanel() Me.SuspendLayout() ' 'lblSelectedVariable @@ -57,50 +59,36 @@ Partial Class dlgOneVariableSummarise Me.lblSelectedVariable.Name = "lblSelectedVariable" Me.lblSelectedVariable.Tag = "Selected_Variable" ' - 'ucrBase - ' - resources.ApplyResources(Me.ucrBase, "ucrBase") - Me.ucrBase.Name = "ucrBase" - ' - 'ucrReceiverOneVarSummarise - ' - Me.ucrReceiverOneVarSummarise.frmParent = Me - resources.ApplyResources(Me.ucrReceiverOneVarSummarise, "ucrReceiverOneVarSummarise") - Me.ucrReceiverOneVarSummarise.Name = "ucrReceiverOneVarSummarise" - Me.ucrReceiverOneVarSummarise.Selector = Nothing - Me.ucrReceiverOneVarSummarise.strNcFilePath = "" - Me.ucrReceiverOneVarSummarise.ucrSelector = Nothing - ' - 'ucrSelectorOneVarSummarise + 'lblMaxSum ' - Me.ucrSelectorOneVarSummarise.bDropUnusedFilterLevels = False - Me.ucrSelectorOneVarSummarise.bShowHiddenColumns = False - Me.ucrSelectorOneVarSummarise.bUseCurrentFilter = True - resources.ApplyResources(Me.ucrSelectorOneVarSummarise, "ucrSelectorOneVarSummarise") - Me.ucrSelectorOneVarSummarise.Name = "ucrSelectorOneVarSummarise" + resources.ApplyResources(Me.lblMaxSum, "lblMaxSum") + Me.lblMaxSum.Name = "lblMaxSum" ' - 'ucrChkOmitMissing + 'cmdSummaries ' - Me.ucrChkOmitMissing.Checked = False - resources.ApplyResources(Me.ucrChkOmitMissing, "ucrChkOmitMissing") - Me.ucrChkOmitMissing.Name = "ucrChkOmitMissing" + resources.ApplyResources(Me.cmdSummaries, "cmdSummaries") + Me.cmdSummaries.Name = "cmdSummaries" + Me.cmdSummaries.Tag = "Summaries" + Me.cmdSummaries.UseVisualStyleBackColor = True ' - 'ucrChkSaveResult + 'lblSummaries ' - Me.ucrChkSaveResult.Checked = False - resources.ApplyResources(Me.ucrChkSaveResult, "ucrChkSaveResult") - Me.ucrChkSaveResult.Name = "ucrChkSaveResult" + resources.ApplyResources(Me.lblSummaries, "lblSummaries") + Me.lblSummaries.Name = "lblSummaries" ' - 'ucrChkCustomise + 'rdoDefault ' - Me.ucrChkCustomise.Checked = False - resources.ApplyResources(Me.ucrChkCustomise, "ucrChkCustomise") - Me.ucrChkCustomise.Name = "ucrChkCustomise" + resources.ApplyResources(Me.rdoDefault, "rdoDefault") + Me.rdoDefault.Name = "rdoDefault" + Me.rdoDefault.TabStop = True + Me.rdoDefault.UseVisualStyleBackColor = True ' - 'lblMaxSum + 'rdoCustomised ' - resources.ApplyResources(Me.lblMaxSum, "lblMaxSum") - Me.lblMaxSum.Name = "lblMaxSum" + resources.ApplyResources(Me.rdoCustomised, "rdoCustomised") + Me.rdoCustomised.Name = "rdoCustomised" + Me.rdoCustomised.TabStop = True + Me.rdoCustomised.UseVisualStyleBackColor = True ' 'ucrNudMaxSum ' @@ -112,27 +100,55 @@ Partial Class dlgOneVariableSummarise Me.ucrNudMaxSum.Name = "ucrNudMaxSum" Me.ucrNudMaxSum.Value = New Decimal(New Integer() {0, 0, 0, 0}) ' - 'cmdSummaries + 'ucrChkOmitMissing ' - resources.ApplyResources(Me.cmdSummaries, "cmdSummaries") - Me.cmdSummaries.Name = "cmdSummaries" - Me.cmdSummaries.Tag = "Summaries" - Me.cmdSummaries.UseVisualStyleBackColor = True + Me.ucrChkOmitMissing.Checked = False + resources.ApplyResources(Me.ucrChkOmitMissing, "ucrChkOmitMissing") + Me.ucrChkOmitMissing.Name = "ucrChkOmitMissing" + ' + 'ucrSelectorOneVarSummarise + ' + Me.ucrSelectorOneVarSummarise.bDropUnusedFilterLevels = False + Me.ucrSelectorOneVarSummarise.bShowHiddenColumns = False + Me.ucrSelectorOneVarSummarise.bUseCurrentFilter = True + resources.ApplyResources(Me.ucrSelectorOneVarSummarise, "ucrSelectorOneVarSummarise") + Me.ucrSelectorOneVarSummarise.Name = "ucrSelectorOneVarSummarise" + ' + 'ucrReceiverOneVarSummarise + ' + Me.ucrReceiverOneVarSummarise.frmParent = Me + resources.ApplyResources(Me.ucrReceiverOneVarSummarise, "ucrReceiverOneVarSummarise") + Me.ucrReceiverOneVarSummarise.Name = "ucrReceiverOneVarSummarise" + Me.ucrReceiverOneVarSummarise.Selector = Nothing + Me.ucrReceiverOneVarSummarise.strNcFilePath = "" + Me.ucrReceiverOneVarSummarise.ucrSelector = Nothing + ' + 'ucrBase + ' + resources.ApplyResources(Me.ucrBase, "ucrBase") + Me.ucrBase.Name = "ucrBase" + ' + 'ucrPnlSummaries + ' + resources.ApplyResources(Me.ucrPnlSummaries, "ucrPnlSummaries") + Me.ucrPnlSummaries.Name = "ucrPnlSummaries" ' 'dlgOneVariableSummarise ' resources.ApplyResources(Me, "$this") Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.Controls.Add(Me.rdoCustomised) + Me.Controls.Add(Me.rdoDefault) + Me.Controls.Add(Me.lblSummaries) Me.Controls.Add(Me.lblMaxSum) Me.Controls.Add(Me.ucrNudMaxSum) - Me.Controls.Add(Me.ucrChkCustomise) - Me.Controls.Add(Me.ucrChkSaveResult) Me.Controls.Add(Me.ucrChkOmitMissing) Me.Controls.Add(Me.ucrSelectorOneVarSummarise) Me.Controls.Add(Me.ucrReceiverOneVarSummarise) Me.Controls.Add(Me.ucrBase) Me.Controls.Add(Me.lblSelectedVariable) Me.Controls.Add(Me.cmdSummaries) + Me.Controls.Add(Me.ucrPnlSummaries) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False @@ -147,10 +163,12 @@ Partial Class dlgOneVariableSummarise Friend WithEvents ucrBase As ucrButtons Friend WithEvents ucrReceiverOneVarSummarise As ucrReceiverMultiple Friend WithEvents ucrSelectorOneVarSummarise As ucrSelectorByDataFrameAddRemove - Friend WithEvents ucrChkSaveResult As ucrCheck Friend WithEvents ucrChkOmitMissing As ucrCheck - Friend WithEvents ucrChkCustomise As ucrCheck Friend WithEvents lblMaxSum As Label Friend WithEvents ucrNudMaxSum As ucrNud Friend WithEvents cmdSummaries As Button + Friend WithEvents rdoCustomised As RadioButton + Friend WithEvents rdoDefault As RadioButton + Friend WithEvents lblSummaries As Label + Friend WithEvents ucrPnlSummaries As UcrPanel End Class \ No newline at end of file diff --git a/instat/dlgOneVariableSummarise.resx b/instat/dlgOneVariableSummarise.resx index fdc9eb7379e..958245e2fde 100644 --- a/instat/dlgOneVariableSummarise.resx +++ b/instat/dlgOneVariableSummarise.resx @@ -117,6 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NoControl + 261, 45 @@ -141,46 +145,19 @@ $this - 8 - - - 10, 288 - - - 410, 52 - - 9 - - ucrBase - - - instat.ucrButtons, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 7 - - - True - - - 6, 13 - - - 415, 345 + + NoControl - 7, 210 + 10, 238 187, 13 - 5 + 7 Maximum Factor Levels Shown: @@ -195,81 +172,157 @@ $this - 0 + 3 - - - 200, 207 - + + True - - 50, 20 + + NoControl - + + 232, 200 + + + 116, 23 + + 6 - - ucrNudMaxSum + + Choose Summaries... - - instat.ucrNud, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + cmdSummaries - + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this - - 1 + + 10 + + + True + + + NoControl - - 261, 163 + + 10, 205 - - 100, 20 + + 61, 13 - + 3 - - ucrChkCustomise + + Summaries: - - instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + lblSummaries + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 2 - - 10, 262 + + True - - 166, 20 + + NoControl + + + 79, 203 + + + 59, 17 + + + 4 + + + Default + + + rdoDefault + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this - + + 1 + + + True + + + NoControl + + + 147, 203 + + + 79, 17 + + + 5 + + + Customised + + + rdoCustomised + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + 205, 235 + + + 50, 20 + + 8 - - ucrChkSaveResult + + ucrNudMaxSum - - instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + instat.ucrNud, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - - 3 + + 4 - 10, 235 + 14, 235 166, 20 - 7 + 9 ucrChkOmitMissing @@ -281,12 +334,11 @@ $this - 4 + 5 10, 10 - 0, 0, 0, 0 @@ -306,34 +358,58 @@ $this - 5 + 6 - + True + + + 6, 13 - - 305, 189 + + 421, 327 - - 77, 23 + + 10, 273 - - 4 + + 410, 52 - - Summaries... + + 11 - - cmdSummaries + + ucrBase - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + instat.ucrButtons, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - - 9 + + 8 + + + 10, 192 + + + 352, 37 + + + 12 + + + ucrPnlSummaries + + + instat.UcrPanel, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 11 CenterScreen @@ -369,6 +445,6 @@ $this - 6 + 7 \ No newline at end of file diff --git a/instat/dlgOneVariableSummarise.vb b/instat/dlgOneVariableSummarise.vb index 79e0805a17a..0c9139c7ddf 100644 --- a/instat/dlgOneVariableSummarise.vb +++ b/instat/dlgOneVariableSummarise.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 instat Imports instat.Translations Public Class dlgOneVariableSummarise @@ -53,24 +54,20 @@ Public Class dlgOneVariableSummarise ucrNudMaxSum.SetParameter(New RParameter("maxsum", 2)) ucrNudMaxSum.SetRDefault("7") + ucrNudMaxSum.SetLinkedDisplayControl(lblMaxSum) + + ucrPnlSummaries.AddRadioButton(rdoDefault) + ucrPnlSummaries.AddRadioButton(rdoCustomised) + ucrPnlSummaries.AddFunctionNamesCondition(rdoCustomised, frmMain.clsRLink.strInstatDataObject & "$summary") + ucrPnlSummaries.AddFunctionNamesCondition(rdoDefault, "summary") + ucrPnlSummaries.AddToLinkedControls(ucrNudMaxSum, {rdoDefault}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlSummaries.AddToLinkedControls(ucrChkOmitMissing, {rdoCustomised}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrChkOmitMissing.SetParameter(New RParameter("na.rm", 3)) ucrChkOmitMissing.SetText("Omit Missing Values") ucrChkOmitMissing.SetRDefault("FALSE") ucrChkOmitMissing.SetValuesCheckedAndUnchecked("TRUE", "FALSE") ucrChkOmitMissing.bUpdateRCodeFromControl = True - - ucrChkCustomise.SetText("Customise") - ucrChkCustomise.AddFunctionNamesCondition(True, frmMain.clsRLink.strInstatDataObject & "$summary") - ucrChkCustomise.AddFunctionNamesCondition(False, "summary") - ucrChkCustomise.AddToLinkedControls(ucrNudMaxSum, {False}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrNudMaxSum.SetLinkedDisplayControl(lblMaxSum) - - ucrChkSaveResult.SetText("Save Result") 'this is disabled in the initial implementation - ucrChkSaveResult.Enabled = False - 'ucrChkSaveResult.SetParameter(New RParameter("store_results")) - 'ucrChkSaveResult.SetValuesCheckedAndUnchecked("TRUE", "FALSE") - 'ucrChkSaveResult.SetRDefault("FALSE") End Sub Private Sub SetDefaults() @@ -79,8 +76,6 @@ Public Class dlgOneVariableSummarise clsInstatSummaryFunction = New RFunction clsConcFunction = New RFunction - cmdSummaries.Enabled = False - ucrSelectorOneVarSummarise.Reset() clsConcFunction.SetRCommand("c") @@ -107,13 +102,14 @@ Public Class dlgOneVariableSummarise ucrNudMaxSum.SetRCode(clsSummaryFunction, bReset) ucrReceiverOneVarSummarise.SetRCode(clsSummaryFunction, bReset) ucrChkOmitMissing.SetRCode(clsSummaryFunction, bReset) - ucrChkCustomise.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset) + ucrPnlSummaries.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset) ucrSelectorOneVarSummarise.SetRCode(clsInstatSummaryFunction, bReset) + ChangeBaseFunction() End Sub Public Sub TestOKEnabled() 'We cannot test the values on the sub dialog because the sub dialog may not be in sync with the main dialog code. This only happens once the sub dialog has been opened. - If ucrReceiverOneVarSummarise.IsEmpty() OrElse (ucrChkCustomise.Checked AndAlso clsSummariesList.clsParameters.Count = 0) OrElse ucrNudMaxSum.GetText = "" Then + If ucrReceiverOneVarSummarise.IsEmpty() OrElse (rdoCustomised.Checked AndAlso clsSummariesList.clsParameters.Count = 0) OrElse ucrNudMaxSum.GetText = "" Then ucrBase.OKEnabled(False) Else ucrBase.OKEnabled(True) @@ -136,15 +132,13 @@ Public Class dlgOneVariableSummarise End Sub Private Sub ChangeBaseFunction() - If ucrChkCustomise.Checked Then + If rdoCustomised.Checked Then ucrBase.clsRsyntax.SetBaseRFunction(clsInstatSummaryFunction) - cmdSummaries.Enabled = True - Else + cmdSummaries.Visible = True + ElseIf rdoDefault.Checked Then ucrBase.clsRsyntax.SetBaseRFunction(clsSummaryFunction) - cmdSummaries.Enabled = False + cmdSummaries.Visible = False End If - 'We need to update the base function to include the - 'ucrBaseDescribeOneVar.clsRsyntax.clsBaseFunction.AddParameter(ucrChkOmitMissing.GetParameter()) End Sub Private Sub ucrReceiverDescribeOneVar_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverOneVarSummarise.ControlValueChanged @@ -168,11 +162,11 @@ Public Class dlgOneVariableSummarise strDefaultColumns = Nothing End Sub - Private Sub ucrChkCustomise_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkCustomise.ControlValueChanged - ChangeBaseFunction() + Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverOneVarSummarise.ControlContentsChanged, ucrNudMaxSum.ControlContentsChanged + TestOKEnabled() End Sub - Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverOneVarSummarise.ControlContentsChanged, ucrChkCustomise.ControlContentsChanged, ucrNudMaxSum.ControlContentsChanged - TestOKEnabled() + Private Sub ucrPnlSummaries_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlSummaries.ControlValueChanged + ChangeBaseFunction() End Sub End Class diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 9ed59cad24e..45d9669c0e4 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -240,63 +240,48 @@ DataBook$set("public", "calculate_summary", function(data_name, columns_to_summa DataBook$set("public", "summary", function(data_name, columns_to_summarise, summaries, factors = c(), store_results = FALSE, drop = FALSE, return_output = FALSE, summary_name = NA, add_cols = c(), filter_names = c(), ...) { calculated_from = list() calculated_from[[1]] <- list(data_name = data_name, columns = columns_to_summarise) - #TODO Change this to store sub_calculations for each column - alltypes_collection <- c(count_non_missing_label, count_missing_label, count_label, mode_label) - numeric_collection <- c(count_non_missing_label, count_missing_label, count_label, mode_label, min_label, max_label, mean_label, sd_label, range_label, median_label, sum_label, var_label, lower_quart_label, upper_quart_label, skewness_label, summary_skewness_mc_label, kurtosis_label, summary_coef_var_label, summary_median_absolute_deviation_label, summary_Qn_label, summary_Sn_label, cor_label, cov_label, first_label, last_label, nth_label, n_distinct_label, proportion_label, count_calc_label) - factor_collection <- c(count_non_missing_label, count_missing_label, count_label, mode_label) #maximum and minimum labels should be added when we distinguish ordered factors - ordered_factor_collection <- c(count_non_missing_label, count_missing_label, count_label, mode_label, min_label, max_label) - i = 1 + + summaries <- unique(summaries) + summaries <- summaries[order(match(summaries, all_summaries))] + summaries_count <- summaries[startsWith(summaries, "summary_count")] + summaries_other <- setdiff(summaries, summaries_count) + summaries <- c(summaries_count, summaries_other) + count_summaries_max <- length(summaries_count) + summaries_max <- length(summaries) + + summary_names <- ifelse(startsWith(summaries, "summary_"), substr(summaries, 9, nchar(summaries)), summaries) + summary_names <- gsub("_", "-", summary_names) + summary_count_names <- summary_names[1:count_summaries_max] + summary_other_names <- summary_names[(count_summaries_max + 1):summaries_max] + col_data_type <- self$get_variables_metadata(data_name = data_name, column = columns_to_summarise, property = data_type_label) + results_count <- data.frame(matrix(ncol = length(columns_to_summarise), nrow = max(1, count_summaries_max))) + results_other <- data.frame(matrix(ncol = length(columns_to_summarise), nrow = summaries_max - count_summaries_max)) + names(results_count) <- columns_to_summarise + names(results_other) <- columns_to_summarise + i <- 1 for(col_new in columns_to_summarise) { - col_data_type = self$get_variables_metadata(data_name = data_name, column = col_new, property = data_type_label) - if(col_data_type == "numeric" || col_data_type == "integer") { - column_summaries = intersect(summaries, numeric_collection) - } - else if(col_data_type == "factor") { - column_summaries = intersect(summaries, factor_collection) - } - else if(col_data_type == paste0(c("ordered","factor"), collapse = ",")) { - column_summaries = intersect(summaries, ordered_factor_collection) - } - else if(col_data_type == "character") { - column_summaries = intersect(summaries, alltypes_collection) - } - else if(col_data_type == "logical") { - #To be defined - } - else if(col_data_type == "Date") { - #To be defined - } - if(length(column_summaries) == 0) { - results <- data.frame(matrix(ncol = length(summaries) + 1)) - names(results) <- c(".id", summaries) - column_summaries <- summaries - } - else { - calc <- calculation$new(type = "summary", parameters = list(data_name = data_name, columns_to_summarise = col_new, summaries = column_summaries, factors = factors, store_results = store_results, drop = drop, return_output = return_output, summary_name = summary_name, add_cols = add_cols, ... = ...), filters = filter_names, calculated_from = calculated_from) - results <- self$apply_calculation(calc) + for(j in seq_along(summaries)) { + calc <- calculation$new(type = "summary", parameters = list(data_name = data_name, columns_to_summarise = col_new, summaries = summaries[j], factors = factors, store_results = store_results, drop = drop, return_output = return_output, summary_name = summary_name, add_cols = add_cols, ... = ...), filters = filter_names, calculated_from = calculated_from) + calc_apply <- tryCatch(self$apply_calculation(calc), + error = function(c) { + x <- data.frame(col_new, NA) + names(x) <- c(".id", summary_names[j]) + return(x) + }) + if(j <= count_summaries_max) results_count[j,i] <- calc_apply[1,2] + else results_other[j - count_summaries_max,i] <- calc_apply[1,2] } - if(!is.null(results)) { - results <- as.data.frame(t(results[,-1])) - #row_names(results) <- get_summary_calculation_names(calc, column_summaries, col_new, calc_filters) - names(results) <- col_new - #use summaries as row names for now. This needs to change in the long run - row.names(results) <- column_summaries - if(i == 1) { - calc_columns <- results - } - else { - calc_columns <- merge(calc_columns, results, by=0, all=TRUE, sort = FALSE)#Sort should be user defined - #we need to clarify which filters are being used - rownames(calc_columns)=calc_columns$Row.names - calc_columns<-calc_columns[,-1] - } - i = i + 1 - } - else { - calc_columns <- NULL - } - } - return(calc_columns) + i = i + 1 + } + # Set type of Date columns since may have coerced to numeric + for(k in seq_along(results_other)) { + if("Date" %in% col_data_type[k]) results_other[[k]] <- as.Date(results_other[[k]], origin = "1970/1/1") + } + results_count <- format(results_count, scientific = FALSE) + results_other <- format(results_other, scientific = FALSE) + results <- bind_rows(results_count, results_other) + row.names(results) <- summary_names + return(results) } ) @@ -433,7 +418,24 @@ circular_range_label="summary_circular_range" # list of all summary function names -all_summaries=c(sum_label, mode_label, count_label, count_missing_label, count_non_missing_label, sd_label, var_label, median_label, range_label, min_label, max_label, mean_label, trimmed_mean_label, quartile_label, lower_quart_label, upper_quart_label, skewness_label, kurtosis_label, summary_coef_var_label, summary_skewness_mc_label, summary_outlier_limit_label, summary_median_absolute_deviation_label, summary_Qn_label, summary_Sn_label, cor_label, cov_label,first_label, last_label, nth_label, n_distinct_label, proportion_label, count_calc_label,standard_error_mean_label, circular_mean_label, circular_median_label, circular_medianHL_label, circular_min_label, circular_max_label, circular_Q1_label, circular_Q3_label, circular_quantile_label, circular_sd_label, circular_var_label, circular_ang_dev_label, circular_ang_var_label, circular_rho_label, circular_range_label) +# the order of this list determines the order summaries appears in certain functions +all_summaries <- c(count_label, count_non_missing_label, count_missing_label, + min_label, lower_quart_label, quartile_label, median_label, + summary_median_absolute_deviation_label, summary_coef_var_label, + summary_Qn_label, summary_Sn_label, + mode_label, mean_label, + trimmed_mean_label, upper_quart_label, max_label, sum_label, + sd_label, var_label, range_label, standard_error_mean_label, + skewness_label, summary_skewness_mc_label, kurtosis_label, + summary_outlier_limit_label, + cor_label, cov_label, first_label, last_label, nth_label, n_distinct_label, + proportion_label, count_calc_label, + circular_min_label, circular_Q1_label, circular_quantile_label, + circular_median_label, circular_medianHL_label, circular_mean_label, + circular_Q3_label, circular_max_label, + circular_sd_label, circular_var_label, circular_range_label, + circular_ang_dev_label, circular_ang_var_label, circular_rho_label) + summary_mode <- function(x,...) { ux <- unique(x) out <- ux[which.max(tabulate(match(x, ux)))] From aa42da6858386199f1ed23808c4f2d71502e1589 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Wed, 13 Nov 2019 18:19:50 +0000 Subject: [PATCH 06/10] added control to TestOK --- instat/dlgOneVariableSummarise.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgOneVariableSummarise.vb b/instat/dlgOneVariableSummarise.vb index 0c9139c7ddf..08aa1517293 100644 --- a/instat/dlgOneVariableSummarise.vb +++ b/instat/dlgOneVariableSummarise.vb @@ -162,7 +162,7 @@ Public Class dlgOneVariableSummarise strDefaultColumns = Nothing End Sub - Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverOneVarSummarise.ControlContentsChanged, ucrNudMaxSum.ControlContentsChanged + Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverOneVarSummarise.ControlContentsChanged, ucrNudMaxSum.ControlContentsChanged, ucrPnlSummaries.ControlValueChanged TestOKEnabled() End Sub From e8ad3a853681953509fea1b163e0c521a1f3e58b Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Wed, 13 Nov 2019 18:34:24 +0000 Subject: [PATCH 07/10] added line to ensure uniqueness of summary names in display --- .../static/InstatObject/R/Backend_Components/summary_functions.R | 1 + 1 file changed, 1 insertion(+) diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 45d9669c0e4..0c1e990f6b1 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -251,6 +251,7 @@ DataBook$set("public", "summary", function(data_name, columns_to_summarise, summ summary_names <- ifelse(startsWith(summaries, "summary_"), substr(summaries, 9, nchar(summaries)), summaries) summary_names <- gsub("_", "-", summary_names) + summary_names <- make.unique(summary_names) summary_count_names <- summary_names[1:count_summaries_max] summary_other_names <- summary_names[(count_summaries_max + 1):summaries_max] col_data_type <- self$get_variables_metadata(data_name = data_name, column = columns_to_summarise, property = data_type_label) From fd6fd7eb64b5d90c594df5e6321dee22a8882a91 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Thu, 14 Nov 2019 16:51:11 +0000 Subject: [PATCH 08/10] improved methods and dialog for describe > two variable summarise --- instat/dlgDescribeTwoVariable.Designer.vb | 45 ++++---- instat/dlgDescribeTwoVariable.resx | 66 +++++------ instat/dlgDescribeTwoVariable.vb | 103 ++++++++++-------- instat/sdgDescribeDisplay.vb | 4 +- .../R/Backend_Components/summary_functions.R | 61 ++++++++--- instat/static/InstatObject/R/data_object_R6.R | 30 ++--- .../static/InstatObject/R/instat_object_R6.R | 8 +- instat/ucrReceiverMultiple.vb | 8 +- 8 files changed, 180 insertions(+), 145 deletions(-) diff --git a/instat/dlgDescribeTwoVariable.Designer.vb b/instat/dlgDescribeTwoVariable.Designer.vb index 2ad1eebeb8d..456d1aefbe7 100644 --- a/instat/dlgDescribeTwoVariable.Designer.vb +++ b/instat/dlgDescribeTwoVariable.Designer.vb @@ -42,9 +42,9 @@ Partial Class dlgDescribeTwoVariable Me.cmdSummaries = New System.Windows.Forms.Button() Me.cmdDisplayOptions = New System.Windows.Forms.Button() Me.lblFirstVariable = New System.Windows.Forms.Label() - Me.lbMultipleVariables = New System.Windows.Forms.Label() - Me.ucrReceiverFirstVar = New instat.ucrReceiverSingle() - Me.ucrReceiverSecondVar = New instat.ucrReceiverMultiple() + Me.lbSecondVariable = New System.Windows.Forms.Label() + Me.ucrReceiverSecondVar = New instat.ucrReceiverSingle() + Me.ucrReceiverFirstVars = New instat.ucrReceiverMultiple() Me.ucrSelectorDescribeTwoVar = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrBase = New instat.ucrButtons() Me.ucrChkSaveResult = New instat.ucrCheck() @@ -69,22 +69,13 @@ Partial Class dlgDescribeTwoVariable ' resources.ApplyResources(Me.lblFirstVariable, "lblFirstVariable") Me.lblFirstVariable.Name = "lblFirstVariable" - Me.lblFirstVariable.Tag = "First_Variable" + Me.lblFirstVariable.Tag = "" ' - 'lbMultipleVariables + 'lbSecondVariable ' - resources.ApplyResources(Me.lbMultipleVariables, "lbMultipleVariables") - Me.lbMultipleVariables.Name = "lbMultipleVariables" - Me.lbMultipleVariables.Tag = "Multiple_Variables" - ' - 'ucrReceiverFirstVar - ' - Me.ucrReceiverFirstVar.frmParent = Me - resources.ApplyResources(Me.ucrReceiverFirstVar, "ucrReceiverFirstVar") - Me.ucrReceiverFirstVar.Name = "ucrReceiverFirstVar" - Me.ucrReceiverFirstVar.Selector = Nothing - Me.ucrReceiverFirstVar.strNcFilePath = "" - Me.ucrReceiverFirstVar.ucrSelector = Nothing + resources.ApplyResources(Me.lbSecondVariable, "lbSecondVariable") + Me.lbSecondVariable.Name = "lbSecondVariable" + Me.lbSecondVariable.Tag = "" ' 'ucrReceiverSecondVar ' @@ -95,8 +86,18 @@ Partial Class dlgDescribeTwoVariable Me.ucrReceiverSecondVar.strNcFilePath = "" Me.ucrReceiverSecondVar.ucrSelector = Nothing ' + 'ucrReceiverFirstVars + ' + Me.ucrReceiverFirstVars.frmParent = Me + resources.ApplyResources(Me.ucrReceiverFirstVars, "ucrReceiverFirstVars") + Me.ucrReceiverFirstVars.Name = "ucrReceiverFirstVars" + Me.ucrReceiverFirstVars.Selector = Nothing + Me.ucrReceiverFirstVars.strNcFilePath = "" + Me.ucrReceiverFirstVars.ucrSelector = Nothing + ' 'ucrSelectorDescribeTwoVar ' + Me.ucrSelectorDescribeTwoVar.bDropUnusedFilterLevels = False Me.ucrSelectorDescribeTwoVar.bShowHiddenColumns = False Me.ucrSelectorDescribeTwoVar.bUseCurrentFilter = True resources.ApplyResources(Me.ucrSelectorDescribeTwoVar, "ucrSelectorDescribeTwoVar") @@ -125,11 +126,11 @@ Partial Class dlgDescribeTwoVariable Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.Controls.Add(Me.ucrChkSaveResult) Me.Controls.Add(Me.ucrChkOmitMissing) - Me.Controls.Add(Me.lbMultipleVariables) + Me.Controls.Add(Me.lbSecondVariable) Me.Controls.Add(Me.lblFirstVariable) Me.Controls.Add(Me.cmdDisplayOptions) - Me.Controls.Add(Me.ucrReceiverFirstVar) Me.Controls.Add(Me.ucrReceiverSecondVar) + Me.Controls.Add(Me.ucrReceiverFirstVars) Me.Controls.Add(Me.cmdSummaries) Me.Controls.Add(Me.ucrSelectorDescribeTwoVar) Me.Controls.Add(Me.ucrBase) @@ -145,12 +146,12 @@ Partial Class dlgDescribeTwoVariable Friend WithEvents ucrBase As ucrButtons Friend WithEvents ucrSelectorDescribeTwoVar As ucrSelectorByDataFrameAddRemove - Friend WithEvents ucrReceiverSecondVar As ucrReceiverMultiple + Friend WithEvents ucrReceiverFirstVars As ucrReceiverMultiple Friend WithEvents cmdSummaries As Button - Friend WithEvents ucrReceiverFirstVar As ucrReceiverSingle + Friend WithEvents ucrReceiverSecondVar As ucrReceiverSingle Friend WithEvents cmdDisplayOptions As Button Friend WithEvents lblFirstVariable As Label - Friend WithEvents lbMultipleVariables As Label + Friend WithEvents lbSecondVariable As Label Friend WithEvents ucrChkSaveResult As ucrCheck Friend WithEvents ucrChkOmitMissing As ucrCheck End Class diff --git a/instat/dlgDescribeTwoVariable.resx b/instat/dlgDescribeTwoVariable.resx index 205a2489352..deddb4feabf 100644 --- a/instat/dlgDescribeTwoVariable.resx +++ b/instat/dlgDescribeTwoVariable.resx @@ -174,13 +174,13 @@ 268, 45 - 70, 13 + 75, 13 1 - First Variable: + First Variables: lblFirstVariable @@ -194,28 +194,28 @@ 3 - - 268, 90 + + 268, 155 - + 100, 15 - + 3 - - Multiple Variables: + + Second Variable: - - lbMultipleVariables + + lbSecondVariable - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 2 @@ -269,29 +269,29 @@ 1 - - 268, 105 + + 271, 63 - + 0, 0, 0, 0 - + 120, 87 - + 4 - - ucrReceiverSecondVar + + ucrReceiverFirstVars - + instat.ucrReceiverMultiple, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - + 6 @@ -351,28 +351,28 @@ System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 268, 60 + + 271, 170 - + 0, 0, 0, 0 - + 120, 20 - + 2 - - ucrReceiverFirstVar + + ucrReceiverSecondVar - + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - + 5 \ No newline at end of file diff --git a/instat/dlgDescribeTwoVariable.vb b/instat/dlgDescribeTwoVariable.vb index efcaf2ce3f8..fee40946222 100644 --- a/instat/dlgDescribeTwoVariable.vb +++ b/instat/dlgDescribeTwoVariable.vb @@ -19,9 +19,11 @@ Public Class dlgDescribeTwoVariable Private bFirstLoad As Boolean = True Private bReset As Boolean = True Private bResetSubdialog As Boolean = False - Public strVarType, strSecondVarType As String + Public strFirstVariablesType, strSecondVariableType As String Public clsGetDataType, clsGetSecondDataType, clsRCorrelation, clsRCustomSummary, clsConcFunction, clsRAnova, clsRFreqTables As New RFunction Private clsSummariesList As New RFunction + Private clsAsMatrixX, clsAsNumericY As New RFunction + Private Sub dlgDescribeTwoVariable_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then InitialiseDialog() @@ -43,14 +45,14 @@ Public Class dlgDescribeTwoVariable ucrSelectorDescribeTwoVar.SetParameter(New RParameter("data_name", 0)) ucrSelectorDescribeTwoVar.SetParameterIsString() - ucrReceiverFirstVar.SetParameter(New RParameter("factors", 2)) - ucrReceiverFirstVar.SetParameterIsString() - ucrReceiverFirstVar.Selector = ucrSelectorDescribeTwoVar + ucrReceiverFirstVars.SetParameter(New RParameter("columns_to_summarise", 1)) + ucrReceiverFirstVars.SetParameterIsString() + ucrReceiverFirstVars.Selector = ucrSelectorDescribeTwoVar + ucrReceiverFirstVars.SetSingleTypeStatus(True) - ucrReceiverSecondVar.SetParameter(New RParameter("columns_to_summarise", 1)) + ucrReceiverSecondVar.SetParameter(New RParameter("factors", 2)) ucrReceiverSecondVar.SetParameterIsString() ucrReceiverSecondVar.Selector = ucrSelectorDescribeTwoVar - ucrReceiverSecondVar.SetSingleTypeStatus(True) ucrChkSaveResult.SetParameter(New RParameter("store_results", 4)) ucrChkSaveResult.SetText("Save Result") @@ -75,16 +77,17 @@ Public Class dlgDescribeTwoVariable clsSummariesList = New RFunction clsRCustomSummary = New RFunction clsConcFunction = New RFunction + clsAsMatrixX = New RFunction + clsAsNumericY = New RFunction ucrSelectorDescribeTwoVar.Reset() - ucrReceiverFirstVar.SetMeAsReceiver() + ucrReceiverFirstVars.SetMeAsReceiver() clsConcFunction.SetRCommand("c") - clsRFreqTables.AddParameter("addmargins", "FALSE", iPosition:=2) - clsRFreqTables.AddParameter("proportions", "FALSE", iPosition:=3) - clsRFreqTables.AddParameter("percentages", "FALSE", iPosition:=4) - clsRFreqTables.AddParameter("transpose", "FALSE", iPosition:=5) + clsRFreqTables.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$frequency_tables") + clsRFreqTables.AddParameter("store_results", "FALSE", iPosition:=4) + clsRFreqTables.AddParameter("as_html", "FALSE", iPosition:=12) clsRAnova.AddParameter("signif.stars", "FALSE", iPosition:=2) clsRAnova.AddParameter("sign_level", "FALSE", iPosition:=3) @@ -98,7 +101,7 @@ Public Class dlgDescribeTwoVariable clsSummariesList.AddParameter("summary_count", Chr(34) & "summary_count" & Chr(34), bIncludeArgumentName:=False) clsSummariesList.AddParameter("summary_sum", Chr(34) & "summary_sum" & Chr(34), bIncludeArgumentName:=False) - clsRCustomSummary.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$calculate_summary") + clsRCustomSummary.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$summary") clsRCustomSummary.AddParameter("summaries", clsRFunctionParameter:=clsSummariesList) clsRCustomSummary.AddParameter("store_results", "FALSE", iPosition:=4) @@ -107,7 +110,10 @@ Public Class dlgDescribeTwoVariable clsRCustomSummary.AddParameter("return_output", "TRUE", iPosition:=7) clsRCorrelation.SetRCommand("cor") - clsRFreqTables.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$frequency_tables") + + clsAsMatrixX.SetRCommand("as.matrix") + clsAsNumericY.SetRCommand("as.numeric") + clsRAnova.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$anova_tables") Results() @@ -117,15 +123,13 @@ Public Class dlgDescribeTwoVariable End Sub Private Sub SetRCodeForControls(bReset As Boolean) - ucrReceiverFirstVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("y_col_name", 2), iAdditionalPairNo:=1) - ucrReceiverFirstVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("factors", 2), iAdditionalPairNo:=2) - ucrReceiverFirstVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("y_col_name", 2), iAdditionalPairNo:=3) - 'ucrReceiverFirstVar.AddAdditionalCodeParameterPair(clsRCorelation, New RParameter("y", 1), iAdditionalPairNo:=4) + ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("y_col_name", 2), iAdditionalPairNo:=1) + ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("factors", 2), iAdditionalPairNo:=2) + ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("y_col_name", 2), iAdditionalPairNo:=3) - ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("x_col_names", 1), iAdditionalPairNo:=1) - ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("columns_to_summarise", 1), iAdditionalPairNo:=2) - ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("x_col_names", 1), iAdditionalPairNo:=3) - ' ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRCorelation, New RParameter("x", 0), iAdditionalPairNo:=4) + ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("x_col_names", 1), iAdditionalPairNo:=1) + ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("columns_to_summarise", 1), iAdditionalPairNo:=2) + ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("x_col_names", 1), iAdditionalPairNo:=3) ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("data_name", 0), iAdditionalPairNo:=1) ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("data_name", 0), iAdditionalPairNo:=2) @@ -137,8 +141,8 @@ Public Class dlgDescribeTwoVariable End Sub Public Sub TestOKEnabled() - If ((Not ucrReceiverFirstVar.IsEmpty()) AndAlso (Not ucrReceiverSecondVar.IsEmpty())) Then - If ((strSecondVarType = "numeric" OrElse strSecondVarType = "integer") AndAlso (strVarType = "factor")) AndAlso clsSummariesList.clsParameters.Count = 0 Then + If ((Not ucrReceiverSecondVar.IsEmpty()) AndAlso (Not ucrReceiverFirstVars.IsEmpty())) Then + If ((strFirstVariablesType = "numeric" OrElse strFirstVariablesType = "integer") AndAlso (strSecondVariableType = "factor")) AndAlso clsSummariesList.clsParameters.Count = 0 Then ucrBase.OKEnabled(False) Else ucrBase.OKEnabled(True) @@ -169,18 +173,30 @@ Public Class dlgDescribeTwoVariable End Sub Public Sub Results() - If Not ucrReceiverFirstVar.IsEmpty() Then - strVarType = ucrReceiverFirstVar.strCurrDataType + Dim lstFirstItemTypes As List(Of String) + + If (ucrReceiverFirstVars.GetCurrentItemTypes.Count > 0) Then + lstFirstItemTypes = ucrReceiverFirstVars.GetCurrentItemTypes() + If lstFirstItemTypes.Contains("factor") OrElse lstFirstItemTypes.Contains("character") Then + strFirstVariablesType = "categorical" + Else + strFirstVariablesType = "numeric" + End If Else - strVarType = "" + strFirstVariablesType = "" End If - If (ucrReceiverSecondVar.GetCurrentItemTypes.Count > 0) Then - strSecondVarType = ucrReceiverSecondVar.GetCurrentItemTypes.Item(0) + If Not ucrReceiverSecondVar.IsEmpty() Then + strSecondVariableType = ucrReceiverSecondVar.strCurrDataType + If strSecondVariableType.Contains("factor") OrElse strSecondVariableType.Contains("character") Then + strSecondVariableType = "categorical" + Else + strSecondVariableType = "numeric" + End If Else - strSecondVarType = "" + strSecondVariableType = "" End If - If ((strVarType = "numeric" OrElse strVarType = "integer") AndAlso (strSecondVarType = "numeric" OrElse strSecondVarType = "integer")) Then + If strFirstVariablesType = "numeric" AndAlso strSecondVariableType = "numeric" Then ucrChkSaveResult.Visible = False cmdSummaries.Visible = False cmdDisplayOptions.Visible = False @@ -190,47 +206,44 @@ Public Class dlgDescribeTwoVariable ucrBase.clsRsyntax.SetBaseRFunction(clsRCorrelation) 'Temporary Fix- Only one of the receivers gets variables (the last variable of the two) 'ie, when ucrReceiverFirstVar and ucrReceiverSecondVar are set from SetParameterIsString to SetParameterIsRFunction only the second (ucrReceiverSecondVar) changes to SetParameterIsRFunction the first one remains as SetParameterIsString which is not needed - clsRCorrelation.AddParameter("x", clsRFunctionParameter:=ucrReceiverSecondVar.GetVariables) - clsRCorrelation.AddParameter("y", clsRFunctionParameter:=ucrReceiverFirstVar.GetVariables) + clsAsMatrixX.AddParameter("x", clsRFunctionParameter:=ucrReceiverFirstVars.GetVariables, iPosition:=0) + clsAsNumericY.AddParameter("x", clsRFunctionParameter:=ucrReceiverSecondVar.GetVariables, iPosition:=0) + clsRCorrelation.AddParameter("x", clsRFunctionParameter:=clsAsMatrixX, iPosition:=0) + clsRCorrelation.AddParameter("y", clsRFunctionParameter:=clsAsNumericY, iPosition:=1) ' ucrReceiverFirstVar.SetParameterIsRFunction() ' ucrReceiverSecondVar.SetParameterIsRFunction() - ElseIf ((strVarType = "numeric" OrElse strVarType = "integer") AndAlso (strSecondVarType = "factor")) Then + ElseIf strFirstVariablesType = "categorical" AndAlso strSecondVariableType = "numeric" Then ucrChkSaveResult.Visible = False cmdSummaries.Visible = False cmdDisplayOptions.Visible = True ucrChkOmitMissing.Visible = False ucrSelectorDescribeTwoVar.SetParameterIsString() ucrBase.clsRsyntax.SetBaseRFunction(clsRAnova) - ucrReceiverFirstVar.SetParameterIsString() ucrReceiverSecondVar.SetParameterIsString() - ElseIf ((strVarType = "factor") AndAlso (strSecondVarType = "numeric" OrElse strSecondVarType = "integer")) Then + ucrReceiverFirstVars.SetParameterIsString() + ElseIf strFirstVariablesType = "numeric" AndAlso strSecondVariableType = "categorical" Then ucrChkSaveResult.Visible = True cmdSummaries.Visible = True cmdDisplayOptions.Visible = False ucrChkOmitMissing.Visible = True ucrSelectorDescribeTwoVar.SetParameterIsString() - ucrReceiverFirstVar.SetParameterIsString() - ucrBase.clsRsyntax.SetBaseRFunction(clsRCustomSummary) ucrReceiverSecondVar.SetParameterIsString() - ElseIf ((strVarType = "factor") AndAlso (strSecondVarType = "factor")) Then + ucrBase.clsRsyntax.SetBaseRFunction(clsRCustomSummary) + ucrReceiverFirstVars.SetParameterIsString() + ElseIf strFirstVariablesType = "categorical" AndAlso strSecondVariableType = "categorical" Then ucrChkSaveResult.Visible = False cmdSummaries.Visible = False cmdDisplayOptions.Visible = True ucrChkOmitMissing.Visible = False ucrSelectorDescribeTwoVar.SetParameterIsString() ucrBase.clsRsyntax.SetBaseRFunction(clsRFreqTables) - ucrReceiverFirstVar.SetParameterIsString() ucrReceiverSecondVar.SetParameterIsString() - Else - ucrChkSaveResult.Visible = False - ucrChkOmitMissing.Visible = False - cmdSummaries.Visible = False - cmdDisplayOptions.Visible = False + ucrReceiverFirstVars.SetParameterIsString() End If SetRCodeForControls(False) End Sub - Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverSecondVar.ControlContentsChanged, ucrReceiverFirstVar.ControlContentsChanged + Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFirstVars.ControlContentsChanged, ucrReceiverSecondVar.ControlContentsChanged Results() TestOKEnabled() End Sub diff --git a/instat/sdgDescribeDisplay.vb b/instat/sdgDescribeDisplay.vb index ec8cb7c35a2..9399301765d 100644 --- a/instat/sdgDescribeDisplay.vb +++ b/instat/sdgDescribeDisplay.vb @@ -69,10 +69,10 @@ Public Class sdgDescribeDisplay End Sub Public Sub GrpBoxEnable() - If ((dlgDescribeTwoVariable.strSecondVarType = "factor") And (dlgDescribeTwoVariable.strVarType = "numeric" OrElse dlgDescribeTwoVariable.strVarType = "integer")) Then + If ((dlgDescribeTwoVariable.strFirstVariablesType = "factor") And (dlgDescribeTwoVariable.strSecondVariableType = "numeric" OrElse dlgDescribeTwoVariable.strSecondVariableType = "integer")) Then grpAnovaOptions.Enabled = True grpFrequenciesOptions.Enabled = False - ElseIf ((dlgDescribeTwoVariable.strVarType = "factor") And (dlgDescribeTwoVariable.strSecondVarType = "factor")) Then + ElseIf ((dlgDescribeTwoVariable.strSecondVariableType = "factor") And (dlgDescribeTwoVariable.strFirstVariablesType = "factor")) Then grpFrequenciesOptions.Enabled = True grpAnovaOptions.Enabled = False End If diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 0c1e990f6b1..01f078cd688 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -240,7 +240,6 @@ DataBook$set("public", "calculate_summary", function(data_name, columns_to_summa DataBook$set("public", "summary", function(data_name, columns_to_summarise, summaries, factors = c(), store_results = FALSE, drop = FALSE, return_output = FALSE, summary_name = NA, add_cols = c(), filter_names = c(), ...) { calculated_from = list() calculated_from[[1]] <- list(data_name = data_name, columns = columns_to_summarise) - summaries <- unique(summaries) summaries <- summaries[order(match(summaries, all_summaries))] summaries_count <- summaries[startsWith(summaries, "summary_count")] @@ -254,34 +253,60 @@ DataBook$set("public", "summary", function(data_name, columns_to_summarise, summ summary_names <- make.unique(summary_names) summary_count_names <- summary_names[1:count_summaries_max] summary_other_names <- summary_names[(count_summaries_max + 1):summaries_max] + col_data_type <- self$get_variables_metadata(data_name = data_name, column = columns_to_summarise, property = data_type_label) - results_count <- data.frame(matrix(ncol = length(columns_to_summarise), nrow = max(1, count_summaries_max))) - results_other <- data.frame(matrix(ncol = length(columns_to_summarise), nrow = summaries_max - count_summaries_max)) - names(results_count) <- columns_to_summarise - names(results_other) <- columns_to_summarise + + factors_disp <- dplyr::if_else(length(factors) == 0, ".id", factors) + factors_levels <- lapply(factors, function(x) { + fac_col <- self$get_columns_from_data(data_name, x) + if(is.factor(fac_col)) return(levels(fac_col)) + else return(sort(unique(fac_col))) + }) + factors_levels <- expand.grid(factors_levels) + names(factors_levels) <- factors + + results <- list() i <- 1 for(col_new in columns_to_summarise) { + results_temp_count <- list() + results_temp_other <- list() for(j in seq_along(summaries)) { calc <- calculation$new(type = "summary", parameters = list(data_name = data_name, columns_to_summarise = col_new, summaries = summaries[j], factors = factors, store_results = store_results, drop = drop, return_output = return_output, summary_name = summary_name, add_cols = add_cols, ... = ...), filters = filter_names, calculated_from = calculated_from) calc_apply <- tryCatch(self$apply_calculation(calc), error = function(c) { - x <- data.frame(col_new, NA) - names(x) <- c(".id", summary_names[j]) - return(x) + if(length(factors) == 0) { + x <- data.frame(NA, NA) + names(x) <- c(".id", summary_names[j]) + return(x) + } + else { + x <- factors_levels + x[[summary_names[j]]] <- NA + return(x) + } }) - if(j <= count_summaries_max) results_count[j,i] <- calc_apply[1,2] - else results_other[j - count_summaries_max,i] <- calc_apply[1,2] + names(calc_apply)[length(factors_disp) + 1] <- col_new + calc_apply$summary <- summary_names[j] + if(j <= count_summaries_max) results_temp_count[[length(results_temp_count) + 1]] <- calc_apply + else results_temp_other[[length(results_temp_other) + 1]] <- calc_apply } - i = i + 1 + results_temp_count <- dplyr::bind_rows(results_temp_count) + results_temp_other <- dplyr::bind_rows(results_temp_other) + # Set type of Date columns since may have coerced to numeric + if("Date" %in% col_data_type[i]) results_temp_other[[col_new]] <- as.Date(results_temp_other[[col_new]], origin = "1970/1/1") + results_temp_count <- format(results_temp_count, scientific = FALSE) + results_temp_other <- format(results_temp_other, scientific = FALSE) + results_temp <- dplyr::bind_rows(results_temp_count, results_temp_other) + if(i == 1) results <- results_temp + else results <- dplyr::full_join(results, results_temp, by = c(factors_disp, "summary")) + i <- i + 1 } - # Set type of Date columns since may have coerced to numeric - for(k in seq_along(results_other)) { - if("Date" %in% col_data_type[k]) results_other[[k]] <- as.Date(results_other[[k]], origin = "1970/1/1") + results <- results %>% select(c(factors_disp, "summary"), everything()) + if(length(factors) == 0) { + results$.id <- NULL + results$summary <- NULL + row.names(results) <- summary_names } - results_count <- format(results_count, scientific = FALSE) - results_other <- format(results_other, scientific = FALSE) - results <- bind_rows(results_count, results_other) - row.names(results) <- summary_names return(results) } ) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 08d9a76870b..ab169ecbd5d 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -596,30 +596,16 @@ DataSheet$set("public", "get_columns_from_data", function(col_names, force_as_da } ) -DataSheet$set("public", "frequency_tables", function(x_col_names, y_col_name, addmargins = FALSE, proportions = FALSE, percentages = FALSE, transpose = FALSE) { - if(missing(x_col_names) || missing(y_col_name)) stop("Both x_col_names and y_col_name are required") - multiply_by = 1 - for (i in 1:length(x_col_names)){ - if(transpose)(my_table = table(private$data[[y_col_name]], private$data[[x_col_names[i]]])) else(my_table = table(private$data[[x_col_names[i]]], private$data[[y_col_name]])) - - if(percentages && proportions)( multiply_by = 100) - else if(percentages && !proportions)warning("Proportions should be set to true to display percentages.") - if(addmargins && proportions)(print(addmargins(prop.table(my_table)*multiply_by))) #Is FUN appropriate here? - else if(addmargins && !proportions)(print(addmargins(my_table))) - else if(!addmargins && proportions)(print(prop.table(my_table)*multiply_by)) - else if(!addmargins && !proportions)(print(my_table)) - } -} -) - DataSheet$set("public", "anova_tables", function(x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE) { if(missing(x_col_names) || missing(y_col_name)) stop("Both x_col_names and y_col_names are required") - if(sign_level || signif.stars)warning("This is nolonger descriptive") - if(sign_level)(end_col = 5)else(end_col = 4) - for (i in 1:length(x_col_names)){ - my_model = lm(formula = as.formula(paste(as.name(y_col_name),as.name(x_col_names[i]), sep = "~")), data=private$data) - print(anova(my_model)[1:end_col], signif.stars = signif.stars) - if(means)(print(model.tables(aov(my_model), type = "means"))) + if(sign_level || signif.stars) message("This is no longer descriptive") + if(sign_level) end_col = 5 else end_col = 4 + for (i in seq_along(x_col_names)) { + mod <- lm(formula = as.formula(paste0("as.numeric(", as.name(y_col_name), ") ~ ", as.name(x_col_names[i]))), data = self$get_data_frame()) + cat("ANOVA table: ", y_col_name, " ~ ", x_col_names[i], "\n", sep = "") + print(anova(mod)[1:end_col], signif.stars = signif.stars) + cat("\n") + if(means) (print(model.tables(aov(mod), type = "means"))) } } ) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index b326a10d4e5..c5d0cf4fef5 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -789,8 +789,12 @@ DataBook$set("public", "rename_column_in_data", function(data_name, column_name, } ) -DataBook$set("public", "frequency_tables", function(data_name, x_col_names, y_col_name, addmargins = FALSE, proportions = FALSE, percentages = FALSE, transpose = FALSE) { - self$get_data_objects(data_name)$frequency_tables(x_col_names, y_col_name, addmargins = addmargins, proportions = proportions, percentages = percentages, transpose = transpose) +DataBook$set("public", "frequency_tables", function(data_name, x_col_names, y_col_name, n_column_factors = 1, store_results = TRUE, drop = TRUE, na.rm = FALSE, summary_name = NA, include_margins = FALSE, return_output = TRUE, treat_columns_as_factor = FALSE, page_by = "default", as_html = TRUE, signif_fig = 2, na_display = "", na_level_display = "NA", weights = NULL, caption = NULL, result_names = NULL, percentage_type = "none", perc_total_columns = NULL, perc_total_factors = c(), perc_total_filter = NULL, perc_decimal = FALSE, margin_name = "(All)", additional_filter, ...) { + for(i in seq_along(x_col_names)) { + cat(x_col_names[i], "by", y_col_name, "\n") + print(data_book$summary_table(data_name = data_name, summaries = count_label, factors=c(x_col_names[i], y_col_name), n_column_factors = n_column_factors, store_results = store_results, drop = drop, na.rm = na.rm, summary_name = summary_name, include_margins = include_margins, return_output = return_output, treat_columns_as_factor = treat_columns_as_factor, page_by = page_by, as_html = as_html, signif_fig = signif_fig, na_display = na_display, na_level_display = na_level_display, weights = weights, caption = caption, result_names = result_names, percentage_type = percentage_type, perc_total_columns = perc_total_columns, perc_total_factors = perc_total_factors, perc_total_filter = perc_total_filter, perc_decimal = perc_decimal, margin_name = margin_name, additional_filter = additional_filter, ... = ...)) + cat("\n") + } } ) diff --git a/instat/ucrReceiverMultiple.vb b/instat/ucrReceiverMultiple.vb index ff5e5a71d1f..f3b4dad4c5f 100644 --- a/instat/ucrReceiverMultiple.vb +++ b/instat/ucrReceiverMultiple.vb @@ -439,19 +439,25 @@ Public Class ucrReceiverMultiple If strVariableTypes.Count > 1 AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("numeric") AndAlso strVariableTypes.Contains("integer")) AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("factor") AndAlso strVariableTypes.Contains("ordered,factor")) Then MsgBox("Cannot add these variables. All variables must be of the same data type.", MsgBoxStyle.OkOnly, "Cannot add variables.") Clear() + SetSelectorHeading("Variables") ElseIf strVariableTypes.Count > 0 Then If strVariableTypes(0) = "integer" Then SetDataType("numeric", bStrict:=True) - ElseIf strVariableTypes(0) = "ordered,factor" Then + SetSelectorHeading("Numerics") + ElseIf strVariableTypes(0) = "ordered,factor" OrElse strVariableTypes(0) = "factor" Then SetDataType("factor", bStrict:=True) + SetSelectorHeading("Factors") Else SetDataType(strVariableTypes(0), bStrict:=True) + SetSelectorHeading(strVariableTypes(0) & " Variables") End If Else RemoveIncludedMetadataProperty(strProperty:="class") + SetSelectorHeading("Variables") End If Else RemoveIncludedMetadataProperty(strProperty:="class") + SetSelectorHeading("Variables") End If Else ' Removed as this was causing data type to be removed on reset for any receiver From a7a33c290a353ada4edb78f9ef814bca6b33aab0 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Fri, 15 Nov 2019 21:33:51 +0000 Subject: [PATCH 09/10] added correlation function added details about output in two variable summarise dialog design allowed broad categorical/numeric types in two variable summarise added option to single type receiver to have broad categorical/numeric types --- instat/dlgDescribeTwoVariable.Designer.vb | 101 +++++-- instat/dlgDescribeTwoVariable.resx | 280 ++++++++++++++---- instat/dlgDescribeTwoVariable.vb | 126 ++++---- instat/static/InstatObject/R/data_object_R6.R | 12 + .../static/InstatObject/R/instat_object_R6.R | 5 + instat/ucrReceiverMultiple.vb | 64 ++-- 6 files changed, 411 insertions(+), 177 deletions(-) diff --git a/instat/dlgDescribeTwoVariable.Designer.vb b/instat/dlgDescribeTwoVariable.Designer.vb index 456d1aefbe7..eb116e0950e 100644 --- a/instat/dlgDescribeTwoVariable.Designer.vb +++ b/instat/dlgDescribeTwoVariable.Designer.vb @@ -40,15 +40,22 @@ Partial Class dlgDescribeTwoVariable Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(dlgDescribeTwoVariable)) Me.cmdSummaries = New System.Windows.Forms.Button() - Me.cmdDisplayOptions = New System.Windows.Forms.Button() Me.lblFirstVariable = New System.Windows.Forms.Label() Me.lbSecondVariable = New System.Windows.Forms.Label() + Me.grpOptions = New System.Windows.Forms.GroupBox() + Me.lblSummary = New System.Windows.Forms.Label() + Me.lblFirstType = New System.Windows.Forms.Label() + Me.lblBy = New System.Windows.Forms.Label() + Me.lblSecondType = New System.Windows.Forms.Label() + Me.lblSummaryName = New System.Windows.Forms.Label() + Me.grpSummaries = New System.Windows.Forms.GroupBox() + Me.ucrChkOmitMissing = New instat.ucrCheck() Me.ucrReceiverSecondVar = New instat.ucrReceiverSingle() Me.ucrReceiverFirstVars = New instat.ucrReceiverMultiple() Me.ucrSelectorDescribeTwoVar = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrBase = New instat.ucrButtons() - Me.ucrChkSaveResult = New instat.ucrCheck() - Me.ucrChkOmitMissing = New instat.ucrCheck() + Me.grpOptions.SuspendLayout() + Me.grpSummaries.SuspendLayout() Me.SuspendLayout() ' 'cmdSummaries @@ -58,13 +65,6 @@ Partial Class dlgDescribeTwoVariable Me.cmdSummaries.Tag = "Summaries" Me.cmdSummaries.UseVisualStyleBackColor = True ' - 'cmdDisplayOptions - ' - resources.ApplyResources(Me.cmdDisplayOptions, "cmdDisplayOptions") - Me.cmdDisplayOptions.Name = "cmdDisplayOptions" - Me.cmdDisplayOptions.Tag = "Display_Options" - Me.cmdDisplayOptions.UseVisualStyleBackColor = True - ' 'lblFirstVariable ' resources.ApplyResources(Me.lblFirstVariable, "lblFirstVariable") @@ -77,6 +77,57 @@ Partial Class dlgDescribeTwoVariable Me.lbSecondVariable.Name = "lbSecondVariable" Me.lbSecondVariable.Tag = "" ' + 'grpOptions + ' + Me.grpOptions.Controls.Add(Me.ucrChkOmitMissing) + Me.grpOptions.Controls.Add(Me.cmdSummaries) + resources.ApplyResources(Me.grpOptions, "grpOptions") + Me.grpOptions.Name = "grpOptions" + Me.grpOptions.TabStop = False + ' + 'lblSummary + ' + resources.ApplyResources(Me.lblSummary, "lblSummary") + Me.lblSummary.Name = "lblSummary" + ' + 'lblFirstType + ' + Me.lblFirstType.ForeColor = System.Drawing.SystemColors.ControlText + resources.ApplyResources(Me.lblFirstType, "lblFirstType") + Me.lblFirstType.Name = "lblFirstType" + ' + 'lblBy + ' + resources.ApplyResources(Me.lblBy, "lblBy") + Me.lblBy.Name = "lblBy" + ' + 'lblSecondType + ' + resources.ApplyResources(Me.lblSecondType, "lblSecondType") + Me.lblSecondType.Name = "lblSecondType" + ' + 'lblSummaryName + ' + resources.ApplyResources(Me.lblSummaryName, "lblSummaryName") + Me.lblSummaryName.Name = "lblSummaryName" + ' + 'grpSummaries + ' + Me.grpSummaries.Controls.Add(Me.lblFirstType) + Me.grpSummaries.Controls.Add(Me.lblSummaryName) + Me.grpSummaries.Controls.Add(Me.lblSummary) + Me.grpSummaries.Controls.Add(Me.lblBy) + Me.grpSummaries.Controls.Add(Me.lblSecondType) + resources.ApplyResources(Me.grpSummaries, "grpSummaries") + Me.grpSummaries.Name = "grpSummaries" + Me.grpSummaries.TabStop = False + ' + 'ucrChkOmitMissing + ' + Me.ucrChkOmitMissing.Checked = False + resources.ApplyResources(Me.ucrChkOmitMissing, "ucrChkOmitMissing") + Me.ucrChkOmitMissing.Name = "ucrChkOmitMissing" + ' 'ucrReceiverSecondVar ' Me.ucrReceiverSecondVar.frmParent = Me @@ -108,30 +159,16 @@ Partial Class dlgDescribeTwoVariable resources.ApplyResources(Me.ucrBase, "ucrBase") Me.ucrBase.Name = "ucrBase" ' - 'ucrChkSaveResult - ' - Me.ucrChkSaveResult.Checked = False - resources.ApplyResources(Me.ucrChkSaveResult, "ucrChkSaveResult") - Me.ucrChkSaveResult.Name = "ucrChkSaveResult" - ' - 'ucrChkOmitMissing - ' - Me.ucrChkOmitMissing.Checked = False - resources.ApplyResources(Me.ucrChkOmitMissing, "ucrChkOmitMissing") - Me.ucrChkOmitMissing.Name = "ucrChkOmitMissing" - ' 'dlgDescribeTwoVariable ' resources.ApplyResources(Me, "$this") Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.Controls.Add(Me.ucrChkSaveResult) - Me.Controls.Add(Me.ucrChkOmitMissing) + Me.Controls.Add(Me.grpSummaries) + Me.Controls.Add(Me.grpOptions) Me.Controls.Add(Me.lbSecondVariable) Me.Controls.Add(Me.lblFirstVariable) - Me.Controls.Add(Me.cmdDisplayOptions) Me.Controls.Add(Me.ucrReceiverSecondVar) Me.Controls.Add(Me.ucrReceiverFirstVars) - Me.Controls.Add(Me.cmdSummaries) Me.Controls.Add(Me.ucrSelectorDescribeTwoVar) Me.Controls.Add(Me.ucrBase) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow @@ -139,6 +176,9 @@ Partial Class dlgDescribeTwoVariable Me.MinimizeBox = False Me.Name = "dlgDescribeTwoVariable" Me.Tag = "Describe_Two_Variable" + Me.grpOptions.ResumeLayout(False) + Me.grpSummaries.ResumeLayout(False) + Me.grpSummaries.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() @@ -149,9 +189,14 @@ Partial Class dlgDescribeTwoVariable Friend WithEvents ucrReceiverFirstVars As ucrReceiverMultiple Friend WithEvents cmdSummaries As Button Friend WithEvents ucrReceiverSecondVar As ucrReceiverSingle - Friend WithEvents cmdDisplayOptions As Button Friend WithEvents lblFirstVariable As Label Friend WithEvents lbSecondVariable As Label - Friend WithEvents ucrChkSaveResult As ucrCheck Friend WithEvents ucrChkOmitMissing As ucrCheck + Friend WithEvents grpOptions As GroupBox + Friend WithEvents lblSecondType As Label + Friend WithEvents lblBy As Label + Friend WithEvents lblFirstType As Label + Friend WithEvents lblSummary As Label + Friend WithEvents lblSummaryName As Label + Friend WithEvents grpSummaries As GroupBox End Class diff --git a/instat/dlgDescribeTwoVariable.resx b/instat/dlgDescribeTwoVariable.resx index deddb4feabf..88877765e37 100644 --- a/instat/dlgDescribeTwoVariable.resx +++ b/instat/dlgDescribeTwoVariable.resx @@ -117,9 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NoControl + - 305, 222 + 9, 45 105, 23 @@ -138,38 +142,17 @@ System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - $this + grpOptions - 7 - - - 304, 221 - - - 105, 23 - - - 8 - - - Display Options - - - cmdDisplayOptions - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 + 1 True + + NoControl + 268, 45 @@ -194,6 +177,9 @@ 3 + + NoControl + 268, 155 @@ -218,38 +204,8 @@ 2 - - True - - - 6, 13 - - - 415, 309 - - - 10, 224 - - - 100, 20 - - - 5 - - - ucrChkSaveResult - - - instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 0 - - 10, 198 + 9, 19 143, 20 @@ -264,15 +220,209 @@ instat.ucrCheck, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - $this + grpOptions + 0 + + + 236, 202 + + + 155, 76 + + + 10 + + + Options + + + grpOptions + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + NoControl + + + 6, 43 + + + 53, 13 + + + 9 + + + Summary: + + + lblSummary + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpSummaries + + + 2 + + + NoControl + + + 6, 16 + + + 55, 13 + + + 10 + + + TopRight + + + lblFirstType + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpSummaries + + + 0 + + + True + + + NoControl + + + 64, 16 + + + 18, 13 + + + 11 + + + by + + + lblBy + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpSummaries + + + 3 + + + True + + + NoControl + + + 82, 16 + + + 0, 13 + + + 12 + + + lblSecondType + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpSummaries + + + 4 + + + True + + + NoControl + + + 60, 43 + + + 0, 13 + + + 13 + + + lblSummaryName + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpSummaries + + 1 + + 10, 202 + + + 210, 72 + + + 14 + + + grpSummaries + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 6, 13 + + + 419, 341 + 271, 63 - 0, 0, 0, 0 @@ -292,7 +442,7 @@ $this - 6 + 5 10, 10 @@ -316,10 +466,10 @@ $this - 8 + 6 - 10, 250 + 10, 286 410, 52 @@ -337,7 +487,7 @@ $this - 9 + 7 CenterScreen @@ -373,6 +523,6 @@ $this - 5 + 4 \ No newline at end of file diff --git a/instat/dlgDescribeTwoVariable.vb b/instat/dlgDescribeTwoVariable.vb index fee40946222..ee677991143 100644 --- a/instat/dlgDescribeTwoVariable.vb +++ b/instat/dlgDescribeTwoVariable.vb @@ -22,7 +22,6 @@ Public Class dlgDescribeTwoVariable Public strFirstVariablesType, strSecondVariableType As String Public clsGetDataType, clsGetSecondDataType, clsRCorrelation, clsRCustomSummary, clsConcFunction, clsRAnova, clsRFreqTables As New RFunction Private clsSummariesList As New RFunction - Private clsAsMatrixX, clsAsNumericY As New RFunction Private Sub dlgDescribeTwoVariable_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then @@ -48,16 +47,12 @@ Public Class dlgDescribeTwoVariable ucrReceiverFirstVars.SetParameter(New RParameter("columns_to_summarise", 1)) ucrReceiverFirstVars.SetParameterIsString() ucrReceiverFirstVars.Selector = ucrSelectorDescribeTwoVar - ucrReceiverFirstVars.SetSingleTypeStatus(True) + ucrReceiverFirstVars.SetSingleTypeStatus(True, bIsCategoricalNumeric:=True) ucrReceiverSecondVar.SetParameter(New RParameter("factors", 2)) ucrReceiverSecondVar.SetParameterIsString() ucrReceiverSecondVar.Selector = ucrSelectorDescribeTwoVar - ucrChkSaveResult.SetParameter(New RParameter("store_results", 4)) - ucrChkSaveResult.SetText("Save Result") - ucrChkSaveResult.SetValuesCheckedAndUnchecked("TRUE", "FALSE") - ucrChkOmitMissing.SetParameter(New RParameter("na.rm", 6)) ucrChkOmitMissing.SetText("Omit Missing Values") ucrChkOmitMissing.SetValuesCheckedAndUnchecked("TRUE", "FALSE") @@ -77,8 +72,6 @@ Public Class dlgDescribeTwoVariable clsSummariesList = New RFunction clsRCustomSummary = New RFunction clsConcFunction = New RFunction - clsAsMatrixX = New RFunction - clsAsNumericY = New RFunction ucrSelectorDescribeTwoVar.Reset() ucrReceiverFirstVars.SetMeAsReceiver() @@ -93,9 +86,6 @@ Public Class dlgDescribeTwoVariable clsRAnova.AddParameter("sign_level", "FALSE", iPosition:=3) clsRAnova.AddParameter("means", "FALSE", iPosition:=4) - clsRCorrelation.AddParameter("use", Chr(34) & "pairwise.complete.obs" & Chr(34), iPosition:=2) - clsRCorrelation.AddParameter("method", Chr(34) & "pearson" & Chr(34), iPosition:=3) - clsSummariesList.SetRCommand("c") clsSummariesList.AddParameter("summary_count_non_missing", Chr(34) & "summary_count_non_missing" & Chr(34), bIncludeArgumentName:=False) clsSummariesList.AddParameter("summary_count", Chr(34) & "summary_count" & Chr(34), bIncludeArgumentName:=False) @@ -109,35 +99,33 @@ Public Class dlgDescribeTwoVariable clsRCustomSummary.AddParameter("na.rm", "FALSE", iPosition:=6) clsRCustomSummary.AddParameter("return_output", "TRUE", iPosition:=7) - clsRCorrelation.SetRCommand("cor") - - clsAsMatrixX.SetRCommand("as.matrix") - clsAsNumericY.SetRCommand("as.numeric") + clsRCorrelation.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$cor") clsRAnova.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$anova_tables") - Results() - ucrBase.clsRsyntax.SetBaseRFunction(clsRCustomSummary) bResetSubdialog = True End Sub Private Sub SetRCodeForControls(bReset As Boolean) ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("y_col_name", 2), iAdditionalPairNo:=1) - ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("factors", 2), iAdditionalPairNo:=2) - ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("y_col_name", 2), iAdditionalPairNo:=3) + ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("y_col_name", 2), iAdditionalPairNo:=2) + ucrReceiverSecondVar.AddAdditionalCodeParameterPair(clsRCorrelation, New RParameter("y_col_name", 2), iAdditionalPairNo:=3) ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("x_col_names", 1), iAdditionalPairNo:=1) - ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("columns_to_summarise", 1), iAdditionalPairNo:=2) - ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("x_col_names", 1), iAdditionalPairNo:=3) + ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("x_col_names", 1), iAdditionalPairNo:=2) + ucrReceiverFirstVars.AddAdditionalCodeParameterPair(clsRCorrelation, New RParameter("x_col_names", 1), iAdditionalPairNo:=3) - ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRAnova, New RParameter("data_name", 0), iAdditionalPairNo:=1) - ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRCustomSummary, New RParameter("data_name", 0), iAdditionalPairNo:=2) - ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRFreqTables, New RParameter("data_name", 0), iAdditionalPairNo:=3) + ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRAnova, ucrSelectorDescribeTwoVar.GetParameter(), iAdditionalPairNo:=1) + ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRCustomSummary, ucrSelectorDescribeTwoVar.GetParameter(), iAdditionalPairNo:=2) + ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsRFreqTables, ucrSelectorDescribeTwoVar.GetParameter(), iAdditionalPairNo:=3) ucrChkOmitMissing.SetRCode(clsRCustomSummary, bReset) - ucrChkSaveResult.SetRCode(clsRCustomSummary, bReset) - ucrSelectorDescribeTwoVar.SetRCode(clsRCustomSummary, bReset) + ucrReceiverFirstVars.SetRCode(clsRCustomSummary, bReset) + ucrReceiverSecondVar.SetRCode(clsRCustomSummary, bReset) + ucrSelectorDescribeTwoVar.SetRCode(clsRCorrelation, bReset) + + Results() End Sub Public Sub TestOKEnabled() @@ -165,7 +153,7 @@ Public Class dlgDescribeTwoVariable TestOKEnabled() End Sub - Private Sub cmdDisplayOptions_Click(sender As Object, e As EventArgs) Handles cmdDisplayOptions.Click + Private Sub cmdDisplayOptions_Click(sender As Object, e As EventArgs) sdgDescribeDisplay.SetRFunction(clsRFreqTables, clsRAnova, bResetSubdialog) bResetSubdialog = False sdgDescribeDisplay.ShowDialog() @@ -175,76 +163,84 @@ Public Class dlgDescribeTwoVariable Public Sub Results() Dim lstFirstItemTypes As List(Of String) - If (ucrReceiverFirstVars.GetCurrentItemTypes.Count > 0) Then - lstFirstItemTypes = ucrReceiverFirstVars.GetCurrentItemTypes() - If lstFirstItemTypes.Contains("factor") OrElse lstFirstItemTypes.Contains("character") Then - strFirstVariablesType = "categorical" + If Not ucrReceiverFirstVars.IsEmpty() Then + lstFirstItemTypes = ucrReceiverFirstVars.GetCurrentItemTypes(True, bIsCategoricalNumeric:=True) + If lstFirstItemTypes.Count = 1 AndAlso lstFirstItemTypes.Contains("logical") Then + lstFirstItemTypes(0) = "categorical" Else - strFirstVariablesType = "numeric" + lstFirstItemTypes.RemoveAll(Function(x) x.Contains("logical")) End If + If (lstFirstItemTypes.Count > 0) Then + strFirstVariablesType = lstFirstItemTypes(0) + Else + strFirstVariablesType = "" + lblFirstType.Text = "________" + lblFirstType.ForeColor = SystemColors.ControlText + End If + lblFirstType.Text = strFirstVariablesType + lblFirstType.ForeColor = SystemColors.Highlight Else strFirstVariablesType = "" + lblFirstType.Text = "________" + lblFirstType.ForeColor = SystemColors.ControlText End If If Not ucrReceiverSecondVar.IsEmpty() Then strSecondVariableType = ucrReceiverSecondVar.strCurrDataType - If strSecondVariableType.Contains("factor") OrElse strSecondVariableType.Contains("character") Then + If strSecondVariableType.Contains("factor") OrElse strSecondVariableType.Contains("character") OrElse strSecondVariableType.Contains("logical") Then strSecondVariableType = "categorical" Else strSecondVariableType = "numeric" End If + lblSecondType.Text = strSecondVariableType + lblSecondType.ForeColor = SystemColors.Highlight Else strSecondVariableType = "" + lblSecondType.Text = "________" + lblSecondType.ForeColor = SystemColors.ControlText End If If strFirstVariablesType = "numeric" AndAlso strSecondVariableType = "numeric" Then - ucrChkSaveResult.Visible = False + grpOptions.Visible = True cmdSummaries.Visible = False - cmdDisplayOptions.Visible = False - ucrChkOmitMissing.Visible = False - - clsRCorrelation.RemoveParameterByName("data_name") + ucrChkOmitMissing.Visible = True ucrBase.clsRsyntax.SetBaseRFunction(clsRCorrelation) - 'Temporary Fix- Only one of the receivers gets variables (the last variable of the two) - 'ie, when ucrReceiverFirstVar and ucrReceiverSecondVar are set from SetParameterIsString to SetParameterIsRFunction only the second (ucrReceiverSecondVar) changes to SetParameterIsRFunction the first one remains as SetParameterIsString which is not needed - clsAsMatrixX.AddParameter("x", clsRFunctionParameter:=ucrReceiverFirstVars.GetVariables, iPosition:=0) - clsAsNumericY.AddParameter("x", clsRFunctionParameter:=ucrReceiverSecondVar.GetVariables, iPosition:=0) - clsRCorrelation.AddParameter("x", clsRFunctionParameter:=clsAsMatrixX, iPosition:=0) - clsRCorrelation.AddParameter("y", clsRFunctionParameter:=clsAsNumericY, iPosition:=1) - ' ucrReceiverFirstVar.SetParameterIsRFunction() - ' ucrReceiverSecondVar.SetParameterIsRFunction() + lblSummaryName.Text = "Correlations" + lblSummaryName.ForeColor = SystemColors.Highlight ElseIf strFirstVariablesType = "categorical" AndAlso strSecondVariableType = "numeric" Then - ucrChkSaveResult.Visible = False - cmdSummaries.Visible = False - cmdDisplayOptions.Visible = True - ucrChkOmitMissing.Visible = False - ucrSelectorDescribeTwoVar.SetParameterIsString() + grpOptions.Visible = False ucrBase.clsRsyntax.SetBaseRFunction(clsRAnova) - ucrReceiverSecondVar.SetParameterIsString() - ucrReceiverFirstVars.SetParameterIsString() + lblSummaryName.Text = "ANOVA tables" + lblSummaryName.ForeColor = SystemColors.Highlight ElseIf strFirstVariablesType = "numeric" AndAlso strSecondVariableType = "categorical" Then - ucrChkSaveResult.Visible = True + grpOptions.Visible = True cmdSummaries.Visible = True - cmdDisplayOptions.Visible = False ucrChkOmitMissing.Visible = True - ucrSelectorDescribeTwoVar.SetParameterIsString() - ucrReceiverSecondVar.SetParameterIsString() ucrBase.clsRsyntax.SetBaseRFunction(clsRCustomSummary) ucrReceiverFirstVars.SetParameterIsString() + lblSummaryName.Text = "Numerical summaries" + lblSummaryName.ForeColor = SystemColors.Highlight ElseIf strFirstVariablesType = "categorical" AndAlso strSecondVariableType = "categorical" Then - ucrChkSaveResult.Visible = False - cmdSummaries.Visible = False - cmdDisplayOptions.Visible = True - ucrChkOmitMissing.Visible = False - ucrSelectorDescribeTwoVar.SetParameterIsString() + grpOptions.Visible = False ucrBase.clsRsyntax.SetBaseRFunction(clsRFreqTables) - ucrReceiverSecondVar.SetParameterIsString() - ucrReceiverFirstVars.SetParameterIsString() + lblSummaryName.Text = "Frequency tables" + lblSummaryName.ForeColor = SystemColors.Highlight + Else + grpOptions.Visible = False + lblSummaryName.Text = "__________" + lblSummaryName.ForeColor = SystemColors.ControlText End If - SetRCodeForControls(False) End Sub Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFirstVars.ControlContentsChanged, ucrReceiverSecondVar.ControlContentsChanged Results() TestOKEnabled() End Sub + + Private Sub ucrChkOmitMissing_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkOmitMissing.ControlValueChanged + If ucrChkOmitMissing.Checked Then + clsRCorrelation.AddParameter("use", Chr(34) & "pairwise.complete.obs" & Chr(34), iPosition:=2) + Else + clsRCorrelation.RemoveParameterByName("use") + End If + End Sub End Class \ No newline at end of file diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index ab169ecbd5d..3a7cd44c77a 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -610,6 +610,18 @@ DataSheet$set("public", "anova_tables", function(x_col_names, y_col_name, signif } ) +DataSheet$set("public", "cor", function(x_col_names, y_col_name, use = "everything", method = c("pearson", "kendall", "spearman")) { + x <- self$get_columns_from_data(x_col_names, force_as_data_frame = TRUE) + y <- self$get_columns_from_data(y_col_name) + x <- sapply(x, as.numeric) + y <- as.numeric(y) + results <- cor(x = x, y = y, use = use, method = method) + dimnames(results)[[2]] <- y_col_name + cat("Correlations:\n") + return(t(results)) +} +) + DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", new_col_name = "", label = "") { curr_data <- self$get_data_frame(use_current_filter = FALSE) # Column name must be character diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index c5d0cf4fef5..5de795093ec 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -803,6 +803,11 @@ DataBook$set("public", "anova_tables", function(data_name, x_col_names, y_col_na } ) +DataBook$set("public", "cor", function(data_name, x_col_names, y_col_name, use = "everything", method = c("pearson", "kendall", "spearman")) { + self$get_data_objects(data_name)$cor(x_col_names = x_col_names, y_col_name = y_col_name, use = use, method = method) +} +) + DataBook$set("public", "remove_columns_in_data", function(data_name, cols, allow_delete_all = FALSE) { self$get_data_objects(data_name)$remove_columns_in_data(cols = cols, allow_delete_all = allow_delete_all) } diff --git a/instat/ucrReceiverMultiple.vb b/instat/ucrReceiverMultiple.vb index f3b4dad4c5f..a8e4e277e4a 100644 --- a/instat/ucrReceiverMultiple.vb +++ b/instat/ucrReceiverMultiple.vb @@ -19,6 +19,8 @@ Imports RDotNet Public Class ucrReceiverMultiple Public bSingleType As Boolean = False + ' If bSingleType and bCategoricalNumeric then categorical and numeric are the only considered types + Public bCategoricalNumeric As Boolean = False Private Sub ucrReceiverMultiple_Load(sender As Object, e As EventArgs) Handles Me.Load If bFirstLoad Then @@ -359,7 +361,7 @@ Public Class ucrReceiverMultiple lstSelectedVariables.Enabled = Not bFixreceiver End Sub - Public Function GetCurrentItemTypes(Optional bUnique As Boolean = False) As List(Of String) + 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) Dim strDataFrame As String @@ -383,12 +385,22 @@ Public Class ucrReceiverMultiple If expTypes IsNot Nothing AndAlso expTypes.Type <> Internals.SymbolicExpressionType.Null Then strDataTypes = expTypes.AsCharacter.ToList() End If - If bUnique Then - strDataTypes = strDataTypes.Distinct().ToList() - End If If strDataTypes.Count = 2 AndAlso strDataTypes.Contains("ordered") AndAlso strDataTypes.Contains("factor") Then strDataTypes = {"factor"}.ToList End If + If bIsCategoricalNumeric Then + ' logical can be considered as both categorical or numeric so should be dealt with on individual dialogs + For i As Integer = 0 To strDataTypes.Count - 1 + If strDataTypes(i).Contains("factor") OrElse strDataTypes(i).Contains("character") Then + strDataTypes(i) = "categorical" + ElseIf Not strDataTypes(i).Contains("logical") Then + strDataTypes(i) = "numeric" + End If + Next + End If + If bUnique Then + strDataTypes = strDataTypes.Distinct().ToList() + End If End If End If Return strDataTypes @@ -435,39 +447,53 @@ Public Class ucrReceiverMultiple If bSingleType Then If (Not IsEmpty()) Then - strVariableTypes = GetCurrentItemTypes(True) - If strVariableTypes.Count > 1 AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("numeric") AndAlso strVariableTypes.Contains("integer")) AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("factor") AndAlso strVariableTypes.Contains("ordered,factor")) Then + strVariableTypes = GetCurrentItemTypes(True, bCategoricalNumeric) + If strVariableTypes.Count > 1 AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("numeric") AndAlso strVariableTypes.Contains("integer")) AndAlso Not (strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("factor") AndAlso strVariableTypes.Contains("ordered,factor")) AndAlso Not (bCategoricalNumeric AndAlso strVariableTypes.Count = 2 AndAlso strVariableTypes.Contains("logical")) Then MsgBox("Cannot add these variables. All variables must be of the same data type.", MsgBoxStyle.OkOnly, "Cannot add variables.") Clear() SetSelectorHeading("Variables") ElseIf strVariableTypes.Count > 0 Then - If strVariableTypes(0) = "integer" Then - SetDataType("numeric", bStrict:=True) - SetSelectorHeading("Numerics") - ElseIf strVariableTypes(0) = "ordered,factor" OrElse strVariableTypes(0) = "factor" Then - SetDataType("factor", bStrict:=True) - SetSelectorHeading("Factors") + If bCategoricalNumeric Then + If strVariableTypes.Contains("categorical") Then + SetIncludedDataTypes({"factor", "character", "logical"}, bStrict:=True) + SetSelectorHeading("Categorical Variables") + ElseIf strVariableTypes.Contains("numeric") Then + SetExcludedDataTypes({"factor", "character"}) + SetSelectorHeading("Numerics") + Else + ' Else it is logical only + RemoveIncludedMetadataProperty(strProperty:="class") + RemoveExcludedMetadataProperty(strProperty:="class") + SetSelectorHeading("Variables") + End If Else - SetDataType(strVariableTypes(0), bStrict:=True) - SetSelectorHeading(strVariableTypes(0) & " Variables") + If strVariableTypes(0) = "integer" OrElse strVariableTypes(0) = "numeric" Then + SetDataType("numeric", bStrict:=True) + SetSelectorHeading("Numerics") + ElseIf strVariableTypes(0) = "ordered,factor" OrElse strVariableTypes(0) = "factor" Then + SetDataType("factor", bStrict:=True) + SetSelectorHeading("Factors") + Else + SetDataType(strVariableTypes(0), bStrict:=True) + SetSelectorHeading(strVariableTypes(0) & " Variables") + End If End If Else RemoveIncludedMetadataProperty(strProperty:="class") + RemoveExcludedMetadataProperty(strProperty:="class") SetSelectorHeading("Variables") End If Else RemoveIncludedMetadataProperty(strProperty:="class") + RemoveExcludedMetadataProperty(strProperty:="class") SetSelectorHeading("Variables") End If - Else - ' Removed as this was causing data type to be removed on reset for any receiver - ' Left as comment in case this cause other issues - 'RemoveIncludedMetadataProperty(strProperty:="class") End If End Sub - Public Sub SetSingleTypeStatus(bIsSingleType As Boolean) + Public Sub SetSingleTypeStatus(bIsSingleType As Boolean, Optional bIsCategoricalNumeric As Boolean = False) bSingleType = bIsSingleType + bCategoricalNumeric = bIsCategoricalNumeric CheckSingleType() End Sub From 063ca5b3eca96cd060bdc3213b63f54bf6a6fb19 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Sat, 16 Nov 2019 19:07:32 +0000 Subject: [PATCH 10/10] quartiles function now uses type = 1 for Date objects to allow calculation to be done Summaries of Date objects in one/two variable summarise now display as Date/numeric correctly --- instat/dlgDescribeTwoVariable.vb | 10 ++++-- .../R/Backend_Components/summary_functions.R | 34 ++++++++++++++----- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/instat/dlgDescribeTwoVariable.vb b/instat/dlgDescribeTwoVariable.vb index ee677991143..a91ead34a4f 100644 --- a/instat/dlgDescribeTwoVariable.vb +++ b/instat/dlgDescribeTwoVariable.vb @@ -87,9 +87,13 @@ Public Class dlgDescribeTwoVariable clsRAnova.AddParameter("means", "FALSE", iPosition:=4) clsSummariesList.SetRCommand("c") - clsSummariesList.AddParameter("summary_count_non_missing", Chr(34) & "summary_count_non_missing" & Chr(34), bIncludeArgumentName:=False) - clsSummariesList.AddParameter("summary_count", Chr(34) & "summary_count" & Chr(34), bIncludeArgumentName:=False) - clsSummariesList.AddParameter("summary_sum", Chr(34) & "summary_sum" & Chr(34), bIncludeArgumentName:=False) + clsSummariesList.AddParameter("summary_count_missing", Chr(34) & "summary_count_missing" & Chr(34), bIncludeArgumentName:=False, iPosition:=0) + clsSummariesList.AddParameter("summary_min", Chr(34) & "summary_min" & Chr(34), bIncludeArgumentName:=False, iPosition:=1) + clsSummariesList.AddParameter("lower_quartile", Chr(34) & "lower_quartile" & Chr(34), bIncludeArgumentName:=False, iPosition:=2) + clsSummariesList.AddParameter("summary_median", Chr(34) & "summary_median" & Chr(34), bIncludeArgumentName:=False, iPosition:=3) + clsSummariesList.AddParameter("summary_mean", Chr(34) & "summary_mean" & Chr(34), bIncludeArgumentName:=False, iPosition:=4) + clsSummariesList.AddParameter("upper_quartile", Chr(34) & "upper_quartile" & Chr(34), bIncludeArgumentName:=False, iPosition:=5) + clsSummariesList.AddParameter("summary_max", Chr(34) & "summary_max" & Chr(34), bIncludeArgumentName:=False, iPosition:=6) clsRCustomSummary.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$summary") clsRCustomSummary.AddParameter("summaries", clsRFunctionParameter:=clsSummariesList) diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 01f078cd688..7e9a7bcf137 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -292,10 +292,14 @@ DataBook$set("public", "summary", function(data_name, columns_to_summarise, summ } results_temp_count <- dplyr::bind_rows(results_temp_count) results_temp_other <- dplyr::bind_rows(results_temp_other) - # Set type of Date columns since may have coerced to numeric - if("Date" %in% col_data_type[i]) results_temp_other[[col_new]] <- as.Date(results_temp_other[[col_new]], origin = "1970/1/1") results_temp_count <- format(results_temp_count, scientific = FALSE) results_temp_other <- format(results_temp_other, scientific = FALSE) + # Convert summaries which have been coerced to numeric but should be dates + if("Date" %in% col_data_type[i]) { + results_temp_other[[col_new]] <- dplyr::if_else(summaries_other[match(results_temp_other$summary, summary_other_names)] %in% date_summaries, + as.character(as.Date(as.numeric(results_temp_other[[col_new]]), origin = "1970/1/1")), + paste(results_temp_other[[col_new]], "days")) + } results_temp <- dplyr::bind_rows(results_temp_count, results_temp_other) if(i == 1) results <- results_temp else results <- dplyr::full_join(results, results_temp, by = c(factors_disp, "summary")) @@ -462,6 +466,14 @@ all_summaries <- c(count_label, count_non_missing_label, count_missing_label, circular_sd_label, circular_var_label, circular_range_label, circular_ang_dev_label, circular_ang_var_label, circular_rho_label) +# which of the summaries should return a Date value when x is a Date? +date_summaries <- c(min_label, lower_quart_label, quartile_label, median_label, + mode_label, mean_label, trimmed_mean_label, upper_quart_label, + max_label, first_label, last_label, nth_label, + circular_min_label, circular_Q1_label, circular_quantile_label, + circular_median_label, circular_medianHL_label, circular_mean_label, + circular_Q3_label, circular_max_label) + summary_mode <- function(x,...) { ux <- unique(x) out <- ux[which.max(tabulate(match(x, ux)))] @@ -672,28 +684,32 @@ summary_median <- function(x, na.rm = FALSE, na_type = "", ...) { } # quantile function -summary_quantile <- function(x, na.rm = FALSE, probs, na_type = "", ...) { +summary_quantile <- function(x, na.rm = FALSE, probs, type = 7, na_type = "", ...) { if(!na.rm && anyNA(x)) return(NA) # This prevents multiple values being returned if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) - else{ - return(quantile(x, na.rm = na.rm, probs = probs)[[1]]) + else { + if(lubridate::is.Date(x) && type %in% c(2, 4:9)) { + message("type = ", type, " not supported for Dates. Deafulting to type = 1") + type <- 1 + } + return(quantile(x, na.rm = na.rm, probs = probs, type = type)[[1]]) } } # lower quartile function -lower_quartile <- function(x, na.rm = FALSE, na_type = "", ...) { +lower_quartile <- function(x, na.rm = FALSE, type = 7, na_type = "", ...) { if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) else{ - return(summary_quantile(x, na.rm = na.rm, probs = 0.25)) + return(summary_quantile(x, na.rm = na.rm, probs = 0.25, type = type)) } } # upper quartile function -upper_quartile <- function(x, na.rm = FALSE, na_type = "", ...) { +upper_quartile <- function(x, na.rm = FALSE, type = 7, na_type = "", ...) { if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) else{ - return(summary_quantile(x, na.rm = na.rm, probs = 0.75)) + return(summary_quantile(x, na.rm = na.rm, probs = 0.75, type = type)) } }