svgjs-draw 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE +13 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/svgjs/draw.rb +8 -0
- data/lib/svgjs/draw/version.rb +5 -0
- data/svgjs-draw.gemspec +28 -0
- data/vendor/LICENSE +21 -0
- data/vendor/assets/javascripts/svg-draw.js +442 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9cdce64e25e6ca33a9c3e561ab6b2ffbaf2cf65c
|
4
|
+
data.tar.gz: 427e43ad7f3b2975a07d8e8bbf85325112389c2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cccd36733bda53f038361f919f2b6d73a13e569b6e4e34c002d5eedd83795c220fdd6776eb677fb0576b55604db705fba4491e25d1607c96d418557f893d6cdf
|
7
|
+
data.tar.gz: 77f9de474f3edcfe8c6703a08579ae3b9d7cb94ee4ede274220942895cd9d82edd8bfbdae48d09268cd91c7606b0aaf51f179b20112c3e6f87f427b906408f3c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2018, koparo.com <info@koparo.com>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Svgjs::Draw
|
2
|
+
|
3
|
+
An extension of svg.js which allows to draw elements with mouse
|
4
|
+
|
5
|
+
This gem bundles the upstream distribution for use with the Ruby on Rails framework. The version number of
|
6
|
+
the gem always tracks the upstream javascript release and the gem itself doesn't provide any additional
|
7
|
+
methods or helpers. If a need for helpers arises in the future they will be developed as a separate gem
|
8
|
+
with this one as its dependency. Should a gem bug be discovered an additional version identifier will be
|
9
|
+
appended and incremented after the upstream version number.
|
10
|
+
|
11
|
+
The gem is developed and tested against Rails 5
|
12
|
+
|
13
|
+
## License
|
14
|
+
svgjs-draw and changes made to svg.draw.js required for rails are licensed under ISC.
|
15
|
+
|
16
|
+
The original svg.draw.js code distributed with this gem is licensed under [MIT](https://tldrlegal.com/license/mit-license)
|
17
|
+
You can find the svg.draw.js license file in the vendor directory, changes made to the original code base are as follows:
|
18
|
+
|
19
|
+
* for consistency with other includes the following renames have been done
|
20
|
+
** `svg.draw.js` to `svg-draw.js`
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'svgjs-draw'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install svgjs-draw
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Add the following directive to your JavaScript manifest file (application.js):
|
41
|
+
|
42
|
+
//= require svg-draw
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/koparo/svgjs-draw.
|
data/Rakefile
ADDED
data/lib/svgjs/draw.rb
ADDED
data/svgjs-draw.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "svgjs/draw/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "svgjs-draw"
|
8
|
+
spec.version = Svgjs::Draw::VERSION
|
9
|
+
spec.authors = ["Adam Wolk"]
|
10
|
+
spec.email = ["adam.wolk@koparo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{svg.draw.js javascript bundle}
|
13
|
+
spec.description = %q{An extension of svg.js which allows to draw elements with mouse}
|
14
|
+
spec.homepage = "https://github.com/svgdotjs/svg.js"
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
|
27
|
+
spec.add_dependency "svgjs", "~> 2.6.4"
|
28
|
+
end
|
data/vendor/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Fuzzy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,442 @@
|
|
1
|
+
/*! svg.draw.js - v2.0.3 - 2017-06-19
|
2
|
+
* https://github.com/svgdotjs/svg.draw.js
|
3
|
+
* Copyright (c) 2017 Ulrich-Matthias Schäfer; Licensed MIT */
|
4
|
+
|
5
|
+
;(function () {
|
6
|
+
// Our Object which manages drawing
|
7
|
+
function PaintHandler(el, event, options) {
|
8
|
+
|
9
|
+
this.el = el;
|
10
|
+
el.remember('_paintHandler', this);
|
11
|
+
|
12
|
+
var _this = this,
|
13
|
+
plugin = this.getPlugin();
|
14
|
+
|
15
|
+
this.parent = el.parent(SVG.Nested) || el.parent(SVG.Doc);
|
16
|
+
this.p = this.parent.node.createSVGPoint(); // Helping point for coord transformation
|
17
|
+
this.m = null; // transformation matrix. We get it when drawing starts
|
18
|
+
this.startPoint = null;
|
19
|
+
this.lastUpdateCall = null;
|
20
|
+
this.options = {};
|
21
|
+
|
22
|
+
// Merge options and defaults
|
23
|
+
for (var i in this.el.draw.defaults) {
|
24
|
+
this.options[i] = this.el.draw.defaults[i];
|
25
|
+
if (typeof options[i] !== 'undefined') {
|
26
|
+
this.options[i] = options[i];
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
if(plugin.point) {
|
31
|
+
plugin['pointPlugin'] = plugin.point;
|
32
|
+
delete plugin.point;
|
33
|
+
}
|
34
|
+
|
35
|
+
// Import all methods from plugin into object
|
36
|
+
for (var i in plugin){
|
37
|
+
this[i] = plugin[i];
|
38
|
+
}
|
39
|
+
|
40
|
+
// When we got an event, we use this for start, otherwise we use the click-event as default
|
41
|
+
if (!event) {
|
42
|
+
this.parent.on('click.draw', function (e) {
|
43
|
+
_this.start(e);
|
44
|
+
});
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
}
|
49
|
+
|
50
|
+
PaintHandler.prototype.transformPoint = function(x, y){
|
51
|
+
|
52
|
+
this.p.x = x - (this.offset.x - window.pageXOffset);
|
53
|
+
this.p.y = y - (this.offset.y - window.pageYOffset);
|
54
|
+
|
55
|
+
return this.p.matrixTransform(this.m);
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
PaintHandler.prototype.start = function (event) {
|
60
|
+
|
61
|
+
var _this = this;
|
62
|
+
|
63
|
+
// get the current transform matrix from screen to element (offset corrected)
|
64
|
+
this.m = this.el.node.getScreenCTM().inverse();
|
65
|
+
|
66
|
+
// we save the current scrolling-offset here
|
67
|
+
this.offset = { x: window.pageXOffset, y: window.pageYOffset };
|
68
|
+
|
69
|
+
// we want to snap in screen-coords, so we have to scale the snapToGrid accordingly
|
70
|
+
this.options.snapToGrid *= Math.sqrt(this.m.a * this.m.a + this.m.b * this.m.b)
|
71
|
+
|
72
|
+
// save the startpoint
|
73
|
+
this.startPoint = this.snapToGrid(this.transformPoint(event.clientX, event.clientY));
|
74
|
+
|
75
|
+
// the plugin may do some initial work
|
76
|
+
if(this.init){ this.init(event); }
|
77
|
+
|
78
|
+
// Fire our `drawstart`-event. We send the offset-corrected cursor-position along
|
79
|
+
this.el.fire('drawstart', {event:event, p:this.p, m:this.m});
|
80
|
+
|
81
|
+
// We need to bind the update-function to the mousemove event to keep track of the cursor
|
82
|
+
SVG.on(window, 'mousemove.draw', function (e) {
|
83
|
+
_this.update(e);
|
84
|
+
});
|
85
|
+
|
86
|
+
// Every consecutive call to start should map to point now
|
87
|
+
this.start = this.point;
|
88
|
+
|
89
|
+
|
90
|
+
};
|
91
|
+
|
92
|
+
// This function draws a point if the element is a polyline or polygon
|
93
|
+
// Otherwise it will just stop drawing the shape cause we are done
|
94
|
+
PaintHandler.prototype.point = function (event) {
|
95
|
+
if (this.point != this.start) return this.start(event);
|
96
|
+
|
97
|
+
if (this.pointPlugin) {
|
98
|
+
return this.pointPlugin(event);
|
99
|
+
}
|
100
|
+
|
101
|
+
// If this function is not overwritten we just call stop
|
102
|
+
this.stop(event);
|
103
|
+
};
|
104
|
+
|
105
|
+
|
106
|
+
// The stop-function does the cleanup work
|
107
|
+
PaintHandler.prototype.stop = function (event) {
|
108
|
+
if (event) {
|
109
|
+
this.update(event);
|
110
|
+
}
|
111
|
+
|
112
|
+
// Plugin may want to clean something
|
113
|
+
if(this.clean){ this.clean(); }
|
114
|
+
|
115
|
+
// Unbind from all events
|
116
|
+
SVG.off(window, 'mousemove.draw');
|
117
|
+
this.parent.off('click.draw');
|
118
|
+
|
119
|
+
// remove Refernce to PaintHandler
|
120
|
+
this.el.forget('_paintHandler');
|
121
|
+
|
122
|
+
// overwrite draw-function since we never need it again for this element
|
123
|
+
this.el.draw = function () {
|
124
|
+
};
|
125
|
+
|
126
|
+
// Fire the `drawstop`-event
|
127
|
+
this.el.fire('drawstop');
|
128
|
+
};
|
129
|
+
|
130
|
+
// Updates the element while moving the cursor
|
131
|
+
PaintHandler.prototype.update = function (event) {
|
132
|
+
|
133
|
+
if(!event && this.lastUpdateCall){
|
134
|
+
event = this.lastUpdateCall;
|
135
|
+
}
|
136
|
+
|
137
|
+
this.lastUpdateCall = event;
|
138
|
+
|
139
|
+
// Call the calc-function which calculates the new position and size
|
140
|
+
this.calc(event);
|
141
|
+
|
142
|
+
// Fire the `drawupdate`-event
|
143
|
+
this.el.fire('drawupdate', {event:event, p:this.p, m:this.m});
|
144
|
+
};
|
145
|
+
|
146
|
+
// Called from outside. Finishs a poly-element
|
147
|
+
PaintHandler.prototype.done = function () {
|
148
|
+
this.calc();
|
149
|
+
this.stop();
|
150
|
+
|
151
|
+
this.el.fire('drawdone');
|
152
|
+
};
|
153
|
+
|
154
|
+
// Called from outside. Cancels a poly-element
|
155
|
+
PaintHandler.prototype.cancel = function () {
|
156
|
+
// stop drawing and remove the element
|
157
|
+
this.stop();
|
158
|
+
this.el.remove();
|
159
|
+
|
160
|
+
this.el.fire('drawcancel');
|
161
|
+
};
|
162
|
+
|
163
|
+
// Calculate the corrected position when using `snapToGrid`
|
164
|
+
PaintHandler.prototype.snapToGrid = function (draw) {
|
165
|
+
|
166
|
+
var temp = null;
|
167
|
+
|
168
|
+
// An array was given. Loop through every element
|
169
|
+
if (draw.length) {
|
170
|
+
temp = [draw[0] % this.options.snapToGrid, draw[1] % this.options.snapToGrid];
|
171
|
+
draw[0] -= temp[0] < this.options.snapToGrid / 2 ? temp[0] : temp[0] - this.options.snapToGrid;
|
172
|
+
draw[1] -= temp[1] < this.options.snapToGrid / 2 ? temp[1] : temp[1] - this.options.snapToGrid;
|
173
|
+
return draw;
|
174
|
+
}
|
175
|
+
|
176
|
+
// Properties of element were given. Snap them all
|
177
|
+
for (var i in draw) {
|
178
|
+
temp = draw[i] % this.options.snapToGrid;
|
179
|
+
draw[i] -= (temp < this.options.snapToGrid / 2 ? temp : temp - this.options.snapToGrid) + (temp < 0 ? this.options.snapToGrid : 0);
|
180
|
+
}
|
181
|
+
|
182
|
+
return draw;
|
183
|
+
};
|
184
|
+
|
185
|
+
PaintHandler.prototype.param = function (key, value) {
|
186
|
+
this.options[key] = value === null ? this.el.draw.defaults[key] : value;
|
187
|
+
this.update();
|
188
|
+
};
|
189
|
+
|
190
|
+
// Returns the plugin
|
191
|
+
PaintHandler.prototype.getPlugin = function () {
|
192
|
+
return this.el.draw.plugins[this.el.type];
|
193
|
+
};
|
194
|
+
|
195
|
+
SVG.extend(SVG.Element, {
|
196
|
+
// Draw element with mouse
|
197
|
+
draw: function (event, options, value) {
|
198
|
+
|
199
|
+
// sort the parameters
|
200
|
+
if (!(event instanceof Event || typeof event === 'string')) {
|
201
|
+
options = event;
|
202
|
+
event = null;
|
203
|
+
}
|
204
|
+
|
205
|
+
// get the old Handler or create a new one from event and options
|
206
|
+
var paintHandler = this.remember('_paintHandler') || new PaintHandler(this, event, options || {});
|
207
|
+
|
208
|
+
// When we got an event we have to start/continue drawing
|
209
|
+
if (event instanceof Event) {
|
210
|
+
paintHandler['start'](event);
|
211
|
+
}
|
212
|
+
|
213
|
+
// if event is located in our PaintHandler we handle it as method
|
214
|
+
if (paintHandler[event]) {
|
215
|
+
paintHandler[event](options, value);
|
216
|
+
}
|
217
|
+
|
218
|
+
return this;
|
219
|
+
}
|
220
|
+
|
221
|
+
});
|
222
|
+
|
223
|
+
// Default values. Can be changed for the whole project if needed
|
224
|
+
SVG.Element.prototype.draw.defaults = {
|
225
|
+
snapToGrid: 1 // Snaps to a grid of `snapToGrid` px
|
226
|
+
};
|
227
|
+
|
228
|
+
SVG.Element.prototype.draw.extend = function(name, obj){
|
229
|
+
|
230
|
+
var plugins = {};
|
231
|
+
if(typeof name === 'string'){
|
232
|
+
plugins[name] = obj;
|
233
|
+
}else{
|
234
|
+
plugins = name;
|
235
|
+
}
|
236
|
+
|
237
|
+
for(var shapes in plugins){
|
238
|
+
var shapesArr = shapes.trim().split(/\s+/);
|
239
|
+
|
240
|
+
for(var i in shapesArr){
|
241
|
+
SVG.Element.prototype.draw.plugins[shapesArr[i]] = plugins[shapes];
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
};
|
246
|
+
|
247
|
+
// Container for all types not specified here
|
248
|
+
SVG.Element.prototype.draw.plugins = {};
|
249
|
+
|
250
|
+
SVG.Element.prototype.draw.extend('rect image', {
|
251
|
+
|
252
|
+
init:function(e){
|
253
|
+
|
254
|
+
var p = this.startPoint;
|
255
|
+
|
256
|
+
this.el.attr({ x: p.x, y: p.y, height: 0, width: 0 });
|
257
|
+
},
|
258
|
+
|
259
|
+
calc:function (e) {
|
260
|
+
|
261
|
+
var rect = {
|
262
|
+
x: this.startPoint.x,
|
263
|
+
y: this.startPoint.y
|
264
|
+
}, p = this.transformPoint(e.clientX, e.clientY);
|
265
|
+
|
266
|
+
rect.width = p.x - rect.x;
|
267
|
+
rect.height = p.y - rect.y;
|
268
|
+
|
269
|
+
// Snap the params to the grid we specified
|
270
|
+
this.snapToGrid(rect);
|
271
|
+
|
272
|
+
// When width is less than zero, we have to draw to the left
|
273
|
+
// which means we have to move the start-point to the left
|
274
|
+
if (rect.width < 0) {
|
275
|
+
rect.x = rect.x + rect.width;
|
276
|
+
rect.width = -rect.width;
|
277
|
+
}
|
278
|
+
|
279
|
+
// ...same with height
|
280
|
+
if (rect.height < 0) {
|
281
|
+
rect.y = rect.y + rect.height;
|
282
|
+
rect.height = -rect.height;
|
283
|
+
}
|
284
|
+
|
285
|
+
// draw the element
|
286
|
+
this.el.attr(rect);
|
287
|
+
}
|
288
|
+
|
289
|
+
});
|
290
|
+
|
291
|
+
|
292
|
+
SVG.Element.prototype.draw.extend('line polyline polygon', {
|
293
|
+
|
294
|
+
init:function(e){
|
295
|
+
// When we draw a polygon, we immediately need 2 points.
|
296
|
+
// One start-point and one point at the mouse-position
|
297
|
+
|
298
|
+
this.set = new SVG.Set();
|
299
|
+
|
300
|
+
var p = this.startPoint,
|
301
|
+
arr = [
|
302
|
+
[p.x, p.y],
|
303
|
+
[p.x, p.y]
|
304
|
+
];
|
305
|
+
|
306
|
+
this.el.plot(arr);
|
307
|
+
|
308
|
+
// We draw little circles around each point
|
309
|
+
// This is absolutely not needed and maybe removed in a later release
|
310
|
+
this.drawCircles();
|
311
|
+
|
312
|
+
},
|
313
|
+
|
314
|
+
|
315
|
+
// The calc-function sets the position of the last point to the mouse-position (with offset ofc)
|
316
|
+
calc:function (e) {
|
317
|
+
var arr = this.el.array().valueOf();
|
318
|
+
arr.pop();
|
319
|
+
|
320
|
+
if (e) {
|
321
|
+
var p = this.transformPoint(e.clientX, e.clientY);
|
322
|
+
arr.push(this.snapToGrid([p.x, p.y]));
|
323
|
+
}
|
324
|
+
|
325
|
+
this.el.plot(arr);
|
326
|
+
|
327
|
+
},
|
328
|
+
|
329
|
+
point:function(e){
|
330
|
+
|
331
|
+
if (this.el.type.indexOf('poly') > -1) {
|
332
|
+
// Add the new Point to the point-array
|
333
|
+
var p = this.transformPoint(e.clientX, e.clientY),
|
334
|
+
arr = this.el.array().valueOf();
|
335
|
+
|
336
|
+
arr.push(this.snapToGrid([p.x, p.y]));
|
337
|
+
|
338
|
+
this.el.plot(arr);
|
339
|
+
this.drawCircles();
|
340
|
+
|
341
|
+
// Fire the `drawpoint`-event, which holds the coords of the new Point
|
342
|
+
this.el.fire('drawpoint', {event:e, p:{x:p.x, y:p.y}, m:this.m});
|
343
|
+
|
344
|
+
return;
|
345
|
+
}
|
346
|
+
|
347
|
+
// We are done, if the element is no polyline or polygon
|
348
|
+
this.stop(e);
|
349
|
+
|
350
|
+
},
|
351
|
+
|
352
|
+
clean:function(){
|
353
|
+
|
354
|
+
// Remove all circles
|
355
|
+
this.set.each(function () {
|
356
|
+
this.remove();
|
357
|
+
});
|
358
|
+
|
359
|
+
this.set.clear();
|
360
|
+
|
361
|
+
delete this.set;
|
362
|
+
|
363
|
+
},
|
364
|
+
|
365
|
+
drawCircles:function () {
|
366
|
+
var array = this.el.array().valueOf()
|
367
|
+
|
368
|
+
this.set.each(function () {
|
369
|
+
this.remove();
|
370
|
+
});
|
371
|
+
|
372
|
+
this.set.clear();
|
373
|
+
|
374
|
+
for (var i = 0; i < array.length; ++i) {
|
375
|
+
|
376
|
+
this.p.x = array[i][0]
|
377
|
+
this.p.y = array[i][1]
|
378
|
+
|
379
|
+
var p = this.p.matrixTransform(this.parent.node.getScreenCTM().inverse().multiply(this.el.node.getScreenCTM()));
|
380
|
+
|
381
|
+
this.set.add(this.parent.circle(5).stroke({width: 1}).fill('#ccc').center(p.x, p.y));
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
});
|
386
|
+
|
387
|
+
SVG.Element.prototype.draw.extend('circle', {
|
388
|
+
|
389
|
+
init:function(e){
|
390
|
+
|
391
|
+
var p = this.startPoint;
|
392
|
+
|
393
|
+
this.el.attr({ cx: p.x, cy: p.y, r: 1 });
|
394
|
+
},
|
395
|
+
|
396
|
+
// We determine the radius by the cursor position
|
397
|
+
calc:function (e) {
|
398
|
+
|
399
|
+
var p = this.transformPoint(e.clientX, e.clientY),
|
400
|
+
circle = {
|
401
|
+
cx: this.startPoint.x,
|
402
|
+
cy: this.startPoint.y,
|
403
|
+
|
404
|
+
// calculating the radius
|
405
|
+
r: Math.sqrt(
|
406
|
+
(p.x - this.startPoint.x) * (p.x - this.startPoint.x) +
|
407
|
+
(p.y - this.startPoint.y) * (p.y - this.startPoint.y)
|
408
|
+
)
|
409
|
+
};
|
410
|
+
|
411
|
+
this.snapToGrid(circle);
|
412
|
+
this.el.attr(circle);
|
413
|
+
}
|
414
|
+
|
415
|
+
});
|
416
|
+
|
417
|
+
SVG.Element.prototype.draw.extend('ellipse', {
|
418
|
+
|
419
|
+
init:function(e){
|
420
|
+
// We start with a circle with radius 1 at the position of the cursor
|
421
|
+
var p = this.startPoint;
|
422
|
+
|
423
|
+
this.el.attr({ cx: p.x, cy: p.y, rx: 1, ry: 1 });
|
424
|
+
|
425
|
+
},
|
426
|
+
|
427
|
+
calc:function (e) {
|
428
|
+
var p = this.transformPoint(e.clientX, e.clientY);
|
429
|
+
|
430
|
+
var ellipse = {
|
431
|
+
cx: this.startPoint.x,
|
432
|
+
cy: this.startPoint.y,
|
433
|
+
rx: Math.abs(p.x - this.startPoint.x),
|
434
|
+
ry: Math.abs(p.y - this.startPoint.y)
|
435
|
+
};
|
436
|
+
|
437
|
+
this.snapToGrid(ellipse);
|
438
|
+
this.el.attr(ellipse);
|
439
|
+
}
|
440
|
+
|
441
|
+
});
|
442
|
+
}).call(this);
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svgjs-draw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Wolk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: svgjs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.4
|
55
|
+
description: An extension of svg.js which allows to draw elements with mouse
|
56
|
+
email:
|
57
|
+
- adam.wolk@koparo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/svgjs/draw.rb
|
68
|
+
- lib/svgjs/draw/version.rb
|
69
|
+
- svgjs-draw.gemspec
|
70
|
+
- vendor/LICENSE
|
71
|
+
- vendor/assets/javascripts/svg-draw.js
|
72
|
+
homepage: https://github.com/svgdotjs/svg.js
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.14.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: svg.draw.js javascript bundle
|
96
|
+
test_files: []
|