diff --git a/index.js b/index.js index dc38b6b..295c87e 100644 --- a/index.js +++ b/index.js @@ -1180,6 +1180,7 @@ d.value.inVicinityOfFocus = d.value.distanceFromFocus < _this.settings.orbitRadius / 16; // Update coordinates once node reaches vicinity of destination or when time since // previous state crosses some threshold. + d.value.state.transitTime++; d.value.transitTime++; var transitThreshold = 500 / Math.ceil(Math.sqrt(_this.settings.speeds[_this.settings.speed])); @@ -4577,7 +4578,10 @@ if (!has.duration && has.start_timepoint && has.end_timepoint) { d.duration = d.end_timepoint - d.start_timepoint + 1; - } + } // Track transit time of node during each state. + + + d.transitTime = 0; }); // Define sequence group.sort(function (a, b) { diff --git a/src/data/mutateData/addVariables.js b/src/data/mutateData/addVariables.js index 52400b0..7e21b5c 100644 --- a/src/data/mutateData/addVariables.js +++ b/src/data/mutateData/addVariables.js @@ -29,6 +29,9 @@ export default function addVariables(has) { if (!has.duration && has.start_timepoint && has.end_timepoint) { d.duration = d.end_timepoint - d.start_timepoint + 1; } + + // Track transit time of node during each state. + d.transitTime = 0; }); // Define sequence diff --git a/src/data/nestData/getAestheticValues.js b/src/data/nestData/getAestheticValues.js deleted file mode 100644 index 20128be..0000000 --- a/src/data/nestData/getAestheticValues.js +++ /dev/null @@ -1,28 +0,0 @@ -import countStateChanges from './getAestheticValues/countStateChanges'; - -export default function getAestheticValues(group, state) { - const colorValue = - this.settings.colorBy.type === 'frequency' - ? countStateChanges.call(this, group) - : this.settings.colorBy.variable !== null - ? state[this.settings.colorBy.variable] - : null; - const sizeValue = - this.settings.sizeBy.type === 'frequency' - ? countStateChanges.call(this, group) - : this.settings.sizeBy.variable !== null - ? state[this.settings.sizeBy.variable] - : null; - const shapeValue = - this.settings.shapeBy.type === 'frequency' - ? countStateChanges.call(this, group) - : this.settings.shapeBy.variable !== null - ? state[this.settings.shapeBy.variable] - : null; - - return { - colorValue, - sizeValue, - shapeValue, - }; -} diff --git a/src/data/nestData/getAestheticValues/countStateChanges.js b/src/data/nestData/getAestheticValues/countStateChanges.js deleted file mode 100644 index dcd5734..0000000 --- a/src/data/nestData/getAestheticValues/countStateChanges.js +++ /dev/null @@ -1,14 +0,0 @@ -export default function countStateChanges(group) { - const nStateChanges = group - .filter((d) => d.start_timepoint <= this.settings.timepoint) - .sort((a, b) => a.start_timepoint - b.start_timepoint) - .filter((d, i, data) => { - const eventPrevious = data[i - 1] ? data[i - 1].event : null; - return ( - !this.settings.eventChangeCount.includes(eventPrevious) && - this.settings.eventChangeCount.includes(d.event) - ); - }).length; - - return nStateChanges; -} diff --git a/src/data/nestData/getAesthetics.js b/src/data/nestData/getAesthetics.js deleted file mode 100644 index 5806343..0000000 --- a/src/data/nestData/getAesthetics.js +++ /dev/null @@ -1,15 +0,0 @@ -import getColor from './getAesthetics/getColor'; -import getSize from './getAesthetics/getSize'; -import getShape from './getAesthetics/getShape'; - -export default function getAesthetics(aestheticValues, colorScale) { - const color = getColor.call(this, this.scales.color, aestheticValues.colorValue); - const size = getSize.call(this, this.scales.size, aestheticValues.sizeValue); - const shape = getShape.call(this, this.scales.shape, aestheticValues.shapeValue); - - return { - ...color, // color, fill, stroke - size, - shape, - }; -} diff --git a/src/data/nestData/getAesthetics/getColor.js b/src/data/nestData/getAesthetics/getColor.js deleted file mode 100644 index 48945fe..0000000 --- a/src/data/nestData/getAesthetics/getColor.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function getColor(scale, value) { - const color = scale !== undefined ? scale(value) : 'rgb(170,170,170)'; - const fill = color.replace('rgb', 'rgba').replace(')', ', 0.5)'); - const stroke = color.replace('rgb', 'rgba').replace(')', ', 1)'); - - return { color, fill, stroke }; -} diff --git a/src/data/nestData/getAesthetics/getShape.js b/src/data/nestData/getAesthetics/getShape.js deleted file mode 100644 index dec0f6f..0000000 --- a/src/data/nestData/getAesthetics/getShape.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function getShape(scale, value) { - const shape = scale !== undefined ? scale(value) : this.settings.shape; - - return shape; -} diff --git a/src/data/nestData/getAesthetics/getSize.js b/src/data/nestData/getAesthetics/getSize.js deleted file mode 100644 index 97a75c3..0000000 --- a/src/data/nestData/getAesthetics/getSize.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function getSize(scale, value) { - const size = scale !== undefined ? scale(value) : this.settings.minRadius; - - return size; -} diff --git a/src/data/nestData/getColorScale.js b/src/data/nestData/getColorScale.js deleted file mode 100644 index 6838f4e..0000000 --- a/src/data/nestData/getColorScale.js +++ /dev/null @@ -1,8 +0,0 @@ -export default function getColorScale(colorValue) { - const colorScale = - this.settings.stratify && this.settings.sizeBy.type === 'frequency' - ? this.metadata.strata.find((stratum) => stratum.key === colorValue).colorScale - : this.scales.color; - - return colorScale; -} diff --git a/src/data/nestData/getCoordinates.js b/src/data/nestData/getCoordinates.js deleted file mode 100644 index 9df966e..0000000 --- a/src/data/nestData/getCoordinates.js +++ /dev/null @@ -1,11 +0,0 @@ -export default function getCoordinates(state, colorValue) { - const destination = - this.settings.stratify && this.settings.colorBy.stratify - ? this.metadata.event - .find((event) => event.key === state.event) - .foci.find((focus) => focus.key === colorValue) - : this.metadata.event.find((event) => event.key === state.event); - const coordinates = { x: destination.x, y: destination.y }; - - return coordinates; -} diff --git a/src/data/nestData/getState.js b/src/data/nestData/getState.js deleted file mode 100644 index df78edc..0000000 --- a/src/data/nestData/getState.js +++ /dev/null @@ -1,32 +0,0 @@ -export default function getState(group, index) { - const minTimepoint = d3.min(group, (d) => d.start_timepoint); - const maxTimepoint = d3.max(group, (d) => d.end_timepoint); - - let state = group.find( - (d, i) => - d.start_timepoint <= this.settings.timepoint && - this.settings.timepoint <= d.end_timepoint - ); // first (and hopefully only) state that overlaps the current timepoint - - switch (true) { - case index !== undefined: - state = group[index]; - break; - case this.settings.timepoint >= maxTimepoint: - state = group[group.length - 1]; - break; - case this.settings.timepoint < minTimepoint: - state = group[0]; - break; - case state === undefined: - state = group - .slice() - .sort((a, b) => b.start_timepoint - a.start_timepoint) - .find((d) => d.start_timepoint <= this.settings.timepoint); - break; - default: - break; - } - - return state; -} diff --git a/src/data/structure.js b/src/data/structure.js index d9109af..f353db0 100644 --- a/src/data/structure.js +++ b/src/data/structure.js @@ -1,8 +1,8 @@ -import getState from './nestData/getState'; -import getAestheticValues from './nestData/getAestheticValues'; -import getCoordinates from './nestData/getCoordinates'; -import getColorScale from './nestData/getColorScale'; -import getAesthetics from './nestData/getAesthetics'; +import getState from './structure/getState'; +import getAestheticValues from './structure/getAestheticValues'; +import getCoordinates from './structure/getCoordinates'; +import getColorScale from './structure/getColorScale'; +import getAesthetics from './structure/getAesthetics'; export default function structure(data) { const grouped = d3 @@ -25,6 +25,8 @@ export default function structure(data) { const colorScale = getColorScale.call(this, aestheticValues.colorValue); const aesthetics = getAesthetics.call(this, aestheticValues, colorScale); + const queue = [state]; + return { index: this.metadata.id.findIndex((id) => id.key === state.id), group, // array: data diff --git a/src/init/startInterval/reset/animation.js b/src/init/startInterval/reset/animation.js index 561b946..f8bbc11 100644 --- a/src/init/startInterval/reset/animation.js +++ b/src/init/startInterval/reset/animation.js @@ -1,9 +1,9 @@ import getNextSequence from '../runNextSequence/getNextSequence'; -import getState from '../../../data/nestData/getState'; -import getAestheticValues from '../../../data/nestData/getAestheticValues'; -import getCoordinates from '../../../data/nestData/getCoordinates'; -import getColorScale from '../../../data/nestData/getColorScale'; -import getAesthetics from '../../../data/nestData/getAesthetics'; +import getState from '../../../data/structure/getState'; +import getAestheticValues from '../../../data/structure/getAestheticValues'; +import getCoordinates from '../../../data/structure/getCoordinates'; +import getColorScale from '../../../data/structure/getColorScale'; +import getAesthetics from '../../../data/structure/getAesthetics'; import runModal from '../../runModal'; export default function resetAnimation(data) { diff --git a/src/init/startInterval/update/data/nestedData.js b/src/init/startInterval/update/data/nestedData.js index fe2362c..20edd6c 100644 --- a/src/init/startInterval/update/data/nestedData.js +++ b/src/init/startInterval/update/data/nestedData.js @@ -1,8 +1,8 @@ -import getState from '../../../../data/nestData/getState'; -import getAestheticValues from '../../../../data/nestData/getAestheticValues'; -import getCoordinates from '../../../../data/nestData/getCoordinates'; -import getColorScale from '../../../../data/nestData/getColorScale'; -import getAesthetics from '../../../../data/nestData/getAesthetics'; +import getState from '../../../../data/structure/getState'; +import getAestheticValues from '../../../../data/structure/getAestheticValues'; +import getCoordinates from '../../../../data/structure/getCoordinates'; +import getColorScale from '../../../../data/structure/getColorScale'; +import getAesthetics from '../../../../data/structure/getAesthetics'; import travelTime from './nestedData/travelTime'; export default function nestedData(data) { @@ -32,6 +32,7 @@ export default function nestedData(data) { // Update coordinates once node reaches vicinity of destination or when time since // previous state crosses some threshold. + d.value.state.transitTime++; d.value.transitTime++; const transitThreshold = 500 / Math.ceil(Math.sqrt(this.settings.speeds[this.settings.speed])); diff --git a/test-page/index.js b/test-page/index.js index 947ec9a..aaef710 100644 --- a/test-page/index.js +++ b/test-page/index.js @@ -6,8 +6,24 @@ fetch('./data/2e4.csv') delete d.duration; }); + const data5 = d3.nest() + .key(d => d.id) + .rollup(group => { + group.forEach((d,i) => { + d.stdy = i + 1; + d.endy = i + 1; + }); + + return group; + }) + .entries(data) + .sort((a,b) => b.value.length - a.value.length) + .slice(0,5) + .map(d => d.value) + .flat(); + const fdg = forceDirectedGraph( - data.filter(d => !/Death/.test(d.event)), + data5, '#container', { individualUnit: 'patient', @@ -15,24 +31,24 @@ fetch('./data/2e4.csv') eventUnit: 'event', eventLabel: 'HFrEF events', timeRelative: 'since randomization', - speed: 'fast', - speedChange: [ - { - timepoint: 60, - speed: 'slow', - }, - { - timepoint: 75, - speed: 'medium' - } - ], - eventFocusLabelChange: [ - { - old_label: 'Home', - new_label: 'Away', - timepoint: 60 - } - ], + speed: 'medium', + //speedChange: [ + // { + // timepoint: 60, + // speed: 'slow', + // }, + // { + // timepoint: 75, + // speed: 'medium' + // } + //], + //eventFocusLabelChange: [ + // { + // old_label: 'Home', + // new_label: 'Away', + // timepoint: 60 + // } + //], delay: 0, minRadius: 3, fill: true,