- min_dist = 3;
- }
- else if ( dynamic_hiding_factor > 100 ) {
- min_dist = 2;
- }
- }
- if ( !node.isExternal() && !node.isCollapse() ) {
- boolean first_child = true;
- float y2 = 0.0f;
- final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
- for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
- final PhylogenyNode child_node = node.getChildNode( i );
- int factor_x;
- if ( !isUniformBranchLengthsForCladogram() ) {
- factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
- }
- else {
- factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
- }
- if ( first_child ) {
- first_child = false;
- y2 = node.getYcoord()
- - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
- }
- else {
- y2 += _y_distance * child_node.getNumberOfExternalNodes();
- }
- final float x2 = calculateBranchLengthToParent( child_node, factor_x );
- new_x = x2 + node.getXcoord();
- if ( dynamically_hide && ( x2 < new_x_min ) ) {
- new_x_min = x2;
- }
- final float diff_y = node.getYcoord() - y2;
- final float diff_x = node.getXcoord() - new_x;
- if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
- || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
- paintBranchRectangular( g,
- node.getXcoord(),
- new_x,
- node.getYcoord(),
- y2,
- child_node,
- to_pdf,
- to_graphics_file );
- }
- child_node.setXcoord( new_x );
- child_node.setYcoord( y2 );
- y2 += _y_distance * child_node.getNumberOfExternalNodes();
- }
- paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
- }
- if ( dynamically_hide
- && !is_in_found_nodes
- && ( ( node.isExternal() && ( _external_node_index % dynamic_hiding_factor != 1 ) ) || ( !node
- .isExternal() && ( ( new_x_min < 20 ) || ( _y_distance * node.getNumberOfExternalNodes() < getTreeFontSet()._fm_large
- .getHeight() ) ) ) ) ) {
- return;
- }
- paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
- paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
- }
-
- final private void paintNodeWithRenderableData( final Graphics2D g,
- final PhylogenyNode node,
- final boolean to_graphics_file,
- final boolean to_pdf ) {
- if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
- return;
- }
- if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
- return;
- }
- if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
- && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
- RenderableDomainArchitecture rds = null;
- if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
- try {
- rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
- }
- catch ( final ClassCastException cce ) {
- cce.printStackTrace();
- return;
- }
- rds.setRenderingHeight( 6 );
- int x = 0;
- if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) {
- x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
- }
- if ( getControlPanel().isShowGeneNames() ) {
- x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
- }
- if ( getControlPanel().isShowGeneSymbols() ) {
- x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
- }
- if ( getControlPanel().isShowSequenceAcc() ) {
- x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
- .toString()
- + " " );
- }
- if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
- x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
- }
- rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
- }
- }
- //////////////
- if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
- && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
- final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
- getStatisticsForExpressionValues(),
- getConfiguration() );
- int x = 0;
- PhylogenyNode my_node = node;
- if ( !getControlPanel().isDrawPhylogram() ) {
- my_node = getPhylogeny().getFirstExternalNode();
- }
- if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
- x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
- }
- if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
- x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
- }
- rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
- }
- //////////////
- }
-
- final private void paintOvRectangle( final Graphics2D g ) {
- final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
- final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
- final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
- final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
- final float width = getOvMaxWidth() / w_ratio;
- final float height = getOvMaxHeight() / h_ratio;
- final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
- final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
- g.setColor( getTreeColorSet().getFoundColor() );
- getOvRectangle().setRect( x, y, width, height );
- if ( ( width < 6 ) && ( height < 6 ) ) {
- drawRectFilled( x, y, 6, 6, g );
- getOvVirtualRectangle().setRect( x, y, 6, 6 );
- }
- else if ( width < 6 ) {
- drawRectFilled( x, y, 6, height, g );
- getOvVirtualRectangle().setRect( x, y, 6, height );
- }
- else if ( height < 6 ) {
- drawRectFilled( x, y, width, 6, g );
- getOvVirtualRectangle().setRect( x, y, width, 6 );
- }
- else {
- drawRect( x, y, width, height, g );
- if ( isInOvRect() ) {
- drawRect( x + 1, y + 1, width - 2, height - 2, g );
- }
- getOvVirtualRectangle().setRect( x, y, width, height );
- }
- }
-
- final void paintPhylogeny( final Graphics2D g,
- final boolean to_pdf,
- final boolean to_graphics_file,
- final int graphics_file_width,
- final int graphics_file_height,
- final int graphics_file_x,
- final int graphics_file_y ) {
- if ( _control_panel.isShowSequenceRelations() ) {
- _query_sequence = _control_panel.getSelectedQuerySequence();
- }
- // Color the background
- if ( !to_pdf ) {
- final Rectangle r = getVisibleRect();
- if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
- g.setColor( getTreeColorSet().getBackgroundColor() );
- if ( !to_graphics_file ) {
- g.fill( r );
- }
- else {
- if ( getOptions().isPrintBlackAndWhite() ) {
- g.setColor( Color.WHITE );
- }
- g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
- }
- }
- else {
- if ( !to_graphics_file ) {
- g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
- + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
- g.fill( r );
- }
- else {
- g.setPaint( new GradientPaint( graphics_file_x,
- graphics_file_y,
- getTreeColorSet().getBackgroundColor(),
- graphics_file_x,
- graphics_file_y + graphics_file_height,
- getTreeColorSet().getBackgroundColorGradientBottom() ) );
- g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
- }
- }
- g.setStroke( new BasicStroke( 1 ) );
- }
- else {
- g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
- }
- if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
- && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
- _external_node_index = 0;
- // Position starting X of tree
- if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
- _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
- }
- else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
- _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
- .getDistanceToParent() * getXcorrectionFactor() ) ) );
- }
- else {
- _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
- }
- // Position starting Y of tree
- _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
- + ( TreePanel.MOVE / 2.0f ) );
- final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
- if ( getControlPanel().isDynamicallyHideData() ) {
- if ( dynamic_hiding_factor > 1 ) {
- getControlPanel().setDynamicHidingIsOn( true );
- }
- else {
- getControlPanel().setDynamicHidingIsOn( false );
- }
- }
- if ( _nodes_in_preorder == null ) {
- _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
- int i = 0;
- for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
- _nodes_in_preorder[ i++ ] = it.next();
- }
- }
- //final PhylogenyNodeIterator it;
- //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
- // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
- // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
- //}
- for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
- paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
- && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
- }
- if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
- if ( !( to_graphics_file || to_pdf ) ) {
- paintScale( g,
- getVisibleRect().x,
- getVisibleRect().y + getVisibleRect().height,
- to_pdf,
- to_graphics_file );
- }
- else {
- paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
- }
- }
- if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
- paintPhylogenyLite( g );
- }
- }
- else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
- if ( getControlPanel().getDynamicallyHideData() != null ) {
- getControlPanel().setDynamicHidingIsOn( false );
- }
- final double angle = getStartingAngle();
- final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
- _dynamic_hiding_factor = 0;
- if ( getControlPanel().isDynamicallyHideData() ) {
- _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
- .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );