mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 19:00:09 -04:00
32 lines
876 B
JavaScript
32 lines
876 B
JavaScript
import d3 from 'd3';
|
|
import { isNil, extend, map, filter, groupBy, omit } from 'lodash';
|
|
|
|
export default function prepareData(data, options) {
|
|
const colorScale = d3.scale.category10();
|
|
|
|
const { classify, latColName, lonColName } = options;
|
|
|
|
const pointGroups = classify ? groupBy(data.rows, classify) : { All: data.rows };
|
|
|
|
return filter(map(pointGroups, (rows, name) => {
|
|
const points = filter(map(rows, (row) => {
|
|
const lat = row[latColName];
|
|
const lon = row[lonColName];
|
|
if (isNil(lat) || isNil(lon)) {
|
|
return null;
|
|
}
|
|
return { lat, lon, row: omit(row, [latColName, lonColName]) };
|
|
}));
|
|
if (points.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const result = extend({}, options.groups[name], { name, points });
|
|
if (isNil(result.color)) {
|
|
result.color = colorScale(name);
|
|
}
|
|
|
|
return result;
|
|
}));
|
|
}
|