Improved readibility of the table layout algorithm
This commit is contained in:
committed by
Marcin Ziąbek
parent
06418238dc
commit
b8ea30be23
@@ -16,85 +16,6 @@ namespace QuestPDF.Examples
|
||||
{
|
||||
public static Random Random { get; } = new Random();
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
RenderingTest
|
||||
.Create()
|
||||
.ProduceImages()
|
||||
.PageSize(PageSizes.A4)
|
||||
.ShowResults()
|
||||
.Render(container =>
|
||||
{
|
||||
container
|
||||
.Padding(25)
|
||||
.Box()
|
||||
.Border(2)
|
||||
.Table(table =>
|
||||
{
|
||||
table.ColumnsDefinition(columns =>
|
||||
{
|
||||
columns.ConstantColumn(100);
|
||||
columns.RelativeColumn();
|
||||
columns.ConstantColumn(100);
|
||||
columns.ConstantColumn(200);
|
||||
});
|
||||
|
||||
table.Cell().ColumnSpan(2).Element(CreateBox("A"));
|
||||
table.Cell().Element(CreateBox("B"));
|
||||
table.Cell().Element(CreateBox("C"));
|
||||
|
||||
table.Cell().Element(CreateBox("D"));
|
||||
table.Cell().RowSpan(2).Element(CreateBox("E"));
|
||||
table.Cell().RowSpan(3).ColumnSpan(2).Element(CreateBox("F"));
|
||||
|
||||
table.Cell().RowSpan(2).Element(CreateBox("G"));
|
||||
table.Cell().RowSpan(2).Element(CreateBox("H"));
|
||||
table.Cell().Element(CreateBox("I"));
|
||||
table.Cell().Element(CreateBox("J"));
|
||||
table.Cell().RowSpan(2).Element(CreateBox("K"));
|
||||
table.Cell().ColumnSpan(2).Element(CreateBox("L"));
|
||||
table.Cell().Element(CreateBox("M"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TreeTable()
|
||||
{
|
||||
RenderingTest
|
||||
.Create()
|
||||
.ProducePdf()
|
||||
.PageSize(PageSizes.A4)
|
||||
.ShowResults()
|
||||
.Render(container =>
|
||||
{
|
||||
container
|
||||
.Padding(25)
|
||||
.Box()
|
||||
.Border(2)
|
||||
.Table(table =>
|
||||
{
|
||||
table.ColumnsDefinition(columns =>
|
||||
{
|
||||
columns.RelativeColumn(100);
|
||||
columns.RelativeColumn(100);
|
||||
columns.RelativeColumn(100);
|
||||
});
|
||||
|
||||
table.Cell().RowSpan(4).Element(CreateBox("A"));
|
||||
|
||||
table.Cell().RowSpan(2).Element(CreateBox("B"));
|
||||
table.Cell().Element(CreateBox("C"));
|
||||
table.Cell().Element(CreateBox("D"));
|
||||
|
||||
table.Cell().RowSpan(2).Element(CreateBox("E"));
|
||||
table.Cell().Element(CreateBox("F"));
|
||||
table.Cell().Element(CreateBox("G"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TemperatureReport()
|
||||
{
|
||||
@@ -102,18 +23,7 @@ namespace QuestPDF.Examples
|
||||
.Create()
|
||||
.ProducePdf()
|
||||
.PageSize(PageSizes.A4)
|
||||
.ShowResults()
|
||||
.Render(container => GeneratePerformanceStructure(container, 10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TemperatureReport_PerformanceTest()
|
||||
{
|
||||
RenderingTest
|
||||
.Create()
|
||||
.ProducePdf()
|
||||
.PageSize(PageSizes.A4)
|
||||
.MaxPages(10000)
|
||||
.MaxPages(10_000)
|
||||
.EnableCaching()
|
||||
.EnableDebugging(false)
|
||||
.ShowResults()
|
||||
@@ -184,20 +94,5 @@ namespace QuestPDF.Examples
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Action<IContainer> CreateBox(string label)
|
||||
{
|
||||
return container =>
|
||||
{
|
||||
var height = Random.Next(2, 6) * 10;
|
||||
|
||||
container
|
||||
.Background(Placeholders.BackgroundColor())
|
||||
// .AlignCenter()
|
||||
// .AlignMiddle()
|
||||
.Height(height);
|
||||
// .Text($"{label}: {height}px");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Engines;
|
||||
using BenchmarkDotNet.Running;
|
||||
using NUnit.Framework;
|
||||
using QuestPDF.Drawing;
|
||||
using QuestPDF.Drawing.Proxy;
|
||||
using QuestPDF.Elements;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Helpers;
|
||||
using QuestPDF.Infrastructure;
|
||||
|
||||
namespace QuestPDF.Examples
|
||||
{
|
||||
[SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 16)]
|
||||
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
|
||||
public class TablePerformanceTest
|
||||
{
|
||||
private static Random Random { get; } = new Random();
|
||||
|
||||
private PageContext PageContext { get; set; }
|
||||
private DocumentMetadata Metadata { get; set; }
|
||||
private Container Content { get; set; }
|
||||
|
||||
[Test]
|
||||
public void Run()
|
||||
{
|
||||
var configuration = ManualConfig
|
||||
.Create(DefaultConfig.Instance)
|
||||
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
|
||||
|
||||
BenchmarkRunner.Run<TablePerformanceTest>(configuration);
|
||||
}
|
||||
|
||||
[IterationSetup]
|
||||
[SetUp]
|
||||
public void GenerateReportData()
|
||||
{
|
||||
Metadata = new DocumentMetadata()
|
||||
{
|
||||
DocumentLayoutExceptionThreshold = 1000
|
||||
};
|
||||
|
||||
var documentContainer = new DocumentContainer();
|
||||
|
||||
documentContainer.Page(page =>
|
||||
{
|
||||
page.Size(PageSizes.A3);
|
||||
GeneratePerformanceStructure(page.Content(), 10_000);
|
||||
});
|
||||
|
||||
Content = documentContainer.Compose();
|
||||
|
||||
PageContext = new PageContext();
|
||||
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
|
||||
|
||||
Content.HandleVisitor(x =>
|
||||
{
|
||||
if (x is ICacheable)
|
||||
x.CreateProxy(y => new CacheProxy(y));
|
||||
});
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[Test]
|
||||
public void GenerationTest()
|
||||
{
|
||||
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
|
||||
}
|
||||
|
||||
void GeneratePerformanceStructure(IContainer container, int itemsCount)
|
||||
{
|
||||
container
|
||||
.Padding(25)
|
||||
.Table(table =>
|
||||
{
|
||||
table.ColumnsDefinition(columns =>
|
||||
{
|
||||
foreach (var size in Enumerable.Range(0, 10))
|
||||
columns.ConstantColumn(100);
|
||||
});
|
||||
|
||||
foreach (var i in Enumerable.Range(1, itemsCount))
|
||||
{
|
||||
table
|
||||
.Cell()
|
||||
.RowSpan((uint)Random.Next(1, 5))
|
||||
.ColumnSpan((uint)Random.Next(1, 5))
|
||||
.Element(CreateBox(i.ToString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Action<IContainer> CreateBox(string label)
|
||||
{
|
||||
return container =>
|
||||
{
|
||||
var height = Random.Next(2, 6) * 20;
|
||||
|
||||
container
|
||||
.Border(2)
|
||||
.Background(Placeholders.BackgroundColor())
|
||||
.AlignCenter()
|
||||
.AlignMiddle()
|
||||
.Height(height)
|
||||
.Text($"{label}: {height}px");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user