/** * This draws the standard legend text for a BELOW legend. * * @param g2 * @param legentTextX * @param legendTextY * @param fontFamily * @param labelHeightPixels * @param shortBoldLines must be valid (if null, nothing will be drawn, and return value will be * legendTextY unchanged) * @param shortLines from makeShortLines * @return the new legendTextY (adjusted so there is a gap after the current text). */ public static int belowLegendText( Graphics2D g2, int legendTextX, int legendTextY, String fontFamily, int labelHeightPixels, StringArray shortBoldLines, StringArray shortLines) { // String2.log("belowLegendText boldTitle=" + boldTitle); if (shortBoldLines == null) return legendTextY; // draw the boldShortLines int n = shortBoldLines.size(); for (int i = 0; i < n; i++) legendTextY = drawHtmlText( g2, legendTextX, legendTextY, 0, fontFamily, labelHeightPixels, false, "<b>" + encodeAsHtml(shortBoldLines.get(i)) + "</b>"); // draw the shortLines n = shortLines.size(); for (int i = 0; i < n; i++) legendTextY = drawHtmlText( g2, legendTextX, legendTextY, 0, fontFamily, labelHeightPixels, i == n - 1, encodeAsHtml(shortLines.get(i))); return legendTextY; }
/** This tests SgtUtil. */ public static void test() throws Exception { // test splitLine String2.log("\n*** SgtUtil.test"); StringArray sa = new StringArray(); // wide sa.clear(); splitLine(38, sa, "This is a test of splitline."); Test.ensureEqual(sa.size(), 1, ""); Test.ensureEqual(sa.get(0), "This is a test of splitline.", ""); // narrow sa.clear(); splitLine(12, sa, "This is a test of splitline."); Test.ensureEqual(sa.size(), 3, ""); Test.ensureEqual(sa.get(0), "This is a ", ""); Test.ensureEqual(sa.get(1), "test of ", ""); Test.ensureEqual(sa.get(2), "splitline.", ""); // narrow and can't split, so chop at limit sa.clear(); splitLine(12, sa, "This1is2a3test4of5splitline."); Test.ensureEqual(sa.size(), 3, ""); Test.ensureEqual(sa.get(0), "This1is2a3t", ""); Test.ensureEqual(sa.get(1), "est4of5split", ""); Test.ensureEqual(sa.get(2), "line.", ""); // caps sa.clear(); splitLine(12, sa, "THESE ARE a a REALLY WIDE."); Test.ensureEqual(sa.size(), 3, ""); Test.ensureEqual(sa.get(0), "THESE ARE ", ""); Test.ensureEqual(sa.get(1), "a a REALLY ", ""); Test.ensureEqual(sa.get(2), "WIDE.", ""); // test suggestPaletteRange Test.ensureEqual( suggestPaletteRange(.3, 8.9), new double[] {0, 10}, ""); // typical Rainbow Linear Test.ensureEqual( suggestPaletteRange(.11, 890), new double[] {.1, 1000}, ""); // typical Rainbow Log Test.ensureEqual( suggestPaletteRange(-7, 8), new double[] {-10, 10}, ""); // typical BlueWhiteRed Linear symmetric // test suggestPalette Test.ensureEqual( suggestPalette(.3, 8.9), "WhiteRedBlack", ""); // small positive, large positive Test.ensureEqual(suggestPalette(300, 890), "Rainbow", ""); // typical Rainbow Log Test.ensureEqual( suggestPalette(-7, 8), "BlueWhiteRed", ""); // typical BlueWhiteRed Linear symmetric // test suggestPaletteScale Test.ensureEqual(suggestPaletteScale(.3, 8.9), "Linear", ""); // typical Rainbow Linear Test.ensureEqual(suggestPaletteScale(.11, 890), "Log", ""); // typical Rainbow Log Test.ensureEqual( suggestPaletteScale(-7, 8), "Linear", ""); // typical BlueWhiteRed Linear symmetric BufferedImage bi = ImageIO.read(new File(String2.unitTestDataDir + "graphs/erdBAssta5day.png")); long time = System.currentTimeMillis(); Test.ensureEqual(findGraph(bi), new int[] {24, 334, 150, 21}, ""); String2.log("findGraph time=" + (System.currentTimeMillis() - time)); }