Skip to content

Commit

Permalink
Add ability to filter by dimension type
Browse files Browse the repository at this point in the history
  • Loading branch information
sagesmith-wf committed May 22, 2023
1 parent a3f95fc commit a3873bd
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 4 deletions.
9 changes: 9 additions & 0 deletions iXBRLViewerPlugin/viewer/src/html/inspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ <h3 data-i18n="inspector.filter">Filter</h3>
<option value="summationOrContributor" data-i18n="inspector.summationOrContributor">Summation or Contributor</option>
</select>

<div class="control-label" data-i18n="inspector.dimensions">
Dimension Type
</div>
<select id="search-filter-dimension-type">
<option value="*" data-i18n="inspector.noFilter">-</option>
<option value="explicit" data-i18n="inspector.explicitDimension">Explicit Dimensions</option>
<option value="typed" data-i18n="inspector.typedDimensions">Typed Dimensions</option>
</select>

<div class="control-label" data-i18n="inspector.factValue">
Fact Value
</div>
Expand Down
18 changes: 18 additions & 0 deletions iXBRLViewerPlugin/viewer/src/js/fact.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ export class Fact {
return dims;
}

hasExplicitDimension() {
for (const d in this.dimensions()) {
if (!this._report.getConcept(d).isTypedDimension()) {
return true;
}
}
return false;
}

hasTypedDimension() {
for (const d in this.dimensions()) {
if (this._report.getConcept(d).isTypedDimension()) {
return true;
}
}
return false;
}

isMonetaryValue() {
return this.unit()?.isMonetary() ?? false;
}
Expand Down
2 changes: 2 additions & 0 deletions iXBRLViewerPlugin/viewer/src/js/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Inspector.prototype.searchSpec = function () {
spec.conceptTypeFilter = $('#search-filter-concept-type').val();
spec.factValueFilter = $('#search-filter-fact-value').val();
spec.calculationsFilter = $('#search-filter-calculations').val();
spec.dimensionTypeFilter = $('#search-filter-dimension-type').val();
return spec;
}

Expand Down Expand Up @@ -349,6 +350,7 @@ Inspector.prototype.resetSearchFilters = function () {
$("#search-filter-concept-type").val("*");
$("#search-filter-fact-value").val("*");
$("#search-filter-calculations").val("*");
$("#search-filter-dimension-type").val("*")
$("#search-hidden-fact-filter").prop("checked", true);
$("#search-visible-fact-filter").prop("checked", true);
$("#search-filter-namespaces option:selected").prop("selected", false);
Expand Down
8 changes: 5 additions & 3 deletions iXBRLViewerPlugin/viewer/src/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ iXBRLReport.prototype.getIXNodeForItemId = function(id) {
}

iXBRLReport.prototype.facts = function() {
var allFacts = [];
$.each(this.data.facts, (id, f) => allFacts.push(this.getItemById(id)));
return allFacts;
const allItems = [];
for (const id in this.data.facts) {
allItems.push(this.getItemById(id));
}
return allItems;
}

iXBRLReport.prototype.filingDocuments = function() {
Expand Down
9 changes: 9 additions & 0 deletions iXBRLViewerPlugin/viewer/src/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export class ReportSearch {
);
}

dimensionTypeFilter(s, item) {
return (
s.dimensionTypeFilter === '*' ||
(s.dimensionTypeFilter === 'typed' && item.hasTypedDimension()) ||
(s.dimensionTypeFilter === 'explicit' && item.hasExplicitDimension())
)
}

factValueFilter(s, item) {
return (
s.factValueFilter === '*' ||
Expand Down Expand Up @@ -167,6 +175,7 @@ export class ReportSearch {
this.visibilityFilter,
this.periodFilter,
this.conceptTypeFilter,
this.dimensionTypeFilter,
this.factValueFilter,
this.calculationsFilter,
this.namespacesFilter,
Expand Down
89 changes: 88 additions & 1 deletion iXBRLViewerPlugin/viewer/src/js/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,35 @@ function getReportSearch(report) {
return reportSearch;
}

function createDimensionConcept(name, label, isExplicit= true) {
const c = createSimpleConcept(name, label);
c[name]["d"] = isExplicit ? "e": "t";
return c;
}
function createSimpleConcept(name, label=null) {
return {
[name]: {
"labels": {
"ns0": {
"std": {
"en-us": label ?? name.split(':')[1]
},
"doc": {
"en-us": label + " documentation"
}
}
}
};
}

function createDimensionalizedFact(id, concept, options=null, dimensions= {}) {
const fact = createSimpleFact(id, concept, options);
for (const d in dimensions) {
const m = dimensions[d];
fact[id]["a"][d] = m;
}
return fact;
}

function createSimpleFact(id, concept, options=null) {
options = options || {};
return {
Expand Down Expand Up @@ -93,6 +110,7 @@ function testSearchSpec(searchString='') {
spec.scalesFilter = [];
spec.periodFilter = '*';
spec.conceptTypeFilter = '*';
spec.dimensionTypeFilter = '*';
spec.factValueFilter = '*';
spec.calculationsFilter = "*";
return spec;
Expand Down Expand Up @@ -367,6 +385,75 @@ describe("Search units filter", () => {
});
});

describe("Search dimension type filter", () => {
const report = testReport(
{},
{
"concepts": {
...createSimpleConcept("test:Concept", "Concept"),
...createSimpleConcept("test:Concept2", "Concept2"),
...createSimpleConcept("test:Member", "Member"),
...createDimensionConcept("test:ExplicitDimension", "ExplicitDimension"),
...createDimensionConcept("test:ExplicitDimension2", "ExplicitDimension2"),
...createDimensionConcept("test:TypedDimension", "TypedDimension", false),
...createDimensionConcept("test:TypedDimension2", "TypedDimension2", false),
},
"facts": {
...createSimpleFact("simple", "test:Concept"),
...createSimpleFact("simple2", "test:Concept2"),
...createDimensionalizedFact("explicit", "test:Concept", null, {"test:ExplicitDimension": "test:Member"}),
...createDimensionalizedFact("explicit2", "test:Concept2", null,{"test:ExplicitDimension2": "test:Member"}),
...createDimensionalizedFact("typed", "test:Concept", null,{"test:TypedDimension": 1}),
...createDimensionalizedFact("typed2", "test:Concept2", null,{"test:TypedDimension2": 2}),
...createDimensionalizedFact("explicitAndTyped", "test:Concept", null,{"test:ExplicitDimension": "test:Member", "test:TypedDimension": 1}),
...createDimensionalizedFact("explicitAndTyped2", "test:Concept2", null,{"test:ExplicitDimension2": "test:Member", "test:TypedDimension2": 2}),
}
}
)
const reportSearch = getReportSearch(report);

test("Dimension 'all' filter works", () => {
const spec = testSearchSpec();
spec.dimensionTypeFilter = '*';
const results = reportSearch.search(spec).map(r => r.fact.id).sort();
expect(results).toEqual(['explicit', 'explicit2', 'explicitAndTyped', 'explicitAndTyped2', 'simple', 'simple2', 'typed', 'typed2']);
});

test("Dimension 'explicit' filter works", () => {
const spec = testSearchSpec();
spec.dimensionTypeFilter = 'explicit';
const results = reportSearch.search(spec).map(r => r.fact.id).sort();
expect(results).toEqual(['explicit', 'explicit2', 'explicitAndTyped', 'explicitAndTyped2']);
});

test("Dimension 'typed' filter works", () => {
const spec = testSearchSpec();
spec.dimensionTypeFilter = 'typed';
const results = reportSearch.search(spec).map(r => r.fact.id).sort();
expect(results).toEqual(['explicitAndTyped', 'explicitAndTyped2', 'typed', 'typed2']);
});

const emptyReport = testReport(
{'fact': {}},
{
"concepts": {
...createSimpleConcept("test:Concept", "Concept"),
},
"facts": {
...createSimpleFact("fact", "test:Fact"),
},
},
)
const emptyReportSearch = getReportSearch(emptyReport);

test("Dimension filter works on empty report", () => {
const spec = testSearchSpec();
spec.dimensionTypeFilter = 'explicit';
const results = emptyReportSearch.search(spec).map(r => r.fact.id).sort();
expect(results).toEqual([]);
});
});

describe("Search scales filter", () => {
const cashUnit = 'test:USD';
const period = '2018-01-01/2019-01-01';
Expand Down

0 comments on commit a3873bd

Please sign in to comment.