in my unit Application i created a Diagram Component, based on the climate cabinet example.
This is the Update Layout method, it resize the graph labels, lines etc... the temperature lines are referred to a heating program saved in another part of the gui.
I also placed a StrokePath on the graph to display a temperature, with the TempPath
super( aSize );
/* calculate upper and lower position according size of wiper */
var int32 y1 = WallpaperTop.Bitmap.FrameSize.y;
var int32 y2 = aSize.y - WallpaperBottom.Bitmap.FrameSize.y;
/* arrange wallpapers and diagram */
WallpaperTop.Bounds = rect( 0, 0, aSize.x, y1 );
WallpaperBottom.Bounds = rect( 0, y2, aSize.x, aSize.y );
Graph.Bounds = rect( 2 * Application::Spacing.x, y1, aSize.x - Application::Spacing.x, y2 - Application::Spacing.y );
StrokePath.Bounds = Graph.Bounds;
StrokePath.Bounds.origin = Graph.Bounds.origin;
TempPath.InitSubPath( 0, Graph.Bounds.w); //setto il path in modo da poter tenere tanti oggetti quanti sono i pixel del grafico
TempPath.Begin(0, 0 , 0);
Rectangle.Bounds = rect( 0, y1, aSize.x, y2 );
/* arrange left scaling text */
var rect r = rect( 0, y1, 2 * Application::Spacing.x - 3, y1 + Application::Spacing.y );
UnitC.Bounds = r;
C4.Bounds = r;
C3.Bounds = r;
C2.Bounds = r;
C1.Bounds = r;
/* arrange lower scaling text */
r = rect( aSize.x - Application::Spacing.x - 3 * Application::Spacing.x, y2 - Application::Spacing.y, aSize.x - Application::Spacing.x, y2 );
UnitT.Bounds = r;
T4.Bounds = r;
T3.Bounds = r;
T2.Bounds = r;
T1.Bounds = r;
This the update view method.
aState;
var int32 rangeTime = totalTime;
var int32 totalTimems = totalTime*1000;
/* adjust scale text */
T1.String = string( rangeTime / 5 * 1 ) + UnitX;
T2.String = string( rangeTime / 5 * 2 ) + UnitX;
T3.String = string( rangeTime / 5 * 3 ) + UnitX;
T4.String = string( rangeTime / 5 * 4 ) + UnitX;
UnitT.String =string ( totalTime) + UnitX;
C0.String = string(MinY) + UnitY;
C1.String = string(MinY+( (MaxY-MinY) / 5 * 1 )) + UnitY;
C2.String = string(MinY+( (MaxY-MinY) / 5 * 2 )) + UnitY;
C3.String = string(MinY+( (MaxY-MinY) / 5 * 3 )) + UnitY;
C4.String = string(MinY+( (MaxY-MinY) / 5 * 4 )) + UnitY;
UnitC.String = string( MaxY) + UnitY;
//creazionde della linea di pocesso... le coordinate sono relative quindi x=0 conincide con tempo 0
var Charts::CoordList coords = new Charts::CoordList;
var float x1 = (float)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].DelayTime )/ (float)rangeTime;
var float x2 = (float)((Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].DelayTime) + (Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PreTime)) / (float)rangeTime;
var float x3 = (float)((Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].DelayTime) + (Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PreTime)+(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].Time)) / (float)rangeTime;
var float x4 = (float)((Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].DelayTime) + (Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PreTime)+(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].Time)+(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PostTime)) / (float)rangeTime;
var float y1 = (float)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndex].PreTemp - MinY ) / (MaxY - MinY);
var float y2 = (float)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndex].Temp - MinY ) / (MaxY - MinY);
var float y3 = (float)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndex].PostTemp - MinY ) / (MaxY - MinY);
coords.AddCoord( 0,0 );
coords.AddCoord( x1,0 );
coords.AddCoord( x1,y1);
coords.AddCoord( x2,y1);
coords.AddCoord( x2,y2);
coords.AddCoord( x3,y2);
coords.AddCoord( x3,y3);
coords.AddCoord( x4,y3);
coords.AddCoord( x4,0);
coords.AddCoord( 1,0);
/* configure diagram */
var point grid = point( Graph.Bounds.w / 5, Graph.Bounds.h / 5);
Graph.GridDistance = grid;
Graph.CoordOrigin = point( 0, Graph.Bounds.h );
Graph.PixelPerUnit = point( Graph.Bounds.w, -Graph.Bounds.h );
Graph.Coordinates = coords;
/*calcolo della posizione della barra e testo per temperatura massima*/
var int32 MaxTempPos = Graph.Bounds.y2 - ((int32) Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].MaxTempReach1 - MinY) * Graph.Bounds.h / (MaxY-MinY);
MaxTempBar.Bounds = rect( Graph.Bounds.x1, MaxTempPos - 1, Graph.Bounds.x2, MaxTempPos + 1 );
MaxTempText.String = string( Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].MaxTempReach1,0,1 )+"°C";
MaxTempText.Bounds.origin = point( MaxTempBar.Bounds.x2 - MaxTempText.Bounds.w, MaxTempPos - MaxTempText.Bounds.h );
//calcolo delle coordinate per centrare il testo della temperatura per fase
var int32 centerXHeatTemp= Graph.Bounds.x1 + (int32)((x2+((x3-x2)/(float)2))*Graph.Bounds.w);
var int32 centerYHeatTemp = (int32)(Graph.Bounds.y2 - y2*Graph.Bounds.h);
TempText.String = string(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].Temp) + "°C";
TempText.Bounds.origin = point( centerXHeatTemp - TempText.Bounds.w / 2, centerYHeatTemp - TempText.Bounds.h );
var int32 centerXPreHeatTemp= Graph.Bounds.x1 + (int32)((x1+((x2-x1)/(float)2))*Graph.Bounds.w);
var int32 centerYPreHeatTemp = (int32)(Graph.Bounds.y2 - y1*Graph.Bounds.h);
PreTempText.String = string(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PreTemp) + "°C";
PreTempText.Bounds.origin = point( centerXPreHeatTemp - TempText.Bounds.w / 2, centerYPreHeatTemp - TempText.Bounds.h );
var int32 centerXPostHeatTemp= Graph.Bounds.x1 + (int32)((x3+((x4-x3)/(float)2))*Graph.Bounds.w);
var int32 centerYPostHeatTemp = (int32)(Graph.Bounds.y2 - y3*Graph.Bounds.h);
PostTempText.String = string(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PostTemp) + "°C";
PostTempText.Bounds.origin = point( centerXPostHeatTemp - PostTempText.Bounds.w / 2, centerYPostHeatTemp - PostTempText.Bounds.h );
/* calculate position of dashed lines */
VertPreHeatLine.Visible=false;
HeatLine.Visible=false;
/*
VertPreHeatLine.Bounds.x1 = Graph.Bounds.x1 + (((int32)Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndex].PreTime) * Graph.Bounds.w / rangeTime);
VertPreHeatLine.Bounds.x2 = VertPreHeatLine.Bounds.x1 + 2;
VertPreHeatLine.Bounds.y1 = centerY + 10;
VertPreHeatLine.Bounds.y2 = Graph.Bounds.y2;
*/
VertPostHeatlLine.Bounds.x1 = Graph.Bounds.x1 + ((int32)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].TimeTempReach1* Graph.Bounds.w / rangeTime));
VertPostHeatlLine.Bounds.x2 = VertPostHeatlLine.Bounds.x1 + 2;
VertPostHeatlLine.Bounds.y1 = Graph.Bounds.y1;
VertPostHeatlLine.Bounds.y2 = Graph.Bounds.y2;
DwellText.String = string(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndex].TimeTempReach1) + " s";
DwellText.Bounds.origin = point( VertPostHeatlLine.Bounds.x1 - DwellText.Bounds.w / 2, Graph.Bounds.y - DwellText.Bounds.h+10 );
/* arrange scale text items */
T1.Bounds.origin.x = Graph.Bounds.x1 + grid.x - T1.Bounds.w / 2;
T2.Bounds.origin.x = T1.Bounds.x1 + grid.x;
T3.Bounds.origin.x = T2.Bounds.x1 + grid.x;
T4.Bounds.origin.x = T3.Bounds.x1 + grid.x;
C4.Bounds.origin.y = Graph.Bounds.y1 + grid.y - C4.Bounds.h / 2;
C3.Bounds.origin.y = C4.Bounds.y1 + grid.y;
C2.Bounds.origin.y = C3.Bounds.y1 + grid.y;
C1.Bounds.origin.y = C2.Bounds.y1 + grid.y;
/* adjust running bar */
RunningBar.Visible = (Application::Device.StartCycle);
RunningBar.Bounds.origin = point( Graph.Bounds.x1 + (totalTimems - ((int32)Application::Device.RemainingTime)) * Graph.Bounds.w / totalTimems, Graph.Bounds.y1 );
When i place this component in another GUI component, i put some initial values just to have them shown if the graph is working:
this the init method of this GUI component, that assigns the values to the TempPath path in the windows object, not the TempPath of the diagram object placed in the window.
I'm scaling the number of temperature values, that are often more than the pixel count of the graph, in a way that every pixel on the graph has a temperature value; so the while cycle through every pixel adding the temperature value to the line, showing the last value of the range of values in the array assigned to that single pixel.
DiagramTemperature is the name of the component imported in the window
// TO DO: Write your code here ...
DiagramTemperature.totalTime = (int32) (Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].DelayTime+Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PreTime+Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].Time+Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].PostTime +Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].CoolingDelayTime+Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].CoolingTime);
TempPath.InitSubPath( 0, DiagramTemperature.Graph.Bounds.w); //setto il path in modo da poter tenere tanti oggetti quanti sono i pixel del grafico
TempPath.Begin(0, 0 , 0);
DiagramTemperature.StrokePath.Path = TempPath;
var int32 i = 0;
while (i<=DiagramTemperature.Graph.Bounds.w)
{
TempPath.AddLine(0, i , (Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].TemperatureValues1[(int32)((float)i*(float)(Application::GlobalSettings.ReceiptArray[Application::GlobalSettings.SelectedProgramIndexHead1].TempPointsNumber1-1)/(float)DiagramTemperature.Graph.Bounds.w)]-DiagramTemperature.MinY) *((float)DiagramTemperature.Graph.Bounds.h/(float)(DiagramTemperature.MaxY-DiagramTemperature.MinY)));
i++;
}
So, i'm having trouble getting the correct size of the Diagram i have in the window, that is resized from the original graph.
When i call DiagramTemperature.Graph.Bounds.w and DiagramTemperature.Graph.Bounds.h i do not the the values of the diagram placed in the window but i get the one of the original Component, so scaling of the Path values get incorrect
Also, i'm not able to assign the temperature value to the path in the DiagramTemperature.TempPath.AddLine, but i have to create a path in the window component and assign it to the StrokePath in the Diagram Component.
This is the result.
Hope to have clarify,