-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add legend direction, discrete gradient, and redesigned symbol legend…
… support.
- Loading branch information
Showing
9 changed files
with
385 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {Vertical} from './constants'; | ||
import {value} from '../../util'; | ||
|
||
export function lookup(name, spec, config) { | ||
return value(spec[name], config[name]); | ||
} | ||
|
||
export function isVertical(spec, configVal) { | ||
return value(spec.direction, configVal) === Vertical; | ||
} | ||
|
||
export function gradientLength(spec, config) { | ||
return value( | ||
spec.gradientLength, | ||
config.gradientLength || config.gradientWidth | ||
); | ||
} | ||
|
||
export function gradientThickness(spec, config) { | ||
return value( | ||
spec.gradientThickness, | ||
config.gradientThickness || config.gradientHeight | ||
); | ||
} | ||
|
||
export function entryColumns(spec, config) { | ||
return value( | ||
spec.columns, | ||
value(config.columns, +isVertical(spec, config.entryDirection)) | ||
); | ||
} | ||
|
||
export function getEncoding(name, encode) { | ||
var v = encode && ( | ||
(encode.update && encode.update[name]) || | ||
(encode.enter && encode.enter[name]) | ||
); | ||
return v && v.signal ? v : v ? v.value : null; | ||
} | ||
|
||
export function getStyle(name, scope, style) { | ||
var s = scope.config.style[style]; | ||
return s && s[name]; | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/vega-parser/src/parsers/guides/legend-gradient-discrete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Value, Perc, Perc2} from './constants'; | ||
import guideMark from './guide-mark'; | ||
import {gradientLength, gradientThickness, isVertical, lookup} from './guide-util'; | ||
import {RectMark} from '../marks/marktypes'; | ||
import {LegendBandRole} from '../marks/roles'; | ||
import {addEncode, encoder} from '../encode/encode-util'; | ||
|
||
export default function(spec, scale, config, userEncode, dataRef) { | ||
var zero = {value: 0}, | ||
vertical = isVertical(spec, config.gradientDirection), | ||
thickness = gradientThickness(spec, config), | ||
length = gradientLength(spec, config), | ||
encode = {}, enter, update, u, v, uu, vv, adjust = ''; | ||
|
||
vertical | ||
? (u = 'y', uu = 'y2', v = 'x', vv = 'width', adjust = '1-') | ||
: (u = 'x', uu = 'x2', v = 'y', vv = 'height'); | ||
|
||
encode.enter = enter = {opacity: zero}; | ||
addEncode(enter, 'stroke', lookup('gradientStrokeColor', spec, config)); | ||
addEncode(enter, 'strokeWidth', lookup('gradientStrokeWidth', spec, config)); | ||
|
||
encode.exit = {opacity: zero}; | ||
encode.update = update = {opacity: {value: 1}}; | ||
|
||
enter.fill = update.fill = {scale: scale, field: Value}; | ||
|
||
enter[u] = update[u] = {signal: adjust + 'datum.' + Perc, mult: length}; | ||
enter[v] = update[v] = {value: 0}; | ||
|
||
enter[uu] = update[uu] = {signal: adjust + 'datum.' + Perc2, mult: length}; | ||
enter[vv] = update[vv] = encoder(thickness); | ||
|
||
return guideMark(RectMark, LegendBandRole, null, Value, dataRef, encode, userEncode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.