⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curvedrawpanel.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		g2.drawString("   0", origX - spaceAxisX, origY + spaceAxisY);

		//grid
		BasicStroke b = new BasicStroke(1.0f, BasicStroke.JOIN_MITER,
				BasicStroke.JOIN_MITER, 5.0f, dash, 0.0f);
		g2.setStroke(b);

//		 Draw the background
		if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_LIFT) ){ 
			// Get the maximum lift; the default maximum lift value is set to 2.  
			double maxLift = 2;
			Iterator keySet = curveData.keySet().iterator();  
			while (keySet.hasNext()) {
				String CurveName = (String) keySet.next();
				// should judge if the input map is of type double[][].
				double[][] dataSet = (double[][]) curveData.get(CurveName);

				//Draw one curve according to the input data Set
				for(int innerCounter = 0 ; innerCounter<dataSet.length; innerCounter++){
					maxLift = Math.max(maxLift, dataSet[innerCounter][1]);
				} 
			}
			// Multiplied by 10 to ease Y axis marker drawing.
			m_LiftChartJumpValue = (int)Math.ceil(maxLift);
			
			//Draw the grid frame
			int i = 1;
			for (; i < maxY / (10 * axisScale) + 1; i++) {
				// draw grid line
				g2.setPaint(Color.gray);
				g2.drawLine((origX + axisScale * 10 * i), origY, (origX + axisScale
						* 10 * i), origY - maxY); //x
				g2.drawLine(origX, (origY - axisScale * 10 * i), origX + maxX,
						(origY - axisScale * 10 * i)); //y
				//Draw the scale marker
				g2.setPaint(Color.BLACK.brighter().brighter());
				g2.drawString("" + (10 * i), (origX + axisScale * 10 * i) - 7,
						origY + spaceAxisY); //x
				g2.drawString("  " + m_LiftChartJumpValue * i / 10.0, (origX - spaceAxisX),
						(origY - axisScale * 10 * i) + 6); //y
				
				//	draw the base line, where lift value = 1;
				if (m_LiftChartJumpValue * i < 10 && m_LiftChartJumpValue * (i+1) >= 10){
					int baseLinePos = origY - (int)( axisScale * 10 * (i - (m_LiftChartJumpValue * i - 10.0)/m_LiftChartJumpValue));
					g2.fillRect(origX, baseLinePos-1, maxX, baseLineWidth);
				}
			} 
	
			//diaplay the label X, Y
			//Label X
			Font fx = new Font("serif", Font.BOLD, 14);
			g2.setFont(fx);
			g2.drawString(getLabelX(), (origX + (maxX - 4*getLabelX().length())) / 2, origY + 40);
			//if (((origX + (maxX - 4*getLabelX().length())) / 2)+ 4*getLabelX().length()> windowsWidth) windowsWidth = ((origX + (maxX - 4*getLabelX().length())) / 2)+ 4*getLabelX().length();
			//if (origY+40 > windowsHeight) windowsHeight = origY+40;

			//Label Y
			AffineTransform fontAT = new AffineTransform();
			fontAT.rotate(Math.toRadians(270));
			Font fy = new Font("serif", Font.BOLD, 14).deriveFont(fontAT);
			g2.setFont(fy);
			g2.drawString(getLabelY(), origX - 35,  origY - (maxY - 4*getLabelY().length()) / 2  );
	
			//set Chart title
			Font fchart = new Font("serif", Font.BOLD, 18);
			g2.setFont(fchart);
			g2.drawString(getChartTitle(),
					origX + (maxX - 4*getChartTitle().length()) / 2, origY
							- maxY - 20);
	 
		}
		else if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_CUMULATIVE_GAIN) ){ 
		 
			//Draw the grid frame
			int i = 1;
			for (; i < maxY / (10 * axisScale); i++) {
				// draw grid line
				g2.setPaint(Color.gray);
				g2.drawLine((origX + axisScale * 10 * i), origY, (origX + axisScale
						* 10 * i), origY - maxY); //x
				g2.drawLine(origX, (origY - axisScale * 10 * i), origX + maxX,
						(origY - axisScale * 10 * i)); //y
				//Draw the scale marker
				g2.setPaint(Color.BLACK.brighter().brighter());
				g2.drawString("" + (10 * i), (origX + axisScale * 10 * i) - 7,
						origY + spaceAxisY); //x
				g2.drawString("  " + (10 * i), (origX - spaceAxisX),
						(origY - axisScale * 10 * i) + 6); //y
			}
	
			//draw the 10th line
			g2.setPaint(Color.gray);
			g2.drawLine((origX + axisScale * 10 * i), origY, (origX + axisScale
					* 10 * i), origY - maxY); //x
			g2.drawLine(origX, (origY - axisScale * 10 * i), origX + maxX,
					(origY - axisScale * 10 * i)); //y
	
			//	draw the bias
			g2.setStroke(new BasicStroke(curveLineWidth));
			g2.setPaint(Color.gray.darker());
			g2.drawLine(origX, origY, (origX + (axisScale * 100)),
					(origY - (axisScale * 100)));
	 		g2.setPaint(Color.BLACK.brighter().brighter());
			g2.drawString("" + (10 * i), (origX + axisScale * 10 * i) - 7, origY
					+ spaceAxisY); //x
			g2.drawString("" + (10 * i), (origX - spaceAxisX), (origY - axisScale
					* 10 * i) + 6); //y
	
			//diaplay the label X, Y
			//Label X
			Font fx = new Font("serif", Font.BOLD, 14);
			g2.setFont(fx);
			g2.drawString(getLabelX(), (origX + (maxX - 4*getLabelX().length())) / 2, origY + 40);
	
			//Label Y
			AffineTransform fontAT = new AffineTransform();
			fontAT.rotate(Math.toRadians(270));
			Font fy = new Font("serif", Font.BOLD, 14).deriveFont(fontAT);
			g2.setFont(fy);
			g2.drawString(getLabelY(), origX - 35,  origY - (maxY - 4*getLabelY().length()) / 2  );
	
			//set Chart title
			Font fchart = new Font("serif", Font.BOLD, 18);
			g2.setFont(fchart);
			g2.drawString(getChartTitle(),
					origX + (maxX - 4*getChartTitle().length()) / 2, origY
							- maxY - 20);
	 
		}
		//g.drawRect(0,0,windowsWidth, windowsHeight);
		
		//Draw the Curve
 		DataDisplay(curveData);
	}

	/**
	 * Draw the specific one curve according to the data Set
	 * 
	 * @param data :
	 *            Curve data
	 * @param ShapeType:
	 *            Drawing line format
	 * @param curveColor:
	 *            Drawing line color
	 */
	public void drawCurve(double[][] data, int ShapeType, Color curveColor) {

		//Optimise the picture
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_RENDERING,
				RenderingHints.VALUE_RENDER_QUALITY);

		g2.setPaint(curveColor.brighter().brighter().brighter());
		g2.setStroke(new BasicStroke(curveLineWidth));

		//Draw the fist point
		if (isLineShowEnable()) {  
			int numOfQuantile = data.length;
			for(int i = 0; i< numOfQuantile-3;){ 
				// omit the line if all the four points fall outside the coordination
				// assume the data has been sorted in increasing order
				if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_LIFT) ){  
					if( data[i+3][0]>=0 && data[i][0]<=numOfQuantile
							&& data[i+3][1]>=0 && data[i][1]<=m_LiftChartJumpValue ){ 
								Shape shape = new CubicCurve2D.Double(			
									origX + (data[i][0]+1)*axisScale,   origY - (int) (data[i][1]*100/m_LiftChartJumpValue * axisScale),
									origX + (data[i+1][0]+1)*axisScale, origY - (int) (data[i+1][1]*100/m_LiftChartJumpValue * axisScale),
									origX + (data[i+2][0]+1)*axisScale, origY - (int) (data[i+2][1]*100/m_LiftChartJumpValue * axisScale),
									origX + (data[i+3][0]+1)*axisScale, origY - (int) (data[i+3][1]*100/m_LiftChartJumpValue * axisScale));							 
								i += 3;
								g2.draw(shape);
						}
					 
				}else{
					if( data[i+3][0]>=0 && data[i][0]<=numOfQuantile
						&& data[i+3][1]>=0 && data[i][1]<=120 ){ 
							Shape shape = new CubicCurve2D.Double(			
								origX + (data[i][0]+1)*axisScale,   origY - axisScale* data[i][1],
								origX + (data[i+1][0]+1)*axisScale, origY - axisScale* data[i+1][1],
								origX + (data[i+2][0]+1)*axisScale, origY - axisScale* data[(i+2)][1],
								origX + (data[i+3][0]+1)*axisScale, origY - axisScale* data[(i+3)][1]);
							i += 3;
							g2.draw(shape);
					}else{
						i += 3;
					}
				} 
			} 
			
			//	 Draw the begining segment 
			if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_CUMULATIVE_GAIN) ){
				Shape begin_Shape = new CubicCurve2D.Double(			
						origX, origY,
						origX, origY,
						origX + (data[0][0]+1)*axisScale, origY - axisScale* data[0][1],
						origX + (data[0][0]+1)*axisScale, origY - axisScale* data[0][1]);
				g2.draw(begin_Shape);
			}else{
				Shape shape = new CubicCurve2D.Double(			
						origX,  origY - (int) (data[0][1]*100/m_LiftChartJumpValue * axisScale), 
						origX,  origY - (int) (data[0][1]*100/m_LiftChartJumpValue * axisScale),  
						origX + (data[0][0]+1)*axisScale, origY - (int) (data[0][1]*100/m_LiftChartJumpValue * axisScale),
						origX + (data[0][0]+1)*axisScale, origY - (int) (data[0][1]*100/m_LiftChartJumpValue * axisScale));							 
				g2.draw(shape);
			}
			
		} else {
			int numOfQuantile = data.length;
			for(int i = 0; i<numOfQuantile; i++){  
				if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_LIFT) ){ 
					g2.fillOval(origX + (int)(data[i][0]+1) * axisScale - circleRadius/2, origY - (int) (data[i][1]*100/m_LiftChartJumpValue * axisScale) - circleRadius/2, circleRadius, circleRadius);
				}else{				
					g2.fillOval(origX + (int)(data[i][0]+1) * axisScale - circleRadius/2, origY - (int) data[i][1] * axisScale - circleRadius/2, circleRadius, circleRadius);
				}
			}
			if ( chartType.equals(PredictionAssessmentOperatorProperty.CHART_TYPE_CUMULATIVE_GAIN) ){ 
	 			//Draw the begining point 
			 	g2.fillOval(origX - circleRadius/2, origY - circleRadius/2, circleRadius, circleRadius);
			}
			
		} 
		
	}

	/**
	 * Display the corresponding cutline on the right of the chart
	 * 
	 * @param aLegendString:
	 *            cutline value
	 * @param x:
	 *            Location X axis value
	 * @param y:
	 *            Location Y axis value
	 * @param ShapeType:
	 *            curve line format
	 */
	private void drawLegend(String aLegendString, int x, int y, int ShapeType) {

		Font fx = new Font("serif", Font.BOLD, 14);
		g2.setFont(fx);
		
		if (isLineShowEnable()){
			g2.drawLine(x, y, x + axisScale * 10, y);
			if (aLegendString != null) { 
				g2.drawString(aLegendString, x + axisScale * 10 + 10, y + 5);
			}
		}else{ 
			g2.fillOval(x + circleRadiusDemo/2, y - circleRadiusDemo/2, circleRadiusDemo, circleRadiusDemo);
			if (aLegendString != null) { 
				g2.drawString(aLegendString, x + circleRadiusDemo + 10, y + 5);
			}
		}
		
		
	}  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -