feat(arch): improved handling of styles

This commit is contained in:
NicolasNewman
2024-04-19 12:30:55 -05:00
parent 2dfadca14c
commit ac7891c14b
7 changed files with 38 additions and 75 deletions

View File

@@ -670,6 +670,7 @@ export interface RequirementDiagramConfig extends BaseDiagramConfig {
export interface ArchitectureDiagramConfig extends BaseDiagramConfig { export interface ArchitectureDiagramConfig extends BaseDiagramConfig {
padding?: number; padding?: number;
iconSize?: number; iconSize?: number;
fontSize?: number;
} }
/** /**
* The object containing configurations specific for mindmap diagrams * The object containing configurations specific for mindmap diagrams

View File

@@ -250,7 +250,7 @@ function layoutArchitecture(
style: { style: {
'text-valign': 'bottom', 'text-valign': 'bottom',
'text-halign': 'center', 'text-halign': 'center',
'font-size': '16px', 'font-size': `${getConfigField('fontSize')}px`,
}, },
}, },
{ {
@@ -265,7 +265,7 @@ function layoutArchitecture(
selector: '.node-group', selector: '.node-group',
style: { style: {
// @ts-ignore Incorrect library types // @ts-ignore Incorrect library types
padding: '40px', padding: `${getConfigField('padding')}px`,
}, },
}, },
], ],

View File

@@ -1,80 +1,22 @@
import type { DiagramStylesProvider } from '../../diagram-api/types.js'; import type { DiagramStylesProvider } from '../../diagram-api/types.js';
import type { ArchitectureStyleOptions } from './architectureTypes.js'; import type { ArchitectureStyleOptions } from './architectureTypes.js';
// @ts-expect-error Incorrect khroma types
import { darken, lighten, isDark } from 'khroma';
const genSections: DiagramStylesProvider = (options) => {
let sections = '';
for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
options['lineColor' + i] = options['lineColor' + i] || options['cScaleInv' + i];
if (isDark(options['lineColor' + i])) {
options['lineColor' + i] = lighten(options['lineColor' + i], 20);
} else {
options['lineColor' + i] = darken(options['lineColor' + i], 20);
}
}
for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
const sw = '' + (17 - 3 * i);
sections += `
.section-${i - 1} rect, .section-${i - 1} path, .section-${i - 1} circle, .section-${i - 1
} polygon, .section-${i - 1} path {
fill: ${options['cScale' + i]};
}
.section-${i - 1} text {
fill: ${options['cScaleLabel' + i]};
}
.node-icon-${i - 1} {
font-size: 40px;
color: ${options['cScaleLabel' + i]};
}
.section-edge-${i - 1}{
stroke: ${options['cScale' + i]};
}
.edge-depth-${i - 1}{
stroke-width: ${sw};
}
.section-${i - 1} line {
stroke: ${options['cScaleInv' + i]} ;
stroke-width: 3;
}
.disabled, .disabled circle, .disabled text {
fill: lightgray;
}
.disabled text {
fill: #efefef;
}
`;
}
return sections;
};
const getStyles: DiagramStylesProvider = (options: ArchitectureStyleOptions) => const getStyles: DiagramStylesProvider = (options: ArchitectureStyleOptions) =>
` `
.edge { .edge {
stroke-width: 3; stroke-width: ${options.archEdgeStrokeWidth};
stroke: #777; stroke: ${options.archEdgeStrokeColor};
}
.arrow {
fill: #777;
}
.section-root rect, .section-root path, .section-root circle, .section-root polygon {
fill: #333;
}
.section-root text {
fill:#333;
}
${genSections(options)}
.edge {
fill: none; fill: none;
} }
.arrow {
fill: ${options.archEdgeArrowColor};
}
.node-bkg { .node-bkg {
fill: none; fill: none;
stroke: #000; stroke: ${options.archGroupBorderStrokeColor};
stroke-width: 2px; stroke-width: ${options.archGroupBorderStrokeWidth};
stroke-dasharray: 8; stroke-dasharray: 8;
} }
`; `;

View File

@@ -172,7 +172,11 @@ export const getArchitectureDirectionXYFactors = function (
}; };
export interface ArchitectureStyleOptions { export interface ArchitectureStyleOptions {
fontFamily: string; archEdgeStrokeColor: string;
archEdgeArrowColor: string;
archEdgeStrokeWidth: string;
archGroupBorderStrokeColor: string;
archGroupBorderStrokeWidth: string;
} }
export interface ArchitectureService { export interface ArchitectureService {

View File

@@ -133,6 +133,11 @@ export const drawEdges = function (edgesEl: D3Element, cy: cytoscape.Core) {
}; };
export const drawGroups = function (groupsEl: D3Element, cy: cytoscape.Core) { export const drawGroups = function (groupsEl: D3Element, cy: cytoscape.Core) {
const padding = getConfigField('padding');
const groupIconSize = padding * 0.75;
const fontSize = getConfigField('fontSize');
const iconSize = getConfigField('iconSize'); const iconSize = getConfigField('iconSize');
const halfIconSize = iconSize / 2; const halfIconSize = iconSize / 2;
@@ -155,15 +160,15 @@ export const drawGroups = function (groupsEl: D3Element, cy: cytoscape.Core) {
let shiftedY1 = y1; let shiftedY1 = y1;
if (data.icon) { if (data.icon) {
const bkgElem = groupLabelContainer.append('g'); const bkgElem = groupLabelContainer.append('g');
// TODO: magic number getIcon(data.icon)?.(bkgElem, groupIconSize);
getIcon(data.icon)?.(bkgElem, 32);
bkgElem.attr( bkgElem.attr(
'transform', 'transform',
'translate(' + (shiftedX1 + halfIconSize + 1) + ', ' + (shiftedY1 + halfIconSize + 1) + ')' 'translate(' + (shiftedX1 + halfIconSize + 1) + ', ' + (shiftedY1 + halfIconSize + 1) + ')'
); );
shiftedX1 += 32; shiftedX1 += groupIconSize;
// TODO: proper values once dynamic sizes are implemented // TODO: test with more values
shiftedY1 += 4; // - 1 - 2 comes from the Y axis transform of the icon and label
shiftedY1 += ((fontSize / 2) - 1 - 2);
} }
if (data.label) { if (data.label) {
const textElem = groupLabelContainer.append('g'); const textElem = groupLabelContainer.append('g');

View File

@@ -887,13 +887,17 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file)
- useMaxWidth - useMaxWidth
- padding - padding
- iconSize - iconSize
- fontSize
properties: properties:
padding: padding:
type: number type: number
default: 10 default: 40
iconSize: iconSize:
type: number type: number
default: 80 default: 80
fontSize:
type: number
default: 16
MindmapDiagramConfig: MindmapDiagramConfig:
title: Mindmap Diagram Config title: Mindmap Diagram Config

View File

@@ -220,6 +220,13 @@ class Theme {
this.pieOuterStrokeColor = this.pieOuterStrokeColor || 'black'; this.pieOuterStrokeColor = this.pieOuterStrokeColor || 'black';
this.pieOpacity = this.pieOpacity || '0.7'; this.pieOpacity = this.pieOpacity || '0.7';
/* architecture */
this.archEdgeStrokeColor = this.archEdgeStrokeColor || '#777';
this.archEdgeArrowColor = this.archEdgeArrowColor || '#777';
this.archEdgeStrokeWidth = this.archEdgeStrokeWidth || '3';
this.archGroupBorderStrokeColor = this.archGroupBorderStrokeColor || '#000';
this.archGroupBorderStrokeWidth = this.archGroupBorderStrokeWidth || '2px';
/* quadrant-graph */ /* quadrant-graph */
this.quadrant1Fill = this.quadrant1Fill || this.primaryColor; this.quadrant1Fill = this.quadrant1Fill || this.primaryColor;
this.quadrant2Fill = this.quadrant2Fill || adjust(this.primaryColor, { r: 5, g: 5, b: 5 }); this.quadrant2Fill = this.quadrant2Fill || adjust(this.primaryColor, { r: 5, g: 5, b: 5 });