Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions drawio_desktop/src/palettes/wavedrom/paletteWavedrom.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import bitfield from '!!raw-loader!./bitfield.json.txt'
import timing from '!!raw-loader!./timing.json.txt'
import schematic from '!!raw-loader!./schematic.json.txt'


Sidebar.prototype.addWavedromPalette = function () {
var style = 'shadow=0;dashed=0;align=left;strokeWidth=1;labelBackgroundColor=#ffffff;noLabel=1;';

this.addPaletteFunctions('wavedrom', 'WaveDrom', true, [
this.createVertexTemplateEntry(style + 'shape=mxgraph.wavedrom.abstract.bitfield;', 300, 75, bitfield, 'Bitfield Diagram', null, null, this.getTagsForStencil('mxgraph.wavedrom.abstract', 'wavedrom', 'byte', 'bit', 'bitfield ').join(' ')),
this.createVertexTemplateEntry(style + 'shape=mxgraph.wavedrom.abstract.timing;', 800, 40, timing, 'Timing Diagram', null, null, this.getTagsForStencil('mxgraph.wavedrom.abstract', 'wavedrom', 'wave', 'timing ').join(' ')),

this.createVertexTemplateEntry(style + 'shape=mxgraph.wavedrom.abstract.bitfield;', 300, 75, bitfield, 'Bitfield Diagram', null, null, this.getTagsForStencil('mxgraph.wavedrom.abstract', 'wavedrom', 'byte', 'bit', 'bitfield ').join(' ')),
this.createVertexTemplateEntry(style + 'shape=mxgraph.wavedrom.abstract.timing;', 800, 40, timing, 'Timing Diagram', null, null, this.getTagsForStencil('mxgraph.wavedrom.abstract', 'wavedrom', 'wave', 'timing ').join(' ')),
this.createVertexTemplateEntry(style + 'shape=mxgraph.wavedrom.abstract.schematic;', 400, 150, schematic, 'Schematic Diagram', null, null, this.getTagsForStencil('mxgraph.wavedrom.abstract', 'wavedrom', 'wave', 'schematic ').join(' ')),
]);
}
}
8 changes: 8 additions & 0 deletions drawio_desktop/src/palettes/wavedrom/schematic.json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ "assign":[
["out",
["|",
["&", ["~", "a"], "b"],
["&", ["~", "b"], "a"]
]
]
]}
74 changes: 74 additions & 0 deletions drawio_desktop/src/shapes/shapeSchematic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import onml from 'onml'
import render from 'wavedrom/lib'
import def from 'wavedrom/skins/default.js'
import narrow from 'wavedrom/skins/narrow.js'
import lowkey from 'wavedrom/skins/lowkey.js'
import json5 from 'json5'

/**
* Extends mxShape.
*/
function mxShapeWavedromSchematic(bounds, fill, stroke, strokewidth) {
mxShape.call(this);
this.bounds = bounds;
this.image = '';
this.error = '';
this.fill = fill;
this.stroke = stroke;
this.strokewidth = (strokewidth != null) ? strokewidth : 1;
this.shadow = false;
};
/**
* Extends mxShape.
*/
mxUtils.extend(mxShapeWavedromSchematic, mxImageShape);

mxShapeWavedromSchematic.prototype.cst = {
SHAPE_WAVEDROM: 'mxgraph.wavedrom.abstract.schematic'
};

mxShapeWavedromSchematic.prototype.customProperties = [
];

mxShapeWavedromSchematic.prototype.updateImage = function () {
try {
var skins = Object.assign({}, def, narrow, lowkey);
var jsonml = render.renderAny(0,json5.parse(this.state.cell.value),skins);
let svg = onml.stringify(jsonml)
svg = svg.slice(0,4) + ' xmlns="http://www.w3.org/2000/svg"' + svg.slice(4);
this.image = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
this.error = '';
} catch (err) {
this.error = err.message;
}
}

/**
* Function: paintVertexShape
* Untitled Diagram.drawio
* Paints the vertex shape.
*/
mxShapeWavedromSchematic.prototype.paintVertexShape = function (c, x, y, w, h) {
if (!this.image) {
this.updateImage();
}
try {
if (!this.error) {
c.image(x, y, w, h, this.image, this.preserveImageAspect, false, false);
}
} catch (err) {
this.error = err.message;
}
if (this.error) {
c.text(x, y, w, h, this.error, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, true, 'html', 0, 0, 0);
c.stroke();
}
this.state.cell.valueChanged = (value) => { var lastValue = mxCell.prototype.valueChanged.call(this.state.cell, value); this.updateImage(); this.redraw(); return lastValue;}
}

mxCellRenderer.registerShape(mxShapeWavedromSchematic.prototype.cst.SHAPE_WAVEDROM, mxShapeWavedromSchematic);

mxShapeWavedromSchematic.prototype.getConstraints = function (style, w, h) {
var constr = [];
return constr;
}
1 change: 1 addition & 0 deletions drawio_desktop/src/wavedrom-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './shapes/shapeTiming'
import './shapes/shapeBitfield'
import './shapes/shapeSchematic'
import "./palettes/wavedrom/paletteWavedrom";
import waveschema from 'wavedrom-schema/waveschema.json'
import jsonschema from 'jsonschema'
Expand Down