搜尋此網誌

2012年10月31日

JChart2D Zoomable char

package com.qci.jchart2ddemo;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.ZoomableChart;
import info.monitorenter.gui.chart.pointpainters.PointPainterDisc;
import info.monitorenter.gui.chart.traces.Trace2DSimple;
import info.monitorenter.gui.chart.views.ChartPanel;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;

public class ZoomTest extends JFrame {

     private static final long serialVersionUID = -2249660781499017221L;

     class ZoomAllAdapter implements ActionListener {

         private ZoomableChart m_zoomableChart;

         public ZoomAllAdapter(final ZoomableChart chart) {
              this.m_zoomableChart = chart;
         }

         public void actionPerformed(final ActionEvent event) {
              this.m_zoomableChart.zoomAll();
         }
     }

     public static void main(final String[] args) {

         ZoomTest zoomTest = new ZoomTest();
         // Show the frame
         zoomTest.setSize(640, 480);
         zoomTest.setVisible(true);

     }

     public ZoomTest() {

         super("ZoomTest");

         Container c = this.getContentPane();
         c.setLayout(new BorderLayout());

         // Create a chart
         ZoomableChart chart = new ZoomableChart();

         ITrace2D trace = new Trace2DSimple();
         // Add the trace to the chart. This has to be done before adding points (deadlock prevention):
         chart.addTrace(trace);   
         // Add all points, as it is static:
         Random random = new Random();
         for(int i=100;i>=0;i--){
           trace.addPoint(i,random.nextDouble()*10.0+i);
         }

         chart.setToolTipType(Chart2D.ToolTipType.VALUE_SNAP_TO_TRACEPOINTS);
         // chart.setPointHighlighter(new PointPainterDisc(8));

         // Add chart to the pane
         c.add(new ChartPanel(chart));

         // Create the zoomAll button
         JButton zoomAllButton = new JButton("Zoom All");
         zoomAllButton.addActionListener(new ZoomAllAdapter(chart));

         // Add zoomAll button to the pane
         c.add(zoomAllButton, BorderLayout.NORTH);

         // Enable the termination button:
         this.addWindowListener(new WindowAdapter() {

              @Override
              public void windowClosing(final WindowEvent e) {
                  System.exit(0);
              }
         });

     }
}

2012年7月31日

Mscgen study - Light weight tool to create sequential diagram

http://www.mcternan.me.uk/mscgen/

Sample script:


msc {
  a, "b", c ;

  a->b [ label = "ab()" ] ;
  b->c [ label = "bc(TRUE)"];
  c->c [ label = "process(1)" ];
  c->c [ label = "process(2)" ];
  ...;
  c->c [ label = "process(n)" ];
  c->c [ label = "process(END)" ];
  a<-c [ label = "callback()"];
  ---  [ label = "If more to run", ID="*" ];
  a->a [ label = "next()"];
  a->c [ label = "ac()"];
  b<-c [ label = "cb(TRUE)"];
  b->b [ label = "stalled(...)"];
  a<-b [ label = "ab() = FALSE"];
}



2012年7月27日

Graphviz study note - Powerful graph visualization software to create kind of diagrams

Powerful graph visualization software


1.          Define digraph gr { graph []; }
2.          Define Graph / Node / Edge attributions [fontname, fontsize, style, color, shape, fillcolor, width, height, …]
3.          Define Node / Edge [font, style, color, shape, fillcolor, label, (html table tag), width, …]
4.          Define Subgraphs and Clusters {label, bgcolor, …}
5.          Define Node / Edge relation [dir, color, style, :n|ne|se|…, …]
6.          Relation condition {rank, ordering, …}
7.          Output format

If want to create Sequential Diagram, Mscgen tool may be another good choice.

Reference: