'use strict';
require('../globals');
var time = require('./time');
var legend = module.exports = {};
legend.defs = function(encoding) {
var defs = [];
// TODO: support alpha
Eif (encoding.has(COLOR) && encoding.legend(COLOR)) {
defs.push(legend.def(COLOR, encoding, {
fill: COLOR,
orient: 'right'
}));
}
Iif (encoding.has(SIZE) && encoding.legend(SIZE)) {
defs.push(legend.def(SIZE, encoding, {
size: SIZE,
orient: defs.length === 1 ? 'left' : 'right'
}));
}
Iif (encoding.has(SHAPE) && encoding.legend(SHAPE)) {
if (defs.length === 2) {
// TODO: fix this
console.error('Vega-lite currently only supports two legends');
return defs;
}
defs.push(legend.def(SHAPE, encoding, {
shape: SHAPE,
orient: defs.length === 1 ? 'left' : 'right'
}));
}
return defs;
};
legend.def = function(name, encoding, props) {
var def = props, timeUnit;
def.title = encoding.fieldTitle(name);
Iif (encoding.isType(name, T) && (timeUnit = encoding.timeUnit(name)) &&
time.hasScale(timeUnit)) {
var properties = def.properties = def.properties || {},
labels = properties.labels = properties.labels || {},
text = labels.text = labels.text || {};
text.scale = 'time-'+ timeUnit;
}
return def;
};
|