Skip to content

Commit

Permalink
Feature/hide options (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirchahal authored Aug 10, 2021
1 parent ceeb242 commit 4f51e8d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
55 changes: 55 additions & 0 deletions ckanext/querytool/fanstatic/javascript/vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,70 @@ $(document).ready(function(){
$(`#chart_field_x_label_hide_${chart_number}`).attr("disabled");
$(`#chart_field_sort_${chart_number}`).attr('disabled', 'true');
$(`#chart_field_x_ticks_format_${chart_number}`).attr('disabled', 'true');

} else {
$(`#chart_field_x_label_${chart_number}`).removeAttr("disabled");
$(`#chart_field_x_label_hide_${chart_number}`).removeAttr("disabled");
$(`#chart_field_sort_${chart_number}`).removeAttr('disabled');
$(`#chart_field_x_ticks_format_${chart_number}`).removeAttr('disabled');


}

//Hide bounds on Pie and Donut
if(selected =='bar' || selected=='hbar' || selected=='sbar' || selected=='shbar' || selected == 'line' || selected == 'spline' || selected == 'area' || selected == 'scatter') {
$(`#show_bounds_checkbox_${chart_number}`).removeClass("hidden");
if($(`#chart_field_show_bounds_${chart_number}`).is(":checked")) {
$(`#lower_bounds_${chart_number}`).removeClass("hidden");
$(`#upper_bounds_${chart_number}`).removeClass("hidden");
} else {
$(`#show_bounds_checkbox_${chart_number}`).removeClass("hidden");
$(`#lower_bounds_${chart_number}`).addClass("hidden");
$(`#upper_bounds_${chart_number}`).addClass("hidden");
}
} else {
$(`#show_bounds_checkbox_${chart_number}`).addClass("hidden");
$(`#lower_bounds_${chart_number}`).addClass("hidden");
$(`#upper_bounds_${chart_number}`).addClass("hidden");
}

//Hide Max number of text labels
if(selected=='line' || selected=='spline' || selected=='area' || selected=='scatter') {
$(`#max_labels__${chart_number}`).removeClass("hidden");
} else {
$(`#max_labels__${chart_number}`).addClass("hidden");
}


//Hide bar width
if(selected=='line' || selected=='spline' || selected=='area' || selected=='pie' || selected=='donut') {
$(`#chart_bar_width_${chart_number}`).addClass("hidden");
} else {
$(`#chart_bar_width_${chart_number}`).removeClass("hidden");
}

if(selected=='pie' || selected=='donut') {
$(`#donut_hole_${chart_number}`).removeClass("hidden");
} else {
$(`#donut_hole_${chart_number}`).addClass("hidden");
}

})


// Hide upper and lower bound
$('body').on('change','[id^=chart_field_show_bounds_]',function(){
var chart_number = this.id.split('_').slice(-1)[0];

if ($(this).is(":checked")) {
$(`#lower_bounds_${chart_number}`).removeClass("hidden");
$(`#upper_bounds_${chart_number}`).removeClass("hidden");
} else {
$(`#lower_bounds_${chart_number}`).addClass("hidden");
$(`#upper_bounds_${chart_number}`).addClass("hidden");
}
});

// Hide annotation on bars with categories
$('body').on('change','[id^=chart_field_graph_]',function(){
var selected = $(this).val();
Expand Down
36 changes: 28 additions & 8 deletions ckanext/querytool/templates/ajax_snippets/chart_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@
{% else %}
{% set x_tick_culling_max_option = false %}
{% endif %}
<div class="control-group">

{% if selected_chart_type in ['line', 'spline', 'area', 'scatter'] %}
{% set x_tick_culling_max_option_hide = '' %}
{% else %}
{% set x_tick_culling_max_option_hide = 'hidden' %}
{% endif %}
<div class="control-group {{x_tick_culling_max_option_hide}}" id="max_labels__{{ n }}">
<label class="control-label" for="chart_field_x_tick_culling_max_{{ n }}">{{ _('Max number of text labels') }}</label>
<div class="controls ">
<input id="chart_field_x_tick_culling_max_{{ n }}" type="number" min="0" step="1" name="chart_field_x_tick_culling_max_{{ n }}" placeholder="10" value="{{ x_tick_culling_max }}" {{'disabled' if x_tick_culling_max_option else ''}}>
Expand Down Expand Up @@ -490,11 +496,13 @@
{% endif %}
{% if selected_chart_type in ['line', 'bar', 'hbar', 'sbar', 'shbar'] %}
{% set donut_option = false %}
{% set hide_donut = 'hidden' %}
{% else %}
{% set donut_option = true %}
{% set hide_donut = '' %}
{% endif %}

<div class="control-group ">
<div class="control-group {{hide_donut}}" id="donut_hole_{{n}}">
<label class="control-label" for="chart_field_donut_hole_{{ n }}">{{ _('Donut hole') }}</label>
<div class="controls ">
<input id="chart_field_donut_hole_{{ n }}" type="text" name="chart_field_donut_hole_{{ n }}" value="{{ h.convert_bar_width(donut_hole, True)|default (4.0) }}" placeholder="{{ _('Donut hole, default 4.0') }}" {{'' if donut_option else 'disabled'}}>
Expand All @@ -514,10 +522,13 @@

{% if selected_chart_type in ['line', 'donut', 'pie'] %}
{% set bar_width_option = false %}
{% set hide_bar_width = 'hidden' %}
{% else %}
{% set bar_width_option = true %}
{% set hide_bar_width = '' %}
{% endif %}
<div class="control-group ">

<div class="control-group {{ hide_bar_width }}" id="chart_bar_width_{{n}}">
<label class="control-label" for="chart_field_bar_width_{{ n }}">{{ _('Bar width') }}</label>
<div class="controls ">
<input id="chart_field_bar_width_{{ n }}" type="text" name="chart_field_bar_width_{{ n }}" value="{{ h.convert_bar_width(bar_width, True)|default (5.0)}}" placeholder="{{ _('Width of bar, default 5.0') }}" {{'' if bar_width_option else 'disabled'}}>
Expand Down Expand Up @@ -572,17 +583,26 @@
{% set show_bounds = chart.show_bounds %}
{% endif %}

<div class="control-group ">

{% if selected_chart_type in ['bar', 'hbar', 'sbar', 'shbar', 'line', 'spline', 'area', 'scatter'] %}
{% set hide_bounds = '' %}
{% else %}
{% set hide_bounds = 'hidden' %}
{% endif %}
{# Upper bounds #}

<div class="control-group {{hide_bounds}}" id="show_bounds_checkbox_{{n}}">
<label class="control-label" for="chart_field_show_bounds_{{ n }}">{{ _('Show bounds') }}</label>
<div class="controls ">
<input id="chart_field_show_bounds_{{ n }}" type="checkbox" name="chart_field_show_bounds_{{ n }}" value="{{ show_bounds }}"{% if show_bounds=='false' %}{% else %}checked{% endif %}>
</div>
</div>

{# {% if selected_chart_type in ['bar', 'hbar', 'sbar', 'shbar', 'line', 'spline', 'area', 'scatter'] %} #}
{% if selected_chart_type in ['bar', 'hbar', 'sbar', 'shbar', 'line', 'spline', 'area', 'scatter'] and show_bounds=='false' %}
{% set hide_bounds = 'hidden' %}
{% endif %}

{# Upper bounds #}
<div class="control-group control-select">
<div class="control-group control-select {{hide_bounds}}" id="lower_bounds_{{n}}">
<label class="control-label" for="chart_field_lower_bounds_{{ n }}">{{ _('Lower bounds') }}</label>
<div class="controls ">
<select id="chart_field_lower_bounds_{{ n }}" name="chart_field_lower_bounds_{{ n }}">
Expand All @@ -595,7 +615,7 @@
</div>

{# Lower bounds #}
<div class="control-group control-select">
<div class="control-group control-select {{hide_bounds}}" id="upper_bounds_{{n}}">
<label class="control-label" for="chart_field_upper_bounds_{{ n }}">{{ _('Upper bounds') }}</label>
<div class="controls ">
<select id="chart_field_upper_bounds_{{ n }}" name="chart_field_upper_bounds_{{ n }}">
Expand Down

0 comments on commit 4f51e8d

Please sign in to comment.