mirror of
https://github.com/lana-k/sqliteviz.git
synced 2026-05-06 20:09:18 +08:00
Add seed layout #136
This commit is contained in:
60
src/components/Graph/ForceAtlasSeedLayoutSettings.vue
Normal file
60
src/components/Graph/ForceAtlasSeedLayoutSettings.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<Field label="Initial algorithm">
|
||||
<Dropdown
|
||||
:options="layoutOptions"
|
||||
:value="modelValue.initialAlgorithm"
|
||||
:clearable="false"
|
||||
className="test_fa2_initial_layout_algorithm_select"
|
||||
@change="update('initialAlgorithm', $event)"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
v-if="modelValue.initialAlgorithm === 'random'"
|
||||
label="Seed value"
|
||||
fieldContainerClassName="test_fa2_seed_value"
|
||||
>
|
||||
<NumericInput
|
||||
:value="modelValue.seedValue"
|
||||
@update="update('seedValue', $event)"
|
||||
/>
|
||||
</Field>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { markRaw } from 'vue'
|
||||
import { applyPureReactInVue } from 'veaury'
|
||||
import Field from 'react-chart-editor/lib/components/fields/Field'
|
||||
import NumericInput from 'react-chart-editor/lib/components/widgets/NumericInput'
|
||||
import Dropdown from 'react-chart-editor/lib/components/widgets/Dropdown'
|
||||
import 'react-chart-editor/lib/react-chart-editor.css'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Field: applyPureReactInVue(Field),
|
||||
Dropdown: applyPureReactInVue(Dropdown),
|
||||
NumericInput: applyPureReactInVue(NumericInput)
|
||||
},
|
||||
props: {
|
||||
modelValue: Object,
|
||||
keyOptions: Array
|
||||
},
|
||||
emits: ['update:modelValue'],
|
||||
data() {
|
||||
return {
|
||||
layoutOptions: markRaw([
|
||||
{ label: 'Circular', value: 'circular' },
|
||||
{ label: 'Random', value: 'random' }
|
||||
])
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
update(attributeName, value) {
|
||||
this.$emit('update:modelValue', {
|
||||
...this.modelValue,
|
||||
[attributeName]: value
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -171,6 +171,17 @@
|
||||
/>
|
||||
</Fold>
|
||||
<template v-if="settings.layout.type === 'forceAtlas2'">
|
||||
<Fold name="Seed layout">
|
||||
<Field>
|
||||
If you already built a graph using another layout, the initial
|
||||
algorithm doesn't apply unless you restart it.
|
||||
</Field>
|
||||
<ForceAtlasSeedLayoutSettings
|
||||
v-model="settings.layout.options"
|
||||
:keyOptions="keysOptions"
|
||||
@update:model-value="updateLayout(settings.layout.type)"
|
||||
/>
|
||||
</Fold>
|
||||
<Fold name="Advanced layout settings">
|
||||
<AdvancedForceAtlasLayoutSettings
|
||||
v-model="settings.layout.options"
|
||||
@@ -182,6 +193,7 @@
|
||||
<Button
|
||||
variant="secondary"
|
||||
class="test_fa2_reset"
|
||||
title="Set the settings to default or previously saved ones."
|
||||
@click="resetFA2LayoutSettings"
|
||||
>
|
||||
Reset
|
||||
@@ -192,16 +204,25 @@
|
||||
@click="toggleFA2Layout"
|
||||
>
|
||||
<template #node:icon>
|
||||
<div
|
||||
:style="{
|
||||
padding: '0 3px'
|
||||
}"
|
||||
>
|
||||
<div>
|
||||
<RunIcon v-if="!fa2Running" />
|
||||
<StopIcon v-else />
|
||||
<PauseIcon v-else />
|
||||
</div>
|
||||
</template>
|
||||
{{ fa2Running ? 'Stop' : 'Start' }}
|
||||
{{ fa2Running ? 'Pause' : 'Continue' }}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
class="test_fa2_restart"
|
||||
title="Clear node coordinates and run the layout algorithm anew."
|
||||
@click="restartFA2Layout"
|
||||
>
|
||||
<template #node:icon>
|
||||
<div>
|
||||
<RestartIcon />
|
||||
</div>
|
||||
</template>
|
||||
Restart
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -234,13 +255,15 @@ import Button from 'react-chart-editor/lib/components/widgets/Button'
|
||||
import Field from 'react-chart-editor/lib/components/fields/Field'
|
||||
import RandomLayoutSettings from '@/components/Graph/RandomLayoutSettings.vue'
|
||||
import ForceAtlasLayoutSettings from '@/components/Graph/ForceAtlasLayoutSettings.vue'
|
||||
import ForceAtlasSeedLayoutSettings from '@/components/Graph/ForceAtlasSeedLayoutSettings.vue'
|
||||
// eslint-disable-next-line max-len
|
||||
import AdvancedForceAtlasLayoutSettings from '@/components/Graph/AdvancedForceAtlasLayoutSettings.vue'
|
||||
import CirclePackLayoutSettings from '@/components/Graph/CirclePackLayoutSettings.vue'
|
||||
import FA2Layout from 'graphology-layout-forceatlas2/worker'
|
||||
import * as forceAtlas2 from 'graphology-layout-forceatlas2'
|
||||
import RunIcon from '@/components/svg/run.vue'
|
||||
import StopIcon from '@/components/svg/stop.vue'
|
||||
import RestartIcon from '@/components/svg/restart.vue'
|
||||
import PauseIcon from '@/components/svg/pause.vue'
|
||||
import { downloadAsPNG, drawOnCanvas } from '@sigma/export-image'
|
||||
import {
|
||||
buildNodes,
|
||||
@@ -248,7 +271,8 @@ import {
|
||||
updateNodes,
|
||||
updateEdges,
|
||||
reduceNodes,
|
||||
reduceEdges
|
||||
reduceEdges,
|
||||
clearNodeCoordinates
|
||||
} from '@/lib/graphHelper'
|
||||
import Graph from 'graphology'
|
||||
import { circular, random, circlepack } from 'graphology-layout'
|
||||
@@ -273,14 +297,16 @@ export default {
|
||||
Button: applyPureReactInVue(Button),
|
||||
ColorPicker: applyPureReactInVue(ColorPicker),
|
||||
RunIcon,
|
||||
StopIcon,
|
||||
RestartIcon,
|
||||
PauseIcon,
|
||||
RandomLayoutSettings,
|
||||
CirclePackLayoutSettings,
|
||||
NodeColorSettings,
|
||||
NodeSizeSettings,
|
||||
EdgeSizeSettings,
|
||||
EdgeColorSettings,
|
||||
AdvancedForceAtlasLayoutSettings
|
||||
AdvancedForceAtlasLayoutSettings,
|
||||
ForceAtlasSeedLayoutSettings
|
||||
},
|
||||
inject: ['tabLayout'],
|
||||
props: {
|
||||
@@ -643,14 +669,12 @@ export default {
|
||||
}
|
||||
|
||||
if (layoutType === 'circular') {
|
||||
circular.assign(this.graph)
|
||||
this.applyCircularLayout()
|
||||
return
|
||||
}
|
||||
|
||||
if (layoutType === 'random') {
|
||||
random.assign(this.graph, {
|
||||
rng: seedrandom(this.settings.layout.options.seedValue)
|
||||
})
|
||||
this.applyRandomLayout()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -688,30 +712,44 @@ export default {
|
||||
}
|
||||
|
||||
if (layoutType === 'forceAtlas2') {
|
||||
if (
|
||||
!this.graph.someNode(
|
||||
(nodeKey, attributes) =>
|
||||
typeof attributes.x === 'number' &&
|
||||
typeof attributes.y === 'number'
|
||||
)
|
||||
) {
|
||||
circular.assign(this.graph)
|
||||
}
|
||||
|
||||
this.fa2Layout = markRaw(
|
||||
new FA2Layout(this.graph, {
|
||||
getEdgeWeight: (_, attr) =>
|
||||
this.settings.layout.options.weightSource
|
||||
? attr.data[this.settings.layout.options.weightSource]
|
||||
: 1,
|
||||
settings: this.settings.layout.options
|
||||
})
|
||||
)
|
||||
this.applyFA2Layout()
|
||||
if (layoutType !== prevLayout) {
|
||||
this.autoRunFA2Layout()
|
||||
}
|
||||
}
|
||||
},
|
||||
applyCircularLayout() {
|
||||
circular.assign(this.graph)
|
||||
},
|
||||
applyRandomLayout() {
|
||||
random.assign(this.graph, {
|
||||
rng: seedrandom(this.settings.layout.options.seedValue)
|
||||
})
|
||||
},
|
||||
applyFA2Layout() {
|
||||
if (
|
||||
!this.graph.someNode(
|
||||
(nodeKey, attributes) =>
|
||||
typeof attributes.x === 'number' && typeof attributes.y === 'number'
|
||||
)
|
||||
) {
|
||||
if (this.settings.layout.options.initialAlgorithm === 'circular') {
|
||||
this.applyCircularLayout()
|
||||
} else {
|
||||
this.applyRandomLayout()
|
||||
}
|
||||
}
|
||||
|
||||
this.fa2Layout = markRaw(
|
||||
new FA2Layout(this.graph, {
|
||||
getEdgeWeight: (_, attr) =>
|
||||
this.settings.layout.options.weightSource
|
||||
? attr.data[this.settings.layout.options.weightSource]
|
||||
: 1,
|
||||
settings: this.settings.layout.options
|
||||
})
|
||||
)
|
||||
},
|
||||
toggleFA2Layout() {
|
||||
if (this.fa2Layout.isRunning()) {
|
||||
this.stopFA2Layout()
|
||||
@@ -731,6 +769,14 @@ export default {
|
||||
this.checkIteration = null
|
||||
}
|
||||
},
|
||||
restartFA2Layout() {
|
||||
if (this.fa2Layout.isRunning()) {
|
||||
this.stopFA2Layout()
|
||||
}
|
||||
clearNodeCoordinates(this.graph)
|
||||
this.applyFA2Layout()
|
||||
this.autoRunFA2Layout()
|
||||
},
|
||||
autoRunFA2Layout() {
|
||||
let iteration = 1
|
||||
this.checkIteration = () => {
|
||||
@@ -748,6 +794,8 @@ export default {
|
||||
setRecommendedFA2Settings() {
|
||||
const sensibleSettings = forceAtlas2.default.inferSettings(this.graph)
|
||||
this.settings.layout.options = {
|
||||
initialAlgorithm: 'circular',
|
||||
seedValue: 1,
|
||||
initialIterationsAmount: 50,
|
||||
adjustSizes: false,
|
||||
barnesHutOptimize: false,
|
||||
@@ -809,4 +857,8 @@ export default {
|
||||
flex-grow: 1;
|
||||
flex-basis: 0;
|
||||
}
|
||||
|
||||
.force-atlas-buttons :deep(.button__icon > div) {
|
||||
padding: 0 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
27
src/components/svg/pause.vue
Normal file
27
src/components/svg/pause.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M3 4C3 3.44772 3.14924 3 3.33333 3H6.66667C6.85076 3 7 3.44772 7
|
||||
4V14C7 14.5523 6.85076 15 6.66667 15H3.33333C3.14924 15 3 14.5523 3 14V4Z"
|
||||
fill="#A2B1C6"
|
||||
/>
|
||||
<path
|
||||
d="M11 4C11 3.44772 11.1492 3 11.3333 3H14.6667C14.8508 3 15 3.44772 15
|
||||
4V14C15 14.5523 14.8508 15 14.6667 15H11.3333C11.1492 15 11 14.5523 11
|
||||
14V4Z"
|
||||
fill="#A2B1C6"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'PauseIcon'
|
||||
}
|
||||
</script>
|
||||
36
src/components/svg/restart.vue
Normal file
36
src/components/svg/restart.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M7.34708 3.32922C8.63088 2.90468 10.017 2.90308 11.3022
|
||||
3.32434C11.9084 3.52308 12.4768 3.8114 12.9906 4.1759V3.34387C12.9906
|
||||
2.79159 13.4384 2.34387 13.9906 2.34387C14.5429 2.34387 14.9906 2.79159
|
||||
14.9906 3.34387V6.67102C14.9906 7.22331 14.5429 7.67102 13.9906
|
||||
7.67102H10.6635C10.1112 7.67102 9.66349 7.22331 9.66349 6.67102C9.66351
|
||||
6.11876 10.1112 5.67102 10.6635 5.67102H11.6313C11.3351 5.4851 11.0154
|
||||
5.33498 10.6791 5.22473C9.80069 4.93681 8.85289 4.93738 7.97501
|
||||
5.22766C7.09726 5.51795 6.33574 6.08228 5.80216 6.83704C5.26867
|
||||
7.59191 4.99088 8.49846 5.01017 9.42297C5.02954 10.3475 5.34482
|
||||
11.2417 5.90958 11.9738C6.47435 12.7058 7.25871 13.237 8.14787
|
||||
13.4904C9.03716 13.7437 9.9843 13.7055 10.85 13.381C11.7157 13.0565
|
||||
12.4548 12.463 12.9584 11.6876C13.2592 11.2244 13.879 11.0929 14.3422
|
||||
11.3937C14.805 11.6945 14.9366 12.3135 14.6361 12.7765C13.8996 13.9106
|
||||
12.8185 14.7794 11.5522 15.254C10.2859 15.7287 8.90058 15.7846 7.60001
|
||||
15.4142C6.2994 15.0437 5.15167 14.2661 4.3256 13.1954C3.49956 12.1247
|
||||
3.03849 10.8169 3.01017 9.46497C2.98191 8.1131 3.38782 6.7872 4.16837
|
||||
5.68274C4.94892 4.57842 6.06331 3.75379 7.34708 3.32922Z"
|
||||
fill="#A2B1C6"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'RestartIcon'
|
||||
}
|
||||
</script>
|
||||
@@ -1,21 +0,0 @@
|
||||
<template>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M3 4C3 3.44772 3.44772 3 4 3H14C14.5523 3 15 3.44772 15 4V14C15
|
||||
14.5523 14.5523 15 14 15H4C3.44772 15 3 14.5523 3 14V4Z"
|
||||
fill="#A2B1C6"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'StopIcon'
|
||||
}
|
||||
</script>
|
||||
@@ -36,6 +36,13 @@ export function dataSourceIsValid(dataSources) {
|
||||
}
|
||||
}
|
||||
|
||||
export function clearNodeCoordinates(graph) {
|
||||
graph.forEachNode((nodeId, attributes) => {
|
||||
delete attributes.x
|
||||
delete attributes.y
|
||||
})
|
||||
}
|
||||
|
||||
export function buildNodes(graph, dataSources, options) {
|
||||
const docColumn = Object.keys(dataSources)[0]
|
||||
const { objectType, nodeId } = options.structure
|
||||
@@ -144,6 +151,9 @@ export function reduceNodes(nodeId, nodeData, interactionState, settings) {
|
||||
if (selectedNodeId || hoveredNodeId || hoveredEdgeId || selectedEdgeId) {
|
||||
res.zIndex = 2
|
||||
res.highlighted = nodeId === selectedNodeId || nodeId === hoveredNodeId
|
||||
if (res.highlighted) {
|
||||
res.labelColor = 'black'
|
||||
}
|
||||
|
||||
const isInHoveredFamily =
|
||||
nodeId === hoveredNodeId ||
|
||||
|
||||
@@ -17,6 +17,18 @@ export default {
|
||||
})
|
||||
}
|
||||
|
||||
if (installedVersion < 4) {
|
||||
inquiries.forEach(inquiry => {
|
||||
if (
|
||||
inquiry.viewType === 'graph' &&
|
||||
inquiry.viewOptions.layout.type === 'forceAtlas2'
|
||||
) {
|
||||
inquiry.viewOptions.layout.options.initialAlgorithm = 'circular'
|
||||
inquiry.viewOptions.layout.options.seedValue = 1
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return inquiries
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import migration from './_migrations'
|
||||
|
||||
const migrate = migration._migrate
|
||||
const myInquiriesKey = 'myInquiries'
|
||||
const latestVersion = 4
|
||||
|
||||
export default {
|
||||
version: 3,
|
||||
version: latestVersion,
|
||||
myInquiriesKey,
|
||||
getStoredInquiries() {
|
||||
let myInquiries = JSON.parse(localStorage.getItem(myInquiriesKey))
|
||||
@@ -21,8 +22,8 @@ export default {
|
||||
return []
|
||||
}
|
||||
|
||||
if (myInquiries.version === 2) {
|
||||
myInquiries = migrate(2, myInquiries.inquiries)
|
||||
if (myInquiries.version < latestVersion) {
|
||||
myInquiries = migrate(myInquiries.version, myInquiries.inquiries)
|
||||
this.updateStorage(myInquiries)
|
||||
return myInquiries
|
||||
}
|
||||
@@ -69,8 +70,8 @@ export default {
|
||||
// Turn data into array if they are not
|
||||
inquiryList = !Array.isArray(inquiries) ? [inquiries] : inquiries
|
||||
inquiryList = migrate(1, inquiryList)
|
||||
} else if (inquiries.version === 2) {
|
||||
inquiryList = migrate(2, inquiries.inquiries)
|
||||
} else if (inquiries.version < latestVersion) {
|
||||
inquiryList = migrate(inquiries.version, inquiries.inquiries)
|
||||
} else {
|
||||
inquiryList = inquiries.inquiries || []
|
||||
}
|
||||
@@ -110,8 +111,8 @@ export default {
|
||||
|
||||
if (!data.version) {
|
||||
return data.length > 0 ? migrate(1, data) : []
|
||||
} else if (data.version === 2) {
|
||||
return migrate(2, data.inquiries)
|
||||
} else if (data.version < latestVersion) {
|
||||
return migrate(data.version, data.inquiries)
|
||||
} else {
|
||||
return data.inquiries
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user