Skip to content

Commit

Permalink
Merge pull request #584 from thewtex/api-hypha
Browse files Browse the repository at this point in the history
feat(ImJoyPluginAPI): Change to a class
  • Loading branch information
thewtex authored Oct 5, 2022
2 parents cb5744a + 0b3c1b9 commit 266dbed
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 77 deletions.
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
itkVtkViewer.imJoyCodecs.forEach((codec) => {
api.registerCodec(codec)
})
api.export(itkVtkViewer.imJoyPluginAPI)
api.export(new itkVtkViewer.ImJoyPluginAPI())
api.log('itk-vtk-viewer loaded successfully.')
}

Expand Down
147 changes: 73 additions & 74 deletions src/imJoyPluginAPI.js → src/ImJoyPluginAPI.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const imJoyPluginAPI = {
setup() {
class ImJoyPluginAPI {
async setup() {
this.viewer = null
itkVtkViewer.createViewerFromLocalFiles(container).then(viewer => {
this.viewer = viewer
})
},
}

async run(ctx) {
if (ctx.data && ctx.data.image) {
Expand Down Expand Up @@ -53,7 +53,7 @@ const imJoyPluginAPI = {
config: ctx.config,
})
}
},
}

async setPointSets(pointSets) {
if (!Array.isArray(pointSets)) pointSets = [pointSets]
Expand All @@ -70,11 +70,11 @@ const imJoyPluginAPI = {
} else {
await this.viewer.setPointSets(pointSets)
}
},
}

async captureImage() {
return await this.viewer.captureImage()
},
}

async setImage(image) {
const multiscaleImage = await itkVtkViewer.utils.toMultiscaleSpatialImage(
Expand All @@ -92,11 +92,11 @@ const imJoyPluginAPI = {
} else {
await this.viewer.setImage(multiscaleImage)
}
},
}

getImage(name) {
return this.viewer.getImage(name)
},
}

async setLabelImage(labelImage) {
if (this.viewer === null) {
Expand All @@ -110,250 +110,249 @@ const imJoyPluginAPI = {
} else {
await this.viewer.setLabelImage(labelImage)
}
},
}

getLabelImage() {
return this.viewer.getLabelImage()
},
}

registerEventListener(event, callback) {
this.viewer.on(event, callback)
},
}

getConfig() {
return this.viewer.getConfig()
},
}

setRenderingViewContainerStyle(containerStyle) {
this.viewer.setRenderingViewContainerStyle(containerStyle)
},
}
getRenderingViewStyle() {
return this.viewer.getRenderingViewStyle()
},
}

setBackgroundColor(bgColor) {
this.viewer.setBackgroundColor(bgColor)
},
}
getBackgroundColor() {
return this.viewer.getBackgroundColor()
},
}

setUnits(units) {
this.viewer.setUnits(units)
},
}
getUnits() {
return this.viewer.getUnits()
},
}

setUICollapsed(collapsed) {
this.viewer.setUICollapsed(collapsed)
},
}
getUICollapsed() {
return this.viewer.getUICollapsed()
},
}

setRotateEnabled(enabled) {
this.viewer.setRotateEnabled(enabled)
},
}
getRotateEnabled() {
return this.viewer.getRotateEnabled()
},
}

setAnnotationsEnabled(enabled) {
this.viewer.setAnnotationsEnabled(enabled)
},
}
getAnnotationsEnabled() {
return this.viewer.getAnnotationsEnabled()
},
}

setAxesEnabled(enabled) {
this.viewer.setAxesEnabled(enabled)
},
}
getAxesEnabled() {
return this.viewer.getAxesEnabled()
},
}

setXSlice(position) {
this.viewer.setXSlice(position)
},
}

getXSlice() {
return this.viewer.getXSlice()
},
}

setYSlice(position) {
this.viewer.setYSlice(position)
},
}

getYSlice() {
return this.viewer.getYSlice()
},
}

setZSlice(position) {
this.viewer.setZSlice(position)
},

}
getZSlice() {
return this.viewer.getZSlice()
},
}

setViewMode(mode) {
this.viewer.setViewMode(mode)
},
}
getViewMode() {
return this.viewer.getViewMode()
},
}

getLayerNames() {
return this.viewer.getLayerNames()
},
}

setLayerVisibility(visible, name) {
this.viewer.setLayerVisibility(visible, name)
},
}

getLayerVisibility(name) {
return this.viewer.getLayerVisibility(name)
},
}

selectLayer(name) {
this.viewer.selectLayer(name)
},
}

setImageComponentVisibility(visibility, component, name) {
this.viewer.setImageComponentVisibility(visibility, component, name)
},
}

getImageComponentVisibility(component, name) {
return this.viewer.getImageComponentVisibility(component, name)
},
}

setImageInterpolationEnabled(enabled) {
this.viewer.setImageInterpolationEnabled(enabled)
},
}
getImageInterpolationEnabled() {
return this.viewer.getImageInterpolationEnabled()
},
}

setImageColorRange(range, component, name) {
this.viewer.setImageColorRange(range, component, name)
},
}

getImageColorRange(component, name) {
return this.viewer.getImageColorRange(component, name)
},
}

setImageColorRangeBounds(bounds, component, name) {
this.viewer.setImageColorRangeBounds(bounds, component, name)
},
}

getImageColorRangeBounds(component, name) {
return this.viewer.getImageColorRangeBounds(component, name)
},
}

setImageColorMap(colorMap, component, name) {
this.viewer.setImageColorMap(colorMap, component, name)
},
}

getImageColorMap(component, name) {
return this.viewer.getImageColorMap(component, name)
},
}

setImagePiecewiseFunctionGaussians(gaussians, component, name) {
this.viewer.setImagePiecewiseFunctionGaussians(gaussians, component, name)
},
}

getImagePiecewiseFunctionGaussians(component, name) {
return this.viewer.getImagePiecewiseFunctionGaussians(component, name)
},
}

setImageShadowEnabled(shadow, name) {
this.viewer.setImageShadowEnabled(shadow, name)
},
}

getImageShadowEnabled(name) {
return this.viewer.getImageShadowEnabled(name)
},
}

setImageGradientOpacity(opacity, name) {
this.viewer.setImageGradientOpacity(opacity, name)
},
}

getImageGradientOpacity(name) {
return this.viewer.getImageGradientOpacity(name)
},
}

setImageGradientOpacityScale(scale, name) {
this.viewer.setImageGradientOpacityScale(scale, name)
},
}

getImageGradientOpacityScale(name) {
return this.viewer.getImageGradientOpacityScale(name)
},
}

setImageVolumeSampleDistance(distance, name) {
this.viewer.setImageVolumeSampleDistance(distance, name)
},
}

getImageVolumeSampleDistance(name) {
return this.viewer.getImageVolumeSampleDistance(name)
},
}

setImageBlendMode(mode, name) {
this.viewer.setImageBlendMode(mode, name)
},
}

getImageBlendMode(name) {
return this.viewer.getImageBlendMode(name)
},
}

setLabelImageLookupTable(lookupTable, name) {
this.viewer.setLabelImageLookupTable(lookupTable, name)
},
}

getLabelImageLookupTable(name) {
return this.viewer.getLabelImageLookupTable(name)
},
}

setLabelImageBlend(blend, name) {
this.viewer.setLabelImageBlend(blend, name)
},
}

getLabelImageBlend(name) {
return this.viewer.getLabelImageBlend(name)
},
}

setLabelImageLabelNames(labelNames, name) {
this.viewer.setLabelImageLabelNames(labelNames, name)
},
}

getLabelImageLabelNames(name) {
return this.viewer.getLabelImageLabelNames(name)
},
}

setLabelImageWeights(weights, name) {
this.viewer.setLabelImageWeights(weights, name)
},
}

getLabelImageWeights(name) {
return this.viewer.getLabelImageWeights(name)
},
}

setCroppingPlanesEnabled(enabled) {
this.viewer.setCroppingPlanesEnabled(enabled)
},
}

getCroppingPlanesEnabled() {
return this.viewer.getCroppingPlanesEnabled()
},
}

setCroppingPlanes(croppingPlanes) {
this.viewer.setCroppingPlanes(croppingPlanes)
},
}

getCroppingPlanes() {
return this.viewer.getCroppingPlanes()
},
}
}

export default imJoyPluginAPI
export default ImJoyPluginAPI
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import toMultiscaleSpatialImage from './IO/toMultiscaleSpatialImage'
import { ConglomerateMultiscaleSpatialImage } from './IO/ConglomerateMultiscaleSpatialImage'
import { isZarr } from './IO/ZarrMultiscaleSpatialImage'

import imJoyPluginAPI from './imJoyPluginAPI'
import ImJoyPluginAPI from './ImJoyPluginAPI.js'
import imJoyCodecs from './imJoyCodecs.js'
import packageJson from '../package.json'
const { version } = packageJson

let doNotInitViewers = false

export { version }
export { imJoyPluginAPI }
export { ImJoyPluginAPI }
export { imJoyCodecs }
export { default as createViewer } from './createViewer'
import * as utils from './utils.js'
Expand Down

0 comments on commit 266dbed

Please sign in to comment.