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

refactor: move 'verticalAlign' object to 'view' object #2135

Merged
merged 4 commits into from
Feb 16, 2023

Conversation

hamed-musallam
Copy link
Member

@hamed-musallam hamed-musallam commented Feb 9, 2023

Tasks

Preview Give feedback

@hamed-musallam hamed-musallam linked an issue Feb 9, 2023 that may be closed by this pull request
@hamed-musallam hamed-musallam force-pushed the refactor-alignment-property-to-view branch from ef95e79 to a759fe2 Compare February 9, 2023 12:34
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 9, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: bf3c2d1
Status: ✅  Deploy successful!
Preview URL: https://553d6003.nmrium.pages.dev
Branch Preview URL: https://refactor-alignment-property-.nmrium.pages.dev

View logs

@hamed-musallam hamed-musallam force-pushed the refactor-alignment-property-to-view branch from 2895e0c to d4d9b75 Compare February 9, 2023 19:04
@hamed-musallam hamed-musallam marked this pull request as ready for review February 9, 2023 19:12
@hamed-musallam hamed-musallam force-pushed the refactor-alignment-property-to-view branch from e8f6311 to 72409e0 Compare February 16, 2023 07:04
@hamed-musallam hamed-musallam merged commit 35166ea into main Feb 16, 2023
@hamed-musallam hamed-musallam deleted the refactor-alignment-property-to-view branch February 16, 2023 11:11
* options to control spectra vertical alignment
* @default 'bottom'
*/
verticalAlign: Partial<Record<Nuclei, VerticalAlignment>>;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we have a more "generic" Record at this level with an object of properties? I expect more values to depend on the nucleus and having a separate record for each of them seems complicated.

Copy link
Member Author

@hamed-musallam hamed-musallam Feb 16, 2023

Choose a reason for hiding this comment

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

Actually, we use it in different places:

  spectra: {
    /**
     * active spectrum id per nucleus
     * @default {}
     */
    activeSpectra: Record<Nucleus , ActiveSpectrum[] | null>;
    },
verticalAlign: Partial<Record<Nuclei, VerticalAlignment>>

but I think that it is more precise and specific to have it like that. for example, verticalAlign is only for 1d so it does not make sense to have this value for a 2d nucleus

 { "1H,1H" :{
     verticalAlign,
     activeSpectra
     }
   }

Copy link
Member Author

Choose a reason for hiding this comment

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

@targos

What do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

Then what about an object for all 1D-specific parameters which depend on the nucleus?

Copy link
Member Author

Choose a reason for hiding this comment

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

@targos

Yes, it could be like that, let's assume we have

view:{
 1H: {
   verticalAlign,
 activeSpectrum,
    ...etc
  },

},

in above structure how I can force specific type for the object based on the Nucleus ?

Or

view1D:{
    1H: {
       verticalAlign,
     activeSpectrum,
        ...etc
      },
}

view2D:{
  "1H,1H":{
     activeSpectrum,
     ...etc
    }
}

on the other hand, we will consider that all object is not optional so we should initiate the object with an initial value, which could be null . This happens on the first time, we attend to store a value, for example, the active spectrum and the object 1H object does not exist.

{
  1H: { 
         verticalAlign: "bottom",
          activeSpectrum:  1,
          x:null,
          y: null,
         ...etc
          }
}

Copy link
Member

Choose a reason for hiding this comment

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

I think we should avoid mixing 1D and 2D when they have different interfaces, so my preference goes towards view1D/view2D.

Copy link
Member Author

@hamed-musallam hamed-musallam Feb 17, 2023

Choose a reason for hiding this comment

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

Ok, then we should have 3 objects

view: {
// which contains all objects that are not grouped by the nucleus.
 },
view1D,
view2D

What do think about the other object that is per spectrum, for example,

{
  ranges: Array<RangeToolState>;
  zones: Array<ZoneToolState>;
  /**
   * peaks view property
   * where the key is the id of the spectrum
   */
  peaks: Record<string, PeaksViewState>;   
  zoom: {
    levels: ContoursLevels; // for 2D only
  }
}

Copy link
Member Author

@hamed-musallam hamed-musallam Feb 17, 2023

Choose a reason for hiding this comment

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

What do you think about this structure ?

view: {
  nuclei:{
    "1D":{
      "1H":{
         verticalAlign: "bottom",
         activeSpectra:"",
         selectReferences:null,
        }
     },
     "2D":{
     "1H,1H":{
         activeSpectra:"",
         selectReferences:null,
        }
       }
   },
  spectra: {
    /**
     * current select tab (nucleus)
     * @default null
     */
    activeTab: string;

    /**
     * show the spectra legend and the intensity
     * @default false
     */
    showLegend: boolean;
   }
}

Copy link
Member

Choose a reason for hiding this comment

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

Ok, then we should have 3 objects

No, we should have everything inside of view:

view: {
  nuclei1D: { // Record<string, ViewNuclei1D>
    '1H': {},
    '13C': {},
  },
  nuclei2D: { // Record<string, ViewNuclei2D>
    '1H,1H': {},
  },
  spectra1D: { // Record<string, ViewSpectra1D>
    uuid1: {},
    uuid2: {},
  },
  spectra2D: { // Record<string, ViewSpectra2D>
    uuid3: {},
    uuid4: {},
  },
  prop1, // other settings that don't depend on nucleus or spectrum
  prop2,
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@targos thanks, we need to consider this refactoring before having a new release of NMRium otherwise we have to write a migration script

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.

Move stack and center properties in view
2 participants