@maxgraph/core
Version:
maxGraph is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.
91 lines (87 loc) • 3.1 kB
JavaScript
"use strict";
/*
Copyright 2021-present The maxGraph project Contributors
Copyright (c) 2006-2015, JGraph Ltd
Copyright (c) 2006-2015, Gaudenz Alder
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.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Constants_js_1 = require("../../../util/Constants.js");
const Shape_js_1 = __importDefault(require("../Shape.js"));
/**
* Extends {@link Shape} to implement a rectangle shape.
*
* This shape is registered under `rectangle` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
class RectangleShape extends Shape_js_1.default {
constructor(bounds, fill, stroke, strokeWidth = 1) {
super();
this.bounds = bounds;
this.fill = fill;
this.stroke = stroke;
this.strokeWidth = strokeWidth;
}
/**
* Returns true for non-rounded, non-rotated shapes with no glass gradient.
*/
isHtmlAllowed() {
let events = true;
if (this.style && this.style.pointerEvents != null) {
events = this.style.pointerEvents;
}
return (!this.isRounded &&
!this.glass &&
this.rotation === 0 &&
(events || this.fill !== Constants_js_1.NONE));
}
/**
* Generic background painting implementation.
*/
paintBackground(c, x, y, w, h) {
let events = true;
if (this.style && this.style.pointerEvents != null) {
events = this.style.pointerEvents;
}
if (events || this.fill !== Constants_js_1.NONE || this.stroke !== Constants_js_1.NONE) {
if (!events && this.fill === Constants_js_1.NONE) {
c.pointerEvents = false;
}
if (this.isRounded) {
const r = this.getArcSize(w, h);
c.roundrect(x, y, w, h, r, r);
}
else {
c.rect(x, y, w, h);
}
c.fillAndStroke();
}
}
/**
* Adds roundable support.
*/
isRoundable(c, x, y, w, h) {
return true;
}
/**
* Generic background painting implementation.
*/
paintForeground(c, x, y, w, h) {
if (this.glass && !this.outline && this.fill !== Constants_js_1.NONE) {
this.paintGlassEffect(c, x, y, w, h, this.getArcSize(w + this.strokeWidth, h + this.strokeWidth));
}
}
}
exports.default = RectangleShape;