Skip to content

Commit

Permalink
Merge pull request #1758 from beto-rodriguez/update-blazor
Browse files Browse the repository at this point in the history
Update blazor
  • Loading branch information
beto-rodriguez authored Jan 7, 2025
2 parents d55236b + 03d7b2c commit 64bd372
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,5 @@ nuget.exe
build/pack.singed.ps1
/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/wwwroot/domInterop.js
/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/wwwroot/domInterop.js.map
/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/domInterop.js
/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/domInterop.js.map
4 changes: 2 additions & 2 deletions samples/BlazorSample/BlazorSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.11" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/BlazorSample/Pages/Events/AddPointOnClick.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
data.Add(new ObservablePoint(dataCoordinates.X, dataCoordinates.Y));

// You can also get all the points or visual elements in a given location.
var points = _chart.GetPointsAt(new LvcPoint(p.X, p.Y));
var visuals = _chart.GetVisualsAt(new LvcPoint(p.X, p.Y));
var points = _chart.GetPointsAt(new LvcPointD(p.X, p.Y));
var visuals = _chart.GetVisualsAt(new LvcPointD(p.X, p.Y));
}
}
2 changes: 1 addition & 1 deletion samples/BlazorSample/Pages/General/Scrollable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
_mainChart.UpdateStarted += OnChart_Updated;
}

private void OnChart_Updated(IChartView<SkiaSharpDrawingContext> chart)
private void OnChart_Updated(IChartView chart)
{
var vm = ViewModel;
var cartesianChart = (CartesianChart)chart;
Expand Down
15 changes: 14 additions & 1 deletion src/LiveChartsCore/LiveCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace LiveChartsCore;
/// </summary>
public static class LiveCharts
{
private static bool s_useGPU = false;
private static bool s_gpuSetByUser = false;

/// <summary>
/// A constant that indicates that the tool tip should not add the current label.
/// </summary>
Expand Down Expand Up @@ -60,7 +63,11 @@ public static class LiveCharts
/// Gets or sets a value indicating whether LiveCharts should use a hardware graphics API
/// to render the charts.
/// </summary>
public static bool UseGPU { get; set; } = false;
public static bool UseGPU
{
get => s_useGPU;
set { s_useGPU = value; s_gpuSetByUser = true; }
}

/// <summary>
/// Gets a value indicating whether LiveCharts has a backend registered.
Expand Down Expand Up @@ -141,4 +148,10 @@ public static TimeSpan AsTimeSpan(this double ticks)
if (ticks < 0) ticks = 0;
return TimeSpan.FromTicks((long)ticks);
}

internal static void SetUseGPUIfNotSetByUser(bool value)
{
if (s_gpuSetByUser) return;
s_useGPU = value;
}
}
28 changes: 14 additions & 14 deletions src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
@*Ideally this component should be abstract, is it posible in Blazor?*@

<div class="lvc-content">
@*
@*
This is an old tooltip that uses HTML and css, instead we now handle also this and draw it.
<DefaultTooltip @ref="Tooltip" Class="@TooltipClass" />
*@

<JsFlexibleContainer @ref="_jsFlexibleContainer" Class="@ContainerActualClass">
<Content>
<div class="lvc-canvas-container" @ref="CanvasContainerElement">
<MotionCanvas
@ref="motionCanvas"
OnPointerDownCallback="OnPointerDown"
OnPointerMoveCallback="OnPointerMove"
OnPointerUpCallback="OnPointerUp"
<JsFlexibleContainer @ref="_jsFlexibleContainer" Class="@ContainerActualClass">
<Content>
<div class="lvc-canvas-container" @ref="CanvasContainerElement">
<MotionCanvas
@ref="motionCanvas"
OnPointerDownCallback="OnPointerDown"
OnPointerMoveCallback="OnPointerMove"
OnPointerUpCallback="OnPointerUp"
OnPointerOutCallback="OnPointerOut"
OnWheelCallback="OnWheel">
</MotionCanvas>
</div>
</Content>
</JsFlexibleContainer>
OnWheelCallback="OnWheel">
</MotionCanvas>
</div>
</Content>
</JsFlexibleContainer>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ protected override void OnInitialized()
{
base.OnInitialized();

// on blazor by default we use the GPU
// just because it looks MUCH better
// the user can disable this feature by calling
// LiveCharts.UseGPU = false;
// or by setting the UseGPU property to false in the chart
LiveCharts.SetUseGPUIfNotSetByUser(true);

LiveCharts.Configure(config => config.UseDefaults());

_visualsObserver = new CollectionDeepObserver<ChartElement>(
Expand Down Expand Up @@ -190,7 +197,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

/// <inheritdoc cref="IChartView.Legend" />
[Parameter]
public IChartLegend? Legend { get; set; } = LiveCharts.DefaultSettings.GetTheme().DefaultLegend();
public IChartLegend? Legend { get; set; }

/// <inheritdoc cref="IChartView.LegendTextPaint" />
[Parameter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,10 @@
<NoWarn>$(NoWarn);BL0007</NoWarn>
</PropertyGroup>

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TypeScriptNoImplicitAny>True</TypeScriptNoImplicitAny>
<TypeScriptOutFile></TypeScriptOutFile>
<TypeScriptTarget>ES6</TypeScriptTarget>
</PropertyGroup>

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TypeScriptNoImplicitAny>True</TypeScriptNoImplicitAny>
<TypeScriptOutFile></TypeScriptOutFile>
<TypeScriptTarget>ES6</TypeScriptTarget>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<TypeScriptCompile Include="wwwroot/*.ts" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.Views.Blazor" Version="$(SkiaSharpVersion)" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="7.3.0" />
Expand All @@ -63,7 +47,7 @@
<PackageReference Condition="$(TargetFramework) == 'net6.0'" Include="Microsoft.AspNetCore.Components.Web" Version="6.0.0" />
<PackageReference Condition="$(TargetFramework) == 'net8.0'" Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />

<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.1.5">
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.7.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -74,8 +58,6 @@
<ProjectReference Include="..\LiveChartsCore.SkiaSharp\LiveChartsCore.SkiaSharpView.csproj" />
</ItemGroup>

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />

<ItemGroup>
<None Include="images\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "ES6",
"outDir": "wwwroot/"
},
"include": [
"wwwroot/domInterop.ts"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 64bd372

Please sign in to comment.