Commit 8d6ca75b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

SBGN operators contain TEXT in a circle

parent a0d17aed
Pipeline #37319 passed with stage
in 15 minutes and 35 seconds
minerva (15.1.3) stable; urgency=medium
* Bug fix: modifier reactions to phenotype were incorrectly translated to
Process Description reactions when exporting to SBGN-ML (#1445)
* Bug fix: AND/OR text was missing when drawing diagram as SBGN (#1428)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 8 Feb 2021 12:00:00 +0200
......
......@@ -352,7 +352,7 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
* @param sbgnFormat
* true if operator is to be drawn in SBGN format
*/
private void drawOperator(final Graphics2D graphics, final NodeOperator operator, boolean sbgnFormat) {
void drawOperator(final Graphics2D graphics, final NodeOperator operator, boolean sbgnFormat) {
Color oldColor = graphics.getColor();
// draw line
......@@ -361,13 +361,25 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
Point2D centerPoint = operator.getLine().getPoints().get(0);
Color fillColor = Color.WHITE;
double radius = DEFAULT_OPERATOR_RADIUS;
// bigger connecting point circles in SBGN view
String text = operator.getOperatorText();
if (operator instanceof AndOperator || operator instanceof SplitOperator
|| operator instanceof DissociationOperator || operator instanceof AssociationOperator
|| operator instanceof TruncationOperator) {
radius = 1.5;
fillColor = operator.getLine().getColor();
}
// bigger connecting point circles in SBGN view
if (sbgnFormat && (operator instanceof AndOperator || operator instanceof OrOperator)) {
fillColor = Color.WHITE;
radius = 15;
if (operator instanceof AndOperator) {
text = "AND";
}
if (operator instanceof OrOperator) {
text = "OR";
}
}
// it's a circle
Ellipse2D cir = new Ellipse2D.Double(centerPoint.getX() - radius, centerPoint.getY() - radius, 2 * radius,
2 * radius);
......@@ -376,7 +388,6 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
graphics.setColor(operator.getLine().getColor());
graphics.draw(cir);
// and text defined by operator
String text = operator.getOperatorText();
Rectangle2D rect = graphics.getFontMetrics().getStringBounds(text, graphics);
graphics.drawString(text, (int) (centerPoint.getX() - rect.getWidth() / 2 + 1),
(int) (centerPoint.getY() + rect.getHeight() / 2) - 2);
......
......@@ -336,6 +336,30 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
}
}
@Test
public void testDrawOperatorWithSbgn() throws Exception {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
NodeOperator operator = new AndOperator();
operator.setLine(new PolylineData(new Point2D.Double(1, 2), new Point2D.Double(3, 4)));
rc.drawOperator(graphics, operator, true);
verify(graphics, times(1)).drawString(eq("AND"), anyInt(), anyInt());
}
@Test
public void testDrawOperatorWithoutSbgn() throws Exception {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
NodeOperator operator = new AndOperator();
operator.setLine(new PolylineData(new Point2D.Double(1, 2), new Point2D.Double(3, 4)));
rc.drawOperator(graphics, operator, false);
verify(graphics, times(1)).drawString(eq(""), anyInt(), anyInt());
}
@Test
public void testDrawComplexReactionWithSemanticZoomingAndAllModifersOff() throws Exception {
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment