Skip to content

Commit

Permalink
Merge pull request #138 from RhoInc/addCustomEvent
Browse files Browse the repository at this point in the history
Add custom event
  • Loading branch information
jwildfire authored Aug 19, 2019
2 parents d353494 + de337ed commit 3acc650
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions safetyOutlierExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,12 @@
updateNormalRangeControl.call(this);
}

function initCustomEvents() {
var chart = this;
chart.participantsSelected = [];
chart.events.participantsSelected = new CustomEvent('participantsSelected');
}

function onInit() {
// 1. Count number of unique participant IDs in data prior to data cleaning.
countParticipants.call(this);
Expand All @@ -874,6 +880,9 @@

// 5. Check controls.
checkControls.call(this);

// 6. Initialize custom events
initCustomEvents.call(this);
}

function identifyControls() {
Expand Down Expand Up @@ -1587,6 +1596,11 @@
});
if (this.multiples.chart) this.multiples.chart.destroy();
delete this.selected_id;

//Trigger participantsSelected event
this.participantsSelected = [];
this.events.participantsSelected.data = this.participantsSelected;
this.wrap.node().dispatchEvent(this.events.participantsSelected);
}

function addOverlayEventListener() {
Expand Down Expand Up @@ -2009,6 +2023,11 @@
context.selected_id = context.multiples.id;
highlightSelected.call(context);
smallMultiples.call(context);

//Trigger participantsSelected event
context.participantsSelected = [context.selected_id];
context.events.participantsSelected.data = context.participantsSelected;
context.wrap.node().dispatchEvent(context.events.participantsSelected);
});
}

Expand Down Expand Up @@ -2060,6 +2079,11 @@
highlightSelected.call(_this);
reorderMarks.call(_this);
smallMultiples.call(_this);

//Trigger participantsSelected event
_this.participantsSelected = [_this.selected_id];
_this.events.participantsSelected.data = _this.participantsSelected;
_this.wrap.node().dispatchEvent(_this.events.participantsSelected);
});
}

Expand All @@ -2085,6 +2109,11 @@
highlightSelected.call(_this);
reorderMarks.call(_this);
smallMultiples.call(_this);

//Trigger participantsSelected event
_this.participantsSelected = [_this.selected_id];
_this.events.participantsSelected.data = _this.participantsSelected;
_this.wrap.node().dispatchEvent(_this.events.participantsSelected);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/callbacks/onInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cleanData from './onInit/cleanData';
import addVariables from './onInit/addVariables';
import defineSets from './onInit/defineSets';
import checkControls from './onInit/checkControls';
import initCustomEvents from './onInit/initCustomEvents';

export default function onInit() {
// 1. Count number of unique participant IDs in data prior to data cleaning.
Expand All @@ -19,4 +20,7 @@ export default function onInit() {

// 5. Check controls.
checkControls.call(this);

// 6. Initialize custom events
initCustomEvents.call(this);
}
5 changes: 5 additions & 0 deletions src/callbacks/onInit/initCustomEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function initCustomEvents() {
var chart = this;
chart.participantsSelected = [];
chart.events.participantsSelected = new CustomEvent('participantsSelected');
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export default function addLineEventListeners() {
highlightSelected.call(this);
reorderMarks.call(this);
smallMultiples.call(this);

//Trigger participantsSelected event
this.participantsSelected = [this.selected_id];
this.events.participantsSelected.data = this.participantsSelected;
this.wrap.node().dispatchEvent(this.events.participantsSelected);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export default function addPointEventListeners() {
highlightSelected.call(this);
reorderMarks.call(this);
smallMultiples.call(this);

//Trigger participantsSelected event
this.participantsSelected = [this.selected_id];
this.events.participantsSelected.data = this.participantsSelected;
this.wrap.node().dispatchEvent(this.events.participantsSelected);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ export default function clearSelected() {
});
if (this.multiples.chart) this.multiples.chart.destroy();
delete this.selected_id;

//Trigger participantsSelected event
this.participantsSelected = [];
this.events.participantsSelected.data = this.participantsSelected;
this.wrap.node().dispatchEvent(this.events.participantsSelected);
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ export default function updateParticipantDropdown() {
context.selected_id = context.multiples.id;
highlightSelected.call(context);
smallMultiples.call(context);

//Trigger participantsSelected event
context.participantsSelected = [context.selected_id];
context.events.participantsSelected.data = context.participantsSelected;
context.wrap.node().dispatchEvent(context.events.participantsSelected);
});
}
14 changes: 14 additions & 0 deletions src/util/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,17 @@ Math.log10 =
function(x) {
return Math.log(x) * Math.LOG10E;
};


(function() {
if (typeof window.CustomEvent === 'function') return false;

function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: null };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}

window.CustomEvent = CustomEvent;
})();
6 changes: 6 additions & 0 deletions test-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ d3.csv(
settings
);
instance.init(data);

//quick test of participantSelected event
instance.wrap.on("participantsSelected",function(){
console.log("Participant Selected Event:")
console.log(d3.event.data)
})
}
);

0 comments on commit 3acc650

Please sign in to comment.