001package org.opengion.hayabusa.io;
002
003import org.opengion.fukurou.system.HybsConst ;          // 6.1.0.0 (2014/12/26)
004
005/**
006 * JsChartData は、JsChartData の個別属性を管理しているデータ管理クラスです。
007 * 
008 * @version     5.9.17.2                2017/02/08
009 * @author      T.OTA
010 * @sinse       JDK7.0
011 *
012 */
013public class JsChartData {
014        private String  chartColumn                     ;       // チャートカラム
015        private String  label                           ;       // ラベル
016        private String  fill                            ;       // フィル
017        private String  tension                         ;       // 伸張
018        private String  borderColor                     ;       // 線の色
019        private String  borderWidth                     ;       // 線の幅
020        private String  backgroundColor         ;       // 背景色
021        private String  pointStyle                      ;       // 6.8.5.0 (2018/01/09) 点のスタイル
022        private String  pointRadius                     ;       // 6.8.5.0 (2018/01/09) 点の大きさ
023        private String  showLine                        ;       // 6.8.5.0 (2018/01/09) ラインを表示するかどうか
024        private String  optionAttributes        ;       // オプション
025
026        /**
027         * デフォルトコンストラクター
028         *
029         * @og.rev 6.9.7.0 (2018/05/14) PMD Each class should declare at least one constructor
030         */
031        public JsChartData() { super(); }               // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
032
033        /**
034         * チャートカラムを設定します。
035         * 
036         * @param chartColumn チャートカラム
037         */
038        public void setChartColumn( final String chartColumn ) {
039                this.chartColumn = chartColumn;
040        }
041
042        /**
043         * JsChartData オブジェクトを作成する時のチャートカラムを取得します。
044         * 
045         * @return チャートカラム
046         */
047        public String getChartColumn() {
048                return chartColumn;
049        }
050
051        /**
052         * ラベルを設定します。
053         * 
054         * @param label ラベル
055         */
056        public void setLabel( final String label ) {
057                this.label = label;
058        }
059
060        /**
061         * ラベルを取得します。
062         * 
063         * @return ラベル
064         */
065        public String getLabel() {
066                return label;
067        }
068
069        /**
070         * フィル を設定します。
071         * @param fill フィル
072         */
073        public void setFill( final String fill ) {
074                this.fill = fill;
075        }
076
077        /**
078         * 線の伸張 を設定します。
079         * 
080         * @param tension 線の伸張
081         */
082        public void setTension( final String tension ) {
083                this.tension = tension;
084        }
085
086        /**
087         * 線の色 を設定します。
088         * 
089         * @param borderColor 線の色
090         */
091        public void setBorderColor( final String borderColor ) {
092                this.borderColor = borderColor;
093        }
094
095        /**
096         * 線の幅 を設定します。
097         * 
098         * @param borderWidth 線の幅
099         */
100        public void setBorderWidth( final String borderWidth ) {
101                this.borderWidth = borderWidth;
102        }
103
104        /**
105         * 背景色 を設定します。
106         * 
107         * @param backgroundColor 背景色
108         */
109        public void setBackgroundColor( final String backgroundColor ) {
110                this.backgroundColor = backgroundColor;
111        }
112
113        /**
114         * 点のスタイルを指定します。
115         *
116         * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。
117         * 点のスタイルは、circle,triangle,rect,rectRot,cross,crossRot,star,line,dash が、
118         * 
119         * @og.rev 6.8.5.0 (2018/01/09) 新規追加
120         * 
121         * @param ptStyle 点のスタイルを指定します。
122         */
123        public void setPointStyle( final String ptStyle ) {
124                pointStyle = ptStyle;
125        }
126
127        /**
128         * 点の大きさを指定します。
129         *
130         * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。
131         * 
132         * @og.rev 6.8.5.0 (2018/01/09) 新規追加
133         * 
134         * @param ptRadius 点の大きさを指定します。
135         */
136        public void setPointRadius( final String ptRadius ) {
137                pointRadius = ptRadius;
138        }
139
140        /**
141         * ラインを表示するかどうか[true/false]を指定します(初期値:null)。
142         *
143         * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。
144         * 初期値(null)は、showLine 属性を設定しませんが、chartJS 自体の初期値が true
145         * なので、表示されます。
146         * 
147         * @og.rev 6.8.5.0 (2018/01/09) 新規追加
148         * 
149         * @param show ラインを表示するかどうか[true/false]
150         */
151        public void setShowLine( final String show ) {
152                showLine = show;
153        }
154
155        /**
156         * オプション情報 を設定します。
157         * 
158         * @param optionAttributes オプション情報
159         */
160        public void setOptionAttributes( final String optionAttributes ) {
161                this.optionAttributes = optionAttributes;
162        }
163
164        /**
165         * JsChartData オブジェクトを作成する時のオプション情報を取得します。
166         * 
167         * @return オプション情報
168         */
169        public String getOptionAttributes() {
170                return optionAttributes;
171        }
172
173        /**
174         * JsChartData オブジェクトを作成するときのパラメータ情報を取得します。
175         * chartColumnとoptionAttributesを使用して、
176         * パラメータ情報を作成します。 
177         * 
178         * @return パラメータ文字列
179         */
180        public String getParameter() {
181                final StringBuilder rtn = new StringBuilder( HybsConst.BUFFER_SMALL );
182                rtn.append( '{' );
183                if( label != null && label.length() > 0 ) {
184                        rtn.append( "label:'" ).append( label ).append( "'," );
185                }
186                rtn.append( "data:" ).append( chartColumn );
187                setProp( rtn, ",fill:"                          , fill                                                          );
188                setProp( rtn, ",tension:"                       , tension                                                       );
189                setProp( rtn, ",borderColor:"           , setParaOrArray( borderColor )         );
190                setProp( rtn, ",borderWidth:"           , borderWidth                                           );
191                setProp( rtn, ",backgroundColor:"       , setParaOrArray( backgroundColor )     );
192                setProp( rtn, ",pointStyle:"            , setParaOrArray( pointStyle )          );
193                setProp( rtn, ",pointRadius:"           , pointRadius                                           );
194                setProp( rtn, ",showLine:"                      , showLine                                                      );
195                setProp( rtn, ","                                       , optionAttributes                                      );
196                rtn.append( '}' );
197
198                return rtn.toString();
199        }
200
201        /**
202         * 配列が指定される事がある場合の、値設定。
203         * 
204         * @param str 引数(配列形式もありえる)
205         * @return パラメータ文字
206         */
207        private String setParaOrArray( final String str ) {
208                final StringBuilder sb = new StringBuilder( HybsConst.BUFFER_MIDDLE );
209
210                // 引数が配列形式の記載であるかを判定。(頭文字が「[」であるかどうか)
211                if( str != null && str.length() > 0 && !"[".equals( str.substring( 0, 1 ) ) ) {
212                        // 配列でない場合は、シングルクォテーションを付与
213                        sb.append( '\'' ).append( str ).append( '\'' );
214                } else {
215                        // 配列の場合はそのまま
216                        sb.append( str );
217                }
218
219                return sb.toString();
220        }
221
222        /**
223         * プロパティ設定用メソッド。
224         * 
225         * setに値が存在する場合,
226         * sbにstr + setの形で値を追加する。
227         * 
228         * @param sb    ベースとなるStringBuilder
229         * @param str   文字列1
230         * @param set   文字列2
231         */
232        private void setProp( final StringBuilder sb, final String str, final String set ) {
233                if( set != null && set.length() > 0 ) {
234                        sb.append( str ).append( set );
235                }
236        }
237}