Skip to content

Commit

Permalink
feat: support domainRaw so one may bind domainRaw to a parameter to b…
Browse files Browse the repository at this point in the history
…uild custom interaction
  • Loading branch information
kanitw committed Jul 6, 2023
1 parent 945a711 commit 209f41b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
40 changes: 40 additions & 0 deletions examples/specs/interactive_point_domainRaw_binding.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/cars.json"},
"params": [{
"name": "min_x",
"value": 50,
"bind": {
"input": "range",
"min": 0,
"max": 300
}
}, {
"name": "max_x",
"value": 250,
"bind": {
"input": "range",
"min": 0,
"max": 300
}
},{
"name": "use_custom_x",
"value": true,
"bind": {
"input": "checkbox"
}
}],
"mark": {"type": "circle", "clip": true},
"encoding": {
"x": {
"field": "Horsepower", "type": "quantitative",
"scale": {
"domainRaw": {"expr": "use_custom_x ? [min_x, max_x] : null"}
}
},
"y": {
"field": "Miles_per_Gallon", "type": "quantitative"
},
"size": {"field": "Cylinders", "type": "quantitative"}
}
}
2 changes: 1 addition & 1 deletion src/compile/scale/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Explicit, Split} from '../split';
* All VgDomain property except domain.
* (We exclude domain as we have a special "domains" array that allow us merge them all at once in assemble.)
*/
export type ScaleComponentProps = Omit<VgScale, 'domain' | 'domainRaw' | 'reverse'> & {
export type ScaleComponentProps = Omit<VgScale, 'domain' | 'reverse'> & {
domains: VgNonUnionDomain[];
selectionExtent?: ParameterExtent;
reverse?: boolean | SignalRef; // Need override since Vega doesn't official support scale reverse yet (though it does in practice)
Expand Down
10 changes: 10 additions & 0 deletions src/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ export interface Scale<ES extends ExprRef | SignalRef = ExprRef | SignalRef> {
| DomainUnionWith
| ES;

/**
* An expression for an array of raw values that, if non-null, directly overrides the _domain_ property.
* This is useful for supporting interactions such as panning or zooming a scale.
* The scale may be initially determined using a data-driven domain, then modified in response to user input by setting the rawDomain value.
*/
domainRaw?: ES;

/**
* Inserts a single mid-point value into a two-element domain. The mid-point value must lie between the domain minimum and maximum values. This property can be useful for setting a midpoint for [diverging color scales](https://vega.github.io/vega-lite/docs/scale.html#piecewise). The domainMid property is only intended for use with scales supporting continuous, piecewise domains.
*/
Expand Down Expand Up @@ -728,6 +735,7 @@ const SCALE_PROPERTY_INDEX: Flag<keyof Scale<any>> = {
domainMax: 1,
domainMin: 1,
domainMid: 1,
domainRaw: 1,
align: 1,
range: 1,
rangeMax: 1,
Expand Down Expand Up @@ -785,6 +793,7 @@ export function scaleTypeSupportProperty(scaleType: ScaleType, propName: keyof S
case 'domainMax':
case 'domainMid':
case 'domainMin':
case 'domainRaw':
case 'clamp':
return isContinuousToContinuous(scaleType);
case 'nice':
Expand Down Expand Up @@ -830,6 +839,7 @@ export function channelScalePropertyIncompatability(channel: Channel, propName:
case 'domain':
case 'domainMax':
case 'domainMin':
case 'domainRaw':
case 'range':
case 'base':
case 'exponent':
Expand Down

0 comments on commit 209f41b

Please sign in to comment.