Compare commits
11 Commits
functions-
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b76c1df3a | |||
| 4cb50a4276 | |||
| 11c2222536 | |||
| 1541d62bb5 | |||
| cd13d21e5f | |||
| d8e3dc8cee | |||
| 7f7a4a1ae6 | |||
| e078914ed2 | |||
| 9234986b6f | |||
| 4bbd92920e | |||
| 2adc151e8e |
12
README.md
12
README.md
@@ -13,15 +13,15 @@ Funkcjonalności aplikacji koncentrują się na tworzeniu i modyfikacji kształt
|
|||||||
- [x] 3. Tworzenie elipsy
|
- [x] 3. Tworzenie elipsy
|
||||||
|
|
||||||
### Akcje na kształtach
|
### Akcje na kształtach
|
||||||
- [ ] 4. Zmiana rozmiaru kształtów.
|
- [x] 4. Zmiana rozmiaru kształtów.
|
||||||
- [x] 5. Przeciągnięcie kzstałtu po planszy
|
- [x] 5. Przeciągnięcie kzstałtu po planszy
|
||||||
- [x] 6. Usunięcie kształtu
|
- [x] 6. Usunięcie kształtu
|
||||||
- [x] 7. Zaznaczenie kształtu
|
- [x] 7. Zaznaczenie kształtu
|
||||||
- [ ] 8. Kopiowanie kształtu
|
- [x] 8. Kopiowanie kształtu
|
||||||
- [ ] 9. Wklejanie kształtu
|
- [x] 9. Wklejanie kształtu
|
||||||
- [ ] 10. Zmiana kolorów kształtów
|
- [x] 10. Zmiana kolorów kształtów
|
||||||
- [ ] 11. Połączenie kształtów (strzałka ->)
|
- [x] 11. Połączenie kształtów (strzałka ->)
|
||||||
- [ ] 12. Usunięcie kształtów
|
- [x] 12. Usunięcie kształtów
|
||||||
|
|
||||||
### Tekst
|
### Tekst
|
||||||
- [x] 13. Dodanie tekstu
|
- [x] 13. Dodanie tekstu
|
||||||
|
|||||||
366
index.html
366
index.html
@@ -10,33 +10,48 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<p>Kształty - przeciągnij i upuść</p>
|
<p>Kształty - przeciągnij i upuść</p>
|
||||||
<div class="shape-wrapper toolbar-wrapper">
|
<div class="shape-wrapper toolbar-wrapper">
|
||||||
<div id="shape-rectangle" class="shape" data-type="rectangle"></div>
|
<div id="shape-rectangle" class="shape" data-type="rectangle"></div>
|
||||||
<div id="shape-ellipse" class="shape" data-type="ellipse"></div>
|
<div id="shape-ellipse" class="shape" data-type="ellipse"></div>
|
||||||
<div id="shape-diamond" class="shape" data-type="diamond"></div>
|
<div id="shape-diamond" class="shape" data-type="diamond"></div>
|
||||||
<div id="shape-text" class="shape" data-type="text">Tekst</div>
|
<div id="shape-text" class="shape" data-type="text">Tekst</div>
|
||||||
</div>
|
</div>
|
||||||
<p>Zoom</p>
|
<p>Akcje</p>
|
||||||
<div class="zoom-wrapper toolbar-wrapper">
|
<div class="tools-wrapper toolbar-wrapper">
|
||||||
<button id="zoom-in">+</button>
|
<button id="btn-delete">Usuń</button>
|
||||||
<button id="zoom-out">-</button>
|
<button id="btn-copy">Kopiuj</button>
|
||||||
|
<button id="btn-paste">Wklej</button>
|
||||||
|
<button id="btn-connect">Połącz</button>
|
||||||
|
<div class="color-wrapper">
|
||||||
|
<button id="btn-change-color">Kolor</button>
|
||||||
|
<div id="color-palette"
|
||||||
|
style="position:absolute; display:none; padding:8px; background:#fff; border:1px solid #ccc; border-radius:6px; gap:6px; z-index:2000;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="canvas-container">
|
<p>Zoom</p>
|
||||||
<div id="paper"></div>
|
<div class="zoom-wrapper toolbar-wrapper">
|
||||||
|
<button id="zoom-in">+</button>
|
||||||
|
<button id="zoom-out">-</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
<div id="resize-handle" style="position: absolute; display: none; border: 2px dashed #4A90E2; z-index: 10;"></div>
|
||||||
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
|
<div class="canvas-container">
|
||||||
<script src="joint.js"></script>
|
<div id="paper"></div>
|
||||||
<script>
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||||
|
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
|
||||||
|
<script src="joint.js"></script>
|
||||||
|
<script>
|
||||||
let selectedElement = null;
|
let selectedElement = null;
|
||||||
let activeElementView = null;
|
let activeElementView = null;
|
||||||
|
let clipboard = null;
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
//init paper - Start
|
|
||||||
const graph = new joint.dia.Graph();
|
const graph = new joint.dia.Graph();
|
||||||
const paper = new joint.dia.Paper({
|
const paper = new joint.dia.Paper({
|
||||||
el: $('#paper'),
|
el: $('#paper'),
|
||||||
@@ -44,51 +59,97 @@
|
|||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
height: window.innerHeight,
|
height: window.innerHeight,
|
||||||
gridSize: 20,
|
gridSize: 20,
|
||||||
|
preventContextMenu: false,
|
||||||
});
|
});
|
||||||
//init paper - END
|
|
||||||
|
const $resizeHandle = $('#resize-handle');
|
||||||
|
|
||||||
|
// --- DODANE FUNKCJE START ---
|
||||||
|
let connectMode = false;
|
||||||
|
|
||||||
|
$('#btn-connect').click(function () {
|
||||||
|
if (!selectedElement) return;
|
||||||
|
connectMode = !connectMode;
|
||||||
|
$(this).css('background', connectMode ? '#e3f2fd' : '#fff');
|
||||||
|
});
|
||||||
|
|
||||||
|
const paletteColors = ['#FF4B4B', '#FFA500', '#FFD700', '#4CAF50', '#00BCD4', '#2196F3', '#9C27B0', '#795548', '#000000'];
|
||||||
|
const $palette = $('#color-palette');
|
||||||
|
$palette.css({gridTemplateColumns: 'repeat(3,28px)'});
|
||||||
|
|
||||||
|
paletteColors.forEach(c => {
|
||||||
|
// ZMIANA TUTAJ: Dodajemy width, height, border i cursor
|
||||||
|
const tile = $('<div></div>').css({
|
||||||
|
background: c,
|
||||||
|
width: '28px', // Dodane
|
||||||
|
height: '28px', // Dodane
|
||||||
|
border: '1px solid #444', // Dodane dla widoczności
|
||||||
|
cursor: 'pointer' // Dodane dla kursora rączki
|
||||||
|
});
|
||||||
|
|
||||||
|
tile.on('click', function () {
|
||||||
|
if (selectedElement) {
|
||||||
|
try {
|
||||||
|
// Ustawianie koloru
|
||||||
|
selectedElement.attr('body/fill', c);
|
||||||
|
if (selectedElement.attributes.type === 'standard.TextBlock') {
|
||||||
|
selectedElement.attr('label/fill', c);
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignoruj */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$palette.hide();
|
||||||
|
});
|
||||||
|
$palette.append(tile);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#btn-change-color').on('click', function () {
|
||||||
|
$palette.toggleClass('active');
|
||||||
|
});
|
||||||
|
$(document).on('click', function (e) {
|
||||||
|
if (!$(e.target).closest('#color-palette,#btn-change-color').length)
|
||||||
|
if ($palette.hasClass('active'))
|
||||||
|
$palette.toggleClass('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
paper.on('element:pointerclick', function (elementView) {
|
||||||
|
if (connectMode && selectedElement && selectedElement !== elementView.model) {
|
||||||
|
const link = new joint.shapes.standard.Link();
|
||||||
|
link.source(selectedElement);
|
||||||
|
link.target(elementView.model);
|
||||||
|
graph.addCell(link);
|
||||||
|
connectMode = false;
|
||||||
|
$('#btn-connect').css('background', '#fff');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// --- DODANE FUNKCJE KONIEC ---
|
||||||
|
|
||||||
// obwódka i znaczek usuwanie
|
// obwódka i znaczek usuwanie
|
||||||
function createToolsView() {
|
function createToolsView() {
|
||||||
return new joint.dia.ToolsView({
|
return new joint.dia.ToolsView({
|
||||||
tools: [
|
tools: [
|
||||||
new joint.elementTools.Boundary({
|
new joint.elementTools.Boundary({
|
||||||
padding: 10,
|
padding: 20,
|
||||||
}),
|
}),
|
||||||
new joint.elementTools.Remove({
|
new joint.elementTools.Remove({
|
||||||
|
offset: {x: -10, y: -10},
|
||||||
focusOpacity: 0.5,
|
focusOpacity: 0.5,
|
||||||
|
action: function () {
|
||||||
|
deleteShape();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//create shape - START
|
|
||||||
function createRectangle(paperX, paperY) {
|
|
||||||
const rect = new joint.shapes.standard.Rectangle({
|
|
||||||
position: { x: paperX - 40, y: paperY - 24 },
|
|
||||||
size: { width: 80, height: 48 },
|
|
||||||
attrs: {
|
|
||||||
body: {
|
|
||||||
fill: 'transparent',
|
|
||||||
stroke: '#000000',
|
|
||||||
strokeWidth: 1
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
text: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
graph.addCell(rect);
|
|
||||||
const elementView = rect.findView(paper);
|
|
||||||
elementView.addTools(createToolsView());
|
|
||||||
}
|
|
||||||
|
|
||||||
function createDiamond(paperX, paperY) {
|
function createDiamond(paperX, paperY) {
|
||||||
const rect = new joint.shapes.standard.Rectangle({
|
const diamond = new joint.shapes.standard.Polygon({
|
||||||
position: { x: paperX - 24, y: paperY - 24 },
|
position: {x: paperX - 24, y: paperY - 24},
|
||||||
size: { width: 48, height: 48 },
|
size: {width: 48, height: 48},
|
||||||
angle: 45,
|
|
||||||
attrs: {
|
attrs: {
|
||||||
body: {
|
body: {
|
||||||
|
refPoints: '0.5,0 1,0.5 0.5,1 0,0.5', // Diamond shape points
|
||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
stroke: '#000000',
|
stroke: '#000000',
|
||||||
strokeWidth: 1
|
strokeWidth: 1
|
||||||
@@ -98,15 +159,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
graph.addCell(rect);
|
|
||||||
const elementView = rect.findView(paper);
|
graph.addCell(diamond);
|
||||||
|
const elementView = diamond.findView(paper);
|
||||||
elementView.addTools(createToolsView());
|
elementView.addTools(createToolsView());
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEllipse(paperX, paperY) {
|
function createEllipse(paperX, paperY) {
|
||||||
const rect = new joint.shapes.standard.Ellipse({
|
const rect = new joint.shapes.standard.Ellipse({
|
||||||
position: { x: paperX - 40, y: paperY - 24 },
|
position: {x: paperX - 40, y: paperY - 24},
|
||||||
size: { width: 80, height: 48 },
|
size: {width: 80, height: 48},
|
||||||
attrs: {
|
attrs: {
|
||||||
body: {
|
body: {
|
||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
@@ -125,8 +187,8 @@
|
|||||||
|
|
||||||
function createText(paperX, paperY) {
|
function createText(paperX, paperY) {
|
||||||
const textBlock = new joint.shapes.standard.TextBlock({
|
const textBlock = new joint.shapes.standard.TextBlock({
|
||||||
position: { x: paperX - 40, y: paperY - 24 },
|
position: {x: paperX - 40, y: paperY - 24},
|
||||||
size: { width: 80, height: 48 },
|
size: {width: 80, height: 48},
|
||||||
attrs: {
|
attrs: {
|
||||||
body: {
|
body: {
|
||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
@@ -144,6 +206,7 @@
|
|||||||
const elementView = textBlock.findView(paper);
|
const elementView = textBlock.findView(paper);
|
||||||
elementView.addTools(createToolsView());
|
elementView.addTools(createToolsView());
|
||||||
}
|
}
|
||||||
|
|
||||||
//create shape - END
|
//create shape - END
|
||||||
|
|
||||||
//init draggalble - START
|
//init draggalble - START
|
||||||
@@ -180,6 +243,7 @@
|
|||||||
|
|
||||||
activeElementView = null;
|
activeElementView = null;
|
||||||
selectedElement = null;
|
selectedElement = null;
|
||||||
|
hideResizeHandle();
|
||||||
|
|
||||||
if (shapeType === 'rectangle') {
|
if (shapeType === 'rectangle') {
|
||||||
createRectangle(paperX, paperY);
|
createRectangle(paperX, paperY);
|
||||||
@@ -200,16 +264,79 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//init draggable - END
|
//init draggable - END
|
||||||
|
|
||||||
|
function getViewportCenter() {
|
||||||
|
const container = $('.canvas-container');
|
||||||
|
const scale = paper.scale();
|
||||||
|
const translate = paper.translate();
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: (container.width() / 2 - translate.tx) / scale.sx,
|
||||||
|
y: (container.height() / 2 - translate.ty) / scale.sy
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyShape() {
|
||||||
|
if (selectedElement) {
|
||||||
|
clipboard = selectedElement.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pasteShape() {
|
||||||
|
if (clipboard) {
|
||||||
|
const center = getViewportCenter();
|
||||||
|
const pasted = clipboard.clone();
|
||||||
|
pasted.position(center.x + 20, center.y + 20);
|
||||||
|
graph.addCell(pasted);
|
||||||
|
|
||||||
|
const pastedView = pasted.findView(paper);
|
||||||
|
if (pastedView) {
|
||||||
|
pastedView.addTools(createToolsView());
|
||||||
|
pastedView.showTools();
|
||||||
|
|
||||||
|
if (activeElementView && activeElementView !== pastedView) {
|
||||||
|
activeElementView.hideTools();
|
||||||
|
}
|
||||||
|
activeElementView = pastedView;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedElement = pasted;
|
||||||
|
showResizeHandle(pastedView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteShape() {
|
||||||
|
if (selectedElement) {
|
||||||
|
selectedElement.remove();
|
||||||
|
selectedElement = null;
|
||||||
|
activeElementView = null;
|
||||||
|
hideResizeHandle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#btn-delete').click(function () {
|
||||||
|
deleteShape()
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#btn-copy').click(function () {
|
||||||
|
copyShape();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#btn-paste').click(function () {
|
||||||
|
pasteShape();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
paper.on('element:pointerclick', function (elementView) {
|
paper.on('element:pointerclick', function (elementView) {
|
||||||
if (activeElementView && activeElementView !== elementView) {
|
if (activeElementView && activeElementView !== elementView) {
|
||||||
activeElementView.hideTools();
|
activeElementView.hideTools();
|
||||||
}
|
}
|
||||||
elementView.showTools();
|
elementView.showTools();
|
||||||
activeElementView = elementView;
|
activeElementView = elementView;
|
||||||
|
|
||||||
selectedElement = elementView.model;
|
selectedElement = elementView.model;
|
||||||
|
showResizeHandle(elementView);
|
||||||
});
|
});
|
||||||
|
|
||||||
let panStart = null;
|
let panStart = null;
|
||||||
@@ -224,6 +351,7 @@
|
|||||||
activeElementView = null;
|
activeElementView = null;
|
||||||
}
|
}
|
||||||
selectedElement = null;
|
selectedElement = null;
|
||||||
|
hideResizeHandle();
|
||||||
//ruszanie caloscia
|
//ruszanie caloscia
|
||||||
panStart = {
|
panStart = {
|
||||||
x: evt.clientX,
|
x: evt.clientX,
|
||||||
@@ -239,6 +367,7 @@
|
|||||||
const dx = evt.clientX - panStart.x;
|
const dx = evt.clientX - panStart.x;
|
||||||
const dy = evt.clientY - panStart.y;
|
const dy = evt.clientY - panStart.y;
|
||||||
paper.translate(panStart.tx + dx, panStart.ty + dy);
|
paper.translate(panStart.tx + dx, panStart.ty + dy);
|
||||||
|
showResizeHandle(activeElementView);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -250,41 +379,153 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
//add text to text block - START
|
//add text to text block - START
|
||||||
paper.on('element:pointerdblclick', function (elementView) {
|
paper.on('element:contextmenu', function (elementView, ev) {
|
||||||
if (elementView.model.attributes.type === 'standard.TextBlock') {
|
if (elementView.model.attributes.type === 'standard.TextBlock') {
|
||||||
|
ev.preventDefault();
|
||||||
const currentText = elementView.model.attr('label/text');
|
const currentText = elementView.model.attr('label/text');
|
||||||
const newText = prompt('Edytuj tekst:', currentText);
|
const newText = prompt('Edytuj tekst:', currentText);
|
||||||
if (newText != null) {
|
if (newText != null) {
|
||||||
elementView.model.attr('label/text', newText);
|
elementView.model.attr('label/text', newText);
|
||||||
}
|
}
|
||||||
|
} else if (elementView.model.attributes.type !== 'standard.TextBlock') {
|
||||||
|
ev.preventDefault();
|
||||||
|
const currentText = elementView.model.attr('label/text') || '';
|
||||||
|
const newText = prompt('Edytuj tekst:', currentText);
|
||||||
|
if (newText != null) {
|
||||||
|
elementView.model.attr('label/text', newText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('keydown', function (e) {
|
$(document).on('keydown', function (e) {
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
|
||||||
|
e.preventDefault();
|
||||||
|
copyShape();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'v') {
|
||||||
|
e.preventDefault();
|
||||||
|
pasteShape();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.key === 'Delete' && selectedElement) {
|
if (e.key === 'Delete' && selectedElement) {
|
||||||
// if (selectedElement.attributes.type === 'standard.TextBlock') {
|
deleteShape();
|
||||||
selectedElement.remove();
|
|
||||||
selectedElement = null;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//add text to text block - END
|
//add text to text block - END
|
||||||
|
|
||||||
|
// resize
|
||||||
|
|
||||||
|
function showResizeHandle(elementView) {
|
||||||
|
if (!elementView) return;
|
||||||
|
|
||||||
|
const bbox = elementView.model.getBBox();
|
||||||
|
const clientRect = paper.localToClientRect(bbox);
|
||||||
|
|
||||||
|
const angle = elementView.model.get('angle') || 0;
|
||||||
|
|
||||||
|
$resizeHandle.css({
|
||||||
|
left: clientRect.x,
|
||||||
|
top: clientRect.y,
|
||||||
|
width: clientRect.width,
|
||||||
|
height: clientRect.height,
|
||||||
|
transform: `rotate(${angle}deg)`,
|
||||||
|
transformOrigin: 'center center'
|
||||||
|
}).show();
|
||||||
|
|
||||||
|
if ($resizeHandle.data('ui-resizable')) {
|
||||||
|
$resizeHandle.resizable('destroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
let originalBBox;
|
||||||
|
|
||||||
|
$resizeHandle.resizable({
|
||||||
|
handles: 'n, e, s, w, ne, se, sw, nw',
|
||||||
|
start: function () {
|
||||||
|
if (activeElementView) {
|
||||||
|
activeElementView.hideTools();
|
||||||
|
}
|
||||||
|
originalBBox = selectedElement.getBBox();
|
||||||
|
},
|
||||||
|
resize: function (event, ui) {
|
||||||
|
if (selectedElement && originalBBox) {
|
||||||
|
const scale = paper.scale();
|
||||||
|
const newWidth = ui.size.width / scale.sx;
|
||||||
|
const newHeight = ui.size.height / scale.sy;
|
||||||
|
|
||||||
|
const newX = originalBBox.x + (ui.position.left - ui.originalPosition.left) / scale.sx;
|
||||||
|
const newY = originalBBox.y + (ui.position.top - ui.originalPosition.top) / scale.sy;
|
||||||
|
|
||||||
|
if (selectedElement.get('angle')) {
|
||||||
|
selectedElement.resize(newWidth, newHeight, {direction: 'center'});
|
||||||
|
} else {
|
||||||
|
selectedElement.position(newX, newY);
|
||||||
|
selectedElement.resize(newWidth, newHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
stop: function () {
|
||||||
|
if (activeElementView) {
|
||||||
|
activeElementView.showTools();
|
||||||
|
showResizeHandle(activeElementView);
|
||||||
|
}
|
||||||
|
originalBBox = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hideResizeHandle() {
|
||||||
|
if ($resizeHandle.data('ui-resizable')) {
|
||||||
|
$resizeHandle.resizable('destroy');
|
||||||
|
}
|
||||||
|
$resizeHandle.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
//create shape - START
|
||||||
|
function createRectangle(paperX, paperY) {
|
||||||
|
const rect = new joint.shapes.standard.Rectangle({
|
||||||
|
position: {x: paperX - 40, y: paperY - 24},
|
||||||
|
size: {width: 80, height: 48},
|
||||||
|
attrs: {
|
||||||
|
body: {
|
||||||
|
fill: 'transparent',
|
||||||
|
stroke: '#000000',
|
||||||
|
strokeWidth: 1
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
text: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
graph.addCell(rect);
|
||||||
|
const elementView = rect.findView(paper);
|
||||||
|
elementView.addTools(createToolsView());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Zoom
|
// Zoom
|
||||||
const zoomStep = 0.2;
|
const zoomStep = 0.2;
|
||||||
const minScale = 0.2;
|
const minScale = 0.2;
|
||||||
const maxScale = 3.0;
|
const maxScale = 3.0;
|
||||||
|
|
||||||
|
function applyZoom(newScale, ox, oy) {
|
||||||
|
paper.scale(newScale, newScale, ox, oy);
|
||||||
|
showResizeHandle(activeElementView);
|
||||||
|
}
|
||||||
|
|
||||||
$('#zoom-in').click(function () {
|
$('#zoom-in').click(function () {
|
||||||
const currentScale = paper.scale().sx;
|
const currentScale = paper.scale().sx;
|
||||||
const newScale = Math.min(maxScale, currentScale + zoomStep);
|
const newScale = Math.min(maxScale, currentScale + zoomStep);
|
||||||
paper.scale(newScale, newScale);
|
applyZoom(newScale);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#zoom-out').click(function () {
|
$('#zoom-out').click(function () {
|
||||||
const currentScale = paper.scale().sx;
|
const currentScale = paper.scale().sx;
|
||||||
const newScale = Math.max(minScale, currentScale - zoomStep);
|
const newScale = Math.max(minScale, currentScale - zoomStep);
|
||||||
paper.scale(newScale, newScale);
|
applyZoom(newScale);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Zoom za pomoca kolka myszy
|
// Zoom za pomoca kolka myszy
|
||||||
@@ -294,10 +535,11 @@
|
|||||||
const zoomFactor = 0.2;
|
const zoomFactor = 0.2;
|
||||||
let newScale = oldScale * (1 + delta * zoomFactor);
|
let newScale = oldScale * (1 + delta * zoomFactor);
|
||||||
newScale = Math.max(minScale, Math.min(maxScale, newScale));
|
newScale = Math.max(minScale, Math.min(maxScale, newScale));
|
||||||
paper.scale(newScale, newScale, x, y);
|
applyZoom(newScale, x, y);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
328
style.css
328
style.css
@@ -1,116 +1,278 @@
|
|||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shape-wrapper {
|
body {
|
||||||
display: grid;
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
background: #f5f5f5;
|
||||||
grid-template-rows: repeat(2, auto);
|
min-height: 100vh;
|
||||||
gap: 30px 10px;
|
overflow: hidden;
|
||||||
padding-bottom: 40px;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#shape-rectangle {
|
.toolbar {
|
||||||
width: 80px;
|
background: #ffffff;
|
||||||
height: 48px;
|
color: #333;
|
||||||
}
|
padding: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
|
||||||
|
position: absolute;
|
||||||
|
width: 280px;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
z-index: 9;
|
||||||
|
overflow-y: auto;
|
||||||
|
border-right: 1px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
#shape-ellipse {
|
.toolbar p {
|
||||||
width: 80px;
|
font-size: 12px;
|
||||||
height: 48px;
|
font-weight: 600;
|
||||||
border-radius: 50%;
|
text-transform: uppercase;
|
||||||
}
|
letter-spacing: 0.5px;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
border-bottom: 2px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
#shape-diamond {
|
.toolbar-wrapper {
|
||||||
height: 48px;
|
background: #f9f9f9;
|
||||||
width: 48px;
|
border-radius: 8px;
|
||||||
transform: rotate(45deg) translateX(15px);
|
border: 1px solid #e0e0e0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#shape-text {
|
.shape-wrapper {
|
||||||
width: 80px;
|
display: flex;
|
||||||
height: 48px;
|
flex-wrap: wrap;
|
||||||
border-style: dashed;
|
gap: 10px;
|
||||||
color: #ffffff;
|
padding: 12px;
|
||||||
font-size: 14px;
|
min-height: 152px;
|
||||||
display: flex;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-content: space-between;
|
||||||
justify-content: center;
|
}
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shape {
|
.shape {
|
||||||
background: transparent;
|
background: #fff;
|
||||||
border: 1px solid white;
|
border: 2px solid #d0d0d0;
|
||||||
cursor: pointer;
|
cursor: grab;
|
||||||
}
|
transition: border-color 0.2s, box-shadow 0.2s;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar {
|
.shape:hover {
|
||||||
background: #3498db;
|
border-color: #666;
|
||||||
color: white;
|
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
|
||||||
padding: 20px;
|
}
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
|
||||||
position: absolute;
|
|
||||||
width: 300px;
|
|
||||||
left: 0px;
|
|
||||||
top: 0px;
|
|
||||||
height: 100vh;
|
|
||||||
z-index: 9;
|
|
||||||
border-top-right-radius: 30px;
|
|
||||||
border-bottom-right-radius: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar-wrapper {
|
.shape:active {
|
||||||
padding-bottom: 30px;
|
cursor: grabbing;
|
||||||
padding: 20px;
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#shape-rectangle {
|
||||||
|
width: 80px;
|
||||||
|
height: 48px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#shape-ellipse {
|
||||||
|
width: 80px;
|
||||||
|
height: 48px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#shape-diamond {
|
||||||
|
height: 48px;
|
||||||
|
width: 48px;
|
||||||
|
transform: rotate(45deg) translate(3px, -16px);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#shape-text {
|
||||||
|
width: 80px;
|
||||||
|
height: 48px;
|
||||||
|
border-style: dashed;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tools wrapper */
|
||||||
|
.tools-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tools-wrapper button {
|
||||||
|
padding: 12px 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
border: 1px solid #d0d0d0;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s, border-color 0.2s;
|
||||||
|
background: #fff;
|
||||||
|
color: #333;
|
||||||
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tools-wrapper button:hover {
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tools-wrapper button:active {
|
||||||
|
background: #e8e8e8;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-delete {
|
||||||
|
color: #d32f2f;
|
||||||
|
border-color: #d32f2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-delete:hover {
|
||||||
|
background: #ffebee;
|
||||||
|
border-color: #c62828;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-copy {
|
||||||
|
color: #1976d2;
|
||||||
|
border-color: #1976d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-copy:hover {
|
||||||
|
background: #e3f2fd;
|
||||||
|
border-color: #1565c0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-paste {
|
||||||
|
color: #388e3c;
|
||||||
|
border-color: #388e3c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-paste:hover {
|
||||||
|
background: #e8f5e9;
|
||||||
|
border-color: #2e7d32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Zoom wrapper */
|
||||||
.zoom-wrapper {
|
.zoom-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 15px;
|
gap: 12px;
|
||||||
padding: 10px 20px !important;
|
padding: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-wrapper button {
|
.zoom-wrapper button {
|
||||||
background: white;
|
background: #fff;
|
||||||
color: #3498db;
|
color: #333;
|
||||||
border: none;
|
border: 1px solid #d0d0d0;
|
||||||
border-radius: 50%;
|
border-radius: 6px;
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
font-size: 24px;
|
font-size: 20px;
|
||||||
|
font-weight: 600;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
transition: all 0.3s ease;
|
transition: background 0.2s, border-color 0.2s;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-wrapper button:hover {
|
.zoom-wrapper button:hover {
|
||||||
background: #2980b9;
|
background: #f5f5f5;
|
||||||
color: white;
|
border-color: #999;
|
||||||
transform: scale(1.1);
|
|
||||||
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-wrapper button:active {
|
.zoom-wrapper button:active {
|
||||||
transform: scale(0.95);
|
background: #e8e8e8;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fajny efekt przy najechaniu */
|
/* Canvas container */
|
||||||
.zoom-wrapper button i {
|
.canvas-container {
|
||||||
transition: transform 0.3s ease;
|
position: absolute;
|
||||||
|
left: 280px;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: #ffffff;
|
||||||
|
background-image:
|
||||||
|
linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
|
||||||
|
linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
|
||||||
|
background-size: 20px 20px;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-wrapper button:hover i {
|
#paper {
|
||||||
transform: scale(1.2);
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scrollbar styling */
|
||||||
|
.toolbar::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar::-webkit-scrollbar-track {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar::-webkit-scrollbar-thumb {
|
||||||
|
background: #d0d0d0;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
#resize-handle {
|
||||||
|
position: absolute;
|
||||||
|
box-sizing: border-box;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.toolbar {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-container {
|
||||||
|
left: 0;
|
||||||
|
top: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* color wrapper */
|
||||||
|
.color-wrapper{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
#color-palette{
|
||||||
|
display:none;
|
||||||
|
top: 41px;
|
||||||
|
}
|
||||||
|
#color-palette.active{
|
||||||
|
display: grid!important;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user