Skip to content

Commit

Permalink
fix: only add data-atom-map-no when defined (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
targos authored Feb 1, 2024
1 parent 62c09cf commit 567b9d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 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" 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" />
<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" />
</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" 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" />
<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" />
</svg>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ protected void onDrawBond(int bond, double x1, double y1, double x2, double y2)

@Override
protected void onDrawAtom(int atom, String symbol, double x, double y) {
int atomMapNo = this.getMolecule().getAtomMapNo(atom);
String s = "<circle " +
"id=\"" + getId() + ":Atom:" + atom + "\" " +
"class=\"event\" " + // class to respond to the mouse event
"data-atom-map-no=\"" + this.getMolecule().getAtomMapNo(atom) + "\" " +
(atomMapNo == 0 ? "" : "data-atom-map-no=\"" + atomMapNo + "\" ") +
"cx=\"" + round(x) + "\" " +
"cy=\"" + round(y) + "\" " +
"r=\"" + DEFAULT_ELEM_WIDTH + "\" " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,19 @@ public static void set(boolean [] a, boolean v){
}
}

public final static boolean isOverlap(int[] a1, int[] a2) {
boolean ov = false;
all:
for (int v1 : a1) {
for (int v2 : a2) {
if(v1==v2){
ov=true;
break all;
}
}
}
return ov;
}


}

0 comments on commit 567b9d7

Please sign in to comment.