Commit 7f7f916f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

dimer cardinality is drawn twice only when different values are provided from sbgn

parent ca2b405f
Pipeline #40144 canceled with stage
in 4 minutes and 5 seconds
......@@ -72,14 +72,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
@Override
protected void drawImpl(final Protein protein, final Graphics2D graphics, final ConverterParams params) {
java.util.List<String> unitOfInformationText = new ArrayList<>();
if (protein.getStatePrefix() != null && protein.getStateLabel() != null) {
if (protein.getStatePrefix().equals("free input")) {
unitOfInformationText.add(protein.getStateLabel());
} else {
unitOfInformationText.add(protein.getStatePrefix() + ":" + protein.getStateLabel());
}
}
java.util.List<String> unitOfInformationText = getUnitOfInformation(protein);
int homodir = protein.getHomodimer();
......@@ -120,6 +113,18 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
protein.setHeight(protein.getHeight() + SpeciesConverter.HOMODIMER_OFFSET * (protein.getHomodimer() - 1));
}
protected java.util.List<String> getUnitOfInformation(final Protein protein) {
java.util.List<String> unitOfInformationText = new ArrayList<>();
if (protein.getStatePrefix() != null && protein.getStateLabel() != null) {
if (protein.getStatePrefix().equals("free input")) {
unitOfInformationText.add(protein.getStateLabel());
} else {
unitOfInformationText.add(protein.getStatePrefix() + ":" + protein.getStateLabel());
}
}
return unitOfInformationText;
}
void drawActivityShape(final Protein protein, final Graphics2D graphics) {
if (protein instanceof GenericProtein && protein.getActivity()) {
drawActivityGenericProtein(protein, graphics);
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
......@@ -38,14 +38,7 @@ public class ProteinSbgnConverter extends ProteinConverter {
@Override
protected void drawImpl(final Protein protein, final Graphics2D graphics, final ConverterParams params) {
List<String> unitOfInformationText = new ArrayList<>();
if (protein.getStatePrefix() != null && protein.getStateLabel() != null) {
if (protein.getStatePrefix().equals("free input")) {
unitOfInformationText.add(protein.getStateLabel());
} else {
unitOfInformationText.add(protein.getStatePrefix() + ":" + protein.getStateLabel());
}
}
List<String> unitOfInformationText = getUnitOfInformation(protein);
int originalHomodimer = protein.getHomodimer();
int homodir;
......@@ -56,10 +49,15 @@ public class ProteinSbgnConverter extends ProteinConverter {
}
protein.setHomodimer(homodir);
super.drawImpl(protein, graphics, params);
protein.setHomodimer(originalHomodimer);
drawUnitOfInformation(unitOfInformationText, protein, graphics);
}
@Override
protected List<String> getUnitOfInformation(final Protein protein) {
List<String> unitOfInformationText = super.getUnitOfInformation(protein);
if (protein instanceof IonChannelProtein) {
if (protein.getActivity()) {
unitOfInformationText.add("open");
......@@ -68,20 +66,20 @@ public class ProteinSbgnConverter extends ProteinConverter {
}
}
if (homodir > 1) {
unitOfInformationText.add("N:" + Integer.toString(protein.getHomodimer()));
if (protein.getHomodimer() > 1) {
String unit = "N:" + Integer.toString(protein.getHomodimer());
if (!unitOfInformationText.contains(unit)) {
unitOfInformationText.add(unit);
}
}
Color oldColor = graphics.getColor();
drawUnitOfInformation(unitOfInformationText, protein, graphics);
graphics.setColor(oldColor);
return unitOfInformationText;
}
@Override
protected Shape getShape(final Protein protein) {
return getGenericShape(protein);
}
@Override
void drawActivityShape(final Protein protein, final Graphics2D graphics) {
}
......
......@@ -376,6 +376,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
* where the drawing should be performed
*/
protected void drawUnitOfInformation(List<String> units, T species, final Graphics2D graphics) {
Color oldColor = graphics.getColor();
List<String> unitsToDraw = new ArrayList<>();
for (String text : units) {
if (text != null && !text.trim().isEmpty()) {
......@@ -394,11 +395,11 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
double height = UNIT_OF_INFORMATION_HEIGHT;
Rectangle2D rectangle = new Rectangle2D.Double(p.getX() - width / 2, p.getY() - height / 2, width, height);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(rectangle);
graphics.setColor(c);
graphics.setColor(species.getBorderColor());
graphics.draw(rectangle);
graphics.setColor(species.getFontColor());
Font font = graphics.getFont();
graphics.setFont(getUnitOfInformationFont());
......@@ -410,6 +411,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
count++;
}
graphics.setColor(oldColor);
}
@Override
......
......@@ -6,9 +6,16 @@ import static org.mockito.Mockito.when;
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Rule;
import org.mockito.Mockito;
......@@ -65,6 +72,9 @@ public abstract class GraphicsTestFunctions {
protected GenericProtein createProtein() {
GenericProtein result = new GenericProtein("s" + elementCounter++);
result.setFillColor(Color.YELLOW);
result.setBorderColor(Color.BLUE);
result.setFontColor(Color.DARK_GRAY);
assignCoordinates(10, 10, 40, 40, result);
return result;
}
......@@ -145,4 +155,15 @@ public abstract class GraphicsTestFunctions {
return pathway;
}
protected void showImage(BufferedImage bi) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bi, "PNG", outputStream);
byte[] output2 = outputStream.toByteArray();
FileUtils.writeByteArrayToFile(new File("tmp.png"), output2);
Desktop.getDesktop().open(new File("tmp.png"));
}
}
package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import static org.mockito.ArgumentMatchers.any;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times;
......@@ -8,6 +9,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import org.junit.Test;
import org.mockito.Mockito;
......@@ -54,4 +56,58 @@ public class ProteinSbgnConverterTest extends GraphicsTestFunctions {
Mockito.verify(graphics, times(2)).draw(any(Rectangle2D.class));
}
@Test
public void testDrawUnitOfInformation() throws Exception {
int size = 200;
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = Mockito.spy(bi.createGraphics());
ProteinConverter rc = new ProteinSbgnConverter(colorExtractor);
Protein protein = createProtein();
protein.setHomodimer(22);
protein.setStatePrefix("bla");
protein.setStateLabel("xxx");
graphics.setColor(Color.CYAN);
rc.drawUnitOfInformation(Arrays.asList("test"), protein, graphics);
Mockito.verify(graphics, times(1)).drawString(anyString(), anyInt(), anyInt());
Mockito.verify(graphics, times(1)).setColor(protein.getBorderColor());
Mockito.verify(graphics, times(1)).setColor(protein.getFontColor());
assertEquals(Color.CYAN, graphics.getColor());
}
@Test
public void testDrawHomodimerInformationTogetherWithCardinality() throws Exception {
int size = 200;
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = Mockito.spy(bi.createGraphics());
ProteinConverter rc = new ProteinSbgnConverter(colorExtractor);
Protein protein = createProtein();
protein.setHomodimer(4);
protein.setStatePrefix("N");
protein.setStateLabel("4");
rc.drawImpl(protein, graphics, new ConverterParams().sbgnFormat(true));
Mockito.verify(graphics, times(2)).drawString(anyString(), anyInt(), anyInt());
Mockito.verify(graphics, times(1)).draw(any(Rectangle2D.class));
}
@Test
public void testDrawHomodimerInformationTogetherWithDifferentCardinality() throws Exception {
int size = 200;
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = Mockito.spy(bi.createGraphics());
ProteinConverter rc = new ProteinSbgnConverter(colorExtractor);
Protein protein = createProtein();
protein.setHomodimer(4);
protein.setStatePrefix("N");
protein.setStateLabel("14");
rc.drawImpl(protein, graphics, new ConverterParams().sbgnFormat(true));
Mockito.verify(graphics, times(3)).drawString(anyString(), anyInt(), anyInt());
Mockito.verify(graphics, times(2)).draw(any(Rectangle2D.class));
}
}
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