Skip to content

Commit

Permalink
[FE-18022] Use column names instead of aliases when doing data export…
Browse files Browse the repository at this point in the history
…, handle BE scatter (#693)

* Use column names instead of aliases when doing data export

* Don't include new color hash column for data export

* Remove comments

* Formatting
  • Loading branch information
johallar authored Feb 7, 2025
1 parent 216078a commit 7065fad
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
30 changes: 17 additions & 13 deletions dist/charting.js
Original file line number Diff line number Diff line change
Expand Up @@ -32728,6 +32728,7 @@ function rasterLayerPointMixin(_layer) {
color = _ref$encoding.color,
orientation = _ref$encoding.orientation,
postFilters = _ref.postFilters;
var isGeo = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
var transforms = [];
if (_typeof(transform) === "object" && _typeof(transform.groupby) === "object" && transform.groupby.length) {
var fields = isDataExport ? [] : [x.field, y.field];
Expand Down Expand Up @@ -32770,51 +32771,54 @@ function rasterLayerPointMixin(_layer) {
if (isDataExport) {
transforms.push({
type: "project",
expr: "ST_SetSRID(ST_Point(".concat(AGGREGATES[x.aggregate], "(").concat(x.field, "), ").concat(AGGREGATES[y.aggregate], "(").concat(y.field, ")), 4326) AS location")
expr: "ST_SetSRID(ST_Point(".concat(AGGREGATES[x.aggregate], "(").concat(x.field, "), ").concat(AGGREGATES[y.aggregate], "(").concat(y.field, ")), 4326) AS 'location(").concat(x.field, ",").concat(y.field, ")'")
});
}
} else {
if (isDataExport) {
if (isDataExport && isGeo) {
transforms.push({
type: "project",
expr: "/*+ cpu_mode */ ST_SetSRID(ST_Point(".concat(x.field, ", ").concat(y.field, "), 4326)")
expr: "/*+ cpu_mode */ ST_SetSRID(ST_Point(".concat(x.field, ", ").concat(y.field, "), 4326)"),
as: "'location(".concat(x.field, ", ").concat(y.field, ")'")
});
} else {
transforms.push({
type: "project",
expr: x.field,
as: "x"
as: isDataExport ? "'".concat(x.field, "'") : "x"
});
transforms.push({
type: "project",
expr: y.field,
as: "y"
as: isDataExport ? "'".concat(y.field, "'") : "y"
});
}
if (_typeof(size) === "object" && size.type === "quantitative") {
transforms.push({
type: "project",
expr: size.field,
as: "size"
as: isDataExport ? "'".concat(size.field, "'") : "size"
});
}
if (_typeof(color) === "object" && (color.type === "quantitative" || color.type === "ordinal")) {
transforms.push({
type: "project",
expr: color.type === "ordinal" && color.fullColorHashing ? Object(__WEBPACK_IMPORTED_MODULE_5__utils_color_helpers__["c" /* buildHashedColor */])(color.field, color.range, color.palette.val.length, color.customColors) : color.field,
as: "color"
});
transforms.push({
type: "project",
expr: color.field,
as: "color_attr"
as: isDataExport ? "'".concat(color.field, "'") : "color"
});
if (!isDataExport) {
transforms.push({
type: "project",
expr: color.field,
as: "color_attr"
});
}
}
if (orientation) {
transforms.push({
type: "project",
expr: orientation.field,
as: "orientation"
as: isDataExport ? "'".concat(orientation.field, "'") : "orientation"
});
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/chart-addons/stacked-legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ function getUpdatedDomainRange(newDomain, oldDomain, range, defaultColor) {
}
}

const sortDomain = (sortDirection, domain) => domain.sort((a, b) =>
sortDirection === SORT_DIRECTION.ASCENDING ? a.localeCompare(b) : b.localeCompare(a)
const sortDomain = (sortDirection, domain) =>
domain.sort((a, b) =>
sortDirection === SORT_DIRECTION.ASCENDING
? a.localeCompare(b)
: b.localeCompare(a)
)

export async function getLegendStateFromChart(chart, useMap, selectedLayer) {
Expand Down Expand Up @@ -316,10 +319,15 @@ export function handleLegendSort(index = 0) {
const currentRange = filteredRange ?? range

// Toggle sort order, or set to ascending initially
color.sorted = sorted === SORT_DIRECTION.DESCENDING || !sorted ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING

const sortedDomain = sortDomain(color.sorted, currentDomain
.filter(d => d !== OTHER_KEY))
color.sorted =
sorted === SORT_DIRECTION.DESCENDING || !sorted
? SORT_DIRECTION.ASCENDING
: SORT_DIRECTION.DESCENDING

const sortedDomain = sortDomain(
color.sorted,
currentDomain.filter(d => d !== OTHER_KEY)
)

const { newDomain, newRange } = getUpdatedDomainRange(
sortedDomain,
Expand Down
32 changes: 18 additions & 14 deletions src/mixins/raster-layer-point-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ export default function rasterLayerPointMixin(_layer) {
globalFilter,
{ transform, encoding: { x, y, size, color, orientation }, postFilters },
lastFilteredSize,
isDataExport
isDataExport,
isGeo = true
) {
const transforms = []

Expand Down Expand Up @@ -249,33 +250,34 @@ export default function rasterLayerPointMixin(_layer) {
type: "project",
expr: `ST_SetSRID(ST_Point(${AGGREGATES[x.aggregate]}(${x.field}), ${
AGGREGATES[y.aggregate]
}(${y.field})), 4326) AS location`
}(${y.field})), 4326) AS 'location(${x.field},${y.field})'`
})
}
} else {
if (isDataExport) {
if (isDataExport && isGeo) {
transforms.push({
type: "project",
expr: `/*+ cpu_mode */ ST_SetSRID(ST_Point(${x.field}, ${y.field}), 4326)`
expr: `/*+ cpu_mode */ ST_SetSRID(ST_Point(${x.field}, ${y.field}), 4326)`,
as: `'location(${x.field}, ${y.field})'`
})
} else {
transforms.push({
type: "project",
expr: x.field,
as: "x"
as: isDataExport ? `'${x.field}'` : "x"
})
transforms.push({
type: "project",
expr: y.field,
as: "y"
as: isDataExport ? `'${y.field}'` : "y"
})
}

if (typeof size === "object" && size.type === "quantitative") {
transforms.push({
type: "project",
expr: size.field,
as: "size"
as: isDataExport ? `'${size.field}'` : "size"
})
}

Expand All @@ -294,20 +296,22 @@ export default function rasterLayerPointMixin(_layer) {
color.customColors
)
: color.field,
as: "color"
})
transforms.push({
type: "project",
expr: color.field,
as: "color_attr"
as: isDataExport ? `'${color.field}'` : "color"
})
if (!isDataExport) {
transforms.push({
type: "project",
expr: color.field,
as: "color_attr"
})
}
}

if (orientation) {
transforms.push({
type: "project",
expr: orientation.field,
as: "orientation"
as: isDataExport ? `'${orientation.field}'` : "orientation"
})
}
}
Expand Down

0 comments on commit 7065fad

Please sign in to comment.