VisioShape
VisioShape
inherits from VisioSheetObject abstract class, exposing an API used
in cells manipulation: getOwnCellNames
, getCell
, setCell
and removeCell
.
visioShape.fromMaster(master, page)
Return a new VisioShape
created from a provided master
and on a provided page
.
The fromMaster()
example shows a typical case when a loaded archive is used as an export target, so
it's used both as a source of masters, and the target for the created VisioShapes
.
Methods
addSection()
visioShape.addSection<K extends keyof VisioSection.SectionClassByType>(type: K): VisioSection.SectionClassByType[K];
Add a new VisioSection
(either VisioIndexedSection
or VisioNamedSection
) based on the given type
.
In case it is a named section that already exists, new one will not be added. New indexed section will be appended at
the end of the given collection with an index incremented from the previously highest index.
// add a custom properties section
vsdShape.addSection(types.VisioSectionType.Property);
getAncestorShapes()
visioShape.getAncestorShapes(): VisioShape[];
Return an array
of ancestor VisioShapes
of the shape, ordered starting with highest level.
getComputedGeometry()
visioShape.getComputedGeometry(): VisioGeometrySection[];
Return an array
of sections merged from own and inherited geometries. If there is no geometry sections
defined on either shape or the master, return an empty array.
getComputedSection()
visioShape.getComputedSection<K extends keyof VisioSection.SectionClassByType>(name: K): VisioSection.SectionClassByType[K] | null;
Return a section merged from own and inherited from master section data. If section of the name
does not
exist on either, return null
.
If the given name
is VisioSectionType.Geometry
, return results of visioShape.getComputedGeometry()
.
getConnect()
visioShape.getConnect(): VisioConnect | null;
Return a VisioConnect
of the shape. If shape does not have a connect pointing to it, return null
.
getGeometry()
visioShape.getGeometry(): VisioGeometrySection[];
Return an array
shapes own geometry sections. If none is defined, return an empty array
.
getImage()
async visioShape.getImage(): Promise<VisioImageObject | null>;
Return an image object
containing following properties:
interface VisioImageObject {
absolutePath: string;
file: string;
extension: string;
base64: string;
selector: string;
}
absolutePath
File path within the visio archive.
file
File name of the image.
extension
File extension of the image.
base64
A base64
representation of the image.
selector
Image element selector.
getMaster()
visioShape.getMaster(): VisioMaster | null;
Return a VisioMaster
for a shape. Return null
if the shape was not created from a stencil master.
getOwnSectionNames()
visioShape.getOwnSectionNames(): string[];
Return an array
of section names defined for the shape.
getPageAngle()
visioShape.getPageAngle(): number;
Return a number
describing shape angle to the page.
getPageBBox()
visioShape.getPageBBox(): g.Rect;
Return a g.Rect
describing the shape bbox on the page.
getPagePosition()
visioShape.getPagePosition(): g.Point;
Return a g.Point
describing position of the shape on the page.
getPageZIndex()
visioShape.getPageZIndex(): number;
Return an int
describing the shape z-index on the page.
getRootShape()
visioShape.getRootShape(): VisioShape;
Return the VisioShape
that is a root shape for the given shape, or the visioShape
itself if it is a root shape.
getSection()
visioShape.getSection<K extends keyof VisioSection.SectionClassByType>(type: K): VisioSection.SectionClassByType[K] | null;
If an own section of type
exists on the shape, return it. If a section does not exist on the shape, return null
Own sections are defined for the shape and set values override sections inherited from master shape.
If the given type
is VisioSectionType.Geometry
, return results of visioShape.getGeometry()
.
getSectionNames()
visioShape.getSectionNames(): string[];
Return an array
of all section names available for the shape, including inherited ones.
getSubShapes()
visioShape.getSubShapes(): VisioShape[];
Return an array
of all shapes nested within the given visioShape
.
getText()
visioShape.getText(): string;
Return a string
representing shape text if one exists. If none is defined, return empty ''
.
hasImage()
visioShape.hasImage(): boolean;
Return true
if the shape contains an image.
isOneDimensional()
visioShape.isOneDimensional(): boolean;
Return true
if the shape is considered 1-D (one-dimensional) in Visio. Such shapes contain beginX
, beginY
, endX
,
endY
cells. Return false
if shape is considered 2-D.
removeSection()
visioShape.removeSection<K extends keyof VisioSection.SectionClassByType>(type: K, index?: number): void;
If a named section is being removed, only the type
parameter is required. For indexed section, a second
parameter, index
has to be provided. index
defaults to 0
if none is provided.
// remove property section
vsdShape.removeSection(types.VisioSectionType.Property);
// remove geometry section with index 2
vsdShape.removeSection(types.VisioSectionType.Geometry, 2);
setText()
visioShape.setText(text: string): void;
Update shape text with given text
. Do mind this will override the existing text.
toElementAttributes()
visioShape.toElementAttributes(): dia.Element.Attributes;
Return JointJS dia.Element attributes
created from the shape. It's particularly useful when using custom Element
instead of the one used by the default converter.
Properties
There are several properties that can be accessed:
id
visioShape.id: number;
A unique, integer shape id
.
masterId
visioShape.masterId: number;
masterId
points to a master given shape was created from.
name
visioShape.name: string | null;
A string name
of the shape.
type
visioShape.type: types.VisioShapeType | string;
A string type
of the shape, i.e. 'Shape'
or 'Group'
.
Static Methods
fromMaster()
VisioShape.fromMaster(master: VisioMaster, page: VisioPage): VisioShape;
const archive = await VisioArchive.fromURL('./project.vsdx');
const { document: vsdDocument } = archive;
const [page0] = vsdDocument.getPages();
// pick a stencil master
const masters = vsdDocument.getMastersNameMap();
const [master0] = masters['Master Name'];
// create a raw shape based on a stencil Master
const vsdShape = await VisioShape.fromMaster(master, page0);