nyaplot 0.1.6 → 0.2.0.rc1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +4 -3
- data/examples/notebook/3DPlot.ipynb +398 -455
- data/examples/notebook/Interaction_with_DataFrame.ipynb +572 -650
- data/examples/notebook/Introduction.ipynb +452 -525
- data/examples/notebook/Mapnya.ipynb +441 -212
- data/examples/notebook/Nyaplotv2.ipynb +307 -0
- data/lib/nyaplot.rb +7 -3
- data/lib/nyaplot/base.rb +80 -46
- data/lib/nyaplot/core.rb +45 -5
- data/lib/nyaplot/data.rb +220 -172
- data/lib/nyaplot/glyph.rb +227 -0
- data/lib/nyaplot/interactive.rb +94 -0
- data/lib/nyaplot/pane.rb +43 -0
- data/lib/nyaplot/plot.rb +173 -124
- data/lib/nyaplot/position.rb +7 -0
- data/lib/nyaplot/scale.rb +19 -0
- data/lib/nyaplot/sheet.rb +83 -0
- data/lib/nyaplot/simple/stage.rb +29 -0
- data/lib/nyaplot/stage2d.rb +56 -0
- data/lib/nyaplot/templates/init.js.erb +1 -1
- data/lib/nyaplot/templates/init_interactive.js +77 -0
- data/lib/nyaplot/templates/iruby.erb +2 -9
- data/lib/nyaplot/version.rb +1 -1
- data/lib/nyaplot3d/core.rb +1 -1
- data/nyaplot.gemspec +1 -26
- metadata +29 -10
- data/lib/mapnya/datasets/geo-boundaries-world-110m/README.md +0 -3
- data/lib/mapnya/datasets/geo-boundaries-world-110m/countries.geojson +0 -360
- data/lib/mapnya/datasets/geo-boundaries-world-110m/datapackage.json +0 -35
- data/lib/nyaplot/database.rb +0 -22
- data/lib/nyaplot/diagram.rb +0 -341
- data/lib/nyaplot/frame.rb +0 -70
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
class RowScale
|
3
|
+
include Nyaplot::Base
|
4
|
+
type :row_scale
|
5
|
+
required_args :scale, :column
|
6
|
+
end
|
7
|
+
|
8
|
+
class DataFrameScale
|
9
|
+
include Nyaplot::Base
|
10
|
+
type :df_scale
|
11
|
+
required_args :data, :column, :range
|
12
|
+
end
|
13
|
+
|
14
|
+
class Scale
|
15
|
+
include Nyaplot::Base
|
16
|
+
type :scale
|
17
|
+
required_args :domain, :range, :type
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
module Sheet
|
3
|
+
# Root class for glyphs
|
4
|
+
class Context
|
5
|
+
include Nyaplot::Base
|
6
|
+
type :context2d
|
7
|
+
required_args :glyphs
|
8
|
+
optional_args :width, :height
|
9
|
+
|
10
|
+
def add_glyph(*glyph)
|
11
|
+
glyphs([]) if glyphs.nil?
|
12
|
+
|
13
|
+
glyph.each{|g|
|
14
|
+
glyph.push(g.child) if g.respond_to? :child
|
15
|
+
}
|
16
|
+
|
17
|
+
glyphs.concat(glyph)
|
18
|
+
add_dependency(*glyph)
|
19
|
+
|
20
|
+
class << glyphs
|
21
|
+
def to_json(*args)
|
22
|
+
self.map{|obj| obj.uuid}.to_json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def range(method_name)
|
28
|
+
glyphs.reduce([Float::INFINITY, -Float::INFINITY]) do |memo, g|
|
29
|
+
if (r = g.send(method_name)).length != 2 || r.any? {|val| !(val.is_a?(Numeric))}
|
30
|
+
memo.delete(Float::INFINITY)
|
31
|
+
memo.delete(-Float::INFINITY)
|
32
|
+
memo.concat(r.to_a).uniq
|
33
|
+
else
|
34
|
+
min, max = r
|
35
|
+
memo[0] = [min, memo[0]].min
|
36
|
+
memo[1] = [max, memo[1]].max
|
37
|
+
memo
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def xscale(range)
|
43
|
+
r = range(:range_x)
|
44
|
+
s = Scale.new(domain: r, range: range)
|
45
|
+
s.type(r.all? {|v| v.is_a? Numeric} ? :linear : :ordinal)
|
46
|
+
s
|
47
|
+
end
|
48
|
+
|
49
|
+
def yscale(range)
|
50
|
+
r = range(:range_y)
|
51
|
+
s = Scale.new(domain: r, range: range)
|
52
|
+
s.type(r.all? {|v| v.is_a? Numeric} ? :linear : :ordinal)
|
53
|
+
s
|
54
|
+
end
|
55
|
+
|
56
|
+
def position(pos)
|
57
|
+
@dependency.each do |g|
|
58
|
+
g.position(pos)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
alias :add :add_glyph
|
63
|
+
end
|
64
|
+
|
65
|
+
class Axis
|
66
|
+
include Nyaplot::Base
|
67
|
+
type :axis2d
|
68
|
+
required_args :xscale, :yscale, :width, :height
|
69
|
+
optional_args :margin, :stroke_color, :stroke_width, :grid
|
70
|
+
|
71
|
+
def before_to_json
|
72
|
+
raise "width and height should be specified" if [width, height].any? {|a| a.nil?}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Background
|
77
|
+
include Nyaplot::Base
|
78
|
+
type :background2d
|
79
|
+
required_args :width, :height
|
80
|
+
optional_args :bg_color, :stroke_width, :stroke_color
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
module Simple
|
3
|
+
class DefaultStage < Stage2D
|
4
|
+
def initialize(width=500, height=500)
|
5
|
+
@width = width; @height = height
|
6
|
+
@background = Nyaplot::Sheet::Background.new
|
7
|
+
@context = Nyaplot::Sheet::Context.new
|
8
|
+
@axis = Nyaplot::Sheet::Axis.new
|
9
|
+
super(background, context, axis)
|
10
|
+
end
|
11
|
+
|
12
|
+
def adjust_size
|
13
|
+
[@background, @context, @axis].each do |sheet|
|
14
|
+
sheet.width
|
15
|
+
sheet.height
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def adjust_margin
|
20
|
+
end
|
21
|
+
|
22
|
+
def before_to_json
|
23
|
+
|
24
|
+
adjust_size
|
25
|
+
adjust_margin
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
# the wrapper class for stage2d of Nyaplotjs
|
3
|
+
# (https://github.com/domitry/Nyaplotjs/blob/v2/src/parser/stage2d.js)
|
4
|
+
#
|
5
|
+
class Stage2D
|
6
|
+
include Nyaplot::Base
|
7
|
+
type :stage2d
|
8
|
+
required_args :sheets
|
9
|
+
optional_args :margin, :width, :height
|
10
|
+
attr_accessor :background, :context, :axis
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super()
|
14
|
+
attr(width: 500, height: 400)
|
15
|
+
@background = Nyaplot::Sheet::Background.new
|
16
|
+
@context = Nyaplot::Sheet::Context.new
|
17
|
+
@axis = Nyaplot::Sheet::Axis.new
|
18
|
+
add_sheet(@background, @axis, @context)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_sheet(*given)
|
22
|
+
sheets([]) if sheets.nil?
|
23
|
+
sheets.concat(given.map{|obj| obj.uuid})
|
24
|
+
add_dependency(*given)
|
25
|
+
end
|
26
|
+
|
27
|
+
def adjust_size(width, height)
|
28
|
+
[[:width, width], [:height, height]].each do |val|
|
29
|
+
name, base = val
|
30
|
+
if @axis.send(name).nil?
|
31
|
+
@axis.send(name, (val = @background.send(name)).nil? ? base : val)
|
32
|
+
end
|
33
|
+
@background.send(name, @axis.send(name)) if @background.send(name).nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def adjust_margin
|
38
|
+
end
|
39
|
+
|
40
|
+
def resolve_dependency
|
41
|
+
child_width, child_height = [width*0.9, height*0.9]
|
42
|
+
|
43
|
+
adjust_size(child_width, child_height)
|
44
|
+
adjust_margin
|
45
|
+
|
46
|
+
x_pad, y_pad = [child_width*0.05, child_height*0.05]
|
47
|
+
xscale = @context.xscale([x_pad, child_width - x_pad])
|
48
|
+
yscale = @context.yscale([child_height - y_pad, y_pad])
|
49
|
+
|
50
|
+
pos = Position2D.new(x: xscale, y: yscale)
|
51
|
+
|
52
|
+
@context.position(pos)
|
53
|
+
@axis.xscale(xscale).yscale(yscale)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -20,7 +20,7 @@ end
|
|
20
20
|
|
21
21
|
var script = d3.select("head")
|
22
22
|
.append("script")
|
23
|
-
.attr("src", "http://
|
23
|
+
.attr("src", "http://rawgit.com/domitry/Nyaplotjs/v2/release/nyaplot.js")
|
24
24
|
.attr("async", true);
|
25
25
|
|
26
26
|
script[0][0].onload = script[0][0].onreadystatechange = function(){
|
@@ -0,0 +1,77 @@
|
|
1
|
+
(function(){
|
2
|
+
if(window.IPython !== undefined){
|
3
|
+
var comm_global = null;
|
4
|
+
|
5
|
+
var callback = function(uuid, ranges){
|
6
|
+
comm_global.send({
|
7
|
+
type: "selected",
|
8
|
+
stage_uuid: uuid,
|
9
|
+
range: ranges.x
|
10
|
+
});
|
11
|
+
};
|
12
|
+
|
13
|
+
window.Nyaplot.sheet_manager.register_sheet(
|
14
|
+
"interactive_layer",
|
15
|
+
["parent", "scalex", "scaley", "stage_uuid"],
|
16
|
+
{
|
17
|
+
opacity: 0.125,
|
18
|
+
color: 'gray'
|
19
|
+
},
|
20
|
+
function(parent, scalex, scaley, stage_uuid, options){
|
21
|
+
var brushed = function(){
|
22
|
+
var ranges = {
|
23
|
+
x: (brush.empty() ? scalex.domain() : brush.extent()),
|
24
|
+
y: scaley.domain()
|
25
|
+
};
|
26
|
+
callback(stage_uuid, ranges);
|
27
|
+
};
|
28
|
+
|
29
|
+
var brush = d3.svg.brush()
|
30
|
+
.x(scalex)
|
31
|
+
.on("brushend", brushed);
|
32
|
+
|
33
|
+
var model = parent.append("g");
|
34
|
+
console.log(scaley);
|
35
|
+
var height = d3.max(scaley.range()) - d3.min(scaley.range());
|
36
|
+
var y = d3.min(scaley.range());
|
37
|
+
|
38
|
+
parent.call(brush)
|
39
|
+
.selectAll("rect")
|
40
|
+
.attr("y", y)
|
41
|
+
.attr("height", height)
|
42
|
+
.style({
|
43
|
+
"fill-opacity": options.opacity,
|
44
|
+
"fill": options.color,
|
45
|
+
"shape-rendering": "crispEdges"
|
46
|
+
});
|
47
|
+
}
|
48
|
+
);
|
49
|
+
|
50
|
+
window.IPython.notebook.kernel.comm_manager.register_target("nyaplot_interactive", function(comm, msg){
|
51
|
+
comm.on_msg(function(msg_){
|
52
|
+
console.log("msg has come.", msg_);
|
53
|
+
var msg = msg_.content.data;
|
54
|
+
|
55
|
+
switch(msg.type){
|
56
|
+
case "hello":
|
57
|
+
comm_global = comm;
|
58
|
+
break;
|
59
|
+
case "update":
|
60
|
+
/*
|
61
|
+
msg: {
|
62
|
+
type: "update",
|
63
|
+
model: model
|
64
|
+
}
|
65
|
+
*/
|
66
|
+
console.log("update");
|
67
|
+
var model = JSON.parse(msg.model);
|
68
|
+
window.Nyaplot.core.parse(model);
|
69
|
+
break;
|
70
|
+
default:
|
71
|
+
console.log("error", msg);
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
});
|
75
|
+
});
|
76
|
+
}
|
77
|
+
})();
|
@@ -2,15 +2,8 @@
|
|
2
2
|
<script>
|
3
3
|
(function(){
|
4
4
|
var render = function(){
|
5
|
-
var model = <%= model
|
6
|
-
|
7
|
-
Nyaplot.core.parse(model, id_name);
|
8
|
-
|
9
|
-
require(['downloadable'], function(downloadable){
|
10
|
-
var svg = d3.select(id_name).select("svg");
|
11
|
-
if(!svg.empty())
|
12
|
-
svg.call(downloadable().filename('fig'));
|
13
|
-
});
|
5
|
+
var model = <%= model %>;
|
6
|
+
Nyaplot.core.parse(model);
|
14
7
|
};
|
15
8
|
if(window['Nyaplot']==undefined){
|
16
9
|
window.addEventListener('load_nyaplot', render, false);
|
data/lib/nyaplot/version.rb
CHANGED
data/lib/nyaplot3d/core.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nyaplot
|
2
2
|
add_extension("Elegans")
|
3
3
|
add_dependency("THREE","http://cdnjs.cloudflare.com/ajax/libs/three.js/r66/three.min")
|
4
|
-
add_dependency("Elegans","
|
4
|
+
add_dependency("Elegans","http://cdn.rawgit.com/domitry/elegans/nyaplot-extension/release/elegans")
|
5
5
|
init_iruby if defined? IRuby
|
6
6
|
end
|
data/nyaplot.gemspec
CHANGED
@@ -51,33 +51,8 @@ EOF
|
|
51
51
|
spec.required_ruby_version = ">= 2.0"
|
52
52
|
|
53
53
|
spec.add_development_dependency "bundler", "~> 1.5"
|
54
|
+
spec.add_runtime_dependency "mikon", "~> 0.1.2.rc1"
|
54
55
|
spec.add_development_dependency "rake"
|
55
56
|
spec.add_development_dependency "rspec"
|
56
57
|
spec.add_development_dependency "pry"
|
57
|
-
|
58
|
-
root_path = File.expand_path(File.dirname(__FILE__))
|
59
|
-
|
60
|
-
# get an array of submodule dirs by executing 'pwd' inside each submodule
|
61
|
-
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
|
62
|
-
# for each submodule, change working directory to that submodule
|
63
|
-
Dir.chdir(submodule_path) do
|
64
|
-
# issue git ls-files in submodule's directory
|
65
|
-
submodule_files = `git ls-files`.split($\)
|
66
|
-
|
67
|
-
# prepend the submodule path to create absolute file paths
|
68
|
-
submodule_files_fullpaths = submodule_files.map do |filename|
|
69
|
-
"#{submodule_path}/#{filename}"
|
70
|
-
end
|
71
|
-
|
72
|
-
# remove leading path parts to get paths relative to the gem's root dir
|
73
|
-
# (this assumes, that the gemspec resides in the gem's root dir)
|
74
|
-
submodule_files_paths = submodule_files_fullpaths.map do |filename|
|
75
|
-
str = filename.gsub root_path, ""
|
76
|
-
str[1..(str.length-1)]
|
77
|
-
end
|
78
|
-
|
79
|
-
# add relative paths to gem.files
|
80
|
-
spec.files += submodule_files_paths
|
81
|
-
end
|
82
|
-
end
|
83
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyaplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoki Nishida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mikon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.2.rc1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.2.rc1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +112,7 @@ files:
|
|
98
112
|
- examples/notebook/Mapnya.ipynb
|
99
113
|
- examples/notebook/Mapnya2.ipynb
|
100
114
|
- examples/notebook/Mapnya3.ipynb
|
115
|
+
- examples/notebook/Nyaplotv2.ipynb
|
101
116
|
- examples/notebook/data/11-1-result0.6.csv
|
102
117
|
- examples/notebook/data/UNdata_Export_20140813_215958400.csv
|
103
118
|
- examples/notebook/data/circular/category.csv
|
@@ -658,9 +673,6 @@ files:
|
|
658
673
|
- lib/mapnya/datasets/countries/dist/countries.xml
|
659
674
|
- lib/mapnya/datasets/countries/index.js
|
660
675
|
- lib/mapnya/datasets/countries/package.json
|
661
|
-
- lib/mapnya/datasets/geo-boundaries-world-110m/README.md
|
662
|
-
- lib/mapnya/datasets/geo-boundaries-world-110m/countries.geojson
|
663
|
-
- lib/mapnya/datasets/geo-boundaries-world-110m/datapackage.json
|
664
676
|
- lib/mapnya/datasets/world.geo.json
|
665
677
|
- lib/mapnya/js/.gitignore
|
666
678
|
- lib/mapnya/js/Gruntfile.js
|
@@ -690,12 +702,18 @@ files:
|
|
690
702
|
- lib/nyaplot/colorbrewer/colorbrewer.json
|
691
703
|
- lib/nyaplot/core.rb
|
692
704
|
- lib/nyaplot/data.rb
|
693
|
-
- lib/nyaplot/
|
694
|
-
- lib/nyaplot/
|
695
|
-
- lib/nyaplot/frame.rb
|
705
|
+
- lib/nyaplot/glyph.rb
|
706
|
+
- lib/nyaplot/interactive.rb
|
696
707
|
- lib/nyaplot/monkeys.rb
|
708
|
+
- lib/nyaplot/pane.rb
|
697
709
|
- lib/nyaplot/plot.rb
|
710
|
+
- lib/nyaplot/position.rb
|
711
|
+
- lib/nyaplot/scale.rb
|
712
|
+
- lib/nyaplot/sheet.rb
|
713
|
+
- lib/nyaplot/simple/stage.rb
|
714
|
+
- lib/nyaplot/stage2d.rb
|
698
715
|
- lib/nyaplot/templates/init.js.erb
|
716
|
+
- lib/nyaplot/templates/init_interactive.js
|
699
717
|
- lib/nyaplot/templates/iruby.erb
|
700
718
|
- lib/nyaplot/templates/static_html.erb
|
701
719
|
- lib/nyaplot/version.rb
|
@@ -745,9 +763,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
745
763
|
version: '2.0'
|
746
764
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
747
765
|
requirements:
|
748
|
-
- - "
|
766
|
+
- - ">"
|
749
767
|
- !ruby/object:Gem::Version
|
750
|
-
version:
|
768
|
+
version: 1.3.1
|
751
769
|
requirements: []
|
752
770
|
rubyforge_project:
|
753
771
|
rubygems_version: 2.2.2
|
@@ -771,3 +789,4 @@ test_files:
|
|
771
789
|
- spec/nyaplot3d_spec.rb
|
772
790
|
- spec/nyaplot_spec.rb
|
773
791
|
- spec/spec_helper.rb
|
792
|
+
has_rdoc:
|