mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-25 18:30:10 +02:00
Made the axis title optional
This commit is contained in:
@@ -15,6 +15,17 @@
|
||||
|
||||
<body>
|
||||
<h1>XY Charts demos</h1>
|
||||
<pre class="mermaid">
|
||||
xychart-beta
|
||||
title "Sales Revenue (in $)"
|
||||
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
|
||||
y-axis "Revenue (in $)" 4000 --> 11000
|
||||
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
|
||||
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
|
||||
</pre>
|
||||
|
||||
<hr />
|
||||
|
||||
<pre class="mermaid">
|
||||
xychart-beta horizontal
|
||||
title "Basic xychart"
|
||||
@@ -24,8 +35,6 @@
|
||||
line [23, 46, 75, 43]
|
||||
</pre>
|
||||
|
||||
<hr />
|
||||
|
||||
<h1>XY Charts demos</h1>
|
||||
<pre class="mermaid">
|
||||
xychart-beta
|
||||
|
@@ -93,7 +93,7 @@ export abstract class BaseAxis implements Axis {
|
||||
this.showTick = true;
|
||||
availableHeight -= this.axisConfig.tickLength;
|
||||
}
|
||||
if (this.axisConfig.showTitle) {
|
||||
if (this.axisConfig.showTitle && this.title) {
|
||||
const spaceRequired = this.textDimensionCalculator.getMaxDimension(
|
||||
[this.title],
|
||||
this.axisConfig.labelFontSize
|
||||
@@ -126,7 +126,7 @@ export abstract class BaseAxis implements Axis {
|
||||
this.showTick = true;
|
||||
availableWidth -= this.axisConfig.tickLength;
|
||||
}
|
||||
if (this.axisConfig.showTitle) {
|
||||
if (this.axisConfig.showTitle && this.title) {
|
||||
const spaceRequired = this.textDimensionCalculator.getMaxDimension(
|
||||
[this.title],
|
||||
this.axisConfig.labelFontSize
|
||||
|
@@ -117,8 +117,13 @@ commaSeparatedNumbers
|
||||
|
||||
parseXAxis
|
||||
: text {yy.setXAxisTitle($text);}
|
||||
| text bandData {yy.setXAxisTitle($text); yy.setXAxisBand($bandData);}
|
||||
| text NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setXAxisTitle($text); yy.setXAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
||||
| text xAxisData {yy.setXAxisTitle($text);}
|
||||
| xAxisData {yy.setXAxisTitle({type: 'text', text: ''});}
|
||||
;
|
||||
|
||||
xAxisData
|
||||
: bandData {yy.setXAxisBand($bandData);}
|
||||
| NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setXAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
||||
;
|
||||
|
||||
bandData
|
||||
@@ -132,7 +137,12 @@ commaSeparatedTexts
|
||||
|
||||
parseYAxis
|
||||
: text {yy.setYAxisTitle($text);}
|
||||
| text NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setYAxisTitle($text); yy.setYAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
||||
| text yAxisData {yy.setYAxisTitle($text);}
|
||||
| yAxisData {yy.setYAxisTitle({type: "text", text: ""});}
|
||||
;
|
||||
|
||||
yAxisData
|
||||
: NUMBER_WITH_DECIMAL ARROW_DELIMITER NUMBER_WITH_DECIMAL {yy.setYAxisRangeData(Number($NUMBER_WITH_DECIMAL1), Number($NUMBER_WITH_DECIMAL2));}
|
||||
;
|
||||
|
||||
eol
|
||||
|
@@ -128,6 +128,16 @@ describe('Testing xychart jison file', () => {
|
||||
expect(mockDB.setXAxisRangeData).toHaveBeenCalledWith(45.5, 0.34);
|
||||
});
|
||||
|
||||
it('parse x-axis without axisname and range data', () => {
|
||||
const str = 'xychart-beta \nx-axis 45.5 --> 1.34 \n';
|
||||
expect(parserFnConstructor(str)).not.toThrow();
|
||||
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({
|
||||
text: '',
|
||||
type: 'text',
|
||||
});
|
||||
expect(mockDB.setXAxisRangeData).toHaveBeenCalledWith(45.5, 1.34);
|
||||
});
|
||||
|
||||
it('parse x-axis with axis name and category data', () => {
|
||||
const str = 'xychart-beta \nx-axis xAxisName [ "cat1" , cat2a ] \n ';
|
||||
expect(parserFnConstructor(str)).not.toThrow();
|
||||
@@ -144,6 +154,22 @@ describe('Testing xychart jison file', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('parse x-axis without axisname and category data', () => {
|
||||
const str = 'xychart-beta \nx-axis [ "cat1" , cat2a ] \n ';
|
||||
expect(parserFnConstructor(str)).not.toThrow();
|
||||
expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({
|
||||
text: '',
|
||||
type: 'text',
|
||||
});
|
||||
expect(mockDB.setXAxisBand).toHaveBeenCalledWith([
|
||||
{
|
||||
text: 'cat1',
|
||||
type: 'text',
|
||||
},
|
||||
{ text: 'cat2a', type: 'text' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('parse x-axis throw error if unbalanced bracket', () => {
|
||||
let str = 'xychart-beta \nx-axis xAxisName [ "cat1" [ cat2a ] \n ';
|
||||
expect(parserFnConstructor(str)).toThrow();
|
||||
@@ -218,6 +244,12 @@ describe('Testing xychart jison file', () => {
|
||||
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' });
|
||||
expect(mockDB.setYAxisRangeData).toHaveBeenCalledWith(45.5, 33);
|
||||
});
|
||||
it('parse y-axis without axisname with range data', () => {
|
||||
const str = 'xychart-beta \ny-axis 45.5 --> 33 \n';
|
||||
expect(parserFnConstructor(str)).not.toThrow();
|
||||
expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: '', type: 'text' });
|
||||
expect(mockDB.setYAxisRangeData).toHaveBeenCalledWith(45.5, 33);
|
||||
});
|
||||
it('parse y-axis with axis name with range data with only decimal part', () => {
|
||||
const str = 'xychart-beta \ny-axis yAxisName 45.5 --> .33 \n';
|
||||
expect(parserFnConstructor(str)).not.toThrow();
|
||||
|
Reference in New Issue
Block a user