Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const height = extent.height;
const container = select(`#${stockCode}chart`)
.insert('svg', 'div')
.attr('width', width)
.attr('height', height);
// Create scale for x axis
const xScale = scaleDiscontinuous(scaleTime())
.domain(extentDate().accessors([(d) => d.date])(data))
.discontinuityProvider(discontinuitySkipWeekends())
.range([0, width]);
// Create scale for y axis. We're only showing close, so
// only use that extent.
const closeExtent = extentLinear().accessors([(d) => d.close])(data);
const yScale = scaleLinear()
.domain(closeExtent)
.range([height, 0])
.nice();
const area = seriesSvgArea()
.crossValue((d) => d.date)
.baseValue((_) => closeExtent[0])
.mainValue((d) => d.close)
.decorate((selection) => {
selection.attr('fill', `url(#${stockCode}-minichart-gradient)`);
});
const line = seriesSvgLine()
.crossValue((d) => d.date)
.mainValue((d) => d.close);
export function configureScale(isSplitBy, horizontal, dataset, groupBys) {
let mainScale;
let crossScale;
if (isSplitBy) {
let mainExtent = fc
.extentLinear()
.accessors([a => a.map(d => d[1])])
.pad([0, 1])
.padUnit("domain");
mainScale = d3.scaleLinear().domain(mainExtent(dataset));
crossScale = d3
.scaleBand()
.domain(groupBys)
.paddingInner(0.4)
.paddingOuter(0.2);
} else {
mainScale = d3.scaleLinear().domain([0, d3.max(dataset, x => x.mainValue)]);
crossScale = d3
export function configureScaleMultiColumn(horizontal, dataset, groupedBarData) {
const mainExtent = fc
.extentLinear()
.accessors([a => a.map(d => d[1])])
.include([0])
.pad([0, 1])
.padUnit("domain");
const mainScale = d3.scaleLinear().domain(mainExtent(dataset));
const crossScale = d3
.scaleBand()
.domain(groupedBarData.map(entry => entry.crossValue))
.paddingInner(0.4)
.paddingOuter(0.2);
let [xScale, yScale] = horizontal ? [mainScale, crossScale] : [crossScale, mainScale];
return [xScale, yScale];
}
.append("div")
.attr("class", "legend-container legend-color")
.style("z-index", "2")
);
const {width, height} = legendSelection.node().getBoundingClientRect();
const xScale = d3
.scaleBand()
.domain([0, 1])
.range([0, width]);
const domain = scale
.copy()
.nice()
.domain();
const paddedDomain = fc
.extentLinear()
.pad([0.1, 0.1])
.padUnit("percent")(domain);
const [min, max] = paddedDomain;
const expandedDomain = d3.range(min, max, (max - min) / height);
const yScale = d3
.scaleLinear()
.domain(paddedDomain)
.range([height, 0]);
const svgBar = fc
.autoBandwidth(fc.seriesSvgBar())
.xScale(xScale)
.yScale(yScale)
.crossValue(0)
const getCloseExtent = chartData => {
return extentLinear().accessors([d => d.close])(chartData);
};