001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.hayabusa.io; 017 018import java.util.List; 019import java.awt.GradientPaint; 020import java.awt.Color; 021import java.awt.BasicStroke; 022 023import org.jfree.chart.plot.Plot; 024import org.jfree.chart.plot.ValueMarker; 025import org.jfree.chart.axis.CategoryAxis; 026import org.jfree.chart.axis.ValueAxis; 027import org.jfree.chart.renderer.category.CategoryItemRenderer; 028import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 029import org.jfree.data.category.CategoryDataset; 030import org.jfree.ui.Layer; 031 032/** 033 * ChartPlot_Category は、ChartPlot インターフェースを継承した実体クラスです。 034 * JFreeChart では、CategoryPlot 関係の プロットを構築して、レンデラーや、データセットを 035 * 設定していきます。 036 * ここでは、複数のデータセットをサポートしており、ChartCreate の getDatasetList で 037 * 得られる List オブジェクトを順に設定していきます。 038 * 039 * @version 0.9.0 2007/06/21 040 * @author Kazuhiko Hasegawa 041 * @since JDK1.1, 042 */ 043public class ChartPlot_Category implements ChartPlot { 044 045 private static final BasicStroke DOT_LINE = 046 new BasicStroke( 047 2.0f, // 太さ 048 BasicStroke.CAP_ROUND, 049 BasicStroke.JOIN_ROUND, 050 1.0f, 051 new float[] { 10.0f, 6.0f }, // 破線の形状 052 0.0f); 053 054 /** 055 * デフォルトコンストラクター 056 * 057 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 058 */ 059 public ChartPlot_Category() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 060 061 /** 062 * Plot オブジェクトを取得します。 063 * 064 * Plot オブジェクト には、その種類の応じた、データセットやレンデラーを 065 * 設定する必要があります。 066 * また、複数のデータセットや、それに関係する属性情報も、設定する必要が 067 * あります。 068 * Plot は、JFreeChart オブジェクトにつき、一つ用意しなければなりません。 069 * チャート合成時でも、Plot は一つです。 070 * 071 * @og.rev 3.8.9.2 (2007/07/28) シリーズ指定時の色、シェープ対応 072 * @og.rev 4.1.1.0 (2008/02/04) クリッカブル・マップの設定を ChartDataset に移動 073 * @og.rev 4.1.1.0 (2008/02/04) CategoryPlotの設定を ChartCreate に移動 074 * @og.rev 4.1.1.0 (2008/02/19) Shapes の設定をChartDatasetに移動。 075 * @og.rev 5.1.4.0 (2010/03/01) jfreechart-1.0.13 対応。CategoryDataset は、setRangeAxis より先に行う必要がある。 076 * @og.rev 6.2.0.0 (2015/02/27) グラフの重ね合わせ時に、縦軸表示が崩れる対応(暫定) 077 * 078 * @param create ChartCreateオブジェクト 079 * 080 * @return Plotオブジェクト 081 */ 082 public Plot getPlot( final ChartCreate create ) { 083 final int serNo = create.getSeriesPikup(); 084 final HybsCategoryPlot cPlot = create.makeCategoryPlot(); 085 086 CategoryItemRenderer rend ; 087 088 // クリッカブル・マップ 089 final HybsURLGenerator urlGen = create.getURLGenerator(); 090 // 4.3.1.0 (2008/08/09) ツールチップス利用フラグ 091 // 4.9.9.9 (2009/08/07) メソッド名変更 092 final boolean useToolTip = create.isUseToolTip(); 093 094 final List<ChartDataset> datasetList = create.getDatasetList(); 095 for( int idx=0; idx<datasetList.size(); idx++ ) { 096 final ChartDataset chDataset = datasetList.get( idx ); 097 098 // 5.1.4.0 (2010/03/01) jfreechart-1.0.13 対応。CategoryDataset は、setRangeAxis より先に行う必要がある。 099 final CategoryDataset dtset = (CategoryDataset)chDataset.getDataset(); 100 101 final int rowCnt = dtset.getRowCount(); // Series の個数 102 cPlot.setDataset( idx,dtset ); 103 104 // 個別に、CategoryAxis を作成します。 105 final CategoryAxis categoryAxis = create.makeCategoryAxis(); 106 cPlot.setDomainAxis( idx,categoryAxis,false ); 107 108 // 横軸ラベルの表示は、グラフ合成時には行いません 109 if( idx > 0 ) { 110 categoryAxis.setVisible( false ); // ドメインラベルの表示有無 111 } 112 113 // 4.1.1.0 (2008/02/04) クリッカブル・マップの設定を移動 114 rend = chDataset.getRenderer( serNo,urlGen ); 115 cPlot.setRenderer( idx,rend,false ); 116 117 final ValueAxis vaxis = chDataset.makeNumberAxis(); 118 cPlot.setRangeAxis( idx,vaxis,false ); 119 120 // 縦軸マーカーの設定(横ライン) 121 final ValueMarker[] marker = chDataset.getValueMarkers(); 122 for( int i=0; i<marker.length; i++ ) { 123 cPlot.addRangeMarker( idx,marker[i],Layer.FOREGROUND ); 124 } 125 126 // 4.0.3.0 (2008/01/07) BOXチャートのバー幅(double)を指定 127 final String barWidth = chDataset.getBarWidth(); 128 if( barWidth != null ) { 129 cPlot.setBarWidth( idx,Double.valueOf( barWidth ) ); 130 } 131 132 // シリーズの色設定 133 final Color[] colors = chDataset.getSeriesColors(); 134 if( serNo < 0 && colors != null && colors.length > 0 ) { 135 final int size = colors.length ; 136 for( int row=0; row<rowCnt; row++ ) { 137 rend.setSeriesPaint( row, colors[ row%size ] ); 138 } 139 } 140 141 if( serNo >= 0 && serNo < rowCnt ) { 142 for( int row=0; row<rowCnt; row++ ) { 143 if( row == serNo ) { continue; } 144 rend.setSeriesPaint( row, Color.CYAN ); 145 } 146 rend.setSeriesPaint( serNo, Color.RED ); 147 } 148 149 // グラデーションの設定 150 if( chDataset.isUseGradient() ) { 151 for( int row=0; row<rowCnt; row++ ) { 152 final Color clr = (Color)rend.getSeriesPaint(row) ; 153 if( clr != null ) { 154 final Color clr1 = clr.brighter().brighter() ; 155 final Color clr2 = clr.darker().darker() ; 156 157 final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, clr1, 0.0f, 0.0f, clr2); 158 rend.setSeriesPaint( row, gp0 ); 159 } 160 } 161 } 162 163 // ラインチャートの点線表示 164 if( chDataset.isUseDottedLine() ) { 165 for( int row=0; row<rowCnt; row++ ) { 166 rend.setSeriesStroke( row,DOT_LINE ); 167 } 168 } 169 170 // 4.3.1.0 (2008/08/09) ツールチップスの利用 171 if( useToolTip ) { 172 rend.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); 173 } 174 } 175 return cPlot; 176 } 177}