Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

creating helper methods for rendertreebuilder in a world of sequence numbers

$
0
0

I'm using blazor - and writing stuff to draw graphs and I'm finding a lot of repeated code - like:

       // Draw X-axis        builder.OpenElement(100, "line");        builder.AddAttribute(101, "x1", graphArea.X);        builder.AddAttribute(102, "y1", graphArea.Y + graphArea.Height);        builder.AddAttribute(103, "x2", graphArea.X + graphArea.Width);        builder.AddAttribute(104, "y2", graphArea.Y + graphArea.Height);        builder.AddAttribute(105, "stroke", color);        builder.AddAttribute(106, "stroke-width", AxisThickness);        builder.CloseElement();        // Draw X-axis ticks and labels        for (var i = 0; i <= HorizontalTicks; i++)        {            var x = graphArea.X + i * graphArea.Width / HorizontalTicks;            var date = dateMin.AddTicks((dateMax - dateMin).Ticks * i / HorizontalTicks);            builder.OpenElement(110, "line");            builder.AddAttribute(111, "x1", x);            builder.AddAttribute(112, "y1", graphArea.Y + graphArea.Height);            builder.AddAttribute(113, "x2", x);            builder.AddAttribute(114, "y2", graphArea.Y + graphArea.Height + 5 * AxisThickness);            builder.AddAttribute(115, "stroke", color);            builder.AddAttribute(106, "stroke-width", AxisThickness);            builder.CloseElement();

what I really sort of want is to be able to say something like builder.AddLine( x, y, x+width, x + height, Color.Red);

but of course then I run into lots of warnings of programmatic sequence numbers and so on. Is there a way to do it without tanking performance?


Viewing all articles
Browse latest Browse all 4839

Trending Articles