|
@@ -1,9 +1,15 @@
|
|
|
<template>
|
|
|
<template v-if="axissInfo">
|
|
|
<v-group v-for="info in axissInfo" :config="{ listening: false }">
|
|
|
- <v-line :config="{ points: info.points, ...style }" />
|
|
|
+ <v-line :config="{ points: info.points, ...config.labelLineConfig }" />
|
|
|
<v-text
|
|
|
- :config="{ ...style, strokeWidth: 0, ...textConfig, fontSize, align: 'center' }"
|
|
|
+ :config="{
|
|
|
+ ...config.labelLineConfig,
|
|
|
+ strokeWidth: 0,
|
|
|
+ ...textConfig,
|
|
|
+ fontSize: config.labelLineConfig.fontSize,
|
|
|
+ align: 'center',
|
|
|
+ }"
|
|
|
v-for="textConfig in info.texts"
|
|
|
/>
|
|
|
</v-group>
|
|
@@ -20,52 +26,66 @@ import {
|
|
|
useViewerTransform,
|
|
|
useViewSize,
|
|
|
} from "../hook/use-viewer";
|
|
|
-import { useResize } from "../hook/use-event";
|
|
|
import { Pos } from "@/utils/math";
|
|
|
import { TextConfig } from "konva/lib/shapes/Text";
|
|
|
import { Transform } from "konva/lib/Util";
|
|
|
import { normalPadding } from "@/utils/bound";
|
|
|
import { useConfig } from "../hook/use-config";
|
|
|
import { useProportion } from "../hook/use-proportion";
|
|
|
+import { useFormalLayer } from "../hook/use-layer";
|
|
|
+import { Group } from "konva/lib/Group";
|
|
|
+import { DataGroupId } from "@/constant";
|
|
|
|
|
|
-const style = {
|
|
|
- stroke: "#000",
|
|
|
- strokeWidth: 1,
|
|
|
- opacity: 1,
|
|
|
- strokeScaleEnabled: false,
|
|
|
- shadowColor: "#fff",
|
|
|
- shadowBlur: 3,
|
|
|
- shadowOffset: { x: 0, y: 0 },
|
|
|
- shadowOpacity: 1,
|
|
|
-};
|
|
|
-
|
|
|
-const props = withDefaults(
|
|
|
- defineProps<{
|
|
|
- splitOffset?: number;
|
|
|
- showOffset?: number;
|
|
|
- splitWidth?: number;
|
|
|
- }>(),
|
|
|
- { splitOffset: 80, showOffset: 20, splitWidth: 10 }
|
|
|
-);
|
|
|
+const config = useConfig();
|
|
|
|
|
|
+const format = useFormalLayer();
|
|
|
const getPixel = useGetViewBoxPositionPixel();
|
|
|
+const viewMat = useViewerTransform();
|
|
|
const size = useViewSize();
|
|
|
-const center = computed(() => {
|
|
|
- if (!size.value) return;
|
|
|
- return getPixel({
|
|
|
- left: size.value.width / 2,
|
|
|
- top: size.value.height / 2,
|
|
|
- });
|
|
|
-});
|
|
|
-const config = useConfig();
|
|
|
const rang = computed(() => {
|
|
|
- if (!size.value) return;
|
|
|
+ if (!size.value || !format.value) return;
|
|
|
const mrs = normalPadding(config.margin || 0);
|
|
|
|
|
|
- return {
|
|
|
- lt: getPixel({ left: props.showOffset + mrs[3], top: props.showOffset + mrs[0] }),
|
|
|
- rb: getPixel({ right: props.showOffset + mrs[1], bottom: props.showOffset + mrs[2] }),
|
|
|
- };
|
|
|
+ if (config.labelLineConfig.type === "fix") {
|
|
|
+ return {
|
|
|
+ lt: getPixel({
|
|
|
+ left: config.labelLineConfig.showOffset + mrs[3],
|
|
|
+ top: config.labelLineConfig.showOffset + mrs[0],
|
|
|
+ }),
|
|
|
+ rb: getPixel({
|
|
|
+ right: config.labelLineConfig.showOffset + mrs[1],
|
|
|
+ bottom: config.labelLineConfig.showOffset + mrs[2],
|
|
|
+ }),
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ // 收集点变动
|
|
|
+ points.value;
|
|
|
+ viewMat.value;
|
|
|
+
|
|
|
+ const formatGroup = format.value.findOne<Group>(`#${DataGroupId}`)!;
|
|
|
+ const rect = formatGroup.getClientRect();
|
|
|
+ const bw = config.labelLineConfig.strokeWidth / 2;
|
|
|
+ // console.log(rect);
|
|
|
+ return {
|
|
|
+ lt: {
|
|
|
+ x: rect.x - config.labelLineConfig.showOffset - mrs[3] + bw,
|
|
|
+ y: rect.y - config.labelLineConfig.showOffset - mrs[0] + bw,
|
|
|
+ },
|
|
|
+ rb: {
|
|
|
+ x: rect.x + rect.width + config.labelLineConfig.showOffset + mrs[1] - bw,
|
|
|
+ y: rect.y + rect.height + config.labelLineConfig.showOffset + mrs[2] - bw,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const center = computed(() => {
|
|
|
+ if (!rang.value) return;
|
|
|
+
|
|
|
+ return getPixel({
|
|
|
+ left: (rang.value.lt.x + rang.value.rb.x) / 2,
|
|
|
+ top: (rang.value.lt.y + rang.value.rb.y) / 2,
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
const compsInfo = useComponentsAttach(
|
|
@@ -103,7 +123,8 @@ const rectAxisSteps = computed(() => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const can = (data: number) => Math.abs(data - cur) > props.splitOffset;
|
|
|
+ const can = (data: number) =>
|
|
|
+ Math.abs(data - cur) > config.labelLineConfig.splitOffset;
|
|
|
|
|
|
let i = axis.length - 1;
|
|
|
for (i; i >= 0; i--) {
|
|
@@ -133,7 +154,6 @@ const rectAxisSteps = computed(() => {
|
|
|
|
|
|
const { transform: getWidthText } = useProportion();
|
|
|
const invConfig = useViewerInvertTransformConfig();
|
|
|
-const fontSize = 12;
|
|
|
const axissInfo = computed(() => {
|
|
|
if (!rang.value) return;
|
|
|
const infos: Record<string, { points: number[]; texts: TextConfig[] }> = {
|
|
@@ -147,17 +167,17 @@ const axissInfo = computed(() => {
|
|
|
for (let i = 0; i < rectAxisSteps.value.left.length; i++) {
|
|
|
const cur = rectAxisSteps.value.left[i];
|
|
|
infos.left.points.push(rang.value!.lt.x, cur);
|
|
|
- infos.left.points.push(rang.value!.lt.x + props.splitWidth, cur);
|
|
|
+ infos.left.points.push(rang.value!.lt.x + config.labelLineConfig.splitWidth, cur);
|
|
|
infos.left.points.push(rang.value!.lt.x, cur);
|
|
|
|
|
|
if (i === 0) continue;
|
|
|
const prev = rectAxisSteps.value.left[i - 1];
|
|
|
const lt = {
|
|
|
- x: rang.value!.lt.x + fontSize / 2,
|
|
|
+ x: rang.value!.lt.x + config.labelLineConfig.fontSize / 2,
|
|
|
y: prev,
|
|
|
};
|
|
|
const width = cur - prev;
|
|
|
- const height = fontSize;
|
|
|
+ const height = config.labelLineConfig.fontSize;
|
|
|
const center = { x: 0, y: height / 2 };
|
|
|
|
|
|
const tf = new Transform()
|
|
@@ -177,17 +197,17 @@ const axissInfo = computed(() => {
|
|
|
for (let i = 0; i < rectAxisSteps.value.right.length; i++) {
|
|
|
const cur = rectAxisSteps.value.right[i];
|
|
|
infos.right.points.push(rang.value!.rb.x, cur);
|
|
|
- infos.right.points.push(rang.value!.rb.x - props.splitWidth, cur);
|
|
|
+ infos.right.points.push(rang.value!.rb.x - config.labelLineConfig.splitWidth, cur);
|
|
|
infos.right.points.push(rang.value!.rb.x, cur);
|
|
|
|
|
|
if (i === 0) continue;
|
|
|
const prev = rectAxisSteps.value.right[i - 1];
|
|
|
const lt = {
|
|
|
- x: rang.value!.rb.x - fontSize / 1.5,
|
|
|
+ x: rang.value!.rb.x - config.labelLineConfig.fontSize / 1.5,
|
|
|
y: prev,
|
|
|
};
|
|
|
const width = cur - prev;
|
|
|
- const height = fontSize;
|
|
|
+ const height = config.labelLineConfig.fontSize;
|
|
|
const center = { x: 0, y: height / 2 };
|
|
|
|
|
|
const tf = new Transform()
|
|
@@ -207,14 +227,14 @@ const axissInfo = computed(() => {
|
|
|
for (let i = 0; i < rectAxisSteps.value.top.length; i++) {
|
|
|
const cur = rectAxisSteps.value.top[i];
|
|
|
infos.top.points.push(cur, rang.value!.lt.y);
|
|
|
- infos.top.points.push(cur, rang.value!.lt.y + props.splitWidth);
|
|
|
+ infos.top.points.push(cur, rang.value!.lt.y + config.labelLineConfig.splitWidth);
|
|
|
infos.top.points.push(cur, rang.value!.lt.y);
|
|
|
|
|
|
if (i === 0) continue;
|
|
|
const prev = rectAxisSteps.value.top[i - 1];
|
|
|
const lt = {
|
|
|
x: prev,
|
|
|
- y: rang.value!.lt.y + fontSize / 3,
|
|
|
+ y: rang.value!.lt.y + config.labelLineConfig.fontSize / 3,
|
|
|
};
|
|
|
|
|
|
const width = cur - prev;
|
|
@@ -230,14 +250,14 @@ const axissInfo = computed(() => {
|
|
|
for (let i = 0; i < rectAxisSteps.value.bottom.length; i++) {
|
|
|
const cur = rectAxisSteps.value.bottom[i];
|
|
|
infos.bottom.points.push(cur, rang.value!.rb.y);
|
|
|
- infos.bottom.points.push(cur, rang.value!.rb.y - props.splitWidth);
|
|
|
+ infos.bottom.points.push(cur, rang.value!.rb.y - config.labelLineConfig.splitWidth);
|
|
|
infos.bottom.points.push(cur, rang.value!.rb.y);
|
|
|
|
|
|
if (i === 0) continue;
|
|
|
const prev = rectAxisSteps.value.bottom[i - 1];
|
|
|
const lt = {
|
|
|
x: prev,
|
|
|
- y: rang.value!.rb.y - fontSize,
|
|
|
+ y: rang.value!.rb.y - config.labelLineConfig.fontSize,
|
|
|
};
|
|
|
|
|
|
const width = cur - prev;
|