forked from ~ulysseskao/xdashangular

Dennis Kao
2016-04-25 4b0f4c0e8a08411990dbc5391142bc48fdd858aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*! JointJS v0.9.7 - JavaScript diagramming library  2016-04-20 
 
 
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
//      JointJS library.
//      (c) 2011-2013 client IO
 
joint.shapes.pn = {};
 
joint.shapes.pn.Place = joint.shapes.basic.Generic.extend({
 
    markup: '<g class="rotatable"><g class="scalable"><circle class="root"/><g class="tokens" /></g><text class="label"/></g>',
 
    defaults: joint.util.deepSupplement({
 
        type: 'pn.Place',
        size: { width: 50, height: 50 },
        attrs: {
            '.root': {
                r: 25,
                fill: '#ffffff',
                stroke: '#000000',
                transform: 'translate(25, 25)'
            },
            '.label': {
                'text-anchor': 'middle',
                'ref-x': .5,
                'ref-y': -20,
                ref: '.root',
                fill: '#000000',
                'font-size': 12
            },
            '.tokens > circle': {
                fill: '#000000',
                r: 5
            },
            '.tokens.one > circle': { transform: 'translate(25, 25)' },
 
            '.tokens.two > circle:nth-child(1)': { transform: 'translate(19, 25)' },
            '.tokens.two > circle:nth-child(2)': { transform: 'translate(31, 25)' },
 
            '.tokens.three > circle:nth-child(1)': { transform: 'translate(18, 29)' },
            '.tokens.three > circle:nth-child(2)': { transform: 'translate(25, 19)' },
            '.tokens.three > circle:nth-child(3)': { transform: 'translate(32, 29)' },
 
            '.tokens.alot > text': {
                transform: 'translate(25, 18)',
                'text-anchor': 'middle',
                fill: '#000000'
            }
        }
 
    }, joint.shapes.basic.Generic.prototype.defaults)
});
 
 
joint.shapes.pn.PlaceView = joint.dia.ElementView.extend({
 
    initialize: function() {
 
        joint.dia.ElementView.prototype.initialize.apply(this, arguments);
 
        this.model.on('change:tokens', function() {
 
            this.renderTokens();
            this.update();
 
        }, this);
    },
 
    render: function() {
 
        joint.dia.ElementView.prototype.render.apply(this, arguments);
 
        this.renderTokens();
        this.update();
    },
 
    renderTokens: function() {
 
        var $tokens = this.$('.tokens').empty();
        $tokens[0].className.baseVal = 'tokens';
 
        var tokens = this.model.get('tokens');
 
        if (!tokens) return;
 
        switch (tokens) {
 
            case 1:
                $tokens[0].className.baseVal += ' one';
                $tokens.append(V('<circle/>').node);
                break;
 
            case 2:
                $tokens[0].className.baseVal += ' two';
                $tokens.append(V('<circle/>').node, V('<circle/>').node);
                break;
 
            case 3:
                $tokens[0].className.baseVal += ' three';
                $tokens.append(V('<circle/>').node, V('<circle/>').node, V('<circle/>').node);
                break;
 
            default:
                $tokens[0].className.baseVal += ' alot';
                $tokens.append(V('<text/>').text(tokens + '' ).node);
                break;
        }
    }
});
 
 
joint.shapes.pn.Transition = joint.shapes.basic.Generic.extend({
 
    markup: '<g class="rotatable"><g class="scalable"><rect class="root"/></g></g><text class="label"/>',
 
    defaults: joint.util.deepSupplement({
 
        type: 'pn.Transition',
        size: { width: 12, height: 50 },
        attrs: {
            'rect': {
                width: 12,
                height: 50,
                fill: '#000000',
                stroke: '#000000'
            },
            '.label': {
                'text-anchor': 'middle',
                'ref-x': .5,
                'ref-y': -20,
                ref: 'rect',
                fill: '#000000',
                'font-size': 12
            }
        }
 
    }, joint.shapes.basic.Generic.prototype.defaults)
});
 
joint.shapes.pn.Link = joint.dia.Link.extend({
 
    defaults: joint.util.deepSupplement({
 
        type: 'pn.Link',
        attrs: { '.marker-target': { d: 'M 10 0 L 0 5 L 10 10 z' }}
 
    }, joint.dia.Link.prototype.defaults)
});