dash14 / v-network-graph

An interactive network graph visualization component for Vue 3
https://dash14.github.io/v-network-graph/
MIT License
495 stars 44 forks source link

Using RecursivePartial from common.ts in application #10

Closed markus-ebner closed 2 years ago

markus-ebner commented 2 years ago

Hi,

when using your awesome library with TS, I run into a warning in my IDE because of missing type declarations. I'm using the RecursivePartial to properly type the main configuration. And since it is not referenced in the index.d.ts TS does not know the type declarations.

Is it possible to add common/common.ts to the exported type information?

// @ts-ignore because of Cannot find module 'v-network-graph/lib/types/common/common' or its corresponding type declarations.
import { RecursivePartial } from 'v-network-graph/lib/types/common/common'
...
const mainConfig: UnwrapNestedRefs<RecursivePartial<Configs>> = reactive({})
dash14 commented 2 years ago

Hi @markus-ebner,

Thank you for your report. First, is it possible to use UserConfigs as an alias for RecursivePartial<Configs> ? I think UserConfigs has already been exported.

import { UserConfigs } from 'v-network-graph'
...
const mainConfig: UnwrapNestedRefs<UserConfigs> = reactive({})

If you have a case where you want to use RecursivePartial for something other than Configs, please let me know again so I will modify it to export.

Best regards,

markus-ebner commented 2 years ago

Thanks for the fast response @dash14! Yes, I tried it but I get the following problems with UserConfigs:

const mainConfig: UnwrapNestedRefs<UserConfigs> = reactive({
    view: {
      // TS2322: Type 'false' is not assignable to type 'true'. Shouldn't this be a boolean type? 
      panEnabled: false,
      // TS2322: Type 'false' is not assignable to type 'true'. Shouldn't this be a boolean type? 
      zoomEnabled: false,
      ...
    },
   edge: {
      summarized: {
          shape: {
            // TS2322: Type '(edge: any) => number' is not assignable to type 'string | number'. 
            // Type '(edge: any) => number' is not assignable to type 'number'. Somehow the function isn't working here? 
            strokeDasharray: edge => edge.config.dashDensity as number ?? 0
           ...
         }
     ... 
     }
  }
}
dash14 commented 2 years ago

Hi @markus-ebner, Thank you very much for your reply and report! This was a bug... The type definition was such that false could not be specified for view.{panEnabled, zoomEnabled}.

edge.summarized.* config did not support specifying a function, but this has been implemented along with the bug fix. Note that edge.summarized.* are the configs when multiple edges are merged into one, so the specified function's argument is not 'edge' but 'edges' ({ edgeId: edge } object).

const mainConfig = reactive<UserConfigs>({
   ...
   edge: {
      summarized: {
          shape: {
            strokeDasharray: edges => Object.values(edges)[0].someParameterOfEdge as number ?? 0
           ...
         }
     ... 
     }
  }
}

I just released a new version (v0.3.2), please check it.

markus-ebner commented 2 years ago

Thank you very much. It works as expected.