From f42c4a218c1b9093156a85529590be150f7c7d67 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Sun, 13 Nov 2016 00:00:48 +0300 Subject: [PATCH 01/27] proposal for adding options on GeneralForGraphics --- instat/dlgGeneralForGraphics.Designer.vb | 13 ++++++++++++ instat/dlgGeneralForGraphics.vb | 25 ++++++++++++++++++++++++ instat/sdgPlots.vb | 7 +++++++ instat/ucrAdditionalLayers.vb | 6 +++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/instat/dlgGeneralForGraphics.Designer.vb b/instat/dlgGeneralForGraphics.Designer.vb index a4bba9e7399..6cdc6909633 100644 --- a/instat/dlgGeneralForGraphics.Designer.vb +++ b/instat/dlgGeneralForGraphics.Designer.vb @@ -25,6 +25,7 @@ Partial Class dlgGeneralForGraphics Me.ucrAdditionalLayers = New instat.ucrAdditionalLayers() Me.ucrSaveGraph = New instat.ucrSaveGraph() Me.ucrBase = New instat.ucrButtons() + Me.cmdOptions = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'ucrAdditionalLayers @@ -48,11 +49,22 @@ Partial Class dlgGeneralForGraphics Me.ucrBase.Size = New System.Drawing.Size(410, 53) Me.ucrBase.TabIndex = 0 ' + 'cmdOptions + ' + Me.cmdOptions.Location = New System.Drawing.Point(267, 45) + Me.cmdOptions.Name = "cmdOptions" + Me.cmdOptions.Size = New System.Drawing.Size(120, 25) + Me.cmdOptions.TabIndex = 9 + Me.cmdOptions.Tag = "Options" + Me.cmdOptions.Text = "Plot Options" + Me.cmdOptions.UseVisualStyleBackColor = True + ' 'dlgGeneralForGraphics ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(422, 303) + Me.Controls.Add(Me.cmdOptions) Me.Controls.Add(Me.ucrAdditionalLayers) Me.Controls.Add(Me.ucrSaveGraph) Me.Controls.Add(Me.ucrBase) @@ -70,4 +82,5 @@ Partial Class dlgGeneralForGraphics Friend WithEvents ucrBase As ucrButtons Friend WithEvents ucrSaveGraph As ucrSaveGraph Friend WithEvents ucrAdditionalLayers As ucrAdditionalLayers + Friend WithEvents cmdOptions As Button End Class diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index fc53228b617..60ded6913f2 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -51,6 +51,8 @@ Public Class dlgGeneralForGraphics ucrAdditionalLayers.SetRSyntax(ucrBase.clsRsyntax) ucrAdditionalLayers.SetGGplotFunction(clsRggplotFunction) ucrAdditionalLayers.SetAesFunction(clsGgplotAesFunction) + sdgPlots.SetRSyntax(ucrBase.clsRsyntax) 'Warning/question: sdgPlots is treated as sort of a ucr of the main. But then there is only one instance for all dialogues. How comes this doesn't causes problems ? The RSyntax of differetn dialogues should be linked through here ? Why does this not actually happen ? + 'Warning: in some specific plots, GgplotFunction is set here as well. In others not... ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False 'By default, we want to put in the script the output of our Base R-command (in this case the ...+...+...) even when it has been assigned to some object (in which case we want the name of that object in the script so that it's called when the script is run). 'For example, when a graph is saved, it is assigned to it's place in an R-instat object. If we had set bExcludeAssignedFunctionOutput to True, then we would never print the graph when running the script. @@ -70,6 +72,9 @@ Public Class dlgGeneralForGraphics If ucrBase.clsRsyntax.clsBaseOperator IsNot Nothing Then ucrBase.clsRsyntax.clsBaseOperator.RemoveAllAdditionalParameters() End If + sdgPlots.Reset() + 'Warning/to be discussed: sdgPlots doesn't work like sdgLayerOptions. Information actually stays on the dialogue, as it cannot be editted on the general for graphics (yet) I think that sdgPlots should work like LayerOptions and be filled in at load, thanks to a setup function and setsettings sub. + OptionsEnabled() TestOKEnabled() End Sub @@ -77,6 +82,13 @@ Public Class dlgGeneralForGraphics End Sub + Public Sub OptionsEnabled() 'probably not necessary... + If ucrAdditionalLayers.lstLayers.Items.Count < 1 Then + cmdOptions.Enabled = False + Else + cmdOptions.Enabled = True + End If + End Sub Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset SetDefaults() End Sub @@ -168,4 +180,17 @@ Public Class dlgGeneralForGraphics ucrBase.clsRsyntax.SetAssignTo("last_graph", strTempDataframe:=sdgLayerOptions.ucrGeomWithAes.UcrSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempGraph:="last_graph") End If End Sub + + Private Sub SetUpPlotOptions() + 'Note: in specific plots, this is in initialise dialog. Also, in set defaults, reset sdgPlots is called. sdgPlots is considered as a ucr on the main. What if we try sdgPlots to behave like sdgLayerOptions, using RSyntax. I think would be safer... + sdgPlots.SetRSyntax(ucrBase.clsRsyntax) + sdgPlots.SetGgplotFunction(clsRggplotFunction) + 'Warning there is no dataframe on dlgGenerelForGraphics !! how do we setup the dataframe for facets ? Could we add facets on the main dlg, there we need to chose which dataframe to chose,then that one can be sent to plotOptions... I think we should actually do this after rethinking the link between sdgPlots and others... + End Sub + Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click + sdgPlots.DisableLayersTab() + sdgPlots.SetDataFrame(strNewDataFrame:=ucrAdditionalLayers.strGlobalDataFrame) 'Warning: temporary solution... + sdgPlots.ShowDialog() + sdgPlots.EnableLayersTab() + End Sub End Class \ No newline at end of file diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index 2dbec6dab43..75336483283 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -46,6 +46,13 @@ Public Class sdgPlots autoTranslate(Me) End Sub + Public Sub DisableLayersTab() + tabLayers.Enabled = False + End Sub + + Public Sub EnableLayersTab() + tabLayers.Enabled = True + End Sub Public Sub SetDefaults() TitleDefaults() diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index 855903ef8d5..8ccc27c5f7a 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -24,7 +24,7 @@ Public Class ucrAdditionalLayers Public bFirstLoad As Boolean = True Public lstLayerComplete As New List(Of Boolean) Public iLayerIndex As Integer - Private strGlobalDataFrame As String + Public strGlobalDataFrame As String Public bSetGlobalIsDefault As Boolean 'Deciding if the first layer needs to be used for global aesthetics. 'Question to be discussed: What is this variable about again ? it is linked with sdgPlots.bAdditionalLayersSetGlobal in sdgPLots.bLayersDefaultIsGolobal. @@ -116,6 +116,7 @@ Public Class ucrAdditionalLayers clsRSyntax.SetOperatorParameter(False, strParameterName:=strLayerName, clsRFunc:=sdgLayerOptions.clsGeomFunction.Clone()) dlgGeneralForGraphics.TestOKEnabled() + dlgGeneralForGraphics.OptionsEnabled() End Sub Private Sub cmdDelete_Click(sender As Object, e As EventArgs) Handles cmdDelete.Click @@ -123,6 +124,9 @@ Public Class ucrAdditionalLayers clsRSyntax.RemoveOperatorParameter(lstLayers.SelectedItems(0).Text) lstLayerComplete.RemoveAt(lstLayers.SelectedIndices(0)) lstLayers.Items.Remove(lstLayers.SelectedItems(0)) + + dlgGeneralForGraphics.TestOKEnabled() + dlgGeneralForGraphics.OptionsEnabled() End If End Sub From 18be435de542a8ec3e22233c4ed85759630aa37a Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Sun, 13 Nov 2016 00:38:13 +0300 Subject: [PATCH 02/27] corrections of previous nonsense --- instat/dlgGeneralForGraphics.vb | 16 +--------------- instat/ucrAdditionalLayers.vb | 4 +--- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index 60ded6913f2..d86f96cad56 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -74,7 +74,6 @@ Public Class dlgGeneralForGraphics End If sdgPlots.Reset() 'Warning/to be discussed: sdgPlots doesn't work like sdgLayerOptions. Information actually stays on the dialogue, as it cannot be editted on the general for graphics (yet) I think that sdgPlots should work like LayerOptions and be filled in at load, thanks to a setup function and setsettings sub. - OptionsEnabled() TestOKEnabled() End Sub @@ -82,13 +81,6 @@ Public Class dlgGeneralForGraphics End Sub - Public Sub OptionsEnabled() 'probably not necessary... - If ucrAdditionalLayers.lstLayers.Items.Count < 1 Then - cmdOptions.Enabled = False - Else - cmdOptions.Enabled = True - End If - End Sub Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset SetDefaults() End Sub @@ -181,15 +173,9 @@ Public Class dlgGeneralForGraphics End If End Sub - Private Sub SetUpPlotOptions() - 'Note: in specific plots, this is in initialise dialog. Also, in set defaults, reset sdgPlots is called. sdgPlots is considered as a ucr on the main. What if we try sdgPlots to behave like sdgLayerOptions, using RSyntax. I think would be safer... - sdgPlots.SetRSyntax(ucrBase.clsRsyntax) - sdgPlots.SetGgplotFunction(clsRggplotFunction) - 'Warning there is no dataframe on dlgGenerelForGraphics !! how do we setup the dataframe for facets ? Could we add facets on the main dlg, there we need to chose which dataframe to chose,then that one can be sent to plotOptions... I think we should actually do this after rethinking the link between sdgPlots and others... - End Sub + 'Warning: never setup sdgPlots.SetGgplotFunction(clsRggplotFunction) ? same in scattered plot which works well. In dotplot, adds it in initialise, but then additional layers don't work ... Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click sdgPlots.DisableLayersTab() - sdgPlots.SetDataFrame(strNewDataFrame:=ucrAdditionalLayers.strGlobalDataFrame) 'Warning: temporary solution... sdgPlots.ShowDialog() sdgPlots.EnableLayersTab() End Sub diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index 8ccc27c5f7a..abda7e2be3c 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -24,7 +24,7 @@ Public Class ucrAdditionalLayers Public bFirstLoad As Boolean = True Public lstLayerComplete As New List(Of Boolean) Public iLayerIndex As Integer - Public strGlobalDataFrame As String + Private strGlobalDataFrame As String Public bSetGlobalIsDefault As Boolean 'Deciding if the first layer needs to be used for global aesthetics. 'Question to be discussed: What is this variable about again ? it is linked with sdgPlots.bAdditionalLayersSetGlobal in sdgPLots.bLayersDefaultIsGolobal. @@ -116,7 +116,6 @@ Public Class ucrAdditionalLayers clsRSyntax.SetOperatorParameter(False, strParameterName:=strLayerName, clsRFunc:=sdgLayerOptions.clsGeomFunction.Clone()) dlgGeneralForGraphics.TestOKEnabled() - dlgGeneralForGraphics.OptionsEnabled() End Sub Private Sub cmdDelete_Click(sender As Object, e As EventArgs) Handles cmdDelete.Click @@ -126,7 +125,6 @@ Public Class ucrAdditionalLayers lstLayers.Items.Remove(lstLayers.SelectedItems(0)) dlgGeneralForGraphics.TestOKEnabled() - dlgGeneralForGraphics.OptionsEnabled() End If End Sub From aefd58f3dfd5ab2256531738a1fed43e3c3dd6a1 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Mon, 14 Nov 2016 10:20:33 +0300 Subject: [PATCH 03/27] Adding split_Date Method --- instat/static/InstatObject/R/data_object_R6.R | 32 +++++++++++++++++-- .../static/InstatObject/R/instat_object_R6.R | 5 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index f366b8ece37..06ae59469df 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1652,14 +1652,40 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = } ) -data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts) { +data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, matrix = NA) { if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") #checks needed on contrasts before assigning - if(!(new_contrasts %in% c("contr.treatment","contr.helmert","contr.poly","contr.sum"))){ + if(!(new_contrasts %in% c("contr.treatment","contr.helmert","contr.poly","contr.sum", "user_defined"))){ stop(new_contrasts, " is not a valid contrast name") + } else if (!is.character(new_contrasts)) { + stop("New column name must be of type: character") + } + + contrasts(private$data[[col_name]]) <- new_contrasts +} +) +data_object$set("public","Split_Date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { + col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) + if(!(is.Date(col_data)))(stop("This column must be a date!")) + + + if(week==TRUE){ + week=week(col_data) + self$add_columns_to_data(col_name = "week", col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) + } + if(month==TRUE){ + month=month(col_data) + self$add_columns_to_data(col_name = "month", col_data = month,use_col_name_as_prefix = use_col_name_as_prefix) + } + if(year==TRUE){ + year=year(col_data) + self$add_columns_to_data(col_name = "year", col_data = year, use_col_name_as_prefix = use_col_name_as_prefix) + } + if(day==TRUE){ + day=day(col_data) + self$add_columns_to_data(col_name = "day", col_data = day, use_col_name_as_prefix = use_col_name_as_prefix) } - contrasts(private$data[[col_name]]) <- new_contrasts } ) \ 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 446b50f8af8..f0c78d2e504 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -1030,4 +1030,9 @@ instat_object$set("public","create_factor_data_frame", function(data_name, facto self$add_link(from_data_frame = data_name, to_data_frame = factor_data_frame_name, link_pairs = factor, type = keyed_link_label) } } +) + +instat_object$set("public","Split_Date", function(data_name, col_names="", year=FALSE, month=FALSE, day=FALSE, week=FALSE,use_col_name_as_prefix = TRUE ) { + self$get_data_objects(data_name)$Split_Date(year = year,col_names=col_names, month = month, day = day, week=week,use_col_name_as_prefix = use_col_name_as_prefix ) +} ) \ No newline at end of file From 083eb3b4f8efa321145963b2f98543b723bb097d Mon Sep 17 00:00:00 2001 From: Lunalo Date: Mon, 14 Nov 2016 12:37:46 +0300 Subject: [PATCH 04/27] Editing contrast method --- instat/static/InstatObject/R/data_object_R6.R | 16 ++++++++++++++-- instat/static/InstatObject/R/instat_object_R6.R | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 06ae59469df..71f03489f20 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1652,16 +1652,28 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = } ) -data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, matrix = NA) { +data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, contr_vector = NA) { if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") #checks needed on contrasts before assigning - + factor_col=self$get_columns_from_data(col_name) if(!(new_contrasts %in% c("contr.treatment","contr.helmert","contr.poly","contr.sum", "user_defined"))){ stop(new_contrasts, " is not a valid contrast name") } else if (!is.character(new_contrasts)) { stop("New column name must be of type: character") } + + if((new_contrast=="user_defined")){ + if (!is.na(contr_vector)){ + contr_col=nlevels(factor_col)-1 + contr_row=nlevels(factor_col) + if (length(contr_vector)==contr_col*contr_col){ + contr_matrix<-as.matrix(contr_vector, contr_row, contr_col) + } else { + stop("Specify correct number of rows and columns in the defined matrix") + } + } + } contrasts(private$data[[col_name]]) <- new_contrasts } diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index f0c78d2e504..a7f25b7563a 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -987,8 +987,8 @@ instat_object$set("public","make_date_yeardoy", function(data_name, year, doy, y } ) -instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts) { - self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts) +instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts, contr_vector = NA) { + self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, contr_vector =contr_vector) } ) From 16a7f7b525c20525eb4aa34d99e39c68e53427d0 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Mon, 14 Nov 2016 12:39:37 +0300 Subject: [PATCH 05/27] setup sdgPLots when called in GeneralForGraphics temporary version + few minor changes in ucrAdditionalLayers --- instat/dlgGeneralForGraphics.vb | 13 ++++++++++--- instat/ucrAdditionalLayers.vb | 8 +++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index d86f96cad56..64e75102828 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -43,7 +43,7 @@ Public Class dlgGeneralForGraphics clsRggplotFunction.SetRCommand("ggplot") clsGgplotAesFunction.SetRCommand("aes") ucrBase.clsRsyntax.SetOperatorParameter(True, clsRFunc:=clsRggplotFunction) - 'True for "we are setting the first parameter, on the left of +. + 'True for "we are setting the first parameter, on the left of +". ucrBase.iHelpTopicID = 356 ucrSaveGraph.SetDataFrameSelector(sdgLayerOptions.ucrGeomWithAes.UcrSelector.ucrAvailableDataFrames) @@ -51,8 +51,10 @@ Public Class dlgGeneralForGraphics ucrAdditionalLayers.SetRSyntax(ucrBase.clsRsyntax) ucrAdditionalLayers.SetGGplotFunction(clsRggplotFunction) ucrAdditionalLayers.SetAesFunction(clsGgplotAesFunction) - sdgPlots.SetRSyntax(ucrBase.clsRsyntax) 'Warning/question: sdgPlots is treated as sort of a ucr of the main. But then there is only one instance for all dialogues. How comes this doesn't causes problems ? The RSyntax of differetn dialogues should be linked through here ? Why does this not actually happen ? - 'Warning: in some specific plots, GgplotFunction is set here as well. In others not... + 'Warning: commented the following out and set them up when clicking on sdgPlotOptions... making sure to rewrite the links that have been made with other dlg in specific plots... + 'sdgPlots.SetRSyntax(ucrBase.clsRsyntax) 'Warning/question: sdgPlots is treated as sort of a ucr of the main. But then there is only one instance for all dialogues. How comes this doesn't causes problems ? The RSyntax of different dialogues should be unfortunately linked through here ? Is this actually happening in specific plots ? + 'sdgPlots.SetGgplotFunction(clsRggplotFunction) + 'Warning: in some specific plots, GgplotFunction is set here as well. In others not... In scattered plot it is not, and scattered plot works fine with Layers. Now here Layers is disabled on sdgPLots so theer is no need to link clsRggplotFunction. ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False 'By default, we want to put in the script the output of our Base R-command (in this case the ...+...+...) even when it has been assigned to some object (in which case we want the name of that object in the script so that it's called when the script is run). 'For example, when a graph is saved, it is assigned to it's place in an R-instat object. If we had set bExcludeAssignedFunctionOutput to True, then we would never print the graph when running the script. @@ -173,9 +175,14 @@ Public Class dlgGeneralForGraphics End If End Sub + Private Sub SetupPlotOptions() 'Warning to be discussed: I m hoping to have a Setup function in sdgPlots itself... ? + sdgPlots.SetRSyntax(ucrBase.clsRsyntax) + sdgPlots.SetGgplotFunction(clsRggplotFunction) + End Sub 'Warning: never setup sdgPlots.SetGgplotFunction(clsRggplotFunction) ? same in scattered plot which works well. In dotplot, adds it in initialise, but then additional layers don't work ... Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click sdgPlots.DisableLayersTab() + SetupPlotOptions() sdgPlots.ShowDialog() sdgPlots.EnableLayersTab() End Sub diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index abda7e2be3c..1d7429eb357 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -114,7 +114,7 @@ Public Class ucrAdditionalLayers End If clsRSyntax.SetOperatorParameter(False, strParameterName:=strLayerName, clsRFunc:=sdgLayerOptions.clsGeomFunction.Clone()) - + 'Note: as the GeomFunction on sdgLayerOptions will be edited for different layers, it cannot be linked like clsGgplotFunction would, it needs to be cloned. dlgGeneralForGraphics.TestOKEnabled() End Sub @@ -134,6 +134,7 @@ Public Class ucrAdditionalLayers Dim bIgnoreGlobalAes As Boolean 'bIgnoreGlobalAes is used in Setup(Layer) to determine whether the chkIgnoreGlobalAes should be ticked in the sdgLayerOptions. It's value is determined below. The following RParameter will be used in this procedure. Dim clsTempRParameter As RParameter + 'The selected geom is found as the RFunction of the appropriate RParameter of RSyntax. The name of that Parameter is the name of the selected item in the lstLayers. That one is fetched using .SelectedItems(0) as there can only be one selected item at a time when the edit button is clicked. clsSelectedGeom = clsRSyntax.GetParameter(lstLayers.SelectedItems(0).Text).clsArgumentFunction If clsSelectedGeom.GetParameter("mapping") IsNot Nothing Then @@ -148,9 +149,10 @@ Public Class ucrAdditionalLayers bIgnoreGlobalAes = True Else bIgnoreGlobalAes = False End If - - sdgLayerOptions.SetupLayer(clsTempGgPlot:=dlgGeneralForGraphics.clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=dlgGeneralForGraphics.clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) + 'Warning: sdgLayerOptions should not be setup using dlgGeneralForGraphics' fields !! These fields should be given through to the ucrAdditionalLayers (which should have all these) + sdgLayerOptions.SetupLayer(clsTempGgPlot:=clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) 'It has been chosen to fix the value of bApplyAesGlobally to False as when a Layer is editted, the choice to apply the Aes globally should be reconsidered no matter what it has been during last edit. + ParentForm.SendToBack() 'Otherwise sdgLayerOptions appears behind sdgPLotOptions sdgLayerOptions.ShowDialog() AddLayers(lstLayers.SelectedItems(0)) End Sub From e0f900cea73f29c5d3bbf9932198d5785b82d508 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Mon, 14 Nov 2016 16:37:39 +0300 Subject: [PATCH 06/27] Changes on contrats and splitDate methods --- instat/static/InstatObject/R/data_object_R6.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 71f03489f20..7363b7f7433 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1663,8 +1663,8 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr stop("New column name must be of type: character") } - if((new_contrast=="user_defined")){ - if (!is.na(contr_vector)){ + if(new_contrast=="user_defined"){ + if (!is.na(contr_vector) & is.numeric(contr_vector)){ contr_col=nlevels(factor_col)-1 contr_row=nlevels(factor_col) if (length(contr_vector)==contr_col*contr_col){ @@ -1680,24 +1680,24 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr ) data_object$set("public","Split_Date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) - if(!(is.Date(col_data)))(stop("This column must be a date!")) - - + if(!is.Date(col_data) | !is.period(col_data)| !is.POSIXt(col_data) | !is.POSIXct(col_data) | !is.POSIXlt(col_data)) (stop("This column must be a date or time!")) if(week==TRUE){ week=week(col_data) self$add_columns_to_data(col_name = "week", col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) - } +} if(month==TRUE){ month=month(col_data) self$add_columns_to_data(col_name = "month", col_data = month,use_col_name_as_prefix = use_col_name_as_prefix) - } +} if(year==TRUE){ year=year(col_data) self$add_columns_to_data(col_name = "year", col_data = year, use_col_name_as_prefix = use_col_name_as_prefix) - } +} if(day==TRUE){ day=day(col_data) self$add_columns_to_data(col_name = "day", col_data = day, use_col_name_as_prefix = use_col_name_as_prefix) - } +} + #TO Do + #Implement option for the day of the year } ) \ No newline at end of file From faf56a7f1d41bb09fc4bc06331e61c7fd0e7bc4a Mon Sep 17 00:00:00 2001 From: Lunalo Date: Mon, 14 Nov 2016 17:04:47 +0300 Subject: [PATCH 07/27] Eddding check for the date column --- instat/static/InstatObject/R/data_object_R6.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 7363b7f7433..445d46205dd 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1118,6 +1118,8 @@ data_object$set("public", "get_data_type", function(col_name = "") { type = "logical" } else if(is.Date(private$data[[col_name]])){ + # #TODO + #we can add options for other forms of dates serch as POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, and fts objects. type = "Date" } else if(is.numeric(private$data[[col_name]])) { @@ -1680,7 +1682,8 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr ) data_object$set("public","Split_Date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) - if(!is.Date(col_data) | !is.period(col_data)| !is.POSIXt(col_data) | !is.POSIXct(col_data) | !is.POSIXlt(col_data)) (stop("This column must be a date or time!")) +if(self$get_data_type(col_names=col_names) != "Date") stop("This column must be a date or time!") + if(week==TRUE){ week=week(col_data) self$add_columns_to_data(col_name = "week", col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) From e5164d87eb18dde36ddc466f2fcc235b00ff67a2 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Mon, 14 Nov 2016 17:10:27 +0300 Subject: [PATCH 08/27] ok/return enabled according to the number of layers in ucrAdditionalLayers, to be validated/tested --- instat/dlgGeneralForGraphics.vb | 5 +++++ instat/sdgPlots.vb | 14 ++++++++++++-- instat/ucrAdditionalLayers.vb | 8 ++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index 64e75102828..23095aa0c3b 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -186,4 +186,9 @@ Public Class dlgGeneralForGraphics sdgPlots.ShowDialog() sdgPlots.EnableLayersTab() End Sub + + Private Sub ucrAdditionalLayers_OkOrReturnInDanger() Handles ucrAdditionalLayers.OkOrReturnInDanger + 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. + TestOKEnabled() + End Sub End Class \ No newline at end of file diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index 75336483283..cd2cd3f2f5a 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -427,6 +427,16 @@ Public Class sdgPlots clsRsyntax.RemoveOperatorParameter("labs") End If End Sub - - + Private Sub TestReturnEnabled() + Dim bTemp As Boolean = False + For Each bTemp In ucrAdditionalLayers.lstLayerComplete + If Not bTemp Then + Exit For + End If + Next + ucrBaseSubdialog.cmdReturn.Enabled = bTemp 'Task/ question ?: should add a method in the ucrBaseSubdialog ... + End Sub + Private Sub ucrPlotsAdditionalLayers_OkOrReturnInDanger() Handles ucrPlotsAdditionalLayers.OkOrReturnInDanger + TestReturnEnabled() + End Sub End Class \ No newline at end of file diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index 1d7429eb357..08c31552be5 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -26,6 +26,7 @@ Public Class ucrAdditionalLayers Public iLayerIndex As Integer Private strGlobalDataFrame As String Public bSetGlobalIsDefault As Boolean + Public Event OkOrReturnInDanger() 'This event is raised when the number of Layers in the lstLayers on ucrAdditionalLayers has been changed, then handled by testOk/ReturnEnabled On sdgPlots. 'Deciding if the first layer needs to be used for global aesthetics. 'Question to be discussed: What is this variable about again ? it is linked with sdgPlots.bAdditionalLayersSetGlobal in sdgPLots.bLayersDefaultIsGolobal. @@ -115,7 +116,9 @@ Public Class ucrAdditionalLayers clsRSyntax.SetOperatorParameter(False, strParameterName:=strLayerName, clsRFunc:=sdgLayerOptions.clsGeomFunction.Clone()) 'Note: as the GeomFunction on sdgLayerOptions will be edited for different layers, it cannot be linked like clsGgplotFunction would, it needs to be cloned. - dlgGeneralForGraphics.TestOKEnabled() + + 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. + RaiseEvent OkOrReturnInDanger() End Sub Private Sub cmdDelete_Click(sender As Object, e As EventArgs) Handles cmdDelete.Click @@ -124,7 +127,8 @@ Public Class ucrAdditionalLayers lstLayerComplete.RemoveAt(lstLayers.SelectedIndices(0)) lstLayers.Items.Remove(lstLayers.SelectedItems(0)) - dlgGeneralForGraphics.TestOKEnabled() + 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. + RaiseEvent OkOrReturnInDanger() End If End Sub From 2a885b36fadce930f69368a98645a90b9dc28363 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Mon, 14 Nov 2016 17:26:48 +0300 Subject: [PATCH 09/27] Edting split_date method --- instat/static/InstatObject/R/data_object_R6.R | 4 ++-- instat/static/InstatObject/R/instat_object_R6.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 445d46205dd..481ab0f81e0 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1680,9 +1680,9 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr contrasts(private$data[[col_name]]) <- new_contrasts } ) -data_object$set("public","Split_Date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { +data_object$set("public","split_date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) -if(self$get_data_type(col_names=col_names) != "Date") stop("This column must be a date or time!") +if(self$get_data_type(col_name=col_names) != "Date") stop("This column must be a date or time!") if(week==TRUE){ week=week(col_data) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index a7f25b7563a..25a00b119b6 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -1032,7 +1032,7 @@ instat_object$set("public","create_factor_data_frame", function(data_name, facto } ) -instat_object$set("public","Split_Date", function(data_name, col_names="", year=FALSE, month=FALSE, day=FALSE, week=FALSE,use_col_name_as_prefix = TRUE ) { - self$get_data_objects(data_name)$Split_Date(year = year,col_names=col_names, month = month, day = day, week=week,use_col_name_as_prefix = use_col_name_as_prefix ) +instat_object$set("public","split_date", function(data_name, col_names="", year=FALSE, month=FALSE, day=FALSE, week=FALSE,use_col_name_as_prefix = TRUE ) { + self$get_data_objects(data_name)$split_date(year = year,col_names=col_names, month = month, day = day, week=week,use_col_name_as_prefix = use_col_name_as_prefix ) } ) \ No newline at end of file From 0ff1d178e18d18313c6ba3932dab187b6a752f33 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Mon, 14 Nov 2016 17:31:18 +0300 Subject: [PATCH 10/27] changes in testOkEnabled mehtod --- instat/dlgGeneralForGraphics.vb | 2 +- instat/sdgPlots.vb | 16 ++++------------ instat/ucrAdditionalLayers.vb | 7 +++---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index 23095aa0c3b..678b494e23f 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -187,7 +187,7 @@ Public Class dlgGeneralForGraphics sdgPlots.EnableLayersTab() End Sub - Private Sub ucrAdditionalLayers_OkOrReturnInDanger() Handles ucrAdditionalLayers.OkOrReturnInDanger + Private Sub ucrAdditionalLayers_NumberOfLayersChanged() Handles ucrAdditionalLayers.NumberOfLayersChanged 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. TestOKEnabled() End Sub diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index cd2cd3f2f5a..e6c6afe59d1 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -427,16 +427,8 @@ Public Class sdgPlots clsRsyntax.RemoveOperatorParameter("labs") End If End Sub - Private Sub TestReturnEnabled() - Dim bTemp As Boolean = False - For Each bTemp In ucrAdditionalLayers.lstLayerComplete - If Not bTemp Then - Exit For - End If - Next - ucrBaseSubdialog.cmdReturn.Enabled = bTemp 'Task/ question ?: should add a method in the ucrBaseSubdialog ... - End Sub - Private Sub ucrPlotsAdditionalLayers_OkOrReturnInDanger() Handles ucrPlotsAdditionalLayers.OkOrReturnInDanger - TestReturnEnabled() - End Sub + + + 'Warning/Task to be discussed: need to disable ok on dlg's when layers are not complete on subdialogues + warning message... OR introduce a TestReturnEnabled on ucrBaseSubdialog. Would perhaps be better to have a cancel button in that case ? ... + End Class \ No newline at end of file diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index 08c31552be5..4deccf4c58c 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -26,10 +26,9 @@ Public Class ucrAdditionalLayers Public iLayerIndex As Integer Private strGlobalDataFrame As String Public bSetGlobalIsDefault As Boolean - Public Event OkOrReturnInDanger() 'This event is raised when the number of Layers in the lstLayers on ucrAdditionalLayers has been changed, then handled by testOk/ReturnEnabled On sdgPlots. 'Deciding if the first layer needs to be used for global aesthetics. 'Question to be discussed: What is this variable about again ? it is linked with sdgPlots.bAdditionalLayersSetGlobal in sdgPLots.bLayersDefaultIsGolobal. - + Public Event NumberOfLayersChanged() 'This event is raised when the number of Layers in the lstLayers on ucrAdditionalLayers has been changed, then handled by testOkEnabled On GeneralForGraphics. Public Sub New() ' This call is required by the designer. @@ -118,7 +117,7 @@ Public Class ucrAdditionalLayers 'Note: as the GeomFunction on sdgLayerOptions will be edited for different layers, it cannot be linked like clsGgplotFunction would, it needs to be cloned. 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. - RaiseEvent OkOrReturnInDanger() + RaiseEvent NumberOfLayersChanged() End Sub Private Sub cmdDelete_Click(sender As Object, e As EventArgs) Handles cmdDelete.Click @@ -128,7 +127,7 @@ Public Class ucrAdditionalLayers lstLayers.Items.Remove(lstLayers.SelectedItems(0)) 'When the number of Layers in the lstLayers on ucrAdditionalLayers need to check if OK is enabled on dlgGeneralForGraphics. - RaiseEvent OkOrReturnInDanger() + RaiseEvent NumberOfLayersChanged() End If End Sub From 24da223c6077c78ef47a42f82f616ee4e70375b0 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Mon, 14 Nov 2016 17:38:32 +0300 Subject: [PATCH 11/27] edited comment --- instat/sdgPlots.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index e6c6afe59d1..d815f99b372 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -430,5 +430,5 @@ Public Class sdgPlots 'Warning/Task to be discussed: need to disable ok on dlg's when layers are not complete on subdialogues + warning message... OR introduce a TestReturnEnabled on ucrBaseSubdialog. Would perhaps be better to have a cancel button in that case ? ... - + 'Warning: actually this will be very hard to implement until the global aes, set from the main layer are properly communicated to plots. Global aes might fill in missing mandatory aes... End Class \ No newline at end of file From 2c814788df0b948740409e3d20c105958d50428d Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Tue, 15 Nov 2016 09:34:41 +0300 Subject: [PATCH 12/27] edited comment --- instat/sdgPlots.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index d815f99b372..a1a9cc4ca07 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -429,6 +429,6 @@ Public Class sdgPlots End Sub - 'Warning/Task to be discussed: need to disable ok on dlg's when layers are not complete on subdialogues + warning message... OR introduce a TestReturnEnabled on ucrBaseSubdialog. Would perhaps be better to have a cancel button in that case ? ... + 'Warning/Task to be discussed: need to disable ok on dlg's when layers are not complete on subdialogues + warning message... 'Warning: actually this will be very hard to implement until the global aes, set from the main layer are properly communicated to plots. Global aes might fill in missing mandatory aes... End Class \ No newline at end of file From e42e85db58557e650677420238ca64b3228d2e1d Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Tue, 15 Nov 2016 09:42:47 +0300 Subject: [PATCH 13/27] small typo in ucrAdditionalLayers --- instat/ucrAdditionalLayers.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index 4deccf4c58c..adf1ad03ed6 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -148,7 +148,7 @@ Public Class ucrAdditionalLayers 'Before we set-up the Layer in sdgLayerOptions, we determine the value of bIgnoreGlobalAes. We can detect if chkIgnoreGlobalAes was ticked last time the Layer was editted by looking at the "inherit.aes" parameter of the layer parameters. clsTempRParameter = clsSelectedGeom.GetParameter("inherit.aes") - If (clsTempRParameter IsNot Nothing) AndAlso (clsTempRParameter.strArgumentValue = "False") Then + If (clsTempRParameter IsNot Nothing) AndAlso (clsTempRParameter.strArgumentValue = "FALSE") Then bIgnoreGlobalAes = True Else bIgnoreGlobalAes = False End If From de44adc929a2168ba11121eedc9ca42875bf5e73 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Tue, 15 Nov 2016 10:15:25 +0300 Subject: [PATCH 14/27] Editing contrast and split date method --- instat/static/InstatObject/R/data_object_R6.R | 48 +++++++++++-------- .../static/InstatObject/R/instat_object_R6.R | 8 ++-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 481ab0f81e0..f8e3b5e4dff 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1654,24 +1654,26 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = } ) -data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, contr_vector = NA) { +data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, defined_contr_matrix = NA) { if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") #checks needed on contrasts before assigning - factor_col=self$get_columns_from_data(col_name) - if(!(new_contrasts %in% c("contr.treatment","contr.helmert","contr.poly","contr.sum", "user_defined"))){ + factor_col <- self$get_columns_from_data(col_name) + if(!(new_contrasts %in% c("contr.treatment" ,"contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { stop(new_contrasts, " is not a valid contrast name") - } else if (!is.character(new_contrasts)) { + } + else if(!is.character(new_contrasts)) { stop("New column name must be of type: character") } - if(new_contrast=="user_defined"){ - if (!is.na(contr_vector) & is.numeric(contr_vector)){ - contr_col=nlevels(factor_col)-1 - contr_row=nlevels(factor_col) - if (length(contr_vector)==contr_col*contr_col){ - contr_matrix<-as.matrix(contr_vector, contr_row, contr_col) - } else { + if(new_contrast == "user_defined"){ + if (!is.na(defined_contr_matrix) && is.numeric(defined_contr_matrix)) { + contr_col = nlevels(factor_col)-1 + contr_row = nlevels(factor_col) + if (length(defined_contr_matrix) == contr_row*contr_col) { + contr_matrix<-as.matrix(defined_contr_matrix, contr_row, contr_col) + } + else{ stop("Specify correct number of rows and columns in the defined matrix") } } @@ -1680,25 +1682,29 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr contrasts(private$data[[col_name]]) <- new_contrasts } ) -data_object$set("public","split_date", function(data_name,col_names="", week=FALSE, month=FALSE, year=FALSE,day=FALSE, use_col_name_as_prefix = TRUE) { +data_object$set("public","split_date", function(data_name, col_name = "", week=FALSE, month=FALSE, year = FALSE, day = FALSE) { col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) -if(self$get_data_type(col_name=col_names) != "Date") stop("This column must be a date or time!") +if(self$get_data_type(col_name=col_name) != "Date") stop("This column must be a date or time!") - if(week==TRUE){ + if(!week){ week=week(col_data) - self$add_columns_to_data(col_name = "week", col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) + col_name <- next_default_item(prefix = "week", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) } - if(month==TRUE){ + if(!month){ month=month(col_data) - self$add_columns_to_data(col_name = "month", col_data = month,use_col_name_as_prefix = use_col_name_as_prefix) + col_name <- next_default_item(prefix = "month", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = month, use_col_name_as_prefix = use_col_name_as_prefix) } - if(year==TRUE){ + if(!year){ year=year(col_data) - self$add_columns_to_data(col_name = "year", col_data = year, use_col_name_as_prefix = use_col_name_as_prefix) + col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = year, use_col_name_as_prefix = use_col_name_as_prefix) } - if(day==TRUE){ + if(!day){ day=day(col_data) - self$add_columns_to_data(col_name = "day", col_data = day, use_col_name_as_prefix = use_col_name_as_prefix) + col_name <- next_default_item(prefix = "day", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = day, use_col_name_as_prefix = use_col_name_as_prefix) } #TO Do #Implement option for the day of the year diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 25a00b119b6..ac602e4b63a 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -987,8 +987,8 @@ instat_object$set("public","make_date_yeardoy", function(data_name, year, doy, y } ) -instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts, contr_vector = NA) { - self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, contr_vector =contr_vector) +instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts,defined_contr_matrix = NA) { + self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix=defined_contr_matrix) } ) @@ -1032,7 +1032,7 @@ instat_object$set("public","create_factor_data_frame", function(data_name, facto } ) -instat_object$set("public","split_date", function(data_name, col_names="", year=FALSE, month=FALSE, day=FALSE, week=FALSE,use_col_name_as_prefix = TRUE ) { - self$get_data_objects(data_name)$split_date(year = year,col_names=col_names, month = month, day = day, week=week,use_col_name_as_prefix = use_col_name_as_prefix ) +instat_object$set("public","split_date", function(data_name, col_name="", year=FALSE, month=FALSE, day=FALSE, week=FALSE) { + self$get_data_objects(data_name)$split_date(year = year,col_name=col_name, month = month, day = day) } ) \ No newline at end of file From f7ae959cf6a1edfa0a82e279870d39ae0c2e0bec Mon Sep 17 00:00:00 2001 From: Lunalo Date: Tue, 15 Nov 2016 11:06:29 +0300 Subject: [PATCH 15/27] Editing the conventions in split date method --- instat/static/InstatObject/R/data_object_R6.R | 44 +++++++++---------- .../static/InstatObject/R/instat_object_R6.R | 4 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index f8e3b5e4dff..787b6e210bb 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1683,29 +1683,29 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr } ) data_object$set("public","split_date", function(data_name, col_name = "", week=FALSE, month=FALSE, year = FALSE, day = FALSE) { - col_data <- self$get_columns_from_data(col_names, use_current_filter = FALSE) -if(self$get_data_type(col_name=col_name) != "Date") stop("This column must be a date or time!") + col_data <- self$get_columns_from_data(col_names = col_name, use_current_filter = FALSE) + if(self$get_data_type(col_name = col_name) != "Date") stop("This column must be a date or time!") - if(!week){ - week=week(col_data) - col_name <- next_default_item(prefix = "week", existing_names = self$get_column_names(), include_index = FALSE) - self$add_columns_to_data(col_name = col_name, col_data = week, use_col_name_as_prefix = use_col_name_as_prefix) -} - if(!month){ - month=month(col_data) - col_name <- next_default_item(prefix = "month", existing_names = self$get_column_names(), include_index = FALSE) - self$add_columns_to_data(col_name = col_name, col_data = month, use_col_name_as_prefix = use_col_name_as_prefix) -} - if(!year){ - year=year(col_data) - col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) - self$add_columns_to_data(col_name = col_name, col_data = year, use_col_name_as_prefix = use_col_name_as_prefix) -} - if(!day){ - day=day(col_data) - col_name <- next_default_item(prefix = "day", existing_names = self$get_column_names(), include_index = FALSE) - self$add_columns_to_data(col_name = col_name, col_data = day, use_col_name_as_prefix = use_col_name_as_prefix) -} + if(week){ + week <- week(col_data) + col_name <- next_default_item(prefix = "week", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = week) + } + if(month){ + month <- month(col_data) + col_name <- next_default_item(prefix = "month", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = month) + } + if(year){ + year <- year(col_data) + col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = year) + } + if(day){ + day <- day(col_data) + col_name <- next_default_item(prefix = "day", existing_names = self$get_column_names(), include_index = FALSE) + self$add_columns_to_data(col_name = col_name, col_data = day) + } #TO Do #Implement option for the day of the year } diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index ac602e4b63a..04e00b3fcc9 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -1032,7 +1032,7 @@ instat_object$set("public","create_factor_data_frame", function(data_name, facto } ) -instat_object$set("public","split_date", function(data_name, col_name="", year=FALSE, month=FALSE, day=FALSE, week=FALSE) { - self$get_data_objects(data_name)$split_date(year = year,col_name=col_name, month = month, day = day) +instat_object$set("public","split_date", function(data_name, col_name = "", year = FALSE, month = FALSE, day = FALSE, week = FALSE) { + self$get_data_objects(data_name)$split_date(col_name =col_name , week = week, month = month, day = day, year = year) } ) \ No newline at end of file From 69442a4076aefb2e609d1edc1b26ac0758548cab Mon Sep 17 00:00:00 2001 From: Lunalo Date: Tue, 15 Nov 2016 11:33:47 +0300 Subject: [PATCH 16/27] Minor edits on split date method --- instat/static/InstatObject/R/data_object_R6.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 787b6e210bb..7206294c2e9 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1659,7 +1659,7 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") #checks needed on contrasts before assigning factor_col <- self$get_columns_from_data(col_name) - if(!(new_contrasts %in% c("contr.treatment" ,"contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { + if(!(new_contrasts %in% c("contr.treatment", "contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { stop(new_contrasts, " is not a valid contrast name") } else if(!is.character(new_contrasts)) { @@ -1667,9 +1667,9 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr } if(new_contrast == "user_defined"){ - if (!is.na(defined_contr_matrix) && is.numeric(defined_contr_matrix)) { - contr_col = nlevels(factor_col)-1 - contr_row = nlevels(factor_col) + if(!is.na(defined_contr_matrix) && is.numeric(defined_contr_matrix)) { + contr_col <- nlevels(factor_col)-1 + contr_row <- nlevels(factor_col) if (length(defined_contr_matrix) == contr_row*contr_col) { contr_matrix<-as.matrix(defined_contr_matrix, contr_row, contr_col) } @@ -1682,7 +1682,7 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr contrasts(private$data[[col_name]]) <- new_contrasts } ) -data_object$set("public","split_date", function(data_name, col_name = "", week=FALSE, month=FALSE, year = FALSE, day = FALSE) { +data_object$set("public","split_date", function(data_name, col_name = "", week = FALSE, month = FALSE, year = FALSE, day = FALSE) { col_data <- self$get_columns_from_data(col_names = col_name, use_current_filter = FALSE) if(self$get_data_type(col_name = col_name) != "Date") stop("This column must be a date or time!") From 3c4a8e8433b5a0152ee882c4dc0e9e9af84a05bc Mon Sep 17 00:00:00 2001 From: Lily Date: Tue, 15 Nov 2016 13:17:00 +0000 Subject: [PATCH 17/27] Split Text Designer - edits and sorted tabs. --- instat/dlgSplitText.Designer.vb | 18 +++++++++--------- instat/dlgSplitText.vb | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/instat/dlgSplitText.Designer.vb b/instat/dlgSplitText.Designer.vb index f4d9a9a89b0..f6c03b4d328 100644 --- a/instat/dlgSplitText.Designer.vb +++ b/instat/dlgSplitText.Designer.vb @@ -40,7 +40,7 @@ Partial Class dlgSplitText Me.lblSelectedFactor.Location = New System.Drawing.Point(271, 37) Me.lblSelectedFactor.Name = "lblSelectedFactor" Me.lblSelectedFactor.Size = New System.Drawing.Size(140, 23) - Me.lblSelectedFactor.TabIndex = 7 + Me.lblSelectedFactor.TabIndex = 1 Me.lblSelectedFactor.Tag = "Selected_Factor" Me.lblSelectedFactor.Text = "Selected Factor:" ' @@ -49,7 +49,7 @@ Partial Class dlgSplitText Me.lblSplitBy.Location = New System.Drawing.Point(271, 81) Me.lblSplitBy.Name = "lblSplitBy" Me.lblSplitBy.Size = New System.Drawing.Size(140, 23) - Me.lblSplitBy.TabIndex = 6 + Me.lblSplitBy.TabIndex = 3 Me.lblSplitBy.Tag = "" Me.lblSplitBy.Text = "Split by:" ' @@ -58,7 +58,7 @@ Partial Class dlgSplitText Me.lblNewColumnNames.Location = New System.Drawing.Point(10, 203) Me.lblNewColumnNames.Name = "lblNewColumnNames" Me.lblNewColumnNames.Size = New System.Drawing.Size(161, 23) - Me.lblNewColumnNames.TabIndex = 5 + Me.lblNewColumnNames.TabIndex = 7 Me.lblNewColumnNames.Tag = "" Me.lblNewColumnNames.Text = "Prefix for New Columns:" ' @@ -67,7 +67,7 @@ Partial Class dlgSplitText Me.lblNumberofPiecesToReturn.Location = New System.Drawing.Point(269, 131) Me.lblNumberofPiecesToReturn.Name = "lblNumberofPiecesToReturn" Me.lblNumberofPiecesToReturn.Size = New System.Drawing.Size(149, 23) - Me.lblNumberofPiecesToReturn.TabIndex = 4 + Me.lblNumberofPiecesToReturn.TabIndex = 5 Me.lblNumberofPiecesToReturn.Tag = "Number_of_Pieces_to_Return" Me.lblNumberofPiecesToReturn.Text = "Number of Pieces to Return:" ' @@ -77,7 +77,7 @@ Partial Class dlgSplitText Me.nudN.Minimum = New Decimal(New Integer() {1, 0, 0, 0}) Me.nudN.Name = "nudN" Me.nudN.Size = New System.Drawing.Size(37, 20) - Me.nudN.TabIndex = 3 + Me.nudN.TabIndex = 6 Me.nudN.Value = New Decimal(New Integer() {1, 0, 0, 0}) ' 'ucrInputPattern @@ -86,7 +86,7 @@ Partial Class dlgSplitText Me.ucrInputPattern.Location = New System.Drawing.Point(272, 96) Me.ucrInputPattern.Name = "ucrInputPattern" Me.ucrInputPattern.Size = New System.Drawing.Size(137, 21) - Me.ucrInputPattern.TabIndex = 0 + Me.ucrInputPattern.TabIndex = 4 ' 'ucrReceiverSplitTextColumn ' @@ -95,7 +95,7 @@ Partial Class dlgSplitText Me.ucrReceiverSplitTextColumn.Name = "ucrReceiverSplitTextColumn" Me.ucrReceiverSplitTextColumn.Selector = Nothing Me.ucrReceiverSplitTextColumn.Size = New System.Drawing.Size(137, 20) - Me.ucrReceiverSplitTextColumn.TabIndex = 1 + Me.ucrReceiverSplitTextColumn.TabIndex = 2 ' 'ucrInputColumnsIntoText ' @@ -103,7 +103,7 @@ Partial Class dlgSplitText Me.ucrInputColumnsIntoText.Location = New System.Drawing.Point(131, 200) Me.ucrInputColumnsIntoText.Name = "ucrInputColumnsIntoText" Me.ucrInputColumnsIntoText.Size = New System.Drawing.Size(137, 21) - Me.ucrInputColumnsIntoText.TabIndex = 2 + Me.ucrInputColumnsIntoText.TabIndex = 8 ' 'ucrSelectorSplitTextColumn ' @@ -113,7 +113,7 @@ Partial Class dlgSplitText Me.ucrSelectorSplitTextColumn.Margin = New System.Windows.Forms.Padding(0) Me.ucrSelectorSplitTextColumn.Name = "ucrSelectorSplitTextColumn" Me.ucrSelectorSplitTextColumn.Size = New System.Drawing.Size(210, 180) - Me.ucrSelectorSplitTextColumn.TabIndex = 8 + Me.ucrSelectorSplitTextColumn.TabIndex = 0 ' 'ucrBase ' diff --git a/instat/dlgSplitText.vb b/instat/dlgSplitText.vb index 6b61da09534..205ee396892 100644 --- a/instat/dlgSplitText.vb +++ b/instat/dlgSplitText.vb @@ -77,15 +77,15 @@ Public Class dlgSplitText Private Sub PatternParameter() Select Case ucrInputPattern.GetText Case "Whitespace" - ucrBase.clsRsyntax.AddParameter("pattern", Chr(34) & " " & Chr(34)) + ucrBase.clsRsyntax.AddParameter("pattern", "fixed (" & Chr(34) & " " & Chr(34) & ")") Case "" If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then - ucrBase.clsRsyntax.AddParameter("pattern", Chr(34) & "" & Chr(34)) + ucrBase.clsRsyntax.AddParameter("pattern", "fixed (" & Chr(34) & "" & Chr(34) & ")") Else ucrBase.clsRsyntax.RemoveParameter("pattern") End If Case Else - ucrBase.clsRsyntax.AddParameter("pattern", Chr(34) & ucrInputPattern.GetText() & Chr(34)) + ucrBase.clsRsyntax.AddParameter("pattern", "fixed (" & Chr(34) & ucrInputPattern.GetText() & Chr(34) & ")") End Select End Sub From d678277d984203cf5250eb3db73a6b4c36a5be6e Mon Sep 17 00:00:00 2001 From: Lunalo Date: Tue, 15 Nov 2016 16:51:03 +0300 Subject: [PATCH 18/27] Changes on contrast method --- instat/static/InstatObject/R/data_object_R6.R | 25 ++++++++----------- .../static/InstatObject/R/instat_object_R6.R | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 7206294c2e9..d5457f74107 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1654,11 +1654,19 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = } ) -data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, defined_contr_matrix = NA) { +data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, defined_contr_matrix) { + if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") #checks needed on contrasts before assigning factor_col <- self$get_columns_from_data(col_name) + contr_col <- nlevels(factor_col)-1 + contr_row <- nlevels(factor_col) + + if(new_contrasts == "user_defined") { + if(is.na(any(defined_contr_matrix)) ||!is.numeric(defined_contr_matrix) ||nrow(defined_contr_matrix) != contr_row || ncol(defined_contr_matrix) != contr_col) stop(paste0("The contrast matrix should have ", contr_col, " column(s) and ", contr_row, " row(s) ")) + } + if(!(new_contrasts %in% c("contr.treatment", "contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { stop(new_contrasts, " is not a valid contrast name") } @@ -1666,24 +1674,13 @@ data_object$set("public","set_contrasts_of_factor", function(col_name, new_contr stop("New column name must be of type: character") } - if(new_contrast == "user_defined"){ - if(!is.na(defined_contr_matrix) && is.numeric(defined_contr_matrix)) { - contr_col <- nlevels(factor_col)-1 - contr_row <- nlevels(factor_col) - if (length(defined_contr_matrix) == contr_row*contr_col) { - contr_matrix<-as.matrix(defined_contr_matrix, contr_row, contr_col) - } - else{ - stop("Specify correct number of rows and columns in the defined matrix") - } - } - } + contrasts(private$data[[col_name]]) <- new_contrasts } ) data_object$set("public","split_date", function(data_name, col_name = "", week = FALSE, month = FALSE, year = FALSE, day = FALSE) { - col_data <- self$get_columns_from_data(col_names = col_name, use_current_filter = FALSE) + col_data <- self$get_columns_from_data(col_name, use_current_filter = FALSE) if(self$get_data_type(col_name = col_name) != "Date") stop("This column must be a date or time!") if(week){ diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 04e00b3fcc9..6f975c6f289 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -987,7 +987,7 @@ instat_object$set("public","make_date_yeardoy", function(data_name, year, doy, y } ) -instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts,defined_contr_matrix = NA) { +instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts, defined_contr_matrix) { self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix=defined_contr_matrix) } ) From c9502bf56ba11bebe659e25a7553cfdede83e183 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Tue, 15 Nov 2016 17:34:05 +0300 Subject: [PATCH 19/27] last commit, dirty method in cmdEdit_Click --- instat/ucrAdditionalLayers.vb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index adf1ad03ed6..d3fb6cc9be0 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -136,7 +136,6 @@ Public Class ucrAdditionalLayers Dim clsLocalAes As RFunction Dim bIgnoreGlobalAes As Boolean 'bIgnoreGlobalAes is used in Setup(Layer) to determine whether the chkIgnoreGlobalAes should be ticked in the sdgLayerOptions. It's value is determined below. The following RParameter will be used in this procedure. - Dim clsTempRParameter As RParameter 'The selected geom is found as the RFunction of the appropriate RParameter of RSyntax. The name of that Parameter is the name of the selected item in the lstLayers. That one is fetched using .SelectedItems(0) as there can only be one selected item at a time when the edit button is clicked. clsSelectedGeom = clsRSyntax.GetParameter(lstLayers.SelectedItems(0).Text).clsArgumentFunction @@ -147,15 +146,14 @@ Public Class ucrAdditionalLayers End If 'Before we set-up the Layer in sdgLayerOptions, we determine the value of bIgnoreGlobalAes. We can detect if chkIgnoreGlobalAes was ticked last time the Layer was editted by looking at the "inherit.aes" parameter of the layer parameters. - clsTempRParameter = clsSelectedGeom.GetParameter("inherit.aes") - If (clsTempRParameter IsNot Nothing) AndAlso (clsTempRParameter.strArgumentValue = "FALSE") Then + If (clsSelectedGeom.GetParameter("inherit.aes") IsNot Nothing) AndAlso (clsSelectedGeom.GetParameter("inherit.aes").strArgumentValue = "FALSE") Then bIgnoreGlobalAes = True - Else bIgnoreGlobalAes = False + Else + bIgnoreGlobalAes = False End If - 'Warning: sdgLayerOptions should not be setup using dlgGeneralForGraphics' fields !! These fields should be given through to the ucrAdditionalLayers (which should have all these) - sdgLayerOptions.SetupLayer(clsTempGgPlot:=clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) + + sdgLayerOptions.SetupLayer(clsTempGgPlot:=dlgGeneralForGraphics.clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=dlgGeneralForGraphics.clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) 'It has been chosen to fix the value of bApplyAesGlobally to False as when a Layer is editted, the choice to apply the Aes globally should be reconsidered no matter what it has been during last edit. - ParentForm.SendToBack() 'Otherwise sdgLayerOptions appears behind sdgPLotOptions sdgLayerOptions.ShowDialog() AddLayers(lstLayers.SelectedItems(0)) End Sub From b64ec56614ca0d7904e802ceb8229ac7b68e67b7 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Wed, 16 Nov 2016 09:38:45 +0300 Subject: [PATCH 20/27] reimplementing previous changes deleted by error --- instat/ucrAdditionalLayers.vb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/instat/ucrAdditionalLayers.vb b/instat/ucrAdditionalLayers.vb index d3fb6cc9be0..08dc51aed9c 100644 --- a/instat/ucrAdditionalLayers.vb +++ b/instat/ucrAdditionalLayers.vb @@ -152,8 +152,10 @@ Public Class ucrAdditionalLayers bIgnoreGlobalAes = False End If - sdgLayerOptions.SetupLayer(clsTempGgPlot:=dlgGeneralForGraphics.clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=dlgGeneralForGraphics.clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) - 'It has been chosen to fix the value of bApplyAesGlobally to False as when a Layer is editted, the choice to apply the Aes globally should be reconsidered no matter what it has been during last edit. + 'Warning: sdgLayerOptions should not be setup using dlgGeneralForGraphics' fields !! These fields should be given through to the ucrAdditionalLayers (which should have all these) + sdgLayerOptions.SetupLayer(clsTempGgPlot:=clsRggplotFunction, clsTempGeomFunc:=clsSelectedGeom, clsTempAesFunc:=clsGgplotAesFunction, bFixAes:=False, bFixGeom:=True, strDataframe:=strGlobalDataFrame, bApplyAesGlobally:=False, bIgnoreGlobalAes:=bIgnoreGlobalAes, clsTempLocalAes:=clsLocalAes) + 'It has been chosen to fix the value of bApplyAesGlobally to False as when a Layer is editted, the choice to apply the Aes globally should be reconsidered no matter what it has been during last edit. + ParentForm.SendToBack() 'Otherwise sdgLayerOptions appears behind sdgPLotOptions sdgLayerOptions.ShowDialog() AddLayers(lstLayers.SelectedItems(0)) End Sub From 6130b3faee13bb1ee725b75b50afe0d2535c2fd0 Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 16 Nov 2016 09:07:07 +0000 Subject: [PATCH 21/27] Removed "fixed" for whitespace --- instat/dlgSplitText.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgSplitText.vb b/instat/dlgSplitText.vb index 205ee396892..804fdfae3c0 100644 --- a/instat/dlgSplitText.vb +++ b/instat/dlgSplitText.vb @@ -77,7 +77,7 @@ Public Class dlgSplitText Private Sub PatternParameter() Select Case ucrInputPattern.GetText Case "Whitespace" - ucrBase.clsRsyntax.AddParameter("pattern", "fixed (" & Chr(34) & " " & Chr(34) & ")") + ucrBase.clsRsyntax.AddParameter("pattern", Chr(34) & " " & Chr(34)) Case "" If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then ucrBase.clsRsyntax.AddParameter("pattern", "fixed (" & Chr(34) & "" & Chr(34) & ")") From 7f921714106594e4c6859016da48556684a68244 Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 16 Nov 2016 09:59:34 +0000 Subject: [PATCH 22/27] Sorted TestOKEnabled() --- instat/dlgSplitText.vb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instat/dlgSplitText.vb b/instat/dlgSplitText.vb index 804fdfae3c0..ea4b7d951db 100644 --- a/instat/dlgSplitText.vb +++ b/instat/dlgSplitText.vb @@ -33,7 +33,7 @@ Public Class dlgSplitText End Sub Private Sub TestOKEnabled() - If Not ucrReceiverSplitTextColumn.IsEmpty() AndAlso nudN.Text <> "" Then + If Not ucrReceiverSplitTextColumn.IsEmpty() AndAlso nudN.Text <> "" AndAlso Not ucrInputPattern.IsEmpty AndAlso Not ucrInputColumnsIntoText.IsEmpty Then ucrBase.OKEnabled(True) Else ucrBase.OKEnabled(False) @@ -59,7 +59,6 @@ Public Class dlgSplitText Private Sub SetDefaults() ucrSelectorSplitTextColumn.Reset() ucrSelectorSplitTextColumn.Focus() - ucrInputColumnsIntoText.Reset() ucrInputColumnsIntoText.SetName("SplitText") ucrInputPattern.ResetText() nudN.Value = 2 @@ -72,6 +71,7 @@ Public Class dlgSplitText Private Sub cboInputPattern_Namechanged() Handles ucrInputPattern.NameChanged PatternParameter() + TestOKEnabled() End Sub Private Sub PatternParameter() @@ -91,6 +91,7 @@ Public Class dlgSplitText Private Sub ucrInputColumnIntText_NameChanged() Handles ucrInputColumnsIntoText.NameChanged ucrBase.clsRsyntax.SetAssignTo(strAssignToName:=ucrInputColumnsIntoText.GetText, strTempDataframe:=ucrSelectorSplitTextColumn.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrInputColumnsIntoText.GetText, bAssignToIsPrefix:=True) + TestOKEnabled() End Sub Private Sub ucrReceiverSplitTextColumn_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverSplitTextColumn.SelectionChanged From 806bf504c9ae15f255ed668364bb35a8bfe8ad90 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Wed, 16 Nov 2016 14:25:22 +0300 Subject: [PATCH 23/27] Spacing in split date method --- instat/static/InstatObject/R/instat_object_R6.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 6f975c6f289..4dc175b1cf6 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -988,7 +988,7 @@ instat_object$set("public","make_date_yeardoy", function(data_name, year, doy, y ) instat_object$set("public","set_contrasts_of_factor", function(data_name, col_name, new_contrasts, defined_contr_matrix) { - self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix=defined_contr_matrix) + self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix = defined_contr_matrix) } ) @@ -1033,6 +1033,6 @@ instat_object$set("public","create_factor_data_frame", function(data_name, facto ) instat_object$set("public","split_date", function(data_name, col_name = "", year = FALSE, month = FALSE, day = FALSE, week = FALSE) { - self$get_data_objects(data_name)$split_date(col_name =col_name , week = week, month = month, day = day, year = year) + self$get_data_objects(data_name)$split_date(col_name = col_name , week = week, month = month, day = day, year = year) } ) \ No newline at end of file From 35111d413c9c689711e1d9ba87a1884591fd7657 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Wed, 16 Nov 2016 16:18:37 +0300 Subject: [PATCH 24/27] Relocate the ucrAdditional Layers setup : needs --- instat/sdgPlots.vb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index a1a9cc4ca07..60ced2457ef 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -23,7 +23,7 @@ Public Class sdgPlots Public clsRsyntax As New RSyntax 'This clsRSyntax is linked with the ucrBase.clsRSyntax from the dlg calling sdgPLotOptions... Public clsRggplotFunction As New RFunction - Public clsAesFunction As New RFunction + Public clsAesFunction As New RFunction 'Warning: I m not sure this field is useful... Will all be revised when changing links though... Public clsRFacetFunction As New RFunction Public clsXLabFunction As New RFunction Public clsYLabFunction As New RFunction @@ -87,10 +87,9 @@ Public Class sdgPlots InitialiseTabs() CreateThemes() FacetsReceiversSetup() - 'The following three setup the ucrAdditionalLayers on the sdgPlots. Shares the global ggplot function and aesthetics, as well as the whole PLots RSyntax. - ucrPlotsAdditionalLayers.SetGGplotFunction(clsRggplotFunction) + 'The following sets up the clsGgplotAesFunction in ucrAdditionalLayers. Not sure this should happen in the initialise dialog... Not sure of the objective either... It is never linked to the main dlg anyway... ucrPlotsAdditionalLayers.SetAesFunction(clsAesFunction) - ucrPlotsAdditionalLayers.SetRSyntax(clsRsyntax) + 'Set's the X Axis tab to X mode and the YAxis tab to Y mode (each tab contains a generic ucrAxis with internal X or Y boolean setting). 'Also carry the RSyntax through to these ucr's . ucrXAxis.SetXorY(True) @@ -353,7 +352,9 @@ Public Class sdgPlots 'Question to be discussed/Task: This is the kind of subs that could go into a SetupPlotOptions procedure... also only called in two specific plots and not in the others ... Why ? (to be explored) Public Sub SetGgplotFunction(clsGgplotFunc As RFunction) + 'When the link for clsRggplotFunction has been changed, the ucrAdditionalLayers GgplotFunction needs to be updated. clsRggplotFunction = clsGgplotFunc + ucrPlotsAdditionalLayers.SetGGplotFunction(clsRggplotFunction) End Sub Public Sub SetDataFrame(strNewDataFrame As String) @@ -362,7 +363,9 @@ Public Class sdgPlots End Sub Public Sub SetRSyntax(clsRSyntaxIn As RSyntax) + 'When the link for RSyntax has been changed, the ucrAdditionalLayers RSyntax needs to be updated. clsRsyntax = clsRSyntaxIn + ucrPlotsAdditionalLayers.SetRSyntax(clsRsyntax) End Sub From 47182d5d33c10945b0061b85df30e9053a2bacce Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Wed, 16 Nov 2016 16:23:02 +0300 Subject: [PATCH 25/27] reintroduce the ucrAdditionalLayers setup in initialise dialog for security purposes --- instat/sdgPlots.vb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instat/sdgPlots.vb b/instat/sdgPlots.vb index 60ced2457ef..a876aa8a990 100644 --- a/instat/sdgPlots.vb +++ b/instat/sdgPlots.vb @@ -89,6 +89,9 @@ Public Class sdgPlots FacetsReceiversSetup() 'The following sets up the clsGgplotAesFunction in ucrAdditionalLayers. Not sure this should happen in the initialise dialog... Not sure of the objective either... It is never linked to the main dlg anyway... ucrPlotsAdditionalLayers.SetAesFunction(clsAesFunction) + 'The following two setup the ucrAdditionalLayers on the sdgPlots. Shares the global ggplot function, as well as the whole PLots RSyntax. + ucrPlotsAdditionalLayers.SetGGplotFunction(clsRggplotFunction) + ucrPlotsAdditionalLayers.SetRSyntax(clsRsyntax) 'Set's the X Axis tab to X mode and the YAxis tab to Y mode (each tab contains a generic ucrAxis with internal X or Y boolean setting). 'Also carry the RSyntax through to these ucr's . From faec7d754c99c1503b38909f2b64288ba0137966 Mon Sep 17 00:00:00 2001 From: FrancoisJRenaud Date: Wed, 16 Nov 2016 16:57:58 +0300 Subject: [PATCH 26/27] deleting confusing comments in generalforgraphics --- instat/dlgGeneralForGraphics.vb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/instat/dlgGeneralForGraphics.vb b/instat/dlgGeneralForGraphics.vb index 678b494e23f..3a063fa3974 100644 --- a/instat/dlgGeneralForGraphics.vb +++ b/instat/dlgGeneralForGraphics.vb @@ -51,10 +51,6 @@ Public Class dlgGeneralForGraphics ucrAdditionalLayers.SetRSyntax(ucrBase.clsRsyntax) ucrAdditionalLayers.SetGGplotFunction(clsRggplotFunction) ucrAdditionalLayers.SetAesFunction(clsGgplotAesFunction) - 'Warning: commented the following out and set them up when clicking on sdgPlotOptions... making sure to rewrite the links that have been made with other dlg in specific plots... - 'sdgPlots.SetRSyntax(ucrBase.clsRsyntax) 'Warning/question: sdgPlots is treated as sort of a ucr of the main. But then there is only one instance for all dialogues. How comes this doesn't causes problems ? The RSyntax of different dialogues should be unfortunately linked through here ? Is this actually happening in specific plots ? - 'sdgPlots.SetGgplotFunction(clsRggplotFunction) - 'Warning: in some specific plots, GgplotFunction is set here as well. In others not... In scattered plot it is not, and scattered plot works fine with Layers. Now here Layers is disabled on sdgPLots so theer is no need to link clsRggplotFunction. ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False 'By default, we want to put in the script the output of our Base R-command (in this case the ...+...+...) even when it has been assigned to some object (in which case we want the name of that object in the script so that it's called when the script is run). 'For example, when a graph is saved, it is assigned to it's place in an R-instat object. If we had set bExcludeAssignedFunctionOutput to True, then we would never print the graph when running the script. @@ -179,7 +175,6 @@ Public Class dlgGeneralForGraphics sdgPlots.SetRSyntax(ucrBase.clsRsyntax) sdgPlots.SetGgplotFunction(clsRggplotFunction) End Sub - 'Warning: never setup sdgPlots.SetGgplotFunction(clsRggplotFunction) ? same in scattered plot which works well. In dotplot, adds it in initialise, but then additional layers don't work ... Private Sub cmdOptions_Click(sender As Object, e As EventArgs) Handles cmdOptions.Click sdgPlots.DisableLayersTab() SetupPlotOptions() From 8c0576a711e533b2696794ee68d54c91827d81b6 Mon Sep 17 00:00:00 2001 From: Lunalo Date: Thu, 17 Nov 2016 09:38:54 +0300 Subject: [PATCH 27/27] Editing split date method --- instat/static/InstatObject/R/data_object_R6.R | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index d5457f74107..c1fc22afc1b 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1655,55 +1655,48 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = ) data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, defined_contr_matrix) { - if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") - #checks needed on contrasts before assigning factor_col <- self$get_columns_from_data(col_name) - contr_col <- nlevels(factor_col)-1 + contr_col <- nlevels(factor_col) - 1 contr_row <- nlevels(factor_col) - if(new_contrasts == "user_defined") { - if(is.na(any(defined_contr_matrix)) ||!is.numeric(defined_contr_matrix) ||nrow(defined_contr_matrix) != contr_row || ncol(defined_contr_matrix) != contr_col) stop(paste0("The contrast matrix should have ", contr_col, " column(s) and ", contr_row, " row(s) ")) - } - - if(!(new_contrasts %in% c("contr.treatment", "contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { + if(any(is.na(defined_contr_matrix)) ||!is.numeric(defined_contr_matrix) ||nrow(defined_contr_matrix) != contr_row || ncol(defined_contr_matrix) != contr_col) stop(paste0("The contrast matrix should have ", contr_col, " column(s) and ", contr_row, " row(s) ")) + } + #checks needed on contrasts before assigning + if(!(new_contrasts %in% c("contr.treatment", "contr.helmert", "contr.poly", "contr.sum", "user_defined"))) { stop(new_contrasts, " is not a valid contrast name") } else if(!is.character(new_contrasts)) { stop("New column name must be of type: character") } - - - - contrasts(private$data[[col_name]]) <- new_contrasts -} + contrasts(private$data[[col_name]]) <- new_contrasts + } ) data_object$set("public","split_date", function(data_name, col_name = "", week = FALSE, month = FALSE, year = FALSE, day = FALSE) { col_data <- self$get_columns_from_data(col_name, use_current_filter = FALSE) - if(self$get_data_type(col_name = col_name) != "Date") stop("This column must be a date or time!") - - if(week){ + if(!is.Date(col_data)) stop("This column must be a date or time!") + if(week) { week <- week(col_data) col_name <- next_default_item(prefix = "week", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = week) } - if(month){ + if(month) { month <- month(col_data) col_name <- next_default_item(prefix = "month", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = month) } - if(year){ + if(year) { year <- year(col_data) col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = year) } - if(day){ + if(day) { day <- day(col_data) col_name <- next_default_item(prefix = "day", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = day) } #TO Do #Implement option for the day of the year -} + } ) \ No newline at end of file