mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-20 16:56:41 +02:00
refactor: Address review comments
Moved some types around Removed unnecessary params Co-authored-by: Reda Al Sulais <u.yokozuna@gmail.com> Co-authored-by: Alois Klink <alois@aloisklink.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
|
||||
import { imgSnapshotTest } from '../../helpers/util';
|
||||
|
||||
describe('packet structure', () => {
|
||||
it('should render a simple packet diagram', () => {
|
||||
|
@@ -14,7 +14,7 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[defaultConfig.ts:272](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L272)
|
||||
[defaultConfig.ts:275](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L275)
|
||||
|
||||
---
|
||||
|
||||
|
@@ -259,10 +259,6 @@ const config: RequiredDeep<MermaidConfig> = {
|
||||
},
|
||||
packet: {
|
||||
...defaultConfigJson.packet,
|
||||
useWidth: undefined,
|
||||
// this is false, unlike every other diagram (other than gitGraph)
|
||||
// TODO: can we make this default to `true` instead?
|
||||
useMaxWidth: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -1,13 +1,9 @@
|
||||
import type { Block, PacketDB, Row } from './types.js';
|
||||
import type { Block, PacketDB, PacketData, Row } from './types.js';
|
||||
import type { PacketDiagramConfig } from '../../config.type.js';
|
||||
|
||||
import { log } from '../../logger.js';
|
||||
import DEFAULT_CONFIG from '../../defaultConfig.js';
|
||||
import { getConfig as commonGetConfig } from '../../config.js';
|
||||
|
||||
interface PacketData {
|
||||
packet: Row[];
|
||||
}
|
||||
import { cleanAndMerge } from '../../utils.js';
|
||||
|
||||
const defaultPacketData: PacketData = {
|
||||
packet: [],
|
||||
@@ -17,7 +13,7 @@ let data: PacketData = structuredClone(defaultPacketData);
|
||||
export const DEFAULT_PACKET_CONFIG: Required<PacketDiagramConfig> = DEFAULT_CONFIG.packet;
|
||||
|
||||
export const getConfig = (): Required<PacketDiagramConfig> => {
|
||||
const config = structuredClone({
|
||||
const config = cleanAndMerge({
|
||||
...DEFAULT_PACKET_CONFIG,
|
||||
...commonGetConfig().packet,
|
||||
});
|
||||
@@ -61,9 +57,9 @@ export const getNextFittingBlock = (
|
||||
};
|
||||
|
||||
export const populate = ({ blocks }: { blocks: Block[] }) => {
|
||||
clear();
|
||||
let lastByte = -1;
|
||||
let word: Row = [];
|
||||
data.packet = [];
|
||||
let row = 1;
|
||||
const { bitsPerRow } = getConfig();
|
||||
for (let { start, end, label } of blocks) {
|
||||
@@ -97,7 +93,6 @@ export const populate = ({ blocks }: { blocks: Block[] }) => {
|
||||
if (word.length > 0) {
|
||||
data.packet.push(word);
|
||||
}
|
||||
log.debug(data);
|
||||
};
|
||||
|
||||
export const clear = () => {
|
||||
@@ -107,4 +102,5 @@ export const clear = () => {
|
||||
export const db: PacketDB = {
|
||||
getPacket,
|
||||
getConfig,
|
||||
clear,
|
||||
};
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import type { DiagramStylesProvider } from '../../diagram-api/types.js';
|
||||
import { log } from '../../logger.js';
|
||||
import type { PacketStyleOptions } from './types.js';
|
||||
|
||||
export const styles = (options: any = {}) => {
|
||||
export const styles: DiagramStylesProvider = (options: { packet?: PacketStyleOptions } = {}) => {
|
||||
log.debug({ options });
|
||||
return `
|
||||
.byte {
|
||||
|
@@ -9,4 +9,20 @@ export type Row = Required<Block>[];
|
||||
export interface PacketDB extends DiagramDB {
|
||||
getPacket: () => Row[];
|
||||
getConfig: () => Required<PacketDiagramConfig>;
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
export interface PacketStyleOptions {
|
||||
byteFontSize?: string;
|
||||
startByteColor?: string;
|
||||
endByteColor?: string;
|
||||
labelColor?: string;
|
||||
labelFontSize?: string;
|
||||
blockStrokeColor?: string;
|
||||
blockStrokeWidth?: string;
|
||||
blockFillColor?: string;
|
||||
}
|
||||
|
||||
export interface PacketData {
|
||||
packet: Row[];
|
||||
}
|
||||
|
@@ -2,13 +2,19 @@ grammar Packet
|
||||
import "../common/common";
|
||||
|
||||
entry Packet:
|
||||
"packet-beta" NEWLINE*
|
||||
TitleAndAccessibilities?
|
||||
(blocks+=Block)*;
|
||||
NEWLINE*
|
||||
"packet-beta"
|
||||
(
|
||||
NEWLINE* TitleAndAccessibilities blocks+=PacketBlock*
|
||||
| NEWLINE+ blocks+=PacketBlock+
|
||||
| NEWLINE*
|
||||
)
|
||||
;
|
||||
|
||||
Block:
|
||||
start=INT ('-' end=INT)? ':' label=STRING;
|
||||
PacketBlock:
|
||||
start=INT('-' end=INT)? ':' label=STRING NEWLINE+
|
||||
;
|
||||
|
||||
hidden terminal WS: /\s+/;
|
||||
terminal INT returns number: /[0-9]+/;
|
||||
terminal INT returns number: /0|[1-9][0-9]*/;
|
||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
||||
|
Reference in New Issue
Block a user