001package org.opengion.hayabusa.taglib; 002 003import org.opengion.hayabusa.common.HybsSystemException; 004import org.opengion.hayabusa.io.JsChartData; 005 006import java.util.Set; // 6.4.3.4 (2016/03/11) 007import org.opengion.fukurou.util.ArraySet; // 6.4.3.4 (2016/03/11) 008import org.opengion.fukurou.util.ToString; 009import org.opengion.fukurou.util.ColorMap; // 6.7.7.0 (2017/03/31) 010import static org.opengion.fukurou.util.StringUtil.nval ; 011 012/** 013 * 設定された値をJsChartDataに設定し、 014 * JsChartTagのJsChartDataリストに追加するタグです。 015 * 016 * @og.formSample 017 * ●形式:<og:jsChartData chartColumn="…" … /> 018 * ●body:なし 019 * 020 * ●Tag定義: 021 * <og:jsChartData 022 * chartColumn ○【TAG】チャートのカラム名を指定します(必須)。 023 * label 【TAG】凡例の値を指定します。 024 * fill 【TAG】線下を塗りつぶすかどうか[true/false]を指定します(初期値:false)。 025 * tension 【TAG】線の伸張を指定します。0で直線になります(初期値:0.4)。 026 * borderColor 【TAG】線の色を指定します。 027 * colorNo 【TAG】線の色(borderColor)をColorMapの色番号で指定します。 028 * borderWidth 【TAG】線の幅を指定します。 029 * backgroundColor 【TAG】データの背景色を指定します。 030 * pointStyle 【TAG】点のスタイル(circle,triangle,rect,rectRot,cross,crossRot,star,line,dash)を指定します。 // 6.8.5.0 (2018/01/09) 031 * pointRadius 【TAG】点の大きさを指定します。 // 6.8.5.0 (2018/01/09) 032 * showLine 【TAG】ラインを表示するかどうか[true/false]を指定します(初期値:null)。 // 6.8.5.0 (2018/01/09) 033 * optionAttributes 【TAG】その他オプションを指定します。 034 * caseKey 【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null) 035 * caseVal 【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null) 036 * caseNN 【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:判定しない) 037 * caseNull 【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:判定しない) 038 * caseIf 【TAG】指定の値が、true/TRUE文字列の場合は、このタグは使用されます(初期値:判定しない) 039 * > /> 040 * 041 * ●使用例 042 * <og:jsChart...> 043 * <og:jsChartData 044 * chartColumn ="CLM1" 045 * label ="ラベル" 046 * fill ="true" 047 * tension ="0" 048 * borderColor ="rbga(150,150,150,0.7)" 049 * borderWidth ="2" 050 * />> 051 * </og:jsChart> 052 * 053 * @og.group 画面表示 054 * 055 * @version 5.9.17.2 2017/02/08 056 * @author T.OTA 057 * @since JDK7.0 058 * 059 */ 060public class JsChartDataTag extends CommonTagSupport { 061 //* このプログラムのVERSION文字列を設定します。{@VALUE} */ 062 private static final String VERSION = "6.8.5.0 (2018/01/09)"; 063 private static final long serialVersionUID = 685020180109L; 064 065 private static final Set<String> TYPE_BOOLEAN = new ArraySet<>( "true", "false" ); 066 067 // 変数宣言 068 private String chartColumn ; 069 private String label ; 070 private String fill = "false"; 071 private String tension = "0.4"; 072 private String borderColor ; 073 private String borderWidth ; 074 private String backgroundColor ; 075 private String pointStyle ; // 6.8.5.0 (2018/01/09) 点のスタイル 076 private String pointRadius ; // 6.8.5.0 (2018/01/09) 点の大きさ 077 private String showLine ; // 6.8.5.0 (2018/01/09) ラインを表示するかどうか 078 private String optionAttributes ; 079 080 /** 081 * Taglibの終了タグが見つかった時に処理する doEndTag() を オーバーライドします。 082 * 083 * @og.rev 6.7.6.0 (2017/03/17) タグの使用を決める共通属性の追加 084 * @og.rev 6.7.7.0 (2017/03/31) backgroundColor が未設定の場合は、borderColor を使用します。 085 * @og.rev 6.8.5.0 (2018/01/09) pointStyle , pointRadius , showLine 属性の追加。 086 * 087 * @return 後続処理の指示 088 */ 089 @Override 090 public int doEndTag() { 091 debugPrint(); 092 if( !useTag() ) { return EVAL_PAGE ; } // 6.7.6.0 (2017/03/17) 093 094 final JsChartTag jsChartTag = (JsChartTag) findAncestorWithClass( this, JsChartTag.class ); 095 096 if( jsChartTag == null ) { 097 final String errMsg = "jsChart タグが見つかりませんでした。"; 098 throw new HybsSystemException( errMsg ); 099 } 100 101 // 6.7.7.0 (2017/03/31) 各種初期設定を行います。 102 if( borderColor == null || borderColor.isEmpty() ) { 103 final int size = jsChartTag.getJsChartDataSize(); // 登録順に色番号を設定します。 104 final String[] cols = ColorMap.getColorKeys(); 105 borderColor = cols[size % cols.length]; 106 } 107 if( backgroundColor == null || backgroundColor.isEmpty() ) { 108 backgroundColor = borderColor; 109 } 110 111 final JsChartData jsData = new JsChartData(); // 6.7.7.0 (2017/03/31) ローカル変数化 112 jsData.setChartColumn( chartColumn ); 113 jsData.setLabel( label ); 114 jsData.setFill( fill ); 115 jsData.setTension( tension ); 116 jsData.setBorderColor( borderColor ); 117 jsData.setBorderWidth( borderWidth ); 118 jsData.setBackgroundColor( backgroundColor ); 119 jsData.setPointStyle( pointStyle ); // 6.8.5.0 (2018/01/09) 120 jsData.setPointRadius( pointRadius ); // 6.8.5.0 (2018/01/09) 121 jsData.setShowLine( showLine ); // 6.8.5.0 (2018/01/09) 122 jsData.setOptionAttributes( optionAttributes ); 123 124 jsChartTag.addJsChartData( jsData ); 125 126 return EVAL_PAGE; 127 } 128 129 /** 130 * タグリブオブジェクトをリリースします。 131 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 132 * 133 * @og.rev 6.7.7.0 (2017/03/31) jsDataのローカル変数化。 134 * @og.rev 6.8.5.0 (2018/01/09) pointStyle , pointRadius , showLine 属性の追加。 135 */ 136 @Override 137 protected void release2() { 138 super.release2(); 139 chartColumn = null; 140 label = null; 141 fill = "false"; 142 tension = "0.4"; 143 borderColor = null; 144 borderWidth = null; 145 backgroundColor = null; 146 pointStyle = null; // 6.8.5.0 (2018/01/09) 点のスタイル 147 pointRadius = null; // 6.8.5.0 (2018/01/09) 点のスタイル 148 showLine = null; // 6.8.5.0 (2018/01/09) ラインを表示するかどうか 149 optionAttributes = null; 150 } 151 152 /** 153 * 【TAG】チャートのカラム名を指定します(必須)。 154 * 155 * @og.tag 156 * 157 * @param clm チャートのカラム名 158 */ 159 public void setChartColumn( final String clm ) { 160 chartColumn = nval( getRequestParameter( clm ),chartColumn ); 161 } 162 163 /** 164 * 【TAG】凡例の値を指定します。 165 * 166 * @og.tag 167 * 168 * @param lbl 凡例 169 */ 170 public void setLabel( final String lbl ) { 171 label = nval( getRequestParameter( lbl ),label ); 172 } 173 174 /** 175 * 【TAG】線下を塗りつぶすかどうか[true/false]を指定します(初期値:false)。 176 * 177 * @og.tag 178 * フィル(線より下の塗りつぶし) を設定します。 179 * 180 * @param fill 塗りつぶすかどうか [true/false] 181 */ 182 public void setFill( final String fill ) { 183 this.fill = nval( getRequestParameter( fill ) , this.fill ); 184 185 checkPara( this.fill, TYPE_BOOLEAN, "fill" ); 186 } 187 188 /** 189 * 【TAG】線の伸張を指定します。0で直線になります(初期値:0.4)。 190 * 191 * @og.tag 192 * 伸張 を設定します。 193 * 194 * @param tension 線の伸張 195 */ 196 public void setTension( final String tension ) { 197 this.tension = nval( getRequestParameter( tension ),this.tension ); 198 } 199 200 /** 201 * 【TAG】線の色を指定します。 202 * 203 * @og.tag 204 * borderColor = "BLUE" とすると、すべての線の色を指定できます。 205 * 配列で指定すると、データの順番に適用されます。 206 * 例:borderColor = "['#ffaaaa','#ffffaa','#aaffaa','#aaaaff','#aaaaff']" 207 * 208 * 色の代わりに、ColorMapの色番号を指定した場合でも、borderColor が優先されます。 209 * どちらも指定しない場合は、JsChartTagに登録した順番に色コードで指定されます。 210 * 211 * @param color 線の色 212 * @see #setColorNo(String) 213 */ 214 public void setBorderColor( final String color ) { 215 borderColor = nval( getRequestParameter( color ),borderColor ); 216 } 217 218 /** 219 * 【TAG】線の色(borderColor)をColorMapの色番号で指定します。 220 * 221 * @og.tag 222 * 色の代わりに、ColorMapの色番号を指定した場合でも、borderColor が優先されます。 223 * この引数は、色に変換後、borderColor に設定されます。 224 * 225 * @og.rev 6.7.7.0 (2017/03/31) ColorMapの色番号で指定 226 * 227 * @param colorNo 線の色の番号 228 * @see ColorMap#getColorKeys() 229 */ 230 public void setColorNo( final String colorNo ) { 231 if( borderColor == null ) { // borderColor が、未設定の場合のみ、色番号を利用する。 232 final String colNo = nval( getRequestParameter( colorNo ),null ); 233 if( colNo != null ) { 234 try { 235 final int no = Integer.parseInt( colNo ); 236 final String[] cols = ColorMap.getColorKeys(); 237 borderColor = cols[no % cols.length]; 238 } 239 catch( final NumberFormatException ex ) { 240 final String errMsg = "colorNo を数値に変換できません。colorNo=" + colNo ; 241 throw new HybsSystemException( errMsg,ex ); 242 } 243 } 244 } 245 } 246 247 /** 248 * 【TAG】線の幅を指定します。 249 * 250 * @og.tag 251 * 252 * @param width 線の幅 253 */ 254 public void setBorderWidth( final String width ) { 255 borderWidth = nval( getRequestParameter( width ),borderWidth ); 256 } 257 258 /** 259 * 【TAG】データの背景色を指定します。 260 * 261 * @og.tag 262 * backgroundColor = "BLUE" とすると、すべての背景色を指定できます。 263 * 配列で指定すると、データの順番に適用されます。 264 * 例:backgroundColor = "['#ffaaaa','#ffffaa','#aaffaa','#aaaaff','#aaaaff']" 265 * 266 * 背景色を指定しない場合、線の色(borderColor)を使用します。 267 * 268 * @param bgColor 背景色 269 * @see #setBorderColor(String) 270 */ 271 public void setBackgroundColor( final String bgColor ) { 272 backgroundColor = nval( getRequestParameter( bgColor ),backgroundColor ); 273 } 274 275 /** 276 * 【TAG】点のスタイルを指定します。 277 * 278 * @og.tag 279 * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。 280 * 点のスタイルは、circle,triangle,rect,rectRot,cross,crossRot,star,line,dash が、 281 * 282 * @og.rev 6.8.5.0 (2018/01/09) 新規追加 283 * 284 * @param ptStyle 点のスタイルを指定します。 285 */ 286 public void setPointStyle( final String ptStyle ) { 287 pointStyle = nval( getRequestParameter( ptStyle ),pointStyle ); 288 } 289 290 /** 291 * 【TAG】点の大きさを指定します。 292 * 293 * @og.tag 294 * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。 295 * 296 * @og.rev 6.8.5.0 (2018/01/09) 新規追加 297 * 298 * @param ptRadius 点の大きさを指定します。 299 */ 300 public void setPointRadius( final String ptRadius ) { 301 pointRadius = nval( getRequestParameter( ptRadius ),pointRadius ); 302 } 303 304 /** 305 * 【TAG】ラインを表示するかどうか[true/false]を指定します(初期値:null)。 306 * 307 * @og.tag 308 * jsChartTag で、usePointStyle = "true" をセットした場合に有効になります。 309 * 初期値(null)は、showLine 属性を設定しませんが、chartJS 自体の初期値が true 310 * なので、表示されます。 311 * 312 * @og.rev 6.8.5.0 (2018/01/09) 新規追加 313 * 314 * @param show ラインを表示するかどうか [true:表示する/false:表示しない] 315 */ 316 public void setShowLine( final String show ) { 317 showLine = nval( getRequestParameter( show ),showLine ); 318 } 319 320 /** 321 * 【TAG】その他オプションを指定します。 322 * 323 * @og.tag 324 * 325 * @param attri その他オプション 326 */ 327 public void setOptionAttributes( final String attri ) { 328 optionAttributes = nval( getRequestParameter( attri ),optionAttributes ); 329 } 330 331 /** 332 * パラメータチェック用メソッド。 333 * 334 * @param trg チェック対象 335 * @param set 設定可能なリスト 336 * @param trgStr チェック対象の文字列(エラー表示用) 337 */ 338 private void checkPara( final String trg, final Set<String> set, final String trgStr ) { 339 if( trg != null && trg.length() > 0 && !check( trg, set ) ) { 340 final StringBuilder errMsg = new StringBuilder( BUFFER_MIDDLE ) 341 .append( "指定の" ).append( trgStr ).append( "は指定できません。" ) 342 .append( CR ) 343 .append( trgStr ).append( "=[" ).append( trg ).append( ']' ) 344 .append( CR ); 345 for( final String lst : set ) { 346 errMsg.append( " | " ) 347 .append( lst ); 348 } 349 throw new HybsSystemException( errMsg.toString() ); 350 } 351 } 352 353 /** 354 * このオブジェクトの文字列表現を返します。 355 * 基本的にデバッグ目的に使用します。 356 * 357 * @return このクラスの文字列表現 358 */ 359 @Override 360 public String toString() { 361 return ToString.title( this.getClass().getName() ) 362 .println( "VERSIION" , VERSION ) 363 .println( "chartColumn" , chartColumn ) 364 .println( "label" , label ) 365 .println( "fill" , fill ) 366 .println( "tension" , tension ) 367 .println( "borderColor" , borderColor ) 368 .println( "borderWidth" , borderWidth ) 369 .println( "backgroundColor" , backgroundColor ) 370 .println( "optionAttributes" , optionAttributes ) 371 .fixForm().toString(); 372 } 373}