/****************************************************************************
**
** This file is part of yFiles FLEX 1.6.
**
** yWorks proprietary/confidential. Use is subject to license terms.
**
** Unauthorized redistribution of this file or of a byte-code version
** of this file is strictly forbidden.
**
** Copyright (c) 2006 - 2011 by yWorks GmbH, Vor dem Kreuzberg 28,
** 72070 Tuebingen, Germany. All rights reserved.
**
***************************************************************************/
package demo.orgchart {
import demo.orgchart.component.OrgChartCanvasComponent;
import mx.graphics.SolidColor;
import com.yworks.graph.drawing.ShapeNodeStyle;
import com.yworks.canvas.drawing.IPaintable;
import com.yworks.graph.drawing.INodeStyle;
import com.yworks.graph.model.INode;
import com.yworks.canvas.drawing.IPaintContext;
import com.yworks.canvas.drawing.YGraphics;
import com.yworks.graph.model.IGraph;
import com.yworks.graph.drawing.OverviewGraphPaintable;
/**
* A custom graph overview that visualizes the nodes in a color according to the status attribute of
* their corresponding XML
node.
*/
public class OrgChartOverviewGraphPaintable extends OverviewGraphPaintable{
protected var _graph:IGraph;
protected var _canvas:OrgChartCanvasComponent;
private static var _statusColorMap:Object = {
離席中: new SolidColor(PersonNode.STATUS_COLORS[ '離席中' ]),
会議: new SolidColor(PersonNode.STATUS_COLORS[ '会議' ]),
病欠: new SolidColor(PersonNode.STATUS_COLORS[ '病欠' ]),
出勤: new SolidColor(PersonNode.STATUS_COLORS[ '出勤' ]),
出張: new SolidColor(PersonNode.STATUS_COLORS[ '出張' ]),
確認中: new SolidColor(PersonNode.STATUS_COLORS[ '確認中' ])
}
/**
* Creates a new instance for the given graph.
*/
public function OrgChartOverviewGraphPaintable( graph:IGraph, canvas:OrgChartCanvasComponent ) {
super(graph);
this._graph = graph;
this._canvas = canvas;
}
/**
* Callback that paints the node.
* @param g the graphics context.
* @param ctx the paint context.
* @param node The node to paint.
*/
override protected function paintNode( g:YGraphics, ctx:IPaintContext, node:INode ):void {
var style:INodeStyle = getOverviewNodeStyle( node );
//ShapeNodeStyle(style).fill(null);
var paintable:IPaintable = style.styleRenderer.getPaintable( node, style );
if( null != paintable ) {
paintable.paint( g, ctx );
}
}
/**
* Callback that returns and/or configures a node style for the given node to render.
* @param node The node to render.
* @return The style or null
*/
override protected function getOverviewNodeStyle( node:INode ):INodeStyle {
var nodeStyle:ShapeNodeStyle = overviewNodeStyle as ShapeNodeStyle;
var xmlData:XML = this._canvas.node2xmlNode(node);
if (nodeStyle != null
&& xmlData != null) {
nodeStyle.fill = OrgChartOverviewGraphPaintable.statusColorMap[xmlData.@status];
return nodeStyle;
}
return overviewNodeStyle;
}
public static function get statusColorMap():Object {
return _statusColorMap;
}
}
}