Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for attribute 'p' in columns. #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/google_visualr/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@ def initialize(options = {})
# * id [Optional] A unique (basic alphanumeric) string ID of the column. Be careful not to choose a JavaScript keyword. Example: id:'col_1'
# * role [Optional] A string value that describes the purpose of the data in that column. Example, a column might hold data describing tooltip text, data point annotations, or uncertainty indicators.
# * pattern [Optional] A number (or date) format string specifying how to display the column value; used in conjunction with role.
def new_column(type, label=nil, id =nil, role=nil, pattern=nil)
column = { :type => type, :label => label, :id => id, :role => role, :pattern => pattern }.reject { |key, value| value.nil? }
# * p [Optional] A hash of custom values applied to the cell. These values can be of any type that responds to #to_json. If your visualization supports any cell-level properties, it will describe them; otherwise, this property will be ignored.
def new_column(type, label=nil, id =nil, role=nil, pattern=nil, p=nil)
column = { :type => type, :label => label, :id => id, :role => role, :pattern => pattern, :p => p }.reject { |key, value| value.nil? }
@cols << column
end

# Adds multiple columns to the data_table.
#
# Parameters:
# * columns [Required] An array of column objects {:type, :label, :id, :role, :pattern}. Calls new_column for each column object.
# * columns [Required] An array of column objects {:type, :label, :id, :role, :pattern, :p}. Calls new_column for each column object.
def new_columns(columns)
columns.each do |column|
new_column(column[:type], column[:label], column[:id], column[:role], column[:pattern])
new_column(column[:type], column[:label], column[:id], column[:role], column[:pattern], column[:p])
end
end

Expand Down
9 changes: 8 additions & 1 deletion spec/google_visualr/data_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,27 @@ def valid_object
dt.new_column('string', nil, nil, 'interval', 'pattern')
dt.cols.first.should == {:type => 'string', :role => 'interval', :pattern => 'pattern'}
end

it "initializes a new column with custom 'p' param" do
dt.new_column('string', nil, nil, 'role', nil, {:my_property => 'value'})
dt.cols.first.should == {:type => 'string', :role => 'role', :p => {:my_property => 'value'}}
end
end

describe "new_columns" do
it "initializes new columns (with experimental support)" do
columns = [
{:id => 'A', :label => 'NEW A', :type => 'string'},
{:id => 'B', :label => 'NEW B', :type => 'string'},
{:type => 'string', :role => 'interval', :pattern => 'pattern'}
{:type => 'string', :role => 'interval', :pattern => 'pattern'},
{:type => 'string', :role => 'tooltip', :p => {:html => true}}
]

dt.new_columns(columns)
dt.cols[0].should == columns[0]
dt.cols[1].should == columns[1]
dt.cols[2].should == columns[2]
dt.cols[3].should == columns[3]
end
end

Expand Down