Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display properly when there is no data #276

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/assets/javascripts/blacklight-range-limit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export default class BlacklightRangeLimit {

this.distributionElement = container.querySelector(".profile .distribution")

// If there is no distribution element on page, it means we don't have data,
// nothing to do.
if (! this.distributionElement) {
return;
}

const bounding = container.getBoundingClientRect();
if (bounding.width > 0 || bounding.height > 0) {
this.setup(); // visible, init now
Expand Down Expand Up @@ -120,7 +126,7 @@ export default class BlacklightRangeLimit {
this.rangeBuckets = Array.from(facetListDom.querySelectorAll("ul.facet-values li")).map( li => {
const from = this.parseNum(li.querySelector("span.from")?.getAttribute("data-blrl-begin") || li.querySelector("span.single")?.getAttribute("data-blrl-single"));
const to = this.parseNum(li.querySelector("span.to")?.getAttribute("data-blrl-end") || li.querySelector("span.single")?.getAttribute("data-blrl-single"));
const count = this.parseNum(li.querySelector("span.facet-count,span.count").innerText);
const count = this.parseNum(li.querySelector("span.facet-count,span.count").textContent);
const avg = (count / (to - from + 1));

return {
Expand Down Expand Up @@ -178,6 +184,7 @@ export default class BlacklightRangeLimit {
// Blacklight's config.full_width_layout = true
// See: https://github.com/projectblacklight/blacklight_range_limit/pull/269
this.chartCanvasElement.style.display = 'inline-block';
wrapperDiv.style.display = "block"; // un-hide it
wrapperDiv.prepend(this.chartCanvasElement);

return this.chartCanvasElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="profile mb-3">
<%# if was very hard to get chart.js to be succesfully resonsive, required this wrapper!
https://github.com/chartjs/Chart.js/issues/11005 %>
<div class="chart-wrapper" data-chart-wrapper="true" style="position: relative; width: 100%; aspect-ratio: <%= range_config[:chart_aspect_ratio] %>;">
<div class="chart-wrapper" data-chart-wrapper="true" style="display: none; position: relative; width: 100%; aspect-ratio: <%= range_config[:chart_aspect_ratio] %>;">
</div>

<% if (min = @facet_field.min) &&
Expand Down
Loading