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

adding support for embedded functions inside the google visualization #74

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

golsombe
Copy link

I needed a new function inside the draw_chart() function to support custom tooltips for the TreeMap chart. Added a new add_function method along with additional spec for testing. Please advise?

Ex:

@chart.add_function("   function showTooltip(row, size, value) {
    return '<div style=\"background:#99dcff; padding:10px; border-style:solid; font-size: small;\">' +
           '<span style=\"font-family:Times;\"><b>' + data_table.getValue(row, 1) + '<\b></span><br></div>';  }")

@@ -32,6 +33,10 @@ def add_listener(event, callback)
@listeners << { :event => event.to_s, :callback => callback }
end

def add_function(callback)
@functions << {:callback=> callback}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Use 2 (not -3) spaces for indentation.
Surrounding space missing for operator '=>'.
Space inside { missing.
Space inside } missing.
Tab detected.

@@ -32,6 +33,10 @@ def add_listener(event, callback)
@listeners << { :event => event.to_s, :callback => callback }
end

def add_function(callback)
@functions << { :callback=> callback }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Surrounding space missing for operator '=>'.

@@ -32,6 +33,10 @@ def add_listener(event, callback)
@listeners << { :event => event.to_s, :callback => callback }
end

def add_function(callback)
@functions << { :callback => callback }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

module GoogleVisualr
module Interactive

# https://developers.google.com/chart/interactive/docs/gallery/timeline
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winston
Copy link
Owner

winston commented Jun 16, 2014

Hi! Thanks for the PR!

The stuff for the new calendar chart is great (and can be extracted as another PR), and I'll merge that. However, I am not so sure about introducing the embedded functions, as it doesn't look too good if you have to write JS in the code, which is precisely the reason for this gem.

Do you have a specific use case that cannot be done with listeners?

Let me know.

Thank you!

@golsombe
Copy link
Author

If you take a look at the Treemap example in Google charts, they
demonstrate a custom tooltip function that I use in my project. Since I
have to be within the outer drawchart function, I need it embedded in
google_visualr. I'll admit that I'm not the best js developer, so if you
can figure a way to use a listener by all means educate me.

As for the calendar, I wasn't quite ready to release it to the project but
an accident git push went to master instead of my working branch which is
why you got it earlier than I intended. I'll clean up the errors and take
a stab at a document page along with a spec tomorrow. The code does work,
just isn't as pretty as it needs to be.

Thanks for google_visualr. It's a great time saver and makes the visuals
section of my projects nice and dry. I plan on tackling some binders and
controls next.

Robert Hall
Golsombe@gmail.com
@golsombe Twitter
On Jun 15, 2014 9:18 PM, "Winston" notifications@github.com wrote:

Hi! Thanks for the PR!

The stuff for the new calendar chart is great (and can be extracted as
another PR), and I'll merge that. However, I am not so sure about
introducing the embedded functions, as it doesn't look too good if you have
to write JS in the code, which is precisely the reason for this gem.

Do you have a specific use case that cannot be done with listeners?

Let me know.

Thank you!

Reply to this email directly or view it on GitHub
#74 (comment).

@winston
Copy link
Owner

winston commented Jun 16, 2014

I had a look at the treemap example, and it seems like you can actually do

var options = {
    minColor: 'red',
    midColor: '#ddd',
    maxColor: '#0d0',
    headerHeight: 15,
    fontColor: 'black',
    showScale: true,
    generateTooltip: function hi() { return '<div>ok</div>'; }
}

tree.draw(data, options);

So I guess in the Ruby code, you can also do the same, instead of creating additional functions.

Will that work for you? I am thinking that this is an edge case for treemap, and am still unsure if it the gem should support adding functions at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants