Skip to content

Commit

Permalink
feat: add data-atom-map-no props in the circle of the svg (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny authored Aug 11, 2023
1 parent 1b84d44 commit ea29871
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
24 changes: 12 additions & 12 deletions __tests__/__snapshots__/molecule.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ exports[`Molecule toSVG with autoCrop 1`] = `
<line id="myId:Bond:2" class="event" x1="160.39" y1="69" x2="139.61" y2="81" stroke-width="8" opacity="0" />
<line id="myId:Bond:3" class="event" x1="139.61" y1="81" x2="118.82" y2="69" stroke-width="8" opacity="0" />
<line id="myId:Bond:4" class="event" x1="118.82" y1="69" x2="98.04" y2="81" stroke-width="8" opacity="0" />
<circle id="myId:Atom:0" class="event" cx="201.96" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:1" class="event" cx="181.18" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:2" class="event" cx="160.39" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:3" class="event" cx="139.61" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:4" class="event" cx="118.82" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:5" class="event" cx="98.04" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:0" class="event" data-atom-map-no="0" cx="201.96" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:1" class="event" data-atom-map-no="0" cx="181.18" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:2" class="event" data-atom-map-no="0" cx="160.39" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:3" class="event" data-atom-map-no="0" cx="139.61" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:4" class="event" data-atom-map-no="0" cx="118.82" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:5" class="event" data-atom-map-no="0" cx="98.04" cy="81" r="8" opacity="0" />
</svg>"
`;

Expand All @@ -41,11 +41,11 @@ exports[`Molecule toSVG with autoCrop 2`] = `
<line id="myId:Bond:2" class="event" x1="160.39" y1="69" x2="139.61" y2="81" stroke-width="8" opacity="0" />
<line id="myId:Bond:3" class="event" x1="139.61" y1="81" x2="118.82" y2="69" stroke-width="8" opacity="0" />
<line id="myId:Bond:4" class="event" x1="118.82" y1="69" x2="98.04" y2="81" stroke-width="8" opacity="0" />
<circle id="myId:Atom:0" class="event" cx="201.96" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:1" class="event" cx="181.18" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:2" class="event" cx="160.39" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:3" class="event" cx="139.61" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:4" class="event" cx="118.82" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:5" class="event" cx="98.04" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:0" class="event" data-atom-map-no="0" cx="201.96" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:1" class="event" data-atom-map-no="0" cx="181.18" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:2" class="event" data-atom-map-no="0" cx="160.39" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:3" class="event" data-atom-map-no="0" cx="139.61" cy="81" r="8" opacity="0" />
<circle id="myId:Atom:4" class="event" data-atom-map-no="0" cx="118.82" cy="69" r="8" opacity="0" />
<circle id="myId:Atom:5" class="event" data-atom-map-no="0" cx="98.04" cy="81" r="8" opacity="0" />
</svg>"
`;
14 changes: 14 additions & 0 deletions __tests__/data/atomMapNo.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@



5 4 0 0 0 0 0 0 0 0999 V2000
-1.4289 0.2062 0.0000 H 0 0 0 0 0 0 0 0 0 2 0 0
-0.7145 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 1 0 0
-0.0000 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 3 0 0
0.7145 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 4 0 0
1.4289 0.2062 0.0000 O 0 0 0 0 0 0 0 0 0 5 0 0
1 2 1 0 0
2 3 1 0 0
3 4 1 0 0
4 5 1 0 0
M END
27 changes: 27 additions & 0 deletions __tests__/molfileAndAtomMapNo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const { readFileSync } = require('fs');

const { Molecule } = require('../minimal');



test('molfile with atomMapNo', () => {
const molfile = readFileSync(
`${__dirname}/data/atomMapNo.mol`,
'utf8',
);
const molecule = Molecule.fromMolfile(molfile);

const newMolfile = molecule.toMolfile();
const atomMapNo = newMolfile.split(/\r?\n/).filter((line) => line.match(/ [OCH] /))
.map(line => line.replace(/.* ([OCH]) .*(.) {2}0 {2}0$/, '$1 $2'));

Check warning on line 18 in __tests__/molfileAndAtomMapNo.test.js

View workflow job for this annotation

GitHub Actions / lint

Capture group '([OCH])' should be converted to a named or non-capturing group

Check warning on line 18 in __tests__/molfileAndAtomMapNo.test.js

View workflow job for this annotation

GitHub Actions / lint

Capture group '(.)' should be converted to a named or non-capturing group
expect(atomMapNo).toStrictEqual(['O 5', 'C 1', 'C 3', 'C 4', 'H 2'])

const svg = molecule.toSVG(300, 200);
const mapNos = svg.split(/\r?\n/).filter((line) => line.includes('data-atom-map')).map(line => line.replace(/.*atom-map-no="(.).*/, '$1'));

Check warning on line 22 in __tests__/molfileAndAtomMapNo.test.js

View workflow job for this annotation

GitHub Actions / lint

Capture group '(.)' should be converted to a named or non-capturing group
expect(mapNos).toStrictEqual(["5", "1", "3", "4", "2"])



})
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ protected void onDrawAtom(int atom, String symbol, double x, double y) {
String s = "<circle " +
"id=\"" + getId() + ":Atom:" + atom + "\" " +
"class=\"event\" " + // class to respond to the mouse event
"data-atom-map-no=\"" + this.getMolecule().getAtomMapNo(atom) + "\" " +
"cx=\"" + round(x) + "\" " +
"cy=\"" + round(y) + "\" " +
"r=\"" + DEFAULT_ELEM_WIDTH + "\" " +
Expand Down

0 comments on commit ea29871

Please sign in to comment.