Skip to content

Commit

Permalink
Merge pull request #16 from paulwarren-wk/viewer-references
Browse files Browse the repository at this point in the history
Viewer references
  • Loading branch information
rmconsole5-wk authored Apr 18, 2019
2 parents 6541ed3 + 732b68e commit 1b16ce9
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 24 deletions.
14 changes: 9 additions & 5 deletions iXBRLViewerPlugin/iXBRLViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ def addConcept(self, concept):
conceptData["labels"].setdefault(self.roleMap.getPrefix(l.role),{})[l.xmlLang.lower()] = l.text;
self.addLanguage(l.xmlLang.lower());

refString = " ".join(_refPart.stringValue.strip()
for _refRel in concept.modelXbrl.relationshipSet(XbrlConst.conceptReference).fromModelObject(concept)
for _refPart in _refRel.toModelObject.iterchildren())
refData = []
for _refRel in concept.modelXbrl.relationshipSet(XbrlConst.conceptReference).fromModelObject(concept):
ref = []
for _refPart in _refRel.toModelObject.iterchildren():
ref.append([_refPart.localName, _refPart.stringValue.strip()])
refData.append(ref)

conceptData['r'] = refString
if len(refData) > 0:
conceptData['r'] = refData

self.taxonomyData["concepts"][conceptName] = conceptData

Expand Down Expand Up @@ -260,7 +264,7 @@ def createViewer(self, scriptUrl="js/dist/ixbrlviewer.js"):

def saveViewer(self, outFile, xmlDocument):
"""
Save the ixbl viewer
Save the iXBRL viewer
"""
with open(outFile, "wb") as fout:
# Using "xml" permits self-closing tags which confuses an HTML DOM
Expand Down
5 changes: 5 additions & 0 deletions iXBRLViewerPlugin/viewer/src/html/inspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ <h3 class="search-header collapsible-header">Search</h3>
</div>
</div>
</div>
<div class="collapsible-section">
<h3 class="collapsible-header">References</h3>
<div class="collapsible-body references">
</div>
</div>
<div class="collapsible-section">
<h3 class="collapsible-header">Calculations</h3>
<div class="collapsible-body calculations">
Expand Down
8 changes: 4 additions & 4 deletions iXBRLViewerPlugin/viewer/src/js/accordian.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import $ from 'jquery'

export function Accordian() {
this._html = $('<div class="accordian">');
this._contents = $('<div class="accordian">');
}

Accordian.prototype.addCard = function(title, body, selected) {
Expand All @@ -34,13 +34,13 @@ Accordian.prototype.addCard = function(title, body, selected) {
})
)
.append($('<div class="body">').append(body))
.appendTo(this._html);
.appendTo(this._contents);

if (selected) {
card.addClass("active");
}
}

Accordian.prototype.html = function () {
return this._html;
Accordian.prototype.contents = function () {
return this._contents;
}
30 changes: 28 additions & 2 deletions iXBRLViewerPlugin/viewer/src/js/concept.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,36 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import $ from 'jquery'

export function Concept(report, name) {
this._c = report.data.concepts[name]
}

Concept.prototype.references = function() {
return this._c.r;
/*
* Return a space separated list of reference values, or the empty string if
* the concept has none.
*/
Concept.prototype.referenceValuesAsString = function() {
if (!this._c.r) {
return "";
}
else {
return $.map(this._c.r, function (r,j) {
return $.map(r, function (p,i) { return p[1] }).join(" ")
}).join(" ");
}
}

Concept.prototype.references = function () {
if (!this._c.r) {
return [];
}
else {
return $.map(this._c.r, function (r, i) {
return [ $.map(r, function (p, j) {
return { "part": p[0], "value": p[1] };
})];
});
}
}
61 changes: 61 additions & 0 deletions iXBRLViewerPlugin/viewer/src/js/concept.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2019 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { iXBRLReport } from "./report.js";

var testReportData = {
"prefixes": {
"eg": "http://www.example.com",
"iso4217": "http://www.xbrl.org/2003/iso4217",
"e": "http://example.com/entity",
},
"concepts": {
"eg:Concept1": {
"labels": {
"std": {
"en": "English label"
}
}
},
"eg:Concept2": {
"labels": {
"std": {
"en": "English label for concept two"
}
}
},
"eg:Concept3": {
"labels": {
"std": {
"en": "English label for concept three"
}
},
"r": [ [ [ "Part1", "Value1" ], ["Part2", "Value2"] ] ]
}
},
"facts": {
}
};

describe("Concept references", () => {
var r = new iXBRLReport(testReportData);
test("Absent reference", () => {
var c1 = r.getConcept("eg:Concept1");
expect(c1.referenceValuesAsString()).toEqual("");
});
test("Simple reference", () => {
var c1 = r.getConcept("eg:Concept3");
expect(c1.referenceValuesAsString()).toEqual("Value1 Value2");
});
});
29 changes: 25 additions & 4 deletions iXBRLViewerPlugin/viewer/src/js/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,34 @@ Inspector.prototype.search = function (s) {
.text(r.fact.getLabel("std")) // + " (" + r.score + ")" );
.appendTo(row);
}

});
viewer.highlightRelatedFacts($.map(results, function (r) { return r.fact } ));

}

Inspector.prototype.updateCalculation = function (fact, elr) {
$('.calculations .tree').html(this._calculationHTML(fact, elr));
$('.calculations .tree').empty().append(this._calculationHTML(fact, elr));
}

Inspector.prototype._referencesHTML = function (fact) {
var c = fact.concept();
var a = new Accordian();
$.each(fact.concept().references(), function (i,r) {
var title = $("<span>").text(r[0].value);
var body = $('<table class="fact-properties"><tbody>')
var tbody = body.find("tbody");
$.each(r, function (j,p) {
var row = $("<tr>")
.append($("<th>").text(p.part))
.append($("<td>").text(p.value))
.appendTo(tbody);
if (p.part == 'URI') {
row.addClass("uri");
row.find("td").wrapInner($("<a>").attr("href",p.value));
}
});
a.addCard(title, body, i == 0);
});
return a.contents();
}

Inspector.prototype._calculationHTML = function (fact, elr) {
Expand Down Expand Up @@ -179,7 +199,7 @@ Inspector.prototype._calculationHTML = function (fact, elr) {
a.addCard($("<span>").text(label), calcBody, e == elr);

});
return a.html();
return a.contents();
}

Inspector.prototype.viewerMouseEnter = function (id) {
Expand Down Expand Up @@ -299,6 +319,7 @@ Inspector.prototype.update = function () {
);
this._updateEntityIdentifier(fact);
this.updateCalculation(fact);
$('div.references').empty().append(this._referencesHTML(fact));
this._updateValue(fact);
$('tr.accuracy td').text(fact.readableAccuracy());
$('#dimensions').empty();
Expand Down
2 changes: 1 addition & 1 deletion iXBRLViewerPlugin/viewer/src/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ReportSearch.prototype.buildSearchIndex = function () {
l += " " + this._report.getLabel(dims[d],"std");
}
doc.label = l;
doc.ref = f.concept().references();
doc.ref = f.concept().referenceValuesAsString();
docs.push(doc);
}
this._searchIndex = lunr(function () {
Expand Down
18 changes: 10 additions & 8 deletions iXBRLViewerPlugin/viewer/src/less/inspector.less
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
}
}
table.fact-properties {
table-layout: fixed;
width: 100%;
th {
width: 100px;
Expand All @@ -246,6 +247,13 @@
cursor: pointer;
}
}
td {
overflow: hidden;
text-overflow: ellipsis;
}
tr.uri > td {
white-space: nowrap;
}
}
.duplicates {
text-align: center;
Expand Down Expand Up @@ -387,7 +395,8 @@

.collapsible-section {
.collapsible-body {
padding-left: 9px;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.collapsible-header {
position: relative;
Expand Down Expand Up @@ -517,13 +526,6 @@
}

.calculations {
margin-left: 20px;
margin-right: 20px;
select {
padding: 3px;
width: 100%;
margin: 5px 0;
}
.item {
padding: 5px 0;
position: relative;
Expand Down

0 comments on commit 1b16ce9

Please sign in to comment.