Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports FarPoint.Win
Imports FarPoint.Win.Spread
Imports Spread.Common.Features.Spread.Common.Features.Sample

Namespace Features
    Public Class ScatterSparkline
        Inherits BaseSampleControl

        Public Sub New()
            InitializeComponent()
            Name = "Scatter"

            Dim colors As List(Of Color) = New List(Of Color) From {
                Color.White,
                Color.Black,
                Color.Orange,
                Color.LightGray,
                Color.Gray,
                Color.DarkGray,
                Color.Green
            }

            comboColor1.DataSource = colors
            comboColor1.SelectedItem = Color.Black

            comboColor2.DataSource = colors.ToList()
            comboColor2.SelectedItem = Color.Green

            InitSpreadsheet(FpSpread1.ActiveSheet)

            AddHandler comboColor1.SelectedIndexChanged, AddressOf ComboColor_SelectedIndexChanged
            AddHandler comboColor2.SelectedIndexChanged, AddressOf ComboColor_SelectedIndexChanged
        End Sub

#Region "Private methods"
        Private Sub InitSpreadsheet(ByVal sheetView As SheetView)
            Dim worksheet As GrapeCity.Spreadsheet.IWorksheet = sheetView.AsWorksheet()
            worksheet.Cells("A1:E1").Merge()
            worksheet.Cells("A1").Value = "Rainfall effect on Particulate Levels and Temperature"
            worksheet.Cells("A1").Font.ApplyFont(New GrapeCity.Spreadsheet.Font() With {
                .Name = "Arial",
                .Size = 13
            })
            sheetView.Cells("A1").BackColor = ColorTranslator.FromHtml("#BBBBBB")
            worksheet.Cells("A1").VerticalAlignment = GrapeCity.Spreadsheet.VerticalAlignment.Center

            worksheet.SetValue(1, 0, New Object(,) {
            {"Daily Rainfall", "Particulate Level", "Daily Rainfall1", "Temperature", "Diagram"},
            {2.0, 100, 2.0, 15, Nothing},
            {2.5, 130, 2.5, 12, Nothing},
            {3.0, 120, 3.0, 11, Nothing},
            {3.5, 140, 3.5, 9, Nothing},
            {4.0, 120, 4.0, 10, Nothing},
            {4.5, 110, 4.5, 10, Nothing},
            {5.0, 110, 5.0, 9, Nothing},
            {5.5, 105, 5.5, 9, Nothing},
            {6.0, 100, 6.0, 8, Nothing}})

            worksheet.Cells("E3:E11").Merge()
            worksheet.Cells("E3").Formula2 = "SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,," & $"TRUE,TRUE,TRUE,""{(CType(comboColor1.SelectedItem, Color)).Name}"",""{(CType(comboColor2.SelectedItem, Color)).Name}"",TRUE)"
            worksheet.Rows("1:11").RowHeight = 25

            worksheet.Cells("A2:E2").Font.ApplyFont(New GrapeCity.Spreadsheet.Font() With {
                .Name = "Arial",
                .Size = 11,
                .Bold = True
            })

            worksheet.Cells("A2:E2").Borders.ApplyBorder(New GrapeCity.Spreadsheet.Border() With {
                .Bottom = New GrapeCity.Spreadsheet.BorderLine(GrapeCity.Spreadsheet.BorderLineStyle.Thin, GrapeCity.Spreadsheet.Color.FromKnownColor(GrapeCity.Core.KnownColor.Black))
            })

            worksheet.Cells("A3:D11").HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.Left
            worksheet.Columns("A").ColumnWidth = 130
            worksheet.Columns("B").ColumnWidth = 130
            worksheet.Columns("D").ColumnWidth = 130
            worksheet.Columns("E").ColumnWidth = 200
            worksheet.Columns("C").Hidden = True
        End Sub
#End Region

#Region "Event handlers"
        Private Sub ComboColor_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            FpSpread1.Sheets(0).AsWorksheet().Cells("E3").Formula2 = "SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,," & $"TRUE,TRUE,TRUE,""{(CType(comboColor1.SelectedItem, Color)).Name}"",""{(CType(comboColor2.SelectedItem, Color)).Name}"",TRUE)"
        End Sub
#End Region
    End Class
End Namespace


'
'ScatterSparkline.Designer.vb
'


Namespace Features
    Partial Class ScatterSparkline
        ''' <summary> 
        ''' Required designer variable.
        ''' </summary>
        Private components As System.ComponentModel.IContainer = Nothing

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Shadows Sub Dispose(disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()>
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ScatterSparkline))
            Me.FpSpread1 = New FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, CType(resources.GetObject("pnlMain.Controls"), Object))
            Me.FpSpread1_Sheet1 = Me.FpSpread1.GetSheet(0)
            Me.comboColor2 = New System.Windows.Forms.ComboBox()
            Me.label2 = New System.Windows.Forms.Label()
            Me.comboColor1 = New System.Windows.Forms.ComboBox()
            Me.label1 = New System.Windows.Forms.Label()
            Me.pnlMain.SuspendLayout()
            Me.pnlControls.SuspendLayout()
            CType(Me.FpSpread1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'pnlMain
            '
            Me.pnlMain.Controls.Add(Me.FpSpread1)
            '
            'pnlControls
            '
            Me.pnlControls.Controls.Add(Me.comboColor2)
            Me.pnlControls.Controls.Add(Me.label2)
            Me.pnlControls.Controls.Add(Me.comboColor1)
            Me.pnlControls.Controls.Add(Me.label1)
            Me.pnlControls.Size = New System.Drawing.Size(210, 599)
            '
            'FpSpread1
            '
            Me.FpSpread1.AccessibleDescription = "Book1, Sheet1, Row 0, Column 0"
            Me.FpSpread1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.FpSpread1.Font = New System.Drawing.Font("Calibri", 11.0!)
            Me.FpSpread1.Location = New System.Drawing.Point(0, 0)
            Me.FpSpread1.Name = "FpSpread1"
            Me.FpSpread1.Size = New System.Drawing.Size(636, 599)
            Me.FpSpread1.TabIndex = 1
            '
            'comboColor2
            '
            Me.comboColor2.FormattingEnabled = True
            Me.comboColor2.Location = New System.Drawing.Point(10, 130)
            Me.comboColor2.Name = "comboColor2"
            Me.comboColor2.Size = New System.Drawing.Size(121, 24)
            Me.comboColor2.TabIndex = 7
            '
            'label2
            '
            Me.label2.AutoSize = True
            Me.label2.Location = New System.Drawing.Point(7, 101)
            Me.label2.Name = "label2"
            Me.label2.Size = New System.Drawing.Size(231, 17)
            Me.label2.TabIndex = 6
            Me.label2.Text = "Rainfall - Temperature Graph Color"
            '
            'comboColor1
            '
            Me.comboColor1.FormattingEnabled = True
            Me.comboColor1.Location = New System.Drawing.Point(8, 60)
            Me.comboColor1.Name = "comboColor1"
            Me.comboColor1.Size = New System.Drawing.Size(121, 24)
            Me.comboColor1.TabIndex = 5
            '
            'label1
            '
            Me.label1.AutoSize = True
            Me.label1.Location = New System.Drawing.Point(5, 31)
            Me.label1.Name = "label1"
            Me.label1.Size = New System.Drawing.Size(254, 17)
            Me.label1.TabIndex = 4
            Me.label1.Text = "Rainfall - Particulate Level Graph Color"
            '
            'ScatterSparkline
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.Name = "ScatterSparkline"
            Me.pnlMain.ResumeLayout(False)
            Me.pnlControls.ResumeLayout(False)
            Me.pnlControls.PerformLayout()
            CType(Me.FpSpread1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub
        Friend WithEvents FpSpread1 As FarPoint.Win.Spread.FpSpread
        Private WithEvents comboColor2 As System.Windows.Forms.ComboBox
        Private WithEvents label2 As System.Windows.Forms.Label
        Private WithEvents comboColor1 As System.Windows.Forms.ComboBox
        Private WithEvents label1 As System.Windows.Forms.Label
        Friend WithEvents FpSpread1_Sheet1 As FarPoint.Win.Spread.SheetView
    End Class
End Namespace
