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

implemented multiple properties view #79

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6080cc2
Updates jointjs and requirejs config
anastasia143 Feb 23, 2017
fe9a6a8
Updates jointjs in editor-core
anastasia143 Feb 23, 2017
eba2774
Changes pathes in requirejs
anastasia143 Feb 24, 2017
1d4ed39
Adds bacbone path to jointjs d ts
anastasia143 Feb 24, 2017
393ff0a
Adds attrs description to jointObjectAttributes in DefaultDiagramNode.ts
anastasia143 Feb 24, 2017
b165697
Updates grunt and typescript in package.json
anastasia143 Feb 24, 2017
d97537b
Changes diagramElementView to elementView in DiagramScene.ts
anastasia143 Feb 24, 2017
adea85c
Adds PortsModelInterface to jointjs.d.ts
anastasia143 Feb 24, 2017
3f6098a
Adds empty ImageWithPorts to DefaultDiagramNode.ts
anastasia143 Feb 24, 2017
fc72909
Removes TextAttrs from Text constructor
anastasia143 Feb 24, 2017
ed60e55
Updates requirejs with new libs in []
anastasia143 Feb 26, 2017
d89b147
Adds backbone
anastasia143 Feb 26, 2017
e2ec1f4
Adds lodash
anastasia143 Feb 26, 2017
80ce591
Fix requirejs config.
TanVD Mar 1, 2017
92e0c07
Adds ports tp the ImageWithPorts
anastasia143 Mar 5, 2017
547335d
Merge branch 'create-modules' of https://github.com/qreal/wmp into cr…
anastasia143 Mar 12, 2017
462ae1d
Merge branch 'create-modules' into jointjs-update-merge
anastasia143 Mar 12, 2017
9058ba7
Update joint.css
TanVD Mar 13, 2017
b8a629b
Change notation file format
saimonsaret Mar 19, 2017
2a9ec0a
Merge branch 'master' into containers
saimonsaret Mar 19, 2017
082aeb3
Add embedding saving and loading
saimonsaret Mar 20, 2017
b00aae5
Prepare for auto-embedding
saimonsaret Mar 20, 2017
c4c957c
Merge branch 'jointjs-update-merge' of https://github.com/anastasia14…
saimonsaret Mar 21, 2017
4c88447
Implement correct saving/loading/undo-redo/linking for containers
saimonsaret Mar 23, 2017
86ee3a1
Diagram saving and drawing bugfix
saimonsaret Mar 26, 2017
02928de
Fix resize and remove debug code
saimonsaret Mar 28, 2017
786929c
implemented multiple properties view
shavkunov Apr 1, 2017
2f19905
Merge remote-tracking branch 'origin/containers' into multiple-proper…
shavkunov May 5, 2017
73d9102
implemented text joint labels
shavkunov May 9, 2017
347eef1
few comments added
shavkunov May 9, 2017
162c400
replaced var into let
shavkunov May 9, 2017
2366a93
more cosmetic changes
shavkunov May 9, 2017
446702f
replaced magic numbers with magic variables
shavkunov May 9, 2017
2655512
added center text align
shavkunov May 14, 2017
bb2e3de
fixed requested changes
shavkunov May 14, 2017
614fa4a
fixed saving properties coordinates
shavkunov May 21, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export class SceneController {
}
node.completeResize();
cellView.unhighlight(cellView.model.id);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ImageWithPorts extends joint.shapes.basic.Generic {
constructor(portsModelInterface: joint.shapes.basic.PortsModelInterface) {
super(portsModelInterface);

this.set("markup", '<g class="rotatable"><g class="scalable"><rect class ="outer"/><image/></g><text/><g class="inPorts"/><g class="outPorts"/></g>')
this.set("markup", '<g class="rotatable"><g class="scalable"><rect class ="outer"/><image/></g><text/><g class="inPorts"/><g class="outPorts"/></g>');
this.set("portMarkup", '<g class="port<%= id %>"><circle/><text/></g>')
}

Expand All @@ -32,19 +32,18 @@ class ImageWithPorts extends joint.shapes.basic.Generic {

return attrs;
}
};

}
export class DefaultDiagramNode implements DiagramNode {

private logicalId: string;
private jointObject: ImageWithPorts;
private name: string;
private type: string;
private constPropertiesPack: PropertiesPack;
private changeableProperties: Map<String, Property>;
private imagePath: string;
private propertyEditElement: PropertyEditElement;
private propertyEditElements: Map<String, PropertyEditElement>;
private parentNode: DiagramContainer;
private graph : joint.dia.Graph;

private resizeParameters = {
isTopResizing: false,
Expand All @@ -63,6 +62,11 @@ export class DefaultDiagramNode implements DiagramNode {
height: 0,
};

private lastPointermoveCursor = {
x: 0,
y: 0,
};

constructor(name: string, type: string, x: number, y: number, width: number, height: number,
properties: Map<String, Property>, imagePath: string, id?: string,
notDefaultConstProperties?: PropertiesPack) {
Expand Down Expand Up @@ -94,25 +98,26 @@ export class DefaultDiagramNode implements DiagramNode {
jQuery.extend(jointObjectAttributes, {id: id});
}

console.log("default diagram node constructor");
this.propertyEditElements = new Map();
this.jointObject = new ImageWithPorts(jointObjectAttributes);
this.changeableProperties = properties;
this.imagePath = imagePath;
this.parentNode = null;
}

pointermove(cellView, evt, x, y): void {
console.log("Default diagram node pointer move with x : " + x + " and y : " + y);
cellView.options.interactive = true;
var bbox = cellView.getBBox();
var newX = bbox.x + (<number> (bbox.width - 50)/2);
var newY = bbox.y + bbox.height - 50;
this.propertyEditElement.setPosition(newX, newY);
var diffX = x - this.lastMousePosition.x;
var diffY = y - this.lastMousePosition.y;
this.lastPointermoveCursor.x = this.getX();
this.lastPointermoveCursor.y = this.getY();
console.log("Diagram pos in pointermove : " + this.getX() + ", " + this.getY());

if (this.resizeParameters.isBottomResizing || this.resizeParameters.isRightResizing)
{
if (this.resizeParameters.isBottomResizing || this.resizeParameters.isRightResizing) {
cellView.options.interactive = false;
var model = <joint.dia.Element> cellView.model;
var diffX = x - this.lastMousePosition.x;
var diffY = y - this.lastMousePosition.y;
this.lastMousePosition.x = x;
this.lastMousePosition.y = y;

Expand All @@ -130,17 +135,44 @@ export class DefaultDiagramNode implements DiagramNode {
}
}

initPropertyEditElements(zoom: number): void {
initPropertyEditElements(zoom: number, graph: joint.dia.Graph): void {
this.graph = graph;
var parentPosition = this.getJointObjectPagePosition(zoom);
this.propertyEditElement = new PropertyEditElement(this.logicalId, this.jointObject.id,
this.changeableProperties);
var propertyEditElementX = parentPosition.x + (<number> (this.boundingBox.width - 50)/2);
var propertyEditElementY = parentPosition.y + this.boundingBox.height - 50;
this.propertyEditElement.setPosition(propertyEditElementX, propertyEditElementY);
var propertyEditElementX = parentPosition.x + (<number> (this.boundingBox.width - 50));
var propertyEditElementY = parentPosition.y + this.boundingBox.height;
var delta = PropertyEditElement.fontSize;

console.log("Init edit elements");

for (var propertyKey in this.changeableProperties) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As IDEA reminds: it's better to use let instead of var cause it behaves more strictly.

var property = this.changeableProperties[propertyKey];
if (property.type === "string") {
console.log("Init of property with name " + property.name + " and value " + property.value);
let x = propertyEditElementX;
let y = propertyEditElementY;

let propertyEditElement = new PropertyEditElement(x, y, property, graph);
propertyEditElementY += delta;


this.propertyEditElements[propertyKey] = propertyEditElement;
}
}
console.log("End of init edit elements");
}

getTextProperties() : joint.shapes.basic.Text[] {
var textObjects = [];

for (var propertyKey in this.propertyEditElements) {
textObjects.push(this.propertyEditElements[propertyKey].getTextObject());
}

return textObjects;
}

getPropertyEditElement(): PropertyEditElement {
return this.propertyEditElement;
getPropertyEditElements(): Map<String, PropertyEditElement> {
return this.propertyEditElements;
}

getLogicalId(): string {
Expand Down Expand Up @@ -171,23 +203,27 @@ export class DefaultDiagramNode implements DiagramNode {
return String(this.boundingBox.width) + ", " + String(this.boundingBox.height);
}

changeTextPosition() : void {
var dx = this.getX() - this.lastPointermoveCursor.x;
var dy = this.getY() - this.lastPointermoveCursor.y;
console.log("Diagram pos in changeTextPosition : " + this.getX() + ", " + this.getY());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use log levels, so it's better to remove unnecessary logs before merge to master.

//console.log("Last cursor was at " + this.lastPointermoveCursor.x + ", " + this.lastPointermoveCursor.y);
console.log("Change position of text. diffX : " + dx + " diffY : " + dy);

if (dx !== 0 || dy !== 0) {
for (var propertyKey in this.propertyEditElements) {
this.propertyEditElements[propertyKey].setRelativePosition(dx, dy);
}
}
}

setPosition(x: number, y: number, zoom: number, cellView : joint.dia.CellView): void {
this.jointObject.position(x, y);
// var position = this.getJointObjectPagePosition(zoom);
// this.propertyEditElement.setPosition(position.x, position.y);
var bbox = cellView.getBBox();
var newX = bbox.x + (<number> (bbox.width - 50)/2);
var newY = bbox.y + bbox.height - 50;
this.propertyEditElement.setPosition(newX, newY);
}

setSize(width: number, height: number, cellView : joint.dia.CellView): void {
var model = <joint.dia.Element> cellView.model;
model.resize(width - 2, height);
var bbox = cellView.getBBox();
var newX = bbox.x + (<number> (bbox.width - 50)/2);
var newY = bbox.y + bbox.height - 50;
this.propertyEditElement.setPosition(newX, newY);
}

setParentNode(parent: DiagramContainer): void {
Expand All @@ -212,8 +248,10 @@ export class DefaultDiagramNode implements DiagramNode {
return this.constPropertiesPack;
}

setProperty(key: string, property: Property): void {
setProperty(key: string, property: Property ): void {
this.changeableProperties[key] = property;
console.log("Set new text property : " + property.name + " : " + property.value);
this.propertyEditElements[key].setProperty(property, this.graph);
var propertyChangedEvent = new CustomEvent('property-changed', {
detail: {
nodeId: this.getLogicalId(),
Expand Down Expand Up @@ -305,5 +343,4 @@ export class DefaultDiagramNode implements DiagramNode {
return (x <= bbox.x + bbox.width + paddingPercent && x >= bbox.x - paddingPercent &&
y <= bbox.y + bbox.height + paddingPercent && y >= bbox.y + bbox.height - paddingPercent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export interface DiagramNode extends DiagramElement {
setPosition(x: number, y: number, zoom: number, cellView : joint.dia.CellView): void;
setSize(width: number, height: number, cellView : joint.dia.CellView): void;
setParentNode(parent: DiagramContainer): void;
getPropertyEditElement(): PropertyEditElement;
initPropertyEditElements(zoom: number): void;
getPropertyEditElements(): Map<String, PropertyEditElement>;
getTextProperties(): joint.shapes.basic.Text[];
initPropertyEditElements(zoom: number, graph: joint.dia.Graph): void;
changeTextPosition() : void;
initResize(bbox, x: number, y: number, paddingPercent) : void;
completeResize() : void;
isResizing() : boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DiagramNode} from "./DiagramNode";
import {SubprogramNode} from "./SubprogramNode";
import {DiagramElementListener} from "../controller/DiagramElementListener";
import {DiagramContainer} from "./DiagramContainer";
import {PropertyEditElement} from "./PropertyEditElement";
export class DiagramScene extends joint.dia.Paper {

private htmlId: string;
Expand Down Expand Up @@ -128,9 +129,9 @@ export class DiagramScene extends joint.dia.Paper {

node.getJointObject().remove();
if (node.getPropertyEditElements()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean? Is it check for null or what? Use explicit syntax.

var editElements = node.getPropertyEditElements();
for (let i in editElements) {
editElements[i].getHtmlElement().remove();
var textElements: Map<String, PropertyEditElement> = node.getPropertyEditElements();
for (var propertyKey in textElements) {
textElements[propertyKey].getTextObject().remove();
}
}
delete this.nodesMap[nodeId];
Expand Down Expand Up @@ -165,15 +166,14 @@ export class DiagramScene extends joint.dia.Paper {
}

public addNode(node: DiagramNode): void {
console.log("Diagram Scene : add node " + node);
this.nodesMap[node.getJointObject().id] = node;
this.graph.addCell(node.getJointObject());
node.initPropertyEditElements(this.zoom);
if (node.getPropertyEditElements()) {
var editElements = node.getPropertyEditElements();
for (let i in editElements) {
editElements[i].getHtmlElement().insertBefore("#" + this.getId());
}
}

node.initPropertyEditElements(this.zoom, this.graph);
node.getJointObject().on('change:position', function() {
node.changeTextPosition();
});
}

public setCurrentLinkType(linkType: string): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,74 @@
import {StringUtils} from "../../../utils/StringUtils";
import {Property} from "./Property";

export class PropertyEditElement {
public static fontSize = 20;

private static propertyTemplate = "" +
"<span>{3}:</span> " +
"<input class='{0} property-edit-input' data-id='{1}' data-type='{2}' " +
"style='border: dashed 1px; padding-left: 2px; margin-bottom: 1px' value='{4}'>" +
"<br>";
private textObject: joint.shapes.basic.Text;
private lastX: number;
private lastY: number;

private static template: string = "" +
"<div class='property-edit-element' style='position: absolute; text-align: left; z-index: 1;'>" +
" {0}" +
"</div>";
/**
* Creates property at specified coordinates with specified name and value.
* @param x x axis coordinate
* @param y y axis coordinate
* @param property property to set
* @param graph graph for setting text on the plane.
*/
constructor(x : number, y : number, property : Property, graph : joint.dia.Graph) {
console.log("Property edit element constructor");

private htmlElement;
this.lastX = x;
this.lastY = y;
this.setProperty(property, graph);

constructor(logicalId: string, jointObjectId: string, propertyKey : string, property : Property) {
var propertiesHtml: string = "";
this.textObject.on("cell:pointermove", (cellView, event, x, y): void => {
this.setPosition(x, y);
});
}

propertiesHtml += StringUtils.format(PropertyEditElement.propertyTemplate,
propertyKey + "-" + logicalId, jointObjectId, propertyKey, property.name, property.value);
public getTextObject() : joint.shapes.basic.Text {
return this.textObject;
}

this.htmlElement = $(StringUtils.format(PropertyEditElement.template, propertiesHtml));
this.initInputSize();
this.initInputAutosize();
getX(): number {
return (this.textObject.get("position"))['x'];
}

public getHtmlElement() {
return this.htmlElement;
getY(): number {
return (this.textObject.get("position"))['y'];
}

public setPosition(x: number, y: number): void {
this.htmlElement.css({ left: x - 25, top: y + 55 });
console.log("Setting text position with x : " + x + " and y : " + y);
this.textObject.position(x, y);
}

private initInputSize(): void {
this.htmlElement.find('input').each(function(index) {
$(this).css("width", StringUtils.getInputStringSize(this));
}
);
public setProperty(property : Property, graph : joint.dia.Graph): void {
var width: number = 0.5 * (property.name.length + property.value.length) * PropertyEditElement.fontSize;
var height: number = PropertyEditElement.fontSize;

}
if (this.textObject) {
this.lastX = this.getX();
this.lastY = this.getY();
this.textObject.remove();
}

private initInputAutosize(): void {
this.htmlElement.find('input').on('input', function(event) {
$(this).trigger('autosize');
this.textObject = new joint.shapes.basic.Text({
position: { x: this.lastX, y: this.lastY },
size: { width: width, height: height },
attrs: {
text: {
text: property.name + " : " + property.value,
},
},
});

this.htmlElement.find('input').on('autosize', function(event) {
$(this).css("width", StringUtils.getInputStringSize(this));
});
graph.addCell(this.textObject);
}

public setRelativePosition(deltaX : number, deltaY : number): void {
this.lastX = this.getX() + deltaX;
this.lastY = this.getY() + deltaY;
this.setPosition(this.lastX, this.lastY);
}
}