getRunTimeContext( ).getLocale( ) ) );
getRunTimeContext( ).getULocale( ).toLocale( ) ) );
	protected final void renderFittingCurve( IPrimitiveRenderer ipr,			Location[] points, CurveFitting curve, boolean bShowAsTape,			boolean bDeferred ) throws ChartException	{		if ( !curve.getLineAttributes( ).isSetVisible( ) )		{			throw new ChartException( ChartEnginePlugin.ID,					ChartException.RENDERING,					"exception.curve.line.visibility.not.defined", //$NON-NLS-1$					ResourceBundle.getBundle( Messages.ENGINE,							getRunTimeContext( ).getLocale( ) ) );		}		boolean isTransposed = ( (ChartWithAxes) getModel( ) ).isTransposed( );		if ( curve.getLineAttributes( ).isVisible( ) )		{			ScriptHandler.callFunction( getRunTimeContext( ).getScriptHandler( ),					ScriptHandler.BEFORE_DRAW_FITTING_CURVE,					curve,					getRunTimeContext( ).getScriptContext( ) );			getRunTimeContext( ).notifyStructureChange( IStructureDefinitionListener.BEFORE_DRAW_FITTING_CURVE,					curve );			// Render curve.			double[] xArray = new double[points.length];			double[] yArray = new double[points.length];			for ( int i = 0; i < xArray.length; i++ )			{				xArray[i] = points[i].getX( );				yArray[i] = points[i].getY( );			}			sort( xArray, yArray, !isTransposed );			double[] baseArray = xArray, orthogonalArray = yArray;			if ( isTransposed )			{				baseArray = yArray;				orthogonalArray = xArray;			}			FittingCalculator fc = new FittingCalculator( baseArray,					orthogonalArray,					0.33 );			double[] fitYarray = fc.getFittedValue( );			orthogonalArray = fitYarray;			if ( isTransposed )			{				baseArray = fitYarray;				orthogonalArray = yArray;				sort( baseArray, orthogonalArray, false );			}			if ( curve.getLineAttributes( ).getColor( ) != null )			{				CurveRenderer crdr = new CurveRenderer( (ChartWithAxes) getModel( ),						this,						curve.getLineAttributes( ),						LocationImpl.create( baseArray, orthogonalArray ),						bShowAsTape,						-1,						bDeferred,						false,						null,						false,						true );				crdr.draw( ipr );			}			// Render curve label.			if ( curve.getLabel( ).isSetVisible( )					&& curve.getLabel( ).isVisible( ) )			{				Label lb = LabelImpl.copyInstance( curve.getLabel( ) );				// handle external resource string				final String sPreviousValue = lb.getCaption( ).getValue( );				lb.getCaption( )						.setValue( getRunTimeContext( ).externalizedMessage( sPreviousValue ) );				if ( isTransposed )				{					// transpose text angel.					double rot = lb.getCaption( ).getFont( ).getRotation( );					if ( rot >= 0 && rot <= 90 )					{						rot = -( 90 - rot );					}					else if ( rot < 0 && rot >= -90 )					{						rot = ( rot + 90 );					}					lb.getCaption( ).getFont( ).setRotation( rot );				}				BoundingBox bb = Methods.computeBox( getXServer( ),						IConstants.LEFT/* DONT-CARE */,						lb,						0,						0 );				Anchor lbAnchor = curve.getLabelAnchor( );				if ( lbAnchor == null )				{					lbAnchor = Anchor.NORTH_LITERAL;				}				int horizontal = IConstants.CENTER;				int vertical = IConstants.ABOVE;				// convert anchor to position.				switch ( lbAnchor.getValue( ) )				{					case Anchor.WEST :					case Anchor.NORTH_WEST :					case Anchor.SOUTH_WEST :						horizontal = IConstants.LEFT;						break;					case Anchor.NORTH :					case Anchor.SOUTH :						horizontal = IConstants.CENTER;						break;					case Anchor.EAST :					case Anchor.NORTH_EAST :					case Anchor.SOUTH_EAST :						horizontal = IConstants.RIGHT;						break;				}				switch ( lbAnchor.getValue( ) )				{					case Anchor.NORTH :					case Anchor.NORTH_WEST :					case Anchor.NORTH_EAST :					case Anchor.WEST :					case Anchor.EAST :						vertical = IConstants.ABOVE;						break;					case Anchor.SOUTH :					case Anchor.SOUTH_WEST :					case Anchor.SOUTH_EAST :						vertical = IConstants.BELOW;						break;				}				double xc, yc;				if ( isTransposed )				{					if ( horizontal == IConstants.LEFT )					{						yc = orthogonalArray[orthogonalArray.length - 1]								- bb.getHeight( );					}					else if ( horizontal == IConstants.RIGHT )					{						yc = orthogonalArray[0] + bb.getHeight( ) / 2d;					}					else					{						yc = orthogonalArray[0]								+ ( orthogonalArray[orthogonalArray.length - 1] - orthogonalArray[0] )								/ 2d;					}					xc = getFitYPosition( orthogonalArray,							baseArray,							yc,							bb.getHeight( ),							bb.getWidth( ),							vertical == IConstants.BELOW );				}				else				{					if ( horizontal == IConstants.LEFT )					{						xc = xArray[0];					}					else if ( horizontal == IConstants.RIGHT )					{						xc = xArray[xArray.length - 1] - bb.getWidth( );					}					else					{						xc = xArray[0]								+ ( xArray[xArray.length - 1] - xArray[0] )								/ 2d;					}					yc = getFitYPosition( xArray,							fitYarray,							xc,							bb.getWidth( ),							bb.getHeight( ),							vertical == IConstants.ABOVE );				}				bb.setLeft( xc );				bb.setTop( yc );				if ( ChartUtil.isShadowDefined( lb ) )				{					renderLabel( StructureSource.createSeries( getSeries( ) ),							TextRenderEvent.RENDER_SHADOW_AT_LOCATION,							lb,							Position.RIGHT_LITERAL,							LocationImpl.create( bb.getLeft( ), bb.getTop( ) ),							BoundsImpl.create( bb.getLeft( ),									bb.getTop( ),									bb.getWidth( ),									bb.getHeight( ) ) );				}				renderLabel( StructureSource.createSeries( getSeries( ) ),						TextRenderEvent.RENDER_TEXT_IN_BLOCK,						lb,						Position.RIGHT_LITERAL,						LocationImpl.create( bb.getLeft( ), bb.getTop( ) ),						BoundsImpl.create( bb.getLeft( ),								bb.getTop( ),								bb.getWidth( ),								bb.getHeight( ) ) );			}			ScriptHandler.callFunction( getRunTimeContext( ).getScriptHandler( ),					ScriptHandler.AFTER_DRAW_FITTING_CURVE,					curve,					getRunTimeContext( ).getScriptContext( ) );			getRunTimeContext( ).notifyStructureChange( IStructureDefinitionListener.AFTER_DRAW_FITTING_CURVE,					curve );		}	}