flammarion 0.1.7 → 0.1.8pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Readme.md CHANGED
@@ -185,4 +185,4 @@ They are:
185
185
  * [leaflet](http://leafletjs.com/)
186
186
  * [font awesome](https://fortawesome.github.io/Font-Awesome/)
187
187
  * [emojione](http://emojione.com/)
188
- * [Plotly](htps://plot.ly/)
188
+ * [Plotly](https://plot.ly/)
@@ -1,3 +1,3 @@
1
1
  module Flammarion
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8pre"
3
3
  end
@@ -52,12 +52,25 @@ module Flammarion
52
52
  def plot(data, options = {})
53
53
  if data.respond_to?(:keys)
54
54
  options = options.merge(data)
55
+ if data.include?(:xy) then
56
+ data = data.clone
57
+ data[:x] = data[:xy].map(&:first)
58
+ data[:y] = data[:xy].map(&:last)
59
+ data.delete(:xy)
60
+ end
55
61
  data = [data]
56
62
  elsif not data.first.respond_to?(:keys)
57
63
  data = [{y:data, x:(1..data.size).to_a}.merge(options)]
58
64
  end
59
65
  @engraving.send_json({action:'plot', id:@id, target:@target, data:data}.merge(options))
60
66
  end
67
+
68
+ def to_svg
69
+ svg = nil
70
+ @engraving.script(%|$('#plot-i9').find('svg')[0].outerHTML|, coffee:false) {|r| svg = r['result'] || "Error"}
71
+ sleep(0.1) while svg.nil?
72
+ return svg
73
+ end
61
74
  end
62
75
 
63
76
  # @!macro [new] escape_options
@@ -138,13 +151,13 @@ module Flammarion
138
151
  # @example
139
152
  # f.plot(100.times.map{rand}, mode: 'markers')
140
153
  # @overload plot(dataset, options = {})
141
- # @param [Hash] A hash representing a Plotly dataset
154
+ # @param [Hash] A hash representing a Plotly trace
142
155
  # @example
143
156
  # f.plot(x: (1..314).to_a.map{|x| Math.sin(x.to_f / 20.0)}, y:(1..314).to_a.map{|x| Math.sin(x.to_f / 10)}, replace:true)
144
157
  # @example
145
158
  # f.plot(x: [Time.now, Time.now + 24*60*60].map(&:to_s), y: [55, 38], type:'bar', replace:true)
146
159
  # @overload plot(datasets, options = {})
147
- # @param [Array<Hash>] An array of Plotly datasets
160
+ # @param [Array<Hash>] An array of Plotly traces
148
161
  # @example
149
162
  # f.plot(5.times.map{|t| {y: 100.times.map{rand * t}}})f.plot(5.times.map{|t| {y: 100.times.map{rand * t}}})
150
163
  def plot(data, options = {})
@@ -317,9 +330,18 @@ module Flammarion
317
330
  # the options given. Defaults to CoffeeScript
318
331
  # @option options [Boolean] :coffee (true) If true, will compile +text+ from
319
332
  # CoffeeScript to JavaScript. If false, will pass text as plain JavaScript
320
- def script(text, options = {})
333
+ def script(text, options = {}, &block)
321
334
  data = options.fetch(:coffee, true) ? CoffeeScript.compile(text) : text
322
- send_json({action:'script', data:data}.merge(options))
335
+ id = @engraving.make_id
336
+ d = nil
337
+ if block_given?
338
+ @engraving.callbacks[id] = block
339
+ else
340
+ d = DeferredValue.new
341
+ @engraving.callbacks[id] = Proc.new {|v| d.__setobj__(v["result"])}
342
+ end
343
+ send_json({action:'script', data:data, id: id}.merge(options))
344
+ return d
323
345
  end
324
346
 
325
347
  # Sets CSS styles attributes on the current pane.
@@ -382,7 +382,15 @@ return"undefined"!=typeof b&&""!==b&&b in a.jsEscapeMap?(d=a.jsEscapeMap[b],e=a.
382
382
  return $("body").html(data.data);
383
383
  },
384
384
  script: function(data) {
385
- return eval(data.data);
385
+ var r;
386
+ r = eval(data.data);
387
+ return this.__parent.send({
388
+ id: data.id,
389
+ action: 'callback',
390
+ source: 'script',
391
+ original_msg: data,
392
+ result: r
393
+ });
386
394
  },
387
395
  style: function(data) {
388
396
  var target;
@@ -7048,7 +7048,15 @@ window.font_awesome_list = ["glass","music","search","envelope-o","heart","star"
7048
7048
  return $("body").html(data.data);
7049
7049
  },
7050
7050
  script: function(data) {
7051
- return eval(data.data);
7051
+ var r;
7052
+ r = eval(data.data);
7053
+ return this.__parent.send({
7054
+ id: data.id,
7055
+ action: 'callback',
7056
+ source: 'script',
7057
+ original_msg: data,
7058
+ result: r
7059
+ });
7052
7060
  },
7053
7061
  style: function(data) {
7054
7062
  var target;
@@ -108,7 +108,14 @@ $.extend WSClient.prototype.actions,
108
108
  $("body").html(data.data)
109
109
 
110
110
  script: (data) ->
111
- eval(data.data)
111
+ r = eval(data.data)
112
+ @__parent.send({
113
+ id:data.id
114
+ action:'callback'
115
+ source:'script'
116
+ original_msg:data
117
+ result: r
118
+ })
112
119
 
113
120
  style: (data) ->
114
121
  target = @__parent.check_target(data)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flammarion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
5
- prerelease:
4
+ version: 0.1.8pre
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zach Capalbo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-06 00:00:00.000000000 Z
12
+ date: 2016-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubame
@@ -3847,9 +3847,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
3847
3847
  required_rubygems_version: !ruby/object:Gem::Requirement
3848
3848
  none: false
3849
3849
  requirements:
3850
- - - ! '>='
3850
+ - - ! '>'
3851
3851
  - !ruby/object:Gem::Version
3852
- version: '0'
3852
+ version: 1.3.1
3853
3853
  requirements: []
3854
3854
  rubyforge_project:
3855
3855
  rubygems_version: 1.8.23