Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
9

Go to list of users who liked

8

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby | Gvizでインデント構造のテキストをマインドマップに変換する

Last updated atPosted at 2014-09-12

Ruby | Gvizでインデント構造のテキストをマインドマップに変換する

概要

Gvizでインデント構造のテキストをマインドマップに変換します。

利用ライブラリ

利用ライブラリについては、下記記事参照

Gvizでインデント構造のテキストをグラフに変換する

サンプルコード

require'familyable'require'gottani_core'require"gviz"text=<<-EOSRuby  スクリプト言語  影響    From      Perl      Lisp      Smalltalk    To      CoffeeScript      Elixir  Author    まつもとゆきひろ      Matz      松江      Heroku  Web    Ruby on Rails      Author        DHH      Products        Redmine        GitLab    Sinatra  DevOps    Vagrant      Author        M.Hashimoto      Provider        Virtual Box        VMWare          Workstation          Fusion        AWS    Chef    Puppet  特徴    楽しい    すべてがオブジェクト    可読性の高さ    動的言語      強力なメタプログラミング      DSL作成の容易さEOSsp2=Gottani::Space2.newindent_text=sp2.space2_to_common(text)indexed_indent_text=indent_text.reverse.map.with_index{|e,i|e.merge({id:i})}moduleFamilyableclassPersonattr_accessor:value,:levelendendi=0persons=indexed_indent_text.reduce([])do|persons,person|parent=indexed_indent_text[(i+1)..-1].find{|e|e[:level]==person[:level]-1}parent_ids=parent.nil??[]:[parent[:id]]person=Familyable::Person.new(id:i,parent_ids:parent_ids).tapdo|e|e.value=person[:value]e.level=person[:level]endpersons<<personi+=1personsendsorted_persons=persons.reversefamily=Familyable::Family.new(family:persons)Graphdogloballayout:'twopi',overlap:false,splines: :curvednodesfontname:'MS GOTHIC',shape: :none,style:'filled'edgesdir: :none# ノードの定義sorted_persons.each{|person|node:"person#{person.id}",{label:person.value}}# エッジの定義sorted_persons.eachdo|person|parents=family.get_parents(person)nextifparents.empty?parent=parents.firstoptions={}options[:penwidth]=6ifparent.level==0edge:"person#{parent.id}_person#{person.id}",optionsend# *** 根のランク, スタイル定義 ***min_id=persons.find{|e|e.level==0}.idmin_person_key=:"person#{min_id}"rank:min,[min_person_key]nodemin_person_key,{shape:'pentagon',fontsize:80,fillcolor: :red}# *** 根以外のノードのランク定義 ***ranked_persons=sorted_persons.group_by{|e|e.level}.select{|key,value|key.nonzero?}ranked_persons.eachdo|rank,each_rank_persons|each_rank_persons.map{|e|node:"person#{e.id}",{fontsize:40}}ifrank==1persons=each_rank_persons.map{|e|"person#{e.id}".to_sym}rank(:same,persons)endsave:"givz_mindmap",:pngend

出力

givz_mindmap.png

参照

関連記事

9

Go to list of users who liked

8
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9

Go to list of users who liked

8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp