2022-08-30 15:36:33 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021-present The maxGraph project Contributors
|
|
|
|
Copyright (c) 2006-2020, JGraph Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-09-07 09:07:27 +00:00
|
|
|
import {
|
2023-10-12 21:41:37 +00:00
|
|
|
CellOverlay,
|
2021-09-07 09:07:27 +00:00
|
|
|
Graph,
|
2023-10-12 21:41:37 +00:00
|
|
|
InternalEvent,
|
2021-09-07 09:07:27 +00:00
|
|
|
EdgeStyle,
|
2022-01-08 01:49:35 +00:00
|
|
|
DomHelpers,
|
|
|
|
xmlUtils,
|
2021-09-07 09:07:27 +00:00
|
|
|
Perimeter,
|
|
|
|
utils,
|
2022-01-08 01:49:35 +00:00
|
|
|
constants,
|
|
|
|
cloneUtils,
|
|
|
|
Codec,
|
2021-09-07 09:07:27 +00:00
|
|
|
} from '@maxgraph/core';
|
2023-10-12 21:41:37 +00:00
|
|
|
import { globalTypes, globalValues } from './shared/args.js';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Misc/Monitor',
|
|
|
|
argTypes: {
|
2021-08-30 14:20:26 +00:00
|
|
|
...globalTypes,
|
|
|
|
},
|
2023-10-12 21:41:37 +00:00
|
|
|
args: {
|
|
|
|
...globalValues,
|
|
|
|
},
|
2021-04-25 03:39:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Template = ({ label, ...args }) => {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
|
|
|
const container = document.createElement('div');
|
|
|
|
container.style.position = 'relative';
|
|
|
|
container.style.overflow = 'hidden';
|
|
|
|
container.style.width = `${args.width}px`;
|
|
|
|
container.style.height = `${args.height}px`;
|
|
|
|
container.style.background = 'url(/images/grid.gif)';
|
|
|
|
container.style.cursor = 'default';
|
|
|
|
div.appendChild(container);
|
|
|
|
|
2021-09-10 05:17:59 +00:00
|
|
|
// Should we allow overriding constants?
|
2022-01-08 01:49:35 +00:00
|
|
|
// constants.SHADOWCOLOR = '#e0e0e0';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Creates the graph inside the given container
|
|
|
|
const graph = createGraph(container);
|
|
|
|
|
|
|
|
// Creates a process display using the activity names as IDs to refer to the elements
|
|
|
|
const xml =
|
2021-08-30 14:20:26 +00:00
|
|
|
'<Transactions><root><Cell id="0"/><Cell id="1" parent="0"/>' +
|
|
|
|
'<Cell id="2" value="Claim Handling Process" style="swimlane" vertex="1" parent="1"><Geometry x="1" width="850" height="400" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="3" value="Claim Manager" style="swimlane" vertex="1" parent="2"><Geometry x="30" width="820" height="200" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="5" value="" style="start" vertex="1" parent="3"><Geometry x="40" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="AuthorizeClaim" value="Authorize
Claim" vertex="1" parent="3"><Geometry x="90" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="6" value="X" style="step" vertex="1" parent="3"><Geometry x="210" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="ApproveClaim" value="Approve
Claim" vertex="1" parent="3"><Geometry x="260" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="7" value="X" style="step" vertex="1" parent="3"><Geometry x="380" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="8" value="" edge="1" parent="3" source="5" target="AuthorizeClaim"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="9" value="" edge="1" parent="3" source="AuthorizeClaim" target="6"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="10" value="" edge="1" parent="3" source="6" target="ApproveClaim"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="11" value="" edge="1" parent="3" source="ApproveClaim" target="7"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="12" value="" edge="1" parent="3" source="7" target="AuthorizeClaim"><Geometry relative="1" as="geometry"><Array as="points"><Point x="140" y="40"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="ReviewClaim" value="Review
Claim" vertex="1" parent="3"><Geometry x="480" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="22" value="X" style="step" vertex="1" parent="3"><Geometry x="600" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="23" value="" edge="1" parent="3" source="ReviewClaim" target="22"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="ApproveReviewedClaim" value="Approve Rev.
Claim" vertex="1" parent="3"><Geometry x="650" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="26" value="" edge="1" parent="3" source="22" target="ApproveReviewedClaim"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="27" value="X" style="step" vertex="1" parent="3"><Geometry x="770" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="28" value="" edge="1" target="27" parent="3" source="ApproveReviewedClaim"><Geometry relative="1" as="geometry"><Point x="740" y="100" as="sourcePoint"/><Point x="760" y="100" as="targetPoint"/></Geometry></Cell>' +
|
|
|
|
'<Cell id="32" value="" edge="1" parent="3" source="27" target="ReviewClaim"><Geometry relative="1" as="geometry"><Array as="points"><Point x="665" y="160"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="4" value="Accountant" style="swimlane" vertex="1" parent="2"><Geometry x="30" y="200" width="820" height="200" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="EnterAccountingData" value="Enter
Data" vertex="1" parent="4"><Geometry x="430" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="14" value="X" style="step" vertex="1" parent="4"><Geometry x="550" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="15" value="" edge="1" parent="4" source="EnterAccountingData" target="14"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="CheckAccountingData" value="Check
Data" vertex="1" parent="4"><Geometry x="600" y="80" width="100" height="40" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="16" value="" edge="1" parent="4" source="14" target="CheckAccountingData"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="17" value="X" style="step" vertex="1" parent="4"><Geometry x="720" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="18" value="" edge="1" parent="4" source="CheckAccountingData" target="17"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="19" value="" style="end" vertex="1" parent="4"><Geometry x="770" y="85" width="30" height="30" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="20" value="" edge="1" parent="4" source="17" target="19"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="31" value="" edge="1" parent="4" source="17" target="EnterAccountingData"><Geometry relative="1" as="geometry"><Array as="points"><Point x="625" y="160"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="13" value="" edge="1" parent="2" source="7" target="EnterAccountingData"><Geometry relative="1" as="geometry"/></Cell>' +
|
|
|
|
'<Cell id="24" value="" edge="1" parent="2" source="14" target="ReviewClaim" style="edgeStyle=none"><Geometry relative="1" as="geometry"><Array as="points"><Point x="595" y="180"/><Point x="480" y="180"/><Point x="480" y="100"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="29" value="" edge="1" parent="2" source="22" target="EnterAccountingData"><Geometry relative="1" as="geometry"><Array as="points"><Point x="469" y="40"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="30" value="" edge="1" parent="2" source="27" target="EnterAccountingData"><Geometry relative="1" as="geometry"><Array as="points"><Point x="469" y="40"/></Array></Geometry></Cell>' +
|
|
|
|
'<Cell id="33" value="" edge="1" parent="2" source="6" target="EnterAccountingData"><Geometry relative="1" as="geometry"><Array as="points"><Point x="255" y="200"/></Array></Geometry></Cell>' +
|
2021-06-06 13:04:44 +00:00
|
|
|
'</root></Transactions>';
|
2022-01-08 01:49:35 +00:00
|
|
|
const doc = xmlUtils.parseXml(xml);
|
|
|
|
const codec = new Codec(doc);
|
|
|
|
codec.decode(doc.documentElement, graph.getDataModel());
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
const buttons = document.createElement('div');
|
|
|
|
div.appendChild(buttons);
|
|
|
|
|
|
|
|
// Creates a button to invoke the refresh function
|
|
|
|
buttons.appendChild(
|
2022-01-08 01:49:35 +00:00
|
|
|
DomHelpers.button('Update', function (evt) {
|
2021-08-30 14:20:26 +00:00
|
|
|
// XML is normally fetched from URL at server using utils.get - this is a client-side
|
2021-04-25 03:39:40 +00:00
|
|
|
// string with randomized states to demonstrate the idea of the workflow monitor
|
|
|
|
const xml =
|
|
|
|
`<process><update id="ApproveClaim" state="${getState()}"/><update id="AuthorizeClaim" state="${getState()}"/>` +
|
|
|
|
`<update id="CheckAccountingData" state="${getState()}"/><update id="ReviewClaim" state="${getState()}"/>` +
|
|
|
|
`<update id="ApproveReviewedClaim" state="${getState()}"/><update id="EnterAccountingData" state="${getState()}"/></process>`;
|
|
|
|
update(graph, xml);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the display of the given graph using the XML data
|
|
|
|
*/
|
|
|
|
function update(graph, xml) {
|
|
|
|
if (xml != null && xml.length > 0) {
|
2022-01-08 01:49:35 +00:00
|
|
|
const doc = xmlUtils.parseXml(xml);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
if (doc != null && doc.documentElement != null) {
|
2022-01-08 01:49:35 +00:00
|
|
|
const model = graph.getDataModel();
|
2021-04-25 03:39:40 +00:00
|
|
|
const nodes = doc.documentElement.getElementsByTagName('update');
|
|
|
|
|
|
|
|
if (nodes != null && nodes.length > 0) {
|
|
|
|
model.beginUpdate();
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
|
|
// Processes the activity nodes inside the process node
|
|
|
|
const id = nodes[i].getAttribute('id');
|
|
|
|
const state = nodes[i].getAttribute('state');
|
|
|
|
|
|
|
|
// Gets the cell for the given activity name from the model
|
|
|
|
const cell = model.getCell(id);
|
|
|
|
|
|
|
|
// Updates the cell color and adds some tooltip information
|
|
|
|
if (cell != null) {
|
|
|
|
// Resets the fillcolor and the overlay
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.setCellStyles('fillColor', 'white', [cell]);
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.removeCellOverlays(cell);
|
|
|
|
|
|
|
|
// Changes the cell color for the known states
|
|
|
|
if (state == 'Running') {
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.setCellStyles('fillColor', '#f8cecc', [cell]);
|
2021-04-25 03:39:40 +00:00
|
|
|
} else if (state == 'Waiting') {
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.setCellStyles('fillColor', '#fff2cc', [cell]);
|
2021-04-25 03:39:40 +00:00
|
|
|
} else if (state == 'Completed') {
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.setCellStyles('fillColor', '#d4e1f5', [cell]);
|
2021-04-25 03:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adds tooltip information using an overlay icon
|
|
|
|
if (state != 'Init') {
|
|
|
|
// Sets the overlay for the cell in the graph
|
|
|
|
graph.addCellOverlay(
|
|
|
|
cell,
|
|
|
|
createOverlay(graph.warningImage, `State: ${state}`)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for
|
|
|
|
} finally {
|
|
|
|
model.endUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an overlay object using the given tooltip and text for the alert window
|
|
|
|
* which is being displayed on click.
|
|
|
|
*/
|
|
|
|
function createOverlay(image, tooltip) {
|
2021-06-06 13:04:44 +00:00
|
|
|
const overlay = new CellOverlay(image, tooltip);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Installs a handler for clicks on the overlay
|
2021-08-30 14:20:26 +00:00
|
|
|
overlay.addListener(InternalEvent.CLICK, function (sender, evt) {
|
2023-10-12 21:41:37 +00:00
|
|
|
window.alert(`${tooltip}\nLast update: ${new Date()}`);
|
2021-04-25 03:39:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an empty graph inside the given container.
|
|
|
|
*/
|
|
|
|
function createGraph(container) {
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.setTooltips(true);
|
|
|
|
graph.setEnabled(false);
|
|
|
|
|
|
|
|
// Disables folding
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.isCellFoldable = function (cell, collapse) {
|
2021-04-25 03:39:40 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates the stylesheet for the process display
|
|
|
|
let style = graph.getStylesheet().getDefaultVertexStyle();
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = 11;
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'black';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = '#808080';
|
|
|
|
style.fillColor = 'white';
|
|
|
|
style.gradientColor = 'white';
|
2022-01-08 01:49:35 +00:00
|
|
|
style.gradientDirection = constants.DIRECTION.EAST;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.rounded = true;
|
|
|
|
style.shadow = true;
|
|
|
|
style.fontStyle = 1;
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
style = graph.getStylesheet().getDefaultEdgeStyle();
|
2021-08-30 14:20:26 +00:00
|
|
|
style.edge = EdgeStyle.ElbowConnector;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = '#808080';
|
|
|
|
style.rounded = true;
|
|
|
|
style.shadow = true;
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
style = [];
|
2022-01-08 01:49:35 +00:00
|
|
|
style.shape = constants.SHAPE.SWIMLANE;
|
2021-08-30 14:20:26 +00:00
|
|
|
style.perimiter = Perimeter.RectanglePerimeter;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = '#a0a0a0';
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = '#606060';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fillColor = '#E0E0DF';
|
|
|
|
style.gradientColor = 'white';
|
|
|
|
style.startSize = 30;
|
|
|
|
style.rounded = false;
|
|
|
|
style.fontSize = 12;
|
|
|
|
style.fontStyle = 0;
|
|
|
|
style.horizontal = false;
|
2021-04-25 03:39:40 +00:00
|
|
|
// To improve text quality for vertical labels in some old IE versions...
|
2021-05-02 06:04:34 +00:00
|
|
|
style.labelBackgroundColor = '#efefef';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
graph.getStylesheet().putCellStyle('swimlane', style);
|
|
|
|
|
|
|
|
style = [];
|
2022-01-08 01:49:35 +00:00
|
|
|
style.shape = constants.SHAPE.RHOMBUS;
|
2021-08-30 14:20:26 +00:00
|
|
|
style.perimiter = Perimeter.RhombusPerimeter;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = '#91BCC0';
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'gray';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fillColor = '#91BCC0';
|
|
|
|
style.gradientColor = 'white';
|
2022-01-08 01:49:35 +00:00
|
|
|
style.align = constants.ALIGN.CENTER;
|
|
|
|
style.verticalAlign = constants.ALIGN.MIDDLE;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = 16;
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.getStylesheet().putCellStyle('step', style);
|
|
|
|
|
|
|
|
style = [];
|
2022-01-08 01:49:35 +00:00
|
|
|
style.shape = constants.SHAPE.ELLIPSE;
|
2021-08-30 14:20:26 +00:00
|
|
|
style.perimiter = Perimeter.EllipsePerimeter;
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'gray';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fillColor = '#A0C88F';
|
|
|
|
style.gradientColor = 'white';
|
|
|
|
style.strokeColor = '#A0C88F';
|
2022-01-08 01:49:35 +00:00
|
|
|
style.align = constants.ALIGN.CENTER;
|
|
|
|
style.verticalAlign = constants.ALIGN.MIDDLE;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = 16;
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.getStylesheet().putCellStyle('start', style);
|
|
|
|
|
2022-01-08 01:49:35 +00:00
|
|
|
style = cloneUtils.clone(style);
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fillColor = '#DACCBC';
|
|
|
|
style.strokeColor = '#AF7F73';
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.getStylesheet().putCellStyle('end', style);
|
|
|
|
|
|
|
|
return graph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a random state.
|
|
|
|
*/
|
|
|
|
function getState() {
|
|
|
|
let state = 'Init';
|
|
|
|
const rnd = Math.random() * 4;
|
|
|
|
|
|
|
|
if (rnd > 3) {
|
|
|
|
state = 'Completed';
|
|
|
|
} else if (rnd > 2) {
|
|
|
|
state = 'Running';
|
|
|
|
} else if (rnd > 1) {
|
|
|
|
state = 'Waiting';
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-25 03:39:40 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|