Commit 6e67cbdc authored by Marko Řeháček's avatar Marko Řeháček
Browse files

Turn off computed caching in GraphNode/Link to fix slow reaction. Implement...

Turn off computed caching in GraphNode/Link to fix slow reaction. Implement isTransferred in GraphLink.
Store: load modules automatically, rename module files
parent 3fca2db8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@
<script>
import { mapGetters, mapActions, mapMutations } from 'vuex'
import { isEqual } from 'lodash'
import { validateDataset } from '@/store/modules/data.js'
import { validateDataset } from '@/store/modules/data.store.js'

const JSON5 = require('json5')

+0 −1
Original line number Diff line number Diff line
@@ -321,7 +321,6 @@ export default {

      // create new links
      for (const link of newLinksArr) {
        console.log('respondAggregateNodes: creating link ' + JSON.stringify(link))
        this.data.links.push({
          id: link.id,
          source: this.findNode(link.source),
+43 −64
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@

<script>
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex'
import { getLinkSource, getLinkTarget } from '@/store/modules/data.js'
import { getLinkSource, getLinkTarget, isBundledIn, isMultilink } from '@/store/modules/data.store.js'
import * as d3 from 'd3' // FIXME

export default {
@@ -82,7 +82,7 @@ export default {
  },

  computed: {
    ...mapGetters('data', ['getNodeById', 'getLinkById']),
    ...mapGetters('data', ['getNodeById', 'getLinkById', 'getMultilinkLinks']),
    ...mapState('interaction', ['inDebug']),
    ...mapGetters('interaction', ['isLinkDetailed']),
    link() {
@@ -107,69 +107,48 @@ export default {
    showLabel() {
      return this.isDetailed || this.isHovering
    },
    isTransferred() {
      // FIXME
      const source = this.getNodeById(getLinkSource(this.link))
      const target = this.getNodeById(getLinkTarget(this.link))
      if (source === undefined | target === undefined) throw Error("Failed to fetch node data.")

      switch (source.type) {
        case 'regular':
          switch (target.type) {
    sourceNode() {
      return this.getNodeById(getLinkSource(this.link)) 
    },
    targetNode() {
      return this.getNodeById(getLinkTarget(this.link))
    },
    isTransferred: {
      cache: false,
      get: function() {
        switch (this.sourceNode.type) {
          case 'regular':
          case 'alias':
              return false
            case 'group':
              break
            case 'bundle':
              if (source === this.link.source || target === this.link.target) return false
              break
            default:
              throw Error('Undefined link type')
          }
        case 'alias':
          switch (target.type) {
            switch (this.targetNode.type) {
              case 'regular':
              case 'alias':
                if (isMultilink(this.link)) {
                  const singlelinks = this.$store.getters['data/getMultilinkLinks'](this.dataId)
                  for (const l of singlelinks) {
                    if (l.vis && l.vis.newSource !== undefined) return true
                  }
                } else {
                  if (isBundledIn(this.getNodeById(this.link.source), this.sourceNode.id) || isBundledIn(this.getNodeById(this.link.target), this.targetNode.id)) return true
                }
                return false
              case 'group':
              break
            case 'bundle':
              if (source === this.link.source || target === this.link.target) return false
              break
                return true
              default:
              throw Error('Undefined link type')
                throw Error(`Cannot compute isTransferred property: unknown link type of '${this.targetNode.type}'`)
            }
          case 'group':
          switch (target.type) {
            switch (this.targetNode.type) {
              case 'regular':
              case 'alias':
              case 'group':
              break
            case 'bundle':
              if (source === this.link.source || target === this.link.target) return false
              break
                return true
              default:
              throw Error('Undefined link type')
                throw Error(`Cannot compute isTransferred property: unknown link type of '${this.targetNode.type}'`)
            }
        case 'bundle':
          if (source.id === this.link.id)
          switch (target.type) {
            case 'regular':
            case 'alias':
              if (source === this.link.source || target === this.link.target) return false
              break
            case 'group':
              break
            case 'bundle':
              if (source === this.link.source || target === this.link.target) return false
              break
          default:
              throw Error('Undefined link type')
            throw Error(`Cannot compute isTransferred property: unknown link type of '${this.targetNode.type}'`)
        }
          return true
      }
      return true
    }
  },

+7 −27
Original line number Diff line number Diff line
@@ -147,32 +147,12 @@ export default {
      currentDragLength: 0, // approx. px to distinguish single-click from drag
      isUserSelecting: false,
      overrideMouseEvents: false,
      debouncedClickEvents: [],
      bundleSize: 0
      debouncedClickEvents: []
    }
  },

  mounted() {
    this.$store.subscribe(mutation => {
      const pl = mutation.payload

      switch (mutation.type) {
        case 'data/AGGREGATE_NODES':
          if (pl.targetGroupNode.id === this.node.id && pl.action === 'bundle')
            this.bundleSize += pl.nodeIds.length
          break
        case 'data/DISAGGREGATE_NODE':
          if (pl.revertAction === 'bundle' && pl.nodeId === this.node.id)
            this.bundleSize -= pl.newVisibleNodes.length
            if (this.bundleSize < 0) throw Error("Bundle size cannot be negative number.")
          break
      }
    })
  },

  computed: {
    ...mapState('interaction', ['inDebug']),
    ...mapGetters('data', ['getNodeBundledNodeCount']),
    node() {
      return this.$store.getters['data/getNodeById'](this.dataId)
    },
@@ -183,12 +163,6 @@ export default {
      return this.node !== undefined
    },
    isConnectedLinkHovered() {
      /*const focusedLinkId = this.$store.getters['interaction/getFocusedLinkId']
      if (!focusedLinkId) return

      const link = this.$store.getters['data/getLinkById'](focusedLinkId)
      if (!link) return
      return link.target === this.node.id || link.source === this.node.id*/
      return false
    },
    isHighlighted() {
@@ -210,6 +184,12 @@ export default {
    },
    visBundleCircleDistance() {
      return 2 + (['group', 'alias'].includes(this.node.type) ? this.visuals.groupNodeRadiusDifference : 0)
    },
    bundleSize: {
      cache: false,
      get: function () {
        return this.$store.getters['data/getNodeBundledNodeCount'](this.dataId)
      }
    }
  },

+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@

<script>
import { mapState, mapGetters, mapActions } from 'vuex'
import { isNodeAggregated, isNodeBundle } from '@/store/modules/data.js'
import { isNodeAggregated, isNodeBundle } from '@/store/modules/data.store.js'

export default {
  computed: {
Loading