Line data Source code
1 : import * as dashql from '@ankoh/dashql-core';
2 : import { PROFILE_OPERATOR_SYMBOL_SIZE } from './profile_operator_symbol.js';
3 :
4 : /// The width of the annotation slot at the left of every operator: the status icon, the row count or the estimate.
5 : /// A row count like `7.53M` fills it.
6 : export const PROFILE_OPERATOR_ANNOTATION_WIDTH = 34;
7 :
8 : /// The layout config of rendered query profiles. Every operator reserves the annotation slot left of its label.
9 : ///
10 : /// A plan grows top-down by default. A left-to-right plan fits wide and short viewports like the query progress of
11 : /// the feed: its height grows with the inputs of the operators, not with the depth of the plan.
12 : ///
13 : /// The plan is dense. The row counts sit in the annotation slots of the operators, the gaps between the operators only
14 : /// hold the edges and the fragment contours, which pad the operators by 8 pixels.
15 1 : export function createProfileLayoutConfig(
16 1 : orientation = dashql.buffers.profile.ProfileLayoutOrientation.TOP_DOWN,
17 1 : ): dashql.buffers.profile.ProfileLayoutConfigT {
18 1 : const leftToRight = orientation === dashql.buffers.profile.ProfileLayoutOrientation.LEFT_TO_RIGHT;
19 1 : const config = new dashql.buffers.profile.ProfileLayoutConfigT();
20 1 : config.levelHeight = 56;
21 1 : config.nodeHeight = 32;
22 1 : config.nodeMarginHorizontal = leftToRight ? 32 : 28;
23 1 : config.nodeMarginVertical = 40;
24 1 : config.nodePaddingLeft = 12;
25 1 : config.nodePaddingRight = 12;
26 1 : config.iconWidth = PROFILE_OPERATOR_ANNOTATION_WIDTH;
27 1 : config.iconMarginRight = 8;
28 1 : config.maxLabelChars = 20;
29 1 : config.widthPerLabelChar = 8.5;
30 1 : config.nodeMinWidth = 0;
31 : // An operator without a label of its own is as narrow as the symbol of its kind
32 1 : config.symbolWidth = PROFILE_OPERATOR_SYMBOL_SIZE;
33 1 : config.orientation = orientation;
34 1 : return config;
35 1 : }
36 :
37 : /// The other orientation of a plan, rotating a plan lays it out again with it
38 0 : export function rotateProfileLayoutOrientation(
39 0 : orientation: dashql.buffers.profile.ProfileLayoutOrientation,
40 0 : ): dashql.buffers.profile.ProfileLayoutOrientation {
41 0 : const { LEFT_TO_RIGHT, TOP_DOWN } = dashql.buffers.profile.ProfileLayoutOrientation;
42 0 : return orientation === LEFT_TO_RIGHT ? TOP_DOWN : LEFT_TO_RIGHT;
43 0 : }
44 :
45 : /// The layout config of the query progress. The progress shows the plan in short panels, the plan grows left-to-right.
46 1 : export function createProgressLayoutConfig(): dashql.buffers.profile.ProfileLayoutConfigT {
47 1 : return createProfileLayoutConfig(dashql.buffers.profile.ProfileLayoutOrientation.LEFT_TO_RIGHT);
48 1 : }
|