1{* This is intended as an example of how to present Elasticsearch facets, known now as aggregations. 2 3Example wiki page "chart" contents: 4 5{CUSTOMSEARCH(wiki="charts tpl")} 6 {facet name="tracker_field_testUser"} 7 {facet name="deep_categories_under_1"} 8 {OUTPUT(template="templates/examples/search/facet_charts.tpl")} 9 {chart type="pie" title="Users" colors="orange:yellow:red:purple:grey:blue:green:pink:black" class="col-sm-4" size="300:600"} 10 {chart type="bar" title="Countries" colors="#888:#aaa:#ccc:#eee:#888:#aaa:#ccc:#eee:#888:#aaa:#ccc:#eee" class="col-sm-8" size="300:400"} 11 {OUTPUT} 12{CUSTOMSEARCH} 13 14Example wiki page "chart tpl" contents for the form: 15 16{literal}<div class="row"><div class="col-sm-4 offset-sm-4"><div class="input-group"> 17 {input _filter="content" type="text" class="form-control" placeholder="Search..."} 18 <div class="input-group-append"> 19 {input type="submit" value="Go" class="btn btn-primary"} 20 {input _filter="content" type="hidden" _field="tracker_status" id="tracker_status"} 21 {input _filter="content" type="hidden" _field="tracker_field_eventCategory" id="deep_categories_under_2"} 22 </div></div></div></div> 23{/literal} 24 25 *} 26 27{if not empty($facets)} 28 <pre style="display: none;" class="facets-data">{$facets|var_dump}</pre> 29 <pre style="display: none;" class="charts-data">{$chart|var_dump}</pre> 30 31 {if empty($container)} 32 {$containerClass = 'row'} 33 {else} 34 {$containerClass = $container.class} 35 {/if} 36 {$i = 0} 37 <div class="{$containerClass}"> 38 {foreach $facets as $facet} 39 {if count($facet.options) gt 0} 40 {if not empty($chart.title) and not empty($chart.type) and not empty($chart.colors)} 41 {$chart = [$chart]}{* if there is only one chart then it will not be in an array *} 42 {/if} 43 {if not isset($chart[$i].class)}{$chart[$i].class = 'col-sm-12'}{/if} 44 <div class="{$chart[$i].class|escape}"> 45 <label class="h3"> 46 {if not empty($chart[$i].title)} 47 {$chart[$i].title|escape} 48 {else} 49 {$facet.label|replace:' (Tree)':''|tr_if|escape} 50 {/if} 51 </label> 52 {$values = []} 53 {$labels = []} 54 {foreach from=$facet.options key=value item=label} 55 {if strpos($label, 'trackeritem:0 ') !== false} 56 {continue} 57 {/if} 58 {if preg_match('/(.*?)\s+\((\d+)\)/', $label|escape, $matches)} 59 {$labels[] = $matches[1]} 60 {$values[] = $matches[2]} 61 {/if} 62 {/foreach} 63 64 {if not isset($chart[$i].type)}{$chart[$i].type = 'bar'}{/if} 65 {if not isset($chart[$i].id)}{$chart[$i].id = 'chart_'|cat:$i}{/if} 66 {if not isset($chart[$i].size)} 67 {$chart[$i].size = ['','']} 68 {else} 69 {$chart[$i].size = ':'|explode:$chart[$i].size} 70 {/if} 71 72 {if not isset($chart[$i].colors)} 73 {$col = []} 74 {else} 75 {$col = ':'|explode:$chart[$i].colors} 76 {/if} 77 78 {if not empty($chart[$i].hcolors)} 79 {$hcol = ':'|explode:$chart[$i].hcolors} 80 {else} 81 {$hcol = $col} 82 {/if} 83 84 {$datasets = [ 85 'data' => $values, 86 'backgroundColor' => $col 87 ]} 88 {if $hcol}{$datasets.hoverBackgroundColor = $hcol}{/if} 89 {if $chart[$i].title}{$datasets.label = $chart[$i].title|escape}{/if} 90 91 {$data = ['data' => ['labels' => $labels,'datasets' => [$datasets]]]} 92 93 {$options = ['responsive' => true, 'maintainAspectRatio' => false]}{* some handy defaults (not working as expected) *} 94 {$data.options = $options} 95 96 <pre style="display: none;" class="data-options">{$data|var_dump}</pre> 97 98 {wikiplugin _name='chartjs' type=$chart[$i].type id=$chart[$i].id width=$chart[$i].size[0] height=$chart[$i].size[1] debug=1} 99 {$data|json_encode} 100 {/wikiplugin} 101 </div> 102 {/if} 103 {$i = $i + 1} 104 {/foreach} 105 </div> 106{/if} 107