Draws ticks, grid and axis label for each tick/grid line. The grid or major tick spacing in each direction is given by steps
(double[] steps)
| 2701 | /** Draws ticks, grid and axis label for each tick/grid line. |
| 2702 | * The grid or major tick spacing in each direction is given by steps */ |
| 2703 | @AstroImageJ(reason = "Set font size to 12 for axis labels", modified = true) |
| 2704 | void drawAxesTicksGridNumbers(double[] steps) { |
| 2705 | |
| 2706 | if (ip==null) |
| 2707 | return; |
| 2708 | String[] xCats = labelsInBraces('x'); // create categories for the axes (if any) |
| 2709 | String[] yCats = labelsInBraces('y'); |
| 2710 | String multiplySymbol = getMultiplySymbol(); // for scientific notation |
| 2711 | Font scFont = scFont(pp.frame.getFont()); |
| 2712 | Font scFontMedium = scFont.deriveFont(scFont.getSize2D()*10f/12f); //for axis numbers if full size does not fit |
| 2713 | Font scFontSmall = scFont.deriveFont(scFont.getSize2D()*9f/12f); //for subscripts |
| 2714 | ip.setFont(scFont); |
| 2715 | ip.setFontSize(12); |
| 2716 | FontMetrics fm = ip.getFontMetrics(); |
| 2717 | int fontAscent = fm.getAscent(); |
| 2718 | ip.setJustification(LEFT); |
| 2719 | // --- A l o n g X A x i s |
| 2720 | int yOfXAxisNumbers = topMargin + frameHeight + fm.getHeight()*5/4 + sc(2); |
| 2721 | if (hasFlag(X_NUMBERS | (logXAxis ? (X_TICKS | X_MINOR_TICKS) : X_LOG_TICKS) + X_GRID)) { |
| 2722 | Font baseFont = scFont; |
| 2723 | boolean majorTicks = logXAxis ? hasFlag(X_LOG_TICKS) : hasFlag(X_TICKS); |
| 2724 | boolean minorTicks = hasFlag(X_MINOR_TICKS); |
| 2725 | minorTicks = minorTicks && (xCats == null); |
| 2726 | double step = steps[0]; |
| 2727 | int i1 = (int)Math.ceil (Math.min(xMin, xMax)/step-1.e-10); |
| 2728 | int i2 = (int)Math.floor(Math.max(xMin, xMax)/step+1.e-10); |
| 2729 | int suggestedDigits = (int)Tools.getNumberFromList(pp.frame.options, "xdecimals="); //is not given, NaN cast to 0 |
| 2730 | int digits = getDigits(xMin, xMax, step, 7, suggestedDigits); |
| 2731 | int y1 = topMargin; |
| 2732 | int y2 = topMargin + frameHeight; |
| 2733 | if (xMin==xMax) { |
| 2734 | if (hasFlag(X_NUMBERS)) { |
| 2735 | String s = IJ.d2s(xMin,getDigits(xMin, 0.001*xMin, 5, suggestedDigits)); |
| 2736 | int y = yBasePxl; |
| 2737 | ip.drawString(s, xBasePxl-ip.getStringWidth(s)/2, yOfXAxisNumbers); |
| 2738 | } |
| 2739 | } else { |
| 2740 | if (hasFlag(X_NUMBERS)) { |
| 2741 | int w1 = ip.getStringWidth(IJ.d2s(currentMinMax[0], logXAxis ? -1 : digits)); |
| 2742 | int w2 = ip.getStringWidth(IJ.d2s(currentMinMax[1], logXAxis ? -1 : digits)); |
| 2743 | int wMax = Math.max(w1,w2); |
| 2744 | if (wMax > Math.abs(step*xScale)-sc(8)) { |
| 2745 | baseFont = scFontMedium; //small font if there is not enough space for the numbers |
| 2746 | ip.setFont(baseFont); |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | for (int i=0; i<=(i2-i1); i++) { |
| 2751 | double v = (i+i1)*step; |
| 2752 | int x = (int)Math.round((v - xMin)*xScale) + leftMargin; |
| 2753 | |
| 2754 | if (xCats!= null) { |
| 2755 | int index = (int) v; |
| 2756 | double remainder = Math.abs(v - Math.round(v)); |
| 2757 | if(index >= 0 && index < xCats.length && remainder < 1e-9){ |
| 2758 | String s = xCats[index]; |
| 2759 | String[] parts = s.split("\n"); |
| 2760 | int w = 0; |
no test coverage detected