src_js/iconolab-bundle/src/components/editor/ShapeFree.vue
author ymh <ymh.work@gmail.com>
Thu, 16 Mar 2017 13:14:44 +0100
changeset 442 de38f6ddaff5
parent 437 0aa597a588c1
child 447 3ad8513b751a
permissions -rw-r--r--
Added tag 0.0.22 for changeset 1b9ce022efe9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     1
<template>
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
     2
    <svg>
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
     3
        <defs>
437
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
     4
            <path v-bind:id="annotationHref" ref="path" v-bind:d="path" class="path"></path>
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
     5
        </defs>
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
     6
        <g ref="g" filter="url(#shadow)">
437
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
     7
            <use v-bind:xlink:href="annotationSelector" v-bind:stroke-width="strokeWidth * 2" class="stroke-bg" />
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
     8
            <use v-bind:xlink:href="annotationSelector" v-bind:stroke-width="strokeWidth" class="stroke-fg" />
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
     9
            <circle ref="handlers"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    10
                v-for="(point, key) in points"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    11
                :key="key"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    12
                v-show="!readonly"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    13
                v-bind:data-key="key"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    14
                v-bind:cx="point.x"
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    15
                v-bind:cy="point.y"
437
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
    16
                v-bind:r="strokeWidth * 2"
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
    17
                v-bind:stroke-width="strokeWidth"
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    18
                v-bind:class="{ handler: true, 'handler--first': key === 0 &amp;&amp; !closed }"></circle>
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    19
        <g>
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    20
    </svg>
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    21
</template>
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    22
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    23
<script>
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    24
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    25
    import Snap from 'snapsvg'
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    26
    import tooltip from './mixins/tooltip'
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    27
    import save from './mixins/save'
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    28
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    29
    export default {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    30
        mixins: [ tooltip, save ],
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    31
        props: [
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    32
            'paper',
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    33
            'original-annotation',
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    34
            'original-path',
342
ebec1d59dc74 Disable resize & change drawing mode when readonly.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    35
            'readonly',
437
0aa597a588c1 Pass strokeWidth as prop.
Alexandre Segura <mex.zktk@gmail.com>
parents: 425
diff changeset
    36
            'stroke-width',
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    37
        ],
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    38
        data() {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    39
            return {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    40
                path: '',
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    41
                closed: false,
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    42
                points: [],
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    43
            }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    44
        },
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    45
        computed: {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    46
            annotationHref: function() {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    47
                if (this.originalAnnotation) {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    48
                    return 'annotation-path-' + this.originalAnnotation.annotation_guid;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    49
                } else {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    50
                    return 'annotation-path-new';
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    51
                }
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    52
            },
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    53
            annotationSelector: function() {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    54
                return '#' + this.annotationHref;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    55
            }
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    56
        },
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    57
        mounted() {
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
    58
            if (this.originalPath) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
    59
                this.fromSVGPath(this.originalPath, false);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
    60
                var g = new Snap(this.$refs.g);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
    61
                g.click(() => this.$emit('click'));
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
    62
            }
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    63
        },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    64
        watch: {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    65
            closed: function(closed) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    66
                if (closed) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    67
                    this.path += ' Z';
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    68
                }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    69
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    70
            // Redraw the path when the points have changed
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    71
            points: function(points) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    72
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    73
                var path = "M";
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    74
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    75
                if (points.length <= 1) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    76
                    return;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    77
                }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    78
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    79
                path += points[0].x + ',' + points[0].y;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    80
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    81
                for (var i = 0; i < points.length; i++) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    82
                    if (i == 0) continue;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    83
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    84
                    var pointInfos = points[i];
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    85
                    var lPath = "L" + pointInfos.x + "," + pointInfos.y;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    86
                    path += " " + lPath;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    87
                }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    88
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    89
                if (this.closed) { path += ' Z'; }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    90
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    91
                this.path = path;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    92
            }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    93
        },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    94
        methods: {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    95
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    96
            addPoint: function(x, y) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    97
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    98
                this.points.push({ x: x, y: y });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    99
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   100
                // Attach events to last point once DOM has been refreshed
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   101
                // @link https://vuejs.org/v2/guide/reactivity.html
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   102
                this.$nextTick(() => {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   103
                    var handler = this.$refs.handlers[this.$refs.handlers.length - 1];
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   104
                    this.addResizeHandler(handler);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   105
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   106
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   107
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   108
            clear: function() {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   109
                this.destroyTooltip();
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   110
                Object.assign(this, {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   111
                    points: [],
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   112
                    closed: false,
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   113
                    path: ''
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   114
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   115
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   116
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   117
            getTooltipTarget: function() {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   118
                return this.$refs.path;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   119
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   120
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   121
            fromSVGPath: function(pathString, tooltip) {
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   122
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   123
                var segments = Snap.parsePathString(pathString);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   124
                var points = [];
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   125
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   126
                // Don't use this.addPoint to avoid
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   127
                // race condition when registering events
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   128
                segments.map((segment) => {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   129
                    if (segment[0] !== 'Z') {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   130
                        points.push({ x: segment[1], y: segment[2] });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   131
                    }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   132
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   133
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   134
                this.points = points;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   135
                this.closed = true;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   136
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   137
                this.$nextTick(() => {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   138
                    this.addResizeHandlers();
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   139
                    if (tooltip) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   140
                        // FIXME Race condition with destroy
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   141
                        setTimeout(() => this.addTooltip(), 250);
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   142
                    }
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   143
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   144
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   145
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   146
            toSVGPath: function() {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   147
                return this.$parent.normalizePath(this.path) + ';FREE'
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   148
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   149
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   150
            addResizeHandler: function(handler) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   151
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   152
                var self = this;
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   153
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   154
                var circle = new Snap(handler);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   155
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   156
                var isDragged = false;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   157
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   158
                circle.click((e) => {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   159
                    var key = parseInt(circle.attr('data-key'), 10);
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   160
                    if (key === 0 && this.points.length > 2) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   161
                        this.closed = true;
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   162
                        this.$nextTick(() => {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   163
                            // FIXME Race condition with destroy
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   164
                            setTimeout(() => this.addTooltip(), 250);
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 320
diff changeset
   165
                        });
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   166
                    }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   167
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   168
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   169
                // Remove point on double click
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   170
                circle.dblclick((e) => {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   171
                    var circle = new Snap(e.target);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   172
                    var key = parseInt(circle.attr('data-key'), 10);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   173
                    this.points.splice(key, 1);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   174
                });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   175
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   176
                var dragEvents = {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   177
                    onMove: function(dx, dy, x, y, e) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   178
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   179
                        isDragged = true;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   180
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   181
                        var offset = self.$parent.computeOffset(e);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   182
                        this.attr({ cx: offset.x, cy: offset.y });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   183
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   184
                        var key = parseInt(this.attr('data-key'), 10);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   185
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   186
                        // Must use splice for reactivity to work
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   187
                        // @see https://vuejs.org/v2/guide/list.html#Mutation-Methods
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   188
                        self.points.splice(key, 1, { x: offset.x, y: offset.y });
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   189
                    },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   190
                    onStart: () => this.hideTooltip(),
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   191
                    onEnd: function(e) {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   192
                        if (!isDragged) { return; }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   193
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   194
                        isDragged = false;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   195
                        self.showTooltip();
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   196
                    }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   197
                }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   198
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   199
                circle.drag(dragEvents.onMove, dragEvents.onStart, dragEvents.onEnd);
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   200
            },
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   201
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   202
            addResizeHandlers: function() {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   203
                this.$refs.handlers.forEach((handler) => this.addResizeHandler(handler));
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   204
            }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   205
        }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   206
    }
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   207
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   208
</script>
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   209
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   210
<style scoped>
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   211
.handler {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   212
    fill: #fff;
342
ebec1d59dc74 Disable resize & change drawing mode when readonly.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
   213
    stroke: #000;
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   214
}
408
159042869b47 Introduce shadow effect on shapes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 342
diff changeset
   215
.path {
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   216
    stroke: inherit;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   217
    stroke-width: inherit;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   218
    fill: inherit;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   219
    transform: inherit;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   220
}
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   221
.stroke-fg {
408
159042869b47 Introduce shadow effect on shapes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 342
diff changeset
   222
    stroke: #000;
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
   223
    fill: transparent;
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
   224
}
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   225
.stroke-fg:hover {
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 408
diff changeset
   226
    cursor: pointer;
425
7bc5febc9933 Change hover color.
Alexandre Segura <mex.zktk@gmail.com>
parents: 420
diff changeset
   227
    fill: #c5f2ff;
7bc5febc9933 Change hover color.
Alexandre Segura <mex.zktk@gmail.com>
parents: 420
diff changeset
   228
    opacity: 0.25;
420
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   229
    stroke-opacity: 1;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   230
}
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   231
.stroke-bg {
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   232
    stroke: #fff;
0a4779c0e445 Use xlinks to display stroke.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   233
    fill: transparent;
408
159042869b47 Introduce shadow effect on shapes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 342
diff changeset
   234
}
320
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   235
.handler--first {
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   236
    fill: yellow;
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   237
}
81945eedc63f Introduce refactored components using Vue.js.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   238
</style>