wisemapping-frontend/packages/web2d/test/playground/line.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
2022-07-13 03:58:11 +02:00
import { Workspace, Line, Rect } from '../../src';
2021-12-05 00:39:20 +01:00
global.$ = $;
const workspaceAttributes = {
2022-07-13 03:58:11 +02:00
width: '700px',
height: '100px',
coordSize: '350 50',
fillColor: '#ffffcc',
2021-12-05 00:39:20 +01:00
};
const strokeWidthWorkspace = new Workspace(workspaceAttributes);
const rect = new Rect();
rect.setSize(10, 10);
rect.setStroke(0);
rect.setPosition(250, 5);
strokeWidthWorkspace.append(rect);
for (let i = 0; i <= 10; i++) {
const line = new Line();
2022-07-13 03:58:11 +02:00
line.setFrom(5 + i * 25, 5);
line.setTo(5 + i * 25, 45);
2021-12-05 00:39:20 +01:00
line.setAttribute('strokeWidth', i + 1);
strokeWidthWorkspace.append(line);
}
strokeWidthWorkspace.append(rect);
strokeWidthWorkspace.addItAsChildTo($('#strokeWidthSample'));
const strokeOpacityWorkspace = new Workspace(workspaceAttributes);
for (let i = 0; i < 10; i++) {
const line = new Line();
2022-07-13 03:58:11 +02:00
line.setFrom(15 + i * 25, 5);
line.setTo(3 + i * 25, 45);
2021-12-05 00:39:20 +01:00
line.setAttribute('strokeWidth', 2);
line.setAttribute('strokeOpacity', 1 / (i + 1));
line.setAttribute('strokeColor', 'red');
strokeOpacityWorkspace.append(line);
}
strokeOpacityWorkspace.addItAsChildTo($('#strokeOpacitySample'));
const strokeStyleWorkspace = new Workspace(workspaceAttributes);
const styles = ['solid', 'dot', 'dash', 'dashdot', 'longdash'];
for (let i = 0; i < styles.length; i++) {
const line = new Line();
2022-07-13 03:58:11 +02:00
line.setFrom(25 + i * 30, 5);
line.setTo(13 + i * 30, 45);
2021-12-05 00:39:20 +01:00
line.setAttribute('strokeWidth', 2);
line.setAttribute('strokeColor', 'red');
line.setAttribute('strokeStyle', styles[i]);
strokeStyleWorkspace.append(line);
}
strokeStyleWorkspace.addItAsChildTo($('#strokeStyleSample'));
const strokeArrowWorkspace = new Workspace(workspaceAttributes);
2022-07-13 03:58:11 +02:00
const styles2 = [
'none ',
'block ',
'classic',
'diamond ',
'oval',
'open',
'chevron',
'doublechevron',
];
2021-12-05 00:39:20 +01:00
for (let i = 0; i < styles.length; i++) {
const line = new Line();
2022-07-13 03:58:11 +02:00
line.setFrom(25 + i * 30, 5);
line.setTo(13 + i * 30, 45);
2021-12-05 00:39:20 +01:00
line.setAttribute('strokeWidth', 2);
line.setAttribute('strokeColor', 'red');
line.setArrowStyle(styles2[i]);
strokeArrowWorkspace.append(line);
}
strokeArrowWorkspace.addItAsChildTo($('#strokeArrowSample'));