Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acts_as_graph_diagram

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acts_as_graph_diagram

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Acts As Graph Diagram

Acts As Graph Diagram extends Active Record to add simple function for draw the Force Directed Graph with html.

Ruby Gem Version Ruby Style Guide CircleCI

See It Work

acts_as_graph_diagram

Usage

Append the line to your model file like below:

class God < ApplicationRecord
  acts_as_graph_diagram
end

God.find_by(name: 'Rheā').add_destination God.find_by(name: 'Hēra', figure: 1)
# => #<Edge:0x000000010b0d4560
#  id: 1,
#  comment: "",
#  figure: 0,
#  directed: true,
#  destination_type: "God",
#  destination_id: 2,
#  departure_type: "God",
#  departure_id: 1,
#  created_at: Sun, 12 Jun 2022 11:11:06.995007000 UTC +00:00,
#  updated_at: Sun, 12 Jun 2022 11:11:06.995007000 UTC +00:00>

God.find_by(name: 'Rheā').connecting_count
# => 1

God.find_by(name: 'Rheā').aheads
# => [#<Edge:0x000000010b5642b0
#   id: 1,
#   comment: "",
#   figure: 0,
#   directed: true,
#   destination_type: "God",
#   destination_id: 2,
#   departure_type: "God",
#   departure_id: 1,
#   created_at: Sun, 12 Jun 2022 11:11:06.995007000 UTC +00:00,
#   updated_at: Sun, 12 Jun 2022 11:11:06.995007000 UTC +00:00>]

God.find_by(name: 'Rheā').aheads.first.destination
# => #<God:0x000000010b5efb58 id: 2, name: "Hēra", created_at: Sun, 12 Jun 2022 11:11:06.984341000 UTC +00:00, updated_at: Sun, 12 Jun 2022 11:11:06.984341000 UTC +00:00>

Methods

  • aheads
  • behinds
  • add_destination(node, comment: '', figure: 0)
  • add_departure(node, comment: '', figure: 0)
  • get_destination(node)
  • get_departure(node)
  • remove_destination(node)
  • remove_departure(node)
  • connecting?(node)
  • connecting_count()
  • add_connection(node, directed: false, comment: '', figure: 0)
  • sum_tree(column)
  • assemble_tree_nodes()

Draws the graph diagram with D3.js

Distributes to represent a graph JSON via API.

  1. Implement a renderer in your controller file as below:
class GodsController < ApplicationController
  def data_network
    render json: { 'nodes' => God.all.pluck(:id, :name)
                                 .map { |x| Hash[id: x[0], name: x[1]] },
                   'links' => Edge.all.pluck(:destination_id, :departure_id)
                                  .map { |x| Hash[target: x[0], source: x[1]] } }
  end
end
  1. And append the line to your routes.rb file like below:
Rails.application.routes.draw do
  get 'data_network' => 'gods#data_network'
end
  1. Then execute a D3 query in your javascript file as below:
// v7.4.4
d3.json("http://127.0.0.1:3000/data_network").then(function (graph) {});

Pert_chart_colored

PERT Chart. Drawn in Adobe Illustrator - inspired by a chart at netmba.com. Created by Jeremy Kemp. 2005/01/11 From Wikipedia, the free encyclopedia

Milestone.create(name: 10)
Milestone.create(name: 20)
Milestone.create(name: 30)
Milestone.create(name: 40)
Milestone.create(name: 50)

Milestone.find_by(name: 10).add_destination(Milestone.find_by(name: 20), figure: 3)
Milestone.find_by(name: 10).add_destination(Milestone.find_by(name: 30), figure: 4)
Milestone.find_by(name: 30).add_destination(Milestone.find_by(name: 40), figure: 1)
Milestone.find_by(name: 40).add_destination(Milestone.find_by(name: 50), figure: 3)
Milestone.find_by(name: 30).add_destination(Milestone.find_by(name: 50), figure: 2)
Milestone.find_by(name: 20).add_destination(Milestone.find_by(name: 50), figure: 3)

Milestone.find_by(name: 10).sum_tree(:figure)
# => 16

Installation

Add this line to your application's Gemfile:

gem "acts_as_graph_diagram"
$ bundle

Or install it yourself as:

$ gem install acts_as_graph_diagram

Then executes:

$ bin/rails generate acts_as_graph_diagram
$ bin/rails db:migrate

Development

Rails console

test/dummy/bin/rails console

Test

bin/test

Contributing

Bug reports and pull requests are welcome on Github at https://github.com/routeflags/acts_as_graph_diagram. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Changelog

Available here.

Code of Conduct

Everyone interacting in the project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

You may enjoy owning other libraries and my company.

Аcknowledgments

FAQs

Package last updated on 17 Jun 2022

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