informatics-isi-edu / openseadragon-viewer

2D viewer with openseadragon
Apache License 2.0
5 stars 2 forks source link

Display channel names on top of the image #88

Closed RFSH closed 2 years ago

RFSH commented 3 years ago

This PR will add basic channel labels on top of the image. The labels will be responsive based on the selected hue value.

What's left:

We still need to discuss the following:

Related issue: #87

rastogi-bhavya commented 3 years ago

Channel Names over OSD

The set of visible channels are shown over the OSD with the following properties

  1. Only a limited number of channels names will be shown (under the present conditions the names which can fit in 3 lines)

  2. If all the channel names can't be shown, then ..., in white color, would be shown at the end of the last line.

  3. The color of the channel name text would be the same as the channel name itself.

  4. Each line showing the channels will have a black background, and 2 consecutive lines would have space between them.

Channel Names in the screenshot

The channel names that appear in the screenshot have the same implementation as those that appear over the OSD, and therefore follow the same logic. The only difference is that, they are added using canvas logic, instead of css.

Implementation

  1. Create an array containing the channel properties (name, channel_color) for each visible channel.

  2. Determine the font size of the text. This is done by starting from a max value and decrementing to a certain min value, until all the channel names are fit in the 3 lines. For eg., we start at font: 20, and find out that all the names can't fit. We then decrease the font by 2, (new font: 18), and do the same check. This is done until either the content fits or we reach the min value.

  3. There could be long channel names that won't fit into a single line. For such cases we are updating the channel names that are displayed, by removing 1 character from the RHS, until the name fits and adding ... at the end, indicating that the channel name have been truncated.

  4. After updating the channel names we add channel names to the lines.

rastogi-bhavya commented 3 years ago

Test for: https://dev.gudmap.org/~brastogi/chaise/viewer/#2/Gene_Expression:Image/id=14-47YP?url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c0.ome.tif%3AP2QULUFK3TNMLB5HARK5ROCQN4/info.json&channelName=DAPI&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=Alexa_Fluor_488&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c2.ome.tif%3AOFSWNELKI4ZKDJYKDMRI7GXWVI/info.json&channelName=Alexa_Fluor_555&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c3.ome.tif%3A7227BA2GTHPFIYG2MGHKNQMBVQ/info.json&channelName=Alexa_Fluor_647&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c0.ome.tif%3AP2QULUFK3TNMLB5HARK5ROCQN4/info.json&channelName=Hoechst&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=mcherry&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=Rhodamine&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c0.ome.tif%3AP2QULUFK3TNMLB5HARK5ROCQN4/info.json&channelName=DAPI&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=Alexa_Fluor_488&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c2.ome.tif%3AOFSWNELKI4ZKDJYKDMRI7GXWVI/info.json&channelName=Alexa_Fluor_555&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c3.ome.tif%3A7227BA2GTHPFIYG2MGHKNQMBVQ/info.json&channelName=Alexa_Fluor_647&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c0.ome.tif%3AP2QULUFK3TNMLB5HARK5ROCQN4/info.json&channelName=Hoechst&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=mcherry&url=/iiif/2/https%3A%2F%2Fdev.gudmap.org%2Fhatrac%2Fresources%2Fprocessed_images%2F2018%2F10%2F14-47YP%2F20140810-hKD8.6wWTC8.6-JAM-0-33-000-s0-z2-c1.ome.tif%3AZLRDDVZJPIPPFJKZ5ZI2IXFZHI/info.json&channelName=Rhodamine

Make sure that screenshot and what we are displaying are the same.

RFSH commented 3 years ago

Now that the functionality is in place, you should spend some time refactoring and documenting,

  1. Having two sets of functions that are doing almost the same thing is confusing and hard to maintain. So either:

    • Merge them into one function and pass a parameter to the function to do things differently based on the parameter.
    • Extract the common functionality into one function so the two functions call that one.

    Based on what I saw, doing the first approach should work.

  2. I don't like attaching these functions directly to viewer or Utils. Their names are very general and it could lead to more confusion. Assuming that you'd do what I suggested in the previous step, you could create a wrapper for all these function in the utils, so in utils.js:

    function Utils() {
      this.channelNameOverlay = new ChannelNameOverlayUtils();
    }
    
    function ChannelNameOverlayUtils() {}
    
    ChannelNameOverlayUtils.prototype.addChannelNames = function () {
    
    }
    
    // the rest of functions go here...
    

    And now in viewer you would use this by doing this.utils.channelNameOverlay.addChannelNames and in Utils you could do this.channelNameOverlay.addChannelNames