/***************************************************************************** * * 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 #include #include #pragma hdrstop #include "bars1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma link "OlectraChart3D_TLB" #pragma resource "*.dfm" TfrmBars *frmBars; //--------------------------------------------------------------------------- __fastcall TfrmBars::TfrmBars(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- // End the program //--------------------------------------------------------------------------- void __fastcall TfrmBars::mnuExitClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- // Setup the Form and the Chart //--------------------------------------------------------------------------- void __fastcall TfrmBars::FormCreate(TObject *Sender) { //Start with the form in the top-left corner Top = 5; Left = 5; //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; Variant vCG = Chart3D1->ChartGroups; vCG1 = vCG.OleFunction("Item", 1); SetupTheChart(); LastRow = 0; LastCol = 0; PickRow = 0; PickCol = 0; HiLiteColor = ocColorLightSeaGreen; //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- // Setup the Chart //--------------------------------------------------------------------------- void TfrmBars::SetupTheChart() { //Setup the Chart type vCG1.OlePropertySet("ChartType", oc3dTypeBar); //Setup some colors Variant vInterior = Chart3D1->Interior_; vInterior.OlePropertySet("BackgroundColor", (int)ocColorLinen); vInterior.OlePropertySet("ForegroundColor", (int)ocColorBlack); //Setup the borders Variant vBorder = Chart3D1->Border_; vBorder.OlePropertySet("Type", oc3dBorder3DIn); vBorder.OlePropertySet("Width", 2); //Setup the ChartArea Variant vCArea = Chart3D1->ChartArea_; vInterior = vCArea.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorAntiqueWhite); vBorder = vCArea.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderEtchedIn); vBorder.OlePropertySet("Width", 4); Variant vPlotCube = vCArea.OlePropertyGet("PlotCube"); vInterior = vPlotCube.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorLemonChiffon); //Setup the Data group Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); vCG1Data.OlePropertySet("RowCount", 3); vCG1Data.OlePropertySet("ColumnCount", 5); Variant vElevation = vCG1.OlePropertyGet("Elevation"); vElevation.OlePropertySet("IsShaded", true); //Setup the Scale vPlotCube.OlePropertySet("XScale", 200); vPlotCube.OlePropertySet("YScale", 200); //Setup the Axes Variant vAxes = vCArea.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); Variant vZAxis = vAxes.OlePropertyGet("Item", "Z"); Variant vAnnoFont = vXAxis.OlePropertyGet("AnnotationFont"); vAnnoFont.OlePropertySet("Type", oc3dRomanSimplex); vAnnoFont.OlePropertySet("Size", 60); Variant vTitle = vXAxis.OlePropertyGet("Title"); vTitle.OlePropertySet("Text", "Rows"); vTitle = vYAxis.OlePropertyGet("Title"); vTitle.OlePropertySet("Text", "Columns"); Variant vTitleFont = vXAxis.OlePropertyGet("TitleFont"); vTitleFont.OlePropertySet("Type", oc3dRomanTriplex); vTitleFont.OlePropertySet("Size", 100); //Turn on all the grid lines Variant vXAxisMGrid = vXAxis.OlePropertyGet("MajorGrid"); Variant vYAxisMGrid = vYAxis.OlePropertyGet("MajorGrid"); Variant vZAxisMGrid = vZAxis.OlePropertyGet("MajorGrid"); vXAxisMGrid.OlePropertySet("IsOnXYPlane", true); vXAxisMGrid.OlePropertySet("IsOnXZPlane", true); vYAxisMGrid.OlePropertySet("IsOnXYPlane", true); vYAxisMGrid.OlePropertySet("IsOnYZPlane", true); vZAxisMGrid.OlePropertySet("IsOnXZPlane", true); vZAxisMGrid.OlePropertySet("IsOnYZPlane", true); //Setup the Header Variant vHeader = Chart3D1->Header; Variant vText = vHeader.OlePropertyGet("Text"); vText.OlePropertySet("Text", "Change the value of\nany bar by dragging it!"); vBorder = vHeader.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderEtchedOut); vBorder.OlePropertySet("Width", 4); vInterior = vHeader.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorLightGoldenrod); Variant vFont = vHeader.OlePropertyGet("Font"); vFont.OlePropertySet("Size", 14); vFont.OlePropertySet("Bold", true); //Setup the Footer Variant vFooter = Chart3D1->Footer; vText = vFooter.OlePropertyGet("Text"); vText.OlePropertySet("Text", "No Bar Selected"); vBorder = vFooter.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderShadow); vBorder.OlePropertySet("Width", 4); vInterior = vFooter.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorBlanchedAlmond); vFooter.OlePropertySet("Font", "Times New Roman"); vFont = vFooter.OlePropertyGet("Font"); vFont.OlePropertySet("Size", 12); //Add the colors to the bars and do the entire column for each row Variant vBar = vCArea.OlePropertyGet("Bar"); Variant vColors = vBar.OlePropertyGet("Colors"); vColors.OleFunction("Add", 1, 0, (int)ocColorBeige); vColors.OleFunction("Add", 2, 0, (int)ocColorBlanchedAlmond); vColors.OleFunction("Add", 3, 0, (int)ocColorTan); vInterior = vHeader.OlePropertyGet("Interior"); HeaderColor = vInterior.OlePropertyGet("BackgroundColor"); vInterior = vFooter.OlePropertyGet("Interior"); FooterColor = vInterior.OlePropertyGet("BackgroundColor"); } //--------------------------------------------------------------------------- // Update the information in the Footer //--------------------------------------------------------------------------- void TfrmBars::UpdateTheFooter(int Row, int Col) { //Update the Footer with info about where the mouse is Variant Value, vRow(Row), vCol(Col); double dblValue; char sBuffer[80]; if ((Row > 0) && (Col > 0)) { Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); Value = vCG1Data.OlePropertyGet("Value", vRow, vCol); dblValue = Value.VDouble; sprintf(sBuffer, "Bar Index(%i, %i) = %4.1f", Row, Col, dblValue); Variant vFooter = Chart3D1->Footer; vFooter.OlePropertySet("Text", sBuffer); } else { Variant vFooter = Chart3D1->Footer; vFooter.OlePropertySet("Text", "No Bar Selected"); } } //--------------------------------------------------------------------------- // Respond to the user pressing the Left-Mouse button while over the Chart //--------------------------------------------------------------------------- void __fastcall TfrmBars::Chart3D1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { //When the mouse button goes down, note that and set some variables int Row, Col, Distance; Region = vCG1.OlePropertyGet("CoordToDataIndex", X, Y, &Row, &Col, &Distance); if (Region == oc3dRegionInChartArea) { //Check to make sure it was the left button pressed and make sure we are very close to a bar if ((Button == mbLeft) && (Distance < 5)) { //Store the Row and Column for use Later PickRow = Row; PickCol = Col; } } } //--------------------------------------------------------------------------- // Respond to the user moving the mouse over the Chart //--------------------------------------------------------------------------- void __fastcall TfrmBars::Chart3D1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { //Watch the movement of the mouse and either highlight a Region or update a bar //that is being dragged to a new value double Value; Variant vValue; int Row, Col, Distance; Variant vCArea = Chart3D1->ChartArea_; Variant vBar = vCArea.OlePropertyGet("Bar"); Variant vColors = vBar.OlePropertyGet("Colors"); //Store the current Region OldRegion = Region; //Check to see if we are dragging a bar, if so update the bar to its new value if ((PickRow != 0) && (PickCol != 0)) { //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; vValue = vCG1.OleFunction("DragZValue", PickRow, PickCol, X, Y); Value = vValue.VDouble; //Limit the new values to be great than -15 and less than 15 if (Value > 15) { Value = 15; } if (Value < -15) { Value = -15; } Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); vCG1Data.OlePropertySet("Value", PickRow, PickCol, Value); UpdateTheFooter(PickRow, PickCol); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } else { //Find out where the mouse is Region = vCG1.OleFunction("CoordToDataIndex", X, Y, &Row, &Col, &Distance); //The mouse is over one of the two regions, so highlight it if (((Region == oc3dRegionInHeader) || (Region == oc3dRegionInFooter)) && (Region != OldRegion)) { if (Region == oc3dRegionInHeader) { RemoveHiLite(); RegionSaveColor = HeaderColor; Variant vHeader = Chart3D1->Header; vTitleInterior = vHeader.OlePropertyGet("Interior"); AddHiLite(X, Y); } else { RemoveHiLite(); RegionSaveColor = FooterColor; Variant vFooter = Chart3D1->Footer; vTitleInterior = vFooter.OlePropertyGet("Interior"); AddHiLite(X, Y); } } else { //The mouse is not on the Chart, so reset the last bar color and update the footer if ((Region != oc3dRegionInChartArea) || (Row <= 0) || (Col <= 0) || (Distance != 0)) { Row = 0; Col = 0; if ((LastRow > 0) && (LastCol > 0)) { vColors.OleFunction("Remove", LastRow, LastCol); } LastRow = 0; LastCol = 0; UpdateTheFooter(Row, Col); } else { //We are on the Chart and on a different bar, so update everything accordingly if ((Row != LastRow) || (Col != LastCol)) { //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; if ((LastRow > 0) && (LastCol > 0)) { vColors.OleFunction("Remove", LastRow, LastCol); } if ((Row > 0) && (Col > 0)) { vColors.OleFunction("Add", Row, Col, HiLiteColor); } UpdateTheFooter(Row, Col); //Store the current Row and Column LastRow = Row; LastCol = Col; //Resume regular updates to the Chart Chart3D1->IsBatched = false; } } } } } //--------------------------------------------------------------------------- // Respond to the user letting the Left-Mouse button go while over the Chart //--------------------------------------------------------------------------- void __fastcall TfrmBars::Chart3D1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { //Reset the previously selected Row and Column to none PickRow = 0; PickCol = 0; } //--------------------------------------------------------------------------- // Add a 'HiLite' to the Header/Footer when the user moves the mouse over either of them //--------------------------------------------------------------------------- void TfrmBars::AddHiLite(int px, int py) { //Add a Highlight to the header/footer when the mouse passes over it int LabelHiLiteColor, Location1, Location2, Total; Variant cLabel; Variant vBorder; Variant vInterior; //Setup the Highlight color ahead of time LabelHiLiteColor = ocColorRosyBrown; //Check to make sure we are in one of the two Regions if ((Region == oc3dRegionInFooter) || (Region == oc3dRegionInHeader)) { //Make sure that we are not over the same region we were before if (vTitleInterior.VType != varEmpty) { vTitleInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); } } if ((Region == oc3dRegionInFooter) || (Region == oc3dRegionInHeader)) { //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; if (Region == oc3dRegionInHeader) { Variant vHeader = Chart3D1->Header; Variant vInterior = vHeader.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); Variant vCLabels = Chart3D1->ChartLabels; cLabel = vCLabels.OleFunction("Add"); cLabel.OlePropertySet("IsBatched", true); cLabel.OlePropertySet("AttachMethod", oc3dAttachCoord); cLabel.OlePropertySet("Text", "Thats's The Header!"); Variant vLocation = vHeader.OlePropertyGet("Location"); Variant vLocationLeft = vLocation.OlePropertyGet("Left"); Location1 = vLocationLeft.OlePropertyGet("Value"); Variant vLocationWidth = vLocation.OlePropertyGet("Width"); Location2 = vLocationWidth.OlePropertyGet("Value"); Total = Location1 + Location2; Variant vAttachCoord = cLabel.OlePropertyGet("AttachCoord"); vAttachCoord.OlePropertySet("X", Total); Variant vLocationTop = vLocation.OlePropertyGet("Top"); Location1 = vLocationTop.OlePropertyGet("Value"); Variant vLocationHeight = vLocation.OlePropertyGet("Height"); Location2 = vLocationHeight.OlePropertyGet("Value"); Total = Location1 + Location2; vAttachCoord.OlePropertySet("Y", Total); cLabel.OlePropertySet("VerticalOffset", 25); cLabel.OlePropertySet("HorizontalOffset", 25); vTitleInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); } if (Region == oc3dRegionInFooter) { Variant vFooter = Chart3D1->Footer; Variant vInterior = vFooter.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); Variant vCLabels = Chart3D1->ChartLabels; cLabel = vCLabels.OleFunction("Add"); cLabel.OlePropertySet("IsBatched", true); cLabel.OlePropertySet("AttachMethod", oc3dAttachCoord); cLabel.OlePropertySet("Text", "Thats's The Footer!"); Variant vLocation = vFooter.OlePropertyGet("Location"); Variant vLocationLeft = vLocation.OlePropertyGet("Left"); Location1 = vLocationLeft.OlePropertyGet("Value"); Variant vLocationWidth = vLocation.OlePropertyGet("Width"); Location2 = vLocationWidth.OlePropertyGet("Value"); Total = Location1 + Location2; Variant vAttachCoord = cLabel.OlePropertyGet("AttachCoord"); vAttachCoord.OlePropertySet("X", Total); Variant vLocationTop = vLocation.OlePropertyGet("Top"); Total = vLocationTop.OlePropertyGet("Value"); vAttachCoord.OlePropertySet("Y", Total); cLabel.OlePropertySet("VerticalOffset", -25); cLabel.OlePropertySet("HorizontalOffset", 25); vTitleInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); } cLabel.OlePropertySet("Name", "Region"); vBorder = cLabel.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc3dBorderShadow); vBorder.OlePropertySet("Width", 4); cLabel.OlePropertySet("IsConnected", true); vInterior = cLabel.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", LabelHiLiteColor); cLabel.OlePropertySet("IsBatched", false); cLabel.Clear(); //Resume regular updates to the Chart Chart3D1->IsBatched = false; Timer1->Interval = 1500; Timer1->Enabled = true; } } //--------------------------------------------------------------------------- // Remove the 'HiLite' from the Header/Footer //--------------------------------------------------------------------------- void TfrmBars::RemoveHiLite() { //Remove the HiLite Color and Label from the Header/Footer RemoveLabel(); Timer1Timer(Timer1); Timer1->Interval = 0; Timer1->Enabled = false; } //--------------------------------------------------------------------------- // Remove the Label that is a part of the 'HiLite' //--------------------------------------------------------------------------- void TfrmBars::RemoveLabel() { Variant vCLabels = Chart3D1->ChartLabels; //Remove the label from the Header/Footer if (vCLabels.OlePropertyGet("Count") > 0) { //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; vCLabels.OleFunction("Remove", "Region"); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } } //--------------------------------------------------------------------------- // Remove the 'HiLite' after a period of time has elapsed //--------------------------------------------------------------------------- void __fastcall TfrmBars::Timer1Timer(TObject *Sender) { //When the Timer fires, remove the HiLite from the Header/Footer //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; RemoveLabel(); Timer1->Interval = 0; Timer1->Enabled = false; if (vTitleInterior.VType != varEmpty) { vTitleInterior.OlePropertySet("BackgroundColor", RegionSaveColor); } //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- // Release memory before we exit //--------------------------------------------------------------------------- void __fastcall TfrmBars::FormDestroy(TObject *Sender) { //Empty the Variant to give back its memory before we exit vTitleInterior.Clear(); vCG1.Clear(); } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmBars::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(12); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmBars::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Change the fonts to Stroke Fonts //--------------------------------------------------------------------------- void __fastcall TfrmBars::mnuStrokeFontsClick(TObject *Sender) { if (mnuStrokeFonts->Checked == False) { mnuStrokeFonts->Checked = true; mnuTrueTypeFonts->Checked = false; Chart3D1->UseTrueType = false; } } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Change the fonts to TrueType //--------------------------------------------------------------------------- void __fastcall TfrmBars::mnuTrueTypeFontsClick(TObject *Sender) { if (mnuTrueTypeFonts->Checked == False) { mnuTrueTypeFonts->Checked = true; mnuStrokeFonts->Checked = false; Chart3D1->UseTrueType = true; } } //---------------------------------------------------------------------------