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

How to control order of rough elements in svg #15

Open
maratumba opened this issue Jan 16, 2022 · 0 comments
Open

How to control order of rough elements in svg #15

maratumba opened this issue Jan 16, 2022 · 0 comments

Comments

@maratumba
Copy link

maratumba commented Jan 16, 2022

Thank you for this, really useful.

Not really an issue, but it might be useful to someone.

When using this in SVG mode, the rough elements in the SVG end up always at the "top" because they're appended to the end of the RoughSvg element. To overcome this, you can use a "RoughGroup" component to contain the rough elements in specific places within the SVG:

// RoughG.vue
<template>
  <g ref="g">
    <slot />
  </g>
</template>

<script>
export default {
  created(){
    this.rough = this.$parent.rough;
  },
  methods: {
    remove(){
      if(this.$refs.g) {
        this.$refs.g.remove()
      }
    },
    append(x){
      if(this.$refs.g){
        this.$refs.g.append(x)
      }
    },
  }
}
</script>

Now, if you put the rough element within this component, it stays where you want it:

<RoughSvg>
  <RoughG>
      <RoughLine :x1="x1" :y1="y1" :x2="x2" :y2="y2" />
  </RoughG>
  <SomeOtherComponent />
</RoughSvg>
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

1 participant