Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// with accessors
numOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToNum);
strOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToStr);
numericOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToNumeric);
dateOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToDate);
numOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToNumOrUndefined);
strOrUndefined = d3Array.max(mixedObjectArray, accessorMixedObjectToStrOrUndefined);
// min() -----------------------------------------------------------------------
// without accessors
numOrUndefined = d3Array.min(numbersArray);
strOrUndefined = d3Array.min(stringyNumbersArray);
numericOrUndefined = d3Array.min(numericArray);
dateOrUndefined = d3Array.min(dateArray);
// with accessors
numOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToNum);
strOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToStr);
numericOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToNumeric);
dateOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToDate);
numOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToNumOrUndefined);
strOrUndefined = d3Array.min(mixedObjectArray, accessorMixedObjectToStrOrUndefined);
// extent() --------------------------------------------------------------------
// without accessors
const fontVerticalMargin = 0.6;
const labelDisplayRatio = Math.ceil(state.nLines*state.minLabelFont/Math.sqrt(2)/state.graphH/fontVerticalMargin);
const tickVals = state.yScale.domain().filter((d, i) => !(i % labelDisplayRatio));
let fontSize = Math.min(12, state.graphH/tickVals.length*fontVerticalMargin*Math.sqrt(2));
let maxChars = Math.ceil(state.rightMargin/(fontSize/Math.sqrt(2)));
state.yAxis.tickValues(tickVals);
state.yAxis.tickFormat(d => reduceLabel(d.split('+&+')[1], maxChars));
state.svg.select('g.y-axis')
.transition().duration(state.transDuration)
.attr('transform', 'translate(' + state.graphW + ', 0)')
.style('font-size', fontSize + 'px')
.call(state.yAxis);
// Grp
const minHeight = d3Min(state.grpScale.range(), function (d,i) {
return i>0?d-state.grpScale.range()[i-1]:d*2;
});
fontSize = Math.min(14, minHeight*fontVerticalMargin*Math.sqrt(2));
maxChars = Math.floor(state.leftMargin/(fontSize/Math.sqrt(2)));
state.grpAxis.tickFormat(d => reduceLabel(d, maxChars));
state.svg.select('g.grp-axis')
.transition().duration(state.transDuration)
.style('font-size', fontSize + 'px')
.call(state.grpAxis);
// Make Axises clickable
if (state.onLabelClick) {
state.svg.selectAll('g.y-axis,g.grp-axis').selectAll('text')
.style('cursor', 'pointer')
.on('click', function(d) {
export function determineRangeBoundaries(outOfRange) {
const lowThresholds = _.filter(outOfRange, { value: 'low' });
const highThresholds = _.filter(outOfRange, { value: 'high' });
const boundaries = {};
if (!_.isEmpty(lowThresholds)) {
// if there is data from multiple devices present with different thresholds
// we want to use the more conservative (= higher) threshold for lows
boundaries.low = max(lowThresholds, (d) => (d.threshold));
}
if (!_.isEmpty(highThresholds)) {
// if there is data from multiple devices present with different thresholds
// we want to use the more conservative (= lower) threshold for highs
boundaries.high = min(highThresholds, (d) => (d.threshold));
}
return boundaries;
}
);
y.domain([
0,
d3.max(data, function(d) {
return Math.max(d.total_candidate_fem, d.total_ghosts_fem);
})
]);
const dataIn2009 = data.filter(function(elem) {
return elem.ano_eleicao === 2009;
});
var dataMax = max(dataIn2009, function(d) {
return Math.max(d.total_candidate_fem, d.total_ghosts_fem);
});
var dataMin = min(dataIn2009, function(d) {
return Math.min(d.total_candidate_fem, d.total_ghosts_fem);
});
const g = chart
.append("g")
.attr("transform", "translate(" + 30 + ", " + 30 + ")");
// Add the valueline path.
g.append("path")
.data([data])
.attr("class", "line-linechart")
.attr("d", valueline);
// Add the valueline path.
g.append("path")
.data([data])
} else {
if (
(day.value === 0 ||
(day.value === 1 && day['zero-value'] === true)) &&
initialValueObtained === true &&
dataStartObject >= currentDay
) {
lineEndDates.push(currentDay);
}
}
});
});
this.dataStartDate =
lineStartDates.length > 0
? d3Array.min(lineStartDates, (c) => {
return c;
})
: dataStartObject;
this.dataEndDate =
lineEndDates.length > 0
? d3Array.max(lineEndDates, (c) => {
return c;
})
: dataEndObject;
} catch (error) {
this.error.emit('jsError');
this.loggerService.log('error', error);
}
}
}
const minY = this.y.invert(scrollOffset);
const maxY = this.y.invert(divHeight + scrollOffset - 75);
//Filter data to adjust x axis to the range of nodes that are visible in the window.
const filteredNodes = this.data.nodes.filter((d: Node) => {
return d.y >= Math.round(minY) && d.y <= Math.round(maxY);
});
if (filteredNodes.length === 0) {
return; //no visible nodes on the screen;
}
const filteredDomain = [min(filteredNodes, function (d: Node) {
return +d.bdate - 5;
}),
max(filteredNodes, function (d: Node) {
return d.ddate ? +d.ddate + 5 : +d.bdate + 5; //account for datasets without a death date
})];
const allDomain = [min(this.data.nodes, function (d: Node) {
return +d.bdate - 5;
}),
max(this.data.nodes, function (d: Node) {
return d.ddate ? +d.ddate: +d.bdate; //account for datasets without a death date
})];
//Temporary cap @ 2016. Not sure why the axis are scaling to 2025 automatically.
if (allDomain[1] > CURRENT_YEAR) {
public findLastLeaf(node: Node) {
//will have to add case if there are ever leaf nodes with spouses but no children. 2/23/2017
//Base case -> leaf node w/ no spouse
if (node.spouse.length === 0 && !node.hasChildren) {
return node.originalY;
} else {//Search through spouse and all of spouses relationships to find last child leaf
return min(node.spouse.map((spouse) => {
return min(spouse.spouse.map((otherSpouse) => {
return min(otherSpouse.children.map((child) => {
return this.findLastLeaf(child);
}));
}));
}));
}
};
}
stats({ validValues, format }) {
const xmin = min(validValues);
const xmax = max(validValues);
const xmean = mean(validValues);
const xmed = median(validValues);
return [
{ x: xmin, label: format(xmin), name: 'Min' },
{ x: xmax, label: format(xmax), name: 'Max' },
{ x: xmean, label: format(xmean), name: __('describe / histogram / mean') },
{ x: xmed, label: format(xmed), name: __('describe / histogram / median') }
];
},
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
let extent$$1 = [d3Array.min(values), d3Array.max(values)];
extent$$1[0] = extent$$1[0] == null ? d3Array.min(include) : d3Array.min([extent$$1[0]].concat(toConsumableArray(include)));
extent$$1[1] = extent$$1[1] == null ? d3Array.max(include) : d3Array.max([extent$$1[1]].concat(toConsumableArray(include)));
if (symmetricalAbout != null) {
let halfRange = Math.max(Math.abs(extent$$1[1] - symmetricalAbout), Math.abs(extent$$1[0] - symmetricalAbout));
extent$$1[0] = symmetricalAbout - halfRange;
extent$$1[1] = symmetricalAbout + halfRange;
}
return paddingStrategy(extent$$1);
};
function initializeNodeBreadths(columns) {
const ky = min(columns, c => (y1 - y0 - (c.length - 1) * py) / sum(c, value));
for (const nodes of columns) {
let y = y0;
for (const node of nodes) {
node.y0 = y;
node.y1 = y + node.value * ky;
y = node.y1 + py;
for (const link of node.sourceLinks) {
link.width = link.value * ky;
}
}
y = (y1 - y + py) / (nodes.length + 1);
for (let i = 0; i < nodes.length; ++i) {
const node = nodes[i];
node.y0 += y * (i + 1);
node.y1 += y * (i + 1);
}