Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const key = each.key;
return each.map((d) => {
// eslint-disable-next-line prefer-const
let array = [d[0], d[1]];
array.data = {
x: d.data.x,
i,
appearance: d.data.appearance[key]
};
return array;
});
});
// console.log(newData);
// console.log(merge(newData));
const bars = merge(newData)
// .filter(d => isDefined(d.y))
.map(d => {
// let baseValue = yScale.invert(getBase(xScale, yScale, d.datum));
let y = yScale(d[1]);
/* let h = isDefined(d.y0) && d.y0 !== 0 && !isNaN(d.y0)
? yScale(d.y0) - y
: getBase(xScale, yScale, d.datum) - yScale(d.y)*/
let h = getBase(xScale, yScale, d.data) - yScale(d[1] - d[0]);
// console.log(d.y, yScale.domain(), yScale.range())
// let h = ;
// if (d.y < 0) h = -h;
// console.log(d, y, h)
if (h < 0) {
y = y + h;
h = -h;
}
calcExtent(values) {
const { gridMax, gridMin } = this.props
// One more merge for stacked groups
const mergedValues = array.merge(values)
return array.extent([...mergedValues, gridMin, gridMax])
}
for (let key in req.query) {
if (!reserved.includes(key)) {
let ids = req.query[key];
for (const alias in aliases) {
if (Object.prototype.hasOwnProperty.call(aliases, alias)) {
const list = aliases[alias] instanceof Array ? aliases[alias] : [aliases[alias]];
if (list.includes(key)) key = alias;
}
}
const searchDim = key in dimensionMap ? dimensionMap[key] : key;
ids = await Promise.all(d3Array.merge(ids
.split(/,(?=[^\s])/g)
.map(id => {
if (id.includes(":") && key in relations) {
const rels = Object.keys(relations[key]);
id = id.split(":");
const root = id[0];
return id.slice(1)
.map(v => {
if (rels.includes(v)) {
const rel = relations[key][v];
if (typeof rel === "function") {
return analyzeRelation(key, searchDim, rel(root));
}
.x0(d => x(d[0]))
.x1(d => x(d[1]))
.y((d, _index) => (_index === 0 ? y(entryIndex) : y(entryIndex) + y.bandwidth()))
.defined(d => !isNaN(d[0]) && !isNaN(d[1]))([ entry, entry ])
return {
path,
color: colors[keyIndex],
key: keys[keyIndex],
}
})
})
)
}
return array.merge(
series.map((serie, keyIndex) => {
return serie.map((entry, entryIndex) => {
const path = shape
.area()
.y0(d => y(d[0]))
.y1(d => y(d[1]))
.x((d, _index) => (_index === 0 ? x(entryIndex) : x(entryIndex) + x.bandwidth()))
.defined(d => !isNaN(d[0]) && !isNaN(d[1]))([ entry, entry ])
return {
path,
color: colors[keyIndex],
key: keys[keyIndex],
}
})
})
render() {
const { data, animate, animationDuration, style, numberOfTicks, children, horizontal } = this.props
const { height, width } = this.state
if (data.length === 0) {
return
this.canvas.attr(
"transform",
`translate(${this.margin.left},${this.margin.top})`
);
this.yAxis.tickSize(-this.width);
this.xAxisSelection.attr("transform", `translate(0,${this.height})`);
this.xAxisSelection.call(this.xAxis);
this.yAxisSelection.call(this.yAxis);
this.dots.attr("cx", d => this.x(d.date)).attr("cy", d => this.y(d.value));
this.lines.attr("d", d => this.line(d.values));
this.quadtree = quadtree(
merge(this.data.map(d => d.values)),
d => this.x(d.date),
d => this.y(d.value)
);
this.legend = {
domain: this.data.map(d => d.name),
scale: scales.currencies,
};
}
}
} else if (offset === 'expand') {
layoutOffset = shape.stackOffsetExpand;
}
const layout = shape.stack()
.keys(shown.map((d) => d.name))
.value((d, key) => d[key])
.offset(layoutOffset)(data);
const xScale = scaleUtc()
.range([0, dims[0]])
.domain([dates[0], dates[dates.length - 1]]);
const yScale = scaleLinear()
.range([dims[1], 0])
.domain(extent(merge(merge(layout))));
const paths = [];
for (let k = 0; k < shown.length; k++) {
paths.push({
name: shown[k].name,
fill: colors(shown[k].name),
path: getPath(xScale, yScale, layout[k], dates),
});
}
return { filter, offset, paths, xScale, yScale };
},
);
} = this.props
const { height, width } = this.state
if (data.length === 0) {
return
app.get("/api/data/", async(req, res) => {
const measures = findKey(req.query, "measures", []);
if (!measures.length) res.json({error: "Query must contain at least one measure."});
else {
let reserved = ["captions", "drilldowns", "limit", "measures", "order", "parents", "properties", "sort", "Year"];
reserved = reserved.concat(d3Array.merge(reserved.map(r => {
let alts = aliases[r] || [];
if (typeof alts === "string") alts = [alts];
return alts;
})));
const drilldowns = findKey(req.query, "drilldowns", []);
const properties = findKey(req.query, "properties", []);
const order = findKey(req.query, "order", ["Year"]);
const year = findKey(req.query, "Year", "all");
const captions = findKey(req.query, "captions", false);
const {
parents = "false",
sort = "desc"
} = req.query;
export default function(raw, fill, groupBy = []) {
if (groupBy && !(groupBy instanceof Array)) groupBy = [groupBy];
const colors = nest().key(fill).entries(raw);
let data, id;
if (groupBy.length) {
const numColors = colors.length;
for (let i = 0; i < groupBy.length; i++) {
const ids = colors.map(c => Array.from(new Set(c.values.map(d => groupBy[i](d))))),
total = sum(ids, d => d.length),
uniques = new Set(merge(ids)).size;
if (total === numColors && uniques === numColors || i === groupBy.length - 1) {
id = groupBy[i];
data = nest().key(id).entries(raw).map(d => combine(d.values));
break;
}
}
}
else {
id = fill;
data = colors.map(d => combine(d.values));
}
return {data, id};
}