Refactor facet handling in dlgBarAndPieChart#10074
Refactor facet handling in dlgBarAndPieChart#10074ARMSTRONGOPONDO wants to merge 4 commits intoIDEMSInternational:masterfrom
Conversation
Replaced `clsFacetRowOp` and `clsFacetColOp` with `clsVarsFunction` to streamline row and column variable management. Updated `dlgBarAndPieChart_Load` to initialize `clsVarsFunction`. Refactored `UpdateParameters` and `facet_grid` logic to use `clsVarsFunction` for `rows` and `cols` parameters.
Summary of ChangesHello @ARMSTRONGOPONDO, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request aims to modernize and simplify the internal handling of facet variables within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the facet handling in dlgBarAndPieChart to use clsVarsFunction, aligning with ggplot2's vars() syntax for facet_grid. This is a good improvement. The changes are mostly correct, but I've identified a couple of issues with the implementation for facet_grid parameters and a regression in the group_by functionality. I've provided detailed comments and code suggestions to address these. The other changes, including typo fixes, look good.
instat/dlgBarAndPieChart.vb
Outdated
| If bRowAll OrElse bColAll Then | ||
| clsFacetFunction.AddParameter("margins", "TRUE") | ||
| clsFacetFunction.AddParameter("margin", "TRUE", iPosition:=1) | ||
| Else | ||
| clsFacetFunction.RemoveParameterByName("margins") | ||
| clsFacetFunction.RemoveParameterByName("margin") | ||
| End If | ||
|
|
||
| If bRow OrElse bRowAll Then | ||
| clsFacetVariablesOperator.AddParameter("left", clsROperatorParameter:=clsFacetRowOp, iPosition:=0) | ||
| ElseIf (bCol OrElse bColAll) AndAlso bWrap = False Then | ||
| clsFacetVariablesOperator.AddParameter("left", ".", iPosition:=0) | ||
| clsFacetFunction.AddParameter("rows", clsRFunctionParameter:=clsVarsFunction, iPosition:=0) | ||
| Else | ||
| clsFacetVariablesOperator.RemoveParameterByName("left") | ||
| clsFacetFunction.RemoveParameterByName("rows") | ||
| End If | ||
|
|
||
| If bCol OrElse bColAll Then | ||
| clsFacetVariablesOperator.AddParameter("right", clsROperatorParameter:=clsFacetColOp, iPosition:=1) | ||
| ElseIf (bRow OrElse bRowAll) AndAlso bWrap = False Then | ||
| clsFacetVariablesOperator.AddParameter("right", ".", iPosition:=1) | ||
| clsFacetFunction.AddParameter("cols", clsRFunctionParameter:=clsVarsFunction, iPosition:=0) | ||
| Else | ||
| clsFacetVariablesOperator.RemoveParameterByName("right") | ||
| clsFacetFunction.RemoveParameterByName("cols") | ||
| End If |
There was a problem hiding this comment.
There are a couple of issues with the facet_grid parameters:
- The parameter for margins in
ggplot2::facet_gridismargins, notmargin. - You are using
iPosition:=0for bothrowsandcolsparameters. This can lead to an unpredictable order of arguments in the generated R code. It's better to use distinct positions to ensure correctness. - The
iPositionformargins(marginin your code) is1, which could conflict withcolsifcolswere correctly positioned.
I suggest the following changes to fix these issues:
If bRowAll OrElse bColAll Then
clsFacetFunction.AddParameter("margins", "TRUE", iPosition:=2)
Else
clsFacetFunction.RemoveParameterByName("margins")
End If
If bRow OrElse bRowAll Then
clsFacetFunction.AddParameter("rows", clsRFunctionParameter:=clsVarsFunction, iPosition:=0)
Else
clsFacetFunction.RemoveParameterByName("rows")
End If
If bCol OrElse bColAll Then
clsFacetFunction.AddParameter("cols", clsRFunctionParameter:=clsVarsFunction, iPosition:=1)
Else
clsFacetFunction.RemoveParameterByName("cols")
End If
| Select Case ucrInputStation.GetText() | ||
| Case strFacetWrap | ||
| GetParameterValue(clsFacetVariablesOperator) | ||
| Case strFacetCol, strFacetColAll | ||
| GetParameterValue(clsFacetColOp) | ||
| Case strFacetRow, strFacetRowAll | ||
| GetParameterValue(clsFacetRowOp) | ||
|
|
||
| End Select |
There was a problem hiding this comment.
The logic to populate clsGroupByFunction for facet_grid (cases strFacetCol and strFacetRow) seems to be missing after the refactoring. This will break the group_by functionality when using facet_grid.
You should add back the cases for strFacetCol and strFacetRow and populate clsGroupByFunction from clsVarsFunction. Since GetParameterValue only accepts an ROperator, you'll need to either inline the logic or refactor GetParameterValue to accept an RCodeStructure.
Here is a suggestion to inline the logic:
Select Case ucrInputStation.GetText()
Case strFacetWrap
GetParameterValue(clsFacetVariablesOperator)
Case strFacetCol, strFacetColAll, strFacetRow, strFacetRowAll
Dim i As Integer = 0
For Each param As RParameter In clsVarsFunction.clsParameters
If param.strArgumentValue <> "" AndAlso param.strArgumentValue <> "." Then
clsGroupByFunction.AddParameter(i, param.strArgumentValue, bIncludeArgumentName:=False, iPosition:=i)
i += 1
End If
Next
End Select
instat/dlgBarAndPieChart.vb
Outdated
| clsFacetRowOp.SetOperation("+") | ||
| clsFacetRowOp.bBrackets = False | ||
| clsFacetColOp.SetOperation("+") | ||
| clsFacetColOp.bBrackets = False |
There was a problem hiding this comment.
I can see here when I compare to @anastasia-mbithe's changes in dlgBoxPlot (#10071) that she adds in
clsFacetFunction.AddParameter("facets", clsROperatorParameter:=clsFacetVariablesOperator, iPosition:=0)Is there a reason this is missing? Can you go through comparing yours to hers to see what the differences are? I have put both side by side to see on my screen (see screenshot above).
Run through them side by side to see what changes she has that you do not, and vice versa.
Also, this is a really good learning point -- if there is any code on here that you do not understand, then you should ask (even if it's most of it!). This is the time to really understand the VB code so that you can become a real expert in it!
There was a problem hiding this comment.
@lilyclements , that line is still there on his side(616), for my dialogs I just moved it up so that its readable and someone doesn't miss it when looking at the function
|
@ARMSTRONGOPONDO I just checked out your branch and its working okay. I assume you tested without looking at the facet options, and the first is facet wrap, which hasn't changed its function and still uses the old version with ~, but if you test the Facet Row, or Column or Row +O, Col+O, which uses facet_grid it should work with the updated arguments. Please test again from your end and see if its updated |
|
@ARMSTRONGOPONDO have you been able to test this? |
Refactored `dlgBarAndPieChart.vb` and `dlgGeneralForGraphics.vb` to improve parameter management and streamline logic for `facet_wrap` and `facet_grid`. Removed redundant operators (`clsFacetRowOp`, `clsFacetColOp`) and replaced them with `clsVarsFunction` for better consistency and maintainability. Simplified the initialization and updating of facet-related parameters, ensuring cleaner and more modular code. Enhanced readability and reduced redundancy by consolidating logic for handling `rows`, `cols`, and `margin` parameters.
|
@lilyclements I have done the changes and tested it @anastasia-mbithe can you also test the two dialogs the dlgbarandpiechart and dlggeneralforgraph work as expected |
lilyclements
left a comment
There was a problem hiding this comment.
This is great @ARMSTRONGOPONDO! Well done. I've left a tiny change for you to make.
I'm not sure if it were something already in the VB code when you got to it, and not a big deal as R does partial-matching of strings, but, the margins parameter is margins, not margin
instat/dlgBarAndPieChart.vb
Outdated
| clsFacetFunction.SetRCommand("facet_grid") | ||
|
|
||
| If bRowAll OrElse bColAll Then | ||
| clsFacetFunction.AddParameter("margin", "TRUE") |
There was a problem hiding this comment.
This should be margins not margin
instat/dlgGeneralForGraphics.vb
Outdated
| clsFacetFunction.RemoveParameterByName("facets") | ||
| clsFacetFunction.RemoveParameterByName("rows") | ||
| clsFacetFunction.RemoveParameterByName("cols") | ||
| clsFacetFunction.RemoveParameterByName("margin") |
There was a problem hiding this comment.
Again here - correct as margins not margin
instat/dlgGeneralForGraphics.vb
Outdated
| clsFacetVariablesOperator.RemoveParameterByName("left") | ||
| End If | ||
| If bRowAll OrElse bColAll Then | ||
| clsFacetFunction.AddParameter("margin", "TRUE") |
There was a problem hiding this comment.
Again here - correct as margins not margin
instat/dlgBarAndPieChart.vb
Outdated
| clsFacetFunction.RemoveParameterByName("facets") | ||
| clsFacetFunction.RemoveParameterByName("rows") | ||
| clsFacetFunction.RemoveParameterByName("cols") | ||
| clsFacetFunction.RemoveParameterByName("margin") |
Noted let me implemented the change |
|
@ARMSTRONGOPONDO what is the state of this? Did you implement the change? Have you tested this? |
|
@lilyclements I implemented the changes and tested it's ready for review |
|
@anastasia-mbithe can you review this? I believe you've been involved in the facet side of things |
|
@anastasia-mbithe have you been able to look at this? |
this pull request partially fixes issue #10035
@lilyclements @berylwaswa @anastasia-mbithe Replaced
clsFacetRowOpandclsFacetColOpwithclsVarsFunctionto streamline row and column variable management. UpdateddlgBarAndPieChart_Loadto initializeclsVarsFunction. RefactoredUpdateParametersandfacet_gridlogic to useclsVarsFunctionforrowsandcolsparameters.Ive changed the logic but i keep getting the previous syntax on the R output maybe you can recommend a different dataset i can use to test it with @lilyclements