Skip to content

Commit

Permalink
v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jauhl committed Jul 4, 2019
1 parent b3cc876 commit 05fa1a5
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 21 deletions.
152 changes: 151 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ const origin = g2().beg({ lc: 'round', lj: 'round', ls:()=>app.show.darkmode?'si
.txt({str:'y', x: 6, y: 30})
.end();

// deprecated
// /**
// * Returns a gravity vector as a g2-object.
// * @method
// * @returns {object}
// */
// const gravvec = (cartesian = true) => {
// const ytxt = cartesian ? -20 : -15;
// return g2().beg({ w: -pi/2, lw: 2, ls:()=>app.show.darkmode?'silver':'slategray', fs: 'darkgray'})
// .p()
// .m({ x: 0, y: 0 })
// .l({ x: 50, y: 0 })
// .stroke()
// .p()
// .m({ x: 50, y: 0 })
// .l({ x: 50 - 17.5, y: -3.5 })
// .a({ dw: pi/3, x: 50 - 17.5, y: 3.5 })
// .z()
// .drw()
// .end()
// .beg({ ls:()=>app.show.darkmode?'silver':'slategray', font: '14px roboto'})
// .txt({str:'g', x: -15, y: ytxt})
// .end();
// };

/**
* Container for `create()` & `prototype()`.
* @typedef {object}
Expand Down Expand Up @@ -205,7 +230,7 @@ const App = {
* @const
* @type {string}
*/
this.VERSION = '0.6.9';
this.VERSION = '0.7.0';

/**
* mixin requirement.
Expand All @@ -222,6 +247,16 @@ const App = {
this.ctxmenuheader = document.getElementById("contextMenuHeader");
this.ctxmenubody = document.getElementById("contextMenuBody");

this.mecDefaults = {
// nodeScaling: false,
// darkmode: false,
// nodeLabels: false,
// constraintLabels: true,
// loadLabels: true,
nodes: true,
constraints: true
};

// states
this.build = false; // build state
this.tempElm = false; // contextmenu/view state
Expand Down Expand Up @@ -471,6 +506,7 @@ const App = {
// expand or retract sidebar for charts
document.querySelector('#sb-r').style['padding-left'] = !!this.model.state.hasChart ? '0px' : '270px';
runSymbol.setAttribute('d',svgplay); // for reinits
Object.assign(this.show, { ...this.mecDefaults }); // reset to defaults (show nodes etc.)

this.state = 'initialized';
},
Expand Down Expand Up @@ -527,6 +563,46 @@ const App = {
* @method
* @param {object} elm - Element whose dependants should be reinitialized.
*/
// updDependants(elm) {
// let dependants = {ori:[],len:[]}; // declaring and filling array would be way more efficient in app scope since dependents don't change during drag
// // for (const el of this.model.constraints) {
// // if (el.dependsOn(elm) && ( (el.ori.type === 'const' && el.ori.ref)
// // || el.ori.type === 'drive'
// // || (el.len.type === 'const' && el.len.ref)
// // || el.len.type === 'drive')) {
// // // if (el.dependsOn(elm) && (el.ori.type === 'drive' || el.len.type === 'drive')) {
// // dependants.push(el);
// // }
// // };
// for (const el of this.model.constraints) {
// if (el.dependsOn(elm)) {
// if ( (el.ori.type === 'const' && el.ori.ref) || el.ori.type === 'drive' ) {
// dependants.ori.push(el);
// }
// if ( (el.len.type === 'const' && el.len.ref) || el.len.type === 'drive' ) {
// dependants.len.push(el);
// }
// }
// // if (el.dependsOn(elm) && (el.ori.type === 'drive' || el.len.type === 'drive')) {
// };
// console.log(dependants);
// // debugger
// // dependants.forEach(el => el.init(this.model)); // since only needed for drives, maybe implement user setting to choose between performance & simplicity
// // dependants.ori.forEach(el => {
// // if (el.ori.type === 'drive')
// // el.w0 = el.w
// // // el.init_ori_drive(el.ori)
// // if (el.len.type === 'drive')
// // el.init_len_drive(el.len)
// // // el.init(this.model);
// // });
// dependants.ori.forEach(el => el.w0 = el.w);
// dependants.len.forEach(el => el.r0 = el.r);

// if (this.model.state.hasChartPreview || this.model.state.hasTracePreview)
// this.model.preview();
// },

updDependants(elm) {
let dependants = []; // declaring and filling array would be way more efficient in app scope since dependents don't change during drag
for (const el of this.model.constraints) {
Expand Down Expand Up @@ -690,6 +766,19 @@ const App = {
this.notify('render')
},

// /**
// * Create a canvas for a chart, set options & append to container.
// * @method
// * @param {object} chart - chart-view for canvas.
// */
// createCanvas(chart) {
// let canvas = document.createElement('canvas');
// canvas.id = chart.canvas;
// canvas.width = 350;
// canvas.height = 200;
// chartcontainer.appendChild(canvas);
// },

/**
* Builds a g2-command-queue for charts in secondary canvas-elements.
* @method
Expand Down Expand Up @@ -730,6 +819,12 @@ const App = {
this.notify('render');
},

// replaceNode(oldN, newN) { // deprecated
// if (!(oldN.x === newN.x)) this.model.nodeById(oldN.id).x = newN.x;
// if (!(oldN.y === newN.y)) this.model.nodeById(oldN.id).y = newN.y;
// if (!(oldN.m === newN.m)) this.model.nodeById(oldN.id).m = newN.m;
// },

/**
* Adds a new node to the model.
* @method
Expand Down Expand Up @@ -1343,6 +1438,35 @@ const App = {
fr.readAsText(file); // fires load event
},

// /**
// * Opens a dialogue to download thr current model as a JSON file.
// * @method
// */
// saveToJSON() {
// let a = document.createElement('a'),
// file = new Blob([this.model.asJSON()], { type: 'application/json' });
// a.href = URL.createObjectURL(file);
// a.download = (!!this.model.id && this.model.id.length > 0) ? `${this.model.id}.json` : 'linkage.json';
// document.body.appendChild(a); // Firefox needs the element to be added to the DOM for this to work, Chrome & Edge ¯\_(ツ)_/¯
// a.click();
// document.body.removeChild(a);
// },

// /**
// * Opens a dialogue to download the current model as a JSON file.
// * @method
// */
// saveToHTML() {
// let modelHasId = (!!this.model.id && this.model.id.length) ? true : false;
// let a = document.createElement('a');
// let file = new Blob([tmpl.mec2Element(modelHasId)], { type: 'application/html' });
// a.href = URL.createObjectURL(file);
// a.download = modelHasId ? `${this.model.id}.html` : 'linkage.html';
// document.body.appendChild(a);
// a.click();
// document.body.removeChild(a);
// },

/**
* Opens a dialogue to download the current model as a specified file (json or html).
* @method
Expand Down Expand Up @@ -1545,6 +1669,32 @@ load()

// arrays for view-modal, do this whenever...
(async () => {
// Slower version of new Set method
// copy-merge alyValue arrays for faster checking in view-modal (keep in mind that some (eg. acc, vel, forceAbs) are in multiple!)
// app.alyValues.forNodes = await app.alyValues.nodes.info.concat(app.alyValues.nodes.vector, app.alyValues.nodes.tracePoint);
// app.alyValues.forConstraints = await app.alyValues.constraints.info.concat(app.alyValues.constraints.vector, app.alyValues.constraints.tracePoint);

//build filtered array (no duplicates) with all possible aly values for all components
// copy node values to new array
// app.alyValues.all = await app.alyValues.forNodes.concat();
// app.alyValues.all = [];

// await app.alyValues.forNodes.forEach(element => {
// if ( !app.alyValues.all.includes(element) )
// app.alyValues.all.push(element);
// });
// // add constraint values
// await app.alyValues.forConstraints.forEach(element => {
// if ( !app.alyValues.all.includes(element) )
// app.alyValues.all.push(element);
// });
// // add model value(s) (currently a single element...)
// await app.alyValues.model.tracePoint.forEach(element => {
// if ( !app.alyValues.all.includes(element) )
// app.alyValues.all.push(element);
// });


// copy-merge alyValue arrays for faster checking in view-modal (keep in mind that some (eg. acc, vel, forceAbs) are in multiple!)
app.alyValues.forNodes = await [... new Set([
... app.alyValues.nodes.info,
Expand Down
2 changes: 1 addition & 1 deletion app.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@
User Guide
</a>
<div class="dropdown-menu m-0">
<a class="dropdown-item" role="button" href="https://github.com/jauhl/mecEdit/blob/master/docs/userguide_en.md"
target="_blank" rel="noopener" aria-label="mecEdit User Guide en" style="display:flex !important">
English
<a class="dropdown-item" role="button" href="https://github.com/jauhl/mecEdit/blob/master/docs/userguide_de.md"
target="_blank" rel="noopener" aria-label="mecEdit User Guide de" style="display:flex !important">
Deutsch
<svg xmlns="http://www.w3.org/2000/svg" width="15px" height="15px" viewBox="0 0 511.626 511.627" style="position:relative;top:5px;margin-left:auto;">
<g>
<path fill="currentColor" d="M392.857,292.354h-18.274c-2.669,0-4.859,0.855-6.563,2.573c-1.718,1.708-2.573,3.897-2.573,6.563v91.361
Expand All @@ -316,9 +316,9 @@
</svg>
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" role="button" href="https://github.com/jauhl/mecEdit/blob/master/docs/userguide_de.md"
target="_blank" rel="noopener" aria-label="mecEdit User Guide de" style="display:flex !important">
German
<a class="dropdown-item" role="button" href="https://github.com/jauhl/mecEdit/blob/master/docs/userguide_en.md"
target="_blank" rel="noopener" aria-label="mecEdit User Guide en" style="display:flex !important">
English
<svg xmlns="http://www.w3.org/2000/svg" width="15px" height="15px" viewBox="0 0 511.626 511.627" style="position:relative;top:5px;margin-left:auto;">
<g>
<path fill="currentColor" d="M392.857,292.354h-18.274c-2.669,0-4.859,0.855-6.563,2.573c-1.718,1.708-2.573,3.897-2.573,6.563v91.361
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mecedit",
"version": "0.6.9",
"version": "0.7.0",
"description": "A lightweight editor for modeling and simulation of planar linkages.",
"keywords": [
"vector",
Expand All @@ -20,7 +20,7 @@
"build": "npm run minify && npm run minify-css && npm run minify-sw",
"fullbuild": "npm run minify && npm run minify-css && npm run minify-sw && npm run jsdoc && npm run gzip",
"minify": "uglifyjs ./scripts/mixin.js ./scripts/slider.js ./scripts/templates.js ./scripts/appevents.js ./scripts/examples.js ./app.js -o ./app.min.js --comments -c",
"minify-sw": "uglifyjs ./scripts/serviceworker-static.js -o ./sw.js --comments -c --define env.VERSION='%date%-%time%'",
"minify-sw": "uglifyjs ./scripts/serviceworker.js -o ./sw.js --comments -c --define env.VERSION='%date%-%time%'",
"minify-css": "postcss app.css > app.min.css",
"jsdoc": "jsdoc2md ./app.js > ./docs/app.md",
"gzip": "ngzip ./app.min.js > ./app.min.js.gz"
Expand Down
12 changes: 10 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ planar linkages.
<br><br>
# User guide

[English](./docs/userguide_en.md)
[Deutsch](./docs/userguide_de.md)

[German](./docs/userguide_de.md)
[English](./docs/userguide_en.md)

---
<br><br>

# Changelog

## v0.7.0

### general:
+ Node and constraint visibility is now reset for each new model.
+ Fixed a bug where the drag&drop overlay would persist.

---

## v0.6.9

### general:
Expand Down
20 changes: 12 additions & 8 deletions scripts/appevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,18 @@ const events = {
e.stopPropagation();
e.preventDefault();
const files = e.dataTransfer.files;

if (files[0].type.match('application/json')) {
console.log('Model was dropped ...');
app.loadFromJSON(files)
} else {
console.error('Only files of type JSON can be processed!');
try {
if (!!files && files.length && files[0].type.match('application/json')) {
console.log('Model was dropped ...');
app.loadFromJSON(files)
} else {
console.error('Only files of type JSON can be processed!');
}
} catch (e) {
console.error(e);
} finally {
document.querySelector('.drop-info').style.display = 'none';
}

document.querySelector('.drop-info').style.display = 'none';
});

document.getElementById(id).addEventListener('dragover', (e) => {
Expand All @@ -497,6 +500,7 @@ const events = {

document.getElementById(id).addEventListener('dragenter', (e) => {
// show drop-info
// console.log(e);
document.querySelector('.drop-info').style.display = 'block';
});

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05fa1a5

Please sign in to comment.