-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from apexcharts/add-selection-event
Add selection event
- Loading branch information
Showing
15 changed files
with
429 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
docs/BlazorApexCharts.Docs/Components/Events/BrushedScrolled/Basic.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<ApexChart TItem="TimeSeries" | ||
Title="Value" | ||
Options=options1 | ||
Height="150" | ||
XAxisType="XAxisType.Datetime" | ||
> | ||
|
||
<ApexPointSeries TItem="TimeSeries" | ||
Items="data" | ||
Name="Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.Date)" | ||
YAggregate="@(e => e.Sum(e => e.Value))" | ||
OrderBy="e=>e.X" | ||
Stroke="@(new SeriesStroke { Width = 2, Color="#1F15E5"})" /> | ||
</ApexChart> | ||
|
||
<ApexChart TItem="TimeSeries" | ||
Title="Quantity" | ||
Options=options2 | ||
Height="150" | ||
XAxisType="XAxisType.Datetime" | ||
OnBrushScrolled=BrushScroll> | ||
|
||
<ApexPointSeries TItem="TimeSeries" | ||
Items="data" | ||
Name="Quantity" | ||
SeriesType="SeriesType.Bar" | ||
XValue="@(e => e.Date)" | ||
YValue="@(e => e.Quantity)" | ||
OrderBy="e=>e.X" | ||
Stroke="@(new SeriesStroke { Width = 2, Color="#E51C15"})" /> | ||
</ApexChart> | ||
|
||
<h3 class="mt-2">Selection</h3> | ||
<Row> | ||
<RowCol Auto> | ||
XAxis Min: @XMin.ToString("d") | ||
</RowCol> | ||
<RowCol Auto> | ||
XAxis Max: @XMax.ToString("d") | ||
</RowCol> | ||
</Row> | ||
|
||
@code { | ||
private List<TimeSeries> data { get; set; } = new TimeSeriesGenerator(100).TimeSeries; | ||
private ApexChartOptions<TimeSeries> options1 = new(); | ||
private ApexChartOptions<TimeSeries> options2 = new(); | ||
|
||
private DateTimeOffset XMin; | ||
private DateTimeOffset XMax; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
const string mainChartId = "mainChart"; | ||
|
||
options1.Chart.Id = mainChartId; | ||
options1.Chart.Toolbar = new Toolbar { AutoSelected = AutoSelected.Pan, Show = false }; | ||
|
||
XMin = data.Min(e => e.Date).AddDays(30); | ||
XMax = XMin.AddDays(40); | ||
|
||
options2.Chart.Toolbar = new Toolbar { Show = false }; | ||
options2.Xaxis = new XAxis { TickPlacement = TickPlacement.On }; | ||
options2.Chart.Brush = new ApexCharts.Brush { Enabled = true, Target = mainChartId }; | ||
options2.Chart.Selection = new Selection | ||
{ | ||
Enabled = true, | ||
Xaxis = new SelectionXaxis | ||
{ | ||
Min = XMin.ToUnixTimeMilliseconds(), | ||
Max = XMax.ToUnixTimeMilliseconds() | ||
} | ||
}; | ||
} | ||
|
||
private void BrushScroll(SelectionData<TimeSeries> selection) | ||
{ | ||
|
||
var min = selection?.XAxis?.Min; | ||
if (min != null) | ||
{ | ||
XMin = DateTimeOffset.FromUnixTimeMilliseconds((long)min); | ||
} | ||
|
||
|
||
var max = selection?.XAxis?.Max; | ||
if (max != null) | ||
{ | ||
XMax = DateTimeOffset.FromUnixTimeMilliseconds((long)max); | ||
} | ||
|
||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
docs/BlazorApexCharts.Docs/Components/Events/BrushedScrolled/BrushScrolled.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@page "/events/brush-scrolled" | ||
|
||
<DocExamples Title="BrushScrolled"> | ||
|
||
<CodeSnippet Title="Basic" ClassName=@typeof(Basic).ToString()> | ||
<Snippet> | ||
<Basic /> | ||
</Snippet> | ||
</CodeSnippet> | ||
|
||
|
||
</DocExamples> |
78 changes: 78 additions & 0 deletions
78
docs/BlazorApexCharts.Docs/Components/Events/Selection/Basic.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<ApexChart TItem="TimeSeries" | ||
Title="Quantity" | ||
Options=options | ||
Height="150" | ||
XAxisType="XAxisType.Datetime" | ||
OnSelection=Selected> | ||
|
||
<ApexPointSeries TItem="TimeSeries" | ||
Items="data" | ||
Name="Quantity" | ||
SeriesType="SeriesType.Bar" | ||
XValue="@(e => e.Date)" | ||
YValue="@(e => e.Quantity)" | ||
OrderBy="e=>e.X" | ||
Stroke="@(new SeriesStroke { Width = 2, Color="#E51C15"})" /> | ||
</ApexChart> | ||
|
||
|
||
<h3 class="mt-2">Selection</h3> | ||
<Row> | ||
<RowCol Auto> | ||
XAxis Min: @XMin?.ToString("d") | ||
</RowCol> | ||
<RowCol Auto> | ||
XAxis Min: @XMax?.ToString("d") | ||
</RowCol> | ||
</Row> | ||
|
||
@code { | ||
private List<TimeSeries> data { get; set; } = new TimeSeriesGenerator(100).TimeSeries; | ||
private ApexChartOptions<TimeSeries> options = new(); | ||
private SelectionData<TimeSeries> currentSelection; | ||
|
||
private DateTimeOffset? XMin; | ||
private DateTimeOffset? XMax; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
var selectionStart = data.Min(e => e.Date).AddDays(30); | ||
options.Chart.Toolbar = new Toolbar { Show = false }; | ||
options.Xaxis = new XAxis { TickPlacement = TickPlacement.On }; | ||
options.Chart.Brush = new ApexCharts.Brush { Enabled = true }; | ||
options.Chart.Selection = new ApexCharts.Selection | ||
{ | ||
Enabled = true, | ||
Xaxis = new SelectionXaxis | ||
{ | ||
Min = selectionStart.ToUnixTimeMilliseconds(), | ||
Max = selectionStart.AddDays(40).ToUnixTimeMilliseconds() | ||
} | ||
}; | ||
} | ||
|
||
private void Selected(SelectionData<TimeSeries> selection) | ||
{ | ||
currentSelection = selection; | ||
|
||
var min = selection?.XAxis?.Min; | ||
if (min != null) | ||
{ | ||
XMin = DateTimeOffset.FromUnixTimeMilliseconds((long)min); | ||
} | ||
else | ||
{ | ||
min = null; | ||
} | ||
|
||
var max = selection?.XAxis?.Max; | ||
if (max != null) | ||
{ | ||
XMax = DateTimeOffset.FromUnixTimeMilliseconds((long)max); | ||
} | ||
else | ||
{ | ||
max = null; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/BlazorApexCharts.Docs/Components/Events/Selection/Selection.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@page "/events/selection" | ||
|
||
<DocExamples Title="Selection"> | ||
|
||
<ChildContent> | ||
<CodeSnippet Title="Basic" ClassName=@typeof(Basic).ToString()> | ||
<Snippet> | ||
<Basic /> | ||
</Snippet> | ||
</CodeSnippet> | ||
|
||
|
||
</ChildContent> | ||
|
||
</DocExamples> |
55 changes: 55 additions & 0 deletions
55
docs/BlazorApexCharts.Docs/Components/Events/Zoomed/Basic.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<ApexChart TItem="TimeSeries" | ||
Title="Value" | ||
Height="150" | ||
XAxisType="XAxisType.Datetime" | ||
OnZoomed=Zoom> | ||
|
||
<ApexPointSeries TItem="TimeSeries" | ||
Items="timeSeries" | ||
Name="Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.Date.ToUnixTimeMilliseconds())" | ||
YValue="@( e=> e.Value)" | ||
Stroke="@(new SeriesStroke { Width = 2, Color="#1F15E5"})" /> | ||
</ApexChart> | ||
|
||
<h3 class="mt-2">Zoomed</h3> | ||
<Row> | ||
<RowCol Auto> | ||
XAxis Min: @xMin | ||
</RowCol> | ||
<RowCol Auto> | ||
XAxis Max: @xMax | ||
</RowCol> | ||
</Row> | ||
|
||
|
||
@code { | ||
private List<TimeSeries> timeSeries = new TimeSeriesGenerator(100).TimeSeries; | ||
private DateTimeOffset xMin; | ||
private DateTimeOffset xMax; | ||
|
||
|
||
private void Zoom(ZoomedData<TimeSeries> zoomedData) | ||
{ | ||
|
||
if(zoomedData.XAxis?.Min == null) | ||
{ | ||
xMin = timeSeries.Min(e => e.Date); | ||
} | ||
else | ||
{ | ||
xMin = DateTimeOffset.FromUnixTimeMilliseconds((long)zoomedData.XAxis.Min); | ||
} | ||
|
||
|
||
if(zoomedData.XAxis?.Max == null) | ||
{ | ||
xMax = timeSeries.Max(e => e.Date); | ||
} | ||
else | ||
{ | ||
xMax = DateTimeOffset.FromUnixTimeMilliseconds((long)zoomedData.XAxis.Max); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/BlazorApexCharts.Docs/Components/Events/Zoomed/Zoomed.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@page "/events/zoomed" | ||
|
||
<DocExamples Title="Zoomed"> | ||
|
||
<ChildContent> | ||
<CodeSnippet Title="Basic" ClassName=@typeof(Basic).ToString()> | ||
<Snippet> | ||
<Basic /> | ||
</Snippet> | ||
</CodeSnippet> | ||
|
||
|
||
</ChildContent> | ||
|
||
</DocExamples> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.