Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a function on the panEnabled property #66

Closed
Coeurdecedre opened this issue Jun 13, 2022 · 7 comments
Closed

Use a function on the panEnabled property #66

Coeurdecedre opened this issue Jun 13, 2022 · 7 comments

Comments

@Coeurdecedre
Copy link

Hi ! I would like to know if there was a way to use a function on the panEnabled property that return a boolean ? I tried but it doesn't work.

image

Thanks for your reply ! :)

@dash14
Copy link
Owner

dash14 commented Jun 13, 2022

Hi @Coeurdecedre,
Unfortunately, specifying a function to panEnabled is not supported at this time.
I guess the following steps can be used as an alternative, so please try them out.
(The following explanation assumes the Composition API, but if a different syntax is used, please read it accordingly.)

  • Wrap configs in reactive() and then pass it to v-network-graph.
    const configs = reactive(
      defineConfigs({
        view: {
          panEnabled: false,
          // ...
        },
        // ...
      })
    )
    <v-network-graph ... :configs="configs" />
  • Observe $store.state.keyboard.holdingShift changes by watch and assign to configs.view.panEnabled when the value is changed
    watch(() => /* store value */, value => {
      configs.view.panEnabled = value
    })

I hope this helps you.

@Coeurdecedre
Copy link
Author

Thanks @dash14 , I'll use watchers then ! However, would it be possible for you to add the possibility of adding a function this this property in the near future ? Thanks again ^^

@dash14
Copy link
Owner

dash14 commented Jun 15, 2022

Hi @Coeurdecedre,
Thank you for your reply.
I realized that by using JavaScript's getter functionality, it seems to be possible to achieve your requirement.
Please check the below example:

Node and edge configs require a function to be specified as a config in order to retrieve values from each object in some cases. However, since configs.view.* has a single value and the alternatives are available such as using getter/watch, it's not currently considering extending the view configs.

Best Regards,

@Coeurdecedre
Copy link
Author

Hi @dash14 ! Thank you very much for your help ! However, it doesn't work for me :(

This is my code :

image

image

I'm using Options API and not Composition API. holdingShift is a computed that return a boolean to each change of shift key status. Do you have an idea to solve my problem ?

Best Regards.

@dash14
Copy link
Owner

dash14 commented Jun 18, 2022

Hi @Coeurdecedre,
Thanks for trying it out!
I think this in the getter does not point to a component and this.holdingShift is undefined.
It may work to create a function that binds this outside of the getter and call it inside the getter, as shown below.

  data() {
    const panEnabled = () => !this.holdingShift;
    return {
      vNGConfigs: {
        view: {
          get panEnabled() {
            return panEnabled();
          },

Best Regards,

@Coeurdecedre
Copy link
Author

Hi @dash14 ! Thank you very much for your help !

I put the configs as a computed and it's working ! :)

Best Regards !

@dash14
Copy link
Owner

dash14 commented Jun 21, 2022

Hi @Coeurdecedre,
Thank you for your reply. I'm glad you got it resolved! 👍
Best Regards!

@dash14 dash14 closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants