minimum page preview

This commit is contained in:
klemek
2019-12-06 21:28:51 +01:00
parent 06b7ea17b4
commit c9a287ccf6
3 changed files with 123 additions and 81 deletions
+6 -4
View File
@@ -43,7 +43,7 @@
<td>×</td>
<td><input v-model="n" type="number" min="1"></td>
</tr>
<tr>
<tr v-if="!incomplete">
<td>Box size:</td>
<td><input id="bw" v-model="bw" v-bind:disabled="(finishedH && !bw) || fbw" type="number" min="0.1"></td>
<td>×</td>
@@ -51,13 +51,13 @@
<td><small>cm</small></td>
<td><span><input v-model="ratio" type="checkbox">Use ratio</span></td>
</tr>
<tr v-if="ratio">
<tr v-if="ratio && !incomplete">
<td>Box ratio:</td>
<td><input v-model="rw" type="number" min="0.1" step="0.1"></td>
<td>/</td>
<td><input v-model="rh" type="number" min="0.1" step="0.1"></td>
</tr>
<tr>
<tr v-if="!incomplete">
<td>Box margin:</td>
<td><input id="mh" v-model="mh" v-bind:disabled="finishedH && !mh" type="number" min="0.1" step="0.1"></td>
<td><small>cm</small></td>
@@ -65,7 +65,7 @@
<td><small>cm</small></td>
<td><span><input v-model="padding" type="checkbox">Sheet padding</span></td>
</tr>
<tr v-if="padding">
<tr v-if="padding && !incomplete">
<td>Sheet padding:</td>
<td><input id="ph" v-model="ph" v-bind:disabled="finishedH && !ph" type="number" min="0.1"></td>
<td><small>cm</small></td>
@@ -78,6 +78,8 @@
</tr>
</table>
<br>
<canvas id="preview"></canvas>
<br>
<small><a href="https://twitter.com/_klemek" target="_blank">@Klemek</a> - <a href="" target="_blank">Github Repository</a> - 2019</small>
</main>
</body>
+53 -19
View File
@@ -67,7 +67,7 @@ let app = {
data: {
//inputs
sw: 21, sh: 29.7, //sheet size
m: 2, n: 3, //boxes
m: undefined, n: undefined, //boxes
bw: undefined, bh: undefined, //box size
rw: undefined, rh: undefined, //box ratio
mh: undefined, mv: undefined, //margin
@@ -75,6 +75,7 @@ let app = {
sheet: 5,
ratio: false,
padding: false,
incomplete: false,
finishedH: false, finishedV: false, //finished h
fbw: false, fbh: false, //forced width or height
sheets: [
@@ -87,32 +88,40 @@ let app = {
this.sw = this.sheets[v].w;
this.sh = this.sheets[v].h;
}
this.refreshValues();
},
padding: function (v) {
if (!v && this.bw && this.mh)
this.mh = undefined;
if (!v && this.bh && this.mv)
this.mv = undefined;
this.checkFinished();
this.refreshValues();
},
ratio: 'checkFinished',
bw: 'checkFinished',
bh: 'checkFinished',
rw: 'checkFinished',
rh: 'checkFinished',
mh: 'checkFinished',
mv: 'checkFinished',
ph: 'checkFinished',
pv: 'checkFinished',
ratio: 'refreshValues',
sw: 'refreshValues',
sh: 'refreshValues',
m: 'refreshValues',
n: 'refreshValues',
bw: 'refreshValues',
bh: 'refreshValues',
rw: 'refreshValues',
rh: 'refreshValues',
mh: 'refreshValues',
mv: 'refreshValues',
ph: 'refreshValues',
pv: 'refreshValues',
},
methods: {
checkFinished: function () {
refreshValues: function () {
const self = this;
this.finishedH = false;
this.finishedV = false;
this.incomplete = false;
this.fbw = false;
this.fbh = false;
if (!this.sw || !this.sh || !this.m || !this.n) return;
if (!this.sw || !this.sh || !this.m || !this.n) {
this.incomplete = true;
} else {
if (this.ratio && this.rw && this.rh) {
if (this.bh && !this.fbw) {
this.fbw = true;
@@ -172,9 +181,8 @@ let app = {
});
}
}
if(this.finishedH && this.finishedV){
//TODO draw
}
this.redraw();
},
finalValue: function (n, v) {
v = utils.round(v, 2);
@@ -186,27 +194,53 @@ let app = {
['bw', 'bh', 'rw', 'rh', 'mh', 'mv', 'ph', 'pv'].forEach(name => {
Vue.set(self, name, undefined);
});
},
redraw: function () {
if (this.sw && this.sh) {
const maxWidth = 0.8 * this.$el.getBoundingClientRect().width;
let height = this.previewMaxHeight;
let width = height * this.sw / this.sh;
if (width > maxWidth) {
width = maxWidth;
height = width * this.sh / this.sw;
}
this.preview.setAttribute('width', width);
this.preview.style.width = `${width}px`;
this.preview.setAttribute('height', height);
this.preview.style.height = `${height}px`;
const ctx = this.preview.getContext('2d');
ctx.clearRect(0,0, width, height);
ctx.lineWidth = 4;
ctx.strokeStyle = '#424242';
ctx.strokeRect(0, 0, width, height);
} else {
this.preview.width = 1;
this.preview.height = 1;
}
}
},
'mounted': function () {
const self = this;
this.preview = document.getElementById('preview');
data.papers.forEach(s => {
self.sheets.push({
title: `${s.title} (${s.w}×${s.h}cm)`,
w: s.w,
h: s.h
w: s.w, h: s.h
});
});
data.papers.forEach(s => {
self.sheets.push({
title: `${s.title} landscape (${s.h}×${s.w}cm)`,
w: s.h,
h: s.w
w: s.h, h: s.w
});
});
console.log('app mounted');
setTimeout(() => {
self.$el.setAttribute('style', '');
self.previewMaxHeight = this.preview.getBoundingClientRect().height;
self.refreshValues();
});
}
};
+7 -1
View File
@@ -53,7 +53,7 @@ td:nth-child(2), td:nth-child(4) {
}
td:nth-child(3), td:nth-child(5) {
width: 1.1rem;
width: 1.8rem;
}
td:nth-child(6), td[colspan="5"]+td {
@@ -66,6 +66,12 @@ td[colspan="5"]{
text-align: center;
}
canvas{
display:block;
margin:auto;
height:20rem;
}
@media only screen and (min-width: 768px) {
main {
max-width: 42rem;