Merge pull request #20 from leomurca/feature/stitches_and_size_count
Display stitches count and size values
This commit is contained in:
commit
231c79a375
3 changed files with 36 additions and 7 deletions
|
@ -2,7 +2,7 @@ import { jDataView } from "./jdataview";
|
|||
import { supportedFormats } from "../format-readers";
|
||||
import { Pattern } from "./pattern";
|
||||
|
||||
function renderFile(filename, evt, canvas, colorView) {
|
||||
function renderFile(filename, evt, canvas, colorView, stitchesView, sizeView) {
|
||||
const fileExtension = filename.toLowerCase().split(".").pop();
|
||||
const view = jDataView(evt.target.result, 0, evt.size);
|
||||
const pattern = new Pattern();
|
||||
|
@ -12,6 +12,8 @@ function renderFile(filename, evt, canvas, colorView) {
|
|||
pattern.moveToPositive();
|
||||
pattern.drawShapeTo(canvas);
|
||||
pattern.drawColorsTo(colorView);
|
||||
pattern.drawStitchesCountTo(stitchesView);
|
||||
pattern.drawSizeValuesTo(stitchesView);
|
||||
}
|
||||
|
||||
function renderAbortMessage(errorMessageRef) {
|
||||
|
@ -52,12 +54,14 @@ export default function renderFileToCanvas(
|
|||
fileObject,
|
||||
canvas,
|
||||
errorMessageRef,
|
||||
colorView
|
||||
colorView,
|
||||
stitchesView,
|
||||
sizeView
|
||||
) {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onloadend = (evt) =>
|
||||
renderFile(fileObject.name, evt, canvas, colorView);
|
||||
renderFile(fileObject.name, evt, canvas, colorView, stitchesView, sizeView);
|
||||
reader.abort = (/** @type {any} */ _) => renderAbortMessage(errorMessageRef);
|
||||
reader.onerror = (evt) =>
|
||||
renderErrorMessage(evt.target.error.name, errorMessageRef);
|
||||
|
|
|
@ -180,4 +180,14 @@ Pattern.prototype.drawColorsTo = function (colorContainer) {
|
|||
});
|
||||
};
|
||||
|
||||
Pattern.prototype.drawStitchesCountTo = function (stitchesContainer) {
|
||||
stitchesContainer.innerHTML += `<div><strong>Stitches:</strong> ${this.stitches.length} </div>`;
|
||||
};
|
||||
|
||||
Pattern.prototype.drawSizeValuesTo = function (sizeContainer) {
|
||||
sizeContainer.innerHTML += `<div><strong>Size (x, y):</strong> ${Math.round(
|
||||
this.right / 10
|
||||
)}mm x ${Math.round(this.bottom / 10)}mm </div>`;
|
||||
};
|
||||
|
||||
export { Pattern, Color, stitchTypes };
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
export let files = [];
|
||||
let canvasRefs = [];
|
||||
let colorRefs = [];
|
||||
let stitchesRefs = [];
|
||||
let sizeRefs = [];
|
||||
let errorMessageRef;
|
||||
</script>
|
||||
|
||||
|
@ -12,11 +14,20 @@
|
|||
{#each Array.from(files) as file, i}
|
||||
<div class="canvas-container">
|
||||
<canvas bind:this={canvasRefs[i]} class="canvas" />
|
||||
<p>{file.name}</p>
|
||||
<p><strong>{file.name}</strong></p>
|
||||
<div class="stitches-container" bind:this={stitchesRefs[i]} />
|
||||
<div class="size-container" bind:this={sizeRefs[i]} />
|
||||
<div class="colors-container" bind:this={colorRefs[i]} />
|
||||
</div>
|
||||
{canvasRefs[i] &&
|
||||
renderFileToCanvas(file, canvasRefs[i], errorMessageRef, colorRefs[i])}
|
||||
renderFileToCanvas(
|
||||
file,
|
||||
canvasRefs[i],
|
||||
errorMessageRef,
|
||||
colorRefs[i],
|
||||
stitchesRefs[i],
|
||||
sizeRefs[i]
|
||||
)}
|
||||
{/each}
|
||||
<!-- svelte-ignore a11y-missing-content -->
|
||||
<h1 bind:this={errorMessageRef} />
|
||||
|
@ -38,8 +49,7 @@
|
|||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 550px;
|
||||
/* Maybe use height: auto; */
|
||||
height: 550px;
|
||||
max-height: 1000px;
|
||||
margin-bottom: 15px;
|
||||
padding: 10px;
|
||||
border: 2px solid black;
|
||||
|
@ -53,11 +63,16 @@
|
|||
|
||||
.colors-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
row-gap: 5px;
|
||||
}
|
||||
|
||||
.stitches-container {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
@media only screen and (max-device-width: 812px) {
|
||||
.canvas-container {
|
||||
width: 100%;
|
||||
|
|
Loading…
Reference in a new issue