Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const bisectValue = bisector(valueAccessor).left;
// limit to minPercentile if passed in
if (minPercentile != null) {
// get the value at the percentile
const minQuantileValue = quantile(array, minPercentile, valueAccessor);
const quantileInsertIndex = Math.max(0, bisectValue(array, minQuantileValue));
// this may not exist in the array, so find the nearest point to it
// and use that.
minValue = valueAccessor(array[quantileInsertIndex]);
}
// limit to maxPercentile if passed in
if (maxPercentile != null) {
const maxQuantileValue = quantile(array, maxPercentile, valueAccessor);
const quantileInsertIndex = Math.min(array.length - 1, bisectValue(array, maxQuantileValue));
maxValue = valueAccessor(array[quantileInsertIndex]);
// ensure we do not get a value bigger than the quantile value
if (maxValue > maxQuantileValue && quantileInsertIndex > 0) {
maxValue = valueAccessor(array[quantileInsertIndex - 1]);
}
}
return [minValue, maxValue];
}
.y((d) => this.scale.y(d[0]));
const vPath = violinG.append("path")
.datum(vertices)
.attr("d", violin)
.classed("violin", true)
.style("fill", ()=>{
if (entry.color !== undefined) return entry.color;
// alternate the odd and even colors, maybe we don't want this feature
if(gIndex%2 == 0) return "#90c1c1";
return "#94a8b8";
});
// boxplot
const q1 = quantile(entry.values, 0.25);
const q3 = quantile(entry.values, 0.75);
const z = this.scale.z.domain()[1]/3;
if(showWhisker){
// the upper and lower limits of entry.values
const iqr = Math.abs(q3-q1);
const upper = max(entry.values.filter((d)=>dd>q1-(iqr*1.5)));
dom.append("line")
.classed("whisker", true)
.attr("x1", this.scale.z(0))
.attr("x2", this.scale.z(0))
.attr("y1", this.scale.y(upper))
.attr("y2", this.scale.y(lower))
.style("stroke", "#fff");
}
const getSummaryStatistics = (data) => {
const dependentVars = data.map((datum) => datum._y);
const quartiles = {
_q1: nanToNull(d3Quantile(dependentVars, 0.25)), // eslint-disable-line no-magic-numbers
_q3: nanToNull(d3Quantile(dependentVars, 0.75)), // eslint-disable-line no-magic-numbers
_min: nanToNull(d3Min(dependentVars)),
_median: nanToNull(d3Quantile(dependentVars, 0.5)),
_max: nanToNull(d3Max(dependentVars))
};
return assign({}, data[0], quartiles, { _y: data[0]._y });
};
.range([this.scale.subx(entry.label), this.scale.subx(entry.label) + this.scale.subx.bandwidth()]);
// re-render the violin
const g = dom.select(`#violin${gg.index}-${entry.label}`);
g.select(".violin")
.transition(t)
.attr("d", area()
.x0((d) => this.scale.z(d[1]))
.x1((d) => this.scale.z(-d[1]))
.y((d) => this.scale.y(d[0]))
);
// re-render the box plot
// interquartile range
const q1 = quantile(entry.values, 0.25);
const q3 = quantile(entry.values, 0.75);
const z = 0.1;
g.select(".violin-ir")
.transition(t)
.attr("x", this.scale.z(-z))
.attr("y", this.scale.y(q3))
.attr("width", Math.abs(this.scale.z(-z) - this.scale.z(z)))
.attr("height", Math.abs(this.scale.y(q3) - this.scale.y(q1)));
// the median line
const med = median(entry.values);
g.select(".violin-median")
.transition(t)
.attr("x1", this.scale.z(-z))
.attr("x2", this.scale.z(z))
.attr("y1", this.scale.y(med))
x1 = x0 + this.scale.x.bandwidth();
this.scale.z.range([x0, x1]);
// rerender the violin
let g = dom.select(`#violin${i}`);
g.select(".violin")
.transition(t)
.attr("d", area()
.x0((d) => this.scale.z(d[1]))
.x1((d) => this.scale.z(-d[1]))
.y((d) => this.scale.y(d[0])));
// rerender the box plot
// interquartile range
const q1 = quantile(entry.values, 0.25);
const q3 = quantile(entry.values, 0.75);
const z = 0.1;
g.select(".violin-ir")
.transition(t)
.attr("x", this.scale.z(-z))
.attr("y", this.scale.y(q3))
.attr("width", Math.abs(this.scale.z(-z)-this.scale.z(z)))
.attr("height", Math.abs(this.scale.y(q3) - this.scale.y(q1)));
// the median line
const med = median(entry.values);
g.select(".violin-median")
.transition(t)
.attr("x1", this.scale.z(-z))
.attr("x2", this.scale.z(z))
.attr("y1", this.scale.y(med))
.attr("y2", this.scale.y(med))
export function quartiles(array, f) {
var values = numbers(array, f);
return [
quantile(values.sort(ascending), 0.25),
quantile(values, 0.50),
quantile(values, 0.75)
];
}
stopDataValues.map(function (q, i) {
var value = d3array.quantile(data, q)
styleFunction.stops[i][0] = value
})
stopDataValues.map(function (q, i) {
var value = d3array.quantile(data, q)
styleFunction.stops[i][0] = value
})
private getSevenFigureSummary(a: number[]): ISevenFigureSummary {
return {
min: Math.round(Math.min.apply(null, a)),
max: Math.round(Math.max.apply(null, a)),
10: Math.round(quantile(a, 0.1) as number),
25: Math.round(quantile(a, 0.25) as number),
50: Math.round(quantile(a, 0.5) as number),
75: Math.round(quantile(a, 0.75) as number),
90: Math.round(quantile(a, 0.9) as number),
};
}
private getConfidenceInterval(
summaryValueNest = [
quantile(summaryValueNest, 0.0),
quantile(summaryValueNest, 0.25),
quantile(summaryValueNest, 0.5),
quantile(summaryValueNest, 0.75),
quantile(summaryValueNest, 1.0)
]
if (projection === "vertical") {
summaryPositionNest = thisSummaryData
.map(p => p.scaledVerticalValue)
.sort((a, b) => b - a)
summaryPositionNest = [
quantile(summaryPositionNest, 0.0),
quantile(summaryPositionNest, 0.25),
quantile(summaryPositionNest, 0.5),
quantile(summaryPositionNest, 0.75),
quantile(summaryPositionNest, 1.0)
]
const xPosition = positionFn(summary.middle, key, summaryI)
translate = `translate(${xPosition},0)`
extentlineX1 = 0
extentlineX2 = 0
extentlineY1 = summaryPositionNest[0]
extentlineY2 = summaryPositionNest[4]
topLineX1 = -columnWidth / 2
topLineX2 = columnWidth / 2
midLineX1 = -columnWidth / 2
midLineX2 = columnWidth / 2