Skip to content

Commit

Permalink
[Add] Improve .editorconfig and run dotnet format (#48)
Browse files Browse the repository at this point in the history
* Formatting

* Use file scoped namespaces

* Remove regions

* Prefer var

* Add .venv to .gitignore

---------

Co-authored-by: Apollo3zehn <[email protected]>
  • Loading branch information
Apollo3zehn and Apollo3zehn authored Mar 7, 2024
1 parent 06eaab9 commit f402fb1
Show file tree
Hide file tree
Showing 111 changed files with 12,157 additions and 12,512 deletions.
21 changes: 18 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# How to format:
# (1) Add dotnet_diagnostic.XXXX.severity = error
# (2) Run dotnet-format: dotnet format --diagnostics XXXX
# How to apply single rule:
# Run dotnet format --diagnostics XXXX --severity info

# How to apply all rules:
# Run dotnet format --severity error/info/warn/

[*]
trim_trailing_whitespace = true

[*.cs]
# "run cleanup": https://betterprogramming.pub/enforce-net-code-style-with-editorconfig-d2f0d79091ac
# TODO: build real editorconfig file: https://github.com/dotnet/roslyn/blob/main/.editorconfig

# Prefer var
csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = true
csharp_style_var_elsewhere = true
dotnet_diagnostic.IDE0007.severity = warning

# Make field
dotnet_diagnostic.IDE0044.severity = warning

# Use file scoped namespace declarations
dotnet_diagnostic.IDE0161.severity = error
csharp_style_namespace_declarations = file_scoped

# Enable naming rule violation errors on build (alternative: dotnet_analyzer_diagnostic.category-Style.severity = error)
dotnet_diagnostic.IDE1006.severity = error

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vs/
.venv/

artifacts/
BenchmarkDotNet.Artifacts

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"python.analysis.extraPaths": [
"src/clients/python-client"
],
"dotnet.defaultSolution": "Nexus.sln"
"dotnet.defaultSolution": "Nexus.sln",
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tests/extensibility/python-extensibility-tests"
],
"stubPath": "",
"executionEnvironments":[
"executionEnvironments": [
{
"root": ".",
"extraPaths": [
Expand Down
211 changes: 105 additions & 106 deletions src/Nexus.UI/Charts/AvailabilityChart.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,144 +3,143 @@
using SkiaSharp;
using SkiaSharp.Views.Blazor;

namespace Nexus.UI.Charts
namespace Nexus.UI.Charts;

public partial class AvailabilityChart
{
public partial class AvailabilityChart
{
private const float LINE_HEIGHT = 7.0f;
private const float HALF_LINE_HEIGHT = LINE_HEIGHT / 2;
private const float LINE_HEIGHT = 7.0f;
private const float HALF_LINE_HEIGHT = LINE_HEIGHT / 2;

[Inject]
public TypeFaceService TypeFaceService { get; set; } = default!;
[Inject]
public TypeFaceService TypeFaceService { get; set; } = default!;

[Parameter]
public AvailabilityData AvailabilityData { get; set; } = default!;
[Parameter]
public AvailabilityData AvailabilityData { get; set; } = default!;

private void PaintSurface(SKPaintGLSurfaceEventArgs e)
{
/* sizes */
var canvas = e.Surface.Canvas;
var surfaceSize = e.BackendRenderTarget.Size;
private void PaintSurface(SKPaintGLSurfaceEventArgs e)
{
/* sizes */
var canvas = e.Surface.Canvas;
var surfaceSize = e.BackendRenderTarget.Size;

var yMin = LINE_HEIGHT * 2;
var yMax = (float)surfaceSize.Height;
var yMin = LINE_HEIGHT * 2;
var yMax = (float)surfaceSize.Height;

var xMin = 0.0f;
var xMax = (float)surfaceSize.Width;
var xMin = 0.0f;
var xMax = (float)surfaceSize.Width;

/* colors */
using var barStrokePaint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = new SKColor(249, 115, 22)
};
/* colors */
using var barStrokePaint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = new SKColor(249, 115, 22)
};

using var barFillPaint = new SKPaint
{
Color = new SKColor(249, 115, 22, 0x19)
};
using var barFillPaint = new SKPaint
{
Color = new SKColor(249, 115, 22, 0x19)
};

using var axisTitlePaint = new SKPaint
{
TextSize = 17,
IsAntialias = true,
Color = new SKColor(0x55, 0x55, 0x55),
TextAlign = SKTextAlign.Center
};
using var axisTitlePaint = new SKPaint
{
TextSize = 17,
IsAntialias = true,
Color = new SKColor(0x55, 0x55, 0x55),
TextAlign = SKTextAlign.Center
};

using var axisLabelPaint = new SKPaint
{
IsAntialias = true,
Typeface = TypeFaceService.GetTTF("Courier New Bold"),
Color = new SKColor(0x55, 0x55, 0x55)
};
using var axisLabelPaint = new SKPaint
{
IsAntialias = true,
Typeface = TypeFaceService.GetTTF("Courier New Bold"),
Color = new SKColor(0x55, 0x55, 0x55)
};

using var axisLabelCenteredPaint = new SKPaint
{
IsAntialias = true,
Typeface = TypeFaceService.GetTTF("Courier New Bold"),
Color = new SKColor(0x55, 0x55, 0x55),
TextAlign = SKTextAlign.Center
};
using var axisLabelCenteredPaint = new SKPaint
{
IsAntialias = true,
Typeface = TypeFaceService.GetTTF("Courier New Bold"),
Color = new SKColor(0x55, 0x55, 0x55),
TextAlign = SKTextAlign.Center
};

using var axisTickPaint = new SKPaint
{
Color = new SKColor(0xDD, 0xDD, 0xDD)
};
using var axisTickPaint = new SKPaint
{
Color = new SKColor(0xDD, 0xDD, 0xDD)
};

/* y-axis */
var yRange = yMax - (yMin + 40);
/* y-axis */
var yRange = yMax - (yMin + 40);

xMin += 20;
xMin += 20;

using (var canvasRestore = new SKAutoCanvasRestore(canvas))
{
canvas.RotateDegrees(270, xMin, yMin + yRange / 2);
canvas.DrawText("Availability / %", new SKPoint(xMin, yMin + yRange / 2), axisTitlePaint);
}
using (var canvasRestore = new SKAutoCanvasRestore(canvas))
{
canvas.RotateDegrees(270, xMin, yMin + yRange / 2);
canvas.DrawText("Availability / %", new SKPoint(xMin, yMin + yRange / 2), axisTitlePaint);
}

xMin += 10;
xMin += 10;

var widthPerCharacter = axisLabelPaint.MeasureText(" ");
var desiredYLabelCount = 11;
var maxYLabelCount = yRange / 50;
var ySkip = (int)(desiredYLabelCount / (float)maxYLabelCount) + 1;
var widthPerCharacter = axisLabelPaint.MeasureText(" ");
var desiredYLabelCount = 11;
var maxYLabelCount = yRange / 50;
var ySkip = (int)(desiredYLabelCount / (float)maxYLabelCount) + 1;

for (int i = 0; i < desiredYLabelCount; i++)
for (int i = 0; i < desiredYLabelCount; i++)
{
if ((i + ySkip) % ySkip == 0)
{
if ((i + ySkip) % ySkip == 0)
{
var relative = i / 10.0f;
var y = yMin + (1 - relative) * yRange;
var label = $"{(int)(relative * 100),3:D0}";
var lineOffset = widthPerCharacter * 3;

canvas.DrawText(label, new SKPoint(xMin, y + HALF_LINE_HEIGHT), axisLabelPaint);
canvas.DrawLine(new SKPoint(xMin + lineOffset, y), new SKPoint(xMax, y), axisTickPaint);
}
var relative = i / 10.0f;
var y = yMin + (1 - relative) * yRange;
var label = $"{(int)(relative * 100),3:D0}";
var lineOffset = widthPerCharacter * 3;

canvas.DrawText(label, new SKPoint(xMin, y + HALF_LINE_HEIGHT), axisLabelPaint);
canvas.DrawLine(new SKPoint(xMin + lineOffset, y), new SKPoint(xMax, y), axisTickPaint);
}
}

xMin += widthPerCharacter * 4;
xMin += widthPerCharacter * 4;

/* x-axis + data */
var count = AvailabilityData.Data.Count;
var xRange = xMax - xMin;
var valueWidth = xRange / count;
/* x-axis + data */
var count = AvailabilityData.Data.Count;
var xRange = xMax - xMin;
var valueWidth = xRange / count;

var maxXLabelCount = xRange / 200;
var xSkip = (int)(count / (float)maxXLabelCount) + 1;
var lastBegin = DateTime.MinValue;
var maxXLabelCount = xRange / 200;
var xSkip = (int)(count / (float)maxXLabelCount) + 1;
var lastBegin = DateTime.MinValue;

for (int i = 0; i < count; i++)
{
var availability = AvailabilityData.Data[i];
for (int i = 0; i < count; i++)
{
var availability = AvailabilityData.Data[i];

var x = xMin + i * valueWidth + valueWidth * 0.1f;
var y = yMin + yRange;
var w = valueWidth * 0.8f;
var h = -yRange * (float)availability;
var x = xMin + i * valueWidth + valueWidth * 0.1f;
var y = yMin + yRange;
var w = valueWidth * 0.8f;
var h = -yRange * (float)availability;

canvas.DrawRect(x, y, w, h, barFillPaint);
canvas.DrawRect(x, y, w, h, barFillPaint);

var path = new SKPath();
var path = new SKPath();

path.MoveTo(x, y);
path.RLineTo(0, h);
path.RLineTo(w, 0);
path.RLineTo(0, -h);
path.MoveTo(x, y);
path.RLineTo(0, h);
path.RLineTo(w, 0);
path.RLineTo(0, -h);

canvas.DrawPath(path, barStrokePaint);
canvas.DrawPath(path, barStrokePaint);

if ((i + xSkip) % xSkip == 0)
{
var currentBegin = AvailabilityData.Begin.AddDays(i);
canvas.DrawText(currentBegin.ToString("dd.MM"), xMin + (i + 0.5f) * valueWidth, yMax - 20, axisLabelCenteredPaint);
if ((i + xSkip) % xSkip == 0)
{
var currentBegin = AvailabilityData.Begin.AddDays(i);
canvas.DrawText(currentBegin.ToString("dd.MM"), xMin + (i + 0.5f) * valueWidth, yMax - 20, axisLabelCenteredPaint);

if (lastBegin.Year != currentBegin.Year)
canvas.DrawText(currentBegin.ToString("yyyy"), xMin + (i + 0.5f) * valueWidth, yMax, axisLabelCenteredPaint);
if (lastBegin.Year != currentBegin.Year)
canvas.DrawText(currentBegin.ToString("yyyy"), xMin + (i + 0.5f) * valueWidth, yMax, axisLabelCenteredPaint);

lastBegin = currentBegin;
}
lastBegin = currentBegin;
}
}
}
Expand Down
Loading

0 comments on commit f402fb1

Please sign in to comment.