diff --git a/admin_front/components/FloorplanCanvas.vue b/admin_front/components/FloorplanCanvas.vue
new file mode 100644
index 0000000..3a4fdc4
--- /dev/null
+++ b/admin_front/components/FloorplanCanvas.vue
@@ -0,0 +1,42 @@
+
+
+
+
\ No newline at end of file
diff --git a/admin_front/components/FloorplanSvg.vue b/admin_front/components/FloorplanSvg.vue
new file mode 100644
index 0000000..ef5d4b8
--- /dev/null
+++ b/admin_front/components/FloorplanSvg.vue
@@ -0,0 +1,86 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin_front/pages/plan/index.vue b/admin_front/pages/plan/index.vue
index 480bd28..79873f0 100644
--- a/admin_front/pages/plan/index.vue
+++ b/admin_front/pages/plan/index.vue
@@ -4,7 +4,10 @@ import PF, { Grid } from 'pathfinding'
import { chunks } from '~/helpers';
const config = useRuntimeConfig()
-const point_array = ref
()
+const point_array = useState('point_array', () => [[]])
+const chunk_size = useState('chunk_size', () => 8)
+const threshold = useState('chunk_size', () => 20)
+
const paths_array = ref<{ path: string, unwalkable: boolean, x: number, y: number }[]>()
const loading = ref(false)
@@ -33,9 +36,6 @@ const onUpload = (event: FileUploadUploadEvent) => {
try {
const data = JSON.parse(event.xhr.response)
point_array.value = data.response.np_field
- paths_array.value = sampling_data(data.response.np_field, 8, 20)
-
- newDraw()
} catch (error) {
console.log(error)
}
@@ -46,73 +46,23 @@ const selectFileEvent = async () => {
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`)
const data = await res.json()
point_array.value = data.np_field
- paths_array.value = sampling_data(data.np_field, 8, 20)
-
- newDraw()
} catch (error) {
console.log(error)
}
loadingFile.value = false
}
-
-const sampling_data = (np_field: number[][], chunkSize: number, threshold: number) => {
- const prepared_array = [...chunks(np_field, chunkSize)].map(line => {
- const line_data = [] as any[][]
- line.map((item: any) => [...chunks(item, chunkSize)]).map((item) => {
- item.map((one_line, k) => {
- if (!line_data[k]) line_data[k] = []
- line_data[k].push(...one_line)
- })
- })
- return line_data.map(el => {
- return el.filter(e => e > 0).length > threshold ? 1 : 0
- })
- });
- const res: any[] = []
- prepared_array.forEach((line, indexY) => {
- line.forEach((point, indexX) => {
- const targetX = indexX * chunkSize
- const targetY = indexY * chunkSize
- res.push({
- path: `M${targetX} ${targetY} ${targetX + chunkSize} ${targetY} ${targetX + chunkSize} ${targetY + chunkSize} ${targetX} ${targetY + chunkSize}Z`,
- unwalkable: !!point,
- x: indexX,
- y: indexY,
- })
- })
- })
- return res
-}
-const newDraw = async () => {
- startPoint.value = undefined
- endPoint.value = undefined
- startToEndPath.value = undefined
-
- context.value = canvasElement.value?.getContext('2d') || undefined;
- const lines = point_array.value
- if (!lines) return;
-
- context.value?.clearRect(0, 0, cw, ch)
- await nextFrame()
-
- for (let indexY = 0; indexY < lines.length; indexY++) {
- const line = lines[indexY];
-
- const drawLine = () => {
- line.forEach((point, indexX) => {
- if (canvasElement.value && context.value && point > 0) {
- context.value.fillStyle = 'crimson'
- context.value.fillRect(indexX, indexY, 1, 1)
- }
- })
- }
- drawLine()
- await nextFrame()
+const loadFiles = async () => {
+ try {
+ loadingFile.value = true
+ const res = await fetch(`${config.public.apiBase}/api/floorplan/`)
+ const data = await res.json()
+ files.value = data
+ } catch (error) {
+ console.log(error)
}
- grid.value = new PF.Grid(lines.map(y => y.map(x => x > 0 ? 1 : 0)))
+ loadingFile.value = false
}
-
const toggleBlock = (name: string) => {
if (openBlocks.value.includes(name)) {
openBlocks.value.splice(openBlocks.value.indexOf(name), 1)
@@ -131,17 +81,6 @@ const fileBtnClick = async () => {
}
toggleBlock('upload_file')
}
-const loadFiles = async () => {
- try {
- loadingFile.value = true
- const res = await fetch(`${config.public.apiBase}/api/floorplan/`)
- const data = await res.json()
- files.value = data
- } catch (error) {
- console.log(error)
- }
- loadingFile.value = false
-}
onMounted(async () => {
await loadFiles()
})
@@ -169,45 +108,15 @@ onMounted(async () => {
chooseLabel="Выберите файл" :disabled="loading" />
+
+
+
+