@maxgraph/core
Version:
maxGraph is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.
65 lines (61 loc) • 2.08 kB
JavaScript
;
/*
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 Shape_js_1 = __importDefault(require("../Shape.js"));
/**
* Extends {@link Shape} to implement a horizontal line shape.
*
* The shape is used to represent edges, not vertices.
*
* This shape is registered under `line` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
class LineShape extends Shape_js_1.default {
constructor(bounds, stroke, strokeWidth = 1, vertical = false) {
super();
this.bounds = bounds;
this.stroke = stroke;
this.strokeWidth = strokeWidth;
this.vertical = vertical;
}
/**
* Redirects to redrawPath for subclasses to work.
* @param {AbstractCanvas2D} c
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
paintVertexShape(c, x, y, w, h) {
c.begin();
if (this.vertical) {
const mid = x + w / 2;
c.moveTo(mid, y);
c.lineTo(mid, y + h);
}
else {
const mid = y + h / 2;
c.moveTo(x, mid);
c.lineTo(x + w, mid);
}
c.stroke();
}
}
exports.default = LineShape;