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