in solr/webapp/solr/js/scripts/schema-browser.js [67:206]
success : function( response, text_status, xhr )
{
var additional_styles = [];
var field_data = response.fields[field];
if( !field_data || !( field_data.topTerms && field_data.histogram ) )
{
terminfo_element
.addClass( 'disabled' );
return false;
}
var get_width = function get_width()
{
return $( this ).width();
}
var topterms_holder_element = $( '.topterms-holder', data_element );
var histogram_holder_element = $( '.histogram-holder', data_element );
if( !field_data.topTerms )
{
topterms_holder_element
.hide();
}
else
{
topterms_holder_element
.show();
var topterms_table_element = $( 'ul', topterms_holder_element );
var topterms = field_data.topTerms;
var topterms_count = topterms.length;
var topterms_content = '';
var topterms_frq_last = null;
for( var i = 0; i < topterms_count; i += 2 )
{
if( topterms_frq_last !== topterms[i+1] )
{
if( topterms_frq_last )
{
topterms_content += '</ul></li>' + "\n";
}
topterms_frq_last = topterms[i+1];
topterms_content += '<li class="clearfix">'
+ '<p><span>' + app.format_number( topterms_frq_last ) + '</span></p>' + "\n"
+ '<ul>' + "\n";
}
var target = '#/' + current_core + '/query?q=' + field.esc() + ':' + encodeURIComponent( '"' + topterms[i] + '"' );
topterms_content += '<li><a href="' + target + '">' + topterms[i].esc() + '</a></li>' + "\n";
}
topterms_content += '</li>';
topterms_count = topterms_count / 2;
$( 'input', trigger_element )
.val( topterms_count );
topterms_table_element
.html( topterms_content );
var max_width = 10 + Math.max.apply( Math, $( 'p', topterms_table_element ).map( get_width ).get() );
additional_styles.push
(
topterms_table_element.selector + ' p { width: ' + max_width + 'px !important; }' + "\n" +
topterms_table_element.selector + ' ul { margin-left: ' + ( max_width + 5 ) + 'px !important; }'
);
topterms_count_element
.val( topterms_count );
$( 'p.head .max', topterms_holder_element )
.html( field_data.distinct );
$( 'p.head #query_link', topterms_holder_element )
.attr( 'href', '#/' + current_core + '/query?q=' + field.esc() + ':[* TO *]' );
$( 'ul li:even', topterms_table_element )
.addClass( 'odd' );
}
if( !field_data.histogram )
{
histogram_holder_element
.hide();
}
else
{
histogram_holder_element
.show();
var histogram_values = luke_array_to_hash( field_data.histogram );
var histogram_entries = [];
var histogram_max = null;
for( var key in histogram_values )
{
histogram_max = Math.max( histogram_max, histogram_values[key] );
}
for( var key in histogram_values )
{
histogram_entries.push
(
'<li>' + "\n" +
' <dl class="clearfix" style="width: ' + ( ( histogram_values[key] / histogram_max ) * 100 ) + '%;">' + "\n" +
' <dt><span>' + app.format_number( key ) + '</span></dt>' + "\n" +
' <dd><span>' + app.format_number( histogram_values[key] ) + '</span></dd>' + "\n" +
' </dl>' + "\n" +
'</li>'
);
}
$( 'ul', histogram_holder_element )
.html( histogram_entries.join( "\n" ) );
$( 'ul li:even', histogram_holder_element )
.addClass( 'odd' );
var max_width = 10 + Math.max.apply( Math, $( 'dt', histogram_holder_element ).map( get_width ).get() );
additional_styles.push
(
histogram_holder_element.selector + ' ul { margin-left: ' + max_width + 'px !important; }' + "\n" +
histogram_holder_element.selector + ' li dt { left: ' + ( max_width * -1 ) + 'px !important; width: ' + max_width + 'px !important; }'
);
}
if( additional_styles )
{
terminfo_element
.prepend( '<style type="text/css">' + additional_styles.join( "\n" ) + '</style>' );
}
},