Skip to content

Commit

Permalink
fix!: Use orderby not order, allow highlight to auto-assign orderby.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Jan 12, 2024
1 parent 17f61a9 commit bac02bd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
2 changes: 0 additions & 2 deletions dev/yaml/highlight-cube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ vconcat:
data: { from: athletes, filterBy: $query }
x: { count: }
y: nationality
order: nationality
sort: {
y: '-x',
limit: 10
Expand All @@ -30,7 +29,6 @@ vconcat:
data: { from: athletes, filterBy: $query }
x: { count: }
y: sport
order: sport
sort: {
y: '-x',
limit: 10
Expand Down
3 changes: 2 additions & 1 deletion dev/yaml/weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ vconcat:
colorRange: $colors
rDomain: Fixed
rRange: [2, 10]
marginLeft: 45
width: 800
- plot:
- mark: barX
Expand All @@ -40,7 +41,6 @@ vconcat:
x: { count: }
y: weather
fill: weather
order: weather
- select: toggleY
as: $click
- select: highlight
Expand All @@ -50,4 +50,5 @@ vconcat:
yLabel: null
colorDomain: $domain
colorRange: $colors
marginLeft: 45
width: 800
2 changes: 1 addition & 1 deletion docs/public/specs/esm/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default vg.vconcat(
),
vg.barX(
vg.from("weather", { filterBy: $range }),
{ x: vg.count(), y: "weather", fill: "weather", order: "weather" }
{ x: vg.count(), y: "weather", fill: "weather" }
),
vg.toggleY({ as: $click }),
vg.highlight({ by: $click }),
Expand Down
3 changes: 1 addition & 2 deletions docs/public/specs/json/weather.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
"count": null
},
"y": "weather",
"fill": "weather",
"order": "weather"
"fill": "weather"
},
{
"select": "toggleY",
Expand Down
1 change: 0 additions & 1 deletion docs/public/specs/yaml/weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ vconcat:
x: { count: }
y: weather
fill: weather
order: weather
- select: toggleY
as: $click
- select: highlight
Expand Down
33 changes: 32 additions & 1 deletion packages/vgplot/src/interactors/Highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,43 @@ import { coordinator, throttle } from '@uwdata/mosaic-core';
import { and } from '@uwdata/mosaic-sql';
import { sanitizeStyles } from './util/sanitize-styles.js';

function configureMark(mark) {
const { channels } = mark;
const dims = new Set;
let ordered = false;
let aggregate = false;

for (const c of channels) {
const { channel, field, as } = c;
if (channel === 'orderby') {
ordered = true;
} else if (field) {
if (field.aggregate) {
aggregate = true;
} else {
if (dims.has(as)) continue;
dims.add(as);
}
}
}

// if orderby is defined, we're ok: nothing to do
// or, if there is no groupby aggregation, we're ok: nothing to do
// grouping may result in optimizations that change result order
// so we orderby the grouping dimensions to ensure stable indices
if (!ordered && aggregate && dims.size) {
mark.channels.push(({ channel: 'orderby', value: Array.from(dims) }));
}

return mark;
}

export class Highlight {
constructor(mark, {
selection,
channels = {}
}) {
this.mark = mark;
this.mark = configureMark(mark);
this.selection = selection;
const c = Object.entries(sanitizeStyles(channels));
this.channels = c.length ? c : [['opacity', 0.2]];
Expand Down
2 changes: 1 addition & 1 deletion packages/vgplot/src/marks/HexbinMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class HexbinMark extends Mark {
const aggr = new Set;
const cols = {};
for (const c of channels) {
if (c.channel === 'order') {
if (c.channel === 'orderby') {
q.orderby(c.value); // TODO revisit once groupby is added
} else if (c.channel === 'x') {
x = c;
Expand Down
2 changes: 1 addition & 1 deletion packages/vgplot/src/marks/Mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function markQuery(channels, table, skip = []) {
const { channel, field, as } = c;
if (skip.includes(channel)) continue;

if (channel === 'order') {
if (channel === 'orderby') {
q.orderby(c.value);
} else if (field) {
if (field.aggregate) {
Expand Down

0 comments on commit bac02bd

Please sign in to comment.