flammarion 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
data/lib/flammarion/plot.rb
CHANGED
@@ -69,5 +69,49 @@ module Flammarion
|
|
69
69
|
def layout(options)
|
70
70
|
@engraving.send_json({action:'plot', id:@id, target: @target, layout: options})
|
71
71
|
end
|
72
|
+
|
73
|
+
# Saves the plot as a static image. +block+ will be called with a hash
|
74
|
+
# argurment when the plot is finished being converted to an image
|
75
|
+
def save(options = {}, &block)
|
76
|
+
id = @engraving.make_id
|
77
|
+
@engraving.callbacks[id] = block
|
78
|
+
@engraving.send_json({action:'savePlot', id:@id, target:@target, callback_id: id, format: options})
|
79
|
+
end
|
80
|
+
|
81
|
+
# Converts the plot to a png image. If a block is given, it will be called
|
82
|
+
# with the png data. Otherwise this function will wait until the image has
|
83
|
+
# been created, and then return a string containing the png data
|
84
|
+
def to_png(options = {})
|
85
|
+
png = nil
|
86
|
+
save(options.merge({format: 'png'})) do |data|
|
87
|
+
d = data['data']
|
88
|
+
png = Base64.decode64(d[d.index(',') + 1..-1])
|
89
|
+
if block_given?
|
90
|
+
yield png
|
91
|
+
end
|
92
|
+
end
|
93
|
+
unless block_given?
|
94
|
+
sleep 0.1 while png.nil?
|
95
|
+
return png
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Converts the plot to an svg image. If a block is given, it will be called
|
100
|
+
# with the svg xml string. Otherwise this function will wait until the image has
|
101
|
+
# been created, and then return a string containing the svg xml string
|
102
|
+
def to_svg(options = {})
|
103
|
+
svg = nil
|
104
|
+
save(options.merge({format: 'svg'})) do |data|
|
105
|
+
d = data['data']
|
106
|
+
svg = URI.unescape(d[d.index(',') + 1 .. -1])
|
107
|
+
if block_given?
|
108
|
+
yield svg
|
109
|
+
end
|
110
|
+
end
|
111
|
+
unless block_given?
|
112
|
+
sleep 0.1 while svg.nil?
|
113
|
+
return svg
|
114
|
+
end
|
115
|
+
end
|
72
116
|
end
|
73
117
|
end
|
data/lib/flammarion/version.rb
CHANGED
data/lib/flammarion/writeable.rb
CHANGED
@@ -290,6 +290,7 @@ module Flammarion
|
|
290
290
|
# @option options [Boolean] :coffee (true) If true, will compile +text+ from
|
291
291
|
# CoffeeScript to JavaScript. If false, will pass text as plain JavaScript
|
292
292
|
def script(text, options = {}, &block)
|
293
|
+
return script_src(text) if !options.fetch(:no_file, false) && File.exist?(text)
|
293
294
|
data = options.fetch(:coffee, true) ? CoffeeScript.compile(text) : text
|
294
295
|
id = @engraving.make_id
|
295
296
|
d = nil
|
@@ -307,6 +308,14 @@ module Flammarion
|
|
307
308
|
script(text, options.merge(coffee:false), &block)
|
308
309
|
end
|
309
310
|
|
311
|
+
def script_src(src)
|
312
|
+
if File.exist?(src) then
|
313
|
+
html("<script>#{File.read(src)}</script>")
|
314
|
+
else
|
315
|
+
html("<script src='#{src}'></src>")
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
310
319
|
# Sets CSS styles attributes on the current pane.
|
311
320
|
# @overload style(attribute, value)
|
312
321
|
# @param attribute [String] The css attribute to set. Currently does not
|
@@ -7975,6 +7975,23 @@ window.font_awesome_list = ["glass","music","search","envelope-o","heart","star"
|
|
7975
7975
|
return Plotly.relayout(plotDiv[0], data);
|
7976
7976
|
}
|
7977
7977
|
}
|
7978
|
+
},
|
7979
|
+
savePlot: function(data) {
|
7980
|
+
var plotDiv, target;
|
7981
|
+
target = this.__parent.check_target(data);
|
7982
|
+
this.__plots || (this.__plots = {});
|
7983
|
+
plotDiv = target.find("#plot-" + data.id)[0];
|
7984
|
+
return Plotly.toImage(plotDiv, data.format).then((function(_this) {
|
7985
|
+
return function(imgData) {
|
7986
|
+
return _this.__parent.send({
|
7987
|
+
id: data.callback_id,
|
7988
|
+
action: 'callback',
|
7989
|
+
source: 'plot',
|
7990
|
+
data: imgData,
|
7991
|
+
original_msg: data
|
7992
|
+
});
|
7993
|
+
};
|
7994
|
+
})(this));
|
7978
7995
|
}
|
7979
7996
|
});
|
7980
7997
|
|
@@ -57,6 +57,23 @@
|
|
57
57
|
return Plotly.relayout(plotDiv[0], data);
|
58
58
|
}
|
59
59
|
}
|
60
|
+
},
|
61
|
+
savePlot: function(data) {
|
62
|
+
var plotDiv, target;
|
63
|
+
target = this.__parent.check_target(data);
|
64
|
+
this.__plots || (this.__plots = {});
|
65
|
+
plotDiv = target.find("#plot-" + data.id)[0];
|
66
|
+
return Plotly.toImage(plotDiv, data.format).then((function(_this) {
|
67
|
+
return function(imgData) {
|
68
|
+
return _this.__parent.send({
|
69
|
+
id: data.callback_id,
|
70
|
+
action: 'callback',
|
71
|
+
source: 'plot',
|
72
|
+
data: imgData,
|
73
|
+
original_msg: data
|
74
|
+
});
|
75
|
+
};
|
76
|
+
})(this));
|
60
77
|
}
|
61
78
|
});
|
62
79
|
|
@@ -36,3 +36,15 @@ $.extend WSClient.prototype.actions,
|
|
36
36
|
plotDiv[0].data = data.data
|
37
37
|
Plotly.redraw(plotDiv[0])
|
38
38
|
Plotly.relayout(plotDiv[0], data) if data.layout
|
39
|
+
savePlot: (data) ->
|
40
|
+
target = @__parent.check_target(data)
|
41
|
+
@__plots ||= {}
|
42
|
+
plotDiv = target.find("#plot-#{data.id}")[0]
|
43
|
+
Plotly.toImage(plotDiv, data.format).then (imgData) =>
|
44
|
+
@__parent.send({
|
45
|
+
id:data.callback_id
|
46
|
+
action:'callback'
|
47
|
+
source:'plot'
|
48
|
+
data: imgData
|
49
|
+
original_msg:data
|
50
|
+
})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flammarion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubame
|