Skip to content

Commit

Permalink
Fixed label placement controls
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Jul 31, 2022
1 parent f078712 commit 92d391c
Show file tree
Hide file tree
Showing 57 changed files with 209 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String getTitle() {

@Override
public String getIcon() {
return "/github/kite9-org/kite9/templates/admin/icons/github.png?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/github.png?v=v0.15";
}

@Override
Expand Down Expand Up @@ -89,7 +89,7 @@ public String getTitle() {

@Override
public String getIcon() {
return "/github/kite9-org/kite9/templates/admin/icons/github.png?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/github.png?v=v0.15";
}

@Override
Expand Down Expand Up @@ -281,9 +281,9 @@ private String getIconUrl(Link l, GHContent c) {
if (fs.getFormatFor(c.getName()) instanceof DiagramFileFormat) {
return l.getHref();
} else if (hasIcon(c.getName())) {
return "/github/kite9-org/kite9/templates/admin/icons/"+getExtension(c.getName())+".svg?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/"+getExtension(c.getName())+".svg?v=v0.15";
} else {
return "/github/kite9-org/kite9/templates/admin/icons/unknown.svg?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/unknown.svg?v=v0.15";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ private String getExtension(String name) {
@Override
public String getIcon() {
if (hasIcon(d.getFilename())) {
return "/github/kite9-org/kite9/templates/admin/icons/"+getExtension(d.getFilename())+".svg?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/"+getExtension(d.getFilename())+".svg?v=v0.15";
} else {
return "/github/kite9-org/kite9/templates/admin/icons/unknown.svg?v=v0.14";
return "/github/kite9-org/kite9/templates/admin/icons/unknown.svg?v=v0.15";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected Document generateRestXML(RepresentationModel<?> t) throws XMLStreamExc
}

private void handleTemplateNaming(Document out) {
out.getDocumentElement().setAttributeNS(Kite9Namespaces.XSL_TEMPLATE_NAMESPACE, "xslt:template", "/github/kite9-org/kite9/templates/admin/admin-template.xsl?v=v0.14");
out.getDocumentElement().setAttributeNS(Kite9Namespaces.XSL_TEMPLATE_NAMESPACE, "xslt:template", "/github/kite9-org/kite9/templates/admin/admin-template.xsl?v=v0.15");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta property="og:title" content="Kite9 Diagrams" />
<meta property="og:description"
content="Kite9 draws diagrams, automatically. UML, Risk-First, Templated, SVG, Flow-Charts, System Diagrams." />
<meta property="og:image" content="https://www.kite9.org/github/kite9-org/kite9/templates/admin/kite9-preview.png?v=v0.14" />
<meta property="og:image" content="https://www.kite9.org/github/kite9-org/kite9/templates/admin/kite9-preview.png?v=v0.15" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="718" />
<meta property="og:image:height" content="372" />
Expand All @@ -18,7 +18,7 @@
<meta property="twitter:title" content="Kite9" />
<meta property="twitter:description"
content="Kite9 draws diagrams, automatically. UML, Risk-First, Templated, SVG, Flow-Charts, System Diagrams." />
<meta property="twitter:image:src" content="https://www.kite9.org/github/kite9-org/kite9/templates/admin/kite9-preview.png?v=v0.14" />
<meta property="twitter:image:src" content="https://www.kite9.org/github/kite9-org/kite9/templates/admin/kite9-preview.png?v=v0.15" />
<meta property="twitter:image:width" content="718" />
<meta property="twitter:image:height" content="372" />
<meta charset="UTF-8" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export function createInsertLabelStep(e, templateUri, command) {
const info = parseInfo(e);
const end = info.end;
const linkId = info.terminates ? info.terminates : e.getAttribute("id");
const customLabel = e.getAttribute("k9-label");
const newId = createUniqueId();
const labelUri = customLabel ? customLabel : templateUri;

command.push({
"type": 'InsertUrl',
"fragmentId": linkId,
"uriStr": templateUri,
"uriStr": labelUri,
"newId" : newId,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,101 @@
import { getMainSvg } from '/public/bundles/screen.js'
import { parseStyle } from '/public/bundles/css.js'
import { hasLastSelected, parseInfo, getContainingDiagram, reverseDirection, createUniqueId } from '/public/bundles/api.js'

const PLACEMENTS = [ "top-left", "top", "top-right", "left", "none", "right", "bottom-left", "bottom", "bottom-right" ];
const STYLE_NAME = '--kite9-label-placement'

export function labelableSelector() {
const labelables = Array.from(getMainSvg().querySelectorAll("[k9-ui~=label].selected"));
return labelables;
function getPlacement(command, e) {
const adlElement = command.getADLDom(e.getAttribute("id"));
var style = parseStyle(adlElement.getAttribute("style"));
var l = style[STYLE_NAME];
return l;
}

export function createPlaceLabelStep(e, templateUri, command) {
const info = parseInfo(e);
const end = info.end;
const linkId = info.terminates ? info.terminates : e.getAttribute("id");
const newId = createUniqueId();
function drawPlacement(event, cm, placement, selected) {
if (placement == null) {
placement = "none";
}

command.push({
"type": 'InsertUrl',
"fragmentId": linkId,
"uriStr": templateUri,
"newId" : newId,
});
var out = cm.addControl(event, "/public/behaviours/labels/place/" + placement.toLowerCase().replace("_","-") + ".svg",
"placement (" + placement + ")",
undefined);

if (end) {
command.push({
"type": "ReplaceAttr",
"fragmentId": newId,
"name": "end",
"to" : end,
"from" : e.getAttribute("end")
});
var img = out.children[0];

if (selected == placement) {
img.setAttribute("class", "selected");
}

return img;
}


export function initPlaceLabelContextMenuCallback(command, templateUri, selector, action) {
export function initPlaceLabelContextMenuCallback(placementProperty, command, selector) {

if (selector == undefined) {
selector = labelableSelector;
}

if (action == undefined) {
action = createInsertLabelStep;
selector = function () {
return getMainSvg().querySelectorAll("[id][k9-ui~=place].selected");
}
}

/**
* Provides a label option for the context menu
* Provides a placement option for the context menu
*/
return function(event, contextMenu) {

const selectedElements = hasLastSelected(selector());

if (selectedElements.length > 0) {
contextMenu.addControl(event, "/public/behaviours/labels/place/place.svg", "Add Label",
function(e2, selector) {
contextMenu.destroy();
selectedElements.forEach(e => action(e, templateUri, command));
command.perform();
}
)
return function (event, contextMenu) {

const e = hasLastSelected(selector());

if (e.length> 0) {
const ls = hasLastSelected(e, true);
const placement = getPlacement(command, ls);
var img = drawPlacement(event, contextMenu, placement);

img.addEventListener("click", formEvent => {
contextMenu.clear();
placementProperty.populateForm(formEvent, contextMenu, e);
});
}
};
}

export function initLabelPlacementPropertyFormCallback(command) {

return function(propertyOwner, contextEvent, contextMenu, selectedElements) {
const ls = hasLastSelected(selectedElements, true);
const placement = getPlacement(command, ls);

PLACEMENTS.forEach(s => {
var img2 = drawPlacement(event, contextMenu, s, placement);
if (placement != s) {
img2.setAttribute("title", s);
img2.addEventListener("click", (formEvent) => propertyOwner.setProperty(contextEvent, formEvent, contextMenu, selectedElements));
}
});
}
}

export function initLabelPlacementPropertySetCallback(command) {

return function(propertyOwner, contextEvent, formEvent, contextMenu, selectedElements) {

const placement = formEvent.currentTarget.getAttribute("title");
selectedElements.forEach(e => {

const existing = getPlacement(command, e);
const id = e.getAttribute("id");

if (PLACEMENTS.includes(placement)) {
command.push({
fragmentId: id,
type: 'ReplaceStyle',
name: STYLE_NAME,
to: placement,
from: getPlacement(command, e)
});
}
});

}
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function createAdlToSVGResolver(transition, command, metadata) {

const XSL_TEMPLATE_NAMESPACE = "http://www.kite9.org/schema/xslt";
const ADL_NAMESPACE = "http://www.kite9.org/schema/adl";
const DEFAULT_TEMPLATE = "/github/kite9-org/kite9/templates/basic/basic-template.xsl?v=v0.14";
const DEFAULT_TEMPLATE = "/github/kite9-org/kite9/templates/basic/basic-template.xsl?v=v0.15";
const META_NAMESPACE = "http://www.kite9.org/schema/metadata";


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/** From: https://github.com/joshwnj/style-attr */

export function parseStyle(raw, opts) {
opts = opts || {}
raw = raw || ""

var preserveNumbers = opts.preserveNumbers;
var trim = function (s) { return s.trim(); };
var obj = {};

getKeyValueChunks(raw)
.map(trim)
.filter(Boolean)
.forEach(function (item) {
// split with `.indexOf` rather than `.split` because the value may also contain colons.
var pos = item.indexOf(':');
var key = item.substr(0, pos).trim();
var val = item.substr(pos + 1).trim();
if (preserveNumbers && isNumeric(val)) {
val = Number(val);
}

obj[key] = val;
});

return obj;
}

function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}

function getKeyValueChunks(raw) {
var chunks = [];
var offset = 0;
var sep = ';';
var hasUnclosedUrl = /url\([^\)]+$/;
var chunk = '';
var nextSplit;
while (offset < raw.length) {
nextSplit = raw.indexOf(sep, offset);
if (nextSplit === -1) { nextSplit = raw.length; }

chunk += raw.substring(offset, nextSplit);

// data URIs can contain semicolons, so make sure we get the whole thing
if (hasUnclosedUrl.test(chunk)) {
chunk += ';';
offset = nextSplit + 1;
continue;
}

chunks.push(chunk);
chunk = '';
offset = nextSplit + 1;
}

return chunks;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<diagram xslt:template="/github/kite9-org/kite9/templates/basic/basic-template.xsl?v=v0.14"
<diagram xslt:template="/github/kite9-org/kite9/templates/basic/basic-template.xsl?v=v0.15"
xmlns="http://www.kite9.org/schema/adl"
xmlns:xslt="http://www.kite9.org/schema/xslt" id="dia">

Expand All @@ -7,6 +7,7 @@
<container id="bigbox" layout="horizontal" style="fill: green; fill-opacity: 0.8; ">
<box id="b2" ><textarea id="t2">,</textarea></box>
<box id="b3" ><textarea id="t3">b3 line</textarea></box>
<label id="l1">Box title</label>
</container>

<link id="link1" r="r">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<svg:defs>
<svg:style type="text/css">
@import url('/github/kite9-org/kite9/templates/formats/formats-textures.css?v=v0.14');
@import url('/github/kite9-org/kite9/templates/formats/formats-textures.css?v=v0.15');
</svg:style>
</svg:defs>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ import { command, metadata, transition, instrumentation, dragger, contextMenu, p

const
containment = new Containment(),
layout = new Property("layout");
layout = new Property("layout"),
placement = new Property("placement");

export { command, metadata, transition, instrumentation, dragger, contextMenu, containment, palette, layout };
export { command, metadata, transition, instrumentation, dragger, contextMenu, containment, palette, layout, placement };

function initEditor() {

Expand All @@ -54,7 +55,9 @@ function initEditor() {

if (metadata.isEditor()) {
command.add(initUndoableCommandCallback(command));

layout.setCallback(() => command.perform());
placement.setCallback(() => command.perform());

dragger.dropWith(initCompleteDragable(command));
dragger.dragLocator(initDragableDragLocator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
<xsl:param name="text"><text><xsl:value-of select="text()" /></text></xsl:param>
<xsl:call-template name="formats-text-shape-inline">
<xsl:with-param name="k9-texture">none</xsl:with-param>
<xsl:with-param name="k9-highlight"></xsl:with-param>
<xsl:with-param name="k9-elem">label</xsl:with-param>
<xsl:with-param name="k9-contains" />
<xsl:with-param name="k9-palette">label</xsl:with-param>
<xsl:with-param name="k9-ui">delete edit xml</xsl:with-param>
<xsl:with-param name="k9-ui">delete edit xml place</xsl:with-param>
</xsl:call-template>

</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { once } from '/public/bundles/ensure.js'

import { command, placement, contextMenu, metadata } from '/public/templates/editor/editor.js'
import { initAddLabelContextMenuCallback } from '/public/behaviours/labels/add/labels-add.js'
import { initPlaceLabelContextMenuCallback } from '/public/behaviours/labels/place/labels-place.js'
import { command, metadata, contextMenu } from '/public/templates/adl/adl.js'
import { initPlaceLabelContextMenuCallback, initLabelPlacementPropertyFormCallback, initLabelPlacementPropertySetCallback } from '/public/behaviours/labels/place/labels-place.js'

function initLabels() {

if (metadata.isEditor()) {

placement.formCallback(initLabelPlacementPropertyFormCallback(command));
placement.setCallback(initLabelPlacementPropertySetCallback(command));

contextMenu.add(initAddLabelContextMenuCallback(command, document.params['label-template-uri']));
contextMenu.add(initPlaceLabelContextMenuCallback(placement, command));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@ContextConfiguration
public class PrivateGithubIT extends AbstractRestIT {

public static final String JS = "/github/kite9-org/examples/some.js?v=v0.14";
public static final String JS = "/github/kite9-org/examples/some.js?v=v0.15";
public static final String DIR = "/github/kite9-org/examples";


Expand Down
Loading

0 comments on commit 92d391c

Please sign in to comment.