visualisierung
This commit is contained in:
1 parent
d0655f3638
commit
367c93c93e
84 files changed
+2265
-148
No files matched your search
@@ -341,21 +341,45 @@ export class DrawAnlageDurmin {
|
||||
let ba3_pos_hf_x = 750
|
||||
let ba3_pos_hf_y = 770 //anfanf(B1) 130 B2 310; B3 ende 520
|
||||
|
||||
group1.add(this.createBand({ posX: 100, posY: 20, width: zufuefband_l, height: zufuefband_b, nordSued: true, boxEnde: true })) // BA1 Zufuehrband
|
||||
group1.add(this.createBand({ posX: ba1_pos_hf_x, posY: ba1_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
group1.add(this.createBand({ posX: ba1_pos_hf_x - (kopfband_l / 2 - verteilband_b / 2), posY: ba1_pos_hf_y - (kopfband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
group1.add(this.createBand({ posX: ba1_pos_hf_x - (kopfband_l / 2 - verteilband_b / 2), posY: ba1_pos_hf_y + verteilband_l - (kopfband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
/* group1.add(new DrawLine({x1:0,y1:100,x2:1500,y2:100}));
|
||||
group1.add(new DrawLine({x1:0,y1:110,x2:1500,y2:110}));
|
||||
group1.add(new DrawLine({x1:0,y1:120,x2:1500,y2:120}));
|
||||
group1.add(new DrawLine({x1:0,y1:130,x2:1500,y2:130}));
|
||||
group1.add(new DrawLine({x1:0,y1:140,x2:1500,y2:140}));
|
||||
group1.add(new DrawLine({x1:0,y1:150,x2:1500,y2:150}));
|
||||
group1.add(new DrawLine({x1:0,y1:160,x2:1500,y2:160}));
|
||||
group1.add(new DrawLine({x1:0,y1:170,x2:1500,y2:170}));
|
||||
group1.add(new DrawLine({x1:0,y1:180,x2:1500,y2:180}));
|
||||
group1.add(new DrawLine({x1:0,y1:190,x2:1500,y2:190}));
|
||||
group1.add(new DrawLine({x1:0,y1:200,x2:1500,y2:200}));
|
||||
|
||||
group1.add(new DrawLine({x1:10,y1:0,x2:10,y2:1100}));
|
||||
group1.add(new DrawLine({x1:20,y1:0,x2:20,y2:1100}));
|
||||
group1.add(new DrawLine({x1:30,y1:0,x2:30,y2:1100}));
|
||||
group1.add(new DrawLine({x1:40,y1:0,x2:40,y2:1100}));
|
||||
group1.add(new DrawLine({x1:50,y1:0,x2:50,y2:1100}));
|
||||
group1.add(new DrawLine({x1:60,y1:0,x2:60,y2:1100}));
|
||||
group1.add(new DrawLine({x1:70,y1:0,x2:70,y2:1100}));
|
||||
|
||||
group1.add(new DrawLine({x1:80,y1:0,x2:80,y2:1100}));
|
||||
group1.add(new DrawLine({x1:90,y1:0,x2:90,y2:1100}));
|
||||
group1.add(new DrawLine({x1:100,y1:0,x2:100,y2:1100}));
|
||||
*/
|
||||
//group1.add(this.createBand({ posX: 100, posY: 20, width: zufuefband_l, height: zufuefband_b, nordSued: true, boxEnde: true })) // BA1 Zufuehrband
|
||||
//group1.add(this.createBand({ posX: ba1_pos_hf_x, posY: ba1_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
//group1.add(this.createBand({ posX: ba1_pos_hf_x - (kopfband_l / 2 - verteilband_b / 2), posY: ba1_pos_hf_y - (kopfband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
//group1.add(this.createBand({ posX: ba1_pos_hf_x - (kopfband_l / 2 - verteilband_b / 2), posY: ba1_pos_hf_y + verteilband_l - (kopfband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
|
||||
|
||||
group1.add(this.createBand({ posX: 340, posY: 240, width: zufuefband_l + 400, height: zufuefband_b, nordSued: false, boxStart: true, boxEnde: true }))// BA2 Zufuehrband
|
||||
group1.add(this.createBand({ posX: ba2_pos_hf_x, posY: ba2_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
group1.add(this.createBand({ posX: ba2_pos_hf_x - (kopfband_b / 2), posY: ba2_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
group1.add(this.createBand({ posX: ba2_pos_hf_x + verteilband_l - (kopfband_b / 2), posY: ba2_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
//group1.add(this.createBand({ posX: 340, posY: 240, width: zufuefband_l + 400, height: zufuefband_b, nordSued: false, boxStart: true, boxEnde: true }))// BA2 Zufuehrband
|
||||
//group1.add(this.createBand({ posX: ba2_pos_hf_x, posY: ba2_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
//group1.add(this.createBand({ posX: ba2_pos_hf_x - (kopfband_b / 2), posY: ba2_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
//group1.add(this.createBand({ posX: ba2_pos_hf_x + verteilband_l - (kopfband_b / 2), posY: ba2_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
|
||||
group1.add(this.createBand({ posX: 360, posY: 900, width: zufuefband_l + 400, height: zufuefband_b, nordSued: false, boxStart: true, boxEnde: true }))// BA2 Zufuehrband
|
||||
group1.add(this.createBand({ posX: ba3_pos_hf_x, posY: ba3_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
group1.add(this.createBand({ posX: ba3_pos_hf_x - (kopfband_b / 2), posY: ba3_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
group1.add(this.createBand({ posX: ba3_pos_hf_x + verteilband_l - (kopfband_b / 2), posY: ba3_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
//group1.add(this.createBand({ posX: 360, posY: 900, width: zufuefband_l + 400, height: zufuefband_b, nordSued: false, boxStart: true, boxEnde: true }))// BA2 Zufuehrband
|
||||
//group1.add(this.createBand({ posX: ba3_pos_hf_x, posY: ba3_pos_hf_y, width: verteilband_l, height: verteilband_b, nordSued: false, boxEnde: true, boxStart: true }))// BA1 Verteilband
|
||||
//group1.add(this.createBand({ posX: ba3_pos_hf_x - (kopfband_b / 2), posY: ba3_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband hinten
|
||||
//group1.add(this.createBand({ posX: ba3_pos_hf_x + verteilband_l - (kopfband_b / 2), posY: ba3_pos_hf_y - (kopfband_l / 2) + (verteilband_b / 2), width: kopfband_l, height: kopfband_b, nordSued: true, boxEnde: true, boxStart: true }))// BA2 Kopfband vorne
|
||||
|
||||
group1.add(zBa1Schine1);
|
||||
group1.add(zBa1Schine2);
|
||||
|
||||
@@ -12,10 +12,57 @@ describe('BandOben render', () => {
|
||||
const result = new DrawBandOben().getObject({ width: 40, length: 200 }, { fromNorthToSouth, trichterStart });
|
||||
expect(result.width).toBe(width);
|
||||
expect(result.height).toBe(height);
|
||||
expect(result.svg[0].data).toContain('<svg xmlns=');
|
||||
expect(result.svg[0].data).toContain('viewBox="0 0 ' + width + ' ' + height + '"');
|
||||
expect(result.xaml[0].data).toContain('<Viewbox xmlns=');
|
||||
expect(result.xaml[0].data).toContain('Width="' + width + '" Height="' + height + '"');
|
||||
expect(result.varianten[0].svg).toContain('<svg xmlns=');
|
||||
expect(result.varianten[0].svg).toContain('viewBox="0 0 ' + width + ' ' + height + '"');
|
||||
expect(result.varianten[0].xaml).toContain('<Viewbox Stretch="None" StretchDirection="Both" Width="' + width + '" Height="' + height + '" xmlns=');
|
||||
expect(result.varianten[0].xaml).toContain('Width="' + width + '" Height="' + height + '"');
|
||||
});
|
||||
|
||||
it.each([false, true])('liefert Statuspunkte mittig und über dem Band (Nord-Süd %s)', fromNorthToSouth => {
|
||||
const result = new DrawBandOben().getObject({ width: 40, length: 200 }, { fromNorthToSouth, trichterStart: true });
|
||||
expect(result.varianten.map(item => item.state)).toEqual(['inactive', 'active', 'error']);
|
||||
result.varianten.forEach(item => expect(Buffer.from(item.xamlBase64, 'base64').toString('utf8')).toBe(item.xaml));
|
||||
expect(result.varianten[0].svg).not.toContain('<ellipse');
|
||||
for (const [index, color] of [[1, '#00f000'], [2, '#f00000']] as const) {
|
||||
const svg = result.varianten[index].svg;
|
||||
expect(svg).toContain('cx="' + result.width / 2 + '"');
|
||||
expect(svg).toContain('cy="' + result.height / 2 + '"');
|
||||
expect(svg).toContain('fill="' + color + '"');
|
||||
expect(svg.lastIndexOf('<ellipse')).toBeGreaterThan(svg.lastIndexOf('<path'));
|
||||
expect(result.varianten[index].xaml).toContain('Fill="' + color + '"');
|
||||
expect(result.varianten[index].xaml).toContain('<Ellipse');
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
[false, true, false], [true, true, false],
|
||||
[false, false, true], [true, false, true],
|
||||
[false, true, true], [true, true, true],
|
||||
])('setzt die äußere Referenzbox lokal auf 0,0 (%s, %s, %s)', (nordSued, boxStart, boxEnde) => {
|
||||
const result = new DrawBandOben().createBand({ width: 40, height: 200, posX: 0, posY: 0, nordSued, boxStart, boxEnde });
|
||||
const svg = result.band.getChildString(false, 0);
|
||||
const xaml = result.band.getChildString(true, 0);
|
||||
expect(svg).toMatch(/d="M 0 0[^"]*"[^>]*fill="#e0e0e0"/);
|
||||
expect(xaml).toMatch(/Data="M 0,0[^"]*"[^>]*Fill="#e0e0e0"/);
|
||||
if (!boxStart) {
|
||||
expect(svg).toContain(nordSued ? 'M 5 -180' : 'M -180 5');
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
[false, false, false], [true, false, false],
|
||||
[false, true, false], [true, true, false],
|
||||
[false, false, true], [true, false, true],
|
||||
[false, true, true], [true, true, true],
|
||||
])('übernimmt die tatsächlichen Gesamtmaße auch bei kleinen Bändern (%s, %s, %s)', (fromNorthToSouth, trichterStart, trichterEnd) => {
|
||||
const config = { width: 12, length: 30 };
|
||||
const options = { fromNorthToSouth, trichterStart, trichterEnd };
|
||||
const result = new DrawBandOben().getObject(config, options);
|
||||
const crossSize = 12 + (trichterStart || trichterEnd ? 10 : 0) + 2;
|
||||
expect(result.width).toBe(fromNorthToSouth ? crossSize : 32);
|
||||
expect(result.height).toBe(fromNorthToSouth ? 32 : crossSize);
|
||||
expect(result.varianten[1].svg).toContain('cx="' + result.width / 2 + '"');
|
||||
expect(result.varianten[1].svg).toContain('cy="' + result.height / 2 + '"');
|
||||
});
|
||||
|
||||
it('setzt fehlende Optionen auf false und erhält explizites false', () => {
|
||||
|
||||
@@ -107,9 +107,23 @@ export class DrawBandOben implements GraphicGenerator<BandObenConfig, BandObenOp
|
||||
];
|
||||
|
||||
|
||||
// Lokaler Ursprung: äußere Startbox, sonst äußere Endbox, sonst Bandanfang.
|
||||
const anchor = data.boxStart ? pBandBoxStart[0] : data.boxEnde ? pBandBoxEnd[0] : pBand1[0];
|
||||
const anchorX = anchor.type === 'M' ? anchor.x : 0;
|
||||
const anchorY = anchor.type === 'M' ? anchor.y : 0;
|
||||
for (const path of [pBand1, pBand2, pBandBoxStart, pBandBoxStartInnen, pBandBoxEnd, pBandBoxEndInnen]) {
|
||||
const start = path[0];
|
||||
if (start.type === 'M') {
|
||||
path[0] = { ...start, x: start.x - anchorX, y: start.y - anchorY };
|
||||
}
|
||||
}
|
||||
const group = new DrawGroup({});
|
||||
const ueberstand = data.boxStart || data.boxEnde ? boxUeberstand : 0;
|
||||
group.setAtrr({ translate_y: posY + (nordSued ? 0 : ueberstand) + 1, translate_x: posX + (nordSued ? ueberstand : 0) + 1 })
|
||||
// Dokumentrahmen berücksichtigt negative lokale Koordinaten sowie den Linienrand.
|
||||
group.setAtrr({
|
||||
translate_y: posY + anchorY + (nordSued ? 0 : ueberstand) + 1,
|
||||
translate_x: posX + anchorX + (nordSued ? ueberstand : 0) + 1,
|
||||
});
|
||||
|
||||
const belt1 = new DrawPath(pBand1);
|
||||
belt1.setAtrr({ fill: "#404040", stroke: "#404040" })
|
||||
@@ -143,6 +157,7 @@ export class DrawBandOben implements GraphicGenerator<BandObenConfig, BandObenOp
|
||||
|
||||
group.add(belt2)
|
||||
group.add(belt1)
|
||||
|
||||
return {
|
||||
band: group,
|
||||
width: width + (nordSued ? 2 * ueberstand : 0) + 2,
|
||||
@@ -172,19 +187,32 @@ export class DrawBandOben implements GraphicGenerator<BandObenConfig, BandObenOp
|
||||
}
|
||||
|
||||
getObject(config: BandObenConfig, options?: Partial<BandObenOptions>): DrawDataDto {
|
||||
const beldData = this.create(config,options)
|
||||
const bedlWithHeader = this.createObjectWithHeader(beldData.group,beldData.width,beldData.height);
|
||||
|
||||
const xaml = bedlWithHeader.getChildString(true,0);
|
||||
const svg = bedlWithHeader.getChildString(false, 0)
|
||||
|
||||
const bandData = this.create(config, options);
|
||||
const states = ['inactive', 'active', 'error'] as const;
|
||||
const graphics = states.map(state => {
|
||||
const group = new DrawGroup({});
|
||||
if (state !== 'inactive') {
|
||||
const radius = config.width * 0.15;
|
||||
const color = state === 'active' ? this.green : this.red;
|
||||
const point = new DrawEllipse({
|
||||
cx: bandData.width / 2, cy: bandData.height / 2, rx: radius, ry: radius,
|
||||
});
|
||||
point.setAtrr({ fill: color, stroke: color });
|
||||
// DrawGroup gibt die Elemente rückwärts aus: Punkt über dem Band.
|
||||
group.add(point);
|
||||
}
|
||||
group.add(bandData.group);
|
||||
const header = this.createObjectWithHeader(group, bandData.width, bandData.height);
|
||||
const xaml = header.getChildString(true, 0).replace(
|
||||
'<Viewbox ',
|
||||
`<Viewbox Stretch="None" StretchDirection="Both" Width="${bandData.width}" Height="${bandData.height}" `,
|
||||
);
|
||||
return { state, svg: header.getChildString(false, 0), xaml };
|
||||
});
|
||||
return {
|
||||
name: "bandOben",
|
||||
height: beldData.height,
|
||||
width: beldData.width,
|
||||
svg:[{state:'inactive',data:svg}],
|
||||
xaml:[{state:'inactive',data:xaml}]
|
||||
}
|
||||
name: 'bandOben', width: bandData.width, height: bandData.height,
|
||||
varianten: graphics.map(item => ({ ...item, xamlBase64: Buffer.from(item.xaml, 'utf8').toString('base64') })),
|
||||
};
|
||||
}
|
||||
|
||||
createObjectWithHeader(group:DrawGroup,width:number,height:number):DrawHeader{
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { DrawMotor } from './drawMotor';
|
||||
import { parseMotorRequest } from '../../_dto/motor.dto';
|
||||
|
||||
describe('Motor getObject', () => {
|
||||
it('liefert drei Zustände als vollständiges SVG und XAML', () => {
|
||||
const result = new DrawMotor().getObject({ scale: 2, raster: 4 });
|
||||
expect(result.width).toBe(24);
|
||||
expect(result.height).toBe(24);
|
||||
expect(result.varianten.map(item => item.state)).toEqual(['inactive', 'active', 'error']);
|
||||
result.varianten.forEach(item => expect(item.svg).toContain('<svg xmlns='));
|
||||
result.varianten.forEach(item => expect(item.xaml).toContain('<Viewbox xmlns='));
|
||||
result.varianten.forEach(item => expect(Buffer.from(item.xamlBase64, 'base64').toString('utf8')).toBe(item.xaml));
|
||||
expect(result.varianten[1].svg).toContain('#00f000');
|
||||
expect(result.varianten[2].xaml).toContain('#f00000');
|
||||
});
|
||||
it('übernimmt Farben und behält bestehende GET-Ausgaben bei', () => {
|
||||
const generator = new DrawMotor();
|
||||
expect(generator.getObject({ scale: 1, raster: 10 }, { colorActive: '#123456' }).varianten[1].svg).toContain('#123456');
|
||||
expect(generator.getDrawObject({}).px_width).toBe(24);
|
||||
expect(generator.getSvg({})).toContain('<svg');
|
||||
});
|
||||
it('setzt Standardwerte bei leerer config', () => {
|
||||
expect(parseMotorRequest({ config: {} })).toEqual({ config: { scale: 2, raster: 4 }, options: {} });
|
||||
});
|
||||
it.each([1, 2, 4])('zentriert das M in beiden Formaten bei Skalierung %s', scale => {
|
||||
const size = 3 * 4 * scale;
|
||||
const result = new DrawMotor().getObject({ scale, raster: 4 });
|
||||
for (const { svg: data } of result.varianten) {
|
||||
expect(data).toContain('x="' + size / 2 + '" y="' + size / 2 + '"');
|
||||
expect(data).toContain('text-anchor="middle" dominant-baseline="central"');
|
||||
expect(data).toContain('font-size="' + size * 0.6 + '"');
|
||||
expect(data).toContain('>M</text>');
|
||||
expect(data.indexOf('<ellipse')).toBeLessThan(data.indexOf('<text'));
|
||||
}
|
||||
for (const { xaml: data } of result.varianten) {
|
||||
expect(data).toContain('<Grid Canvas.Left="0" Canvas.Top="0" Width="' + size + '" Height="' + size + '">');
|
||||
expect(data).toContain('Text="M"');
|
||||
expect(data).toContain('FontSize="' + size * 0.6 + '"');
|
||||
expect(data).toContain('HorizontalAlignment="Center" VerticalAlignment="Center"');
|
||||
}
|
||||
});
|
||||
it.each([null, {}, { config: { scale: 0 } }, { config: { raster: '4' } },
|
||||
{ config: {}, options: { colorActive: 'red' } }, { config: { unbekannt: 1 } }])('verhindert ungültige Eingaben %j', value => {
|
||||
expect(() => parseMotorRequest(value)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,9 @@ import { DrawEllipse } from "../lib/drawEllipse";
|
||||
|
||||
import { cal_rotation_dim } from '../lib/drawFunktions'
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { DrawDto, DrawShapeOptionenDto } from "src/_dto/draw.dto";
|
||||
import { DrawDataDto, DrawDto, DrawShapeOptionenDto } from "src/_dto/draw.dto";
|
||||
import type { GraphicGenerator } from './graphic-generator';
|
||||
import type { MotorConfig, MotorOptions } from './types';
|
||||
import { DrawHeader } from "../lib/drawHeader";
|
||||
|
||||
interface Para {
|
||||
@@ -14,7 +16,7 @@ interface Para {
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class DrawMotor {
|
||||
export class DrawMotor implements GraphicGenerator<MotorConfig, MotorOptions> {
|
||||
scale = 0;
|
||||
winkel = 0;
|
||||
raster = 4;
|
||||
@@ -35,9 +37,9 @@ export class DrawMotor {
|
||||
|
||||
|
||||
create(optionen?: DrawShapeOptionenDto): DrawGroup {
|
||||
let color = this.normal;
|
||||
if (optionen && optionen.state == 'active') color = this.green;
|
||||
if (optionen && optionen.state == 'error') color = this.red;
|
||||
let color = optionen?.colorInactive ?? this.normal;
|
||||
if (optionen && optionen.state == 'active') color = optionen.colorActive ?? this.green;
|
||||
if (optionen && optionen.state == 'error') color = optionen.colorError ?? this.red;
|
||||
|
||||
|
||||
let raster = 4.0;
|
||||
@@ -65,7 +67,10 @@ export class DrawMotor {
|
||||
|
||||
|
||||
const z_kreis = new DrawEllipse({ cx: x_m, cy: y_m, rx: radius, ry: radius });
|
||||
const z_text = new DrawText({ x: 5, y: 0, text:"M" });
|
||||
const z_text = new DrawText({
|
||||
x: 0, y: 0, text: "M",
|
||||
centeredBox: { width: obj_w, height: obj_h, fontSize: obj_h * 0.6 },
|
||||
});
|
||||
z_kreis.setAtrr({ fill: color })
|
||||
|
||||
|
||||
@@ -88,6 +93,23 @@ export class DrawMotor {
|
||||
|
||||
}
|
||||
|
||||
getObject(config: MotorConfig, options?: Partial<MotorOptions>): DrawDataDto {
|
||||
const width = 3 * config.raster * config.scale;
|
||||
const states = ['inactive', 'active', 'error'] as const;
|
||||
const graphics = states.map(state => {
|
||||
const group = this.create({ ...config, ...options, state });
|
||||
const header = new DrawHeader({ lenght: width, height: width });
|
||||
header.add(group);
|
||||
return { state, svg: header.getChildString(false, 0), xaml: header.getChildString(true, 0) };
|
||||
});
|
||||
return {
|
||||
name: 'motor',
|
||||
width,
|
||||
height: width,
|
||||
varianten: graphics.map(item => ({ ...item, xamlBase64: Buffer.from(item.xaml, 'utf8').toString('base64') })),
|
||||
};
|
||||
}
|
||||
|
||||
getDrawObject(optionen?: DrawShapeOptionenDto): DrawDto {
|
||||
const groupSvg = this.create(optionen)
|
||||
const svg = groupSvg.getChildString(false, 0)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { DrawWarnung, parseWarnungRequest } from './drawWarnung';
|
||||
|
||||
describe('Warnung ohne MinMax', () => {
|
||||
it('liefert die Originalgeometrie als SVG, XAML und UTF-8-Base64', () => {
|
||||
const { config, options } = parseWarnungRequest({ config: {} });
|
||||
const result = new DrawWarnung().getObject(config, options);
|
||||
expect(result.width).toBe(20);
|
||||
expect(result.height).toBe(20);
|
||||
expect(result.varianten).toHaveLength(1);
|
||||
const variant = result.varianten[0];
|
||||
expect(variant.svg).toContain('fill="#FAC44F" fill-rule="evenodd"');
|
||||
expect(variant.xaml).toContain('FillRule="EvenOdd"');
|
||||
expect(variant.xaml).toContain('Width="20" Height="20"');
|
||||
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
|
||||
});
|
||||
it('übernimmt Größe und Farbe', () => {
|
||||
const { config, options } = parseWarnungRequest({ config: { width: 40, height: 30 }, options: { color: '#FF0000' } });
|
||||
expect(new DrawWarnung().getObject(config, options).varianten[0].svg).toContain('fill="#FF0000"');
|
||||
});
|
||||
it.each([null, {}, { config: { width: -1 } }, { config: {}, options: { color: '<script>' } }])('weist ungültige Parameter zurück', input => {
|
||||
expect(() => parseWarnungRequest(input)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import type { DrawDataDto } from '../../_dto/draw.dto';
|
||||
import type { GraphicGenerator } from './graphic-generator';
|
||||
|
||||
export interface WarnungConfig { width: number; height: number }
|
||||
export interface WarnungOptions { color: string }
|
||||
|
||||
export function parseWarnungRequest(input: unknown): { config: WarnungConfig; options: WarnungOptions } {
|
||||
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
||||
if (!object(input) || !object(input.config) || Object.keys(input).some(key => !['config', 'options'].includes(key)))
|
||||
throw new BadRequestException('Erwartet werden config und optional options');
|
||||
const options = input.options ?? {};
|
||||
const width = input.config.width ?? 20, height = input.config.height ?? 20;
|
||||
if (Object.keys(input.config).some(key => !['width', 'height'].includes(key)) ||
|
||||
typeof width !== 'number' || !Number.isFinite(width) || width <= 0 ||
|
||||
typeof height !== 'number' || !Number.isFinite(height) || height <= 0)
|
||||
throw new BadRequestException('width und height müssen positive endliche Zahlen sein');
|
||||
if (!object(options) || Object.keys(options).some(key => key !== 'color') ||
|
||||
(options.color !== undefined && (typeof options.color !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(options.color))))
|
||||
throw new BadRequestException('options erlaubt color als Hexfarbe #RRGGBB');
|
||||
return { config: { width, height }, options: { color: options.color as string ?? '#FAC44F' } };
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DrawWarnung implements GraphicGenerator<WarnungConfig, WarnungOptions> {
|
||||
getObject(config: WarnungConfig, options?: Partial<WarnungOptions>): DrawDataDto {
|
||||
const color = options?.color ?? '#FAC44F';
|
||||
// Originalgeometrie aus „Warnung ohne MinMax.xaml“, einschließlich EvenOdd-Aussparungen.
|
||||
const path = 'm 424.39268 319.47728 h -8.05519 c -0.36301 -0.36301 -0.36301 -0.95151 -1.1e-4 -1.31452 l 3.47998 -6.42969 c 0.3629 -0.36291 0.95141 -0.36291 1.31442 0 l 3.2609 6.42979 c 0.3629 0.36291 0.3629 0.95141 0 1.31442 z m -4.80212 -5.80912 0.38721 3.17549 h 0.77442 l 0.38728 -3.17549 z m 0.77442 3.64031 c -0.34209 0 -0.61958 0.27739 -0.61958 0.61958 0 0.3422 0.27749 0.61962 0.61958 0.61962 0.34219 0 0.61958 -0.27742 0.61958 -0.61962 0 -0.34219 -0.27739 -0.61958 -0.61958 -0.61958';
|
||||
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="${config.width}" height="${config.height}" viewBox="0 0 8.5996358 8.0163929"><g transform="translate(-416.06522 -311.46089)"><path d="${path}" fill="${color}" fill-rule="evenodd"/></g></svg>`;
|
||||
const xaml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Width="${config.width}" Height="${config.height}"><Canvas Width="8.5996358" Height="8.0163929"><Canvas><Canvas.RenderTransform><TranslateTransform X="-416.06522" Y="-311.46089"/></Canvas.RenderTransform><Path Fill="${color}" StrokeThickness="0.352777"><Path.Data><PathGeometry Figures="${path}" FillRule="EvenOdd"/></Path.Data></Path></Canvas></Canvas></Viewbox>`;
|
||||
return {
|
||||
name: 'warnung', ...config, varianten: [{
|
||||
state: 'inactive', svg, xaml, xamlBase64: Buffer.from(xaml, 'utf8').toString('base64'),
|
||||
}]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,14 @@ export interface BandObenOptions{
|
||||
export interface BandObenConfig{
|
||||
length:number,
|
||||
width:number,
|
||||
}
|
||||
}
|
||||
export interface MotorConfig {
|
||||
scale: number;
|
||||
raster: number;
|
||||
}
|
||||
|
||||
export interface MotorOptions {
|
||||
colorInactive: string;
|
||||
colorActive: string;
|
||||
colorError: string;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ interface PropText {
|
||||
x: number,
|
||||
y: number,
|
||||
text:string
|
||||
centeredBox?: { width: number; height: number; fontSize: number };
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
@@ -37,6 +38,10 @@ export class DrawText extends DrawElement {
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const box = this.posAndText.centeredBox;
|
||||
if (box) {
|
||||
return `<text x="${this.posAndText.x + box.width / 2}" y="${this.posAndText.y + box.height / 2}" text-anchor="middle" dominant-baseline="central" font-family="Arial" font-size="${box.fontSize}" font-weight="bold" fill="#000000">${this.posAndText.text}</text>`;
|
||||
}
|
||||
const paraStr = this.convertAttributesToString(this.attributes);
|
||||
const posSvg = this.getSvgPositions(this.posAndText)
|
||||
const posStr = this.convertAttributesToString(posSvg);
|
||||
@@ -47,6 +52,10 @@ export class DrawText extends DrawElement {
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const box = this.posAndText.centeredBox;
|
||||
if (box) {
|
||||
return `<Grid Canvas.Left="${this.posAndText.x}" Canvas.Top="${this.posAndText.y}" Width="${box.width}" Height="${box.height}"><TextBlock Text="${this.posAndText.text}" FontFamily="Arial" FontSize="${box.fontSize}" FontWeight="Bold" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/></Grid>`;
|
||||
}
|
||||
const paraStr = this.convertAttributesToString(this.attributes, true);
|
||||
//const posXaml = this.getXamlPositions(this.posAndText)
|
||||
//const posStr = this.convertAttributesToString(posXaml, true);
|
||||
|
||||
Reference in new issue
Block a user