Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder genes plots #742

Merged
merged 21 commits into from
Jun 22, 2022
Merged

Reorder genes plots #742

merged 21 commits into from
Jun 22, 2022

Conversation

jszpila314
Copy link
Contributor

@jszpila314 jszpila314 commented Jun 15, 2022

Description

Added a separate tab under gene selection in the marker heatmap plot to allow reordering of genes.

Details

URL to issue

https://biomage.atlassian.net/browse/BIOMAGE-1918
https://ui-jakub-ui742.scp-staging.biomage.net/

Link to staging deployment URL (or set N/A)

N/A

Integration test branch

master

Merge checklist

Your changes will be ready for merging after all of the steps below have been completed.

Code updates

Have best practices and ongoing refactors being observed in this PR

  • Migrated any selector / reducer used to the new format.

Manual/unit testing

  • Tested changes using InfraMock locally or no tests required for change, e.g. Kubernetes chart updates.
  • Validated that current unit tests for code work as expected and are sufficient for code coverage or no unit tests required for change, e.g. documentation update.
  • Unit tests written or no unit tests required for change, e.g. documentation update.

Integration testing

You must check the box below to run integration tests on the latest commit on your PR branch.
Integration tests have to pass before the PR can be merged. Without checking the box, your PR
will not pass the required status checks for merging.

  • Started end-to-end tests on the latest commit.

Documentation updates

  • Relevant Github READMEs updated or no GitHub README updates required.
  • Relevant Wiki pages created/updated or no Wiki updates required.

Optional

  • Staging environment is unstaged before merging.
  • Photo of a cute animal attached to this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2022

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 521.31 KB (🟡 +28 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Thirteen Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/data-management 301.08 KB (🟡 +45 B) 822.38 KB
/experiments/[experimentId]/data-exploration 535.3 KB (🟡 +6 B) 1.03 MB
/experiments/[experimentId]/data-processing 499.88 KB (-3 B) 1021.19 KB
/experiments/[experimentId]/plots-and-tables 14.89 KB (🟡 +1 B) 536.2 KB
/experiments/[experimentId]/plots-and-tables/dot-plot 476.66 KB (🟡 +2 B) 997.96 KB
/experiments/[experimentId]/plots-and-tables/embedding-categorical 473.28 KB (🟡 +2 B) 994.58 KB
/experiments/[experimentId]/plots-and-tables/embedding-continuous 473.97 KB (🟡 +2 B) 995.28 KB
/experiments/[experimentId]/plots-and-tables/frequency 475.07 KB (🟡 +2 B) 996.38 KB
/experiments/[experimentId]/plots-and-tables/heatmap 547.24 KB (🟡 +4 B) 1.04 MB
/experiments/[experimentId]/plots-and-tables/marker-heatmap 572.04 KB (🟡 +22.43 KB) 1.07 MB
/experiments/[experimentId]/plots-and-tables/violin 474.11 KB (🟡 +2 B) 995.42 KB
/experiments/[experimentId]/plots-and-tables/volcano 477.46 KB (🟡 +2 B) 998.76 KB
/settings/profile 25.37 KB (-1 B) 546.68 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link
Member

@cosa65 cosa65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look overall since you mentioned it is a work in progress. It looks good!

One suggestion I would make to get rid of the lag between dropping a gene and the list updating would be having onGeneReorder call

setGeneTreeData(composeGeneTree(newOrder));
debouncedUpdatePlotConfig(newOrder)

with debouncedUpdatePlotConfig being something like this:

const debouncedUpdatePlotConfig = useCallback(
    _.debounce((newOrder) => dispatch(updatePlotConfig(plotUuid, { selectedGenes: newOrder })), time), [],
  );

(time here can be pretty small probably, it's just about it updating a little bit later).

With these 2 changes it should no longer need to wait for redux to finish updating before setting the gene in its new place in the list, so it might look faster (with the plot updating a little bit later).

If you search for _.debounce you should find some places where similar things were done in case you want to check other examples. I think it was done a lot in "Data Processing".

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #742 (d8558a8) into master (d9d93d4) will increase coverage by 0.13%.
The diff coverage is 96.29%.

@@            Coverage Diff             @@
##           master     #742      +/-   ##
==========================================
+ Coverage   82.79%   82.93%   +0.13%     
==========================================
  Files         481      483       +2     
  Lines        8249     8302      +53     
  Branches     1628     1633       +5     
==========================================
+ Hits         6830     6885      +55     
+ Misses       1357     1356       -1     
+ Partials       62       61       -1     
Impacted Files Coverage Δ
[...imentId]/plots-and-tables/marker-heatmap/index.jsx](https://codecov.io/gh/hms-dbmi-cellenics/ui/pull/742/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hms-dbmi-cellenics#diff-c3JjL3BhZ2VzL2V4cGVyaW1lbnRzL1tleHBlcmltZW50SWRdL3Bsb3RzLWFuZC10YWJsZXMvbWFya2VyLWhlYXRtYXAvaW5kZXguanN4) 88.32% <50.00%> (+0.08%) ⬆️
src/components/plots/GeneReorderTool.jsx 97.43% <97.43%> (ø)
.../hierarchical-tree-genes/HierarchicalTreeGenes.jsx 100.00% <100.00%> (ø)
src/utils/array-move.js 100.00% <0.00%> (+30.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9d93d4...d8558a8. Read the comment docs.

@jszpila314 jszpila314 marked this pull request as ready for review June 19, 2022 13:27
Comment on lines 311 to 313
// Introduce testing for drag and drop if possible
// In Jest (jsdom) DragEvent and properties to do with rendering (widths, coordinates)
// don't exist -> not possible to test?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to test it one option could be to get the onDrop prop your HierarchicalTreeGenes component passed to Tree and then trigger it yourself.

   const tree = component.find('HierarchicalTreeGenes Tree');
    tree.getElement().props.onDrop(dropInfo);
    component.update();

It would involve using enzyme (which kind of breaks a little bit the idea/philosophy of using rtl, but since rtl doesn't support drag and drop I think it makes sense in this case).

This is just and idea because I read this comment, but it's not necessarily something you need to do.

src/components/plots/GeneReorderTool.jsx Outdated Show resolved Hide resolved
@ivababukova
Copy link
Member

@jszpila314, before implementing a new interface for the genes reorder functionality, did you try to make the existing Select component do the reorder?

I was looking at the Select component examples in Antd: https://ant.design/components/select/, this specific type:
Screenshot 2022-06-21 at 19 07 55
I also saw this Stackoverflow post that shows how to make each of the boxes draggable: https://stackoverflow.com/questions/49498684/cannot-get-antd-select-tags-to-be-draggable Have you tried this? Before implementing a new design, it is better to check if we can adjust the existing one to do what we want.

@ivababukova
Copy link
Member

My suggestion in my previous comment should work. I did a couple of small trials here: https://codesandbox.io/s/eager-archimedes-6uj4fk?file=/index.js What you need to do is to make each entry in config.selectedGenes in the MarkerGeneSelection component have a label with draggable: true in it. Basically, this thing for each gene entry in selectedGenes:

label: (
            <div
              onMouseDown={e => {
                e.stopPropagation();
              }}
            >
              <div
                draggable="true"
                onDragStart={() => {
                  message.info("Drag should work");
                }}
              >
                  <p>MY_GENE</p>
              </div>
            </div>
          )

You can create a new state variable transformedSelectedGenes that has this structure:

  const [transformedSelectedGenes, setTransformedSelectedGenes] = useState([]);

and have a function that populates the entries in this new variable and call it:

const populateEntries = () => {
  const newGenes = []
  
  config.selectedGenes.forEach((geneName) => {
    newGenes.append(
      {
              key: geneName,
              label: (
                <div
                  onMouseDown={e => {
                    e.stopPropagation();
                  }}
                >
                  <div
                    draggable="true"
                    onDragStart={() => {
                      message.info("Drag should work");
                    }}
                  >
                      <p>geneName</p>
                  </div>
                </div>
              )
     })
  })
}

setTransformedSelectedGenes(newGenes);
}

Then you pass transformedSelectedGenes to be the value of Space in MarkerGeneSelection:

value={transformedSelectedGenes}

And you should get the same UI, but draggable and reorderable. Afterwards, you will need to take a look and see if the backend takes this order into an account and if not, fix it.

This is just a pseudo-code, it won't compile if you paste it, but I hope that it helps with getting the idea of what I mean. I think that it is worth a try, it should work. There is no point implementing a brand new separate interface just for ordering genes if we can make the existing interface reorder them.

@jszpila314 jszpila314 merged commit 353a0db into master Jun 22, 2022
@jszpila314 jszpila314 deleted the reorder-genes-plots branch June 22, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants