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);