Updated code to use latest config system

This commit is contained in:
Subhash Halder
2023-08-13 22:56:50 +05:30
parent 6c2faf0bda
commit 526de36c86
20 changed files with 433 additions and 140 deletions

View File

@@ -18,6 +18,7 @@ const MERMAID_CONFIG_DIAGRAM_KEYS = [
'er', 'er',
'pie', 'pie',
'quadrantChart', 'quadrantChart',
'xyChart',
'requirement', 'requirement',
'mindmap', 'mindmap',
'timeline', 'timeline',

View File

@@ -14,7 +14,7 @@
#### Defined in #### Defined in
[defaultConfig.ts:266](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L266) [defaultConfig.ts:270](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L270)
--- ---

View File

@@ -46,6 +46,7 @@ const MERMAID_CONFIG_DIAGRAM_KEYS = [
'er', 'er',
'pie', 'pie',
'quadrantChart', 'quadrantChart',
'xyChart',
'requirement', 'requirement',
'mindmap', 'mindmap',
'timeline', 'timeline',

View File

@@ -704,33 +704,178 @@ export interface QuadrantChartConfig extends BaseDiagramConfig {
*/ */
quadrantExternalBorderStrokeWidth?: number; quadrantExternalBorderStrokeWidth?: number;
} }
/**
* This object contains configuration for XYChart axis config
*
* This interface was referenced by `MermaidConfig`'s JSON-Schema
* via the `definition` "XYChartAxisConfig".
*/
export interface XYChartAxisConfig { export interface XYChartAxisConfig {
showLabel: boolean; /**
labelFontSize: number; * Should show the axis labels (tick text)
lablePadding: number; */
showTitle: boolean; showLabel?: boolean;
titleFontSize: number; /**
titlePadding: number; * font size of the axis labels (tick text)
showTick: boolean; */
tickLength: number; labelFontSize?: number;
tickWidth: number; /**
* top and bottom space from axis label (tick text)
*/
labelPadding?: number;
/**
* Should show the axis title
*/
showTitle?: boolean;
/**
* font size of the axis title
*/
titleFontSize?: number;
/**
* top and bottom space from axis title
*/
titlePadding?: number;
/**
* Should show the axis tick lines
*/
showTick?: boolean;
/**
* length of the axis tick lines
*/
tickLength?: number;
/**
* width of the axis tick lines
*/
tickWidth?: number;
} }
/**
* This object contains configuration specific to XYCharts
*
* This interface was referenced by `MermaidConfig`'s JSON-Schema
* via the `definition` "XYChartConfig".
*/
export interface XYChartConfig extends BaseDiagramConfig { export interface XYChartConfig extends BaseDiagramConfig {
width: number; /**
height: number; * width of the chart
fontFamily: string; */
titleFontSize: number; width?: number;
titlePadding: number; /**
showtitle: boolean; * height of the chart
xAxis: XYChartAxisConfig; */
yAxis: XYChartAxisConfig; height?: number;
plotBorderWidth: number; /**
chartOrientation: 'vertical' | 'horizontal'; * Font family of texts in the xyChart
plotReservedSpacePercent: number; */
fontFamily?: string;
/**
* Font size of the chart title
*/
titleFontSize?: number;
/**
* Top and bottom space from the chart title
*/
titlePadding?: number;
/**
* Should show the chart title
*/
showTitle?: boolean;
xAxis?: XYChartAxisConfig1;
yAxis?: XYChartAxisConfig2;
/**
* width of the line around the plot of the chart
*/
plotBorderWidth?: number;
/**
* How to plot will be drawn horizontal or vertical
*/
chartOrientation?: 'vertical' | 'horizontal';
/**
* Minimum percent of space plots of the chart will take
*/
plotReservedSpacePercent?: number;
}
/**
* This object contains configuration for XYChart axis config
*/
export interface XYChartAxisConfig1 {
/**
* Should show the axis labels (tick text)
*/
showLabel?: boolean;
/**
* font size of the axis labels (tick text)
*/
labelFontSize?: number;
/**
* top and bottom space from axis label (tick text)
*/
labelPadding?: number;
/**
* Should show the axis title
*/
showTitle?: boolean;
/**
* font size of the axis title
*/
titleFontSize?: number;
/**
* top and bottom space from axis title
*/
titlePadding?: number;
/**
* Should show the axis tick lines
*/
showTick?: boolean;
/**
* length of the axis tick lines
*/
tickLength?: number;
/**
* width of the axis tick lines
*/
tickWidth?: number;
}
/**
* This object contains configuration for XYChart axis config
*/
export interface XYChartAxisConfig2 {
/**
* Should show the axis labels (tick text)
*/
showLabel?: boolean;
/**
* font size of the axis labels (tick text)
*/
labelFontSize?: number;
/**
* top and bottom space from axis label (tick text)
*/
labelPadding?: number;
/**
* Should show the axis title
*/
showTitle?: boolean;
/**
* font size of the axis title
*/
titleFontSize?: number;
/**
* top and bottom space from axis title
*/
titlePadding?: number;
/**
* Should show the axis tick lines
*/
showTick?: boolean;
/**
* length of the axis tick lines
*/
tickLength?: number;
/**
* width of the axis tick lines
*/
tickWidth?: number;
} }
/** /**
* The object containing configurations specific for entity relationship diagrams * The object containing configurations specific for entity relationship diagrams
* *

View File

@@ -234,6 +234,10 @@ const config: Partial<MermaidConfig> = {
...defaultConfigJson.pie, ...defaultConfigJson.pie,
useWidth: undefined, useWidth: undefined,
}, },
xyChart: {
...defaultConfigJson.xyChart,
useWidth: undefined,
},
requirement: { requirement: {
...defaultConfigJson.requirement, ...defaultConfigJson.requirement,
useWidth: undefined, useWidth: undefined,

View File

@@ -5,15 +5,15 @@ export interface XYChartAxisThemeConfig {
} }
export interface XYChartThemeConfig { export interface XYChartThemeConfig {
xychartTitleColor: string; titleColor: string;
xychartAxisLineColor: string; axisLineColor: string;
xychartXAxisLableColor: string; xAxisLableColor: string;
xychartXAxisTitleColor: string; xAxisTitleColor: string;
xychartXAxisTickColor: string; xAxisTickColor: string;
xychartYAxisLableColor: string; yAxisLableColor: string;
xychartYAxisTitleColor: string; yAxisTitleColor: string;
xychartYAxisTickColor: string; yAxisTickColor: string;
xychartPlotBaseColor: string; plotBaseColor: string;
} }
export interface ChartComponent { export interface ChartComponent {
@@ -66,6 +66,36 @@ export function isLinearAxisData(data: AxisDataType): data is LinearAxisDataType
return data.type === 'linear'; return data.type === 'linear';
} }
/**
* For now we are keeping this configs as we are removing the required fields while generating the config.type.ts file
* we should remove `XYChartAxisConfig` and `XYChartConfig` after we started using required fields
*/
export interface XYChartAxisConfig {
showLabel: boolean;
labelFontSize: number;
labelPadding: number;
showTitle: boolean;
titleFontSize: number;
titlePadding: number;
showTick: boolean;
tickLength: number;
tickWidth: number;
}
export interface XYChartConfig {
width: number;
height: number;
fontFamily: string;
titleFontSize: number;
titlePadding: number;
showTitle: boolean;
xAxis: XYChartAxisConfig;
yAxis: XYChartAxisConfig;
plotBorderWidth: number;
chartOrientation: 'vertical' | 'horizontal';
plotReservedSpacePercent: number;
}
export interface XYChartData { export interface XYChartData {
xAxis: AxisDataType; xAxis: AxisDataType;
yAxis: AxisDataType; yAxis: AxisDataType;

View File

@@ -1,10 +1,15 @@
import { log } from '../../../logger.js'; import { log } from '../../../logger.js';
import { DrawableElem, XYChartData, XYChartThemeConfig, isBarPlot } from './Interfaces.js'; import {
DrawableElem,
XYChartData,
XYChartThemeConfig,
XYChartConfig,
isBarPlot,
} from './Interfaces.js';
import { getChartTitleComponent } from './components/ChartTitle.js'; import { getChartTitleComponent } from './components/ChartTitle.js';
import { ChartComponent } from './Interfaces.js'; import { ChartComponent } from './Interfaces.js';
import { IAxis, getAxis } from './components/axis/index.js'; import { IAxis, getAxis } from './components/axis/index.js';
import { IPlot, getPlotComponent } from './components/plot/index.js'; import { IPlot, getPlotComponent } from './components/plot/index.js';
import { XYChartConfig } from '../../../config.type.js';
export class Orchestrator { export class Orchestrator {
private componentStore: { private componentStore: {
@@ -25,9 +30,9 @@ export class Orchestrator {
chartData.xAxis, chartData.xAxis,
chartConfig.xAxis, chartConfig.xAxis,
{ {
titleColor: chartThemeConfig.xychartXAxisTitleColor, titleColor: chartThemeConfig.xAxisTitleColor,
labelColor: chartThemeConfig.xychartXAxisLableColor, labelColor: chartThemeConfig.xAxisLableColor,
tickColor: chartThemeConfig.xychartXAxisTickColor, tickColor: chartThemeConfig.xAxisTickColor,
}, },
chartConfig.fontFamily chartConfig.fontFamily
), ),
@@ -35,9 +40,9 @@ export class Orchestrator {
chartData.yAxis, chartData.yAxis,
chartConfig.yAxis, chartConfig.yAxis,
{ {
titleColor: chartThemeConfig.xychartYAxisTitleColor, titleColor: chartThemeConfig.yAxisTitleColor,
labelColor: chartThemeConfig.xychartYAxisLableColor, labelColor: chartThemeConfig.yAxisLableColor,
tickColor: chartThemeConfig.xychartYAxisTickColor, tickColor: chartThemeConfig.yAxisTickColor,
}, },
chartConfig.fontFamily chartConfig.fontFamily
), ),

View File

@@ -1,4 +1,3 @@
import { XYChartConfig } from '../../../../config.type.js';
import { import {
BoundingRect, BoundingRect,
ChartComponent, ChartComponent,
@@ -7,6 +6,7 @@ import {
Point, Point,
XYChartData, XYChartData,
XYChartThemeConfig, XYChartThemeConfig,
XYChartConfig,
} from '../Interfaces.js'; } from '../Interfaces.js';
import { import {
ITextDimensionCalculator, ITextDimensionCalculator,
@@ -28,7 +28,7 @@ export class ChartTitle implements ChartComponent {
width: 0, width: 0,
height: 0, height: 0,
}; };
this.showChartTitle = !!(this.chartData.title && this.chartConfig.showtitle); this.showChartTitle = !!(this.chartData.title && this.chartConfig.showTitle);
} }
setBoundingBoxXY(point: Point): void { setBoundingBoxXY(point: Point): void {
this.boundingRect.x = point.x; this.boundingRect.x = point.x;
@@ -69,7 +69,7 @@ export class ChartTitle implements ChartComponent {
horizontalPos: 'middle', horizontalPos: 'middle',
x: this.boundingRect.x + this.boundingRect.width / 2, x: this.boundingRect.x + this.boundingRect.width / 2,
y: this.boundingRect.y + this.boundingRect.height / 2, y: this.boundingRect.y + this.boundingRect.height / 2,
fill: this.chartThemeConfig.xychartTitleColor, fill: this.chartThemeConfig.titleColor,
rotation: 0, rotation: 0,
}, },
], ],

View File

@@ -1,9 +1,8 @@
import { ScaleBand, scaleBand } from 'd3'; import { ScaleBand, scaleBand } from 'd3';
import { XYChartAxisConfig } from '../../../../../config.type.js';
import { log } from '../../../../../logger.js'; import { log } from '../../../../../logger.js';
import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js'; import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js';
import { BaseAxis } from './BaseAxis.js'; import { BaseAxis } from './BaseAxis.js';
import { XYChartAxisThemeConfig } from '../../Interfaces.js'; import { XYChartAxisThemeConfig, XYChartAxisConfig } from '../../Interfaces.js';
export class BandAxis extends BaseAxis { export class BandAxis extends BaseAxis {
private scale: ScaleBand<string>; private scale: ScaleBand<string>;

View File

@@ -1,4 +1,3 @@
import { XYChartAxisConfig } from '../../../../../config.type.js';
import { log } from '../../../../../logger.js'; import { log } from '../../../../../logger.js';
import { import {
BoundingRect, BoundingRect,
@@ -6,6 +5,7 @@ import {
DrawableElem, DrawableElem,
Point, Point,
XYChartAxisThemeConfig, XYChartAxisThemeConfig,
XYChartAxisConfig,
} from '../../Interfaces.js'; } from '../../Interfaces.js';
import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js'; import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js';
import { AxisPosition, IAxis } from './index.js'; import { AxisPosition, IAxis } from './index.js';
@@ -76,7 +76,7 @@ export abstract class BaseAxis implements IAxis {
if (this.axisConfig.showLabel) { if (this.axisConfig.showLabel) {
const spaceRequired = this.getLabelDimension(); const spaceRequired = this.getLabelDimension();
this.outerPadding = spaceRequired.width / 2; this.outerPadding = spaceRequired.width / 2;
const heightRequired = spaceRequired.height + this.axisConfig.lablePadding * 2; const heightRequired = spaceRequired.height + this.axisConfig.labelPadding * 2;
log.trace('height required for axis label: ', heightRequired); log.trace('height required for axis label: ', heightRequired);
if (heightRequired <= availableHeight) { if (heightRequired <= availableHeight) {
availableHeight -= heightRequired; availableHeight -= heightRequired;
@@ -108,7 +108,7 @@ export abstract class BaseAxis implements IAxis {
if (this.axisConfig.showLabel) { if (this.axisConfig.showLabel) {
const spaceRequired = this.getLabelDimension(); const spaceRequired = this.getLabelDimension();
this.outerPadding = spaceRequired.height / 2; this.outerPadding = spaceRequired.height / 2;
const widthRequired = spaceRequired.width + this.axisConfig.lablePadding * 2; const widthRequired = spaceRequired.width + this.axisConfig.labelPadding * 2;
log.trace('width required for axis label: ', widthRequired); log.trace('width required for axis label: ', widthRequired);
if (widthRequired <= availableWidth) { if (widthRequired <= availableWidth) {
availableWidth -= widthRequired; availableWidth -= widthRequired;
@@ -124,7 +124,7 @@ export abstract class BaseAxis implements IAxis {
[this.title], [this.title],
this.axisConfig.labelFontSize this.axisConfig.labelFontSize
); );
const widthRequired = spaceRequired.height + this.axisConfig.lablePadding * 2; const widthRequired = spaceRequired.height + this.axisConfig.labelPadding * 2;
log.trace('width required for axis title: ', widthRequired); log.trace('width required for axis title: ', widthRequired);
if (widthRequired <= availableWidth) { if (widthRequired <= availableWidth) {
availableWidth -= widthRequired; availableWidth -= widthRequired;
@@ -168,7 +168,7 @@ export abstract class BaseAxis implements IAxis {
x: x:
this.boundingRect.x + this.boundingRect.x +
this.boundingRect.width - this.boundingRect.width -
this.axisConfig.lablePadding - this.axisConfig.labelPadding -
this.axisConfig.tickLength, this.axisConfig.tickLength,
y: this.getScaleValue(tick), y: this.getScaleValue(tick),
fill: this.axisThemeConfig.labelColor, fill: this.axisThemeConfig.labelColor,
@@ -222,7 +222,7 @@ export abstract class BaseAxis implements IAxis {
data: this.getTickValues().map((tick) => ({ data: this.getTickValues().map((tick) => ({
text: tick.toString(), text: tick.toString(),
x: this.getScaleValue(tick), x: this.getScaleValue(tick),
y: this.boundingRect.y + this.axisConfig.lablePadding + this.axisConfig.tickLength, y: this.boundingRect.y + this.axisConfig.labelPadding + this.axisConfig.tickLength,
fill: this.axisThemeConfig.labelColor, fill: this.axisThemeConfig.labelColor,
fontSize: this.axisConfig.labelFontSize, fontSize: this.axisConfig.labelFontSize,
rotation: 0, rotation: 0,
@@ -277,7 +277,7 @@ export abstract class BaseAxis implements IAxis {
y: y:
this.boundingRect.y + this.boundingRect.y +
this.boundingRect.height - this.boundingRect.height -
this.axisConfig.lablePadding - this.axisConfig.labelPadding -
this.axisConfig.tickLength, this.axisConfig.tickLength,
fill: this.axisThemeConfig.labelColor, fill: this.axisThemeConfig.labelColor,
fontSize: this.axisConfig.labelFontSize, fontSize: this.axisConfig.labelFontSize,

View File

@@ -1,9 +1,8 @@
import { ScaleLinear, scaleLinear } from 'd3'; import { ScaleLinear, scaleLinear } from 'd3';
import { XYChartAxisConfig } from '../../../../../config.type.js';
import { log } from '../../../../../logger.js'; import { log } from '../../../../../logger.js';
import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js'; import { ITextDimensionCalculator } from '../../TextDimensionCalculator.js';
import { BaseAxis } from './BaseAxis.js'; import { BaseAxis } from './BaseAxis.js';
import { XYChartAxisThemeConfig } from '../../Interfaces.js'; import { XYChartAxisThemeConfig, XYChartAxisConfig } from '../../Interfaces.js';
export class LinearAxis extends BaseAxis { export class LinearAxis extends BaseAxis {
private scale: ScaleLinear<number, number>; private scale: ScaleLinear<number, number>;

View File

@@ -1,8 +1,8 @@
import { XYChartAxisConfig } from '../../../../../config.type.js';
import { import {
AxisDataType, AxisDataType,
ChartComponent, ChartComponent,
XYChartAxisThemeConfig, XYChartAxisThemeConfig,
XYChartAxisConfig,
isBandAxisData, isBandAxisData,
} from '../../Interfaces.js'; } from '../../Interfaces.js';
import { TextDimensionCalculatorWithFont } from '../../TextDimensionCalculator.js'; import { TextDimensionCalculatorWithFont } from '../../TextDimensionCalculator.js';

View File

@@ -1,5 +1,4 @@
import { XYChartConfig } from '../../../../../config.type.js'; import { BarPlotData, BoundingRect, DrawableElem, XYChartConfig } from '../../Interfaces.js';
import { BarPlotData, BoundingRect, DrawableElem } from '../../Interfaces.js';
import { IAxis } from '../axis/index.js'; import { IAxis } from '../axis/index.js';
export class BarPlot { export class BarPlot {

View File

@@ -1,6 +1,5 @@
import { line } from 'd3'; import { line } from 'd3';
import { XYChartConfig } from '../../../../../config.type.js'; import { DrawableElem, LinePlotData, XYChartConfig } from '../../Interfaces.js';
import { DrawableElem, LinePlotData } from '../../Interfaces.js';
import { IAxis } from '../axis/index.js'; import { IAxis } from '../axis/index.js';
export class LinePlot { export class LinePlot {

View File

@@ -1,5 +1,4 @@
import { XYChartConfig } from '../../../../../config.type.js'; import { BoundingRect, DrawableElem, XYChartConfig, XYChartThemeConfig } from '../../Interfaces.js';
import { BoundingRect, DrawableElem, XYChartThemeConfig } from '../../Interfaces.js';
export class PlotBorder { export class PlotBorder {
constructor( constructor(
private boundingRect: BoundingRect, private boundingRect: BoundingRect,
@@ -19,7 +18,7 @@ export class PlotBorder {
path: `M ${x},${y} L ${x + width},${y} M ${x + width},${y + height} M ${x},${ path: `M ${x},${y} L ${x + width},${y} M ${x + width},${y + height} M ${x},${
y + height y + height
} L ${x},${y}`, } L ${x},${y}`,
strokeFill: this.chartThemeConfig.xychartAxisLineColor, strokeFill: this.chartThemeConfig.axisLineColor,
strokeWidth: 1, strokeWidth: 1,
}, },
], ],
@@ -35,7 +34,7 @@ export class PlotBorder {
path: `M ${x},${y} M ${x + width},${y} M ${x + width},${y + height} L ${x},${ path: `M ${x},${y} M ${x + width},${y} M ${x + width},${y + height} L ${x},${
y + height y + height
} L ${x},${y}`, } L ${x},${y}`,
strokeFill: this.chartThemeConfig.xychartAxisLineColor, strokeFill: this.chartThemeConfig.axisLineColor,
strokeWidth: 1, strokeWidth: 1,
}, },
], ],

View File

@@ -5,13 +5,13 @@ import {
DrawableElem, DrawableElem,
Point, Point,
XYChartThemeConfig, XYChartThemeConfig,
XYChartConfig,
} from '../../Interfaces.js'; } from '../../Interfaces.js';
import { IAxis } from '../axis/index.js'; import { IAxis } from '../axis/index.js';
import { ChartComponent } from '../../Interfaces.js'; import { ChartComponent } from '../../Interfaces.js';
import { LinePlot } from './LinePlot.js'; import { LinePlot } from './LinePlot.js';
import { PlotBorder } from './PlotBorder.js'; import { PlotBorder } from './PlotBorder.js';
import { BarPlot } from './BarPlot.js'; import { BarPlot } from './BarPlot.js';
import { XYChartConfig } from '../../../../../config.type.js';
export interface IPlot extends ChartComponent { export interface IPlot extends ChartComponent {
setAxes(xAxis: IAxis, yAxis: IAxis): void; setAxes(xAxis: IAxis, yAxis: IAxis): void;

View File

@@ -1,7 +1,5 @@
// @ts-ignore: TODO Fix ts errors
import { XYChartConfig } from '../../../config.type.js';
import { log } from '../../../logger.js'; import { log } from '../../../logger.js';
import { DrawableElem, XYChartData, XYChartThemeConfig } from './Interfaces.js'; import { DrawableElem, XYChartData, XYChartConfig, XYChartThemeConfig } from './Interfaces.js';
import { Orchestrator } from './Orchestrator.js'; import { Orchestrator } from './Orchestrator.js';
export class XYChartBuilder { export class XYChartBuilder {

View File

@@ -2,6 +2,7 @@
import { adjust, channel } from 'khroma'; import { adjust, channel } from 'khroma';
import mermaidAPI from '../../mermaidAPI.js'; import mermaidAPI from '../../mermaidAPI.js';
import * as configApi from '../../config.js'; import * as configApi from '../../config.js';
import defaultConfig from '../../defaultConfig.js';
import { sanitizeText } from '../common/common.js'; import { sanitizeText } from '../common/common.js';
import { import {
setAccTitle, setAccTitle,
@@ -20,14 +21,16 @@ import {
XYChartThemeConfig, XYChartThemeConfig,
isBandAxisData, isBandAxisData,
isLinearAxisData, isLinearAxisData,
XYChartConfig,
} from './chartBuilder/Interfaces.js'; } from './chartBuilder/Interfaces.js';
import { XYChartConfig } from '../../config.type.js';
import { getThemeVariables } from '../../themes/theme-default.js'; import { getThemeVariables } from '../../themes/theme-default.js';
const defaultThemeVariables = getThemeVariables(); const defaultThemeVariables = getThemeVariables();
const config = configApi.getConfig(); const config = configApi.getConfig();
let plotIndex = 0;
function plotColorPaletteGenerator(baseColor: string, noOfColorNeeded = 15): string[] { function plotColorPaletteGenerator(baseColor: string, noOfColorNeeded = 15): string[] {
const colors = []; const colors = [];
const MAX_HUE_VALUE = 360; const MAX_HUE_VALUE = 360;
@@ -48,62 +51,45 @@ function plotColorPaletteGenerator(baseColor: string, noOfColorNeeded = 15): str
function getChartDefaultThemeConfig(): XYChartThemeConfig { function getChartDefaultThemeConfig(): XYChartThemeConfig {
return { return {
xychartTitleColor: titleColor:
config.themeVariables?.xychartTitleColor || defaultThemeVariables.xychartTitleColor, config.themeVariables?.xyChart?.titleColor || defaultThemeVariables.xyChart.titleColor,
xychartAxisLineColor: axisLineColor:
config.themeVariables?.xychartAxisLineColor || defaultThemeVariables.xychartAxisLineColor, config.themeVariables?.xyChart?.axisLineColor || defaultThemeVariables.xyChart.axisLineColor,
xychartXAxisLableColor: xAxisLableColor:
config.themeVariables?.xychartXAxisLableColor || defaultThemeVariables.xychartXAxisLableColor, config.themeVariables?.xyChart?.xAxisLableColor ||
xychartXAxisTitleColor: defaultThemeVariables.xyChart.xAxisLableColor,
config.themeVariables?.xychartXAxisTitleColor || defaultThemeVariables.xychartXAxisTitleColor, xAxisTitleColor:
xychartXAxisTickColor: config.themeVariables?.xyChart?.xAxisTitleColor ||
config.themeVariables?.xychartXAxisTickColor || defaultThemeVariables.xychartXAxisTickColor, defaultThemeVariables.xyChart.xAxisTitleColor,
xychartYAxisLableColor: xAxisTickColor:
config.themeVariables?.xychartYAxisLableColor || defaultThemeVariables.xychartYAxisLableColor, config.themeVariables?.xyChart?.xAxisTickColor ||
xychartYAxisTitleColor: defaultThemeVariables.xyChart.xAxisTickColor,
config.themeVariables?.xychartYAxisTitleColor || defaultThemeVariables.xychartYAxisTitleColor, yAxisLableColor:
xychartYAxisTickColor: config.themeVariables?.xyChart?.yAxisLableColor ||
config.themeVariables?.xychartYAxisTickColor || defaultThemeVariables.xychartYAxisTickColor, defaultThemeVariables.xyChart.yAxisLableColor,
xychartPlotBaseColor: yAxisTitleColor:
config.themeVariables?.xychartPlotBaseColor || defaultThemeVariables.xychartPlotBaseColor, config.themeVariables?.xyChart?.yAxisTitleColor ||
defaultThemeVariables.xyChart.yAxisTitleColor,
yAxisTickColor:
config.themeVariables?.xyChart?.yAxisTickColor ||
defaultThemeVariables.xyChart.yAxisTickColor,
plotBaseColor:
config.themeVariables?.xyChart?.plotBaseColor || defaultThemeVariables.xyChart.plotBaseColor,
}; };
} }
function getChartDefaultConfig(): XYChartConfig { function getChartDefaultConfig(): XYChartConfig {
return config.xyChart return {
? { ...config.xyChart, yAxis: { ...config.xyChart.yAxis }, xAxis: { ...config.xyChart.xAxis } } ...(defaultConfig.xyChart as XYChartConfig),
: { ...(config.xyChart ? config.xyChart : {}),
width: 700, yAxis: {
height: 500, ...(defaultConfig.xyChart as XYChartConfig).yAxis,
fontFamily: config.fontFamily || 'Sans', ...(config.xyChart?.yAxis ? config.xyChart.yAxis : {}),
titleFontSize: 16, },
titlePadding: 5, xAxis: {
showtitle: true, ...(defaultConfig.xyChart as XYChartConfig).xAxis,
plotBorderWidth: 2, ...(config.xyChart?.xAxis ? config.xyChart.xAxis : {}),
yAxis: { },
showLabel: true, };
labelFontSize: 14,
lablePadding: 5,
showTitle: true,
titleFontSize: 16,
titlePadding: 5,
showTick: true,
tickLength: 5,
tickWidth: 2,
},
xAxis: {
showLabel: true,
labelFontSize: 14,
lablePadding: 5,
showTitle: true,
titleFontSize: 16,
titlePadding: 5,
showTick: true,
tickLength: 5,
tickWidth: 2,
},
chartOrientation: 'vertical',
plotReservedSpacePercent: 50,
};
} }
function getChartDefalutData(): XYChartData { function getChartDefalutData(): XYChartData {
@@ -127,9 +113,9 @@ function getChartDefalutData(): XYChartData {
let xyChartConfig: XYChartConfig = getChartDefaultConfig(); let xyChartConfig: XYChartConfig = getChartDefaultConfig();
let xyChartThemeConfig: XYChartThemeConfig = getChartDefaultThemeConfig(); let xyChartThemeConfig: XYChartThemeConfig = getChartDefaultThemeConfig();
let xyChartData: XYChartData = getChartDefalutData(); let xyChartData: XYChartData = getChartDefalutData();
let plotColorPalette = Array.isArray(xyChartThemeConfig.xychartPlotBaseColor) let plotColorPalette = Array.isArray(xyChartThemeConfig.plotBaseColor)
? xyChartThemeConfig.xychartPlotBaseColor ? xyChartThemeConfig.plotBaseColor
: plotColorPaletteGenerator(xyChartThemeConfig.xychartPlotBaseColor); : plotColorPaletteGenerator(xyChartThemeConfig.plotBaseColor);
let hasSetXAxis = false; let hasSetXAxis = false;
let hasSetYAxis = false; let hasSetYAxis = false;
@@ -223,8 +209,6 @@ function transformDataWithOutCategory(data: number[]): SimplePlotDataType {
return retData; return retData;
} }
let plotIndex = 0;
function getPlotColorFromPalette(plotIndex: number): string { function getPlotColorFromPalette(plotIndex: number): string {
return plotColorPalette[plotIndex === 0 ? 0 : plotIndex % (plotColorPalette.length - 1)]; return plotColorPalette[plotIndex === 0 ? 0 : plotIndex % (plotColorPalette.length - 1)];
} }
@@ -272,9 +256,9 @@ const clear = function () {
xyChartConfig = getChartDefaultConfig(); xyChartConfig = getChartDefaultConfig();
xyChartData = getChartDefalutData(); xyChartData = getChartDefalutData();
xyChartThemeConfig = getChartDefaultThemeConfig(); xyChartThemeConfig = getChartDefaultThemeConfig();
plotColorPalette = Array.isArray(xyChartThemeConfig.xychartPlotBaseColor) plotColorPalette = Array.isArray(xyChartThemeConfig.plotBaseColor)
? xyChartThemeConfig.xychartPlotBaseColor ? xyChartThemeConfig.plotBaseColor
: plotColorPaletteGenerator(xyChartThemeConfig.xychartPlotBaseColor); : plotColorPaletteGenerator(xyChartThemeConfig.plotBaseColor);
hasSetXAxis = false; hasSetXAxis = false;
hasSetYAxis = false; hasSetYAxis = false;
}; };

View File

@@ -43,6 +43,7 @@ required:
- er - er
- pie - pie
- quadrantChart - quadrantChart
- xyChart
- requirement - requirement
- mindmap - mindmap
- gitGraph - gitGraph
@@ -197,6 +198,8 @@ properties:
$ref: '#/$defs/PieDiagramConfig' $ref: '#/$defs/PieDiagramConfig'
quadrantChart: quadrantChart:
$ref: '#/$defs/QuadrantChartConfig' $ref: '#/$defs/QuadrantChartConfig'
xyChart:
$ref: '#/$defs/XYChartConfig'
requirement: requirement:
$ref: '#/$defs/RequirementDiagramConfig' $ref: '#/$defs/RequirementDiagramConfig'
mindmap: mindmap:
@@ -982,6 +985,131 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
type: number type: number
minimum: 0 minimum: 0
default: 2 default: 2
XYChartAxisConfig:
title: XYChart axis config
description: This object contains configuration for XYChart axis config
type: object
unevaluatedProperties: true
required:
- showLabel
- labelFontSize
- labelPadding
- showTitle
- titleFontSize
- titlePadding
- showTick
- tickLength
- tickWidth
properties:
showLabel:
description: Should show the axis labels (tick text)
type: boolean
default: true
labelFontSize:
description: font size of the axis labels (tick text)
type: integer
default: 14
minimum: 1
labelPadding:
description: top and bottom space from axis label (tick text)
type: integer
default: 5
minimum: 0
showTitle:
description: Should show the axis title
type: boolean
default: true
titleFontSize:
description: font size of the axis title
type: integer
default: 16
minimum: 1
titlePadding:
description: top and bottom space from axis title
type: integer
default: 5
minimum: 0
showTick:
description: Should show the axis tick lines
type: boolean
default: true
tickLength:
description: length of the axis tick lines
type: integer
default: 5
minimum: 1
tickWidth:
description: width of the axis tick lines
type: integer
default: 2
minimum: 1
XYChartConfig:
title: XYChart Config
allOf: [{ $ref: '#/$defs/BaseDiagramConfig' }]
description: This object contains configuration specific to XYCharts
type: object
unevaluatedProperties: false
required:
- width
- height
- fontFamily
- titleFontSize
- titlePadding
- xAxis
- yAxis
- showTitle
- plotBorderWidth
- chartOrientation
- plotReservedSpacePercent
properties:
width:
description: width of the chart
type: integer
default: 700
minimum: 1
height:
description: height of the chart
type: integer
default: 500
minimum: 1
fontFamily:
description: Font family of texts in the xyChart
type: string
default: '"trebuchet ms", verdana, arial, sans-serif'
titleFontSize:
description: Font size of the chart title
type: integer
default: 16
minimum: 1
titlePadding:
description: Top and bottom space from the chart title
type: integer
default: 5
minimum: 0
showTitle:
description: Should show the chart title
type: boolean
default: true
xAxis:
$ref: '#/$defs/XYChartAxisConfig'
default: { '$ref': '#/$defs/XYChartAxisConfig' }
yAxis:
$ref: '#/$defs/XYChartAxisConfig'
default: { '$ref': '#/$defs/XYChartAxisConfig' }
plotBorderWidth:
description: width of the line around the plot of the chart
type: integer
default: 2
minimum: 0
chartOrientation:
description: How to plot will be drawn horizontal or vertical
tsType: '"vertical" | "horizontal"'
default: 'vertical'
plotReservedSpacePercent:
description: Minimum percent of space plots of the chart will take
type: integer
default: 50
minimum: 30
ErDiagramConfig: ErDiagramConfig:
title: Er Diagram Config title: Er Diagram Config

View File

@@ -273,16 +273,18 @@ class Theme {
this.quadrantTitleFill = this.quadrantTitleFill || this.primaryTextColor; this.quadrantTitleFill = this.quadrantTitleFill || this.primaryTextColor;
/* xychart */ /* xychart */
this.xychartBackgroundColor = this.xychartBackgroundColor || this.background; this.xyChart = {
this.xychartTitleColor = this.xychartTitleColor || this.primaryTextColor; backgroundColor: this.xyChart?.backgroundColor || this.background,
this.xychartAxisLineColor = this.xychartAxisLineColor || this.primaryTextColor; titleColor: this.xyChart?.titleColor || this.primaryTextColor,
this.xychartXAxisTitleColor = this.xychartXAxisTitleColor || this.primaryTextColor; axisLineColor: this.xyChart?.axisLineColor || this.primaryTextColor,
this.xychartXAxisLableColor = this.xychartXAxisLableColor || this.primaryTextColor; xAxisTitleColor: this.xyChart?.xAxisTitleColor || this.primaryTextColor,
this.xychartXAxisTickColor = this.xychartXAxisTickColor || this.primaryTextColor; xAxisLableColor: this.xyChart?.xAxisLableColor || this.primaryTextColor,
this.xychartYAxisTitleColor = this.xychartYAxisTitleColor || this.primaryTextColor; xAxisTickColor: this.xyChart?.xAxisTickColor || this.primaryTextColor,
this.xychartYAxisLableColor = this.xychartYAxisLableColor || this.primaryTextColor; yAxisTitleColor: this.xyChart?.yAxisTitleColor || this.primaryTextColor,
this.xychartYAxisTickColor = this.xychartYAxisTickColor || this.primaryTextColor; yAxisLableColor: this.xyChart?.yAxisLableColor || this.primaryTextColor,
this.xychartPlotBaseColor = this.xychartPlotBaseColor || darken(this.primaryColor, 25); yAxisTickColor: this.xyChart?.yAxisTickColor || this.primaryTextColor,
plotBaseColor: this.xyChart?.plotBaseColor || darken(this.primaryColor, 25),
};
/* requirement-diagram */ /* requirement-diagram */
this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBackground = this.requirementBackground || this.primaryColor;