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.Color;                                                                          // 5.9.17.1 (2017/02/10)
020
021import org.jfree.chart.plot.Plot;
022import org.jfree.chart.plot.XYPlot;
023import org.jfree.chart.plot.DatasetRenderingOrder;
024import org.jfree.chart.plot.ValueMarker;
025import org.jfree.chart.axis.DateAxis;
026import org.jfree.chart.axis.ValueAxis;
027import org.jfree.chart.renderer.xy.XYItemRenderer;
028import org.jfree.chart.labels.StandardXYToolTipGenerator;
029import org.jfree.data.xy.XYDataset;
030import org.jfree.ui.Layer;
031
032/**
033 * ChartPlot_XY は、ChartPlot インターフェースを継承した実体クラスです。
034 * JFreeChart では、XYPlot 関係の プロットを構築して、レンデラーや、データセットを
035 * 設定していきます。
036 * ここでは、複数のデータセットはサポートしていません。
037 *
038 * @og.rev 5.6.1.0 (2013/02/01) 新規作成
039 *
040 * @version  0.9.0      2007/06/21
041 * @author       Kazuhiko Hasegawa
042 * @since        JDK1.1,
043 */
044public class ChartPlot_XYTime implements ChartPlot {
045
046        /**
047         * デフォルトコンストラクター
048         *
049         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
050         */
051        public ChartPlot_XYTime() { super(); }          // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
052
053        /**
054         * Plot オブジェクトを取得します。
055         *
056         * Plot オブジェクト には、その種類の応じた、データセットやレンデラーを
057         * 設定する必要があります。
058         * また、複数のデータセットや、それに関係する属性情報も、設定する必要が
059         * あります。
060         * Plot は、JFreeChart オブジェクトにつき、一つ用意しなければなりません。
061         * チャート合成時でも、Plot は一つです。
062         * 
063         * @og.rev 5.9.17.1 (2017/02/10) 色設定の反映
064         *
065         * @param       create  ChartCreateオブジェクト
066         *
067         * @return      Plotオブジェクト
068         */
069        public Plot getPlot( final ChartCreate create ) {
070                final XYPlot xyPlot = new XYPlot();
071
072                XYItemRenderer rend ;
073                ValueAxis      yaxis ;
074
075                final DateAxis daxis = create.getDateAxis();
076                xyPlot.setDomainAxis( daxis );
077
078                xyPlot.setOrientation( create.getPlotOrientation() );
079                xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
080
081                // クリッカブル・マップ
082                final HybsURLGenerator urlGen = create.getURLGenerator();
083                final boolean useToolTip = create.isUseToolTip();               // 4.9.9.9 (2009/08/07) メソッド名変更
084
085                final List<ChartDataset> datasetList = create.getDatasetList();
086                for( int idx=0; idx<datasetList.size(); idx++ ) {
087                        final ChartDataset chDataset = datasetList.get(idx);
088
089                        // 4.1.1.0 (2008/02/04) XYItemRenderer を直接取得します。
090                        final String chartType = chDataset.getChartType();
091                        final TypeRenderer typeRen = ChartFactory.getTypeRenderer( chartType );
092                        rend = (XYItemRenderer)typeRen.getRenderer();
093
094                        xyPlot.setRenderer(idx,rend,false);
095                        // クリッカブル・マップ
096                        if( urlGen != null ) {
097                                rend.setURLGenerator( urlGen );
098                        }
099                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
100                                rend.setBaseToolTipGenerator( new StandardXYToolTipGenerator() );
101                        }
102
103                        // 色設定  5.9.17.1 (2017/02/10)
104                        final Color[] clrs = chDataset.getSeriesColors();
105                        if( clrs != null && clrs.length>0){
106                                for( int i=0;i<clrs.length; i++){
107                                        rend.setSeriesPaint( i, clrs[i] );
108                                }
109                        }
110
111                        yaxis = chDataset.makeNumberAxis();
112                        xyPlot.setRangeAxis( idx,yaxis,false );
113
114                        // 縦軸マーカーの設定(横ライン)
115                        final ValueMarker[] marker = chDataset.getValueMarkers();
116                        for( int i=0; i<marker.length; i++ ) {
117                                xyPlot.addRangeMarker(idx,marker[i],Layer.FOREGROUND);
118                        }
119
120                        xyPlot.setDataset( idx,(XYDataset)chDataset.getDataset() );
121                }
122
123                return xyPlot;
124        }
125}