Skip to content

Commit

Permalink
fix: Bullet/Bubble/Violin Chart Render & deadloop of afterrender from…
Browse files Browse the repository at this point in the history
… G2Plot and AfterChartRender in ChartComponentBase (#145)

* fix: Bullet cannot be rendered.

* fix: deadloop of afterrender from G2Plot and AfterChartRender of ChartComponentBase

* fix: Bubble, Violin Chart render issue

---------

Co-authored-by: Jeffers <[email protected]>
  • Loading branch information
jeffersyuan1976 and JeffersYuan authored Jul 10, 2024
1 parent fbf70d1 commit 2e71160
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
17 changes: 3 additions & 14 deletions src/AntDesign.Charts.Docs/Demos/Bubble/Bubble_Chart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@
<TabPane Key="1" Tab="Sample 1">
<Scatter Config="config1" OnFirstRender="Chart1_FirstRender" />
</TabPane>
@* <TabPane Key="2" Tab="Sample 2"> *@
@* <Scatter Config="config2" OnFirstRender="Chart2_FirstRender" /> *@
@* </TabPane> *@
@*<TabPane Key="3">
<Tab>示例3</Tab>
<ChildContent>
<Bubble @ref="chart3" Data="data3" Config="config3" />
</ChildContent>

<TabPane Key="2" Tab="Sample 2">
<Scatter Config="config2" OnFirstRender="Chart2_FirstRender" />
</TabPane>
<TabPane Key="4">
<Tab>示例4</Tab>
<ChildContent>
<Bubble @ref="chart4" Data="data4" Config="config4" />
</ChildContent>
</TabPane>*@
</Tabs>

<Divider>动手实验</Divider>
Expand Down
21 changes: 14 additions & 7 deletions src/AntDesign.Charts.Docs/Demos/Bullet/Bullet_Chart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@
BulletConfig config1 = new BulletConfig()
{
Data = new BulletViewConfigData[]
{
{
new BulletViewConfigData()
{
Title = "满意度",
Measures = new int[]{83 },
Targets = new int[]{90 },
},
Title = "满意度",
Measures = new int[]{83 },
Targets = new int[]{90 },
Ranges = new double[]{100},
},
RangeMax = 100,
},
TargetField = "target",
RangeField = "ranges",
MeasureField = "measures",
XField = "title"
};


Expand Down Expand Up @@ -136,7 +140,10 @@
Ranges = new double[] {0,0.6,0.9,1},
},
},
RangeMax = 100,
TargetField = "target",
RangeField = "ranges",
MeasureField = "measures",
XField = "title",
RangeColors = new string[] { "#FFB1AC", "#FFDBA2", "#B4EBBF" },


Expand Down
20 changes: 10 additions & 10 deletions src/AntDesign.Charts.Docs/Demos/Violin/Violin_Chart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

<Tabs>
<TabPane Key="1" Tab="Sample 1">
<Violin Data="Data" Config="_config1" />
<Violin Data="Data" Config="_config1" OnFirstRender="onChart1_FirstRender" />
</TabPane>
<TabPane Key="2" Tab="Sample 2">
<Violin Data="Data" Config="_config2" />
<Violin Data="Data" Config="_config2" OnFirstRender="onChart1_FirstRender" />
</TabPane>
<TabPane Key="3" Tab="Sample 3">
<Violin Data="Data" Config="_config3" />
<Violin Data="Data" Config="_config3" OnFirstRender="onChart1_FirstRender" />
</TabPane>
<TabPane Key="4" Tab="Sample 4">
<Violin Data="Data" Config="_config4" />
<Violin Data="Data" Config="_config4" OnFirstRender="onChart1_FirstRender" />
</TabPane>
</Tabs>

Expand All @@ -28,16 +28,16 @@
private DynamicExample _example;
private object[] Data { get; set; }

protected override void OnAfterRender(bool firstRender)
private async Task onChart1_FirstRender(IChartComponent chart)
{
base.OnAfterRender(firstRender);
_example.Chart = Chart;
var data1 = await DemoData.ViolinDataAsync(NavigationManager, HttpClient);
await chart.ChangeData(data1);
}

protected override async Task OnInitializedAsync()
protected override void OnAfterRender(bool firstRender)
{
Data = await DemoData.ViolinDataAsync(NavigationManager, HttpClient);
await base.OnInitializedAsync();
base.OnAfterRender(firstRender);
_example.Chart = Chart;
}

#region Basic violin plot
Expand Down
8 changes: 4 additions & 4 deletions src/AntDesign.Charts/Components/Base/ChartComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ public async Task AfterChartRender()
{
IsCreated = true;

if (Data != null)
{
await JS.InvokeVoidAsync(InteropChangeData, Ref.Id, Data, true);
}
//if (Data != null)
//{
// await JS.InvokeVoidAsync(InteropChangeData, Ref.Id, Data, true);
//}

if (OnCreateAfter.HasDelegate)
await OnCreateAfter.InvokeAsync(this);
Expand Down
11 changes: 10 additions & 1 deletion src/AntDesign.Charts/Components/Plots/Bullet/BulletConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public class BulletConfig : IBulletViewConfig, IPlotConfig
public int? AppendPadding { get; set; }
[JsonPropertyName("autoFit")]
public bool? AutoFit { get; set; }

[JsonPropertyName("targetField")]
public string TargetField { get; set; }

[JsonPropertyName("rangeField")]
public string RangeField { get; set; }

[JsonPropertyName("measureField")]
public string MeasureField { get; set; }
}

public interface IBulletViewConfig : IViewConfig
Expand Down Expand Up @@ -163,7 +172,7 @@ public class BulletViewConfigData
/// <summary>
/// 目标值,array类型。支持多目标设置
/// </summary>
[JsonPropertyName("targets")]
[JsonPropertyName("target")]
public int[] Targets { get; set; }

[JsonPropertyName("markerStyle")]
Expand Down

0 comments on commit 2e71160

Please sign in to comment.