MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / drawBin

Method drawBin

src/org/opensourcephysics/display/Histogram.java:833–862  ·  view source on GitHub ↗

Draws a filled bin. @param drawingPanel @param g @param binNumber @param occurrences

(DrawingPanel drawingPanel, Graphics g, int binNumber, double occurrences)

Source from the content-addressed store, hash-verified

831 * @param occurrences
832 */
833 protected void drawBin(DrawingPanel drawingPanel, Graphics g, int binNumber, double occurrences) {
834 if (adjustForWidth) {
835 occurrences = occurrences / getBinWidth();
836 }
837 if (logScale) {
838 occurrences = Math.max(0, Math.log(occurrences));
839 }
840 int binlx = drawingPanel.xToPix(getLeftMostBinPosition(binNumber));
841 if (discrete) {
842 if (binEdgeColor != null) {
843 g.setColor(binEdgeColor);
844 g.drawLine(binlx, drawingPanel.yToPix(YMIN), binlx, drawingPanel.yToPix(occurrences));
845 }
846 } else { // continous, draw entire bin
847 int binrx = drawingPanel.xToPix(getRightMostBinPosition(binNumber));
848 int pWidth = binrx - binlx;
849 double pHeight = drawingPanel.getYPixPerUnit() * occurrences;
850 java.awt.geom.Rectangle2D.Double rect = new java.awt.geom.Rectangle2D.Double(binlx,
851 drawingPanel.yToPix(occurrences), pWidth, pHeight);
852 Graphics2D g2 = (Graphics2D) g;
853 if (binFillColor != null) {
854 g.setColor(binFillColor);
855 g2.fill(rect);
856 }
857 if (binEdgeColor != null) {
858 g.setColor(binEdgeColor);
859 g2.draw(rect);
860 }
861 }
862 }
863
864 /**
865 * Gets an array containing the bin centers.

Callers 1

drawMethod · 0.95

Calls 12

getBinWidthMethod · 0.95
maxMethod · 0.80
drawLineMethod · 0.80
getYPixPerUnitMethod · 0.80
drawMethod · 0.65
logMethod · 0.45
xToPixMethod · 0.45
setColorMethod · 0.45
yToPixMethod · 0.45
fillMethod · 0.45

Tested by

no test coverage detected