/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * *****************************************************************************/ //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "scatter1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "OlectraChart3D_TLB" #pragma resource "*.dfm" TfrmScatter *frmScatter; //--------------------------------------------------------------------------- __fastcall TfrmScatter::TfrmScatter(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::Chart3D1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) //When the mouse moves over the Chart, see if it is over a data point, and if so, // then show the point's information in the footer. { long Series, Point, Distance; long Region; double Value; char sBuffer[80]; //Indicate in the footer whether the mouse is currently // located over a data point or not Variant vCG = Chart3D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); //Check to make sure that the Data Object is configured as point data //If we don't check this and the data type is grid, then an overflow will occur as there // will be no point data to return Value = vCG1Data.OlePropertyGet("Layout"); if (Value == oc3dDataPoint) { //Get the current location of the mouse Region = vCG1.OleFunction("CoordToDataIndex", X, Y, &Series, &Point, &Distance); //Check to see if the mouse is over the Chart if (Region == oc3dRegionInChartArea) { //If the mouse is over a data point (or at least very close to one), then display which point // it is, and its value in the Footer if ((Series > 0) && (Point > 0) && (Distance <= 5)) { Variant vPointSeries = vCG1Data.OlePropertyGet("PointSeries", Series); Variant vPoint = vPointSeries.OlePropertyGet("Item", Point); Value = vPoint.OlePropertyGet("Z"); sprintf(sBuffer, "Index(%i, %i) = %4.2f", Series, Point, Value); Variant vFooter = Chart3D1->Footer; vFooter.OlePropertySet("Text", sBuffer); } else { Variant vFooter = Chart3D1->Footer; vFooter.OlePropertySet("Text", "Nowhere"); } } } } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::chk2DViewClick(TObject *Sender) //Toggle between the 2D and 3D View. { Variant vCG = Chart3D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vContour = vCG1.OlePropertyGet("Contour"); Variant vElevation = vCG1.OlePropertyGet("Elevation"); //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; if (chk2DView->Checked == true) { vContour.OlePropertySet("IsZoned", true); vElevation.OlePropertySet("IsMeshed", false); } else { vContour.OlePropertySet("IsZoned", false); vElevation.OlePropertySet("IsMeshed", true); } //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::chkDropLinesClick(TObject *Sender) //Toggle the display of Drop Lines. { Variant vCG = Chart3D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vElevation = vCG1.OlePropertyGet("Elevation"); vElevation.OlePropertySet("HasDropLines", chkDropLines->Checked); } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::chkXGridLinesClick(TObject *Sender) //Toggle the display of Grid Lines on the X-Axis. { Variant vCA = Chart3D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); Variant vMGrid = vXAxis.OlePropertyGet("MajorGrid"); //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; vMGrid.OlePropertySet("IsOnXYPlane", chkXGridLines->Checked); vMGrid.OlePropertySet("IsOnXZPlane", chkXGridLines->Checked); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::chkYGridLinesClick(TObject *Sender) //Toggle the display of Grid Lines on the Y-Axis. { Variant vCA = Chart3D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); Variant vMGrid = vYAxis.OlePropertyGet("MajorGrid"); //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; vMGrid.OlePropertySet("IsOnXYPlane", chkYGridLines->Checked); vMGrid.OlePropertySet("IsOnYZPlane", chkYGridLines->Checked); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::chkZGridLinesClick(TObject *Sender) //Toggle the display of Grid Lines on the Z-Axis. { Variant vCA = Chart3D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vZAxis = vAxes.OlePropertyGet("Item", "Z"); Variant vMGrid = vZAxis.OlePropertyGet("MajorGrid"); //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; vMGrid.OlePropertySet("IsOnXZPlane", chkZGridLines->Checked); vMGrid.OlePropertySet("IsOnYZPlane", chkZGridLines->Checked); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::FormCreate(TObject *Sender) //This is where it all begins! { //Start with the form in the top-left corner Top = 5; Left = 5; //Don't show the Chart yet because the configuring of the Chart // will cause it to flicker if it is visible Visible = false; SetupTheChart(); //The Setup of the Chart is complete, so it is ok to make it visible now Visible = true; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::FormResize(TObject *Sender) //Resize the Chart to the width and height of the window. { Chart3D1->Height = ClientHeight - Chart3D1->Top; Chart3D1->Width = ClientWidth; } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::mnuExitClick(TObject *Sender) //End the program. { exit(0); } //--------------------------------------------------------------------------- void TfrmScatter::SetupTheChart() //Do some configuration of the Chart. { double Value; Variant vCG = Chart3D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vCA = Chart3D1->ChartArea_; //Batch the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; //Change some colors Variant vInterior = Chart3D1->Interior_; vInterior.OlePropertySet("BackgroundColor", (int)ocColorAntiqueWhite); Variant vPlotCube = vCA.OlePropertyGet("PlotCube"); vInterior = vPlotCube.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorAliceBlue); //Some basic Chart setup vCG1.OlePropertySet("ChartType", oc3dTypeScatter); Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); vCG1Data.OleFunction("Load", "scatter.dat"); //Setup the Header Variant vHeader = Chart3D1->Header; vHeader.OlePropertySet("Text", "Change the value in the Z-Origin entry field to\nchange where DropLines originate."); Variant vFont = vHeader.OlePropertyGet("Font"); vFont.OlePropertySet("Name", "Arial"); vFont.OlePropertySet("Size", 12); vFont.OlePropertySet("Bold", true); vFont.OlePropertySet("Italic", true); Variant vBorder = vHeader.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderShadow); vBorder.OlePropertySet("Width", 3); vInterior = vHeader.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorCadetBlue); vInterior.OlePropertySet("ForegroundColor", (int)ocColorLemonChiffon); //Temporarily stop batching the updates to the Chart so that the // Header object will get created. If we don't do this, then the // following two lines can not get the size of the legend title // and it will end up in the wrong location. Chart3D1->IsBatched = false; Variant vLocation = vHeader.OlePropertyGet("Location"); Variant vLeft = vLocation.OlePropertyGet("Left"); Variant vWidth = vLocation.OlePropertyGet("Width"); Value = vWidth.OlePropertyGet("Value"); vLeft.OlePropertySet("Value", Chart3D1->Width - Value - 5); Chart3D1->IsBatched = true; //Setup the Footer Variant vFooter = Chart3D1->Footer; vFooter.OlePropertySet("Text", "Nowhere"); vFont = vFooter.OlePropertyGet("Font"); vFont.OlePropertySet("Name", "Arial"); vFont.OlePropertySet("Size", 10); vFont.OlePropertySet("Bold", true); vBorder = vFooter.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorder3DIn); vBorder.OlePropertySet("Width", 3); vInterior = vFooter.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorCadetBlue); vInterior.OlePropertySet("ForegroundColor", (int)ocColorLemonChiffon); //Make some changes to the Axis Style Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); Variant vZAxis = vAxes.OlePropertyGet("Item", "Z"); Variant vMGrid = vXAxis.OlePropertyGet("MajorGrid"); Variant vStyle = vMGrid.OlePropertyGet("Style"); vStyle.OlePropertySet("Color", (int)ocColorMediumBlue); vMGrid = vYAxis.OlePropertyGet("MajorGrid"); vStyle = vMGrid.OlePropertyGet("Style"); vStyle.OlePropertySet("Color", (int)ocColorRed); vMGrid = vZAxis.OlePropertyGet("MajorGrid"); vStyle = vMGrid.OlePropertyGet("Style"); vStyle.OlePropertySet("Color", (int)ocColorOrange); //Add a Legend Variant vLegend = Chart3D1->Legend_; Variant vLabels = vLegend.OlePropertyGet("Labels"); vLabels.OleFunction("Add", "Bats"); vLabels.OleFunction("Add", "Bees"); vLabels.OleFunction("Add", "Birds"); vBorder = vLegend.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderPlain); vBorder.OlePropertySet("Width", 2); vFont = vLegend.OlePropertyGet("Font"); vFont.OlePropertySet("Name", "Arial"); vFont.OlePropertySet("Size", 10); vFont.OlePropertySet("Bold", true); vLegend.OlePropertySet("Anchor", oc3dAnchorNorthWest); //Set the Z-Axis Origin to the value in its related Textbox vZAxis.OlePropertySet("Origin", StrToFloat(txtZOrigin->Text)); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } void __fastcall TfrmScatter::txtZOriginChange(TObject *Sender) //Update the Z-Origin of the Chart. { Variant vCA = Chart3D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vZAxis = vAxes.OlePropertyGet("Item", "Z"); int Size = txtZOrigin->GetTextLen(); if (Size > 0) { if (txtZOrigin->Text != "-") { vZAxis.OlePropertySet("Origin", StrToFloat(txtZOrigin->Text)); } } else vZAxis.OlePropertySet("Origin", 0); } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::txtZOriginKeyPress(TObject *Sender, char &Key) //Limit the entered characters to 0-9, Tab, Backspace, Decimal and Period. { if (((Key < 48) || (Key > 57)) && (Key != 8) && (Key != 9) && (Key != 46) && (Key != 45)) { Key = 0; } } //--------------------------------------------------------------------------- void __fastcall TfrmScatter::txtZOriginExit(TObject *Sender) //Make sure that the number that has been entered is within a valid range. { txtZOrigin->Text = Trim(txtZOrigin->Text); int Size = txtZOrigin->GetTextLen(); if (Size == 0) txtZOrigin->Text = "-2.0"; } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmScatter::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(98); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmScatter::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------