Liesten ProCon
This commit is contained in:
1 parent
4bfd5d9bf7
commit
f43053d7b3
102 files changed
+2376
-86
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { DrawAnlageDurmin } from './drawAnlageDurmin2';
|
||||
import { parseAnlageDurminRequest } from '../../_dto/anlage-durmin.dto';
|
||||
import { validateSyncXml } from '../../visualisierung/shared/sync-xml';
|
||||
|
||||
describe('Durmin-Hintergrundgenerator', () => {
|
||||
it('liefert vollständiges SVG, XAML und UTF-8-Base64 über das gemeinsame Format', () => {
|
||||
const generator = new DrawAnlageDurmin();
|
||||
const result = generator.getObject({});
|
||||
expect(result).toEqual(expect.objectContaining({ name: 'anlageDurmin', width: 1700, height: 1100 }));
|
||||
expect(result.varianten).toHaveLength(1);
|
||||
const variant = result.varianten[0];
|
||||
expect(variant.state).toBe('inactive'); expect(variant.svg).toContain('<svg'); expect(variant.xaml).toContain('<Viewbox');
|
||||
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
|
||||
expect(() => validateSyncXml(variant.xaml)).not.toThrow();
|
||||
expect(variant.svg).toBe(generator.getSvg());
|
||||
expect(variant.xaml).toBe(generator.getSvg({ xaml: true }));
|
||||
expect(generator.getDrawObject({}).xaml).toBe(variant.xaml);
|
||||
expect(generator.getObject({})).toEqual(result);
|
||||
});
|
||||
it('validiert den Render-Aufruf und weist nicht unterstützte Parameter zurück', () => {
|
||||
expect(parseAnlageDurminRequest({ config: {} })).toEqual({ config: {}, options: {} });
|
||||
for (const input of [null, {}, { config: [] }, { config: { width: 200 } }, { config: {}, options: { scale: 2 } }])
|
||||
expect(() => parseAnlageDurminRequest(input)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,9 @@ import { Injectable } from "@nestjs/common";
|
||||
import { DrawDto, DrawShapeOptionenDto } from "src/_dto/draw.dto";
|
||||
import { DrawHeader } from "../lib/drawHeader";
|
||||
import { Line } from "src/_schemas/visu-elements.schema";
|
||||
import type { DrawDataDto } from '../../_dto/draw.dto';
|
||||
import type { GraphicGenerator } from './graphic-generator';
|
||||
import type { AnlageDurminConfig, AnlageDurminOptions } from '../../_dto/anlage-durmin.dto';
|
||||
|
||||
interface Para {
|
||||
scale?: number,
|
||||
@@ -17,7 +20,16 @@ interface Para {
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class DrawAnlageDurmin {
|
||||
export class DrawAnlageDurmin implements GraphicGenerator<AnlageDurminConfig, AnlageDurminOptions> {
|
||||
|
||||
getObject(_config: AnlageDurminConfig, _options?: Partial<AnlageDurminOptions>): DrawDataDto {
|
||||
const group = this.create();
|
||||
const header = new DrawHeader({ lenght: this.obj_width, height: this.obj_height });
|
||||
header.add(group);
|
||||
const svg = header.getChildString(false, 0), xaml = header.getChildString(true, 0);
|
||||
return { name: 'anlageDurmin', width: this.obj_width, height: this.obj_height,
|
||||
varianten: [{ state: 'inactive', svg, xaml, xamlBase64: Buffer.from(xaml, 'utf8').toString('base64') }] };
|
||||
}
|
||||
|
||||
obj_height = 1100;
|
||||
obj_width = 1700;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { DrawFahrwagenOben } from './drawFahrwagenOben';
|
||||
import { parseFahrwagenObenRequest } from '../../_dto/fahrwagen-oben.dto';
|
||||
import { validateSyncXml } from '../../visualisierung/shared/sync-xml';
|
||||
|
||||
describe('Fahrwagen oben', () => {
|
||||
it('füllt alle Zustände immer mittelgrau, auch bei früheren Farboptionen', () => {
|
||||
const { config, options } = parseFahrwagenObenRequest({ config: { length: 100, width: 20 }, options: { fill: '#123456' } });
|
||||
for (const variant of new DrawFahrwagenOben().getObject(config, options).varianten) {
|
||||
expect(variant.svg).toContain('fill="#808080"'); expect(variant.xaml).toContain('Fill="#808080"');
|
||||
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
|
||||
}
|
||||
expect(new DrawFahrwagenOben().getObject(config).varianten[0].svg).toContain('fill="#808080"');
|
||||
expect(new DrawFahrwagenOben().getObject(config, { fill: 'none' }).varianten[0].svg).toContain('fill="#808080"');
|
||||
for (const fill of ['red', '#123', '<script>', 123])
|
||||
expect(() => parseFahrwagenObenRequest({ config, options: { fill } })).toThrow();
|
||||
});
|
||||
it.each([false, true])('rendert alle Zustände mit Orientierung Nord-Süd=%s', fromNorthToSouth => {
|
||||
const { config, options } = parseFahrwagenObenRequest({ config: { length: 200, width: 40 }, options: { fromNorthToSouth } });
|
||||
const generator = new DrawFahrwagenOben();
|
||||
const result = generator.getObject(config, options);
|
||||
expect(result.name).toBe('fahrwagenOben');
|
||||
expect([result.width, result.height]).toEqual(fromNorthToSouth ? [40, 200] : [200, 40]);
|
||||
expect(result.varianten.map(v => v.state)).toEqual(['inactive', 'active', 'error']);
|
||||
result.varianten.forEach((variant, i) => {
|
||||
expect(variant.svg).toContain(['#808080', '#00f000', '#f00000'][i]);
|
||||
expect(variant.svg).toContain('<svg'); expect(variant.xaml).toContain('<Viewbox Stretch="None"');
|
||||
expect(() => validateSyncXml(variant.xaml)).not.toThrow();
|
||||
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
|
||||
expect(variant.svg + variant.xaml).not.toMatch(/NaN|Infinity/);
|
||||
});
|
||||
expect(generator.getObject(config, options)).toEqual(result);
|
||||
});
|
||||
it('hält den Umriss auch bei kleinen Maßen innerhalb der Zeichenfläche', () => {
|
||||
const generator = new DrawFahrwagenOben();
|
||||
const geometry = generator.createFahrwagen({ length: 1, height: 0.5, nordSued: false });
|
||||
expect(geometry.strokeWidth).toBe(0.25);
|
||||
expect(geometry.path[0]).toEqual({ type: 'M', x: 0.125, y: 0.125 });
|
||||
});
|
||||
it('validiert Maße und akzeptiert ausschließlich die Fahrwagen-Option', () => {
|
||||
expect(parseFahrwagenObenRequest({ config: { length: 10, width: 2 } }).options.fromNorthToSouth).toBe(false);
|
||||
for (const input of [null, {}, { config: { length: 0, width: 2 } }, { config: { length: NaN, width: 2 } },
|
||||
{ config: { length: 10, width: 2 }, options: { trichterStart: true } },
|
||||
{ config: { length: 10, width: 2 }, options: { fromNorthToSouth: 'true' } }])
|
||||
expect(() => parseFahrwagenObenRequest(input)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
import { PathCommand } from "../lib/types/path.types";
|
||||
import { DrawPath } from '../lib/drawPath'
|
||||
import { DrawGroup } from '../lib/drawGroup'
|
||||
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import type { DrawDataDto } from '../../_dto/draw.dto';
|
||||
import { DrawHeader } from "../lib/drawHeader";
|
||||
import type { FahrwagenConfig, FahrwagenOptions } from './types';
|
||||
import type { GraphicGenerator } from './graphic-generator';
|
||||
|
||||
interface Para {
|
||||
scale?: number,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class DrawFahrwagenOben implements GraphicGenerator<FahrwagenConfig, FahrwagenOptions> {
|
||||
|
||||
|
||||
red = "#f00000";
|
||||
normal = "#808080";
|
||||
green = "#00f000";
|
||||
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
createFahrwagen(data: { length: number, height: number, nordSued: boolean }) {
|
||||
let { height, length, nordSued } = data;
|
||||
if (nordSued) {
|
||||
height = data.length;
|
||||
length = data.height;
|
||||
}
|
||||
|
||||
const strokeWidth = Math.min(2, length / 2, height / 2);
|
||||
const inset = strokeWidth / 2;
|
||||
const pBox: PathCommand[] = [
|
||||
{ type: "M", x: inset, y: inset },
|
||||
{ relative: true, type: "V", y: height - strokeWidth },
|
||||
{ relative: true, type: "H", x: length - strokeWidth },
|
||||
{ relative: true, type: "V", y: -(height - strokeWidth) },
|
||||
{ type: "Z" }
|
||||
];
|
||||
|
||||
|
||||
return {
|
||||
path:pBox, strokeWidth,
|
||||
width:length,
|
||||
height:height
|
||||
};
|
||||
}
|
||||
|
||||
create(config: FahrwagenConfig, options?: Partial<FahrwagenOptions>): { group: DrawGroup, width: number, height: number } {
|
||||
|
||||
|
||||
const nordSued = options && options?.fromNorthToSouth ? true : false;
|
||||
|
||||
// Schiene
|
||||
const boxData = this.createFahrwagen({ length: config.length, height: config.width, nordSued });
|
||||
const zBox = new DrawPath(boxData.path);
|
||||
zBox.setAtrr({ strokeWidth: boxData.strokeWidth, fill: '#808080' });
|
||||
|
||||
const group = new DrawGroup({});
|
||||
group.add(zBox)
|
||||
|
||||
return {
|
||||
group: group,
|
||||
width: boxData.width,
|
||||
height: boxData.height
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
getObject(config: FahrwagenConfig, options?: Partial<FahrwagenOptions>): DrawDataDto {
|
||||
const states = ['inactive', 'active', 'error'] as const;
|
||||
const graphics = states.map(state => {
|
||||
const boxData = this.create(config, options);
|
||||
const color = state === 'active' ? this.green : state === 'error' ? this.red : this.normal;
|
||||
for (const element of boxData.group.getElements().values()) {
|
||||
if (element instanceof DrawPath) element.setAtrr({ stroke: color });
|
||||
}
|
||||
const header = this.createObjectWithHeader(boxData.group, boxData.width, boxData.height);
|
||||
const xaml = header.getChildString(true, 0).replace(
|
||||
'<Viewbox ',
|
||||
`<Viewbox Stretch="None" StretchDirection="Both" Width="${boxData.width}" Height="${boxData.height}" `,
|
||||
);
|
||||
return { state, svg: header.getChildString(false, 0), xaml };
|
||||
});
|
||||
|
||||
const width = options?.fromNorthToSouth ? config.width : config.length;
|
||||
const height = options?.fromNorthToSouth ? config.length : config.width;
|
||||
return {
|
||||
name: 'fahrwagenOben', width, height,
|
||||
varianten: graphics.map(item => ({ ...item, xamlBase64: Buffer.from(item.xaml, 'utf8').toString('base64') })),
|
||||
};
|
||||
}
|
||||
|
||||
createObjectWithHeader(group:DrawGroup,width:number,height:number):DrawHeader{
|
||||
const header = new DrawHeader({ lenght: width, height: height });
|
||||
header.add(group);
|
||||
return header;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,22 @@ export interface BandObenConfig{
|
||||
length:number,
|
||||
width:number,
|
||||
}
|
||||
|
||||
export interface MotorConfig {
|
||||
scale: number;
|
||||
raster: number;
|
||||
}
|
||||
|
||||
export interface FahrwagenConfig{
|
||||
length:number,
|
||||
width:number,
|
||||
}
|
||||
|
||||
export interface FahrwagenOptions{
|
||||
fill?: string,
|
||||
fromNorthToSouth:boolean,
|
||||
}
|
||||
|
||||
export interface MotorOptions {
|
||||
colorInactive: string;
|
||||
colorActive: string;
|
||||
|
||||
Reference in new issue
Block a user