@@ -36,24 +36,59 @@ def show_script(dom=SecureRandom.uuid, options={})
36
36
end
37
37
38
38
def to_html ( id = nil , options = { } )
39
- path = File . expand_path ( '../../templates/googlecharts/chart_div.erb' , __dir__ )
39
+ if data . is_a? ( Array ) &&
40
+ ( data [ 0 ] . is_a? ( Daru ::View ::Plot ) || data [ 0 ] . is_a? ( Daru ::View ::Table ) )
41
+ id , chart_script , path = extract_multiple_charts_id_script_path
42
+ else
43
+ id , chart_script , path = extract_chart_id_script_path ( id )
44
+ end
40
45
template = File . read ( path )
41
- id ||= SecureRandom . uuid
42
- @html_id = id
43
- chart_script = show_script ( id , script_tag : false )
44
46
ERB . new ( template ) . result ( binding )
45
47
end
46
48
47
49
def show_in_iruby ( dom = SecureRandom . uuid )
48
50
IRuby . html ( to_html ( dom ) )
49
51
end
52
+
53
+ def extract_multiple_charts_id_script_path
54
+ path = File . expand_path (
55
+ '../../templates/googlecharts/multiple_charts_div.erb' , __dir__
56
+ )
57
+ id = [ ]
58
+ chart_script = [ ]
59
+ data . each_with_index do |plot , index |
60
+ id [ index ] ||= SecureRandom . uuid
61
+ chart_script [ index ] = set_chart_script ( plot , id [ index ] )
62
+ end
63
+ [ id , chart_script , path ]
64
+ end
65
+
66
+ def extract_chart_id_script_path ( id = nil )
67
+ path = File . expand_path (
68
+ '../../templates/googlecharts/chart_div.erb' , __dir__
69
+ )
70
+ id ||= SecureRandom . uuid
71
+ @html_id = id
72
+ chart_script = show_script ( id , script_tag : false )
73
+ [ id , chart_script , path ]
74
+ end
75
+
76
+ def set_chart_script ( plot , id )
77
+ if plot . is_a? ( Daru ::View ::Plot )
78
+ plot . chart . show_script ( id , script_tag : false )
79
+ else
80
+ plot . table . show_script ( id , script_tag : false )
81
+ end
82
+ end
50
83
end
51
84
52
85
class DataTable
86
+ attr_accessor :data
53
87
include Display
54
88
end
55
89
56
90
class BaseChart
91
+ attr_accessor :data
57
92
include Display
58
93
end
59
94
end
0 commit comments