Code Monkey home page Code Monkey logo

Comments (3)

stuarteberg avatar stuarteberg commented on May 30, 2024

Try this:

with viewer.txn() as s:
    s.layers['my-layer-name'].segments = ['16429', '18022']

Edit: Oops, that's an example for the Python API. Now I notice that you mentioned JS in the title. Someone else will need to chime in.

from neuroglancer.

stuarteberg avatar stuarteberg commented on May 30, 2024

Your example code works for me, at least in my browser's developer tools console...

temp_state = viewer.state.toJSON();
temp_state['layers'][1]['segments'] = ['26650', '11022'];
viewer.state.restoreState(temp_state);

(It does return undefined, but the viewer updates correctly.)


One thing to double-check: The index of the layer (e.g. temp_state['layers'][10] should NOT match what you see in the UI, since obviously the JSON layers list starts with item 0, whereas the UI starts counting at 1. Are you sure you're updating the correct layer? And be sure you're looking at the complete layer list (including "archived" layers, not just the ones shown at the top of the screen).


BTW, I notice that neuroglancer's own JSON editing UI also calls reset() before applying the new state, though I don't know why that's necessary:

private applyChanges() {
if (this.parsedValue !== null) {
this.viewer.state.reset();
this.viewer.state.restoreState(this.parsedValue);
}
this.applyButton.disabled = true;
}

from neuroglancer.

dvanselow avatar dvanselow commented on May 30, 2024

Ah! working! @stuarteberg - I had two state variables that were very close to the same name and was updating with the incorrect one. Was also thrown off by the undefined response. interesting about the reset.

This has to be the one of the most helpful, quickest replying community. Thanks much!

from neuroglancer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.