update at 2026-01-22 20:01:21

This commit is contained in:
douboer@gmail.com
2026-01-22 20:01:21 +08:00
parent a3e77045ac
commit 9160bc1a70
4 changed files with 13 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ export function useLuopan(
const resolver = new ColorResolver(configObj.theme, configObj.background); const resolver = new ColorResolver(configObj.theme, configObj.background);
const builder = new SectorBuilder(resolver, { const builder = new SectorBuilder(resolver, {
textRadialPosition: textRadialPosition.value, textRadialPosition: textRadialPosition.value,
insetDistance: configObj.insetDistance,
}); });
const sectorLayers = configObj.layers.filter(isSectorLayer); const sectorLayers = configObj.layers.filter(isSectorLayer);
return sectorLayers.flatMap((layer, index) => builder.buildLayer(layer, index)); return sectorLayers.flatMap((layer, index) => builder.buildLayer(layer, index));
@@ -104,6 +105,9 @@ export function useLuopan(
strokeOpacity: typeof configObj.strokeOpacity === 'number' strokeOpacity: typeof configObj.strokeOpacity === 'number'
? configObj.strokeOpacity ? configObj.strokeOpacity
: undefined, : undefined,
insetDistance: typeof configObj.insetDistance === 'number'
? configObj.insetDistance
: undefined,
}; };
config.value = resolvedConfig; config.value = resolvedConfig;

View File

@@ -79,6 +79,7 @@ export const parseConfig = (jsonText: string): LuopanConfig => {
strokeWidth: typeof config.strokeWidth === 'number' ? config.strokeWidth : undefined, strokeWidth: typeof config.strokeWidth === 'number' ? config.strokeWidth : undefined,
strokeColor: typeof config.strokeColor === 'string' ? config.strokeColor : undefined, strokeColor: typeof config.strokeColor === 'string' ? config.strokeColor : undefined,
strokeOpacity: typeof config.strokeOpacity === 'number' ? config.strokeOpacity : undefined, strokeOpacity: typeof config.strokeOpacity === 'number' ? config.strokeOpacity : undefined,
insetDistance: typeof config.insetDistance === 'number' ? config.insetDistance : undefined,
outerRadius: typeof config.outerRadius === 'number' ? config.outerRadius : undefined, outerRadius: typeof config.outerRadius === 'number' ? config.outerRadius : undefined,
theme: normalizeTheme(config.theme), theme: normalizeTheme(config.theme),
layers: config.layers as LuopanConfig['layers'], layers: config.layers as LuopanConfig['layers'],

View File

@@ -18,17 +18,23 @@ const ensureTrailingSlash = (input: string): string =>
interface SectorBuilderOptions { interface SectorBuilderOptions {
textRadialPosition?: TextRadialPosition; textRadialPosition?: TextRadialPosition;
svgIconPath?: string; svgIconPath?: string;
insetDistance?: number;
} }
export class SectorBuilder { export class SectorBuilder {
private colorResolver: ColorResolver; private colorResolver: ColorResolver;
private textRadialPosition: TextRadialPosition; private textRadialPosition: TextRadialPosition;
private svgIconPath: string; private svgIconPath: string;
private insetDistance: number;
constructor(colorResolver: ColorResolver, options: SectorBuilderOptions = {}) { constructor(colorResolver: ColorResolver, options: SectorBuilderOptions = {}) {
this.colorResolver = colorResolver; this.colorResolver = colorResolver;
this.textRadialPosition = options.textRadialPosition ?? 'middle'; this.textRadialPosition = options.textRadialPosition ?? 'middle';
this.svgIconPath = ensureTrailingSlash(options.svgIconPath ?? 'src/assets/icons/'); this.svgIconPath = ensureTrailingSlash(options.svgIconPath ?? 'src/assets/icons/');
this.insetDistance =
typeof options.insetDistance === 'number'
? Math.max(0, options.insetDistance)
: SECTOR_INSET_DISTANCE;
} }
buildLayer(layer: SectorLayerConfig, layerIndex: number): Sector[] { buildLayer(layer: SectorLayerConfig, layerIndex: number): Sector[] {
@@ -57,7 +63,7 @@ export class SectorBuilder {
layer.rOuter, layer.rOuter,
aStart, aStart,
aEnd, aEnd,
SECTOR_INSET_DISTANCE this.insetDistance
) )
: undefined; : undefined;

View File

@@ -29,6 +29,7 @@ export interface LuopanConfig {
strokeWidth?: number; strokeWidth?: number;
strokeColor?: string; strokeColor?: string;
strokeOpacity?: number; strokeOpacity?: number;
insetDistance?: number;
outerRadius?: number; outerRadius?: number;
theme: ThemeConfig; theme: ThemeConfig;
layers: LayerConfig[]; layers: LayerConfig[];