GitHub Discussion #2026
https://github.com/clientIO/joint/issues/2026
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.2/joint.css" />
</head>
<body>
<!-- content -->
<div id="paper"></div>
<!-- dependencies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.4.0/backbone.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.2/joint.js"></script>
</body>
</html>
JavaScript
// From now on the `selector` must be JointJS selector, and not CSS selector
// element.attr([selector, 'fill'], 'red')
// OK: 'label'
// NOT OK: 'text:first' '.my-label'
joint.config.useCSSSelectors = false;
const graph = new joint.dia.Graph({}, {
cellNamespace: joint.shapes
});
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 800,
height: 900,
model: graph,
cellViewNamespace: joint.shapes,
gridSize: 10,
async: true,
sorting: joint.dia.Paper.sorting.APPROX,
defaultLink: () => new joint.shapes.standard.Link(),
});
// Example
const r1 = new joint.shapes.standard.Rectangle({
layer: 'group1',
position: { x: 100, y: 100 },
size: { width: 200, height: 200 },
attrs: {
root: {
magnet: false
},
body: {
stroke: '#333333',
fill: '#fff',
rx: 10,
ry: 10
}
},
portMarkup: [
{
tagName: 'circle',
selector: 'portBody',
attributes: {
r: 10,
fill: '#FFFFFF',
stroke: '#333333'
}
}
],
portLabelMarkup: [
{
tagName: 'rect',
selector: 'portLabelBackground'
},
{
tagName: 'text',
selector: 'portLabel',
attributes: {
fill: '#333333'
}
}
],
ports: {
groups: {
left: {
position: 'left',
label: {
position: {
name: 'outside',
args: {
offset: 30
}
}
},
attrs: {
portLabelBackground: {
ref: 'portLabel',
fill: 'red',
x: 'calc(x - 2)',
y: 'calc(y -...