From 5bb9eb85ab6205c8f53a767c9f4e3be0ae24f028 Mon Sep 17 00:00:00 2001 From: anmcgrath Date: Sun, 3 Nov 2024 19:48:02 +1100 Subject: [PATCH] Remove chart example - adds too much bulk to example site download. --- .../Shared/NavMenu.razor | 5 - .../BlazorDatasheet.SharedPages.csproj | 1 - .../Pages/ChartExample.razor | 124 ------------------ src/BlazorDatasheet.Wasm/Shared/NavMenu.razor | 5 - 4 files changed, 135 deletions(-) delete mode 100644 src/BlazorDatasheet.SharedPages/Pages/ChartExample.razor diff --git a/src/BlazorDatasheet.Server/Shared/NavMenu.razor b/src/BlazorDatasheet.Server/Shared/NavMenu.razor index dc0d334a..b67f5268 100644 --- a/src/BlazorDatasheet.Server/Shared/NavMenu.razor +++ b/src/BlazorDatasheet.Server/Shared/NavMenu.razor @@ -54,11 +54,6 @@ Column filters - diff --git a/src/BlazorDatasheet.SharedPages/BlazorDatasheet.SharedPages.csproj b/src/BlazorDatasheet.SharedPages/BlazorDatasheet.SharedPages.csproj index 48d7d7b5..e5836063 100644 --- a/src/BlazorDatasheet.SharedPages/BlazorDatasheet.SharedPages.csproj +++ b/src/BlazorDatasheet.SharedPages/BlazorDatasheet.SharedPages.csproj @@ -22,7 +22,6 @@ - diff --git a/src/BlazorDatasheet.SharedPages/Pages/ChartExample.razor b/src/BlazorDatasheet.SharedPages/Pages/ChartExample.razor deleted file mode 100644 index 36d2488c..00000000 --- a/src/BlazorDatasheet.SharedPages/Pages/ChartExample.razor +++ /dev/null @@ -1,124 +0,0 @@ -@using BlazorDatasheet.Core.Commands.Data -@using BlazorDatasheet.Core.Data -@using BlazorDatasheet.Core.Events -@using BlazorDatasheet.Core.Validation -@using BlazorDatasheet.DataStructures.Geometry -@using BlazorDatasheet.Formula.Core -@page "/ChartExample" -@using Plotly.Blazor -@using Plotly.Blazor.Traces -@using Plotly.Blazor.Traces.ScatterLib - -

ChartExample

- -This example shows how it would be possible to integrate a charting library such as Plotly.Blazor with a sheet. - -
-
- -
-
- -
-
- -
-
- - -@code { - - private List Points { get; set; } = new(); - private readonly Sheet _sheet = new(50, 2); - - PlotlyChart? chart; - Config config = new Config(); - - Layout layout = new Layout(); - - // Using of the interface IList is important for the event callback! - IList data = new List - { - new Scatter - { - Name = "ScatterTrace", - Mode = ModeFlag.Lines | ModeFlag.Markers, - } - }; - - protected override void OnInitialized() - { - _sheet.Validators.Add(new ColumnRegion(0, 1), new NumberValidator(true)); - _sheet.BatchUpdates(); - - _sheet.FormulaEngine.SetVariable("alpha", 2); - - _sheet.Cells.CellsChanged += CellsOnCellsChanged; - _sheet.Cells.SetValues(0, 0, Enumerable.Range(0, _sheet.NumRows).Select(x => [CellValue.Number(4 * Math.PI * x / _sheet.NumRows)]).ToArray()); - _sheet.Cells[0, 1].Formula = "=-2/(3.14 * 1) * pow(-1,1) * sin(1 * 0.5 * A1 - alpha) -2/(3.14 * 2) * pow(-1,2) * sin(2 * 0.5 * A1 - alpha) -2/(3.14 * 1) * pow(-1,3) * sin(3 * 0.5 * A1 - alpha)"; - for (int i = 0; i < _sheet.NumRows - 1; i++) - _sheet.Commands.ExecuteCommand(new CopyRangeCommand(_sheet.Range("B1")!, _sheet.Range(i + 1, 1)!, new CopyOptions() { CopyValues = false })); - _sheet.EndBatchUpdates(); - } - - protected override void OnAfterRender(bool firstRender) - { - base.OnAfterRender(firstRender); - } - - private async void CellsOnCellsChanged(object? sender, CellDataChangedEventArgs e) - { - await RefreshChartData(); - } - - private async Task RefreshChartData() - { - var cellData = new List(); - for (int i = 0; i < _sheet.NumRows; i++) - { - var cellValueX = _sheet.Cells.GetCellValue(i, 0); - var cellValueY = _sheet.Cells.GetCellValue(i, 1); - if (cellValueX.ValueType != CellValueType.Number || - cellValueY.ValueType != CellValueType.Number) - continue; - - cellData.Add(new(cellValueX.GetValue(), cellValueY.GetValue())); - } - - if (!cellData.Any()) - return; - - this.data = new List - { - new Scatter - { - Name = "ScatterTrace", - Mode = ModeFlag.Lines | ModeFlag.Markers, - X = cellData.Select(x => (object)x.X).ToList(), - Y = cellData.Select(x => (object)x.Y).ToList() - } - }; - - StateHasChanged(); - - if (chart == null) - return; - - await chart.React(); - } - - public class ChartData - { - public double X { get; } - public double Y { get; } - - public ChartData(double x, double y) - { - X = x; - Y = y; - } - } - -} \ No newline at end of file diff --git a/src/BlazorDatasheet.Wasm/Shared/NavMenu.razor b/src/BlazorDatasheet.Wasm/Shared/NavMenu.razor index 326e1bd0..1eeb9b95 100644 --- a/src/BlazorDatasheet.Wasm/Shared/NavMenu.razor +++ b/src/BlazorDatasheet.Wasm/Shared/NavMenu.razor @@ -54,11 +54,6 @@ Column filters -