new Viewer(parentOrElementOrDocument, chemObj, renderType, viewerConfigs)
An universal viewer widget for chem objects (especially molecules).
Parameters:
Name | Type | Description |
---|---|---|
parentOrElementOrDocument |
Variant | |
chemObj |
Kekule.ChemObject | |
renderType |
Int | Display in 2D or 3D. Value from Kekule.Render.RendererType. |
viewerConfigs |
Kekule.ChemWidget.ChemObjDisplayerConfigs |
Properties:
Name | Type | Description |
---|---|---|
renderType |
Int | Display in 2D or 3D. Value from Kekule.Render.RendererType. Read only. |
chemObj |
Kekule.ChemObject | Object to be drawn. Set this property will repaint the client. |
chemObjLoaded |
Bool | Whether the chemObj is successful loaded and drawn in viewer. //@property {Object} renderConfigs Configuration for rendering. // This property should be an instance of Kekule.Render.Render2DConfigs or {@link Kekule.Render.Render3DConfigs} //@property {Hash} drawOptions Options to draw object. //@property {Float} zoom Zoom ratio to draw chem object. Note this setting will overwrite drawOptions.zoom. //@property {Bool} autoSize Whether the widget change its size to fit the dimension of chem object. //@property {Int} padding Padding between chem object and edge of widget, in px. Only works when autoSize is true. |
caption |
String | Caption of viewer. |
showCaption |
Bool | Whether show caption below or above viewer. |
captionPos |
Int | Value from Kekule.Widget.Position, now only TOP and BOTTOM are usable. |
autoCaption |
Bool | Set caption automatically by chemObj info. //@property {Bool} liveUpdate Whether viewer repaint itself automatically when containing chem object changed. |
enableDirectInteraction |
Bool | Whether interact without tool button is allowed (e.g., zoom/rotate by mouse). |
enableTouchInteraction |
Bool | Whether touch interaction is allowed. Note if enableDirectInteraction is false, touch interaction will also be disabled. |
enableRestraintRotation3D |
Bool | Set to true to rotate only on one axis of X/Y/Z when the starting point is near edge of viewer. |
restraintRotation3DEdgeRatio |
Float | |
enableEdit |
Bool | Whether a edit button is shown in toolbar to edit object in viewer. Works only in 2D mode. |
modalEdit |
Bool | Whether opens a modal dialog when editting object in viewer. |
enableEditFromVoid |
Bool | Whether editor can be launched even if viewer is empty. |
editorProperties |
Hash | Hash object to set properties of popup editor. |
restrainEditorWithCurrObj |
Bool | If true, the editor popuped can only edit current object in viewer (and add new objects is disabled). If false, the editor can do everything like a normal composer, viewer will load objects in composer after editting (and will not keep the original object in viewer). |
shareEditorInstance |
Bool | If true, all viewers in one document will shares one editor. This setting may reduce the cost of creating many composer widgets. |
toolButtons |
Array | buttons in interaction tool bar. This is a array of predefined strings, e.g.: ['zoomIn', 'zoomOut', 'resetZoom', 'molDisplayType', ...]. In the array, complex hash can also be used to add custom buttons, e.g.: [ 'zoomIn', 'zoomOut', {'name': 'myCustomButton1', 'widgetClass': 'Kekule.Widget.Button', 'action': actionClass}, {'name': 'myCustomButton2', 'htmlClass': 'MyClass' 'caption': 'My Button', 'hint': 'My Hint', '#execute': function(){ ... }}, ] most hash fields are similar to the param of Kekule.Widget.Utils.createFromHash. If this property is not set, default buttons will be used. |
enableToolbar |
Bool | Whether show tool bar in viewer. |
toolbarPos |
Int | Value from Kekule.Widget.Position, position of toolbar in viewer. For example, set this property to TOP will make toolbar shows in the center below the top edge of viewer, TOP_RIGHT will make the toolbar shows at the top right corner. Default value is BOTTOM_RIGHT. Set this property to AUTO, viewer will set toolbar position (including margin) automatically. |
toolbarMarginHorizontal |
Int | Horizontal margin of toolbar to viewer edge, in px. Negative value means toolbar outside viewer. |
toolbarMarginVertical |
Int | Vertical margin of toolbar to viewer edge, in px. Negative value means toolbar outside viewer. //@property {Array} toolbarShowEvents Events to cause the display of toolbar. If set to null, the toolbar will always be visible. |
toolbarEvokeModes |
Array | Interaction modes to show the toolbar. Array item values should from Kekule.Widget.EvokeMode. Set enableToolbar to true and include Kekule.Widget.EvokeMode.ALWAYS will always show the toolbar. |
toolbarRevokeModes |
Array | Interaction modes to hide the toolbar. Array item values should from Kekule.Widget.EvokeMode. |
toolbarRevokeTimeout |
Int | Toolbar should be hidden after how many milliseconds after shown. Only available when Kekule.Widget.EvokeMode.EVOKEE_TIMEOUT or {@link Kekule.Widget.EvokeMode.EVOKER_TIMEOUT} in toolbarRevokeModes. |
allowedMolDisplayTypes |
Array | Molecule types can be changed in tool bar. |
Extends
Methods
-
allowAutoSize() → {Bool}
-
Whether current painter can meet the requirement of auto size.
- Inherited From:
- Source:
Returns:
- Type
- Bool
-
backgroundColorChanged()
-
Called after background color is changed, should repaint the context.
-
beginContinuousRepainting()
-
Notify the displayer that in following process, continuous repainting will start and auto size should be disabled. After this phase, endContinuousRepainting() must be called.
-
canModifyPartialGraphic() → {Bool}
-
Whether context and draw bridge can modify existing graphic content.
- Inherited From:
- Source:
Returns:
- Type
- Bool
-
captionIsShown()
-
Returns whether the caption is actually displayed.
-
changeContextDimension(newDimension) → {Bool}
-
Change the dimension of context.
Parameters:
Name Type Description newDimension
Hash - Inherited From:
- Source:
Returns:
Return true if dimension change successfully.- Type
- Bool
-
endContinuousRepainting()
-
Notify the displayer that continuous phase has ended, turn into normal mode.
-
exportToDataUri(dataType, options) → {String}
-
Export drawing content in viewer to a data URL for tag to use.
Parameters:
Name Type Description dataType
String Type of image data, e.g. 'image/png'. options
Hash Export options, usually this is a number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp. - Inherited From:
- Source:
Returns:
- Type
- String
-
getAllowEditing()
-
Returns whether editor can be lauched in current viewer.
-
getBackgroundColorOfType(renderType) → {String}
-
Returns background color used for a special renderType.
Parameters:
Name Type Description renderType
Int - Inherited From:
- Source:
Returns:
- Type
- String
-
getContextDimension() → {Hash}
-
Returns dimension of context.
- Inherited From:
- Source:
Returns:
- Type
- Hash
-
getCoordMode() → {Int}
-
Returns coord mode according to current renderType.
- Inherited From:
- Source:
Returns:
- Type
- Int
-
getCurr2DRotationAngle() → {Float}
-
Returns current 2D rotation angle (in arc).
Returns:
- Type
- Float
-
getCurr3DRotationInfo() → {Hash}
-
Returns current 3D rotation info.
Returns:
{rotateMatrix, rotateX, rotateY, rotateZ, rotateAngle, rotateAxisVector}- Type
- Hash
-
getCurrMoleculeDisplayType() → {Int}
-
Returns current molecule display type.
- Inherited From:
- Source:
Returns:
- Type
- Int
-
getCurrZoom() → {Float}
-
Returns zoom property in drawOptions.
- Inherited From:
- Source:
Returns:
- Type
- Float
-
getDrawContextParentElem()
-
Returns parent element to create draw context inside. Descendants can override this method.
-
initialize()
-
isPainting() → {Bool}
-
Returns whether in the painting process.
- Inherited From:
- Source:
Returns:
- Type
- Bool
-
isToolbarEmbedded() → {Bool}
-
Return whether toolbarParentElem is not set the the toolbar is directly embedded in viewer itself.
Returns:
- Type
- Bool
-
load(chemObj)
-
Load and display chemObj in viewer
Parameters:
Name Type Description chemObj
Kekule.ChemObject - Inherited From:
- Source:
-
loadFromData(data, mimeType, fromUrlOrFileName)
-
Load chem object from data of special MIME type or file format.
Parameters:
Name Type Description data
Variant Usually text content. mimeType
String fromUrlOrFileName
String From which file or url is this data loaded. - Inherited From:
- Source:
-
loadFromFile(file)
-
Load chem object from file object. NOTE: browser must support File Reader API to use this method.
Parameters:
Name Type Description file
File - Inherited From:
- Source:
-
openEditor(callerWidget)
-
Open a popup editor to modify displayed object.
Parameters:
Name Type Description callerWidget
Kekule.Widget.BaseWidget Who invokes edit action, default is the viewer itself. -
prepareSaveData()
-
Called before obj is saved. Descendants can overrride this method.
-
repaint(overrideOptions)
-
Repaint the context with current chem object.
Parameters:
Name Type Description overrideOptions
Hash Transform options to do repainting. If this param is set to null, all transform options will be recalculated. If overrideOptions.preserveTransformOptions is true, transform options remains same as last painting process (rather than recalculated). - Inherited From:
- Source:
-
resetDisplay()
-
Reset displayer to initial state (no zoom, rotation and so on).
- Inherited From:
- Source:
-
resetView()
-
Reset viewer to initial state (no zoom, rotation and so on).
-
resetZoom()
-
Reset to normal size.
- Inherited From:
- Source:
-
rotate2DBy(delta, suspendRendering)
-
Do a 2D rotation base on delta.
Parameters:
Name Type Description delta
Float In arc. suspendRendering
Bool Set this to true if a immediate repaint is not needed. -
rotate2DTo(angle, suspendRendering)
-
Do a 2D rotation to angle.
Parameters:
Name Type Description angle
Float In arc. suspendRendering
Bool Set this to true if a immediate repaint is not needed. -
rotate3DBy(deltaX, deltaY, deltaZ, suspendRendering)
-
Do a 3D rotation base on delta.
Parameters:
Name Type Description deltaX
Float In arc. deltaY
Float In arc. deltaZ
Float In arc. suspendRendering
Bool Set this to true if a immediate repaint is not needed. -
rotate3DByAxis(angle, axisVector, suspendRendering)
-
Do a 3D rotation around axis.
Parameters:
Name Type Description angle
Float In arc. axisVector
Hash Axis vector coord. suspendRendering
Bool Set this to true if a immediate repaint is not needed. -
saveData(formatId, dataType, obj) → {Variant}
-
Save loaded chem object to data.
Parameters:
Name Type Description formatId
String dataType
Int Text or binary. Set null to use default type. obj
Kekule.ChemObject Object to save, default is current chemObj loaded in displayer. - Inherited From:
- Source:
Returns:
Saved data.- Type
- Variant
-
setBackgroundColorOfType(color, renderType)
-
Set background color used for a special renderType.
Parameters:
Name Type Description color
String renderType
Int -
setCoordMode(coordMode)
-
Set renderType according to coord mode.
Parameters:
Name Type Description coordMode
Int - Inherited From:
- Source:
-
setHideHydrogens(newType)
-
Hide or show all hydrogen atoms in 3D model.
Parameters:
Name Type Description newType
Int Value from Kekule.Render.Molecule2DDisplayType or {@link Kekule.Render.Molecule3DDisplayType}. -
setRotate3DMatrix(matrix, suspendRendering)
-
Set 3D rotation matrix.
Parameters:
Name Type Description matrix
Array A 4X4 rotation matrix. suspendRendering
Bool Set this to true if a immediate repaint is not needed. -
updateMenu()
-
Update menu in viewer.
-
updateToolbar()
-
Update toolbar in viewer.
-
updateUiComps()
-
Update toolbar and menu in viewer.
-
zoomIn()
-
Zoom in.
- Inherited From:
- Source:
-
zoomOut()
-
Zoom out.
- Inherited From:
- Source:
-
zoomTo(value, suspendRendering)
-
Zoom to a specified ratio
Parameters:
Name Type Description value
Float suspendRendering
Bool Set this to true if a immediate repaint is not needed. - Inherited From:
- Source:
Events
-
load
-
Invoked when the an chem object (or null) is loaded into the displayer. event param of it has one fields: {obj: Object}
- Inherited From:
- Source: