0.17.146
API initializer. Will be called as soon as the webKnossos API is ready.
(number)
window.webknossos.apiReady(3).then((api) => {
// Your cool user script / wK plugin
const nodes = api.tracing.getAllNodes();
...
});
All tracing related API methods. This is the newest version of the API (version 3).
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.tracing.getActiveNodeId();
api.tracing.getActiveTreeId();
...
}
Returns all trees belonging to a tracing.
TreeMap
Deletes the node with nodeId in the tree with treeId
Centers the active node.
Completely resets the skeleton tracing.
Sets the comment for a node.
void
const activeNodeId = api.tracing.getActiveNodeId();
api.tracing.setCommentForNode("This is a branch point", activeNodeId);
Returns the comment for a given node and tree (optional).
(number)
(number)
(any)
Supplying the tree will provide a performance boost for looking up a comment.
string?
const comment = api.tracing.getCommentForNode(23);
// Provide a tree for lookup speed boost
const comment = api.tracing.getCommentForNode(23, api.getActiveTreeid());
Sets the name for a tree. If no tree id is given, the active tree is used.
api.tracing.setTreeName("Special tree", 1);
Changes the color of the referenced tree. Internally, a pre-defined array of colors is used which is why this function uses a colorIndex (between 0 and 500) instead of a proper color.
api.tracing.setTreeColorIndex(3, 10);
Changes the visibility of the referenced tree.
api.tracing.setTreeVisibility(3, false);
Sets the parent group of the referenced tree.
api.tracing.setTreeGroup(
3,
api.tracing.getTreeGroups.find(({ name }) => name === "My Tree Group").id,
);
Renames the group referenced by the provided id.
api.tracing.renameGroup(
3,
"New group name",
);
Saves the tracing and returns a promise (which you can call then
on or use await with).
api.tracing.save().then(() => ... );
await api.tracing.save();
Finishes the task and gets the next one. It returns a promise (which you can call then
on or use await with).
Don't assume that code after the finishAndGetNextTask call will be executed.
It can happen that there is no further task, in which case the user will be redirected to the dashboard.
Or the the page can be reloaded (e.g., if the dataset changed), which also means that no further JS code will
be executed in this site context.
api.tracing.finishAndGetNextTask().then(() => ... );
await api.tracing.finishAndGetNextTask();
Restart webKnossos without refreshing the page. Please prefer finishAndGetNextTask for user scripts since it does extra validation of the requested change and makes sure everything is saved etc.
(AnnotationType)
(string)
(ControlMode)
(Versions)
api.tracing.restart("Explorational", "5909b5aa3e0000d4009d4d15", "TRACE")
Reload tracing by reloading the entire page.
api.tracing.hardReload()
Increases the node radius of the given node by multiplying it with 1.05^delta. If no nodeId and/or treeId are provided, it defaults to the current tree and current node.
void
api.tracing.setNodeRadius(1)
Centers the given node. If no node is provided, the active node is centered.
(number)
void
api.tracing.centerNode()
Centers the 3D view.
void
api.tracing.centerTDView()
Starts an animation to center the given position. See setCameraPosition for a non-animated version of this function.
(Vector3)
Vector3
(boolean)
Boolean which decides whether the third dimension shall also be animated (defaults to true)
(Vector3)
Vector3 (optional) - Will only be noticeable in flight or oblique mode.
void
api.tracing.centerPositionAnimated([0, 0, 0])
Returns the current camera position.
Vector3
const currentPosition = api.tracing.getCameraPosition()
Sets the current camera position. See centerPositionAnimated for an animated version of this function.
(Vector3)
api.tracing.setCameraPosition([100, 100, 100])
Returns the active volume tool which is either "MOVE", "TRACE" or "BRUSH". Volume tracing only!
VolumeTool?
Sets the active volume tool which should be either "MOVE", "TRACE" or "BRUSH". Volume tracing only!
(VolumeTool)
Use this method to create a complete resolution pyramid by downsampling the lowest present mag (e.g., mag 1). This method will save the current changes and then reload the page after the downsampling has finished. This function can only be used for non-tasks.
Note that this invoking this method will not block the UI. Thus, user actions can be performed during the downsampling. The caller should prohibit this (e.g., by showing a not-closable modal during the process).
All binary data / layer related API methods.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.data.getLayerNames();
api.data.reloadBuckets(...);
...
}
Invalidates all downloaded buckets so that they are reloaded.
void
Sets a mapping for a given layer.
(string)
(Mapping)
const position = [123, 123, 123];
const segmentationLayerName = "segmentation";
const segmentId = await api.data.getDataValue(segmentationLayerName, position);
const treeId = api.tracing.getActiveTreeId();
const mapping = {[segmentId]: treeId}
api.data.setMapping(segmentationLayerName, mapping);
Returns raw binary data for a given layer, position and zoom level. If the zoom level is not provided, the first resolution will be used. If this resolution does not exist, the next existing resolution will be used. If the zoom level is provided and points to a not existent resolution, 0 will be returned.
Promise<number>
// Return the greyscale value for a bucket
const position = [123, 123, 123];
api.data.getDataValue("binary", position).then((greyscaleColor) => ...);
// Using the await keyword instead of the promise syntax
const greyscaleColor = await api.data.getDataValue("binary", position);
// Get the segmentation id for a segmentation layer
const segmentId = await api.data.getDataValue("segmentation", position);
Downloads a cuboid of raw data from a dataset (not tracing) layer. A new window is opened for the download - if that is not the case, please check your pop-up blocker.
Promise<void>
// Download a cuboid (from (0, 0, 0) to (100, 200, 100)) of raw data from the "segmentation" layer.
api.data.downloadRawDataCuboid("segmentation", [0,0,0], [100,200,100]);
Label voxels with the supplied value. Volume tracing only!
void
// Set the segmentation id for some voxels to 1337
api.data.labelVoxels([[1,1,1], [1,2,1], [2,1,1], [2,2,1]], 1337);
Returns the dataset's setting for the tracing view.
(($Keys<DatasetConfiguration> | OutdatedDatasetConfigurationKeys))
One of the following keys:
const segmentationOpacity = api.data.getConfiguration("segmentationOpacity");
Set the dataset's setting for the tracing view.
(($Keys<DatasetConfiguration> | OutdatedDatasetConfigurationKeys))
Same keys as for getConfiguration()
(any)
api.data.setConfiguration("segmentationOpacity", 20);
All user configuration related API methods.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.user.getConfiguration(...);
api.user.setConfiguration(...);
...
}
Returns the user's setting for the tracing view.
($Keys<UserConfiguration>)
One of the following keys:
const keyboardDelay = api.user.getConfiguration("keyboardDelay");
Set the user's setting for the tracing view.
($Keys<UserConfiguration>)
Same keys as for getConfiguration()
(any)
api.user.setConfiguration("keyboardDelay", 20);
Utility API methods to control wK.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.utils.sleep(...);
api.utils.showToast(...);
...
}
Show a toast to the user. Returns a function which can be used to remove the toast again.
(string)
Can be one of the following: "info", "warning", "success" or "error"
(string)
The message string you want to show
(number)
Time period in milliseconds after which the toast will be hidden. Time is measured as soon as the user moves the mouse. A value of 0 means that the toast will only hide by clicking on it's X button.
Function?
// Show a toast for 5 seconds
const removeToast = api.utils.showToast("info", "You just got toasted", false, 5000);
// ... optionally:
// removeToast();
Overwrite existing wK actions. wK uses Redux actions to trigger any changes to the application state.
(string)
The name of the action you wish to override:
(function (store, next, originalAction))
Your new implementation for the method in question. Receives the central wK store, a callback to fire the next/original action and the original action.
function ()
:
A function used to unregister the overwriteFunction
api.utils.registerOverwrite("MERGE_TREES", (store, next, originalAction) => {
// ... do stuff before the original function...
next(originalAction);
// ... do something after the original function ...
});