better paint perspective

This commit is contained in:
Jan Prochazka 2022-08-28 14:08:13 +02:00
parent f7a269383f
commit 2f74eab048
5 changed files with 46 additions and 7 deletions

View File

@ -154,3 +154,13 @@ export interface MultipleDatabaseInfo {
[database: string]: DatabaseInfo;
};
}
export function switchPerspectiveReferenceDirection(ref: PerspectiveReferenceConfig): PerspectiveReferenceConfig {
return {
designerId: ref.designerId,
sourceId: ref.targetId,
targetId: ref.sourceId,
isAutoGenerated: ref.isAutoGenerated,
columns: ref.columns.map(x => ({ source: x.target, target: x.source })),
};
}

View File

@ -662,7 +662,9 @@
);
}
for (const reference of value?.references) {
for (const reference of settings?.sortAutoLayoutReferences
? settings?.sortAutoLayoutReferences(value?.references)
: value?.references) {
graph.addEdge(reference.sourceId, reference.targetId);
}

View File

@ -16,8 +16,11 @@
let minpos;
let columnsY = [];
const buswi = 10;
const extwi = 25;
const BUSWI = 10;
const EXTWI = 25;
$: buswi = settings?.referencePaintSettings?.buswi || BUSWI;
$: extwi = settings?.referencePaintSettings?.extwi || EXTWI;
export function recomputePosition() {
const { designerId, sourceId, targetId, columns, joinType } = reference;

View File

@ -5,8 +5,9 @@
PerspectiveConfig,
perspectiveNodesHaveStructure,
PerspectiveTreeNode,
switchPerspectiveReferenceDirection,
} from 'dbgate-datalib';
import _, { findIndex } from 'lodash';
import _ from 'lodash';
import { tick } from 'svelte';
import runCommand from '../commands/runCommand';
@ -109,14 +110,21 @@
});
}
async function detectAutoArrange(config: PerspectiveConfig, dbInfos) {
if (config.nodes.find(x => !x.position) && perspectiveNodesHaveStructure(config, dbInfos, conid, database)) {
async function detectAutoArrange(config: PerspectiveConfig, dbInfos, root) {
if (
root &&
config.nodes.find(x => !x.position) &&
perspectiveNodesHaveStructure(config, dbInfos, conid, database) &&
config.nodes.every(x => root.findNodeByDesignerId(x.designerId))
) {
await tick();
runCommand('designer.arrange');
}
}
$: detectAutoArrange(config, dbInfos);
$: detectAutoArrange(config, dbInfos, root);
// $: console.log('DESIGNER ROOT', root);
</script>
<Designer
@ -210,6 +218,21 @@
if (level <= 9) return `icon num-${level}-outline`;
return 'icon num-9-plus';
},
sortAutoLayoutReferences: references => {
// console.log('sortAutoLayoutReferences', root, references.length);
return _.sortBy(references, reference => {
const node1 = root?.findNodeByDesignerId(reference.sourceId);
const node2 = root?.findNodeByDesignerId(reference.targetId);
if (!node1 || !node2) return 10000;
if (node1.level > node2.level) reference = switchPerspectiveReferenceDirection(reference);
const index = _.findIndex(node1.childNodes, x => x.columnName == reference.columns[0].source);
return index;
});
},
referencePaintSettings: {
buswi: 10,
extwi: 10,
},
}}
referenceComponent={QueryDesignerReference}
value={createDesignerModel(config, dbInfos)}

View File

@ -157,6 +157,7 @@
}
// $: console.log('PERSPECTIVE', config);
// $: console.log('VIEW ROOT', root);
</script>
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>