Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
fix: Namespaces properties added by CRViz and removes them before exp…
Browse files Browse the repository at this point in the history
…ort. fixes #238
  • Loading branch information
rashley-iqt committed Feb 14, 2019
1 parent 6a19d4e commit 6385fcf
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
25 changes: 14 additions & 11 deletions src/domain/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ const getHashFields = (allFields, ignoredFields) => {
const addHashKey = (keys, obj) => {
//console.log("addHashKey keys: %o", keys);
const hashKey = keys.reduce( (h, k) => h + path(k.path, obj) + ":", "");
obj["HASH_KEY"] = hashKey;
obj.CRVIZ["_HASH_KEY"] = hashKey;
}

const addHashWithoutIgnored = (fields, obj) => {
const hash = fields.reduce( (h, f) => h + path(f.path, obj) + "|", "");
obj["HASH_WITHOUT_IGNORED"] = hash;
obj.CRVIZ["_HASH_WITHOUT_IGNORED"] = hash;
}

const applyHashes = (dataset, configuration) => {
dataset.forEach((i) => {
if(!('CRVIZ' in i)){
i['CRVIZ'] = {};
}
addHashKey(configuration.keyFields.length > 0 ? configuration.keyFields : configuration.hashFields, i);
addHashWithoutIgnored(configuration.hashFields, i);
});
Expand Down Expand Up @@ -377,23 +380,23 @@ const selectDatasetIntersection = (state, startOwner, endOwner) => {
ds = end;
} else if(start.length > 0 && end.length > 0) {
start.forEach((s) => {
const idx = end.findIndex(e => e.HASH_KEY === s.HASH_KEY);
const idx = end.findIndex(e => e.CRVIZ._HASH_KEY === s.CRVIZ._HASH_KEY);
if(idx === -1){
s.isRemoved = true;
s.CRVIZ._isRemoved = true;
} else {
s.isRemoved = false;
s.CRVIZ._isRemoved = false;
}
s.isChanged = false;
s.isAdded = false;
s.CRVIZ._isChanged = false;
s.CRVIZ._isAdded = false;
ds.push(s);
});
end.forEach((e) => {
const idx = ds.findIndex(i => i.HASH_KEY === e.HASH_KEY);
const idx = ds.findIndex(i => i.CRVIZ._HASH_KEY === e.CRVIZ._HASH_KEY);
if(idx === -1){
e.isAdded = true;
e.CRVIZ._isAdded = true;
ds.push(e);
} else if(ds[idx].HASH_WITHOUT_IGNORED !== e.HASH_WITHOUT_IGNORED){
ds[idx].isChanged = true;
} else if(ds[idx].CRVIZ._HASH_WITHOUT_IGNORED !== e.CRVIZ._HASH_WITHOUT_IGNORED){
ds[idx].CRVIZ._isChanged = true;
}
})
}
Expand Down
10 changes: 5 additions & 5 deletions src/epics/diff-dataset-epic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ const generateDiff = (payload) => {
changed:[],
removed:[]
};
diffs.added = diffs.added.concat(endDs.filter(ei => startDs.findIndex(si => si["HASH_KEY"] === ei["HASH_KEY"]) === -1).map(i => i["HASH_KEY"]));
diffs.removed = diffs.removed.concat(startDs.filter(si => endDs.findIndex(ei => ei["HASH_KEY"] === si["HASH_KEY"]) === -1).map(i => i["HASH_KEY"]));
diffs.added = diffs.added.concat(endDs.filter(ei => startDs.findIndex(si => si.CRVIZ["_HASH_KEY"] === ei.CRVIZ["_HASH_KEY"]) === -1).map(i => i.CRVIZ["_HASH_KEY"]));
diffs.removed = diffs.removed.concat(startDs.filter(si => endDs.findIndex(ei => ei.CRVIZ["_HASH_KEY"] === si.CRVIZ["_HASH_KEY"]) === -1).map(i => i.CRVIZ["_HASH_KEY"]));

diffs.changed = diffs.changed.concat(
endDs.filter(
ei => startDs.findIndex(
si => si["HASH_KEY"] === ei["HASH_KEY"] &&
si["HASH_WITHOUT_IGNORED"] !== ei["HASH_WITHOUT_IGNORED"]
si => si.CRVIZ["_HASH_KEY"] === ei.CRVIZ["_HASH_KEY"] &&
si.CRVIZ["_HASH_WITHOUT_IGNORED"] !== ei.CRVIZ["_HASH_WITHOUT_IGNORED"]
) !== -1
).map(i => i["HASH_KEY"])
).map(i => i.CRVIZ["_HASH_KEY"])
);

//console.log("diffs to return: %o", diffs);
Expand Down
4 changes: 2 additions & 2 deletions src/epics/search-dataset-epic.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const performSearch = (data) => {
}
}

data.dataset.forEach((el) => { el.isSearchResult = false; });
data.dataset.forEach((el) => { el.CRVIZ._isSearchResult = false; });
results.forEach((r) => {
if(data.dataset[r.ref]){
data.dataset[r.ref].isSearchResult = true;
data.dataset[r.ref].CRVIZ._isSearchResult = true;
data.results.push(data.dataset[r.ref]);
}
});
Expand Down
16 changes: 15 additions & 1 deletion src/features/dataset-controls/export.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import clonedeep from "lodash.clonedeep";

const getDataToExport = (datasets, keyFields, ignoredFields, controls) => {
let exportData = {};

if(datasets)
exportData["datasets"] = datasets;
exportData["datasets"] = sanitizeForExport(datasets);

if(keyFields)
exportData["keyFields"] = keyFields;
Expand All @@ -16,5 +18,17 @@ const getDataToExport = (datasets, keyFields, ignoredFields, controls) => {
return exportData;
}

const sanitizeForExport = (datasets) =>{
let result = clonedeep(datasets);
Object.keys(result).forEach((key) => {
result[key].dataset.forEach((item) => {
delete item.CRVIZ;
});
});
console.log("dataset without CRVIZ: %o", result);
console.log("dataset with CRVIZ: %o", datasets);
return result;
}

export default getDataToExport;
export { getDataToExport };
14 changes: 7 additions & 7 deletions src/features/visualization/d3-viz/append-circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const appendCircles = ({ nodeRoot, labelRoot, packedData, showNodes, hasSearch }
.attr('data-key', datumKey)
.classed(className("rootNode"), (d) => d.depth === 0)
.classed(className("groupingNode"), (d) => d.depth > 0 && d.height > 0)
.classed(className("containsSearchResult"), (d) => hasSearch && d.data.searchResultCount > 0 && d.depth > 0 && d.height > 0)
.classed(className("containsNoSearchResult"), (d) => hasSearch && d.data.searchResultCount === 0 && d.depth > 0 && d.height > 0)
.classed(className("searchResult"), (d) => hasSearch && d.data.isSearchResult && d.depth > 0 && d.height === 0)
.classed(className("isChanged"), (d) => d.data.isChanged && d.depth > 0 && d.height === 0)
.classed(className("isAdded"), (d) => d.data.isAdded && d.depth > 0 && d.height === 0)
.classed(className("isRemoved"), (d) => d.data.isRemoved && d.depth > 0 && d.height === 0)
.classed(className("searchExcluded"), (d) => hasSearch && !d.data.isSearchResult && d.depth > 0 && d.height === 0)
.classed(className("containsSearchResult"), (d) => hasSearch && d.data.CRVIZ._searchResultCount > 0 && d.depth > 0 && d.height > 0)
.classed(className("containsNoSearchResult"), (d) => hasSearch && d.data.CRVIZ._searchResultCount === 0 && d.depth > 0 && d.height > 0)
.classed(className("searchResult"), (d) => hasSearch && d.data.CRVIZ._isSearchResult && d.depth > 0 && d.height === 0)
.classed(className("isChanged"), (d) => d.data.CRVIZ._isChanged && d.depth > 0 && d.height === 0)
.classed(className("isAdded"), (d) => d.data.CRVIZ._isAdded && d.depth > 0 && d.height === 0)
.classed(className("isRemoved"), (d) => d.data.CRVIZ._isRemoved && d.depth > 0 && d.height === 0)
.classed(className("searchExcluded"), (d) => hasSearch && !d.data.CRVIZ._isSearchResult && d.depth > 0 && d.height === 0)
.classed(className("leafNode"), (d) => d.height === 0)
.attr("transform", (d) => `translate(${[d.x, d.y].join(",")})`)
.attr("display", (d) => !showNodes && d.height === 0 ? 'none' : null)
Expand Down
4 changes: 2 additions & 2 deletions src/features/visualization/d3-viz/setup-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const showTooltip = (event, fields, offsetTop, offsetLeft, tooltip) => {
const content = (datum, fields) => {
if (datum.depth > 0 && datum.height > 0) {
let cont = `${ datum.data.fieldValue } (${datum.value})`;
if(datum.data.searchResultCount > 0){
cont += `<br/><span>${datum.data.searchResultCount} search results</span>`
if(datum.data.CRVIZ._searchResultCount > 0){
cont += `<br/><span>${datum.data.CRVIZ._searchResultCount} search results</span>`
}
return cont;
} else if (datum.height === 0) {
Expand Down
9 changes: 6 additions & 3 deletions src/features/visualization/d3-viz/to-hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const countSearchResults = (children) => {
var result = 0;

for(var c in children){
result += (children[c].searchResultCount || 0) + (children[c].isSearchResult || 0) +
if(!('CRVIZ' in children[c])){
children[c]['CRVIZ'] = {};
}
result += (children[c].CRVIZ._searchResultCount || 0) + (children[c].CRVIZ._isSearchResult || 0) +
(
!isNil(children[c].values)
? countSearchResults(children[c].values) : 0
Expand All @@ -59,7 +62,7 @@ const entriesToHierarchy = (fieldValue, field, hierarchyConfig, entries) => {
fieldValue,
field,
children: chain(getLeaves, entries),
searchResultCount: countSearchResults(entries)
CRVIZ:{ _SEARCH_RESULT_COUNT: countSearchResults(entries) }
}
}

Expand All @@ -78,7 +81,7 @@ const entriesToHierarchy = (fieldValue, field, hierarchyConfig, entries) => {
return entry;
}
}, entries),
searchResultCount: countSearchResults(entries)
CRVIZ:{ _SEARCH_RESULT_COUNT: countSearchResults(entries) }
};
};

Expand Down

0 comments on commit 6385fcf

Please sign in to comment.