Skip to content
Shim Heungwoon edited this page May 27, 2016 · 24 revisions

Graphite View

Major Classes

GraphicContainer

  • GraphicContainer wraps and manages a given HTMLElement which will contain graphical contents.
interfaceGraphicContainer{voidsetElement(HTMLElementelement);HTMLElementgetElement();voidsetContents(Widgetcontents);WidgetgetContents();voidsetGraphicContextFactory(GraphicContextFactoryFactory);GraphicContextFactorygetGraphicContextFactory();GraphicContextgraphicContext();};
 GraphicContainer knows
1. What element contains(wraps) graphical contents
2. How to append user's content
3. How to construct graphical context(layers)
4. How to get graphical context
<divid='container'></div>
//Pseudo code.varelement=document.getElementById('container');varcontainer=newGraphicContainer(element,GraphicContextFactory);
  • GraphicContainer provides a way to add user's content root.
//Pseudo code.varuserContentRoot=newSomeWidget();container.setContents(userContentRoot);
  • GraphicContainer should create and return GraphicContext.
//Pseudo code.vargraphicContext=container.getGraphicContext();

GraphicContext

  • GraphicContext is a place which user's contents will be painted.
interfaceGraphicContext{voidsetLayer(Stringid,Layerlayer);LayergetLayer(Stringid);voidroot(WidgetcontextRoot);Widgetroot();voidsetEventReceiver(HTMLElementreceiver);HTMLElementgetEventReceiver();voidsetContents(Widgetcontents);voidsetContentsMapRule(Maprule);};
  • GraphicContext provides ways to access specific graphic contexts such as svg, document, connection, grid, feedback, guide, handle, mask, viewport and any user defined graphic context.
varsvgLayer=graphicContext.getLayer('SVG_LAYER');varrect=newRect();svgLayer.append(rect);
  • getEventReceiver() method returns HTML Element, which receives all the events occurred on GraphicContext.
//Pseudo code.varreceiver=context.getEventReceiver();receiver.addEventListener();//This is just an example, you don't need to do this,//graphite automatically listens events from receiver.
  • GraphicContext can be configured by user defined GraphicContextFactory. Without user defined GraphicContextFactory, GraphicContainer makes default contexts(layers) using DefaultGraphicContextFactory. image

GraphicContextFactory

  • GraphicContextFactory constructs a structure for GraphicContext.
interfaceGraphicContextFactory{GraphicContextcreateGraphicContext();};
  • Basically and internally, DefaultGraphicContextFactory will be used.
  • If you need custom layer structure for GraphicContext, you can make your own GraphicContextFactory.
varshell=newGraphiteShell('container',SomeGraphicContextFactory);
  • GraphicContextFactory should inherits GraphicContextFactory abstract constructor.