Skip to content

GridUnitType

enum cAlgo.API

DesktopCLICloud

Represents the type of the grid unit.

Definition

public enum GridUnitType

Namespace: cAlgo.API · Group: Grid

Examples

using cAlgo.API;

namespace cAlgo
{
    // This sample shows how to use GridUnitType
    public partial class GridUnitTypeSample : Indicator
    {
        protected override void Initialize()
        {
            var grid = new Grid(2, 2)
            {
                BackgroundColor = Color.Gold,
                Opacity = 0.6,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                ShowGridLines = true,
            };
            for (int iRow = 0; iRow < 2; iRow++)
            {
                var row = grid.Rows[iRow];
                SetGridRowLength(row);
                for (int iColumn = 0; iColumn < 2; iColumn++)
                {
                    var column = grid.Columns[iColumn];
                    SetGridColumnLength(column);
                    grid.AddChild(new TextBlock
                    {
                        Text = string.Format("Row {0} and Column {1}", iRow, iColumn),
                        Margin = 5,
                        ForegroundColor = Color.Black,
                        FontWeight = FontWeight.ExtraBold
                    }, iRow, iColumn);
                }
            }
            Chart.AddControl(grid);
        }

        private void SetGridRowLength(GridRow row)
        {
            switch (GridRowLengthUnitType)
            {
                case GridUnitType.Auto:
                    row.SetHeightToAuto();
                    break;

                case GridUnitType.Pixel:
                    row.SetHeightInPixels(GridRowLength);
                    break;

                case GridUnitType.Star:
                    row.SetHeightInStars(GridRowLength);
                    break;
            }
        }

        private void SetGridColumnLength(GridColumn column)
        {
            switch (GridColumnLengthUnitType)
            {
                case GridUnitType.Auto:
                    column.SetWidthToAuto();
                    break;

                case GridUnitType.Pixel:
                    column.SetWidthInPixels(GridColumnLength);
                    break;

                case GridUnitType.Star:
                    column.SetWidthInStars(GridColumnLength);
                    break;
            }
        }

        public override void Calculate(int index)
        {
        }
    }
}
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def initialize(self):
        grid = Grid(2, 2)
        grid.BackgroundColor = Color.Gold
        grid.Opacity = 0.6
        grid.HorizontalAlignment = HorizontalAlignment.Center
        grid.VerticalAlignment = VerticalAlignment.Center
        grid.ShowGridLines = True

        for iRow in range(2):
            row = grid.Rows[iRow]

            self.set_grid_row_length(row)

            for iColumn in range(2):
                column = grid.Columns[iColumn]

                self.set_grid_column_length(column)

                textBlock = TextBlock()
                textBlock.Text = f"Row {iRow} and Column {iColumn}"
                textBlock.Margin = Thickness(5)
                textBlock.ForegroundColor = Color.Black
                textBlock.FontWeight = FontWeight.ExtraBold

                grid.AddChild(textBlock, iRow, iColumn)

        api.Chart.AddControl(grid)

    def set_grid_row_length(self, row):
        match api.GridRowLengthUnitType:
            case GridUnitType.Auto:
                row.SetHeightToAuto()
            case GridUnitType.Pixel:
                row.SetHeightInPixels(api.GridRowLength)
            case GridUnitType.Star:
                row.SetHeightInStars(api.GridRowLength)

    def set_grid_column_length(self, column):
        match api.GridColumnLengthUnitType:
            case GridUnitType.Auto:
                column.SetWidthToAuto()
            case GridUnitType.Pixel:
                column.SetWidthInPixels(api.GridColumnLength)
            case GridUnitType.Star:
                column.SetWidthInStars(api.GridColumnLength)
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "IsOverlay": true,
  "Parameters": [
    {
      "Name": "GridRowLength",
      "DisplayName": "Grid Row Length",
      "Type": "Integer",
      "DefaultValue": 2
    },
    {
      "Name": "GridRowLengthUnitType",
      "DisplayName": "Grid Row Length Unit Type",
      "Type": "Enum",
      "EnumTypeFullName": "cAlgo.API.GridUnitType",
      "DefaultValue": "Auto"
    },
    {
      "Name": "GridColumnLength",
      "DisplayName": "Grid Column Length",
      "Type": "Integer",
      "DefaultValue": 2
    },
    {
      "Name": "GridColumnLengthUnitType",
      "DisplayName": "Grid Column Length Unit Type",
      "Type": "Enum",
      "EnumTypeFullName": "cAlgo.API.GridUnitType",
      "DefaultValue": "Auto"
    }
  ]
}

Values

Name Value Description
Auto 0 The automatic definition of units for the grid.
Pixel 1 Calculate grid size in pixels.
Star 2 Calculate grid size in stars.

See also