Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change actors size with proportions #635

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions addon/components/fd-uml-diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,35 @@ export default Component.extend({
const shift = data.shift;
if (data.widthResize || data.heightResize) {
const oldSize = data.ghost.size();
const position = data.ghost.position();
let coordinates = forPointerMethodOverrideResizeAndDnd(evt, x, y);
data.ghost.resize(data.widthResize ? Math.max(coordinates.x - position.x, view.model.attributes.inputWidth || 0, view.model.attributes.minWidth || 0) : oldSize.width, data.heightResize ? Math.max(coordinates.y - position.y, view.model.attributes.inputHeight || 0, view.model.attributes.minHeight || 0) : oldSize.height);
let newSize = {
width: oldSize.width,
height: oldSize.height
};
if (data.prop) {
if (data.widthResize && data.heightResize) {
newSize.width = x - view.model.getBBox().x;
} else {
if (data.widthResize) {
newSize.width = x - view.model.getBBox().x
}
if (data.heightResize) {
newSize.height = y - view.model.getBBox().y
}
}
let propHeight = newSize.height + ((newSize.width - oldSize.width) / oldSize.width) * newSize.height;
let propWidth = newSize.width + ((newSize.height - oldSize.height) / oldSize.height) * newSize.width;
if (propHeight < view.model.attributes.minHeight) {
propHeight = view.model.attributes.minHeight
}
if (propWidth < view.model.attributes.minWidth) {
propWidth = view.model.attributes.minWidth
}
data.ghost.resize(propWidth, propHeight);
} else {
const position = data.ghost.position();
let coordinates = forPointerMethodOverrideResizeAndDnd(evt, x, y);
data.ghost.resize(data.widthResize ? Math.max(coordinates.x - position.x, view.model.attributes.inputWidth || 0, view.model.attributes.minWidth || 0) : oldSize.width, data.heightResize ? Math.max(coordinates.y - position.y, view.model.attributes.inputHeight || 0, view.model.attributes.minHeight || 0) : oldSize.height);
DubrovinPavel marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
data.ghost.position(x + shift.x, y + shift.y);
}
Expand All @@ -621,6 +647,7 @@ export default Component.extend({
const button = $(evt.target.parentElement);
evt.data.widthResize = button.hasClass('right-down-size-button') || button.hasClass('right-size-button');
evt.data.heightResize = button.hasClass('right-down-size-button') || button.hasClass('down-size-button');
evt.data.prop = button.hasClass('prop');
evt.data.shift = { x: bbox.x - x, y: bbox.y - y};
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default Mixin.create({
let jsonObject = getJsonForElement(
'STORMCASE.UML.ucd.Actor, UMLUCD',
{ x, y },
{ width: 25, height: 50 },
{ width: 5, height: 60 },
{ Name: '' }
);
let usecaseActorObject = fdUseCaseActor.create({ primitive: jsonObject });
Expand Down
11 changes: 10 additions & 1 deletion addon/objects/uml-primitives/fd-uml-note.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@ joint.util.setByPath(joint.shapes, 'flexberry.uml.Note', Note, '.');
joint.shapes.flexberry.uml.NoteView = joint.shapes.flexberry.uml.BaseObjectView.extend({
template: [
'<div class="uml-class-inputs">',
'<textarea class="class-name-input header-input" value="" rows="1" wrap="off"></textarea>',
'<textarea class="class-name-input header-input" value="" rows="1" wrap="off" style="text-align: left;"></textarea>',
'<div class="input-buffer"></div>',
'</div>'
].join(''),

initialize: function () {
joint.shapes.flexberry.uml.BaseObjectView.prototype.initialize.apply(this, arguments);
let paramsBox = this.$box.find('.header-input');
paramsBox.css({
left: 2,
position: 'absolute'
});
},
});
3 changes: 3 additions & 0 deletions addon/objects/uml-primitives/fd-uml-primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ joint.shapes.flexberry.uml.PrimitiveElementView = joint.dia.ElementView.extend({
buttons.addObjects(sizeChangers);
buttons.forEach(button => {
let style = {};
if (button.name.contains(' ')) {
button.name = button.name.replace(' ', '.');
}
style[`.${get(button, 'name')}`] = get(button, 'attrs.element');
style[`.${get(button, 'name')}>circle`] = get(button, 'attrs.circle');
style[`.${get(button, 'name')}>text`] = get(button, 'attrs.text');
Expand Down
17 changes: 17 additions & 0 deletions addon/objects/uml-primitives/fd-uml-use-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ joint.shapes.flexberry.uml.UseCaseView = joint.shapes.flexberry.uml.BaseObjectVi
'</div>'
].join(''),

initialize: function () {
joint.shapes.flexberry.uml.BaseObjectView.prototype.initialize.apply(this, arguments);
this.updateRectangles();
},

updateRectangles: function () {
joint.shapes.flexberry.uml.BaseObjectView.prototype.updateRectangles.apply(this, arguments);
let paramsBox = this.$box.find('.header-input');
let bbox = this.model.getBBox();

paramsBox.css({
top: (bbox.height - paramsBox[0].offsetHeight)/2,
left: (bbox.width - paramsBox[0].offsetWidth)/2,
position: 'absolute'
});
},

getUsecaseName: function() {
return this.model.attributes.objectModel.get('name');
},
Expand Down
37 changes: 37 additions & 0 deletions addon/objects/uml-primitives/fd-uml-usecase-actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { computed } from '@ember/object';
import { isArray } from '@ember/array';
import $ from 'jquery';
import { A } from '@ember/array';

import FdUmlElement from './fd-uml-element';
import { BaseObject } from './fd-uml-baseobject';
Expand Down Expand Up @@ -108,10 +109,46 @@ joint.shapes.flexberry.uml.UsecaseActorView = joint.shapes.flexberry.uml.BaseObj
'</div>'
].join(''),

getSizeChangers() {
DubrovinPavel marked this conversation as resolved.
Show resolved Hide resolved
if (this.paper) {
let readonly = this.paper.options.interactive;
if (!readonly && typeof readonly !== 'object') {
return A();
}
}

return A([{
name: 'right-size-button prop',
text: '&#xf0da',
attrs: {
'element': { 'ref-dx': 0, 'ref-y': 0.5, 'ref': '.joint-highlight-stroke' },
'circle': { r: 6, fill: '#007aff', stroke: '#007aff', 'stroke-width': 1 },
'text': { fill: '#ffffff','font-size': 10, 'text-anchor': 'middle', x: 0.5, y: 3.5, 'font-family': 'Icons' },
}
}, {
name: 'right-down-size-button prop',
text: '&#xf0da',
attrs: {
'element': { 'ref-dx': 0, 'ref-dy': 0, 'ref': '.joint-highlight-stroke' },
'circle': { r: 6, fill: '#007aff', stroke: '#007aff', 'stroke-width': 1 },
'text': { fill: '#ffffff','font-size': 10, 'text-anchor': 'middle', x: 0.5, y: 3.5, 'transform': 'rotate(45)', 'font-family': 'Icons' },
}
}, {
name: 'down-size-button prop',
text: '&#xf0d7',
attrs: {
'element': { 'ref-x': 0.5, 'ref-dy': 0, 'ref': '.joint-highlight-stroke' },
'circle': { r: 6, fill: '#007aff', stroke: '#007aff', 'stroke-width': 1 },
'text': { fill: '#ffffff','font-size': 10, 'text-anchor': 'middle', x: 0, y: 3.5, 'font-family': 'Icons' },
}
}]);
},

updateRectangles: function (resizedWidth, resizedHeight) {
const minWidth = this.model.attributes.minWidth;
const minHeight = this.model.attributes.minHeight;
const oldSize = this.model.size();
this.getSizeChangers();
DubrovinPavel marked this conversation as resolved.
Show resolved Hide resolved

let newHeight = Math.max( resizedHeight || oldSize.height, minHeight)
let newWidth = Math.max( resizedWidth || oldSize.width, minWidth)
Expand Down