statgen / locuszoom

A Javascript/d3 embeddable plugin for interactively visualizing statistical genetic data from customizable sources.
https://statgen.github.io/locuszoom/
MIT License
154 stars 29 forks source link

[Question] Update a `set_state` widget value when the state changes #273

Closed sir4ur0n closed 2 years ago

sir4ur0n commented 2 years ago

Currently it seems that a set_state widget is a one-way binding: a selection from the user changes the state.

However the reverse binding does not happen: when the state changes, it is not reflected back in the widget selected/displayed value.

  1. Is this intentional?
  2. If not, but there is no reason not to: how about adding this reverse binding by default, or behind a boolean property?
  3. If not, and there are reasons not to that I don't have in mind: how do you recommend I achieve this double-binding please? :pray:

My use case: I have a state field (in this case, chr) which can either be selected directly by the user (using the set_state widget), or which can be updated by JS code if the user selects another gene in a custom field (e.g. switching from gene TMEM18 (chromosome 2) to TERT (chromosome 5) updates state.chr, but the widget still displays 2).

abought commented 2 years ago

Hmm. This does appear to be an oversight, but can be changed. Over time, we've added more support for external control over the plot, which has meant adding support for the idea that the value can be changed in more than one way.

I've pushed a commit showing how this is done, and, actually doing it as a default feature of the set_state widget. It's not part of an official release yet, though it should mostly work for your needs. I'll try to make time for more thorough testing in the next week ish.

https://github.com/statgen/locuszoom/commit/1bdbc019357db351d264557d6b023c97d0e1a929

Internally, the key idea is that many changes are communicated by events, so an update can be achieved by listening to state_changed events.

sir4ur0n commented 2 years ago

@abought thank you so much for the fast answer and fix :bow:

For what it's worth, I gave it a shot using npm install https://github.com/statgen/locuszoom and I confirm it works in my use case now :+1:

abought commented 2 years ago

Thanks! If you ever release your tool publicly, I'd be curious to take see how people are using LZ in the wild. :) Some day it would be nice to create an example gallery.

sir4ur0n commented 2 years ago

The code is currently closed-source but I mentioned your question to our stakeholders, we might make it open or partially open source in the future, I/we will let you know!

abought commented 2 years ago

Open source would certainly be an extra bonus! I had been thinking of just a URL- showcasing different ways that people present their public datasets. It's nice to see what features people find useful, and I'll often try to invest extra effort improving what people use most.

Open source is nice, but I'm also a big fan of open data. I admit this is not always easy to pull off- we depend on our scientific collaborators to find the right balance for their patients and colleagues.

Good luck with your projects! Let us know if we can ever assist or improve the tools available to the community.