style: add .editorconfig for code formatting. see issu #25

This commit is contained in:
leo 2024-03-18 09:37:06 +08:00
parent a8eeea4f78
commit 18aaa0a143
225 changed files with 7781 additions and 3911 deletions

View file

@ -1,18 +1,22 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace SourceGit.Views {
public class Chart : Control {
namespace SourceGit.Views
{
public class Chart : Control
{
public static readonly StyledProperty<IBrush> LineBrushProperty =
AvaloniaProperty.Register<Chart, IBrush>(nameof(LineBrush), Brushes.Gray);
public IBrush LineBrush {
public IBrush LineBrush
{
get => GetValue(LineBrushProperty);
set => SetValue(LineBrushProperty, value);
}
@ -20,7 +24,8 @@ namespace SourceGit.Views {
public static readonly StyledProperty<IBrush> ShapeBrushProperty =
AvaloniaProperty.Register<Chart, IBrush>(nameof(ShapeBrush), Brushes.Gray);
public IBrush ShapeBrush {
public IBrush ShapeBrush
{
get => GetValue(ShapeBrushProperty);
set => SetValue(ShapeBrushProperty, value);
}
@ -28,41 +33,59 @@ namespace SourceGit.Views {
public static readonly StyledProperty<List<Models.StatisticsSample>> SamplesProperty =
AvaloniaProperty.Register<Chart, List<Models.StatisticsSample>>(nameof(Samples), null);
public List<Models.StatisticsSample> Samples {
public List<Models.StatisticsSample> Samples
{
get => GetValue(SamplesProperty);
set => SetValue(SamplesProperty, value);
}
static Chart() {
SamplesProperty.Changed.AddClassHandler<Chart>((c, e) => {
static Chart()
{
SamplesProperty.Changed.AddClassHandler<Chart>((c, e) =>
{
c._hitBoxes.Clear();
c._lastHitIdx = -1;
c.InvalidateVisual();
});
}
public override void Render(DrawingContext context) {
public override void Render(DrawingContext context)
{
if (Samples == null) return;
var samples = Samples;
int maxV = 0;
foreach (var s in samples) {
foreach (var s in samples)
{
if (maxV < s.Count) maxV = s.Count;
}
if (maxV < 5) {
if (maxV < 5)
{
maxV = 5;
} else if (maxV < 10) {
}
else if (maxV < 10)
{
maxV = 10;
} else if (maxV < 50) {
}
else if (maxV < 50)
{
maxV = 50;
} else if (maxV < 100) {
}
else if (maxV < 100)
{
maxV = 100;
} else if (maxV < 200) {
}
else if (maxV < 200)
{
maxV = 200;
} else if (maxV < 500) {
}
else if (maxV < 500)
{
maxV = 500;
} else {
}
else
{
maxV = (int)Math.Ceiling(maxV / 500.0) * 500;
}
@ -89,7 +112,8 @@ namespace SourceGit.Views {
var stepV = (height - labelHeight) / 5;
var labelStepV = maxV / 5;
var gridPen = new Pen(LineBrush, 1, new DashStyle());
for (int i = 1; i < 5; i++) {
for (int i = 1; i < 5; i++)
{
var vLabel = new FormattedText(
$"{maxV - i * labelStepV}",
CultureInfo.CurrentCulture,
@ -100,16 +124,19 @@ namespace SourceGit.Views {
var dashHeight = i * stepV;
var vy = Math.Max(0, dashHeight - vLabel.Height * 0.5);
using (context.PushOpacity(.1)) {
using (context.PushOpacity(.1))
{
context.DrawLine(gridPen, new Point(horizonStart + 1, dashHeight), new Point(width, dashHeight));
}
context.DrawText(vLabel, new Point(horizonStart - vLabel.Width - 8, vy));
}
// Calculate hit boxes
if (_hitBoxes.Count == 0) {
if (_hitBoxes.Count == 0)
{
var shapeWidth = Math.Min(32, stepX - 4);
for (int i = 0; i < samples.Count; i++) {
for (int i = 0; i < samples.Count; i++)
{
var h = samples[i].Count * (height - labelHeight) / maxV;
var x = horizonStart + 1 + stepX * i + (stepX - shapeWidth) * 0.5;
var y = height - labelHeight - h;
@ -118,7 +145,8 @@ namespace SourceGit.Views {
}
// Draw shapes
for (int i = 0; i < samples.Count; i++) {
for (int i = 0; i < samples.Count; i++)
{
var hLabel = new FormattedText(
samples[i].Name,
CultureInfo.CurrentCulture,
@ -132,20 +160,25 @@ namespace SourceGit.Views {
context.DrawRectangle(ShapeBrush, null, rect);
if (stepX < 32) {
if (stepX < 32)
{
var matrix = Matrix.CreateTranslation(hLabel.Width * 0.5, -hLabel.Height * 0.5) // Center of label
* Matrix.CreateRotation(Math.PI * 0.25) // Rotate
* Matrix.CreateTranslation(xLabel, yLabel); // Move
using (context.PushTransform(matrix)) {
using (context.PushTransform(matrix))
{
context.DrawText(hLabel, new Point(0, 0));
}
} else {
}
else
{
context.DrawText(hLabel, new Point(xLabel, yLabel));
}
}
// Draw labels on hover
if (_lastHitIdx >= 0 && _lastHitIdx < samples.Count) {
if (_lastHitIdx >= 0 && _lastHitIdx < samples.Count)
{
var rect = _hitBoxes[_lastHitIdx];
var tooltip = new FormattedText(
$"{samples[_lastHitIdx].Count}",
@ -161,42 +194,51 @@ namespace SourceGit.Views {
}
}
protected override void OnPointerMoved(PointerEventArgs e) {
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
var p = e.GetPosition(this);
for (int i = 0; i < _hitBoxes.Count; i++) {
if (_hitBoxes[i].Contains(p)) {
if (_lastHitIdx != i) {
for (int i = 0; i < _hitBoxes.Count; i++)
{
if (_hitBoxes[i].Contains(p))
{
if (_lastHitIdx != i)
{
_lastHitIdx = i;
InvalidateVisual();
}
return;
}
}
if (_lastHitIdx != -1) {
if (_lastHitIdx != -1)
{
_lastHitIdx = -1;
InvalidateVisual();
}
}
}
private List<Rect> _hitBoxes = new List<Rect>();
private readonly List<Rect> _hitBoxes = new List<Rect>();
private int _lastHitIdx = -1;
}
public partial class Statistics : Window {
public Statistics() {
public partial class Statistics : Window
{
public Statistics()
{
InitializeComponent();
}
private void BeginMoveWindow(object sender, PointerPressedEventArgs e) {
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
{
BeginMoveDrag(e);
}
private void CloseWindow(object sender, RoutedEventArgs e) {
private void CloseWindow(object sender, RoutedEventArgs e)
{
Close();
}
}
}
}