Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add point styling for quadrant chart #5173

Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cba803a
add: point styling for quadrant chart (incomplete)
ilyes-ced Jan 1, 2024
8ab0044
add: tests
ilyes-ced Jan 2, 2024
e965507
Merge branch 'mermaid-js:develop' into feature/add-point-styling-quad…
ilyes-ced Jan 11, 2024
9cca389
fix:styles can be in random order and are optional
ilyes-ced Jan 11, 2024
a599e33
add: class names and class definitions|todo: tests
ilyes-ced Jan 12, 2024
0d8016d
cypress tests
ilyes-ced Jan 13, 2024
38ee172
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Jan 16, 2024
4e3d935
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Jan 18, 2024
42589a0
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 5, 2024
b550146
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 6, 2024
2640120
fixed parsing for classes and styles are in jison
ilyes-ced Feb 6, 2024
17959f6
various fixes + add unit tests for parsed styles
ilyes-ced Feb 7, 2024
c1cb171
added styles values validation + unit tests
ilyes-ced Feb 7, 2024
8ad056b
1 tiny typo
ilyes-ced Feb 7, 2024
f1aa6ff
some fixes
ilyes-ced Feb 11, 2024
14e1e63
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 12, 2024
af7364b
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 14, 2024
cabcf1e
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 20, 2024
fc74275
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 29, 2024
67e482f
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Feb 29, 2024
b8e6672
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 5, 2024
1059dd3
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 6, 2024
358d855
fixed typo
ilyes-ced Mar 6, 2024
01082f8
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
sidharthv96 Mar 7, 2024
b191513
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 8, 2024
3344446
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 8, 2024
5b43460
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 9, 2024
37ba7af
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 11, 2024
3072604
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
sidharthv96 Mar 23, 2024
29ec8cb
small fixes
ilyes-ced Mar 24, 2024
3b8e6ec
small fix (follow)
ilyes-ced Mar 24, 2024
3f95c78
added styling docs
ilyes-ced Mar 26, 2024
1d8332d
Merge branch 'develop' into feature/add-point-styling-quadrant-to-charts
ilyes-ced Mar 26, 2024
585609b
lint fix
ilyes-ced Mar 26, 2024
253adcb
added docs build
ilyes-ced Mar 26, 2024
3357844
feat: Change precedence of styling
sidharthv96 Apr 16, 2024
eb4a6fd
docs: Add quadrant point styling
sidharthv96 Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions cypress/integration/rendering/quadrantChart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,52 @@ describe('Quadrant Chart', () => {
);
cy.get('svg');
});

it('it should render data points with styles', () => {
imgSnapshotTest(
`
quadrantChart
title Reach and engagement of campaigns
x-axis Reach -->
y-axis Engagement -->
quadrant-1 We should expand
quadrant-2 Need to promote
quadrant-3 Re-evaluate
quadrant-4 May be improved
Campaign A: [0.3, 0.6] radius: 20
Campaign B: [0.45, 0.23] color: #ff0000
Campaign C: [0.57, 0.69] stroke-color: #ff00ff
Campaign D: [0.78, 0.34] stroke-width: 3px
Campaign E: [0.40, 0.34] radius: 20, color: #ff0000 , stroke-color : #ff00ff, stroke-width : 3px
Campaign F: [0.35, 0.78] stroke-width: 3px , color: #ff0000, radius: 20, stroke-color: #ff00ff
Campaign G: [0.22, 0.22] stroke-width: 3px , color: #309708 , radius : 20 , stroke-color: #5060ff
Campaign H: [0.22, 0.44]
`,
{}
);
cy.get('svg');
});

it('it should render data points with styles + classes', () => {
imgSnapshotTest(
`
quadrantChart
title Reach and engagement of campaigns
x-axis Reach -->
y-axis Engagement -->
quadrant-1 We should expand
quadrant-2 Need to promote
quadrant-3 Re-evaluate
quadrant-4 May be improved
Campaign A:::class1: [0.3, 0.6] radius: 20
Campaign B: [0.45, 0.23] color: #ff0000
Campaign C: [0.57, 0.69] stroke-color: #ff00ff
Campaign D:::class2: [0.78, 0.34] stroke-width: 3px
Campaign E:::class2: [0.40, 0.34] radius: 20, color: #ff0000, stroke-color: #ff00ff, stroke-width: 3px
Campaign F:::class1: [0.35, 0.78]
classDef class1 color: #908342, radius : 10, stroke-color: #310085, stroke-width: 10px
classDef class2 color: #f00fff, radius : 10
`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%x point_start
%x point_x
%x point_y
%x class_name
%%
\%\%(?!\{)[^\n]* /* skip comments */
[^\}]\%\%[^\n]* /* skip comments */
Expand All @@ -35,6 +36,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}
" "*"quadrant-2"" "* return 'QUADRANT_2';
" "*"quadrant-3"" "* return 'QUADRANT_3';
" "*"quadrant-4"" "* return 'QUADRANT_4';
"classDef" return 'CLASSDEF';

["][`] { this.begin("md_string");}
<md_string>[^`"]+ { return "MD_STR";}
Expand All @@ -43,6 +45,9 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}
<string>["] this.popState();
<string>[^"]* return "STR";

\:\:\: {this.begin('class_name')}
<class_name>^\w+ {this.popState(); return 'class_name';}

\s*\:\s*\[\s* {this.begin("point_start"); return 'point_start';}
<point_start>(1)|(0(.\d+)?) {this.begin('point_x'); return 'point_x';}
<point_start>\s*\]" "* {this.popState();}
Expand Down Expand Up @@ -75,6 +80,31 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}

%% /* language grammar */

idStringToken : ALPHA | NUM | NODE_STRING | DOWN | MINUS | DEFAULT | COMMA | COLON | AMP | BRKT | MULT | UNICODE_TEXT;
styleComponent: ALPHA | NUM | NODE_STRING | COLON | UNIT | SPACE | BRKT | STYLE | PCT | MINUS ;

idString
:idStringToken
{$$=$idStringToken}
| idString idStringToken
{$$=$idString+''+$idStringToken}
;

style: styleComponent
|style styleComponent
{$$ = $style + $styleComponent;}
;

stylesOpt: style
{$$ = [$style.trim()]}
| stylesOpt COMMA style
{$stylesOpt.push($style.trim());$$ = $stylesOpt;}
;

classDefStatement
: CLASSDEF SPACE idString SPACE stylesOpt {$$ = $CLASSDEF;yy.addClass($idString,$stylesOpt);}
;

start
: eol start
| SPACE start
Expand All @@ -92,6 +122,7 @@ line

statement
:
| classDefStatement {$$=[];}
| SPACE statement
| axisDetails
| quadrantDetails
Expand All @@ -103,7 +134,10 @@ statement
;

points
: text point_start point_x point_y {yy.addPoint($1, $3, $4);}
: text point_start point_x point_y {yy.addPoint($1, "", $3, $4, []);}
| text class_name point_start point_x point_y {yy.addPoint($1, $2, $4, $5, []);}
| text point_start point_x point_y stylesOpt {yy.addPoint($1, "", $3, $4, $stylesOpt);}
| text class_name point_start point_x point_y stylesOpt {yy.addPoint($1, $2, $4, $5, $stylesOpt);}
;

axisDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,34 @@ describe('Testing quadrantChart jison file', () => {
it('should be able to parse points', () => {
let str = 'quadrantChart\npoint1: [0.1, 0.4]';
expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.addPoint).toHaveBeenCalledWith({ text: 'point1', type: 'text' }, '0.1', '0.4');
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'point1', type: 'text' },
'',
'0.1',
'0.4',
[]
);

clearMocks();
str = 'QuadRantChart \n Point1 : [0.1, 0.4] ';
expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.addPoint).toHaveBeenCalledWith({ text: 'Point1', type: 'text' }, '0.1', '0.4');
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Point1', type: 'text' },
'',
'0.1',
'0.4',
[]
);

clearMocks();
str = 'QuadRantChart \n "Point1 : (* +=[❀": [1, 0] ';
expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Point1 : (* +=[❀', type: 'text' },
'',
'1',
'0'
'0',
[]
);

clearMocks();
Expand Down Expand Up @@ -264,15 +278,149 @@ describe('Testing quadrantChart jison file', () => {
expect(mockDB.setQuadrant4Text).toHaveBeenCalledWith({ text: 'Visionaries', type: 'text' });
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Microsoft', type: 'text' },
'',
'0.75',
'0.75',
[]
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Salesforce', type: 'text' },
'',
'0.55',
'0.60',
[]
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'IBM', type: 'text' },
'',
'0.51',
'0.40',
[]
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Incorta', type: 'text' },
'',
'0.20',
'0.30',
[]
);
});

it('should be able to parse the whole chart with point styling with all params or some params', () => {
const str = `quadrantChart
title Analytics and Business Intelligence Platforms
x-axis "Completeness of Vision ❀" --> "x-axis-2"
y-axis Ability to Execute --> "y-axis-2"
quadrant-1 Leaders
quadrant-2 Challengers
quadrant-3 Niche
quadrant-4 Visionaries
Microsoft: [0.75, 0.75] radius: 10
Salesforce: [0.55, 0.60] radius: 10, color: #ff0000
IBM: [0.51, 0.40] radius: 10, color: #ff0000, stroke-color: #ff00ff
Incorta: [0.20, 0.30] radius: 10 ,color: #ff0000 ,stroke-color: #ff00ff ,stroke-width: 10px`;

expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setXAxisLeftText).toHaveBeenCalledWith({
text: 'Completeness of Vision ❀',
type: 'text',
});
expect(mockDB.setXAxisRightText).toHaveBeenCalledWith({ text: 'x-axis-2', type: 'text' });
expect(mockDB.setYAxisTopText).toHaveBeenCalledWith({ text: 'y-axis-2', type: 'text' });
expect(mockDB.setYAxisBottomText).toHaveBeenCalledWith({
text: 'Ability to Execute',
type: 'text',
});
expect(mockDB.setQuadrant1Text).toHaveBeenCalledWith({ text: 'Leaders', type: 'text' });
expect(mockDB.setQuadrant2Text).toHaveBeenCalledWith({ text: 'Challengers', type: 'text' });
expect(mockDB.setQuadrant3Text).toHaveBeenCalledWith({ text: 'Niche', type: 'text' });
expect(mockDB.setQuadrant4Text).toHaveBeenCalledWith({ text: 'Visionaries', type: 'text' });
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Microsoft', type: 'text' },
'',
'0.75',
'0.75',
'0.75'
['radius: 10']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Salesforce', type: 'text' },
'',
'0.55',
'0.60'
'0.60',
['radius: 10', 'color: #ff0000']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'IBM', type: 'text' },
'',
'0.51',
'0.40',
['radius: 10', 'color: #ff0000', 'stroke-color: #ff00ff']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Incorta', type: 'text' },
'',
'0.20',
'0.30',
['radius: 10', 'color: #ff0000', 'stroke-color: #ff00ff', 'stroke-width: 10px']
);
});

it('should be able to parse the whole chart with point styling with params in a random order + class names', () => {
const str = `quadrantChart
title Analytics and Business Intelligence Platforms
x-axis "Completeness of Vision ❀" --> "x-axis-2"
y-axis Ability to Execute --> "y-axis-2"
quadrant-1 Leaders
quadrant-2 Challengers
quadrant-3 Niche
quadrant-4 Visionaries
Microsoft: [0.75, 0.75] stroke-color: #ff00ff ,stroke-width: 10px, color: #ff0000, radius: 10
Salesforce:::class1: [0.55, 0.60] radius: 10, color: #ff0000
IBM: [0.51, 0.40] stroke-color: #ff00ff ,stroke-width: 10px
Incorta: [0.20, 0.30] stroke-width: 10px`;

expect(parserFnConstructor(str)).not.toThrow();
expect(mockDB.setXAxisLeftText).toHaveBeenCalledWith({
text: 'Completeness of Vision ❀',
type: 'text',
});
expect(mockDB.setXAxisRightText).toHaveBeenCalledWith({ text: 'x-axis-2', type: 'text' });
expect(mockDB.setYAxisTopText).toHaveBeenCalledWith({ text: 'y-axis-2', type: 'text' });
expect(mockDB.setYAxisBottomText).toHaveBeenCalledWith({
text: 'Ability to Execute',
type: 'text',
});
expect(mockDB.setQuadrant1Text).toHaveBeenCalledWith({ text: 'Leaders', type: 'text' });
expect(mockDB.setQuadrant2Text).toHaveBeenCalledWith({ text: 'Challengers', type: 'text' });
expect(mockDB.setQuadrant3Text).toHaveBeenCalledWith({ text: 'Niche', type: 'text' });
expect(mockDB.setQuadrant4Text).toHaveBeenCalledWith({ text: 'Visionaries', type: 'text' });
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Microsoft', type: 'text' },
'',
'0.75',
'0.75',
['stroke-color: #ff00ff', 'stroke-width: 10px', 'color: #ff0000', 'radius: 10']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Salesforce', type: 'text' },
'class1',
'0.55',
'0.60',
['radius: 10', 'color: #ff0000']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'IBM', type: 'text' },
'',
'0.51',
'0.40',
['stroke-color: #ff00ff', 'stroke-width: 10px']
);
expect(mockDB.addPoint).toHaveBeenCalledWith(
{ text: 'Incorta', type: 'text' },
'',
'0.20',
'0.30',
['stroke-width: 10px']
);
expect(mockDB.addPoint).toHaveBeenCalledWith({ text: 'IBM', type: 'text' }, '0.51', '0.40');
expect(mockDB.addPoint).toHaveBeenCalledWith({ text: 'Incorta', type: 'text' }, '0.20', '0.30');
});
});
Loading
Loading