New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

active_graph

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

active_graph

  • 0.2.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= active_graph

http://github.com/kazjote/active_graph/tree/master

== DESCRIPTION:

Gem which makes filling data for Gruff graphs based on ActiveRecord objects much easier.

== FEATURES/PROBLEMS:

Good points:

  • Ease of use
  • Flexible
  • Created in model but enable to customize presentation in controller

Bad points:

  • Slow - requires many database calls (it is intended to create cacheable graphs)
  • Do not allow to customize options after model is loaded (TODO)

== SYNOPSIS:

The simplies case (mosts are defaults - you probably won't use it):

class User < ActiveRecord::Base active_graph :posts, :series => {:submited_posts => {:value => :count_have_posts_between, :caption => "posts"}}

def self.count_have_posts_between(min, max)
  count(:all, :conditions => "posts_count > #{min} AND posts_count <= #{max}")
end

end

Now, featured one. It will create a line graph, which

  • starts at User.start_time,
  • end one week later
  • shows data with 1 day step
  • defines x_axis with formated labels
  • presents 2 data series

class User < ActiveRecord::Base

active_graph :new_posts,
  :type => :line,
  :start => Proc.new {@@start_time}, :end => Proc.new { @@start_time + 1.week },
  :step => 1.day,
  :x_axis => {:interval => 3, :method => Proc.new {|time| time.strftime("%d-%m") }},
  :width => 100,
  :series => {:submited_posts => {:value => :count_have_posts_between, :caption => "posts"},
    :submited_posts2 => {:value => :count_have_posts2_between, :caption => "posts2"}}
  
def self.count_have_posts_between(min, max); end
def self.count_have_posts2_between(min, max); end

end

Statistic on user age?

active_graph :age, :type => :bar, :start => 0, :end => 100, :step => 10, :x_axis => {:interval => 1, :method => Proc.new {|age| "#{age}-#{age + 10}" }}, :series => { :age => {:value => :count_aged_between, :caption => "Age" } }

Now, create an action in your controller:

class UsersController < ApplicationController def new_posts_graph graph = User.new_posts_graph send_data graph.to_blob, :type => "image/png", :disposition => "inline", :filename => "new_users_graph.png" end end

graph is a normal Gruff object, so you can customize presentation before rendering.

== REQUIREMENTS:

  • gem 'activesupport' >= 2.0.2
  • gem 'metaid' >= 1.0
  • gem 'gruff' >= 0.3.1

It can run without Rails (testcase does not use rails at all).

== INSTALL:

  • sudo gem install active_graph

In your envrionment.rb:

config.gem "metaid" config.gem "gruff" config.gem "active_graph"

If you have older rails you can load it with initializer or directly in your model:

require 'gruff' require 'active_graph'

class User < ActiveRecord::Base extend ActiveGraph::ActiveRecordExtension ... end

== LICENSE:

(The MIT License)

Copyright (c) 2008 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 24 Sep 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc