|
@@ -1,6 +1,7 @@
|
|
|
import { SGraphItem } from "./SGraphItem";
|
|
|
import { SObject } from "@saga-web/base/lib";
|
|
|
import { SGraphLayoutType } from "./enums/SGraphLayoutType";
|
|
|
+import { SOrderSetType } from "./enums/SOrderSetType";
|
|
|
|
|
|
/**
|
|
|
* 基本选择器
|
|
@@ -14,6 +15,8 @@ export class SGraphSelectContainer extends SObject {
|
|
|
get count(): number {
|
|
|
return this.itemList.length;
|
|
|
}
|
|
|
+ /** 置顶zorder增加基数 */
|
|
|
+ private radix: number = 0.001;
|
|
|
|
|
|
/**
|
|
|
* 构造体
|
|
@@ -131,6 +134,34 @@ export class SGraphSelectContainer extends SObject {
|
|
|
} // Function layout()
|
|
|
|
|
|
/**
|
|
|
+ * 图层操作
|
|
|
+ *
|
|
|
+ * @param type 操作类型
|
|
|
+ * */
|
|
|
+ setOrder(type: SOrderSetType): void {
|
|
|
+ if (this.itemList.length < 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (type) {
|
|
|
+ case SOrderSetType.Top:
|
|
|
+ this.setTop();
|
|
|
+ break;
|
|
|
+ case SOrderSetType.Bottom:
|
|
|
+ this.setBottom();
|
|
|
+ break;
|
|
|
+ case SOrderSetType.After:
|
|
|
+ this.setAfter();
|
|
|
+ break;
|
|
|
+ case SOrderSetType.Before:
|
|
|
+ this.setBefore();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ console.log("图层操作类型不存在");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } // Function setOrder()
|
|
|
+
|
|
|
+ /**
|
|
|
* 左对齐
|
|
|
*
|
|
|
* */
|
|
@@ -380,4 +411,161 @@ export class SGraphSelectContainer extends SObject {
|
|
|
}
|
|
|
}
|
|
|
} // Function alignHorizontal()
|
|
|
+
|
|
|
+ // 修改层级操作步骤:
|
|
|
+ // 排序(保持相对层级不变)
|
|
|
+ // children里边要取 整数部分相同的 点:children是已经排好序的
|
|
|
+ // 然后再取最大值
|
|
|
+ /**
|
|
|
+ * 置顶
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ private setTop(): void {
|
|
|
+ const arr: SGraphItem[] = this.sortItemList(this.itemList, true);
|
|
|
+ // 按顺序zOrder增加
|
|
|
+ arr.forEach(it => {
|
|
|
+ let max = it.zOrder;
|
|
|
+ if (it.parent) {
|
|
|
+ it.parent.children.forEach(item => {
|
|
|
+ if (
|
|
|
+ Number(max.toFixed()) == Number(item.zOrder.toFixed())
|
|
|
+ ) {
|
|
|
+ if (item.zOrder > max) {
|
|
|
+ max = item.zOrder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ it.zOrder = max + this.radix;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } // Function setTop()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 置底
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ private setBottom(): void {
|
|
|
+ const arr: SGraphItem[] = this.sortItemList(this.itemList, false);
|
|
|
+ // 按顺序zOrder增加
|
|
|
+ arr.forEach(it => {
|
|
|
+ let min = it.zOrder;
|
|
|
+ if (it.parent) {
|
|
|
+ it.parent.children.forEach(item => {
|
|
|
+ if (
|
|
|
+ Number(min.toFixed()) == Number(item.zOrder.toFixed())
|
|
|
+ ) {
|
|
|
+ if (item.zOrder < min) {
|
|
|
+ min = item.zOrder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ it.zOrder = min - this.radix;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } // Function setBottom()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下移一层zorder减小
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ private setBefore(): void {
|
|
|
+ const arr: SGraphItem[] = this.sortItemList(this.itemList, false);
|
|
|
+ arr.forEach(it => {
|
|
|
+ if (it.parent) {
|
|
|
+ const min = it.zOrder;
|
|
|
+ let temp = it.parent.children
|
|
|
+ .map(child => {
|
|
|
+ if (
|
|
|
+ Number(child.zOrder.toFixed()) ==
|
|
|
+ Number(min.toFixed())
|
|
|
+ ) {
|
|
|
+ return child.zOrder;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .filter(c => c);
|
|
|
+ temp = [...new Set(temp)];
|
|
|
+ // 当前层有多个
|
|
|
+ const index = temp.indexOf(it.zOrder);
|
|
|
+ if (index <= 1) {
|
|
|
+ // 当前item 索引为1时 将当前item放至第一个前边
|
|
|
+ // @ts-ignore
|
|
|
+ it.zOrder = temp[0] - this.radix;
|
|
|
+ } else if (index > 1) {
|
|
|
+ // 当前item 索引大于等于2,将当前item放至前两个中间
|
|
|
+ // @ts-ignore
|
|
|
+ it.zOrder = (temp[index - 1] + temp[index - 2]) / 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } // Function setAfter()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上移一层zorder增加
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ private setAfter(): void {
|
|
|
+ const arr: SGraphItem[] = this.sortItemList(this.itemList, false);
|
|
|
+ arr.forEach(it => {
|
|
|
+ if (it.parent) {
|
|
|
+ const max = it.zOrder;
|
|
|
+ let temp = it.parent.children
|
|
|
+ .map(child => {
|
|
|
+ if (
|
|
|
+ Number(child.zOrder.toFixed()) ==
|
|
|
+ Number(max.toFixed())
|
|
|
+ ) {
|
|
|
+ return child.zOrder;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .filter(c => c);
|
|
|
+ temp = [...new Set(temp)].reverse();
|
|
|
+ // 当前层有多个
|
|
|
+ const index = temp.indexOf(it.zOrder);
|
|
|
+ if (index <= 1) {
|
|
|
+ // 当前item 索引为1时 将当前item放至第一个前边
|
|
|
+ // @ts-ignore
|
|
|
+ it.zOrder = temp[0] + this.radix;
|
|
|
+ } else if (index > 1) {
|
|
|
+ // 当前item 索引大于等于2,将当前item放至前两个中间
|
|
|
+ // @ts-ignore
|
|
|
+ it.zOrder = (temp[index - 1] + temp[index - 2]) / 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } // Function setBefore()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数组排序
|
|
|
+ *
|
|
|
+ * @param arr 排序前的数组
|
|
|
+ * @param flag 正序or逆序
|
|
|
+ * @return list 排序后的数组
|
|
|
+ * */
|
|
|
+ sortItemList(arr: SGraphItem[], flag: boolean = true): SGraphItem[] {
|
|
|
+ const list: SGraphItem[] = arr.map(t => t);
|
|
|
+ list.sort(this.compare("zOrder", flag));
|
|
|
+ return list;
|
|
|
+ } // Function sortItemList()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按照某个属性排序
|
|
|
+ *
|
|
|
+ * @param prop 属性
|
|
|
+ * @param flag 默认正序
|
|
|
+ * */
|
|
|
+ private compare(prop: string, flag: boolean) {
|
|
|
+ const f = flag ? 1 : -1;
|
|
|
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
|
+ return (a: any, b: any) => {
|
|
|
+ a = a[prop];
|
|
|
+ b = b[prop];
|
|
|
+ if (a < b) {
|
|
|
+ return f * -1;
|
|
|
+ }
|
|
|
+ if (a > b) {
|
|
|
+ return f * 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ };
|
|
|
+ } // Function compare()
|
|
|
} // Class SGraphSelectContainer
|