-
Notifications
You must be signed in to change notification settings - Fork 52
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 #380 from jacekpapiniak/Add-legend-click-event
Add legend click event
- Loading branch information
Showing
12 changed files
with
240 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@using Plotly.Blazor.LayoutLib | ||
@using Plotly.Blazor.Interop | ||
<PlotlyChart style="height: 60vh; min-height: 350px" @bind-Config="config" @bind-Layout="layout" @bind-Data="data" @ref="chart" | ||
LegendClickAction="LegendClickAction" AfterRender="SubscribeEvents"/> | ||
|
||
@if (LegendInfo != null) | ||
{ | ||
<MudText>Curve number: @LegendInfo.CurveNumber</MudText> | ||
<MudText>ExpandedIndex: @LegendInfo.ExpandedIndex</MudText> | ||
} | ||
|
||
@code | ||
{ | ||
[CascadingParameter] | ||
private MudTheme Theme { get; set; } | ||
|
||
private PlotlyChart chart; | ||
private Config config; | ||
private Layout layout; | ||
private IList<ITrace> data; | ||
private LegendEventDataPoint LegendInfo { get; set; } | ||
|
||
/// <inheritdoc /> | ||
protected override void OnInitialized() | ||
{ | ||
config = new Config | ||
{ | ||
Responsive = true | ||
}; | ||
|
||
layout = new Layout | ||
{ | ||
Title = new Title | ||
{ | ||
Text = GetType().Name | ||
}, | ||
PaperBgColor = Theme.PaletteDark.Surface.ToString(), | ||
PlotBgColor = Theme.PaletteDark.Surface.ToString(), | ||
Font = new Font | ||
{ | ||
Color = Theme.PaletteDark.TextPrimary.ToString() | ||
}, | ||
ShowLegend = true, | ||
BarMode = BarModeEnum.Stack | ||
}; | ||
|
||
data = new List<ITrace> | ||
{ | ||
new Bar | ||
{ | ||
X = new List<object> { "giraffes", "orangutans", "monkeys" }, | ||
Y = new List<object> { 20, 14, 23 }, | ||
Name = "SF Zoo" | ||
}, | ||
new Bar | ||
{ | ||
X = new List<object> { "giraffes", "orangutans", "monkeys" }, | ||
Y = new List<object> { 12, 18, 29 }, | ||
Name = "LA Zoo" | ||
} | ||
}; | ||
|
||
base.OnInitialized(); | ||
} | ||
|
||
public void LegendClickAction(LegendEventDataPoint eventData) | ||
{ | ||
LegendInfo = eventData; | ||
StateHasChanged(); | ||
} | ||
|
||
public async void SubscribeEvents() | ||
{ | ||
await chart.SubscribeLegendClickEvent(); | ||
} | ||
} |
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,5 @@ | ||
@page "/legendclick" | ||
|
||
<Example Title="Legend Click Event" Url="Plotly.Blazor.Examples/Components/LegendClick.razor"> | ||
<LegendClick/> | ||
</Example> |
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
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
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
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
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