From 297c7eeead9f55c123e322013960694d9e1794be Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Mon, 2 Dec 2024 12:15:35 +0300 Subject: [PATCH 1/7] improved the display of shapefile data --- instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index d2b1a9cf27..f34f873bb3 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -87,8 +87,12 @@ Public Class ucrDataViewReoGrid Dim strData As String = dataFrame.DisplayedData(i, j) If strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(LT)") Then strData = GetTransformedLTColumnContents(strData) + ElseIf strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(G)") Then + strData = "MULTIPOLYGON" + grdData.CurrentWorksheet.GetCell(row:=i, col:=j).IsReadOnly = True End If grdData.CurrentWorksheet(row:=i, col:=j) = strData + Next grdData.CurrentWorksheet.RowHeaders.Item(i).Text = strRowNames(i) grdData.CurrentWorksheet.RowHeaders(i).TextColor = textColour From 8248ffd5311ca01385f1890663d2ecda67454e6a Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Mon, 2 Dec 2024 15:46:56 +0300 Subject: [PATCH 2/7] Added a tooltip for short view of the original data --- .../DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index f34f873bb3..9649d91e61 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -39,6 +39,8 @@ Public Class ucrDataViewReoGrid Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved + Private toolTip1 As New ToolTip() + Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns Dim workSheetColumnHeader As ColumnHeader Dim variableTextColour As Color @@ -90,9 +92,11 @@ Public Class ucrDataViewReoGrid ElseIf strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(G)") Then strData = "MULTIPOLYGON" grdData.CurrentWorksheet.GetCell(row:=i, col:=j).IsReadOnly = True + End If grdData.CurrentWorksheet(row:=i, col:=j) = strData + Next grdData.CurrentWorksheet.RowHeaders.Item(i).Text = strRowNames(i) grdData.CurrentWorksheet.RowHeaders(i).TextColor = textColour @@ -103,6 +107,13 @@ Public Class ucrDataViewReoGrid End If Next + + AddHandler grdData.CurrentWorksheet.CellMouseDown, Sub(sender As Object, e As unvell.ReoGrid.Events.CellMouseEventArgs) + If e.Cell IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(e.Cell.Column).Text.Contains("(G)") Then + toolTip1.SetToolTip(grdData, ShortenString(dataFrame.DisplayedData(e.Cell.Row, e.Cell.Column))) + End If + End Sub + If dataFrame.clsFilterOrColumnSelection.bFilterApplied Then grdData.CurrentWorksheet.ScrollToCell("A1") ' will always set the scrollbar at the top. End If @@ -115,6 +126,15 @@ Public Class ucrDataViewReoGrid grdData.CurrentWorksheet.RowHeaderWidth = TextRenderer.MeasureText(strLongestRowHeaderText, Me.Font).Width End Sub + Private Function ShortenString(strText As String) As String + Dim maxLength As Integer = 50 + If strText.Length > maxLength Then + ' Trim the string to the specified length and add ellipsis + Return strText.Substring(0, maxLength) & "..." + End If + Return strText + End Function + ''' ''' Transforms contents of LT column(s) that have structured R-like data into a more readable and user-friendly format that is consistent with R Viewer. ''' For example, content like list(Birmingham = list(IATA = c("BHM", NA, NA, NA), Hartford = list(IATA = "BDL", ICAO = "KBDL")) From 8afb746d0ffdd666830f39cf5cb670a71ff782dc Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Tue, 3 Dec 2024 07:09:08 +0300 Subject: [PATCH 3/7] improve the renaming of geometry column --- instat/static/InstatObject/R/data_object_R6.R | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 2bea3ede08..183480a69d 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -956,7 +956,12 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne } if(self$column_selection_applied()) self$remove_current_column_selection() # Need to use private$data here because changing names of data field - names(private$data)[names(curr_data) == curr_col_name] <- new_col_name + names(private$data)[names(private$data) == curr_col_name] <- new_col_name + + if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$data[[curr_col_name]]))){ + # Update the geometry column reference + sf::st_geometry(private$data) <- new_col_name + } self$append_to_variables_metadata(new_col_name, name_label, new_col_name) # TODO decide if we need to do these 2 lines self$append_to_changes(list(Renamed_col, curr_col_name, new_col_name)) @@ -977,6 +982,10 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne if(any(duplicated(curr_col_names))) stop("Cannot rename columns. Column names must be unique.") if(self$column_selection_applied()) self$remove_current_column_selection() names(private$data)[cols_changed_index] <- new_col_names + if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$dataprivate$data)[cols_changed_index])){ + # Update the geometry column reference + sf::st_geometry(private$data) <- new_col_names + } for (i in seq_along(cols_changed_index)) { self$append_to_variables_metadata(new_col_names[i], name_label, new_col_names[i]) } @@ -995,16 +1004,22 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne } else if (type == "rename_with") { if (missing(.fn)) stop(.fn, "is missing with no default.") curr_col_names <- names(curr_data) + current_geom_col <- attr(private$data, "sf_column") private$data <- curr_data |> dplyr::rename_with( .fn = .fn, .cols = {{ .cols }}, ... ) + if(self$column_selection_applied()) self$remove_current_column_selection() new_col_names <- names(private$data) if (!all(new_col_names %in% curr_col_names)) { new_col_names <- new_col_names[!(new_col_names %in% curr_col_names)] + if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$data[[current_geom_col]]))){ + # Update the geometry column reference + sf::st_geometry(private$data) <- new_col_names + } for (i in seq_along(new_col_names)) { self$append_to_variables_metadata(new_col_names[i], name_label, new_col_names[i]) } From 8474fc796f6078133e9aca55399d728fb3f20ec5 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Tue, 3 Dec 2024 07:52:52 +0300 Subject: [PATCH 4/7] formatting the geomtry data --- .../DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index 9649d91e61..3a9e4d1982 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -90,13 +90,10 @@ Public Class ucrDataViewReoGrid If strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(LT)") Then strData = GetTransformedLTColumnContents(strData) ElseIf strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(G)") Then - strData = "MULTIPOLYGON" + strData = ShortenString(strData) grdData.CurrentWorksheet.GetCell(row:=i, col:=j).IsReadOnly = True - End If grdData.CurrentWorksheet(row:=i, col:=j) = strData - - Next grdData.CurrentWorksheet.RowHeaders.Item(i).Text = strRowNames(i) grdData.CurrentWorksheet.RowHeaders(i).TextColor = textColour @@ -108,12 +105,6 @@ Public Class ucrDataViewReoGrid Next - AddHandler grdData.CurrentWorksheet.CellMouseDown, Sub(sender As Object, e As unvell.ReoGrid.Events.CellMouseEventArgs) - If e.Cell IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(e.Cell.Column).Text.Contains("(G)") Then - toolTip1.SetToolTip(grdData, ShortenString(dataFrame.DisplayedData(e.Cell.Row, e.Cell.Column))) - End If - End Sub - If dataFrame.clsFilterOrColumnSelection.bFilterApplied Then grdData.CurrentWorksheet.ScrollToCell("A1") ' will always set the scrollbar at the top. End If @@ -127,7 +118,7 @@ Public Class ucrDataViewReoGrid End Sub Private Function ShortenString(strText As String) As String - Dim maxLength As Integer = 50 + Dim maxLength As Integer = 30 If strText.Length > maxLength Then ' Trim the string to the specified length and add ellipsis Return strText.Substring(0, maxLength) & "..." From 59080be9adbbeb5e6ed7ee1b6942957fa33510c0 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Tue, 3 Dec 2024 07:58:40 +0300 Subject: [PATCH 5/7] minor change --- instat/static/InstatObject/R/data_object_R6.R | 1 - 1 file changed, 1 deletion(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 183480a69d..8016ff6f7e 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -957,7 +957,6 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne if(self$column_selection_applied()) self$remove_current_column_selection() # Need to use private$data here because changing names of data field names(private$data)[names(private$data) == curr_col_name] <- new_col_name - if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$data[[curr_col_name]]))){ # Update the geometry column reference sf::st_geometry(private$data) <- new_col_name From e66bac1666afc0e2efe8b45f54f38fcac8b94bb9 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Tue, 3 Dec 2024 09:49:13 +0300 Subject: [PATCH 6/7] bug fixes --- instat/static/InstatObject/R/data_object_R6.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 8016ff6f7e..bf80b3f16f 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -956,11 +956,12 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne } if(self$column_selection_applied()) self$remove_current_column_selection() # Need to use private$data here because changing names of data field - names(private$data)[names(private$data) == curr_col_name] <- new_col_name if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$data[[curr_col_name]]))){ # Update the geometry column reference sf::st_geometry(private$data) <- new_col_name } + names(private$data)[names(private$data) == curr_col_name] <- new_col_name + self$append_to_variables_metadata(new_col_name, name_label, new_col_name) # TODO decide if we need to do these 2 lines self$append_to_changes(list(Renamed_col, curr_col_name, new_col_name)) @@ -980,11 +981,12 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne curr_col_names[cols_changed_index] <- new_col_names if(any(duplicated(curr_col_names))) stop("Cannot rename columns. Column names must be unique.") if(self$column_selection_applied()) self$remove_current_column_selection() - names(private$data)[cols_changed_index] <- new_col_names if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$dataprivate$data)[cols_changed_index])){ # Update the geometry column reference sf::st_geometry(private$data) <- new_col_names } + names(private$data)[cols_changed_index] <- new_col_names + for (i in seq_along(cols_changed_index)) { self$append_to_variables_metadata(new_col_names[i], name_label, new_col_names[i]) } @@ -1015,10 +1017,6 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne new_col_names <- names(private$data) if (!all(new_col_names %in% curr_col_names)) { new_col_names <- new_col_names[!(new_col_names %in% curr_col_names)] - if(any(c("sfc", "sfc_MULTIPOLYGON") %in% class(private$data[[current_geom_col]]))){ - # Update the geometry column reference - sf::st_geometry(private$data) <- new_col_names - } for (i in seq_along(new_col_names)) { self$append_to_variables_metadata(new_col_names[i], name_label, new_col_names[i]) } From 492e7afcdcf3c07a172a98a4af5204190327da40 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Mon, 9 Dec 2024 09:11:50 +0300 Subject: [PATCH 7/7] removed unnecessary code --- instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 3 --- instat/static/InstatObject/R/data_object_R6.R | 2 -- 2 files changed, 5 deletions(-) diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index 3a9e4d1982..eab83192d5 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -39,8 +39,6 @@ Public Class ucrDataViewReoGrid Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved - Private toolTip1 As New ToolTip() - Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns Dim workSheetColumnHeader As ColumnHeader Dim variableTextColour As Color @@ -104,7 +102,6 @@ Public Class ucrDataViewReoGrid End If Next - If dataFrame.clsFilterOrColumnSelection.bFilterApplied Then grdData.CurrentWorksheet.ScrollToCell("A1") ' will always set the scrollbar at the top. End If diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index bf80b3f16f..6d665f59ec 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1005,9 +1005,7 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne } else if (type == "rename_with") { if (missing(.fn)) stop(.fn, "is missing with no default.") curr_col_names <- names(curr_data) - current_geom_col <- attr(private$data, "sf_column") private$data <- curr_data |> - dplyr::rename_with( .fn = .fn, .cols = {{ .cols }}, ...