Migrate web2d to storybook
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "."
|
||||
"baseUrl": ".",
|
||||
"module": "ES6",
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
|
@ -7,6 +7,9 @@ describe('Topic Icon Suite', () => {
|
||||
|
||||
it('Open panel', () => {
|
||||
cy.onClickToolbarButton('Add Icon');
|
||||
// Icon images must be loaded. No better solution than wait.
|
||||
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
||||
cy.wait(5000);
|
||||
cy.matchImageSnapshot('icons-pannel');
|
||||
});
|
||||
|
||||
|
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 196 KiB |
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 178 KiB |
@ -26,6 +26,7 @@
|
||||
"lint": "eslint src --ext js,ts",
|
||||
"playground": "webpack serve --config webpack.playground.js",
|
||||
"cy:run": "cypress run",
|
||||
"cy:open": "cypress open",
|
||||
"test:unit": "jest ./test/unit/export/*.ts ./test/unit/import/*.ts ./test/unit/layout/*.js --verbose --silent --detectOpenHandles",
|
||||
"test:integration": "start-server-and-test playground http-get://localhost:8083 cy:run",
|
||||
"test": "yarn test:unit && yarn test:integration"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import { Group, Rect, Line } from '@wisemapping/web2d';
|
||||
import { Group, Rect, StraightLine } from '@wisemapping/web2d';
|
||||
import ImageIcon from './ImageIcon';
|
||||
|
||||
class IconGroupRemoveTip {
|
||||
@ -115,12 +115,12 @@ class IconGroupRemoveTip {
|
||||
});
|
||||
result.append(innerRect);
|
||||
|
||||
const line = new Line({ stroke: '1 solid white' });
|
||||
const line = new StraightLine({ stroke: '1 solid white' });
|
||||
line.setFrom(1, 1);
|
||||
line.setTo(9, 9);
|
||||
result.append(line);
|
||||
|
||||
const line2 = new Line({ stroke: '1 solid white' });
|
||||
const line2 = new StraightLine({ stroke: '1 solid white' });
|
||||
line2.setFrom(1, 9);
|
||||
line2.setTo(9, 1);
|
||||
result.append(line2);
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import { Elipse, Line } from '@wisemapping/web2d';
|
||||
import { Elipse, StraightLine } from '@wisemapping/web2d';
|
||||
import Shape from './util/Shape';
|
||||
import ActionDispatcher from './ActionDispatcher';
|
||||
import Workspace from './Workspace';
|
||||
@ -32,7 +32,7 @@ export enum PivotType {
|
||||
class ControlPivotLine {
|
||||
private _dot: Elipse;
|
||||
|
||||
private _line: Line;
|
||||
private _line: StraightLine;
|
||||
|
||||
private _pivotType: PivotType;
|
||||
|
||||
@ -79,7 +79,7 @@ class ControlPivotLine {
|
||||
);
|
||||
|
||||
// Build line ...
|
||||
this._line = new Line({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 });
|
||||
this._line = new StraightLine({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 });
|
||||
|
||||
const mouseClick = (event: MouseEvent): boolean => {
|
||||
event.preventDefault();
|
||||
|
@ -15,11 +15,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Line } from '@wisemapping/web2d';
|
||||
import { StraightLine } from '@wisemapping/web2d';
|
||||
import SizeType from '../SizeType';
|
||||
import Topic from '../Topic';
|
||||
|
||||
class LineTopicShape extends Line {
|
||||
class LineTopicShape extends StraightLine {
|
||||
private _size: SizeType | null;
|
||||
|
||||
constructor(topic: Topic) {
|
||||
|
15
packages/web2d/.storybook/main.js
Normal file
@ -0,0 +1,15 @@
|
||||
module.exports = {
|
||||
"stories": [
|
||||
"../storybook/src/**/*.stories.mdx",
|
||||
"../storybook/src/**/*.stories.@(js|jsx|ts|tsx)"
|
||||
],
|
||||
"addons": [
|
||||
"@storybook/addon-links",
|
||||
"@storybook/addon-essentials",
|
||||
"@storybook/addon-interactions"
|
||||
],
|
||||
"framework": "@storybook/html",
|
||||
"core": {
|
||||
"builder": "@storybook/builder-webpack5"
|
||||
}
|
||||
}
|
9
packages/web2d/.storybook/preview.js
Normal file
@ -0,0 +1,9 @@
|
||||
export const parameters = {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/,
|
||||
},
|
||||
},
|
||||
}
|
@ -7,8 +7,8 @@ module.exports = defineConfig({
|
||||
// We've imported your old cypress plugins here.
|
||||
// You may want to clean this up later by importing these.
|
||||
setupNodeEvents(on, config) {
|
||||
return require('./cypress/plugins/index.js')(on, config)
|
||||
return require('./cypress/plugins/index.js')(on, config);
|
||||
},
|
||||
baseUrl: 'http://localhost:8080',
|
||||
baseUrl: 'http://localhost:6006',
|
||||
},
|
||||
})
|
||||
});
|
||||
|
17
packages/web2d/cypress/e2e/curvedline.cy.js
Normal file
@ -0,0 +1,17 @@
|
||||
describe('CurvedLine Suite', () => {
|
||||
// CurvedLine tests ...
|
||||
it('CurvedLine Width', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-curvedline--width&viewMode=story');
|
||||
cy.matchImageSnapshot('curvedline-width');
|
||||
});
|
||||
|
||||
it('CurvedLine Stroke', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-curvedline--stroke&viewMode=story');
|
||||
cy.matchImageSnapshot('curvedline-stroke');
|
||||
});
|
||||
|
||||
it('CurvedLine Middle Curved', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-curvedline--fill&viewMode=story');
|
||||
cy.matchImageSnapshot('curvedline-fill');
|
||||
});
|
||||
});
|
7
packages/web2d/cypress/e2e/element.opacity.cy.js
Normal file
@ -0,0 +1,7 @@
|
||||
describe('Element Opacity Suite', () => {
|
||||
// Rect tests ...
|
||||
it('Element Opacity', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-element--opacity&viewMode=story');
|
||||
cy.matchImageSnapshot('element-opacity');
|
||||
});
|
||||
});
|
17
packages/web2d/cypress/e2e/ellipse.cy.js
Normal file
@ -0,0 +1,17 @@
|
||||
describe('Ellipse Suite', () => {
|
||||
// Ellipse tests ...
|
||||
it('Ellipse Fill', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-ellipse--fill&viewMode=story');
|
||||
cy.matchImageSnapshot('ellipse-fill');
|
||||
});
|
||||
|
||||
it('Ellipse Stroke', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-ellipse--fill&viewMode=story');
|
||||
cy.matchImageSnapshot('ellipse-stroke');
|
||||
});
|
||||
|
||||
it('Ellipse Size', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-ellipse--size&viewMode=story');
|
||||
cy.matchImageSnapshot('ellipse-size');
|
||||
});
|
||||
});
|
32
packages/web2d/cypress/e2e/group.cy.js
Normal file
@ -0,0 +1,32 @@
|
||||
describe('Group Suite', () => {
|
||||
// Rect tests ...
|
||||
it('Group Fill', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-rectangle--fill&viewMode=story');
|
||||
cy.matchImageSnapshot('group-fill');
|
||||
});
|
||||
|
||||
it('Group Container', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-group--container&viewMode=story');
|
||||
cy.matchImageSnapshot('group-container');
|
||||
});
|
||||
|
||||
it('Group Bubbling', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-group--event-bubbling&viewMode=story');
|
||||
cy.matchImageSnapshot('group-size');
|
||||
});
|
||||
|
||||
it('Group Nested', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-group--nested&viewMode=story');
|
||||
cy.matchImageSnapshot('group-nested');
|
||||
});
|
||||
|
||||
it('Group Coord Size', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-group--coord-size&viewMode=story');
|
||||
cy.matchImageSnapshot('group-coords-size');
|
||||
});
|
||||
|
||||
it('Group Coord Origin', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-group--coord-origin&viewMode=story');
|
||||
cy.matchImageSnapshot('group-coords-origin');
|
||||
});
|
||||
});
|
@ -1,52 +0,0 @@
|
||||
context('Playground', () => {
|
||||
describe('snapshots', () => {
|
||||
it('Arrow', () => {
|
||||
cy.visit('/arrow.html');
|
||||
cy.matchImageSnapshot('Arrow');
|
||||
});
|
||||
it('Curved Line', () => {
|
||||
cy.visit('/curvedLine.html');
|
||||
cy.matchImageSnapshot('Curved Line');
|
||||
});
|
||||
it('Events', () => {
|
||||
cy.visit('/events.html');
|
||||
cy.matchImageSnapshot('Events');
|
||||
});
|
||||
it('Font', () => {
|
||||
cy.visit('/font.html');
|
||||
cy.matchImageSnapshot('Font');
|
||||
});
|
||||
it('Group', () => {
|
||||
cy.visit('/group.html');
|
||||
cy.matchImageSnapshot('Group');
|
||||
});
|
||||
it('Line', () => {
|
||||
cy.visit('/line.html');
|
||||
cy.matchImageSnapshot('Line');
|
||||
});
|
||||
it('Poly Line', () => {
|
||||
cy.visit('/polyLine.html');
|
||||
cy.matchImageSnapshot('Poly Line');
|
||||
});
|
||||
it('Prototype', () => {
|
||||
cy.visit('/prototype.html');
|
||||
cy.matchImageSnapshot('Prototype');
|
||||
});
|
||||
it('Rect', () => {
|
||||
cy.visit('/rect.html');
|
||||
cy.matchImageSnapshot('Rect');
|
||||
});
|
||||
it('Shapes', () => {
|
||||
cy.visit('/shapes.html');
|
||||
cy.matchImageSnapshot('Shapes');
|
||||
});
|
||||
it('Text', () => {
|
||||
cy.visit('/text.html');
|
||||
cy.matchImageSnapshot('Text');
|
||||
});
|
||||
it('Workspace', () => {
|
||||
cy.visit('/workspace.html');
|
||||
cy.matchImageSnapshot('Workspace');
|
||||
});
|
||||
});
|
||||
});
|
27
packages/web2d/cypress/e2e/polyline.cy.js
Normal file
@ -0,0 +1,27 @@
|
||||
describe('Polyline Suite', () => {
|
||||
// Polyline tests ...
|
||||
it('Polyline Stroke', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-polyline--stroke&viewMode=story');
|
||||
cy.matchImageSnapshot('polyline-stroke');
|
||||
});
|
||||
|
||||
it('Polyline Straight', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-polyline--straight&viewMode=story');
|
||||
cy.matchImageSnapshot('polyline-straight');
|
||||
});
|
||||
|
||||
it('Polyline Middle Straight', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-polyline--middle-straight&viewMode=story');
|
||||
cy.matchImageSnapshot('polyline-middle-straight');
|
||||
});
|
||||
|
||||
it('Polyline Curved', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-polyline--curved&viewMode=story');
|
||||
cy.matchImageSnapshot('polyline-curved');
|
||||
});
|
||||
|
||||
it('Polyline Middle Curved', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-polyline--middle-curved&viewMode=story');
|
||||
cy.matchImageSnapshot('polyline-middle-curved');
|
||||
});
|
||||
});
|
22
packages/web2d/cypress/e2e/rect.cy.js
Normal file
@ -0,0 +1,22 @@
|
||||
describe('Rect Suite', () => {
|
||||
// Rect tests ...
|
||||
it('Reactangle Fill', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-rectangle--fill&viewMode=story');
|
||||
cy.matchImageSnapshot('rectangle-fill');
|
||||
});
|
||||
|
||||
it('Reactangle Stroke', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-rectangle--stroke&viewMode=story');
|
||||
cy.matchImageSnapshot('rectangle-stroke');
|
||||
});
|
||||
|
||||
it('Reactangle Size', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-rectangle--size&viewMode=story');
|
||||
cy.matchImageSnapshot('rectangle-size');
|
||||
});
|
||||
|
||||
it('Reactangle Arc', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-rectangle--arc&viewMode=story');
|
||||
cy.matchImageSnapshot('rectangle-arc');
|
||||
});
|
||||
});
|
12
packages/web2d/cypress/e2e/straightLine.cy.js
Normal file
@ -0,0 +1,12 @@
|
||||
describe('StraightLine Suite', () => {
|
||||
// StraightLine tests ...
|
||||
it('StraightLine Stroke Width', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-straightline--stroke-width&viewMode=story');
|
||||
cy.matchImageSnapshot('straightline-stroke-width');
|
||||
});
|
||||
|
||||
it('StraightLine Stroke Color', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-straightline--stroke-color&viewMode=story');
|
||||
cy.matchImageSnapshot('straightline-stroke-color');
|
||||
});
|
||||
});
|
7
packages/web2d/cypress/e2e/text.cy.js
Normal file
@ -0,0 +1,7 @@
|
||||
describe('Text Suite', () => {
|
||||
// Rect tests ...
|
||||
it('Text Multiline', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-text--multiline&viewMode=story');
|
||||
cy.matchImageSnapshot('text-multiline');
|
||||
});
|
||||
});
|
21
packages/web2d/cypress/e2e/workspace.cy.js
Normal file
@ -0,0 +1,21 @@
|
||||
describe('Workspace Suite', () => {
|
||||
it('Workspace Visibility', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-workspace--visibility&viewMode=story');
|
||||
cy.matchImageSnapshot('workspace-visibility');
|
||||
});
|
||||
|
||||
it('Workspace Position', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-workspace--position&viewMode=story');
|
||||
cy.matchImageSnapshot('workspace-position');
|
||||
});
|
||||
|
||||
it('Workspace Coords Size', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-workspace--coords-size&viewMode=story');
|
||||
cy.matchImageSnapshot('workspace-coord-size');
|
||||
});
|
||||
|
||||
it('Workspace Coords Origin', () => {
|
||||
cy.visit('/iframe.html?args=&id=shapes-workspace--coords-origin&viewMode=story');
|
||||
cy.matchImageSnapshot('workspace-coord-origin');
|
||||
});
|
||||
});
|
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 61 KiB |
BIN
packages/web2d/cypress/snapshots/group.cy.js/group-fill.snap.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 82 KiB |
BIN
packages/web2d/cypress/snapshots/group.cy.js/group-size.snap.png
Normal file
After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 151 KiB |
Before Width: | Height: | Size: 86 KiB |
Before Width: | Height: | Size: 329 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 297 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 35 KiB |
@ -16,5 +16,14 @@
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands';
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
Cypress.on('window:before:load', (win) => {
|
||||
cy.spy(win.console, 'error');
|
||||
cy.spy(win.console, 'warn');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cy.window().then((win) => {
|
||||
expect(win.console.error).to.have.callCount(0);
|
||||
expect(win.console.warn).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
@ -1,40 +1,54 @@
|
||||
{
|
||||
"name": "@wisemapping/web2d",
|
||||
"version": "0.4.6",
|
||||
"description": "WiseMapping - Web2D Render Library",
|
||||
"homepage": "http://www.wisemapping.org/",
|
||||
"license": "MIT",
|
||||
"main": "dist/web2d.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.yarnpkg.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@bitbucket.org:wisemapping/wisemapping-frontend.git"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "webpack --config webpack.dev.js",
|
||||
"build": "webpack --config webpack.prod.js",
|
||||
"lint": "eslint src",
|
||||
"playground": "webpack serve --config webpack.playground.js",
|
||||
"cy:run": "cypress run",
|
||||
"test:integration": "start-server-and-test playground http-get://localhost:8080 cy:run",
|
||||
"test": "yarn test:integration"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cypress": "12.3.0",
|
||||
"cypress-image-snapshot": "^4.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wisemapping/core-js": "^0.4.0",
|
||||
"jquery": "^3.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@wisemapping/core-js": "^0.4.0",
|
||||
"jquery": "^3.6.0"
|
||||
}
|
||||
"name": "@wisemapping/web2d",
|
||||
"version": "0.4.6",
|
||||
"description": "WiseMapping - Web2D Render Library",
|
||||
"homepage": "http://www.wisemapping.org/",
|
||||
"license": "MIT",
|
||||
"main": "dist/web2d.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.yarnpkg.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@bitbucket.org:wisemapping/wisemapping-frontend.git"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "webpack --config webpack.dev.js",
|
||||
"build": "webpack --config webpack.prod.js",
|
||||
"lint": "eslint src",
|
||||
"playground": "webpack serve --config webpack.playground.js",
|
||||
"cy:run": "cypress run",
|
||||
"cy:open": "cypress open",
|
||||
"test:integration": "start-server-and-test storybook http-get://localhost:6006 cy:run",
|
||||
"test": "yarn test:integration",
|
||||
"storybook": "start-storybook -p 6006 --no-open",
|
||||
"build-storybook": "build-storybook"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mdx-js/react": "^1.6.22",
|
||||
"@storybook/addon-actions": "^6.5.15",
|
||||
"@storybook/addon-docs": "^6.5.15",
|
||||
"@storybook/addon-essentials": "^6.5.15",
|
||||
"@storybook/addon-interactions": "^6.5.15",
|
||||
"@storybook/addon-links": "^6.5.15",
|
||||
"@storybook/builder-webpack5": "^6.5.15",
|
||||
"@storybook/html": "^6.5.15",
|
||||
"@storybook/manager-webpack5": "^6.5.15",
|
||||
"@storybook/testing-library": "^0.0.13",
|
||||
"cypress": "12.3.0",
|
||||
"cypress-image-snapshot": "^4.0.1",
|
||||
"start-server-and-test": "^1.15.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wisemapping/core-js": "^0.4.0",
|
||||
"jquery": "^3.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@wisemapping/core-js": "^0.4.0",
|
||||
"jquery": "^3.6.0"
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@
|
||||
import ElementClass from './ElementClass';
|
||||
import Toolkit from './Toolkit';
|
||||
|
||||
class Line extends ElementClass {
|
||||
class StraightLine extends ElementClass {
|
||||
constructor(attributes) {
|
||||
const peer = Toolkit.createLine();
|
||||
const peer = Toolkit.createStraightLine();
|
||||
const defaultAttributes = { strokeColor: '#495879', strokeWidth: 1, strokeOpacity: 1 };
|
||||
for (const key in attributes) {
|
||||
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
|
||||
@ -52,14 +52,6 @@ class Line extends ElementClass {
|
||||
return this.peer.getTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the start and the end line arrow style.
|
||||
* Can have values "none | block | classic | diamond | oval | open | chevron | doublechevron"
|
||||
* */
|
||||
setArrowStyle(startStyle, endStyle) {
|
||||
this.peer.setArrowStyle(startStyle, endStyle);
|
||||
}
|
||||
|
||||
setPosition() {
|
||||
throw new Error('Unsupported operation');
|
||||
}
|
||||
@ -73,4 +65,4 @@ class Line extends ElementClass {
|
||||
}
|
||||
}
|
||||
|
||||
export default Line;
|
||||
export default StraightLine;
|
@ -19,7 +19,7 @@ import FontPeer from './peer/svg/FontPeer';
|
||||
import WorkspacePeer from './peer/svg/WorkspacePeer';
|
||||
import GroupPeer from './peer/svg/GroupPeer';
|
||||
import ElipsePeer from './peer/svg/ElipsePeer';
|
||||
import LinePeer from './peer/svg/LinePeer';
|
||||
import StraightLinePeer from './peer/svg/StraightPeer';
|
||||
import PolyLinePeer from './peer/svg/PolyLinePeer';
|
||||
import CurvedLinePeer from './peer/svg/CurvedLinePeer';
|
||||
import ArrowPeer from './peer/svg/ArrowPeer';
|
||||
@ -40,8 +40,8 @@ class Toolkit {
|
||||
return new ElipsePeer();
|
||||
}
|
||||
|
||||
static createLine() {
|
||||
return new LinePeer();
|
||||
static createStraightLine() {
|
||||
return new StraightLinePeer();
|
||||
}
|
||||
|
||||
static createPolyLine() {
|
||||
|
@ -149,11 +149,11 @@ class ElementPeer {
|
||||
}
|
||||
|
||||
getStroke() {
|
||||
const vmlStroke = this._native;
|
||||
const color = vmlStroke.getAttribute('stroke');
|
||||
const stoke = this._native;
|
||||
const color = stoke.getAttribute('stroke');
|
||||
const dashstyle = this._stokeStyle;
|
||||
const opacity = vmlStroke.getAttribute('stroke-opacity');
|
||||
const width = vmlStroke.getAttribute('stroke-width');
|
||||
const opacity = stoke.getAttribute('stroke-opacity');
|
||||
const width = stoke.getAttribute('stroke-width');
|
||||
return {
|
||||
color,
|
||||
style: dashstyle,
|
||||
@ -171,6 +171,28 @@ class ElementPeer {
|
||||
}
|
||||
if ($defined(style)) {
|
||||
this._stokeStyle = style;
|
||||
|
||||
switch (style) {
|
||||
case 'dash':
|
||||
this._native.setAttribute('stroke-dasharray', '5 5');
|
||||
this._native.setAttribute('stroke-linecap', null);
|
||||
break;
|
||||
case 'dot':
|
||||
this._native.setAttribute('stroke-dasharray', '1 8');
|
||||
this._native.setAttribute('stroke-linecap', 'round');
|
||||
break;
|
||||
case 'dashdot':
|
||||
case 'longdash':
|
||||
this._native.setAttribute('stroke-dasharray', '10 5 2');
|
||||
this._native.setAttribute('stroke-linecap', 'round');
|
||||
break;
|
||||
case 'solid':
|
||||
this._native.setAttribute('stroke-dasharray', null);
|
||||
this._native.setAttribute('stroke-linecap', null);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported style: ${style}`);
|
||||
}
|
||||
}
|
||||
|
||||
if ($defined(opacity)) {
|
||||
|
@ -15,11 +15,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $defined } from '@wisemapping/core-js';
|
||||
import ElementPeer from './ElementPeer';
|
||||
import Point from '../../Point';
|
||||
|
||||
class LinePeer extends ElementPeer {
|
||||
class StraightLinePeer extends ElementPeer {
|
||||
constructor() {
|
||||
const svgElement = window.document.createElementNS(ElementPeer.svgNamespace, 'line');
|
||||
super(svgElement);
|
||||
@ -47,20 +46,6 @@ class LinePeer extends ElementPeer {
|
||||
getTo() {
|
||||
return new Point(this._x2, this._y2);
|
||||
}
|
||||
|
||||
/*
|
||||
* http://www.zvon.org/HowTo/Output/howto_jj_svg_27.html?at=marker-end
|
||||
*/
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
setArrowStyle(startStyle, endStyle) {
|
||||
if ($defined(startStyle)) {
|
||||
// Todo: This must be implemented ...
|
||||
}
|
||||
|
||||
if ($defined(endStyle)) {
|
||||
// Todo: This must be implemented ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default LinePeer;
|
||||
export default StraightLinePeer;
|
@ -18,7 +18,7 @@
|
||||
|
||||
import Workspace from './components/Workspace';
|
||||
import Elipse from './components/Elipse';
|
||||
import Line from './components/Line';
|
||||
import StraightLine from './components/StraightLine';
|
||||
import PolyLine from './components/PolyLine';
|
||||
import CurvedLine from './components/CurvedLine';
|
||||
import Arrow from './components/Arrow';
|
||||
@ -28,4 +28,4 @@ import Text from './components/Text';
|
||||
import Point from './components/Point';
|
||||
import Image from './components/Image';
|
||||
|
||||
export { Arrow, CurvedLine, Elipse, Group, Image, Line, Point, PolyLine, Rect, Text, Workspace };
|
||||
export { Arrow, CurvedLine, Elipse, Group, Image, StraightLine, Point, PolyLine, Rect, Text, Workspace };
|
||||
|
93
packages/web2d/storybook/src/stories/CurvedLine.js
Normal file
@ -0,0 +1,93 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
import CurvedLine from '../../../src/components/CurvedLine';
|
||||
import Elipse from '../../../src/components/Elipse';
|
||||
import Workspace from '../../../src/components/Workspace';
|
||||
import Point from '../../../src/components/Point';
|
||||
|
||||
export const createCurvedLine = ({
|
||||
fillColor,
|
||||
strokeColor,
|
||||
strokeWidth,
|
||||
strokeStyle,
|
||||
width,
|
||||
}) => {
|
||||
const divElem = document.createElement('div');
|
||||
|
||||
const workspace = new Workspace();
|
||||
workspace.setSize('400px', '400px');
|
||||
workspace.setCoordSize(400, 400);
|
||||
workspace.setCoordOrigin(-200, -200);
|
||||
|
||||
// Line 1 ...
|
||||
const line1 = new CurvedLine();
|
||||
line1.setFrom(0, 0);
|
||||
line1.setTo(100, 100);
|
||||
line1.setSrcControlPoint(new Point(100 / 2, 0));
|
||||
line1.setDestControlPoint(new Point(-100 / 2, 0));
|
||||
line1.setStroke(strokeWidth, strokeStyle, strokeColor, 1);
|
||||
line1.setFill(fillColor, 1);
|
||||
line1.setWidth(width);
|
||||
workspace.append(line1);
|
||||
|
||||
const line2 = new CurvedLine();
|
||||
line2.setFrom(0, 0);
|
||||
line2.setTo(-100, -100);
|
||||
line2.setSrcControlPoint(new Point(-100 / 2, 0));
|
||||
line2.setDestControlPoint(new Point(100 / 2, 0));
|
||||
line2.setStroke(strokeWidth, strokeStyle, strokeColor, 1);
|
||||
line2.setFill(fillColor, 1);
|
||||
line2.setWidth(width);
|
||||
workspace.append(line2);
|
||||
|
||||
const line3 = new CurvedLine();
|
||||
line3.setFrom(0, 0);
|
||||
line3.setTo(100, -100);
|
||||
line3.setSrcControlPoint(new Point(100 / 2, 0));
|
||||
line3.setDestControlPoint(new Point(-100 / 2, 0));
|
||||
line3.setStroke(strokeWidth, strokeStyle, strokeColor, 1);
|
||||
line3.setFill(fillColor, 1);
|
||||
line3.setWidth(width);
|
||||
workspace.append(line3);
|
||||
|
||||
const line4 = new CurvedLine();
|
||||
line4.setFrom(0, 0);
|
||||
line4.setTo(-100, 100);
|
||||
line4.setSrcControlPoint(new Point(-100 / 2, 0));
|
||||
line4.setDestControlPoint(new Point(100 / 2, 0));
|
||||
line4.setStroke(strokeWidth, strokeStyle, strokeColor, 1);
|
||||
line4.setFill(fillColor, 1);
|
||||
line4.setWidth(width);
|
||||
workspace.append(line4);
|
||||
|
||||
// Add referene point ...
|
||||
const e1 = new Elipse();
|
||||
e1.setSize(5, 5);
|
||||
e1.setPosition(0, 0);
|
||||
e1.setFill('red');
|
||||
workspace.append(e1);
|
||||
|
||||
const e2 = new Elipse();
|
||||
e2.setPosition(-100, -100);
|
||||
e2.setSize(10, 10);
|
||||
workspace.append(e2);
|
||||
|
||||
const e3 = new Elipse();
|
||||
e3.setPosition(100, 100);
|
||||
e3.setSize(10, 10);
|
||||
workspace.append(e3);
|
||||
|
||||
const e4 = new Elipse();
|
||||
e4.setPosition(-100, 100);
|
||||
e4.setSize(10, 10);
|
||||
workspace.append(e4);
|
||||
|
||||
const e5 = new Elipse();
|
||||
e5.setPosition(100, -100);
|
||||
e5.setSize(10, 10);
|
||||
workspace.append(e5);
|
||||
|
||||
workspace.addItAsChildTo(divElem);
|
||||
|
||||
return divElem;
|
||||
};
|
45
packages/web2d/storybook/src/stories/CurvedLine.stories.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { createCurvedLine } from './CurvedLine';
|
||||
|
||||
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
||||
export default {
|
||||
title: 'Shapes/CurvedLine',
|
||||
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
||||
argTypes: {
|
||||
fillColor: { control: 'color' },
|
||||
width: { control: { type: 'number', min: 0, max: 100, step: 5 } },
|
||||
strokeColor: { control: 'color' },
|
||||
strokeStyle: {
|
||||
control: { type: 'select' },
|
||||
options: ['dash', 'dot', 'solid', 'longdash', 'dashdot'],
|
||||
},
|
||||
strokeWidth: { control: { type: 'number', min: 0, max: 30, step: 1 } },
|
||||
},
|
||||
};
|
||||
|
||||
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
||||
const Template = ({ label, ...args }) => createCurvedLine({ label, ...args });
|
||||
|
||||
export const Width = Template.bind({});
|
||||
Width.args = {
|
||||
width: 10,
|
||||
strokeWidth: 1,
|
||||
strokeStyle: 'solid',
|
||||
strokeColor: 'blue',
|
||||
fillColor: 'red',
|
||||
};
|
||||
|
||||
export const Stroke = Template.bind({});
|
||||
Stroke.args = {
|
||||
width: 10,
|
||||
strokeWidth: 1,
|
||||
strokeStyle: 'longdash',
|
||||
strokeColor: 'red',
|
||||
fillColor: '#1212eb',
|
||||
};
|
||||
|
||||
export const Fill = Template.bind({});
|
||||
Fill.args = {
|
||||
width: 10,
|
||||
strokeWidth: 0,
|
||||
fillColor: 'red',
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
import { createElement } from './Element';
|
||||
|
||||
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
||||
export default {
|
||||
title: 'Shapes/Element',
|
||||
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
||||
argTypes: {
|
||||
onClick: { action: 'onClick' },
|
||||
onMouseOver: { action: 'onMouseOver' },
|
||||
onMouseMove: { action: 'onMouseMove' },
|
||||
onMouseOut: { action: 'onMouseOut' },
|
||||
onDblClick: { action: 'onDblClick' },
|
||||
},
|
||||
};
|
||||
|
||||
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
||||
export const Events = (({ label, ...args }) => createElement({ label, ...args })).bind({});
|
||||
Events.args = {
|
||||
};
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { createEventRegistration } from './Element';
|
||||
|
||||
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
||||
export default {
|
||||
title: 'Shapes/Element',
|
||||
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
||||
argTypes: {
|
||||
enableForWorkspace: { control: 'boolean' },
|
||||
enableForInnerCircle: { control: 'boolean' },
|
||||
enableForOuterCircle: { control: 'boolean' },
|
||||
stopEventPropagation: { control: 'boolean' },
|
||||
onClick: { action: 'onClick' },
|
||||
onMouseOver: { action: 'onMouseOver' },
|
||||
onMouseOut: { action: 'onMouseOut' },
|
||||
onDblClick: { action: 'onDblClick' },
|
||||
},
|
||||
};
|
||||
|
||||
export const EventsRegistration = (({ label, ...args }) => createEventRegistration({ label, ...args })).bind({});
|
||||
EventsRegistration.args = {
|
||||
enableForWorkspace: false,
|
||||
enableForInnerCircle: false,
|
||||
enableForOuterCircle: false,
|
||||
stopEventPropagation: true,
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
import { createElement } from './Element';
|
||||
|
||||
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
||||
export default {
|
||||
title: 'Shapes/Element',
|
||||
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
||||
argTypes: {
|
||||
fillOpacity: { control: { type: 'number', min: 0, max: 1, step: 0.1 } },
|
||||
strokeOpacity: { control: { type: 'number', min: 0, max: 1, step: 0.1 } },
|
||||
},
|
||||
};
|
||||
|
||||
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
||||
const Template = ({ label, ...args }) => createElement({ label, ...args });
|
||||
|
||||
export const Opacity = Template.bind({});
|
||||
Opacity.args = {
|
||||
fillOpacity: 0.5,
|
||||
strokeOpacity: 0.5,
|
||||
opacity: 1,
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
import { createElement } from './Element';
|
||||
|
||||
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
||||
export default {
|
||||
title: 'Shapes/Element',
|
||||
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
||||
argTypes: {
|
||||
visibility: { control: 'boolean' },
|
||||
visibilityDelay: { control: { type: 'number', min: 1, max: 1000, step: 100 } },
|
||||
},
|
||||
};
|
||||
|
||||
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
||||
const Template = ({ label, ...args }) => createElement({ label, ...args });
|
||||
|
||||
export const Visibility = Template.bind({});
|
||||
Visibility.args = {
|
||||
visibility: true,
|
||||
visibilityDelay: 5000,
|
||||
};
|