Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
outputNumber = quantizeScaleNumber(0.51);
// copy(...) -----------------------------------------------------------------
const copiedQuantizeScale: d3Scale.ScaleQuantize = quantizeScaleNumber.copy();
// -------------------------------------------------------------------------------
// Quantile Scale Factory
// -------------------------------------------------------------------------------
// scaleQuantile() -----------------------------------------------------------------
let quantileScaleNumber: d3Scale.ScaleQuantile;
let quantileScaleString: d3Scale.ScaleQuantile;
quantileScaleNumber = d3Scale.scaleQuantile();
quantileScaleString = d3Scale.scaleQuantile();
// ScaleQuantile Interface ========================================================
// domain(...) -----------------------------------------------------------------
quantileScaleNumber = quantileScaleNumber.domain(domainNumbers);
domainNumbers = quantileScaleNumber.domain();
quantileScaleString = quantileScaleString.domain(domainNumeric);
// range(...) -----------------------------------------------------------------
quantileScaleNumber = quantileScaleNumber.range([1, 2, 3, 4]);
rangeNumbers = quantileScaleNumber.range();
// copy(...) -----------------------------------------------------------------
let copiedQuantizeScale: d3Scale.ScaleQuantize = quantizeScaleNumber.copy();
// -------------------------------------------------------------------------------
// Quantile Scale Factory
// -------------------------------------------------------------------------------
// scaleQuantile() -----------------------------------------------------------------
let quantileScaleNumber: d3Scale.ScaleQuantile;
let quantileScaleString: d3Scale.ScaleQuantile;
quantileScaleNumber = d3Scale.scaleQuantile();
quantileScaleString = d3Scale.scaleQuantile();
// ScaleQuantile Interface ========================================================
// domain(...) -----------------------------------------------------------------
quantileScaleNumber = quantileScaleNumber.domain(domainNumbers);
domainNumbers = quantileScaleNumber.domain();
quantileScaleString = quantileScaleString.domain(domainNumeric);
// range(...) -----------------------------------------------------------------
quantileScaleNumber = quantileScaleNumber.range([1, 2, 3, 4]);
}
if (!selectedCounty) {
selectedCounty = data.find(f => f.properties.name === 'Los Angeles, CA');
}
const {flows, centroid} = selectedCounty.properties;
const arcs = Object.keys(flows).map(toId => {
const f = data[toId];
return {
source: centroid,
target: f.properties.centroid,
value: flows[toId]
};
});
const scale = scaleQuantile()
.domain(arcs.map(a => Math.abs(a.value)))
.range(inFlowColors.map((c, i) => i));
arcs.forEach(a => {
a.gain = Math.sign(a.value);
a.quantile = scale(Math.abs(a.value));
});
if (this.props.onSelectCounty) {
this.props.onSelectCounty(selectedCounty);
}
this.setState({arcs, selectedCounty});
}
generateColorScheme(scheme, type, domain) {
if (typeof(scheme) === 'string') {
scheme = colorSets.find(cs => {
return cs.name === scheme;
});
}
let colorScale;
if (type === 'quantile') {
colorScale = scaleQuantile()
.range(scheme.domain)
.domain(domain);
} else if (type === 'ordinal') {
colorScale = scaleOrdinal()
.range(scheme.domain)
.domain(domain);
} else if (type === 'linear') {
colorScale = scaleLinear()
.domain(range(0, 1, 1.0 / (scheme.domain.length - 1)))
.range(scheme.domain);
}
return colorScale;
}
var func;
if(scale === 'linear')
func = D3Scale.scaleLinear();
else if(scale === 'identity')
func = D3Scale.scaleIdentity();
else if(scale === 'sqrt')
func = D3Scale.scaleSqrt();
else if(scale === 'pow')
func = D3Scale.scalePow();
else if(scale === 'log')
func = D3Scale.scaleLog();
else if(scale === 'quantize')
func = D3Scale.scaleQuantize();
else if(scale === 'quantile')
func = D3Scale.scaleQuantile();
else if(scale === 'ordinal')
func = D3Scale.scaleOrdinal()
else if(scale === 'band')
func = D3Scale.scaleBand();
else if(scale === 'time')
func = D3Scale.scaleTime();
else
new Error(`Please check your axis scale setting. "${scale}" scale is invalid. `)
func = _mkScaleSettings(props, func);
return func;
}
if (!data || !selectedFeature) {
return null;
}
const {flows, centroid} = selectedFeature.properties;
const arcs = Object.keys(flows).map(toId => {
const f = data[toId];
return {
source: centroid,
target: f.properties.centroid,
value: flows[toId]
};
});
const scale = scaleQuantile()
.domain(arcs.map(a => Math.abs(a.value)))
.range(inFlowColors.map((c, i) => i));
arcs.forEach(a => {
a.gain = Math.sign(a.value);
a.quantile = scale(Math.abs(a.value));
});
return arcs;
}
export function updatePercentiles(featureCollection, accessor) {
const {features} = featureCollection;
const scale = scaleQuantile()
.domain(features.map(accessor))
.range(range(9));
features.forEach(f => {
const value = accessor(f);
f.properties.value = value;
f.properties.percentile = scale(value);
});
}