diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index e88593ac3f1..ec0d46ef898 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -258,9 +258,9 @@ Public Class RLink End If End If - 'If strScript.Length > 2000 Then - ' MsgBox("The following command cannot be run because it exceeds the character limit of 2000 characters for a command in R-Instat." & vbNewLine & strScript & vbNewLine & vbNewLine & "It may be possible to run the command directly in R.", MsgBoxStyle.Critical, "Cannot run command") - If iCallType = 0 OrElse iCallType = 3 Then + 'If strScript.Length > 2000 Then + ' MsgBox("The following command cannot be run because it exceeds the character limit of 2000 characters for a command in R-Instat." & vbNewLine & strScript & vbNewLine & vbNewLine & "It may be possible to run the command directly in R.", MsgBoxStyle.Critical, "Cannot run command") + If iCallType = 0 OrElse iCallType = 3 Then Try If iCallType = 3 Then If strGraphDisplayOption = "view_output_window" OrElse strGraphDisplayOption = "view_separate_window" Then @@ -273,7 +273,7 @@ Public Class RLink 'need to boost resolution of the devices, it's not as good as with ggsave. End If End If - clsEngine.Evaluate(strScript) + clsEngine.Evaluate(strScript) If iCallType = 3 Then If strGraphDisplayOption = "view_output_window" OrElse strGraphDisplayOption = "view_separate_window" Then 'add an R script (maybe in the form of one of our methods) that copies divices to the temp directory, using the default device production... use dev.list() and dev.copy() with arguments device = the devices in the list and which = jpeg devices with different paths leading to the temp directory, using a paste() method to find different names for the files diff --git a/instat/clsRSyntax.vb b/instat/clsRSyntax.vb index 687f3c37dff..c43a569a6a1 100644 --- a/instat/clsRSyntax.vb +++ b/instat/clsRSyntax.vb @@ -33,6 +33,7 @@ Public Class RSyntax Public bUseCommandString As Boolean = False 'Above, the three types of Base R-commands, and their associated "radio bottons booleans". Public iCallType As Integer = 0 + Public bHTMLOutput As Boolean = False Public strScript As String Public i As Integer Public bExcludeAssignedFunctionOutput As Boolean = True diff --git a/instat/dlgInventoryPlot.designer.vb b/instat/dlgInventoryPlot.designer.vb index ede3afb98d5..4240d2f6ba3 100644 --- a/instat/dlgInventoryPlot.designer.vb +++ b/instat/dlgInventoryPlot.designer.vb @@ -22,200 +22,187 @@ Partial Class dlgInventoryPlot 'Do not modify it using the code editor. Private Sub InitializeComponent() - Me.lblYear = New System.Windows.Forms.Label() Me.lblDayOfyear = New System.Windows.Forms.Label() - Me.lblColourBand = New System.Windows.Forms.Label() - Me.lblDoY = New System.Windows.Forms.Label() Me.cmdOptions = New System.Windows.Forms.Button() - Me.lblThreshold = New System.Windows.Forms.Label() - Me.lblFacet = New System.Windows.Forms.Label() + Me.lblDate = New System.Windows.Forms.Label() + Me.lblStation = New System.Windows.Forms.Label() + Me.cmdInventoryPlotOptions = New System.Windows.Forms.Button() + Me.lblElement = New System.Windows.Forms.Label() + Me.ucrReceiverDate = New instat.ucrReceiverSingle() + Me.ucrInputTitle = New instat.ucrInputTextBox() + Me.ucrChkTitle = New instat.ucrCheck() + Me.ucrReceiverElements = New instat.ucrReceiverMultiple() + Me.ucrChkShowNonMissing = New instat.ucrCheck() Me.ucrSaveGraph = New instat.ucrSave() Me.ucrChkFlipCoordinates = New instat.ucrCheck() - Me.ucrChkAddRecodetoData = New instat.ucrCheck() - Me.ucrNudThreashold = New instat.ucrNud() - Me.ucrFacetsReceiver = New instat.ucrReceiverSingle() - Me.ucrColourReceiver = New instat.ucrReceiverSingle() - Me.ucrDayOfYearReceiver = New instat.ucrReceiverSingle() - Me.ucrYearReceiver = New instat.ucrReceiverSingle() + Me.ucrReceiverStation = New instat.ucrReceiverSingle() Me.ucrInventoryPlotSelector = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrBase = New instat.ucrButtons() Me.SuspendLayout() ' - 'lblYear - ' - Me.lblYear.AutoSize = True - Me.lblYear.Location = New System.Drawing.Point(289, 10) - Me.lblYear.Name = "lblYear" - Me.lblYear.Size = New System.Drawing.Size(29, 13) - Me.lblYear.TabIndex = 16 - Me.lblYear.Text = "Year" - ' 'lblDayOfyear ' Me.lblDayOfyear.AutoSize = True - Me.lblDayOfyear.Location = New System.Drawing.Point(289, 90) + Me.lblDayOfyear.Location = New System.Drawing.Point(289, 88) Me.lblDayOfyear.Name = "lblDayOfyear" Me.lblDayOfyear.Size = New System.Drawing.Size(0, 13) - Me.lblDayOfyear.TabIndex = 19 - ' - 'lblColourBand - ' - Me.lblColourBand.AutoSize = True - Me.lblColourBand.Location = New System.Drawing.Point(289, 113) - Me.lblColourBand.Name = "lblColourBand" - Me.lblColourBand.Size = New System.Drawing.Size(29, 13) - Me.lblColourBand.TabIndex = 20 - Me.lblColourBand.Text = "Rain" - ' - 'lblDoY - ' - Me.lblDoY.AutoSize = True - Me.lblDoY.Location = New System.Drawing.Point(289, 59) - Me.lblDoY.Name = "lblDoY" - Me.lblDoY.Size = New System.Drawing.Size(81, 13) - Me.lblDoY.TabIndex = 22 - Me.lblDoY.Text = "Day of the Year" + Me.lblDayOfyear.TabIndex = 15 ' 'cmdOptions ' Me.cmdOptions.Enabled = False - Me.cmdOptions.Location = New System.Drawing.Point(12, 204) + Me.cmdOptions.Location = New System.Drawing.Point(10, 205) Me.cmdOptions.Name = "cmdOptions" - Me.cmdOptions.Size = New System.Drawing.Size(75, 23) - Me.cmdOptions.TabIndex = 23 + Me.cmdOptions.Size = New System.Drawing.Size(119, 23) + Me.cmdOptions.TabIndex = 7 Me.cmdOptions.Text = "Options" Me.cmdOptions.UseVisualStyleBackColor = True ' - 'lblThreshold - ' - Me.lblThreshold.AutoSize = True - Me.lblThreshold.Location = New System.Drawing.Point(292, 165) - Me.lblThreshold.Name = "lblThreshold" - Me.lblThreshold.Size = New System.Drawing.Size(54, 13) - Me.lblThreshold.TabIndex = 27 - Me.lblThreshold.Text = "Threshold" - ' - 'lblFacet - ' - Me.lblFacet.AutoSize = True - Me.lblFacet.Location = New System.Drawing.Point(295, 189) - Me.lblFacet.Name = "lblFacet" - Me.lblFacet.Size = New System.Drawing.Size(49, 13) - Me.lblFacet.TabIndex = 29 - Me.lblFacet.Text = "Facet By" + 'lblDate + ' + Me.lblDate.AutoSize = True + Me.lblDate.Location = New System.Drawing.Point(260, 45) + Me.lblDate.Name = "lblDate" + Me.lblDate.Size = New System.Drawing.Size(33, 13) + Me.lblDate.TabIndex = 1 + Me.lblDate.Text = "Date:" + ' + 'lblStation + ' + Me.lblStation.AutoSize = True + Me.lblStation.Location = New System.Drawing.Point(261, 204) + Me.lblStation.Name = "lblStation" + Me.lblStation.Size = New System.Drawing.Size(88, 13) + Me.lblStation.TabIndex = 5 + Me.lblStation.Text = "Station(Optional):" + ' + 'cmdInventoryPlotOptions + ' + Me.cmdInventoryPlotOptions.Enabled = False + Me.cmdInventoryPlotOptions.Location = New System.Drawing.Point(10, 238) + Me.cmdInventoryPlotOptions.Name = "cmdInventoryPlotOptions" + Me.cmdInventoryPlotOptions.Size = New System.Drawing.Size(119, 23) + Me.cmdInventoryPlotOptions.TabIndex = 8 + Me.cmdInventoryPlotOptions.Text = "Inventory Plot Options" + Me.cmdInventoryPlotOptions.UseVisualStyleBackColor = True + ' + 'lblElement + ' + Me.lblElement.AutoSize = True + Me.lblElement.Location = New System.Drawing.Point(260, 86) + Me.lblElement.Name = "lblElement" + Me.lblElement.Size = New System.Drawing.Size(59, 13) + Me.lblElement.TabIndex = 3 + Me.lblElement.Text = "Element(s):" + ' + 'ucrReceiverDate + ' + Me.ucrReceiverDate.frmParent = Me + Me.ucrReceiverDate.Location = New System.Drawing.Point(263, 60) + Me.ucrReceiverDate.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverDate.Name = "ucrReceiverDate" + Me.ucrReceiverDate.Selector = Nothing + Me.ucrReceiverDate.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverDate.TabIndex = 2 + ' + 'ucrInputTitle + ' + Me.ucrInputTitle.AddQuotesIfUnrecognised = True + Me.ucrInputTitle.IsMultiline = False + Me.ucrInputTitle.IsReadOnly = False + Me.ucrInputTitle.Location = New System.Drawing.Point(119, 295) + Me.ucrInputTitle.Name = "ucrInputTitle" + Me.ucrInputTitle.Size = New System.Drawing.Size(259, 21) + Me.ucrInputTitle.TabIndex = 12 + ' + 'ucrChkTitle + ' + Me.ucrChkTitle.Checked = False + Me.ucrChkTitle.Location = New System.Drawing.Point(10, 297) + Me.ucrChkTitle.Name = "ucrChkTitle" + Me.ucrChkTitle.Size = New System.Drawing.Size(100, 20) + Me.ucrChkTitle.TabIndex = 11 + ' + 'ucrReceiverElements + ' + Me.ucrReceiverElements.frmParent = Me + Me.ucrReceiverElements.Location = New System.Drawing.Point(263, 101) + Me.ucrReceiverElements.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverElements.Name = "ucrReceiverElements" + Me.ucrReceiverElements.Selector = Nothing + Me.ucrReceiverElements.Size = New System.Drawing.Size(120, 100) + Me.ucrReceiverElements.TabIndex = 4 + ' + 'ucrChkShowNonMissing + ' + Me.ucrChkShowNonMissing.Checked = False + Me.ucrChkShowNonMissing.Location = New System.Drawing.Point(263, 270) + Me.ucrChkShowNonMissing.Name = "ucrChkShowNonMissing" + Me.ucrChkShowNonMissing.Size = New System.Drawing.Size(151, 20) + Me.ucrChkShowNonMissing.TabIndex = 10 + Me.ucrChkShowNonMissing.Visible = False ' 'ucrSaveGraph ' - Me.ucrSaveGraph.Location = New System.Drawing.Point(12, 253) + Me.ucrSaveGraph.Location = New System.Drawing.Point(10, 322) Me.ucrSaveGraph.Name = "ucrSaveGraph" - Me.ucrSaveGraph.Size = New System.Drawing.Size(277, 24) - Me.ucrSaveGraph.TabIndex = 33 + Me.ucrSaveGraph.Size = New System.Drawing.Size(283, 24) + Me.ucrSaveGraph.TabIndex = 13 ' 'ucrChkFlipCoordinates ' Me.ucrChkFlipCoordinates.Checked = False - Me.ucrChkFlipCoordinates.Location = New System.Drawing.Point(292, 263) + Me.ucrChkFlipCoordinates.Location = New System.Drawing.Point(263, 244) Me.ucrChkFlipCoordinates.Name = "ucrChkFlipCoordinates" - Me.ucrChkFlipCoordinates.Size = New System.Drawing.Size(100, 20) - Me.ucrChkFlipCoordinates.TabIndex = 32 - ' - 'ucrChkAddRecodetoData - ' - Me.ucrChkAddRecodetoData.Checked = False - Me.ucrChkAddRecodetoData.Location = New System.Drawing.Point(292, 237) - Me.ucrChkAddRecodetoData.Name = "ucrChkAddRecodetoData" - Me.ucrChkAddRecodetoData.Size = New System.Drawing.Size(100, 20) - Me.ucrChkAddRecodetoData.TabIndex = 31 - ' - 'ucrNudThreashold - ' - Me.ucrNudThreashold.DecimalPlaces = New Decimal(New Integer() {0, 0, 0, 0}) - Me.ucrNudThreashold.Increment = New Decimal(New Integer() {1, 0, 0, 0}) - Me.ucrNudThreashold.Location = New System.Drawing.Point(362, 165) - Me.ucrNudThreashold.Maximum = New Decimal(New Integer() {100, 0, 0, 0}) - Me.ucrNudThreashold.Minimum = New Decimal(New Integer() {0, 0, 0, 0}) - Me.ucrNudThreashold.Name = "ucrNudThreashold" - Me.ucrNudThreashold.Size = New System.Drawing.Size(50, 20) - Me.ucrNudThreashold.TabIndex = 30 - Me.ucrNudThreashold.Value = New Decimal(New Integer() {0, 0, 0, 0}) - ' - 'ucrFacetsReceiver - ' - Me.ucrFacetsReceiver.frmParent = Me - Me.ucrFacetsReceiver.Location = New System.Drawing.Point(292, 204) - Me.ucrFacetsReceiver.Margin = New System.Windows.Forms.Padding(0) - Me.ucrFacetsReceiver.Name = "ucrFacetsReceiver" - Me.ucrFacetsReceiver.Selector = Nothing - Me.ucrFacetsReceiver.Size = New System.Drawing.Size(120, 20) - Me.ucrFacetsReceiver.TabIndex = 28 - ' - 'ucrColourReceiver - ' - Me.ucrColourReceiver.frmParent = Me - Me.ucrColourReceiver.Location = New System.Drawing.Point(292, 135) - Me.ucrColourReceiver.Margin = New System.Windows.Forms.Padding(0) - Me.ucrColourReceiver.Name = "ucrColourReceiver" - Me.ucrColourReceiver.Selector = Nothing - Me.ucrColourReceiver.Size = New System.Drawing.Size(120, 20) - Me.ucrColourReceiver.TabIndex = 18 - ' - 'ucrDayOfYearReceiver - ' - Me.ucrDayOfYearReceiver.frmParent = Me - Me.ucrDayOfYearReceiver.Location = New System.Drawing.Point(292, 82) - Me.ucrDayOfYearReceiver.Margin = New System.Windows.Forms.Padding(0) - Me.ucrDayOfYearReceiver.Name = "ucrDayOfYearReceiver" - Me.ucrDayOfYearReceiver.Selector = Nothing - Me.ucrDayOfYearReceiver.Size = New System.Drawing.Size(120, 20) - Me.ucrDayOfYearReceiver.TabIndex = 17 - ' - 'ucrYearReceiver - ' - Me.ucrYearReceiver.frmParent = Me - Me.ucrYearReceiver.Location = New System.Drawing.Point(292, 32) - Me.ucrYearReceiver.Margin = New System.Windows.Forms.Padding(0) - Me.ucrYearReceiver.Name = "ucrYearReceiver" - Me.ucrYearReceiver.Selector = Nothing - Me.ucrYearReceiver.Size = New System.Drawing.Size(120, 20) - Me.ucrYearReceiver.TabIndex = 15 + Me.ucrChkFlipCoordinates.Size = New System.Drawing.Size(151, 20) + Me.ucrChkFlipCoordinates.TabIndex = 9 + ' + 'ucrReceiverStation + ' + Me.ucrReceiverStation.frmParent = Me + Me.ucrReceiverStation.Location = New System.Drawing.Point(263, 219) + Me.ucrReceiverStation.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverStation.Name = "ucrReceiverStation" + Me.ucrReceiverStation.Selector = Nothing + Me.ucrReceiverStation.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverStation.TabIndex = 6 ' 'ucrInventoryPlotSelector ' Me.ucrInventoryPlotSelector.bShowHiddenColumns = False Me.ucrInventoryPlotSelector.bUseCurrentFilter = True - Me.ucrInventoryPlotSelector.Location = New System.Drawing.Point(9, 9) + Me.ucrInventoryPlotSelector.Location = New System.Drawing.Point(10, 10) Me.ucrInventoryPlotSelector.Margin = New System.Windows.Forms.Padding(0) Me.ucrInventoryPlotSelector.Name = "ucrInventoryPlotSelector" Me.ucrInventoryPlotSelector.Size = New System.Drawing.Size(210, 180) - Me.ucrInventoryPlotSelector.TabIndex = 13 + Me.ucrInventoryPlotSelector.TabIndex = 0 ' 'ucrBase ' - Me.ucrBase.Location = New System.Drawing.Point(9, 283) + Me.ucrBase.Location = New System.Drawing.Point(10, 352) Me.ucrBase.Name = "ucrBase" Me.ucrBase.Size = New System.Drawing.Size(410, 53) - Me.ucrBase.TabIndex = 12 + Me.ucrBase.TabIndex = 14 ' 'dlgInventoryPlot ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(431, 337) + Me.ClientSize = New System.Drawing.Size(417, 413) + Me.Controls.Add(Me.lblElement) + Me.Controls.Add(Me.ucrReceiverDate) + Me.Controls.Add(Me.ucrInputTitle) + Me.Controls.Add(Me.ucrChkTitle) + Me.Controls.Add(Me.cmdInventoryPlotOptions) + Me.Controls.Add(Me.lblDate) + Me.Controls.Add(Me.ucrReceiverElements) + Me.Controls.Add(Me.ucrChkShowNonMissing) Me.Controls.Add(Me.ucrSaveGraph) Me.Controls.Add(Me.ucrChkFlipCoordinates) - Me.Controls.Add(Me.ucrChkAddRecodetoData) - Me.Controls.Add(Me.ucrNudThreashold) - Me.Controls.Add(Me.lblFacet) - Me.Controls.Add(Me.ucrFacetsReceiver) - Me.Controls.Add(Me.lblThreshold) Me.Controls.Add(Me.cmdOptions) - Me.Controls.Add(Me.lblDoY) - Me.Controls.Add(Me.lblColourBand) Me.Controls.Add(Me.lblDayOfyear) - Me.Controls.Add(Me.ucrColourReceiver) - Me.Controls.Add(Me.ucrDayOfYearReceiver) - Me.Controls.Add(Me.lblYear) - Me.Controls.Add(Me.ucrYearReceiver) + Me.Controls.Add(Me.lblStation) + Me.Controls.Add(Me.ucrReceiverStation) Me.Controls.Add(Me.ucrInventoryPlotSelector) Me.Controls.Add(Me.ucrBase) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow @@ -231,19 +218,18 @@ Partial Class dlgInventoryPlot End Sub Friend WithEvents ucrBase As ucrButtons Friend WithEvents ucrInventoryPlotSelector As ucrSelectorByDataFrameAddRemove - Friend WithEvents ucrYearReceiver As ucrReceiverSingle - Friend WithEvents lblYear As Label - Friend WithEvents ucrDayOfYearReceiver As ucrReceiverSingle - Friend WithEvents ucrColourReceiver As ucrReceiverSingle Friend WithEvents lblDayOfyear As Label - Friend WithEvents lblColourBand As Label - Friend WithEvents lblDoY As Label Friend WithEvents cmdOptions As Button - Friend WithEvents lblThreshold As Label - Friend WithEvents ucrFacetsReceiver As ucrReceiverSingle - Friend WithEvents lblFacet As Label Friend WithEvents ucrChkFlipCoordinates As ucrCheck - Friend WithEvents ucrChkAddRecodetoData As ucrCheck - Friend WithEvents ucrNudThreashold As ucrNud Friend WithEvents ucrSaveGraph As ucrSave + Friend WithEvents ucrChkShowNonMissing As ucrCheck + Friend WithEvents lblDate As Label + Friend WithEvents ucrReceiverElements As ucrReceiverMultiple + Friend WithEvents lblStation As Label + Friend WithEvents ucrReceiverStation As ucrReceiverSingle + Friend WithEvents cmdInventoryPlotOptions As Button + Friend WithEvents ucrInputTitle As ucrInputTextBox + Friend WithEvents ucrChkTitle As ucrCheck + Friend WithEvents ucrReceiverDate As ucrReceiverSingle + Friend WithEvents lblElement As Label End Class diff --git a/instat/dlgInventoryPlot.vb b/instat/dlgInventoryPlot.vb index fc019893331..7678893c5c4 100644 --- a/instat/dlgInventoryPlot.vb +++ b/instat/dlgInventoryPlot.vb @@ -16,6 +16,7 @@ Imports instat.Translations Public Class dlgInventoryPlot + Private bFirstLoad As Boolean = True Private bReset As Boolean = True @@ -37,43 +38,38 @@ Public Class dlgInventoryPlot ucrBase.iHelpTopicID = 359 ucrBase.clsRsyntax.iCallType = 3 - ucrYearReceiver.Selector = ucrInventoryPlotSelector - ucrColourReceiver.Selector = ucrInventoryPlotSelector - ucrDayOfYearReceiver.Selector = ucrInventoryPlotSelector - ucrFacetsReceiver.Selector = ucrInventoryPlotSelector - - ucrYearReceiver.Selector = ucrInventoryPlotSelector - ucrYearReceiver.SetMeAsReceiver() - ucrYearReceiver.SetParameter(New RParameter("year")) - ucrYearReceiver.SetParameterIsString() + ucrChkTitle.AddToLinkedControls(ucrInputTitle, objValues:={True}, bNewLinkedHideIfParameterMissing:=True, bNewLinkedAddRemoveParameter:=True) - ucrColourReceiver.Selector = ucrInventoryPlotSelector - ucrColourReceiver.SetIncludedDataTypes({"numeric"}) - ucrColourReceiver.SetParameter(New RParameter("col_name")) - ucrColourReceiver.SetParameterIsString() + ucrReceiverElements.Selector = ucrInventoryPlotSelector + ucrReceiverElements.SetIncludedDataTypes({"numeric"}) + ucrReceiverElements.SetParameter(New RParameter("elements_col", 2)) + ucrReceiverElements.SetParameterIsString() - ucrDayOfYearReceiver.Selector = ucrInventoryPlotSelector - ucrDayOfYearReceiver.SetIncludedDataTypes({"numeric"}) - ucrDayOfYearReceiver.SetParameter(New RParameter("doy")) - ucrDayOfYearReceiver.SetParameterIsString() + ucrReceiverStation.Selector = ucrInventoryPlotSelector + ucrReceiverStation.SetIncludedDataTypes({"factor"}) + ucrReceiverStation.SetParameter(New RParameter("station_col", 3)) + ucrReceiverDate.SetClimaticType("station") + ucrReceiverStation.SetParameterIsString() - ucrFacetsReceiver.Selector = ucrInventoryPlotSelector - ucrFacetsReceiver.SetParameter(New RParameter("facets")) - ucrFacetsReceiver.SetParameterIsString() + ucrReceiverDate.Selector = ucrInventoryPlotSelector + ucrReceiverDate.SetParameter(New RParameter("date_col", 1)) + ucrReceiverDate.SetClimaticType("date") + ucrReceiverDate.bAutoFill = True + ucrReceiverDate.SetParameterIsString() ucrInventoryPlotSelector.SetParameter(New RParameter("data_name", 0)) ucrInventoryPlotSelector.SetParameterIsString() - ucrChkAddRecodetoData.SetText("Add Recode to Data") - ucrChkAddRecodetoData.SetParameter(New RParameter("add_to_data")) - ucrChkAddRecodetoData.SetValuesCheckedAndUnchecked("TRUE", "FALSE") - ucrChkAddRecodetoData.SetRDefault("FALSE") - ucrChkFlipCoordinates.SetText("Flip Coordinates") + ucrChkFlipCoordinates.SetParameter(New RParameter("coord_flip", 4)) + ucrChkFlipCoordinates.SetValuesCheckedAndUnchecked("TRUE", "FALSE") + + ucrChkTitle.SetText("Title") + ucrInputTitle.SetParameter(New RParameter("graph_title", 5)) - ucrChkAddRecodetoData.SetParameter(New RParameter("coord_flip")) - ucrChkAddRecodetoData.SetValuesCheckedAndUnchecked("TRUE", "FALSE") - ucrChkAddRecodetoData.SetRDefault("FALSE") + ucrChkShowNonMissing.SetText("Show Non Missing") + ucrChkShowNonMissing.SetParameter(New RParameter("")) + ucrChkShowNonMissing.SetValuesCheckedAndUnchecked("TRUE", "FALSE") ucrSaveGraph.SetPrefix("Inventory") ucrSaveGraph.SetSaveTypeAsGraph() @@ -81,16 +77,10 @@ Public Class dlgInventoryPlot ucrSaveGraph.SetCheckBoxText("Save Graph") ucrSaveGraph.SetIsComboBox() ucrSaveGraph.SetAssignToIfUncheckedValue("last_graph") - - ucrNudThreashold.SetParameter(New RParameter("threshold")) - ucrNudThreashold.Minimum = 0.85 - ucrNudThreashold.Increment = 0.01 - ucrNudThreashold.DecimalPlaces = 2 - ucrNudThreashold.SetRDefault("0.85") End Sub Private Sub TestOkEnabled() - If (Not ucrYearReceiver.IsEmpty AndAlso Not ucrDayOfYearReceiver.IsEmpty AndAlso Not ucrColourReceiver.IsEmpty) AndAlso ucrSaveGraph.IsComplete() Then + If (Not ucrReceiverDate.IsEmpty AndAlso Not ucrReceiverElements.IsEmpty AndAlso ucrSaveGraph.IsComplete) AndAlso (ucrChkTitle.Checked AndAlso Not ucrInputTitle.IsEmpty OrElse ucrChkTitle.Checked = False) Then ucrBase.OKEnabled(True) Else ucrBase.OKEnabled(False) @@ -99,15 +89,17 @@ Public Class dlgInventoryPlot Private Sub SetDefaults() Dim clsDefaultRFunction As New RFunction - ucrInventoryPlotSelector.Reset() ucrSaveGraph.Reset() - ucrYearReceiver.SetMeAsReceiver() + ucrReceiverDate.SetMeAsReceiver() + ucrChkTitle.Checked = False + ucrInputTitle.SetName("") clsDefaultRFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$make_inventory_plot") - clsDefaultRFunction.AddParameter("threshold", "0.85") + clsDefaultRFunction.AddParameter("coord_flip", Chr(34) & "FALSE" & Chr(34)) clsDefaultRFunction.SetAssignTo("last_graph", strTempDataframe:=ucrInventoryPlotSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempGraph:="last_graph") - ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultRFunction.Clone()) + ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultRFunction) + TestOkEnabled() End Sub @@ -124,9 +116,10 @@ Public Class dlgInventoryPlot Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset SetDefaults() SetRCodeForControls(True) + TestOkEnabled() End Sub - Private Sub AllControls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrYearReceiver.ControlContentsChanged, ucrColourReceiver.ControlContentsChanged, ucrDayOfYearReceiver.ControlContentsChanged, ucrSaveGraph.ControlContentsChanged + Private Sub AllControls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrSaveGraph.ControlContentsChanged, ucrReceiverElements.ControlContentsChanged, ucrChkTitle.ControlContentsChanged, ucrInputTitle.ControlContentsChanged, ucrReceiverDate.ControlContentsChanged TestOkEnabled() 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 bd21f911b09..973c1825b31 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -126,10 +126,11 @@ data_object$set("public", "set_data", function(new_data, messages=TRUE, check_na ) data_object$set("public", "set_meta", function(new_meta) { + meta_data_copy <- new_meta self$clear_metadata() - if(!is.list(new_meta)) stop("new_meta must be of type: list") - for(name in names(new_meta)) { - self$append_to_metadata(name, new_meta[[name]]) + if(!is.list(meta_data_copy)) stop("new_meta must be of type: list") + for(name in names(meta_data_copy)) { + self$append_to_metadata(name, meta_data_copy[[name]]) } self$metadata_changed <- TRUE self$append_to_changes(list(Set_property, "meta data")) @@ -1430,7 +1431,7 @@ data_object$set("public", "data_clone", function(include_objects = TRUE, include else new_filters <- list() if(include_calculations) new_calculations <- lapply(private$calculations, function(x) x$data_clone()) else new_calculations <- list() - + ret <- data_object$new(data = private$data, data_name = self$get_metadata(data_name_label), filters = new_filters, objects = new_objects, calculations = new_calculations, keys = private$keys, keep_attributes = include_metadata) if(include_logs) ret$set_changes(private$changes) else ret$set_changes(list()) @@ -1787,7 +1788,7 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr } ) #This method gets a date column and extracts part of the information such as year, month, week, weekday etc(depending on which parameters are set) and creates their respective new column(s) -data_object$set("public","split_date", function(data_name, col_name = "", week = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, year = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, leap_year = FALSE, day_in_year_366 = FALSE, dekade = FALSE, pentad = FALSE) { +data_object$set("public","split_date", function(col_name = "", week = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, year = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, leap_year = FALSE, day_in_year_366 = FALSE, dekade = FALSE, pentad = FALSE) { col_data <- self$get_columns_from_data(col_name, use_current_filter = FALSE) if(!is.Date(col_data)) stop("This column must be a date or time!") if(day) { @@ -1935,26 +1936,65 @@ data_object$set("public","set_climatic_types", function(types) { ) #Method for creating inventory plot -data_object$set("public","make_inventory_plot", function(year, doy, col_name, add_to_data = FALSE, coord_flip = FALSE, threshold, facets) { - curr_data <- self$get_data_frame() - col_data <- self$get_columns_from_data(col_name) - if(!is.numeric(col_data)) stop("The rainfall column should be numeric") - recode <- ifelse(is.na(col_data), "missing", ifelse(col_data>threshold, "rain", "dry")) - recode <- as.factor(recode) - new_col <- next_default_item(prefix = "recode", existing_names = self$get_column_names(), include_index = FALSE) - curr_data[[new_col]] <- recode - if(add_to_data) { - self$add_columns_to_data(col_name = new_col, col_data = recode) +data_object$set("public","make_inventory_plot", function(date_col, station_col = c(), elements_cols, add_to_data = FALSE, coord_flip = FALSE, graph_title = "Inventory plot") { + if(!self$get_metadata(is_climatic_label))stop("Define data as climatic.") + if(!is.Date(self$get_columns_from_data(date_col))) stop(paste(date_col, " must be of type date/time."))#this will not work!!! + if(missing(date_col)||missing(elements_cols))stop("Date and elements columns must be specified.") + if(!all(elements_cols %in% self$get_column_names())) { + stop("Not all elements columns found in the data") } - - g <- ggplot(data = curr_data, mapping = aes_(x = as.name(year), y = as.name(doy), colour = as.name(new_col), group = as.name(year))) + geom_point() + xlab(year) + ylab(col_name) + labs(color="Recode") - if(!missing(facets)) { - g <- g + facet_wrap(as.name(facets)) + #add year and doy columns if missing in data + if(is.null(self$get_climatic_column_name(year_label))){ + self$split_date(col_name = date_col, year = TRUE) + self$set_climatic_types(types = c(year = "year")) #calling year column by name is just a temporary fix. + } + if(is.null(self$get_climatic_column_name(doy_label))){ + self$split_date(col_name = date_col, day_in_year = TRUE) + self$set_climatic_types(types = c(doy = "day_in_year")) + } + year_col_name = self$get_climatic_column_name(year_label) + doy_col_name = self$get_climatic_column_name(doy_label) + + curr_data <- self$get_data_frame() + #ggplot fails to get column names hence the need to rename + colnames(curr_data)[colnames(curr_data) == year_col_name] <- "year_column" + colnames(curr_data)[colnames(curr_data) == doy_col_name] <- "doy_column" + if(length(elements_cols)!=1){ + if(!is.null(station_col)){ + col_data <- self$get_data_frame(stack_data = TRUE, measure.vars = elements_cols, id.vars=c(date_col, station_col, year_col_name, doy_col_name)) + } + else{ + col_data <- self$get_data_frame(stack_data = TRUE, measure.vars = elements_cols, id.vars=c(date_col, year_col_name, doy_col_name)) + } + colnames(col_data)[colnames(col_data) == year_col_name] <- "year_column" + colnames(col_data)[colnames(col_data) == doy_col_name] <- "doy_column" + recode <- ifelse(is.na(col_data$value), "missing", "present") + recode <- as.factor(recode) + new_col <- next_default_item(prefix = "recode", existing_names = names(col_data), include_index = FALSE) + col_data[[new_col]] <- recode + g <- ggplot(data = col_data, mapping = aes(x = year_column, y = doy_column , colour = recode, group = year_column)) + geom_point() + xlab("Year") + ylab("DOY") + labs(color="Recode") + if(!is.null(station_col)){ + g <- g + facet_wrap(as.formula(paste0(as.name(station_col),"~ variable"))) + } + else{ + g <- g + facet_wrap(~variable) + } + } + else{ + col_data <- self$get_columns_from_data(elements_cols) + recode <- ifelse(is.na(col_data),"missing", "present") + recode <- as.factor(recode) + new_col <- next_default_item(prefix = "recode", existing_names = self$get_column_names(), include_index = FALSE) + curr_data[[new_col]] <- recode + g <- ggplot(data = curr_data, mapping = aes(x = year_column, y = doy_column , colour = recode, group = year_column)) + geom_point() + xlab("Year") + ylab("DOY") + labs(color="Recode") + if(!is.null(station_col)){ + g <- g + facet_wrap(as.name(station_col)) + } } if(coord_flip) { g <- g + coord_flip() } - return(g) + return(g+ggtitle(graph_title) + theme(plot.title = element_text(hjust = 0.5))) } ) @@ -2152,7 +2192,7 @@ corruption_output_label = "Is_Corruption_Output" corruption_red_flag_label = "Is_Corruption_Red_Flag" # Data frame metadata for corruption dataframes -corruption_data_label = "Corruption_Data" +corruption_data_label = "Is_Corruption_Data" corruption_contract_level_label = "Contract Level" corruption_country_level_label = "Country Level" @@ -2188,7 +2228,7 @@ data_object$set("public","define_red_flags", function(red_flags = c()) { ) instat_object$set("public","define_as_corruption", function(data_name, primary_types = c(), calculated_types = c(), country_data_name, country_types, auto_generate = TRUE) { - self$append_to_dataframe_metadata(data_name, corruption_data_label, corruption_contract_level_label) + self$append_to_dataframe_metadata(data_name, corruption_data_label, TRUE) self$get_data_objects(data_name)$set_corruption_types(primary_types, calculated_types, auto_generate) if(!missing(country_data_name)) { self$define_as_corruption_country_level_data(data_name = country_data_name, contract_level_data_name = data_name, types = country_types, auto_generate = auto_generate) @@ -2197,10 +2237,10 @@ instat_object$set("public","define_as_corruption", function(data_name, primary_t ) instat_object$set("public","define_as_corruption_country_level_data", function(data_name, contract_level_data_name, types = c(), auto_generate = TRUE) { - self$append_to_dataframe_metadata(data_name, corruption_data_label, corruption_country_level_label) + #self$append_to_dataframe_metadata(data_name, corruption_data_label, corruption_country_level_label) self$get_data_objects(data_name)$define_as_corruption_country_level_data(types, auto_generate) - contract_level_country_name <- self$get_corruption_column_name(data_name, corruption_country_label) - country_level_country_name <- self$get_corruption_column_name(contract_level_data_name, corruption_country_label) + contract_level_country_name <- self$get_corruption_column_name(contract_level_data_name, corruption_country_label) + country_level_country_name <- self$get_corruption_column_name(data_name, corruption_country_label) if(contract_level_country_name == "" || country_level_country_name == "") stop("country column must be defined in the contract level data and country level data.") link_pairs <- country_level_country_name names(link_pairs) <- contract_level_country_name @@ -2214,7 +2254,7 @@ data_object$set("public","define_as_corruption_country_level_data", function(typ ) data_object$set("public","is_corruption_type_present", function(type) { - return(self$is_metadata(corruption_data_label) && !is.na(self$get_metadata(corruption_data_label)) && self$is_variables_metadata(corruption_type_label) && (type %in% self$get_variables_metadata(property = corruption_type_label))) + return(self$is_metadata(corruption_data_label) && !is.na(self$get_metadata(corruption_data_label)) && self$get_metadata(corruption_data_label) && self$is_variables_metadata(corruption_type_label) && (type %in% self$get_variables_metadata(property = corruption_type_label))) } ) @@ -2745,4 +2785,17 @@ data_object$set("public","standard_country_names", function(country_columns = c( } } } +) + +data_object$set("public", "get_climatic_column_name", function(col_name) { + if(!self$get_metadata(is_climatic_label))stop("Define data as climatic.") + if(col_name %in% self$get_variables_metadata()$Climatic_Type){ + new_data = subset(self$get_variables_metadata(), Climatic_Type==col_name, select = Name) + return(as.character(new_data)) + } + else{ + warning(paste(col_name, " column cannot be found in the data.")) + return() + } +} ) \ No newline at end of file diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 872aaf45857..43fc4813e98 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -1074,8 +1074,8 @@ instat_object$set("public", "import_SST", function(dataset, data_from = 5, data_ } ) -instat_object$set("public","make_inventory_plot", function(data_name,col_name = "", year , doy, add_to_data = FALSE, coord_flip = FALSE, threshold, facets) { - self$get_data_objects(data_name)$make_inventory_plot(col_name = col_name , year = year, doy =doy,add_to_data = add_to_data, coord_flip = coord_flip, threshold = threshold, facets = facets) +instat_object$set("public","make_inventory_plot", function(data_name, date_col, station_col = c(), elements_cols, add_to_data = FALSE, coord_flip = FALSE, graph_title = "Inventory plot") { + self$get_data_objects(data_name)$make_inventory_plot(date_col = date_col , station_col = station_col, elements_cols =elements_cols, add_to_data = add_to_data, coord_flip = coord_flip, graph_title = graph_title) } ) @@ -1183,9 +1183,7 @@ instat_object$set("public", "is_metadata", function(data_name, str) { ) instat_object$set("public", "get_climatic_column_name", function(data_name, col_name) { - new_data = subset(InstatDataObject$get_variables_metadata(data_name), Climatic_Type==col_name, select = Name) - if(!nrow(new_data==1))stop(paste(col_name, " column cannot be found in the data.")) - return(as.character(new_data)) + self$get_data_objects(data_name)$get_climatic_column_name(col_name = col_name) } ) @@ -1197,7 +1195,7 @@ instat_object$set("public", "merge_data", function(data_name, new_data, by = NUL instat_object$set("public", "get_corruption_data_names", function() { corruption_names <- c() for(curr_name in self$get_data_names()) { - if(self$get_data_objects(curr_name)$is_metadata(is_corruption_label) && self$get_data_objects(curr_name)$get_metadata(is_corruption_label)) { + if(self$get_data_objects(curr_name)$is_metadata(corruption_data_label) && self$get_data_objects(curr_name)$get_metadata(corruption_data_label)) { corruption_names <- c(corruption_names, curr_name) } } diff --git a/instat/ucrButtons.vb b/instat/ucrButtons.vb index 1dd3ee209dc..db4113feed0 100644 --- a/instat/ucrButtons.vb +++ b/instat/ucrButtons.vb @@ -71,7 +71,7 @@ Public Class ucrButtons bToBeAssigned = clsRsyntax.GetbToBeAssigned() strAssignTo = clsRsyntax.GetstrAssignTo() 'Also need to be getting strAssignToColumn, strAssignToDataFrame etc. maybe one method to get all as a list - frmMain.clsRLink.RunScript(clsRsyntax.GetScript(), clsRsyntax.iCallType, strComment:=strComments) + frmMain.clsRLink.RunScript(clsRsyntax.GetScript(), clsRsyntax.iCallType, bHtmlOutput:=clsRsyntax.bHTMLOutput, strComment:=strComments) 'This clears the script after it has been run, but leave the function and parameters in the base function 'so that it can be run exactly the same when reopened.