📄 swarm.overview.mag4.build-graph.sect1.html
字号:
<HTML><HEAD><TITLE>Building a Data Graph</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.53"><LINKREL="HOME"TITLE="Documentation Set for Swarm 2.1.1"HREF="set.html"><LINKREL="UP"TITLE="Mag 4x:Sketch of Code "HREF="swarm.overview.mag4.chapter.html"><LINKREL="PREVIOUS"TITLE="Building a Graphical Observer Swarm"HREF="swarm.overview.mag4.build-observer.sect1.html"><LINKREL="NEXT"TITLE="The main() function"HREF="swarm.overview.mag4.main-func.sect1.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Documentation Set for Swarm 2.1.1</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="swarm.overview.mag4.build-observer.sect1.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 4. Mag 4x:Sketch of Code</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="swarm.overview.mag4.main-func.sect1.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SWARM.OVERVIEW.MAG4.BUILD-GRAPH.SECT1">4.7. Building a Data Graph</A></H1><P>An example of an object inside the HeatbugObserverSwarm is a data graph, the graph of average unhappiness. Here is the code necessary to create that object:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">// Create the graph widget to display unhappiness.unhappyGraph = [EZGraph createBegin: [self getZone]];[unhappyGraph setTitle: "Unhappiness of bugs vs. time"];[unhappyGraph setAxisLabelsX: "time" Y: "unhappiness"];unhappyGraph = [unhappyGraph createEnd] ;[unhappyGraph createAverageSequence: "unhappiness" withFeedFrom: [heatbugModelSwarm getHeatbugList] andSelector: M(getUnhappiness)] ;</PRE></TD></TR></TABLE><P>The first step is to build an instance of an EZGraph and set its captions. Then a Sequence is created inside that graph (in this case, an AverageSequence). In general, the Sequence requires a target object and a message with which to extract data from that object -- the data is then plotted as one line in the graph.</P><P>In the case of an AverageSequence, an entire collection of objects is presented to it. The AverageSequence then extracts data from all the objects in the collection (in this case a List) using the provided message (in this case <TTCLASS="LITERAL">getUnhappiness</TT>), and generate a datapoint from these values by averaging them.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="swarm.overview.mag4.build-observer.sect1.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="set.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="swarm.overview.mag4.main-func.sect1.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Building a Graphical Observer Swarm</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="swarm.overview.mag4.chapter.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">The main() function</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -