Skip to main content

Graphviz quick start with example

Graphviz là gì?
What is Graphviz?
Là một phần mềm giúp thể hiện các diagram(biểu đồ các loại) bằng cách viết ra một file "source code"
Nó là open source và free nhé.
It's open source graph drawing tool by typing some text.

Tại sao nên dùng Graphviz?
Why should use Graphviz?
Sau một vài năm tháng sinh nghề tử nghiệp với mạch điện tử, với các loại code kèo, không may mắn mình bị mắc hội chứng ống cổ tay . Bệnh này làm mình trở lên khó chịu với từng cú click chuột. Chất lượng cuộc sống xuống dốc không phanh đến nỗi nhiều lúc đã định nghỉ việc. Sau khi đi thăm khám và thử vài liệu pháp treatment không hiệu quả từ những lang y như từ mẫu, mình nhận ra là chẳng ai cứu được mình ngoài mình.
Anytime you heard about
Mình bắt đầu lên kế hoạch giảm tối đa các thao tác với chuột máy tính. Và Graphviz là một phương thuốc trong bộ giải pháp đó. Hi vọng guideline dưới có thể là một giải pháp hỗ trợ những người bị bệnh giống như mình.

Và thế nên, đừng hỏi mình tại sao không dùng Visio, Astah thậm chí là excel, và một ti tỉ các tool khác trên đời để vẽ diagram.

Dùng thử tính năng chính
Bài toán đặt ra:
Input: source code
Output: graph ?

Bài giải:
Hãy copy source code các example ở đây
http://graphs.grevian.org/example

Sau đó paste vào text box
http://graphs.grevian.org/graph

Chọn cách layout tương ứng (dot, neato ...etc)
Sau đó generate ra graph tương ứng.

Nếu bạn bị lỗi
</pre>
 Error: Failed to generate your graph (Error [400]), perhaps a syntax error?
<pre>
Hãy thử chỉnh lại các tab trong source code (thường là chỗ graph hoặc dấu "}")

Nếu bạn cảm thấy hứng thú thì tiếp tục đọc.
Không thì hay close this window và đi tìm một thứ thú vị hơn để làm cho đỡ lãng phí thời gian.

Cài đặt:
http://www.graphviz.org/Download.php
 
Kiểm tra cài đặt
Mở cửa sổ MSDOS gõ "dot --help"
Trường hợp 1: Command này được nhận ra thì OK, done.
Trường hợp 2:
'dot' is not recognized as an internal or external command,
operable program or batch file.

  
Bạn phải chỉnh lại biến môi trường
Start/Computer/Property/Advance System Setting/Environment Variables/PATH
Ấn Edit và paste dòng dưới vào cuối của text box "variable value"
<pre>
;C:\Program Files (x86)\Graphviz2.38\bin
</pre>

Check lại bằng lệnh "dot --help". Nếu không được thì thử restart lại PC hoặc sửa luôn cái PATH của phần System Variables. Nếu không được nữa thì mình chịu, google giúp đi

Chạy thử chương trình đầu tiên.
Copy source code nào đó bạn thích. (cái nào ngắn thôi nhé, ko fix bug nản lắm :D)
Ví dụ: http://graphs.grevian.org/graph/6537066003300352

Save nội dung vào file example1.gv (ví dụ đặt file này vào thư mục C:\example)
Mở cửa số MSDOS, nhảy vào thư mục tương ứng bằng lệnh cd
Gõ lệnh sau:
dot -Tjpg example1.gv -o example1.jpg

Trong đó
dot: lệnh của grapviz (bạn có thể dùng neato, twopi ..etc, nhớ là phải tương ứng với nội dung của file source gv
-Tjpg: tham số cho phép xuất ra output dạng jpg
example1.gv: tên input file (source code)
-o : tham số output file
example1.jpg: output file

Cuối cùng, kiểm tra thành quả jpg và tiếp tục vọc nhé.
Chúc thành công.

More Example
digraph G
{
    // Set shape
    node [shape=box]
   
    // Simple box
    node0 [label="TextBox 0 content"]

    // Box is filled
    node1 [style=filled, label="TextBox 1 content" ]

    // Box is filled by red color
    node2 [style=filled, fillcolor=red, label="TextBox 2 content"]

    // Set connection between each nodes
    node0 -> node1 -> node2
}

Reference :
Dot language
https://en.wikipedia.org/wiki/DOT_(graph_description_language)

Comments

Popular posts from this blog

[STM32] How to configure Timer 1, Channel 3 is PWM 1kHz, duty cycle 20% to control BLDC motor

 To configure Timer1 for a 1 kHz PWM signal with a 20% duty cycle on an STM32H7S3L8 microcontroller, follow these steps: 1. Understand the Timer Parameters PWM Frequency : 1 kHz → Period = 1 ms. Duty Cycle : 20% → ON time = 0.2 ms. The timer’s clock frequency is derived from the APB clock (e.g., TIMCLK). Let’s assume you know the APB clock frequency. The Timer prescaler and auto-reload register (ARR) define the PWM frequency. 2. Compute Timer Parameters Formula: PWM Frequency = Timer Clock (Prescaler + 1) * (ARR + 1) \text{PWM Frequency} = \frac{\text{Timer Clock}}{\text{(Prescaler + 1) * (ARR + 1)}} PWM Frequency = (Prescaler + 1) * (ARR + 1) Timer Clock ​ For 1 kHz PWM: A R R = Timer Clock PWM Frequency ∗ ( Prescaler + 1) − 1 ARR = \frac{\text{Timer Clock}}{\text{PWM Frequency} * (\text{Prescaler + 1)}} - 1 A RR = PWM Frequency ∗ ( Prescaler + 1) Timer Clock ​ −...

[CanadaLife] Example of answers for final test in Smart Service Ontario 2024

If you have failed the final exam in the first attempt. Congratulations, you are not odd. Here, take a look and grab some corrected answers for your next attempt.  Don't waste your money and time for more failure.  Good luck bros. Quick note: remember that, the system will change the bunch of questions after each attempt. Then your next questionnaire will be different compared with the first trial. ========================================== =============FINAL TEST=================== ========================================== TIP: Here is a list of questions you did not answer correctly. *Please note: You will only be able to view this list immediately following your test attempt. ========================================== Alcohol slows down the central nervous system and impacts how a person thinks, acts, and moves. This means alcohol is a: depressant ========================================== Alcohol is metabolized in the body at a set rate. For most people, that rate is: one...

How to use ChatGPT to get your resume shortlisted?

How to use ChatGPT to get your resume shortlisted? Core steps: Chat GPT -> Resume Creator -> LinkedIn(Copy the job description to ChatGPT) -> Add your personal information -> Copy output from ChatGPT to Instaresume.io to make the template -> Goto SkillSyncer to check ATS(Applicant Tracking Software) score, point out the missing keywords. Detail ☑️In my pursuit of job #opportunities, I encountered a familiar challenge - my resume seemingly disappeared into oblivion, yielding no responses despite my diverse skill set and numerous applications. ☑️As I delved into my research, I uncovered the existence of ATS software, the automated gatekeeper of #resumes, which swiftly filtered out those lacking relevant keywords. ☑️The outcome? Not just one #company, but over a dozen organizations recognized the potential in my resume, resulting in multiple shortlists and promising #job prospects! 💻If you want to supercharge your resume and unlock countless opportunities, don't miss o...