VisioPage
VisioPage
contains metadata describing a page in a document. Its API allows to load contents of the page, as well
as update the page data with JointJS Paper when exporting a project to vsdx format.
Methodsβ
fromPaper()β
async visioPage.fromPaper(paper: dia.Paper, options?: VisioPage.FromPaperAttributes): Promise<void>;
page.fromPaper()
method is used when exporting a JointJS project to a vsdx file format. Before the vsdx archive
is built, its pages should be updated with new content. This new content is built using JointJS paper.
The below example updates visio archive with the contents of JointJS paper and uses default converter to create
a VisioShape
for each JointJS Cell, as well as update project configuration. Lastly, the updated archive is exported
as a vsdx file.
const archive = await VisioArchive.fromURL('./project.vsdx');
const { document: vsdDocument } = archive;
const [page1] = vsdDocument.getPages();
await page1.fromPaper(paper);
const blob = await archive.toVSDX({ type: 'blob' });
util.downloadBlob(blob, 'project.vsdx');
The fromPaper(paper, [opt])
method takes JointJS paper, and an object opt
with the following parameters:
exportElementβ
An async
function run for each dia.Element
present on the provided paper
. The function is passed elementView
and expects either an instance of VisioShape
to be returned or a null
if element is to be skipped in export process.
exportElement: async(elementView) => {
const { model, paper } = elementView;
let master;
// perform relevant logic to find chosen master shape
// ...
// create a raw shape based on a stencil Master
const vsdShape = await VisioShape.fromMaster(master, vsdDocument);
// perform vsdShape manipulations based on the given elementView
// ...
// return modified vsdShape
return vsdShape;
}
exportLinkβ
An async
function run for each dia.Link
present on the provided paper
. The function is passed linkView
and
expects either an instance of VisioShape
to be returned or a null
if links is to be skipped in export process. Connect objects required by Visio are created under the hood. The VisioShape returned by this function is the visual representation of connection in Visio.
exportLink: async(linkView) => {
let master;
// perform relevant logic to find chosen master shape
// ...
return await VisioShape.fromMaster(master, vsdDocument);
}
getContent()β
async visioPage.getContent(): Promise<VisioPageContent>;
Return a VisioPageContent instance containing page shapes.
Propertiesβ
There are several properties that can be accessed:
backgroundβ
visioPage.background: boolean;
Return true
if the page is marked as a background page. Background pages are oftentimes used to show repetitive
content on many foreground pages.
backPageβ
visioPage.backPage: number;
If the page uses a background page, return its id
.
heightβ
visioPage.height: number;
Return page height
in pixels.
idβ
visioPage.id: number;
Return a unique, integer page id
.
nameβ
visioPage.name: string;
Return page name as configured in Visio project.
nameUβ
visioPage.nameU: string;
Return page universal name as configured in Visio project.
widthβ
visioPage.width: number;
Return page height
in pixels.
Typesβ
FromPaperAttributesβ
interface FromPaperAttributes {
exportElement?: (
elementView: dia.ElementView,
visioPage: VisioPage,
templates: VisioShapeTemplates
) => Promise<VisioShape | null>;
exportLink?: (
linkView: dia.LinkView,
visioPage: VisioPage,
templates: VisioShapeTemplates
) => Promise<VisioShape | null>;
}
VisioShapeTemplatesβ
interface VisioShapeTemplates {
fromConnection(linkView: dia.LinkView): Promise<JXON>;
fromNodes(cellView: dia.CellView): Promise<JXON>;
}