Code Monkey home page Code Monkey logo

vue-konva's Introduction

Vue Konva

Version License

ReactKonva Logo

Vue Konva is a JavaScript library for drawing complex canvas graphics using Vue.

It provides declarative and reactive bindings to the Konva Framework.

All vue-konva components correspond to Konva components of the same name with the prefix 'v-'. All the parameters available for Konva objects can add as config in the prop for corresponding vue-konva components.

Core shapes are: v-rect, v-circle, v-ellipse, v-line, v-image, v-text, v-text-path, v-star, v-label, v-path, v-regular-polygon. Also you can create custom shape.

To get more info about Konva you can read Konva Overview.

Documentation / live edit

See Tutorials page

Quick Start

Vue.js version 2.4+ is required.

1 Install via npm

vue@3:

npm install vue-konva konva --save

vue@2:

npm install vue-konva@2 konva --save

2 Import and use VueKonva

vue@3:

import { createApp } from 'vue';
import App from './App.vue';
import VueKonva from 'vue-konva';

const app = createApp(App);
app.use(VueKonva);
app.mount('#app');

vue@2:

import Vue from 'vue';
import VueKonva from 'vue-konva';

Vue.use(VueKonva);

3 Reference in your component templates

<template>
  <v-stage :config="configKonva">
    <v-layer>
      <v-circle :config="configCircle"></v-circle>
    </v-layer>
  </v-stage>
</template>
<script>
export default {
  data() {
    return {
      configKonva: {
        width: 200,
        height: 200
      },
      configCircle: {
        x: 100,
        y: 100,
        radius: 70,
        fill: "red",
        stroke: "black",
        strokeWidth: 4
      }
    };
  }
};

</script>

Or use a CDN

<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
  </head>
  <body>
    <div id="app">
      <v-stage ref="stage" :config="configKonva">
        <v-layer ref="layer">
          <v-circle :config="configCircle"></v-circle>
        </v-layer>
      </v-stage>
    </div>
    <!--1. Link Vue Javascript & Konva-->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/konva/konva.js"></script>
    <!--2. Link VueKonva Javascript -->
    <script src="https://unpkg.com/vue-konva/umd/vue-konva.min.js"></script>
    <script>
      // 3. Create the Vue instance
      new Vue({
        el: '#app',
        data: {
          configKonva: {
            width: 200,
            height: 200,
          },
          configCircle: {
            x: 100,
            y: 100,
            radius: 70,
            fill: 'red',
            stroke: 'black',
            strokeWidth: 4,
          },
        },
      });
    </script>
  </body>
</html>

Core API

Getting reference to Konva objects

You can use ref feature from vue.

<template>
  <v-stage ref="stage">
    <v-layer ref="layer">
      <v-rect ref="rect" />
    </v-layer>
  </v-stage>
</template>

<script>
  const width = window.innerWidth;
  const height = window.innerHeight;

  export default {
    mounted() {
      const stage = this.$refs.stage.getNode();
      const layer = this.$refs.layer.getNode();
      const rect = this.$refs.rect.getNode();
    },
  };
</script>

Strict mode

By default vue-konva works in "non-strict" mode. If you changed a property manually (or by user action like drag&drop) properties of the node will be not matched with properties passed as config. vue-konva updates ONLY changed properties.

In strict mode vue-konva will update all properties of the nodes to the values that you provided in config, no matter changed they or not.

You should decide what mode is better in your actual use case.

To enable strict mode pass __useStrictMode attribute:

<v-rect :config="{}" __useStrictMode></v-rect>

Configurable prefix

By default vue-konva is using v- prefix for all components.

You can use your own prefix if default one conflicts with some other libs or your components.

import Vue from 'vue';
import VueKonva from 'vue-konva'

Vue.use(VueKonva, { prefix: 'Konva'});

// in template:
<konva-stage ref="stage" :config="stage">

Custom Konva Nodes

By passing a Record<string, new (...args: any) => Node<any>> object to customNodes in options, you can use your own konva node classes in Vue Konva.

import Vue from 'vue';
import VueKonva from 'vue-konva'

class MyRect extends Konva.Rect {
  constructor() {
    super()
    console.log('MyRect')
  }
}

Vue.use(VueKonva, {
    // The keys are used as component names.
    customNodes: { MyRect }
})

// in template:
<v-my-rect />

Change log

The change log can be found on the Releases page.

vue-konva's People

Contributors

botz avatar comfyfluffy avatar freeqaz avatar geoffgscott avatar k1nz avatar ktsn avatar lavich avatar lavrton avatar ldoppea avatar mkrazz avatar rafaesc avatar shadskii avatar yoshithechinchilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-konva's Issues

Vue + Stage --> Have to force reload my browser (ctrl + r / ctrl + f5)

Hi there,

I am experiencing somthing quite weird.

I have a stage that has draggable : true on.
I am using a vue CLI server to host this in debug environment.

When i just reload the page by simply browsing to it or pressing normal f5, the stage is not draggable until i force reload (ctrl + f5 or ctrl + r)

Do you think this is a development environment issue, or is this an issue with the vue-konva?

Thanks in advance.

Your library is amazing btw!

How to use in NuxtJS?

How to use it in nuxt js? It always shows an error Unknown custom element: <konva> - did you register the component correctly? I've created plugins/konva.js and added it on my nuxt.config.js file plugins: [ { src: '~/plugins/konva', ssr: false } ]. But i can't access v-stage component or any other component

Transformer 'boundBoxFunc' throws error

When setting the configuration of a transformer, I tried to set the boundBoxFunc and it thew the following error:

Cannot read property 'rotation' of undefined
at Konva.Transformer._fitNodeInto

I set the config on the Transformer component.
<v-transformer :config="transformConfig" ref="transformer" />

And the config is setup like this:
transformConfig: { ignoreStroke: true, rotateEnabled: false, boundBoxFunc: function () { console.log('test') } }

Thanks for your help!

Dragover Example

Hi!

I'm fairly new to Konva, but very experienced with Vue.

Trying to translate this example of Dragover to Vue and I'm having some difficulty.
Would it be possible to get a simple Dragover event example with Vue?

Thanks.

Issue when removing item in v-for

Hi!

First of all thank you for the great package!

I ran into a small issue and I'm not sure how I could correct it.

I have a layer displaying a number of circles using a v-for loop. Adding circles work as expected but removing a point do not seem to update the canvas.

I tried to reproduce the issue using JSFiddle:
https://jsfiddle.net/eywraw8t/10786/

In this case no point seem to be deleted until add a new point, where as in my project the points are deleted in real time except for the last one which stays on the layer even though the array is empty.

Any idea where this could come from?

Thanks in advance!

Usage with NuxtJS?

Hi everyone,

Sorry if this is the wrong place as it is not an issue. Is there a better way to ask for support?

I would like to use vue-konva in addition to NuxtJS, but the main problem is that it does not paint.

I'm using:

  • nuxt: "1.4.0",
  • vue-konva: "1.0.5",
  • vue: "2.5.13"

I have to component "konva.vue" with this code:

<template>
<div>
  <v-stage ref="stage" :config="configKonva">
    <v-layer ref="layer">
      <v-circle :config="configCircle"></v-circle>
    </v-layer>
  </v-stage>
</div>
</template>

<script>
export default {
  data: () => ({
    configKonva: {
      width: 400,
      height: 200
    },
    configCircle: {
      x: 200,
      y: 100,
      radius: 40,
      fill: 'red',
      stroke: 'black',
      strokeWidth: 4
    }
  })
}
</script>

When I use the <konva></konva> component. Vue-konva creates the canvas html element with correct properties.

Generate:

<div class="konvajs-content" role="presentation" style="position: relative; width: 400px; height: 200px;">
    <canvas width="400" height="200" style="padding: 0px; margin: 0px; border: 0px; background: transparent; position: absolute; top: 0px; left: 0px; width: 400px; height: 200px;"></canvas>
</div>

And here is the problem. Vue-konva not printing:
image

I do not know what is happening :(.

What are your thoughts about this?

Memory leak in dynamic rendering

Hey. I ran into a memory leak issue when drawing a list. My application dynamically retrieves the shapes from the server and renders them using a v-for directive. After some time, the memory consumption is about 2 gigabytes and the browser crashes. When monitoring performance, you can see that there are a huge number of undeleted nodes and event subscriptions.

ะกะฝะธะผะพะบ ัะบั€ะฐะฝะฐ ะพั‚ 2019-05-09 18-00-02
ะกะฝะธะผะพะบ ัะบั€ะฐะฝะฐ ะพั‚ 2019-05-09 18-01-25

I give a part of the code at which there is a leak

<v-group>
	<v-rect v-for="plate in processedPlates" :key="plate.id" :config="plate.config"></v-rect>
</v-group>

[Proposal] vue-konva v2

Hello, everyone. I am going to work with a new version of vue-konva and make many changes in repo structure and some code behavior:

  • Get rid of all webpack and other configuration from the repo. Instead, start using https://github.com/insin/nwb so we don't need to care about configurations.
  • Add tests to cover mosts of the cases
  • Create many demos/tutorials and add them into https://konvajs.github.io/docs/vue/ section
  • Possibly change events behaviour. Currently event handlers has VueComponent as the first argument. I think it will be better to have event object as the first argument instead.
  • Can we avoid usage config propery and define attributes directly? Like this: <v-rect fill="red"/>

Creating new layer with shape on click

Hello, I have a question - how to draw canvas layer (for example just simple square) with event on click on button in Vue.js? I have stage and on that stage with position x:0, y:0 i want after click on button to generate that square and with drag and drop to position it on that stage? Or simple - how to create layer with shape after button's click?

Can somebody help me?

Issues using with Quasar Framework

Hi,

I am trying to use vue-konva within the Quasar framework. However, for some reason, the canvas is not being rendered and I get the following error.

You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

found in

---> <VLayer>

I am totally new to vuejs. Am I doing something completely wrong?

V

Using layer.add()

I am trying to add nodes to layers with the following code:

textLayer.add(...layers.textLayer);

Where layers.textLayer is an array of objects like so:

{
    attrs: {
        fill: "rgba(255, 0, 0, 1)",
        index: 0,
        draggable: true,
        text: "Example Text",
        fontFamily: "Bangers",
        fontSize: 60,
        x: 222.41379310344828,
        y: 268.9655172413793,
        scaleX: 4.43772935901027,
        scaleY: 4.43772935901027
    },
    className: "Text",
    filters: []
},
{
    //...
}

But I am receiving this error:

"TypeError: child.getParent is not a function"

I found this issue for react-konva but I am not sure this is the same issue I am facing with Vue.

Adding event modifiers

It seems that Event Modifiers aren't implemented in the current package.
Is it possibile to use these Event Modifiers on the vue-konva components?

I've tried using @mousedown.left, but it doesn't seem to trigger the event.

how to make stage responsive?

https://konvajs.github.io/docs/sandbox/Responsive_Canvas.html

this is my code

computed: {
    stage() {
      return this.$refs.stage.getStage();
    },
  },
      const scale = 2;
      this.stage.width = this.stage.width * scale;
      this.stage.height = this.stage.height * scale;
      this.stage.scale({ x: scale, y: scale });
      this.configCircle.x = this.configCircle.x - 50;
      this.stage.draw();

the stage size is not changing,the canvas size seems can't be changed by this way,but i can see the circle scale 2x bigger.

image

i see your componet, it has two div outside the canvas,it seems must set spectified width and hieght.

Question about grouping

I want to allow users to select a group of nodes so that they can resize/rotate/etc...

I know that I want something like this in terms of setting up the transformer.

What I am having trouble with is that my nodes are spread across layers, my structure looks something like this.

<v-stage>
    <v-layer ref="imageLayer">
        <!-- nodes... -->
    </v-layer>
    <v-layer ref="shapeLayer">
        <!-- nodes... -->
    </v-layer>
    <v-layer ref="textLayer">
        <!-- nodes... -->
    </v-layer>
    <v-layer ref="groupLayer">
        <v-group></v-group>
    </v-layer>
</v-stage>

Where I want to be able to select nodes from the first three layers, add them to the v-group resize/rotate/etc... them and then put them back in their respective layer, is this the right way to approach this problem?

Cheers.

How to event.cancelBubble?

Hello!
Thanks for library!

My code looks like this:

<v-layer
  ref="layer"
  @dragend="k_layer_onDragEnd"
>
<v-circle
  v-for="(p, i) in kPoints"
  :key="`point${i}`"
  :config="p"
  :ref="`point${p.name}`"
  @dragend="k_point_onDragEnd"
></v-circle>
</v-layer>

<script>
  k_layer_onDragEnd(layer) {
        console.log(' ---> k_layer_onDragEnd');
  },
  k_point_onDragEnd(point, e) {
        e.evt.cancelBubble = true;
        // more...
  },
</script>

And event pops up =(

How to set cancelBubble to true?

Red error in console when canvas is empty

Hello, i'm having a ton of errors when i'm creating my canvas with nothing inside

Error in updated hook: "TypeError: Cannot read property 'getZIndex' of null"

found in

---> <VGroup>
...

My template is like so

<v-stage ref="stage" class="canvas" :config="configKonva">
 <v-layer ref="layer">
  <v-group :key="mainStage">
   <BlockContainer />
   <TriggerContainer />
   <CurveContainer />
  </v-group>
 </v-layer>
</v-stage>

Any ideas? It's not blocking the execution but I have a ton of these messages in red in the console

Layer children is not updated after using destroy on a node

I have created an example here: https://codesandbox.io/s/oq3p2y8lzq

Basically when I call destroy on a node, that node is still in the $children array of the layer.

It appears to break getAbsoluteZIndex() on other nodes, it throws:

Cannot read property 'getChildren' of undefined

EDIT
After thinking about this a bit more I actually need to be removing the item from the array the nodes are generated from, i.e I am currently iterating over an images array to generate the images:

<v-image
	v-for="image in images"
	:key="image.src"
	:config="{
            image: image,
            draggable: true,
       }"
/>

Is there anyway from the node instance (getNode()) to identify which item it is on the original array so I can remove it?

"TypeError: Cannot read property 'on' of undefined"

I made a very simple project where I wanted to test vue-konva I get the following:

Error in mounted hook: "TypeError: Cannot read property 'on' of undefined"

My component has a very simple template:

<template>
    <v-stage :config="configKonva">
        <v-layer>
            <v-circle :config="configCircle"></v-circle>
        </v-layer>
    </v-stage>
</template>

and data:

   data () {
      return {
        configKonva: {
          width: 200,
          height: 200,
        },
        configCircle: {
          x: 100,
          y: 100,
          radius: 70,
          fill: 'red',
          stroke: 'black',
          strokeWidth: 4,
        },
        icons: {},
      }
    },

the google chrome trace looks like that:

TypeError: Cannot read property 'on' of undefined
    at VueComponent.mounted (admin.js:84063)
    at callHook (admin.js:90305)
    at Object.insert (admin.js:91542)
    at invokeInsertHook (admin.js:93344)
    at Vue.patch [as __patch__] (admin.js:93563)
    at Vue._update (admin.js:90044)
    at Vue.updateComponent (admin.js:90172)
    at Watcher.get (admin.js:90526)
    at new Watcher (admin.js:90515)
    at mountComponent (admin.js:90179)

admin being the name of my app.

Any idea where does the problem comes from? It looks almost as some vue-konva components would not be correctly registered, but it that case, I would get a different error message from Vue.

I imported vue-konva with import and Vue.use(VueKonva)...

is there reactivity?

Any idea why following sample is not working
Simple rectangle with btn to update the width.

<template>
  <q-page padding>
    <q-btn @click="changeRect">Update</q-btn>
    <div class="row">
    <v-stage ref='stage' :config="configKonva">
      <v-layer ref='layer'>
        <v-rect ref='rect' :config="configRect"></v-rect>
      </v-layer>
    </v-stage>
</div>
  </q-page>
</template>

<style>
</style>

<script>
export default {
  name: 'PageHome',
   data () {
    return {
      configKonva: {
        width: 600,
        height: 600
      },
      configRect: {
        x: 0,
        y: 0,
        width: 100,
        name: 'rect',
        height: 100,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 1,
      }
    }
  },
  mounted () {
  },
  methods:
  {
    changeRect () {
      this.configRect.width = 150
    }
  }
}
</script>

render: createElement( issues

Hi!

So - I did a custom component - which tries to spawn Konva-vue components within its render element - by doing calls like createElement(VueKonva.Text - the issue is with the fact that such an element won't have a name as it won't have a 'componentTag' - so - I replaced the following line:
this.name = this.$options._componentTag;
with:
this.name = this.$options._componentTag || this.$options.propsData.config.name;

and added:

the name to the props\config - I'm rather new both at Vue and Konva - and I wonder if this is the way to go to be able to make custom (i.e. with a render method) components that have sub-components with vue-konva.

If it is - this 'hack' can be easily added to the docs on a new simple section - I can do a PR on that and on the code

Issues with moveUp and moveDown when trying to create an interface to move images

I have created the following example https://codesandbox.io/s/kxj7rxqo4v because the issue is quite hard to explain.

Basically what I am trying to create is an interface where users can see a list of all the images in a layer in the order (based on z-index) they appear in.

I then want to have buttons to allow them to 'raise' or 'lower' an image (using moveUp or moveDown)

So far I can get the images moving down but as soon as you click back on the canvas the moved down image re-appears, I think this is to do with caching but I can't quite figure out how it is supposed to work.

Additionally I can't quite get the buttons to work, the initial move down will work but if you then try to move the new top element (assuming you have only uploaded 2 images) (which is now effectively one layer higher because it has had a layer moved below it it will not work) you can see this if you click around on the buttons in the demo.

Any insight would be much appreciated!

Cheers!

Tween along a path

Hi,

I need to do some animation along a path so it looks like the greensock advanced tweening plugin looks good for this.

What is the best way to add this to a vue-konva based application.

Thanks,

Rob

Update element state on transform

Hello!

I have a component with which I can create a new circle by pressing a button to create it. What it does is copies a new attributes object and saves it in the store:

{
    id: 1,
    radius: 20,
    fill: 'blue',
    stroke: 'black',
    strokeWidth: 1,
    x: 100,
    y: 100,
    draggable: true,
    offsetX: 0,
    offsetY: 0,
    rotation: 0,
    scaleX: 1,
    scaleY: 1,
    skewX: 0,
    skewY: 0
}

And I have a stage component which iterates over those objects saved in the store and creates new <v-circle> shapes with those attributes passed in the config prop of each shape:

<v-stage>
    <v-layer>
        <v-circle
            for="shape in storeShapes"
            :key="shape.id"
            :config="shape"
        />
    </v-layer>
</v-stage>

This works fine, but the problem is when I transform the element the attributes in the store stay the same, while the attributes of the Konva node are different, specifically the scale[X/Y] attributes.

So my question is, is it possible to keep the shape attributes in the store so that the transformer updates them automatically, or do I have to update them manually when events such as dragend and transformend are triggered?

I'm storing the attributes in the store in order to manipulate them more easily and for saving and loading of the canvases later on.

Usage with Vuex

Hi,

First, sorry if this is the wrong place as it is not an issue. Is there a better way to ask for support?

I would like to use vue-konva in addition to Vuex, but i'm not sure how to handle drag events.

If I use your readme.md sample and add 'draggable:true' to the configeCircle object. Then I'll be able to drag and move the v-circle component. But configCircle object will not be updated with new 'x' and 'y' values. This seems logic to me as vuejs wants us to use one way bindings.

Now if I add a Vuex store to serve the configCircle object and I update this object on dragmove event with a custom action. Then the new configCircle values will be propagated to the v-circle object while he is still being dragged.

This seems to work correctly, but is this a good practice?
I'm not comfortable enough with vuejs nor konva so I'm not able to answer this question.

What are your thoughts about this?

Node with multiple colors

I made a shape by using circle and arrow nodes, the arrow start points are the same for the circle, The circle has an transparent color that makes the arrow visible under the circle, My goal is that I want the arrow to start from the circle's edge.
I tried to find a solution using the offset and I tried to find a way to change a color of between specific points on the arrow stroke so I can put it transparent color for that visible part but I couldn't.
(Please check the image)
screenshot 2018-12-21 at 16 25 34

I wish that you can help me with that.

Thanks in advance.

window.Konva is undefined with Konva version 3.1.2

Looks like with recent version of Konva - 3.1.2 window.Konva is undefined.
Thus it results in error in mounted hook in vue-konva.js:
"TypeError: Cannot read property 'Stage' of undefined"

  mounted: function mounted() {
    this._stage = new window.Konva.Stage({
      width: this.config.width,
      height: this.config.height,
      container: this.$el
    });
    this.StageEmitter.emit('mounted', this._stage);
    this.uploadKonva();
  },

Here is a link to codesandbox to reproduce problem

One can get around this problem with a hack like:

if (!window.Konva) window.Konva = require('konva');

Stage drawing shapes often don't work.

Hi there,

I have a puzzle about konva's use in IOS 12.1.1.
"konva": "^2.6.0","vue": "^2.5.2","vue-konva": "^2.0.2";

When I switch a component with konva through routing jumps,
I often fail to draw graphics.

I don't know if this problem has happened on your side,
and if there are any solutions or suggestions.

Thanks for your help!

ZIndexing - SetZIndex(value)

Hi Konva,

Once again thank you for this incredible library.

I have a demo where i am trying to adjust the z-index of nodes.

https://codepen.io/anon/pen/KbeGaM

The z-indexing i have tried to do is on the group and or the rects in the demo.

I cannot seem to get the Groups to move up or down or the rects to move up or down.

Could you please assist.

Racecondition when loading images

I am trying to load multiple images at once with the following code:

// 'template' Object value
const loading = images.map(data => {
    return new Promise((resolve, reject) => {
        const image = new Image();
        image.onload = resolve(image);
        image.onerror = reject(new Error(`Failed trying to load ${data.raw.title}`));
        image.title = data.raw.title;
        image.src = data.raw.src;
    })
});
return Promise.all(loading);

And then:

// Populate vue instance array with HTML images
this.images = await template.images;

Now the issue is I am trying to then set some attributes on the image but node.cache() fails to work because even though the images are loaded when I add them to the vue instance, it takes the stage/layer a small amount of time to get there width/height so I get the following error:

Konva error: Can not cache the node. Width or height of the node equals 0. Caching is skipped.

So I started logging out the width, before and after I try to node.cache:

const getImageWidths = () => {
    this.$refs.imageLayer.getNode().children.map(child => {
        if (child.className === "Image") {
            // There is also a transformer on the layer so that will just return 'undefined'
            return child.attrs.image.width;
        }
    })
}

console.log(getImageWidths()); // [0, 0, 0, 0, undefined]

// Using $nextTick() to try and wait for images to be ready
await this.$nextTick();

// Try to set attributes here, as well as run node.cache()
setAttributes(template.attrs.images, this.$refs.imageLayer.getNode());

setTimeout(() => {
    // Use setTimeout just to force to end of que
    console.log(getImageWidths()); // [233, 233, 233, 233, undefined]
}, 0)

So as you can see it does appear to be a loading issue, the function to set the Attributes is as below:

function setAttributes(attributes, layer) {
    // Attributes is an array of attr objects
    // layer is a layer (this.$refs.imageLayer.getNode())
    attributes.map((attrs, index) => {
        const children = layer.children;
        const node = Object.values(children).find(child => {
            return child.index === index;
        });
        // @NOTE keep any attirbutes we don't bother passing through
        // - This may not be necessary
        // - This includes node filters
        const merged = Object.assign(node.getAttrs(), attrs);
        node.setAttrs(merged);
        node.cache();
    });
}

UPDATE

I think this may actually be to do with Promise.all as I am using it elsewhere simply to load more images and they are not drawing at all, i.e.

function imagesFromUrl(images) {
    const loading = images.map(data => {
        return new Promise((resolve, reject) => {
            const image = new Image();
            image.onload = resolve(image);
            image.onerror = reject(
                new Error(`Failed trying to load ${data.raw.title}`)
            );
            image.title = data.raw.title;
            image.src = data.raw.src;
        });
    });
    return Promise.all(loading);
}

And:

async addNewImages(images) {
    images = this.$_.castArray(images);
    const data = await imagesFromUrl(images);
    this.images.push(...data);
}

Does not draw images at all, (data is an array of HTMLImageElements when logged)>
I also tried this with a stage.batchDraw() still nothing.

Problem with transform

Very nice Library !

Trying to convert following example to vuejs:
https://konvajs.github.io/docs/select_and_transform/Basic_demo.html

<template>
  <q-page padding >
     <v-stage @click="stageClick()" ref='stage' :config="configKonva">
       <v-layer ref='layer'>
<v-rect @click="rectClick($event)" ref='rect'  :config="configRect"></v-rect>
       </v-layer>
  </v-stage>
  </q-page>
</template>

<style>
</style>

<script>
export default {
  name: 'PageIndex',
  data () {
    return {
      configKonva: {
        width: 400,
        height: 400
      },
      configRect: {
        x: 0,
        y: 0,
        width: 100,
        name: 'rect',
        height: 50,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 1,
        draggable: true
      }
    }
  },
  methods:
  {
    stageClick (e) {
      let stage = this.$refs.stage.getStage()
      stage.find('Transformer').destroy()
      stage.draw()
    },
    rectClick (e) {
      let stage = this.$refs.stage.getStage()
      stage.find('Transformer').destroy()
      // create new transformer
      var tr = new window.Konva.Transformer()
      let layer = this.$refs.layer.getStage(tr)
      tr.attachTo(e.target) // no idea what to do here ...
      layer.draw()
    }
  }
}
</script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.