{"id":17656602,"url":"https://github.com/asterite/rgviz-rails","last_synced_at":"2025-04-14T22:37:43.107Z","repository":{"id":1228513,"uuid":"1158872","full_name":"asterite/rgviz-rails","owner":"asterite","description":"Google Visualization API Query Language for Ruby on Rails","archived":false,"fork":false,"pushed_at":"2023-03-02T19:01:01.000Z","size":264,"stargazers_count":23,"open_issues_count":4,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T10:50:21.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asterite.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2010-12-11T15:07:32.000Z","updated_at":"2020-09-17T23:40:24.000Z","dependencies_parsed_at":"2023-07-05T18:31:47.774Z","dependency_job_id":null,"html_url":"https://github.com/asterite/rgviz-rails","commit_stats":{"total_commits":123,"total_committers":7,"mean_commits":"17.571428571428573","dds":"0.41463414634146345","last_synced_commit":"f1d88e5278c3917376f6e5cc632fe82fa3215b7d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterite%2Frgviz-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterite%2Frgviz-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterite%2Frgviz-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterite%2Frgviz-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asterite","download_url":"https://codeload.github.com/asterite/rgviz-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248974804,"owners_count":21192190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-23T14:34:34.271Z","updated_at":"2025-04-14T22:37:43.075Z","avatar_url":"https://github.com/asterite.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"rgviz-rails\n===========\n\n[![Build Status](https://secure.travis-ci.org/asterite/rgviz-rails.png?branch=master)](http://travis-ci.org/asterite/rgviz-rails)\n\nThis library makes it easy to implement a visualization data source so that you can easily chart or visualize your data from [ActiveRecord](http://ar.rubyonrails.org/) models or from in-memory arrays. the library implements the [Google Visualization API wire protocol](http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html).\n\nIt also allows you to [render the visualizations in a view template](https://github.com/asterite/rgviz-rails/wiki/showing-a-visualization-in-a-view) in a very simple but powerful way.\n\nThis library is built on top of [rgviz](https://github.com/asterite/rgviz).\n\nInstallation\n------------\n\n    gem install rgviz-rails\n\nRails 3\n-------\n\nIn your gemfile\n\n    gem 'rgviz'\n    gem 'rgviz-rails', :require =\u003e 'rgviz_rails'\n\nRails 2.x\n---------\n\nIn your environment.rb\n\n    config.gem \"rgviz\"\n    config.gem \"rgviz-rails\", :require =\u003e 'rgviz_rails'\n\nUsage\n-----\n\nTo make a method in your controller be a visualization api endpoint:\n\n    class VizController \u003c ApplicationController\n      def person\n        # Person is an ActiveRecord::Base class\n        render :rgviz =\u003e Person\n      end\n    end\n\nSo for example if \u003cttPperson\u003c/tt\u003e has \u003ctt\u003ename\u003c/tt\u003e and \u003ctt\u003eage\u003c/tt\u003e, pointing your browser to:\n\n    http://localhost:3000/viz/person?tq=select name where age \u003e 20 limit 5\n\nwould render the necessary javascript code that implements the google visualization api wire protocol.\n\nAssociations\n------------\n\nIf you want to filter, order by or group by columns that are in a model's association you can use underscores. this is better understood with an example:\n\n    class Person \u003c ActiveRecord::Base\n      belongs_to :city\n    end\n\n    class City \u003c ActiveRecord::Base\n      belongs_to :country\n    end\n\n    class Country \u003c ActiveRecord::base\n    end\n\nTo select the name of the city each person belongs to:\n\n    select city_name\n\nTo select the name of the country of the city each person belongs to:\n\n    select city_country_name\n\nA slightly more complex example:\n\n    select avg(age) where city_country_name = 'argentina' group by city_name\n\nThe library will make it in just one query, writing all the sql joins for you.\n\nExtra conditions\n----------------\n\nSometimes you want to limit your results the query will work with. You can do it like this:\n\n    render :rgviz =\u003e Person, :conditions =\u003e ['age \u003e ?', 20]\n\nor also:\n\n    render :rgviz =\u003e Person, :conditions =\u003e 'age \u003e 20'\n\nor (Rails 3 only):\n\n    render :rgviz =\u003e Person.where('age \u003e ?', 20)\n\nPreprocessing\n-------------\n\nIf you need to tweak a result before returning it, just include a block:\n\n    render :rgviz =\u003e Person do |table|\n      # modify the Rgviz::Table object\n    end\n\nShowing a visualization in a view\n---------------------------------\n\nYou can invoke the rgviz method in your views. [read more about this](https://github.com/asterite/rgviz-rails/wiki/showing-a-visualization-in-a-view).\n\nYou can always do it the [old way](https://developers.google.com/chart/interactive/docs/examples#full_html_page_example).\n\nExecuting queries over in-memory arrays\n---------------------------------------\n\nYou can also apply a query over an array of arrays that contains your \"records\" to be queried.\n\n    types = [[:id, :number], [:name, :string], [:age, :number]]\n    records = [\n      [1, 'john', 23],\n      [2, 'pete', 36]\n    ]\n    executor = Rgviz::MemoryExecutor.new records, types\n\n    render :rgviz =\u003e executor\n\nThis is very useful if you need to present visualizations against data coming from a csv file.\n\nVirtual columns\n---------------\n\nGQL is nice but it's not very powerful (except for the cute pivot clause).\n\nIf you need to select columns using complex SQL, you might be able to do it with virtual columns.\n\nFor example, in your controller you put:\n\n    render :rgviz =\u003e Person, :virtual_columns =\u003e {\n        'age_range' =\u003e {\n            :sql =\u003e \"case when age \u003c 20 then 'young' else 'old' end\",\n            :type =\u003e :string\n        }\n    }\n\nThen in a query you can do:\n\nselect age_range ...\n\nNote that the keys of the virtual_columns hash must be strings. The value can be a hash with :sql and :type key-value pairs (since GQL needs the type of every column), or can be just a string if you want the column to be replaced by another GQL expression. For example:\n\n    render :rgviz =\u003e Person, :virtual_columns =\u003e {\n        'age_plus_two' =\u003e 'age + 2'\n    }\n\nCurrent limitations\n-------------------\n\n* the *format* clause works, but formatting is as in ruby (like \"%.2f\" for numbers, \"foo %s bar\" for strings, and \"%y-%m-%d\" for dates, as specified by [Time#strftime](http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime))\n* only supports mysql, postgresql and sqlite adapters\n* these scalar functions are not supported for sqlite: *millisecond*, *quarter*\n* these scalar functions are not supported for mysql: *millisecond*\n* the function *toDate* doesn't accept a number as its argument\n* the *tsv* output format is not supported\n\nContributors\n------------\n\n* [Brad Seefeld](https://github.com/bradseefeld)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasterite%2Frgviz-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasterite%2Frgviz-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasterite%2Frgviz-rails/lists"}