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