public static class KVPair<K,V> { private K key; private V value; public KVPair(){} public KVPair(K key, V value){ this.key = key; this.value = value; } public K getKey() { return key; } public void setKey(K key) { this.key = key; } public V getValue() {
var themes = {
simple : RaphaelTheme,
hand : HandRaphaelTheme
};
Diagram.prototype.drawSVG = function (container, options) {
var default_options = {
theme: 'hand'
};
options = _.defaults(options || {}, default_options);
if (!(options.theme in themes))
throw new Error("Unsupported theme: " + options.theme);
var drawing = new themes[options.theme](this);
drawing.draw(container);
}; // end of drawSVG
drawSVG是最外层JS要画图调用的方法。例如:
<div id="diagram">Diagram will be placed here</div>
<script src="sequence-diagram-min.js"></script>
<script>
var diagram = Diagram.parse("A->B: Does something");
diagram.drawSVG('diagram');
</script>
下面就可以画出图形。所以drawSVG是核心入口。
drawSVG的实现过程中,最重要的一句:
drawing.draw(container);
这一句调用的draw function定义如下:
draw : function(container) {
var diagram = this.diagram;
this.init_paper(container);
this.init_font();
this.layout();
var title_height = this._title ? this._title.height : 0;
this._paper.setStart();
this._paper.setSize(diagram.width, diagram.height);
var y = DIAGRAM_MARGIN + title_height;
this.draw_title();
this.draw_actors(y);
this.draw_signals(y + this._actors_height);
this._paper.setFinish();
},