Added support for Diagram title

This commit is contained in:
Subhash Halder
2023-07-02 13:18:28 +05:30
parent d69a8aeb63
commit 1d98ead5c2
2 changed files with 8 additions and 0 deletions

View File

@@ -154,6 +154,7 @@ statement
:
| SPACE statement
| directive
| title title_value { $$=$2.trim();yy.setDiagramTitle($$); }
| X_AXIS parseXAxis
| Y_AXIS parseYAxis
| parseLine

View File

@@ -11,6 +11,7 @@ const parserFnConstructor = (str: string) => {
const mockDB: Record<string, Mock<any, any>> = {
parseDirective: vi.fn(),
setOrientation: vi.fn(),
setDiagramTitle: vi.fn(),
setXAxisTitle: vi.fn(),
setXAxisRangeData: vi.fn(),
addXAxisBand: vi.fn(),
@@ -43,6 +44,12 @@ describe('Testing xychart jison file', () => {
expect(parserFnConstructor(str)).not.toThrow();
});
it('parse title of the chart', () => {
const str = 'xychart-beta \n title This is a title';
expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('This is a title');
});
it('should be able to parse directive', () => {
const str =
'%%{init: {"xychart": {"chartWidth": 600, "chartHeight": 600} } }%% \n xychart-beta';