opc meldunge parameter fehler io
This commit is contained in:
1 parent
ee408475de
commit
3dc1ad623c
115 files changed
+5891
-13
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import {describe,it,expect} from '@jest/globals';
|
||||
import {DrawRechteck} from './drawRechteck';
|
||||
import {parseRechteckRequest} from '../../_dto/rechteck.dto';
|
||||
describe('DrawRechteck',()=>{
|
||||
it('returns exact dimensions and identical static SVG/XAML/base64 variants',()=>{
|
||||
const result=new DrawRechteck().getObject({width:100,height:50},{stroke:'#123456',strokeWidth:2,fill:'#abcdef'});
|
||||
expect(result.name).toBe('rechteck');expect(result.width).toBe(100);expect(result.height).toBe(50);expect(result.varianten.map(v=>v.state)).toEqual(['inactive','active','error']);
|
||||
for(const variant of result.varianten){expect(variant.svg).toContain('viewBox="0 0 100 50"');expect(variant.svg).toContain('stroke="#123456"');expect(variant.svg).toContain('fill="#abcdef"');expect(variant.xaml).toContain('Stroke="#123456"');expect(variant.xaml).toContain('Fill="#abcdef"');expect(Buffer.from(variant.xamlBase64,'base64').toString('utf8')).toBe(variant.xaml);}
|
||||
expect(new Set(result.varianten.map(v=>v.svg)).size).toBe(1);
|
||||
});
|
||||
it('keeps the border fully inside the requested drawing size',()=>{
|
||||
const svg=new DrawRechteck().getObject({width:100,height:50},{strokeWidth:2}).varianten[0].svg;
|
||||
expect(svg).toContain('M 1,1');expect(svg).toContain('L 99,1');expect(svg).toContain('L 99,49');expect(svg).toContain('L 1,49');
|
||||
});
|
||||
it('supports transparent interior and absent borders in SVG and WPF',()=>{
|
||||
const transparent=new DrawRechteck().getObject({width:40,height:20});expect(transparent.varianten[0].svg).toContain('fill="none"');expect(transparent.varianten[0].xaml).not.toContain('Fill=');
|
||||
const noBorder=new DrawRechteck().getObject({width:40,height:20},{stroke:'none',fill:'#808080'});expect(noBorder.varianten[0].svg).toContain('stroke-width="0"');expect(noBorder.varianten[0].xaml).toContain('StrokeThickness="0"');expect(noBorder.varianten[0].xaml).not.toContain('Stroke="none"');
|
||||
});
|
||||
it('supports defaults, small sizes and legacy routes',()=>{
|
||||
expect(parseRechteckRequest({config:{}}).config).toEqual({width:100,height:50});
|
||||
expect(()=>new DrawRechteck().getObject({width:0.01,height:0.02})).not.toThrow();
|
||||
expect(new DrawRechteck().getDrawObject({width:30,height:20}).px_width).toBe(30);
|
||||
expect(new DrawRechteck().getSvg({xaml:true})).toContain('<Viewbox');
|
||||
});
|
||||
it.each([null,{}, {config:{width:0}}, {config:{height:NaN}}, {config:{width:'10'}}, {config:{scale:2}}, {config:{},options:{stroke:'red'}}, {config:{},options:{fill:'"/><script/>'}}, {config:{},options:{strokeWidth:-1}}, {config:{width:10,height:5},options:{strokeWidth:5}}])('rejects invalid geometry/options %j',input=>{expect(()=>parseRechteckRequest(input)).toThrow();});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { DrawDataDto, DrawDto, DrawShapeOptionenDto } from '../../_dto/draw.dto';
|
||||
import { parseRechteckRequest } from '../../_dto/rechteck.dto';
|
||||
import { DrawPath } from '../lib/drawPath';
|
||||
import { DrawGroup } from '../lib/drawGroup';
|
||||
import { DrawHeader } from '../lib/drawHeader';
|
||||
import type { GraphicGenerator } from './graphic-generator';
|
||||
import type { RechteckConfig, RechteckOptions } from './types';
|
||||
@Injectable()
|
||||
export class DrawRechteck implements GraphicGenerator<RechteckConfig,RechteckOptions> {
|
||||
getObject(config:RechteckConfig,options?:Partial<RechteckOptions>):DrawDataDto {
|
||||
const parsed=parseRechteckRequest({config,options}),{width,height}=parsed.config,{strokeWidth,fill,stroke}=parsed.options;
|
||||
const inset=strokeWidth/2;
|
||||
const shape=new DrawPath([{type:'M',x:inset,y:inset},{type:'L',x:width-inset,y:inset},{type:'L',x:width-inset,y:height-inset},{type:'L',x:inset,y:height-inset},{type:'Z'}]);
|
||||
// Rahmen vollständig innerhalb der Zeichenfläche; WPF kennt keinen Stroke="none".
|
||||
shape.setAtrr({stroke:stroke==='none'?'#000000':stroke,strokeWidth,fill:fill==='transparent'?'none':fill});
|
||||
const group=new DrawGroup({});group.add(shape);const header=new DrawHeader({lenght:width,height});header.add(group);
|
||||
const svg=header.getChildString(false,0),xaml=header.getChildString(true,0),xamlBase64=Buffer.from(xaml,'utf8').toString('base64');
|
||||
return {name:'rechteck',width,height,varianten:['inactive','active','error'].map(state=>({state,svg,xaml,xamlBase64}))};
|
||||
}
|
||||
private legacy(options:DrawShapeOptionenDto={}) {
|
||||
const result=this.getObject({width:Number(options.width??100),height:Number(options.height??50)}, {
|
||||
...(options.stroke!==undefined?{stroke:options.stroke}:{}),...(options.fill!==undefined?{fill:options.fill}:{}),...(options.strokeWidth!==undefined?{strokeWidth:Number(options.strokeWidth)}:{}),
|
||||
});return{result,variant:result.varianten.find(v=>v.state===options.state)??result.varianten[0]};
|
||||
}
|
||||
getDrawObject(options?:DrawShapeOptionenDto):DrawDto {const {result,variant}=this.legacy(options);return{name:'rechteck',height:result.height,length:result.width,px_height:result.height,px_width:result.width,raster:1,scale:1,offset_x:0,offset_y:0,svg:variant.svg};}
|
||||
getSvg(options?:DrawShapeOptionenDto){const {variant}=this.legacy(options);return options?.xaml?variant.xaml:variant.svg;}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ export interface MotorConfig {
|
||||
|
||||
export interface PunktConfig { scale: number; raster: number }
|
||||
export interface PunktOptions { colorInactive: string; colorActive: string }
|
||||
export interface RechteckConfig { width: number; height: number }
|
||||
export interface RechteckOptions { stroke: string; strokeWidth: number; fill: string }
|
||||
|
||||
export interface FahrwagenConfig{
|
||||
length:number,
|
||||
|
||||
Reference in new issue
Block a user