Socket
Socket
Sign inDemoInstall

vega-lite

Package Overview
Dependencies
Maintainers
2
Versions
470
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-lite - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

src/axis.js

2

examples/all-examples.json

@@ -1,1 +0,1 @@

["area","area_vertical","bar","bar_1d","bar_aggregate","bar_aggregate_size","bar_filter_calc","bar_grouped","bar_grouped_horizontal","bar_layered_transparent","bar_yearmonth","circle","histogram","line","line_color","line_detail","line_monotone","line_month","line_step","point_1d","point_color","point_dot_timeunit_color","point_filled","point_ordinal_color","scatter","scatter_aggregate_detail","scatter_binned","scatter_binned_color","scatter_binned_size","scatter_bubble","scatter_color","scatter_color_custom","scatter_color_order","scatter_color_ordinal","scatter_color_ordinal_custom","scatter_color_quantitative","scatter_color_shape_constant","scatter_colored_with_shape","scatter_connected","scatter_log","square","stacked_area","stacked_area_normalize","stacked_area_ordinal","stacked_area_stream","stacked_bar_1d","stacked_bar_h","stacked_bar_h_order","stacked_bar_normalize","stacked_bar_population","stacked_bar_v","stacked_bar_weather","text_scatter_colored","text_table_heatmap","tick_dot","tick_dot_thickness","tick_strip","trellis_bar","trellis_bar_histogram","trellis_barley","trellis_row_column","trellis_scatter","trellis_scatter_binned_row","trellis_stacked_bar"]
["area","area_vertical","bar","bar_1d","bar_aggregate","bar_aggregate_size","bar_aggregate_vertical","bar_filter_calc","bar_grouped","bar_grouped_horizontal","bar_layered_transparent","bar_yearmonth","circle","histogram","line","line_color","line_detail","line_monotone","line_month","line_slope","line_step","point_1d","point_color","point_dot_timeunit_color","point_filled","point_ordinal_color","scatter","scatter_aggregate_detail","scatter_binned","scatter_binned_color","scatter_binned_size","scatter_bubble","scatter_color","scatter_color_custom","scatter_color_order","scatter_color_ordinal","scatter_color_ordinal_custom","scatter_color_quantitative","scatter_color_shape_constant","scatter_colored_with_shape","scatter_connected","scatter_log","square","stacked_area","stacked_area_normalize","stacked_area_ordinal","stacked_area_stream","stacked_bar_1d","stacked_bar_h","stacked_bar_h_order","stacked_bar_normalize","stacked_bar_population","stacked_bar_v","stacked_bar_weather","text_scatter_colored","text_table_heatmap","tick_dot","tick_dot_thickness","tick_strip","trellis_bar","trellis_bar_histogram","trellis_barley","trellis_row_column","trellis_scatter","trellis_scatter_binned_row","trellis_stacked_bar"]
{
"name": "vega-lite",
"author": "Jeffrey Heer, Dominik Moritz, Kanit \"Ham\" Wongsuphasawat",
"version": "1.0.6",
"version": "1.0.7",
"collaborators": [

@@ -12,2 +12,7 @@ "Kanit Wongsuphasawat <kanitw@gmail.com> (http://kanitw.yellowpigz.com)",

"main": "src/vl.js",
"bin": {
"vl2png": "./bin/vl2png",
"vl2svg": "./bin/vl2svg",
"vl2vg": "./bin/vl2vg"
},
"directories": {

@@ -19,17 +24,18 @@ "test": "test"

"postbuild": "uglifyjs vega-lite.js -cm --source-map vega-lite.min.js.map > vega-lite.min.js && npm run schema",
"build:all": "npm run clean && npm run data && npm run build && npm test && npm run lint && npm run images",
"cover": "tsc && istanbul cover node_modules/.bin/_mocha -- --recursive",
"build:all": "npm run clean && npm run data && npm run build && npm test && npm run lint && npm run build:images",
"build:images": "npm run data && scripts/generate-images.sh",
"cover": "npm run pretest && istanbul cover node_modules/.bin/_mocha -- --recursive",
"clean": "rm -f vega-lite.* vega-lite-schema.json & find src -name '*.js*' -type f -delete & find test -name '*.js*' -type f -delete & find site -name '*.js*' -type f -delete & rm -rf examples/_diff examples/_original examples/_output examples/images && rm -rf data",
"data": "rm -rf data && cp -r node_modules/vega-datasets/data data",
"data": "cp -r node_modules/vega-datasets/data data",
"deploy": "scripts/deploy.sh",
"deploy:gh": "scripts/deploy-gh.sh",
"lint": "tslint -c tslint.json src/*.ts test/*.ts src/**/*.ts test/**/*.ts",
"prestart": "node scripts/index-examples",
"prestart": "npm run build && npm run data && scripts/index-examples",
"start": "npm run watch & browser-sync start --server --files 'vega-lite.js' --index 'test-gallery.html'",
"poststart": "rm examples/all-examples.json",
"schema": "typescript-json-schema --required true src/schema/schema.ts Spec > vega-lite-schema.json",
"images": "scripts/generate-images.sh",
"presite": "tsc && npm run build && bower install",
"schema": "typescript-json-schema --required true src/spec.ts Spec > vega-lite-schema.json",
"presite": "tsc && npm run build && bower install && npm run data",
"site": "bundle exec jekyll serve --incremental",
"test": "tsc && npm run schema && mocha --recursive --require source-map-support/register test examples",
"pretest": "tsc && npm run data",
"test": "npm run schema && mocha --recursive --require source-map-support/register test examples",
"watch:build": "watchify src/vl.ts -p tsify -v -d -s vl -o 'exorcist vega-lite.js.map > vega-lite.js'",

@@ -36,0 +42,0 @@ "watch:test": "nodemon -x 'npm test && npm run lint'",

import {Channel, ROW, COLUMN, SHAPE, SIZE} from './channel';
/**
* Binning properties or boolean flag for determining whether to bin data or not.
*/
export interface BinProperties {
/**
* The minimum bin value to consider. If unspecified, the minimum value of the specified field is used.
*/
min?: number;
/**
* The maximum bin value to consider. If unspecified, the maximum value of the specified field is used.
*/
max?: number;
/**
* The number base to use for automatic bin determination (default is base 10).
*/
base?: number;
/**
* An exact step size to use between bins. If provided, options such as maxbins will be ignored.
*/
step?: number;
/**
* An array of allowable step sizes to choose from.
*/
steps?: number[];
/**
* A minimum allowable step size (particularly useful for integer values).
*/
minstep?: number;
/**
* Scale factors indicating allowable subdivisions. The default value is [5, 2], which indicates that for base 10 numbers (the default base), the method may consider dividing bin sizes by 5 and/or 2. For example, for an initial step size of 10, the method can check if bin sizes of 2 (= 10/5), 5 (= 10/2), or 1 (= 10/(5*2)) might also satisfy the given constraints.
*/
div?: number[];
/**
* Maximum number of bins.
* @minimum 2
*/
maxbins?: number;
}
export function autoMaxBins(channel: Channel): number {

@@ -4,0 +43,0 @@ switch (channel) {

@@ -39,3 +39,3 @@ /*

interface SupportedMark {
export interface SupportedMark {
point?: boolean;

@@ -94,3 +94,3 @@ tick?: boolean;

interface SupportedRole {
export interface SupportedRole {
measure: boolean;

@@ -97,0 +97,0 @@ dimension: boolean;

"use strict";
var axis_1 = require('../axis');
var channel_1 = require('../channel');
var fielddef_1 = require('../fielddef');
var type_1 = require('../type');
var util_1 = require('../util');
var type_1 = require('../type');
var channel_1 = require('../channel');
var enums_1 = require('../enums');
var util_2 = require('./util');
var common_1 = require('./common');
function compileInnerAxis(channel, model) {

@@ -43,3 +44,3 @@ var isCol = channel === channel_1.COLUMN, isRow = channel === channel_1.ROW, type = isCol ? 'x' : isRow ? 'y' : channel;

};
util_1.extend(def, util_2.formatMixins(model, channel, model.axis(channel).format));
util_1.extend(def, common_1.formatMixins(model, channel, model.axis(channel).format));
[

@@ -111,7 +112,7 @@ 'grid', 'layer', 'offset', 'orient', 'tickSize', 'ticks', 'title',

else if (channel === channel_1.COLUMN) {
return enums_1.AxisOrient.TOP;
return axis_1.AxisOrient.TOP;
}
else if (channel === channel_1.ROW) {
if (model.has(channel_1.Y) && model.axis(channel_1.Y).orient !== enums_1.AxisOrient.RIGHT) {
return enums_1.AxisOrient.RIGHT;
if (model.has(channel_1.Y) && model.axis(channel_1.Y).orient !== axis_1.AxisOrient.RIGHT) {
return axis_1.AxisOrient.RIGHT;
}

@@ -146,3 +147,3 @@ }

}
var fieldTitle = model.fieldTitle(channel);
var fieldTitle = fielddef_1.title(model.fieldDef(channel));
var maxLength;

@@ -189,3 +190,3 @@ if (axis.titleMaxLength) {

else {
if (channel === channel_1.X && (model.isDimension(channel_1.X) || fieldDef.type === type_1.TEMPORAL)) {
if (channel === channel_1.X && (fielddef_1.isDimension(fieldDef) || fieldDef.type === type_1.TEMPORAL)) {
labelsSpec.angle = { value: 270 };

@@ -192,0 +193,0 @@ }

@@ -1,8 +0,10 @@

import {Model} from './Model';
import {AxisOrient} from '../axis';
import {COLUMN, ROW, X, Y, Channel} from '../channel';
import {title as fieldDefTitle, isDimension} from '../fielddef';
import {NOMINAL, ORDINAL, TEMPORAL} from '../type';
import {contains, extend, truncate} from '../util';
import {NOMINAL, ORDINAL, TEMPORAL} from '../type';
import {COLUMN, ROW, X, Y, Channel} from '../channel';
import {AxisOrient} from '../enums';
import {formatMixins} from './util';
import {formatMixins} from './common';
import {Model} from './Model';
// https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#11-ambient-declarations

@@ -197,3 +199,3 @@ declare let exports;

// if not defined, automatically determine axis title from field def
const fieldTitle = model.fieldTitle(channel);
const fieldTitle = fieldDefTitle(model.fieldDef(channel));

@@ -250,3 +252,3 @@ let maxLength;

// auto rotate for X and Row
if (channel === X && (model.isDimension(X) || fieldDef.type === TEMPORAL)) {
if (channel === X && (isDimension(fieldDef) || fieldDef.type === TEMPORAL)) {
labelsSpec.angle = {value: 270};

@@ -253,0 +255,0 @@ } else if (channel === ROW && model.has(X)) {

@@ -8,6 +8,6 @@ "use strict";

var legend_1 = require('./legend');
var mark_1 = require('./mark');
var mark_1 = require('./mark/mark');
var scale_1 = require('./scale');
var util_1 = require('./util');
var util_2 = require('../util');
var common_1 = require('./common');
var util_1 = require('../util');
var data_2 = require('../data');

@@ -20,3 +20,3 @@ var channel_1 = require('../channel');

var config = model.config();
var output = util_2.extend(spec.name ? { name: spec.name } : {}, {
var output = util_1.extend(spec.name ? { name: spec.name } : {}, {
width: 1,

@@ -36,3 +36,3 @@ height: 1,

var spec = model.spec();
var rootGroup = util_2.extend({
var rootGroup = util_1.extend({
name: spec.name ? spec.name + '-root' : 'root',

@@ -51,8 +51,8 @@ type: 'group',

if (model.has(channel_1.ROW) || model.has(channel_1.COLUMN)) {
util_2.extend(rootGroup, facet_1.facetMixins(model, marks));
util_1.extend(rootGroup, facet_1.facetMixins(model, marks));
}
else {
util_1.applyConfig(rootGroup.properties.update, model.config().cell, util_1.FILL_STROKE_CONFIG.concat(['clip']));
common_1.applyConfig(rootGroup.properties.update, model.config().cell, common_1.FILL_STROKE_CONFIG.concat(['clip']));
rootGroup.marks = marks;
rootGroup.scales = scale_1.compileScales(model.channels(), model);
rootGroup.scales = scale_1.compileScales(model);
var axes = (model.has(channel_1.X) && model.axis(channel_1.X) ? [axis_1.compileAxis(channel_1.X, model)] : [])

@@ -59,0 +59,0 @@ .concat(model.has(channel_1.Y) && model.axis(channel_1.Y) ? [axis_1.compileAxis(channel_1.Y, model)] : []);

@@ -11,5 +11,5 @@ /**

import {compileLegends} from './legend';
import {compileMark} from './mark';
import {compileMark} from './mark/mark';
import {compileScales} from './scale';
import {applyConfig, FILL_STROKE_CONFIG} from './util';
import {applyConfig, FILL_STROKE_CONFIG} from './common';
import {extend} from '../util';

@@ -75,3 +75,3 @@

rootGroup.marks = marks;
rootGroup.scales = compileScales(model.channels(), model);
rootGroup.scales = compileScales(model);

@@ -78,0 +78,0 @@ const axes = (model.has(X) && model.axis(X) ? [compileAxis(X, model)] : [])

@@ -1,3 +0,3 @@

import {Encoding} from '../schema/encoding.schema';
import {Config} from '../schema/config.schema';
import {Encoding} from '../encoding';
import {Config} from '../config';
import {StackProperties} from './stack';

@@ -4,0 +4,0 @@

"use strict";
var vlFieldDef = require('../fielddef');
var util_1 = require('../util');
var enums_1 = require('../enums');
var scale_1 = require('../scale');
var bin_1 = require('../bin');

@@ -10,3 +10,3 @@ var channel_1 = require('../channel');

var type_1 = require('../type');
var scale_1 = require('./scale');
var scale_2 = require('./scale');
var time_1 = require('./time');

@@ -120,3 +120,3 @@ var aggregate_1 = require('../aggregate');

transform.push(binTrans);
if (scale_1.scaleType(scale, fieldDef, channel, model.mark()) === enums_1.ScaleType.ORDINAL || channel === channel_1.COLOR) {
if (scale_2.scaleType(scale, fieldDef, channel, model.mark()) === scale_1.ScaleType.ORDINAL || channel === channel_1.COLOR) {
transform.push({

@@ -193,3 +193,3 @@ type: 'formula',

var scale = model.scale(channel);
if (scale_1.scaleType(scale, fieldDef, channel, model.mark()) === enums_1.ScaleType.ORDINAL) {
if (scale_2.scaleType(scale, fieldDef, channel, model.mark()) === scale_1.ScaleType.ORDINAL) {
dims[fielddef_1.field(fieldDef, { binSuffix: '_range' })] = fielddef_1.field(fieldDef, { binSuffix: '_range' });

@@ -286,3 +286,3 @@ }

var scale = model.scale(channel);
if (scale && scale.type === enums_1.ScaleType.LOG) {
if (scale && scale.type === scale_1.ScaleType.LOG) {
dataTable.transform.push({

@@ -289,0 +289,0 @@ type: 'filter',

import * as vlFieldDef from '../fielddef';
import {extend, keys, vals, reduce, contains} from '../util';
import {Model} from './Model';
import {FieldDef} from '../schema/fielddef.schema';
import {VgData} from '../schema/vega.schema';
import {FieldDef} from '../fielddef';
import {VgData} from '../vega.schema';
import {StackProperties} from './stack';
import {ScaleType} from '../enums';
import {ScaleType} from '../scale';

@@ -9,0 +9,0 @@ import {autoMaxBins} from '../bin';

@@ -5,11 +5,12 @@ "use strict";

var channel_1 = require('../channel');
var fielddef_1 = require('../fielddef');
var axis_1 = require('./axis');
var scale_1 = require('./scale');
var util_2 = require('./util');
var common_1 = require('./common');
function facetMixins(model, marks) {
var hasRow = model.has(channel_1.ROW), hasCol = model.has(channel_1.COLUMN);
if (model.has(channel_1.ROW) && !model.isDimension(channel_1.ROW)) {
if (model.has(channel_1.ROW) && !fielddef_1.isDimension(model.encoding().row)) {
util.error('Row encoding should be ordinal.');
}
if (model.has(channel_1.COLUMN) && !model.isDimension(channel_1.COLUMN)) {
if (model.has(channel_1.COLUMN) && !fielddef_1.isDimension(model.encoding().column)) {
util.error('Col encoding should be ordinal.');

@@ -19,3 +20,3 @@ }

marks: [].concat(getFacetGuideGroups(model), [getFacetGroup(model, marks)]),
scales: scale_1.compileScales(model.channels(), model),
scales: scale_1.compileScales(model),
axes: [].concat(hasRow && model.axis(channel_1.ROW) ? [axis_1.compileAxis(channel_1.ROW, model)] : [], hasCol && model.axis(channel_1.COLUMN) ? [axis_1.compileAxis(channel_1.COLUMN, model)] : [])

@@ -73,4 +74,4 @@ };

};
util_2.applyConfig(facetGroupProperties, model.config().cell, util_2.FILL_STROKE_CONFIG.concat(['clip']));
util_2.applyConfig(facetGroupProperties, model.config().facet.cell, util_2.FILL_STROKE_CONFIG.concat(['clip']));
common_1.applyConfig(facetGroupProperties, model.config().cell, common_1.FILL_STROKE_CONFIG.concat(['clip']));
common_1.applyConfig(facetGroupProperties, model.config().facet.cell, common_1.FILL_STROKE_CONFIG.concat(['clip']));
return facetGroupProperties;

@@ -114,3 +115,3 @@ }

groupby: [model.field(channel_1.COLUMN)],
summarize: { '*': 'count' }
summarize: { '*': ['count'] }
}]

@@ -150,3 +151,3 @@ }

groupby: [model.field(channel_1.ROW)],
summarize: { '*': 'count' }
summarize: { '*': ['count'] }
}]

@@ -153,0 +154,0 @@ }

import * as util from '../util';
import {extend} from '../util';
import {COLUMN, ROW, X, Y} from '../channel';
import {isDimension} from '../fielddef';
import {Model} from './Model';

@@ -8,3 +9,3 @@

import {compileScales} from './scale';
import {applyConfig, FILL_STROKE_CONFIG} from './util';
import {applyConfig, FILL_STROKE_CONFIG} from './common';

@@ -17,3 +18,3 @@ /**

if (model.has(ROW) && !model.isDimension(ROW)) {
if (model.has(ROW) && !isDimension(model.encoding().row)) {
// TODO: add error to model instead

@@ -23,3 +24,3 @@ util.error('Row encoding should be ordinal.');

if (model.has(COLUMN) && !model.isDimension(COLUMN)) {
if (model.has(COLUMN) && !isDimension(model.encoding().column)) {
// TODO: add error to model instead

@@ -35,6 +36,3 @@ util.error('Col encoding should be ordinal.');

// assuming equal cellWidth here
scales: compileScales(
model.channels(), // TODO: with nesting, not all scale might be a root-level
model
),
scales: compileScales(model),
axes: [].concat(

@@ -159,3 +157,3 @@ hasRow && model.axis(ROW) ? [compileAxis(ROW, model)] : [],

groupby: [model.field(COLUMN)],
summarize: {'*': 'count'} // just a placeholder aggregation
summarize: {'*': ['count']} // just a placeholder aggregation
}]

@@ -203,3 +201,3 @@ }

groupby: [model.field(ROW)],
summarize: {'*': 'count'} // just a placeholder aggregation
summarize: {'*': ['count']} // just a placeholder aggregation
}]

@@ -206,0 +204,0 @@ }

@@ -1,2 +0,2 @@

import {VgData} from '../schema/vega.schema';
import {VgData} from '../vega.schema';

@@ -3,0 +3,0 @@ import {Model} from './Model';

@@ -6,3 +6,3 @@ "use strict";

var util_1 = require('../util');
var util_2 = require('./util');
var common_1 = require('./common');
var type_1 = require('../type');

@@ -14,6 +14,7 @@ var scale_1 = require('./scale');

var fieldDef = model.fieldDef(channel_1.COLOR);
var scale = useColorLegendScale(fieldDef) ?
var scale = model.scaleName(useColorLegendScale(fieldDef) ?
scale_1.COLOR_LEGEND :
model.scaleName(channel_1.COLOR);
defs.push(compileLegend(model, channel_1.COLOR, model.config().mark.filled ? { fill: scale } : { stroke: scale }));
channel_1.COLOR);
var def = model.config().mark.filled ? { fill: scale } : { stroke: scale };
defs.push(compileLegend(model, channel_1.COLOR, def));
}

@@ -69,3 +70,3 @@ if (model.has(channel_1.SIZE) && model.legend(channel_1.SIZE)) {

}
return util_2.formatMixins(model, channel, typeof legend !== 'boolean' ? legend.format : undefined);
return common_1.formatMixins(model, channel, typeof legend !== 'boolean' ? legend.format : undefined);
}

@@ -98,3 +99,3 @@ exports.formatMixins = formatMixins;

var filled = model.config().mark.filled;
util_2.applyMarkConfig(symbols, model, util_1.without(util_2.FILL_STROKE_CONFIG, [filled ? 'fill' : 'stroke']));
common_1.applyMarkConfig(symbols, model, util_1.without(common_1.FILL_STROKE_CONFIG, [filled ? 'fill' : 'stroke']));
if (filled) {

@@ -133,3 +134,3 @@ symbols.strokeWidth = { value: 0 };

text: {
scale: scale_1.COLOR_LEGEND,
scale: model.scaleName(scale_1.COLOR_LEGEND),
field: 'data'

@@ -142,3 +143,3 @@ }

text: {
scale: scale_1.COLOR_LEGEND_LABEL,
scale: model.scaleName(scale_1.COLOR_LEGEND_LABEL),
field: 'data'

@@ -151,3 +152,3 @@ }

text: {
template: '{{ datum.data | time:\'' + util_2.timeFormat(model, channel) + '\'}}'
template: '{{ datum.data | time:\'' + common_1.timeFormat(model, channel) + '\'}}'
}

@@ -154,0 +155,0 @@ };

@@ -1,3 +0,3 @@

import {FieldDef} from '../schema/fielddef.schema';
import {LegendProperties} from '../schema/legend.schema';
import {FieldDef} from '../fielddef';
import {LegendProperties} from '../legend';

@@ -9,3 +9,3 @@ import {COLOR, SIZE, SHAPE, Channel} from '../channel';

import {Model} from './Model';
import {applyMarkConfig, FILL_STROKE_CONFIG, formatMixins as utilFormatMixins, timeFormat} from './util';
import {applyMarkConfig, FILL_STROKE_CONFIG, formatMixins as utilFormatMixins, timeFormat} from './common';
import {ORDINAL} from '../type';

@@ -19,3 +19,3 @@ import {COLOR_LEGEND, COLOR_LEGEND_LABEL} from './scale';

const fieldDef = model.fieldDef(COLOR);
const scale = useColorLegendScale(fieldDef) ?
const scale = model.scaleName(useColorLegendScale(fieldDef) ?
// To produce ordinal legend (list, rather than linear range) with correct labels:

@@ -26,4 +26,7 @@ // - For an ordinal field, provide an ordinal scale that maps rank values to field values

COLOR_LEGEND :
model.scaleName(COLOR);
defs.push(compileLegend(model, COLOR, model.config().mark.filled ? { fill: scale } : { stroke: scale }));
COLOR
);
const def = model.config().mark.filled ? { fill: scale } : { stroke: scale };
defs.push(compileLegend(model, COLOR, def));
}

@@ -169,3 +172,3 @@

text: {
scale: COLOR_LEGEND,
scale: model.scaleName(COLOR_LEGEND),
field: 'data'

@@ -177,3 +180,3 @@ }

text: {
scale: COLOR_LEGEND_LABEL,
scale: model.scaleName(COLOR_LEGEND_LABEL),
field: 'data'

@@ -180,0 +183,0 @@ }

"use strict";
var config_schema_1 = require('../schema/config.schema');
var config_1 = require('../config');
var channel_1 = require('../channel');
var data_1 = require('../data');
var vlFieldDef = require('../fielddef');
var fielddef_1 = require('../fielddef');
var vlEncoding = require('../encoding');

@@ -10,7 +10,8 @@ var mark_1 = require('../mark');

var util_1 = require('../util');
var config_1 = require('./config');
var config_2 = require('./config');
var stack_1 = require('./stack');
var scale_1 = require('./scale');
var enums_1 = require('../enums');
var scale_2 = require('../scale');
var aggregate_1 = require('../aggregate');
var channel_2 = require('../channel');
;

@@ -23,3 +24,3 @@ var Model = (function () {

var encoding = this._spec.encoding = this._spec.encoding || {};
var config = this._config = util_1.mergeDeep(util_1.duplicate(config_schema_1.defaultConfig), spec.config);
var config = this._config = util_1.mergeDeep(util_1.duplicate(config_1.defaultConfig), spec.config);
vlEncoding.forEach(this._spec.encoding, function (fieldDef, channel) {

@@ -55,4 +56,4 @@ if (!channel_1.supportMark(channel, this._spec.mark)) {

padding: config.scale.padding,
useRawDomain: config.scale.useRawDomain,
bandSize: channel === channel_1.X && _scaleType === enums_1.ScaleType.ORDINAL && mark === mark_1.TEXT ?
includeRawDomain: config.scale.includeRawDomain,
bandSize: channel === channel_1.X && _scaleType === scale_2.ScaleType.ORDINAL && mark === mark_1.TEXT ?
config.scale.textBandWidth : config.scale.bandSize

@@ -83,3 +84,3 @@ }, channelScale);

this._stack = stack_1.compileStackProperties(mark, encoding, scale, config);
this._config.mark = config_1.compileMarkConfig(mark, encoding, config, this._stack);
this._config.mark = config_2.compileMarkConfig(mark, encoding, config, this._stack);
}

@@ -118,5 +119,2 @@ Model.prototype.stack = function () {

};
Model.prototype.is = function (mark) {
return this._spec.mark === mark;
};
Model.prototype.has = function (channel) {

@@ -137,16 +135,13 @@ return vlEncoding.has(this._spec.encoding, channel);

opt = util_1.extend({
binSuffix: scale_1.scaleType(scale, fieldDef, channel, this.mark()) === enums_1.ScaleType.ORDINAL ? '_range' : '_start'
binSuffix: scale_1.scaleType(scale, fieldDef, channel, this.mark()) === scale_2.ScaleType.ORDINAL ? '_range' : '_start'
}, opt);
}
return vlFieldDef.field(fieldDef, opt);
return fielddef_1.field(fieldDef, opt);
};
Model.prototype.fieldTitle = function (channel) {
return vlFieldDef.title(this._spec.encoding[channel]);
Model.prototype.channelWithScales = function () {
var model = this;
return channel_2.CHANNELS.filter(function (channel) {
return !!model.scale(channel);
});
};
Model.prototype.channels = function () {
return vlEncoding.channels(this._spec.encoding);
};
Model.prototype.map = function (f, t) {
return vlEncoding.map(this._spec.encoding, f, t);
};
Model.prototype.reduce = function (f, init, t) {

@@ -161,13 +156,4 @@ return vlEncoding.reduce(this._spec.encoding, f, init, t);

var scale = this.scale(channel);
return this.has(channel) && scale_1.scaleType(scale, fieldDef, channel, this.mark()) === enums_1.ScaleType.ORDINAL;
return this.has(channel) && scale_1.scaleType(scale, fieldDef, channel, this.mark()) === scale_2.ScaleType.ORDINAL;
};
Model.prototype.isDimension = function (channel) {
return vlFieldDef.isDimension(this.fieldDef(channel));
};
Model.prototype.isMeasure = function (channel) {
return vlFieldDef.isMeasure(this.fieldDef(channel));
};
Model.prototype.isAggregate = function () {
return vlEncoding.isAggregate(this._spec.encoding);
};
Model.prototype.isFacet = function () {

@@ -177,3 +163,3 @@ return this.has(channel_1.ROW) || this.has(channel_1.COLUMN);

Model.prototype.dataTable = function () {
return this.isAggregate() ? data_1.SUMMARY : data_1.SOURCE;
return vlEncoding.isAggregate(this._spec.encoding) ? data_1.SUMMARY : data_1.SOURCE;
};

@@ -205,32 +191,2 @@ Model.prototype.data = function () {

};
Model.prototype.sizeValue = function (channel) {
if (channel === void 0) { channel = channel_1.SIZE; }
var fieldDef = this.fieldDef(channel_1.SIZE);
if (fieldDef && fieldDef.value !== undefined) {
return fieldDef.value;
}
var scaleConfig = this.config().scale;
switch (this.mark()) {
case mark_1.TEXT:
return this.config().mark.fontSize;
case mark_1.BAR:
if (this.config().mark.barSize) {
return this.config().mark.barSize;
}
return this.isOrdinalScale(channel) ?
this.scale(channel).bandSize - 1 :
!this.has(channel) ?
scaleConfig.bandSize - 1 :
this.config().mark.barThinSize;
case mark_1.TICK:
if (this.config().mark.tickSize) {
return this.config().mark.tickSize;
}
var bandSize = this.has(channel) ?
this.scale(channel).bandSize :
scaleConfig.bandSize;
return bandSize / 1.5;
}
return this.config().mark.size;
};
return Model;

@@ -237,0 +193,0 @@ }());

@@ -1,15 +0,14 @@

import {Spec} from '../schema/schema';
import {AxisProperties} from '../schema/axis.schema';
import {LegendProperties} from '../schema/legend.schema';
import {Scale} from '../schema/scale.schema';
import {Encoding} from '../schema/encoding.schema';
import {FieldDef} from '../schema/fielddef.schema';
import {defaultConfig, Config} from '../schema/config.schema';
import {Spec} from '../spec';
import {AxisProperties} from '../axis';
import {LegendProperties} from '../legend';
import {Scale} from '../scale';
import {Encoding} from '../encoding';
import {FieldDef} from '../fielddef';
import {defaultConfig, Config} from '../config';
import {COLUMN, ROW, X, Y, COLOR, SHAPE, SIZE, TEXT, PATH, ORDER, Channel, supportMark} from '../channel';
import {SOURCE, SUMMARY} from '../data';
import * as vlFieldDef from '../fielddef';
import {FieldRefOption} from '../fielddef';
import {FieldRefOption, field} from '../fielddef';
import * as vlEncoding from '../encoding';
import {Mark, BAR, TICK, TEXT as TEXTMARK} from '../mark';
import {Mark, TEXT as TEXTMARK} from '../mark';

@@ -22,4 +21,5 @@ import {getFullName, QUANTITATIVE} from '../type';

import {scaleType} from './scale';
import {ScaleType} from '../enums';
import {ScaleType} from '../scale';
import {AggregateOp} from '../aggregate';
import {CHANNELS} from '../channel';

@@ -113,3 +113,3 @@ export interface ScaleMap {

padding: config.scale.padding,
useRawDomain: config.scale.useRawDomain,
includeRawDomain: config.scale.includeRawDomain,
bandSize: channel === X && _scaleType === ScaleType.ORDINAL && mark === TEXTMARK ?

@@ -200,6 +200,2 @@ config.scale.textBandWidth : config.scale.bandSize

public is(mark: Mark) {
return this._spec.mark === mark;
}
public has(channel: Channel) {

@@ -230,17 +226,12 @@ return vlEncoding.has(this._spec.encoding, channel);

return vlFieldDef.field(fieldDef, opt);
return field(fieldDef, opt);
}
public fieldTitle(channel: Channel): string {
return vlFieldDef.title(this._spec.encoding[channel]);
public channelWithScales(): Channel[] {
const model = this;
return CHANNELS.filter(function(channel) {
return !!model.scale(channel);
});
}
public channels(): Channel[] {
return vlEncoding.channels(this._spec.encoding);
}
public map(f: (fd: FieldDef, c: Channel, e: Encoding) => any, t?: any) {
return vlEncoding.map(this._spec.encoding, f, t);
}
public reduce(f: (acc: any, fd: FieldDef, c: Channel, e: Encoding) => any, init, t?: any) {

@@ -261,14 +252,2 @@ return vlEncoding.reduce(this._spec.encoding, f, init, t);

public isDimension(channel: Channel) {
return vlFieldDef.isDimension(this.fieldDef(channel));
}
public isMeasure(channel: Channel) {
return vlFieldDef.isMeasure(this.fieldDef(channel));
}
public isAggregate() {
return vlEncoding.isAggregate(this._spec.encoding);
}
public isFacet() {

@@ -279,3 +258,3 @@ return this.has(ROW) || this.has(COLUMN);

public dataTable() {
return this.isAggregate() ? SUMMARY : SOURCE;
return vlEncoding.isAggregate(this._spec.encoding) ? SUMMARY : SOURCE;
}

@@ -306,2 +285,3 @@

public axis(channel: Channel): AxisProperties {

@@ -316,42 +296,6 @@ return this._axis[channel];

/** returns scale name for a given channel */
public scaleName(channel: Channel): string {
public scaleName(channel: Channel|string): string {
const name = this.spec().name;
return (name ? name + '-' : '') + channel;
}
public sizeValue(channel: Channel = SIZE) {
const fieldDef = this.fieldDef(SIZE);
if (fieldDef && fieldDef.value !== undefined) {
return fieldDef.value;
}
const scaleConfig = this.config().scale;
switch (this.mark()) {
case TEXTMARK:
return this.config().mark.fontSize; // font size 10 by default
case BAR:
if (this.config().mark.barSize) {
return this.config().mark.barSize;
}
// BAR's size is applied on either X or Y
return this.isOrdinalScale(channel) ?
// For ordinal scale or single bar, we can use bandSize - 1
// (-1 so that the border of the bar falls on exact pixel)
this.scale(channel).bandSize - 1 :
!this.has(channel) ?
scaleConfig.bandSize - 1 :
// otherwise, set to thinBarWidth by default
this.config().mark.barThinSize;
case TICK:
if (this.config().mark.tickSize) {
return this.config().mark.tickSize;
}
const bandSize = this.has(channel) ?
this.scale(channel).bandSize :
scaleConfig.bandSize;
return bandSize / 1.5;
}
return this.config().mark.size;
}
}

@@ -9,3 +9,4 @@ "use strict";

var time_1 = require('./time');
var enums_1 = require('../enums');
var scale_1 = require('../scale');
var config_1 = require('../config');
var timeunit_1 = require('../timeunit');

@@ -15,5 +16,4 @@ var fielddef_1 = require('../fielddef');

exports.COLOR_LEGEND_LABEL = 'color_legend_label';
function compileScales(channels, model) {
return channels.filter(channel_1.hasScale)
.reduce(function (scales, channel) {
function compileScales(model) {
return model.channelWithScales().reduce(function (scales, channel) {
var fieldDef = model.fieldDef(channel);

@@ -58,3 +58,3 @@ if (channel === channel_1.COLOR && model.legend(channel_1.COLOR) && (fieldDef.type === type_1.ORDINAL || fieldDef.bin || fieldDef.timeUnit)) {

return {
name: exports.COLOR_LEGEND,
name: model.scaleName(exports.COLOR_LEGEND),
type: 'ordinal',

@@ -70,3 +70,3 @@ domain: {

return {
name: exports.COLOR_LEGEND_LABEL,
name: model.scaleName(exports.COLOR_LEGEND_LABEL),
type: 'ordinal',

@@ -93,3 +93,3 @@ domain: {

if (util_1.contains([channel_1.ROW, channel_1.COLUMN, channel_1.SHAPE], channel)) {
return enums_1.ScaleType.ORDINAL;
return scale_1.ScaleType.ORDINAL;
}

@@ -101,11 +101,11 @@ if (scale.type !== undefined) {

case type_1.NOMINAL:
return enums_1.ScaleType.ORDINAL;
return scale_1.ScaleType.ORDINAL;
case type_1.ORDINAL:
if (channel === channel_1.COLOR) {
return enums_1.ScaleType.LINEAR;
return scale_1.ScaleType.LINEAR;
}
return enums_1.ScaleType.ORDINAL;
return scale_1.ScaleType.ORDINAL;
case type_1.TEMPORAL:
if (channel === channel_1.COLOR) {
return enums_1.ScaleType.TIME;
return scale_1.ScaleType.TIME;
}

@@ -117,13 +117,13 @@ if (fieldDef.timeUnit) {

case timeunit_1.TimeUnit.MONTH:
return enums_1.ScaleType.ORDINAL;
return scale_1.ScaleType.ORDINAL;
default:
return enums_1.ScaleType.TIME;
return scale_1.ScaleType.TIME;
}
}
return enums_1.ScaleType.TIME;
return scale_1.ScaleType.TIME;
case type_1.QUANTITATIVE:
if (fieldDef.bin) {
return util_1.contains([channel_1.X, channel_1.Y, channel_1.COLOR], channel) ? enums_1.ScaleType.LINEAR : enums_1.ScaleType.ORDINAL;
return util_1.contains([channel_1.X, channel_1.Y, channel_1.COLOR], channel) ? scale_1.ScaleType.LINEAR : scale_1.ScaleType.ORDINAL;
}
return enums_1.ScaleType.LINEAR;
return scale_1.ScaleType.LINEAR;
}

@@ -156,3 +156,3 @@ return null;

if (stack && channel === stack.fieldChannel) {
if (stack.offset === enums_1.StackOffset.NORMALIZE) {
if (stack.offset === config_1.StackOffset.NORMALIZE) {
return [0, 1];

@@ -165,4 +165,4 @@ }

}
var useRawDomain = _useRawDomain(scale, model, channel, scaleType), sort = domainSort(model, channel, scaleType);
if (useRawDomain) {
var includeRawDomain = _includeRawDomain(scale, model, channel, scaleType), sort = domainSort(model, channel, scaleType);
if (includeRawDomain) {
return {

@@ -174,3 +174,3 @@ data: data_1.SOURCE,

else if (fieldDef.bin) {
return scaleType === 'ordinal' ? {
return scaleType === scale_1.ScaleType.ORDINAL ? {
data: model.dataTable(),

@@ -209,3 +209,3 @@ field: model.field(channel, { binSuffix: '_range' }),

function domainSort(model, channel, scaleType) {
if (scaleType !== 'ordinal') {
if (scaleType !== scale_1.ScaleType.ORDINAL) {
return undefined;

@@ -226,13 +226,13 @@ }

exports.domainSort = domainSort;
function _useRawDomain(scale, model, channel, scaleType) {
function _includeRawDomain(scale, model, channel, scaleType) {
var fieldDef = model.fieldDef(channel);
return scale.useRawDomain &&
return scale.includeRawDomain &&
fieldDef.aggregate &&
aggregate_1.SHARED_DOMAIN_OPS.indexOf(fieldDef.aggregate) >= 0 &&
((fieldDef.type === type_1.QUANTITATIVE && !fieldDef.bin) ||
(fieldDef.type === type_1.TEMPORAL && util_1.contains(['time', 'utc'], scaleType)));
(fieldDef.type === type_1.TEMPORAL && util_1.contains([scale_1.ScaleType.TIME, scale_1.ScaleType.UTC], scaleType)));
}
function rangeMixins(scale, model, channel, scaleType) {
var fieldDef = model.fieldDef(channel), scaleConfig = model.config().scale;
if (scaleType === 'ordinal' && scale.bandSize && util_1.contains([channel_1.X, channel_1.Y], channel)) {
if (scaleType === scale_1.ScaleType.ORDINAL && scale.bandSize && util_1.contains([channel_1.X, channel_1.Y], channel)) {
return { bandSize: scale.bandSize };

@@ -255,3 +255,3 @@ }

case channel_1.SIZE:
if (model.is(mark_1.BAR)) {
if (model.mark() === mark_1.BAR) {
if (scaleConfig.barSizeRange !== undefined) {

@@ -263,3 +263,3 @@ return { range: scaleConfig.barSizeRange };

}
else if (model.is(mark_1.TEXT)) {
else if (model.mark() === mark_1.TEXT) {
return { range: scaleConfig.fontSizeRange };

@@ -270,4 +270,4 @@ }

}
var xIsMeasure = model.isMeasure(channel_1.X);
var yIsMeasure = model.isMeasure(channel_1.Y);
var xIsMeasure = fielddef_1.isMeasure(model.encoding().x);
var yIsMeasure = fielddef_1.isMeasure(model.encoding().y);
var bandSize = xIsMeasure !== yIsMeasure ?

@@ -293,3 +293,4 @@ model.scale(xIsMeasure ? channel_1.Y : channel_1.X).bandSize :

function clamp(prop, scaleType) {
if (util_1.contains(['linear', 'pow', 'sqrt', 'log', 'time', 'utc'], scaleType)) {
if (util_1.contains([scale_1.ScaleType.LINEAR, scale_1.ScaleType.POW, scale_1.ScaleType.SQRT,
scale_1.ScaleType.LOG, scale_1.ScaleType.TIME, scale_1.ScaleType.UTC], scaleType)) {
return prop;

@@ -301,3 +302,3 @@ }

function exponent(prop, scaleType) {
if (scaleType === 'pow') {
if (scaleType === scale_1.ScaleType.POW) {
return prop;

@@ -309,7 +310,8 @@ }

function nice(prop, scaleType, channel, fieldDef) {
if (util_1.contains(['linear', 'pow', 'sqrt', 'log', 'time', 'utc', 'quantize'], scaleType)) {
if (util_1.contains([scale_1.ScaleType.LINEAR, scale_1.ScaleType.POW, scale_1.ScaleType.SQRT, scale_1.ScaleType.LOG,
scale_1.ScaleType.TIME, scale_1.ScaleType.UTC, scale_1.ScaleType.QUANTIZE], scaleType)) {
if (prop !== undefined) {
return prop;
}
if (util_1.contains(['time', 'utc'], scaleType)) {
if (util_1.contains([scale_1.ScaleType.TIME, scale_1.ScaleType.UTC], scaleType)) {
return time_1.smallestUnit(fieldDef.timeUnit);

@@ -323,3 +325,3 @@ }

function padding(prop, scaleType, channel) {
if (scaleType === 'ordinal' && util_1.contains([channel_1.X, channel_1.Y], channel)) {
if (scaleType === scale_1.ScaleType.ORDINAL && util_1.contains([channel_1.X, channel_1.Y], channel)) {
return prop;

@@ -331,3 +333,3 @@ }

function points(__, scaleType, channel) {
if (scaleType === 'ordinal' && util_1.contains([channel_1.X, channel_1.Y], channel)) {
if (scaleType === scale_1.ScaleType.ORDINAL && util_1.contains([channel_1.X, channel_1.Y], channel)) {
return true;

@@ -346,3 +348,3 @@ }

function zero(prop, scaleType, channel, fieldDef) {
if (!util_1.contains(['time', 'utc', 'ordinal'], scaleType)) {
if (!util_1.contains([scale_1.ScaleType.TIME, scale_1.ScaleType.UTC, scale_1.ScaleType.ORDINAL], scaleType)) {
if (prop !== undefined) {

@@ -349,0 +351,0 @@ return prop;

// https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#11-ambient-declarations
declare var exports;
import {FieldDef} from '../schema/fielddef.schema';
import {Scale} from '../schema/scale.schema';
import {FieldDef} from '../fielddef';

@@ -15,5 +14,6 @@ import {contains, extend} from '../util';

import {rawDomain, smallestUnit} from './time';
import {ScaleType, StackOffset} from '../enums';
import {Scale, ScaleType} from '../scale';
import {StackOffset} from '../config';
import {TimeUnit} from '../timeunit';
import {field} from '../fielddef';
import {field, isMeasure} from '../fielddef';

@@ -29,5 +29,4 @@ /**

export function compileScales(channels: Channel[], model: Model) {
return channels.filter(hasScale)
.reduce(function(scales: any[], channel: Channel) {
export function compileScales(model: Model) {
return model.channelWithScales().reduce(function(scales: any[], channel: Channel) {
const fieldDef = model.fieldDef(channel);

@@ -96,3 +95,3 @@

return {
name: COLOR_LEGEND,
name: model.scaleName(COLOR_LEGEND),
type: 'ordinal',

@@ -113,3 +112,3 @@ domain: {

return {
name: COLOR_LEGEND_LABEL,
name: model.scaleName(COLOR_LEGEND_LABEL),
type: 'ordinal',

@@ -184,3 +183,3 @@ domain: {

export function domain(scale: Scale, model: Model, channel:Channel, scaleType: string): any {
export function domain(scale: Scale, model: Model, channel:Channel, scaleType: ScaleType): any {
const fieldDef = model.fieldDef(channel);

@@ -224,6 +223,6 @@

const useRawDomain = _useRawDomain(scale, model, channel, scaleType),
const includeRawDomain = _includeRawDomain(scale, model, channel, scaleType),
sort = domainSort(model, channel, scaleType);
if (useRawDomain) { // useRawDomain - only Q/T
if (includeRawDomain) { // includeRawDomain - only Q/T
return {

@@ -234,3 +233,3 @@ data: SOURCE,

} else if (fieldDef.bin) { // bin
return scaleType === 'ordinal' ? {
return scaleType === ScaleType.ORDINAL ? {
// ordinal bin scale takes domain from bin_range, ordered by bin_start

@@ -271,4 +270,4 @@ data: model.dataTable(),

export function domainSort(model: Model, channel: Channel, scaleType: string): any {
if (scaleType !== 'ordinal') {
export function domainSort(model: Model, channel: Channel, scaleType: ScaleType): any {
if (scaleType !== ScaleType.ORDINAL) {
return undefined;

@@ -296,12 +295,12 @@ }

/**
* Determine if useRawDomain should be activated for this scale.
* Determine if includeRawDomain should be activated for this scale.
* @return {Boolean} Returns true if all of the following conditons applies:
* 1. `useRawDomain` is enabled either through scale or config
* 1. `includeRawDomain` is enabled either through scale or config
* 2. Aggregation function is not `count` or `sum`
* 3. The scale is quantitative or time scale.
*/
function _useRawDomain (scale: Scale, model: Model, channel: Channel, scaleType: string) {
function _includeRawDomain (scale: Scale, model: Model, channel: Channel, scaleType: ScaleType) {
const fieldDef = model.fieldDef(channel);
return scale.useRawDomain && // if useRawDomain is enabled
return scale.includeRawDomain && // if includeRawDomain is enabled
// only applied to aggregate table

@@ -318,3 +317,3 @@ fieldDef.aggregate &&

// T uses non-ordinal scale when there's no unit or when the unit is not ordinal.
(fieldDef.type === TEMPORAL && contains(['time', 'utc'], scaleType))
(fieldDef.type === TEMPORAL && contains([ScaleType.TIME, ScaleType.UTC], scaleType))
);

@@ -324,3 +323,3 @@ }

export function rangeMixins(scale: Scale, model: Model, channel: Channel, scaleType: string): any {
export function rangeMixins(scale: Scale, model: Model, channel: Channel, scaleType: ScaleType): any {
// TODO: need to add rule for quantile, quantize, threshold scale

@@ -331,3 +330,3 @@

if (scaleType === 'ordinal' && scale.bandSize && contains([X, Y], channel)) {
if (scaleType === ScaleType.ORDINAL && scale.bandSize && contains([X, Y], channel)) {
return {bandSize: scale.bandSize};

@@ -356,3 +355,3 @@ }

case SIZE:
if (model.is(BAR)) {
if (model.mark() === BAR) {
if (scaleConfig.barSizeRange !== undefined) {

@@ -363,3 +362,3 @@ return {range: scaleConfig.barSizeRange};

return {range: [ model.config().mark.barThinSize, model.scale(dimension).bandSize]};
} else if (model.is(TEXT_MARK)) {
} else if (model.mark() === TEXT_MARK) {
return {range: scaleConfig.fontSizeRange };

@@ -372,4 +371,4 @@ }

const xIsMeasure = model.isMeasure(X);
const yIsMeasure = model.isMeasure(Y);
const xIsMeasure = isMeasure(model.encoding().x);
const yIsMeasure = isMeasure(model.encoding().y);

@@ -400,6 +399,7 @@ const bandSize = xIsMeasure !== yIsMeasure ?

export function clamp(prop: boolean, scaleType: string) {
export function clamp(prop: boolean, scaleType: ScaleType) {
// Only works for scale with both continuous domain continuous range
// (Doesn't work for quantize, quantile, threshold, ordinal)
if (contains(['linear', 'pow', 'sqrt', 'log', 'time', 'utc'], scaleType)) {
if (contains([ScaleType.LINEAR, ScaleType.POW, ScaleType.SQRT,
ScaleType.LOG, ScaleType.TIME, ScaleType.UTC], scaleType)) {
return prop;

@@ -410,4 +410,4 @@ }

export function exponent(prop: number, scaleType: string) {
if (scaleType === 'pow') {
export function exponent(prop: number, scaleType: ScaleType) {
if (scaleType === ScaleType.POW) {
return prop;

@@ -418,8 +418,9 @@ }

export function nice(prop: boolean|string, scaleType: string, channel: Channel, fieldDef: FieldDef) {
if (contains(['linear', 'pow', 'sqrt', 'log', 'time', 'utc', 'quantize'], scaleType)) {
export function nice(prop: boolean|string, scaleType: ScaleType, channel: Channel, fieldDef: FieldDef) {
if (contains([ScaleType.LINEAR, ScaleType.POW, ScaleType.SQRT, ScaleType.LOG,
ScaleType.TIME, ScaleType.UTC, ScaleType.QUANTIZE], scaleType)) {
if (prop !== undefined) {
return prop;
}
if (contains(['time', 'utc'], scaleType)) {
if (contains([ScaleType.TIME, ScaleType.UTC], scaleType)) {
return smallestUnit(fieldDef.timeUnit);

@@ -433,3 +434,3 @@ }

export function padding(prop: number, scaleType: string, channel: Channel) {
export function padding(prop: number, scaleType: ScaleType, channel: Channel) {
/* Padding is only allowed for X and Y.

@@ -443,3 +444,3 @@ *

*/
if (scaleType === 'ordinal' && contains([X, Y], channel)) {
if (scaleType === ScaleType.ORDINAL && contains([X, Y], channel)) {
return prop;

@@ -450,4 +451,4 @@ }

export function points(__, scaleType: string, channel: Channel) {
if (scaleType === 'ordinal' && contains([X, Y], channel)) {
export function points(__, scaleType: ScaleType, channel: Channel) {
if (scaleType === ScaleType.ORDINAL && contains([X, Y], channel)) {
// We always use ordinal point scale for x and y.

@@ -460,3 +461,3 @@ // Thus `points` isn't included in the scale's schema.

export function round(prop: boolean, scaleType: string, channel: Channel) {
export function round(prop: boolean, scaleType: ScaleType, channel: Channel) {
if (contains([X, Y, ROW, COLUMN, SIZE], channel) && prop !== undefined) {

@@ -469,5 +470,5 @@ return prop;

export function zero(prop: boolean, scaleType: string, channel: Channel, fieldDef: FieldDef) {
export function zero(prop: boolean, scaleType: ScaleType, channel: Channel, fieldDef: FieldDef) {
// only applicable for non-ordinal scale
if (!contains(['time', 'utc', 'ordinal'], scaleType)) {
if (!contains([ScaleType.TIME, ScaleType.UTC, ScaleType.ORDINAL], scaleType)) {
if (prop !== undefined) {

@@ -474,0 +475,0 @@ return prop;

"use strict";
var channel_1 = require('../channel');
var enums_1 = require('../enums');
var scale_1 = require('../scale');
var config_1 = require('../config');
var mark_1 = require('../mark');

@@ -8,4 +9,4 @@ var fielddef_1 = require('../fielddef');

var util_1 = require('../util');
var util_2 = require('./util');
var scale_1 = require('./scale');
var common_1 = require('./common');
var scale_2 = require('./scale');
function compileStackProperties(mark, encoding, scale, config) {

@@ -15,3 +16,3 @@ var stackFields = getStackFields(mark, encoding, scale);

util_1.contains([mark_1.BAR, mark_1.AREA], mark) &&
config.mark.stacked !== enums_1.StackOffset.NONE &&
config.mark.stacked !== config_1.StackOffset.NONE &&
encoding_1.isAggregate(encoding)) {

@@ -51,3 +52,3 @@ var isXMeasure = encoding_1.has(encoding, channel_1.X) && fielddef_1.isMeasure(encoding.x), isYMeasure = encoding_1.has(encoding, channel_1.Y) && fielddef_1.isMeasure(encoding.y);

fields.push(fielddef_1.field(fieldDef, {
binSuffix: scale_1.scaleType(scale[channel], fieldDef, channel, mark) === enums_1.ScaleType.ORDINAL ? '_range' : '_start'
binSuffix: scale_2.scaleType(scale[channel], fieldDef, channel, mark) === scale_1.ScaleType.ORDINAL ? '_range' : '_start'
}));

@@ -75,3 +76,3 @@ }

var sortby = model.has(channel_1.ORDER) ?
(util_1.isArray(encoding[channel_1.ORDER]) ? encoding[channel_1.ORDER] : [encoding[channel_1.ORDER]]).map(util_2.sortField) :
(util_1.isArray(encoding[channel_1.ORDER]) ? encoding[channel_1.ORDER] : [encoding[channel_1.ORDER]]).map(common_1.sortField) :
stack.stackFields.map(function (field) {

@@ -78,0 +79,0 @@ return '-' + field;

@@ -1,7 +0,8 @@

import {Encoding} from '../schema/encoding.schema';
import {Config} from '../schema/config.schema';
import {FieldDef} from '../schema/fielddef.schema';
import {Encoding} from '../encoding';
import {Config} from '../config';
import {FieldDef} from '../fielddef';
import {Model, ScaleMap} from './Model';
import {Channel, X, Y, COLOR, DETAIL, ORDER} from '../channel';
import {ScaleType, StackOffset} from '../enums';
import {ScaleType} from '../scale';
import {StackOffset} from '../config';
import {BAR, AREA, Mark} from '../mark';

@@ -11,3 +12,3 @@ import {field, isMeasure} from '../fielddef';

import {isArray, contains} from '../util';
import {sortField} from './util';
import {sortField} from './common';

@@ -30,3 +31,3 @@ import {scaleType} from './scale';

// TODO: put all vega interface in one place
interface StackTransform {
export interface StackTransform {
type: string;

@@ -33,0 +34,0 @@ offset?: any;

"use strict";
var type_1 = require('./type');
(function (DataFormat) {
DataFormat[DataFormat["JSON"] = 'json'] = "JSON";
DataFormat[DataFormat["CSV"] = 'csv'] = "CSV";
DataFormat[DataFormat["TSV"] = 'tsv'] = "TSV";
})(exports.DataFormat || (exports.DataFormat = {}));
var DataFormat = exports.DataFormat;
exports.SUMMARY = 'summary';

@@ -8,8 +14,8 @@ exports.SOURCE = 'source';

exports.types = {
'boolean': type_1.NOMINAL,
'number': type_1.QUANTITATIVE,
'integer': type_1.QUANTITATIVE,
'date': type_1.TEMPORAL,
'string': type_1.NOMINAL
'boolean': type_1.Type.NOMINAL,
'number': type_1.Type.QUANTITATIVE,
'integer': type_1.Type.QUANTITATIVE,
'date': type_1.Type.TEMPORAL,
'string': type_1.Type.NOMINAL
};
//# sourceMappingURL=data.js.map
/*
* Constants and utilities for data.
*/
import {Type} from './type';
import {NOMINAL, QUANTITATIVE, TEMPORAL} from './type';
export enum DataFormat {
JSON = 'json' as any,
CSV = 'csv' as any,
TSV = 'tsv' as any,
}
export interface Data {
formatType?: DataFormat;
url?: string;
/**
* Pass array of objects instead of a url to a file.
*/
values?: any[];
}
export const SUMMARY = 'summary';

@@ -13,9 +28,9 @@ export const SOURCE = 'source';

/** Mapping from datalib's inferred type to Vega-lite's type */
// TODO: ALL_CAPS
// TODO: consider if we can remove
export const types = {
'boolean': NOMINAL,
'number': QUANTITATIVE,
'integer': QUANTITATIVE,
'date': TEMPORAL,
'string': NOMINAL
'boolean': Type.NOMINAL,
'number': Type.QUANTITATIVE,
'integer': Type.QUANTITATIVE,
'date': Type.TEMPORAL,
'string': Type.NOMINAL
};
// utility for encoding mapping
import {Encoding} from './schema/encoding.schema';
import {FieldDef} from './schema/fielddef.schema';
import {FieldDef, PositionChannelDef, FacetChannelDef, ChannelDefWithLegend, OrderChannelDef} from './fielddef';
import {Channel, CHANNELS} from './channel';
import {isArray, any as anyIn} from './util';
export interface Encoding {
x?: PositionChannelDef;
y?: PositionChannelDef;
row?: FacetChannelDef;
column?: FacetChannelDef;
color?: ChannelDefWithLegend;
size?: ChannelDefWithLegend;
shape?: ChannelDefWithLegend; // TODO: maybe distinguish ordinal-only
detail?: FieldDef | FieldDef[];
text?: FieldDef;
label?: FieldDef;
path?: OrderChannelDef | OrderChannelDef[];
order?: OrderChannelDef | OrderChannelDef[];
}
export function countRetinal(encoding: Encoding) {

@@ -8,0 +24,0 @@ let count = 0;

"use strict";
var aggregate_1 = require('./aggregate');
var timeunit_1 = require('./timeunit');
var type_1 = require('./type');
var util_1 = require('./util');
var type_1 = require('./type');
var timeunit_1 = require('./timeunit');
var aggregate_1 = require('./aggregate');
exports.aggregate = {
type: 'string',
enum: aggregate_1.AGGREGATE_OPS,
supportedEnums: {
quantitative: aggregate_1.AGGREGATE_OPS,
ordinal: ['median', 'min', 'max'],
nominal: [],
temporal: ['mean', 'median', 'min', 'max'],
'': ['count']
},
supportedTypes: util_1.toMap([type_1.QUANTITATIVE, type_1.NOMINAL, type_1.ORDINAL, type_1.TEMPORAL, ''])
};
function field(fieldDef, opt) {

@@ -7,0 +19,0 @@ if (opt === void 0) { opt = {}; }

// utility for a field definition object
import {FieldDef} from './schema/fielddef.schema';
import {contains, getbins} from './util';
import {NOMINAL, ORDINAL, QUANTITATIVE, TEMPORAL} from './type';
import {AggregateOp, AGGREGATE_OPS} from './aggregate';
import {AxisProperties} from './axis';
import {BinProperties} from './bin';
import {LegendProperties} from './legend';
import {Scale} from './scale';
import {SortField, SortOrder} from './sort';
import {TimeUnit} from './timeunit';
import {AggregateOp} from './aggregate';
import {Type, NOMINAL, ORDINAL, QUANTITATIVE, TEMPORAL} from './type';
import {contains, getbins, toMap} from './util';
/**
* Interface for any kind of FieldDef;
* For simplicity, we do not declare multiple interfaces of FieldDef like
* we do for JSON schema.
*/
export interface FieldDef {
field?: string;
type?: Type;
value?: number | string | boolean;
// function
timeUnit?: TimeUnit;
bin?: boolean | BinProperties;
aggregate?: AggregateOp;
// TODO: maybe extend this in other app?
// unused metadata -- for other application
displayName?: string;
}
export const aggregate = {
type: 'string',
enum: AGGREGATE_OPS,
supportedEnums: {
quantitative: AGGREGATE_OPS,
ordinal: ['median','min','max'],
nominal: [],
temporal: ['mean', 'median', 'min', 'max'], // TODO: revise what should time support
'': ['count']
},
supportedTypes: toMap([QUANTITATIVE, NOMINAL, ORDINAL, TEMPORAL, ''])
};
export interface ChannelDefWithScale extends FieldDef {
scale?: Scale;
sort?: SortField | SortOrder;
}
export interface PositionChannelDef extends ChannelDefWithScale {
axis?: boolean | AxisProperties;
}
export interface ChannelDefWithLegend extends ChannelDefWithScale {
legend?: LegendProperties;
}
// Detail
// Order Path have no scale
export interface OrderChannelDef extends FieldDef {
sort?: SortOrder;
}
// TODO: consider if we want to distinguish ordinalOnlyScale from scale
export type FacetChannelDef = PositionChannelDef;
export interface FieldRefOption {

@@ -11,0 +71,0 @@ /** exclude bin, aggregate, timeUnit */

/** module for shorthand */
import {Encoding} from './schema/encoding.schema';
import {FieldDef} from './schema/fielddef.schema';
import {Spec} from './schema/schema';
import {Encoding} from './encoding';
import {FieldDef} from './fielddef';
import {Spec} from './spec';

@@ -7,0 +7,0 @@ import {AggregateOp, AGGREGATE_OPS} from './aggregate';

"use strict";
var Model_1 = require('./compile/Model');
var channel_1 = require('./channel');

@@ -17,3 +16,3 @@ var vlEncoding = require('./encoding');

function getCleanSpec(spec) {
return new Model_1.Model(spec).toSpec(true);
return spec;
}

@@ -20,0 +19,0 @@ exports.getCleanSpec = getCleanSpec;

/* Utilities for a Vega-Lite specificiation */
import {FieldDef} from './schema/fielddef.schema';
import {Spec} from './schema/schema';
import {FieldDef} from './fielddef';
// Package of defining Vega-lite Specification's json schema
import {Model} from './compile/Model';
import {Config} from './config';
import {Data} from './data';
import {Encoding} from './encoding';
import {Mark} from './mark';
import {Transform} from './transform';
import {COLOR, SHAPE} from './channel';

@@ -12,2 +17,21 @@ import * as vlEncoding from './encoding';

/**
* Schema for Vega-Lite specification
* @required ["mark", "encoding"]
*/
export interface Spec {
/**
* A name for the specification. The name is used to annotate marks, scale names, and more.
*/
name?: string;
description?: string;
data?: Data;
transform?: Transform;
mark: Mark;
encoding: Encoding;
config?: Config;
}
// TODO: add vl.spec.validate & move stuff from vl.validate to here

@@ -27,3 +51,3 @@

// TODO: move toSpec to here!
return new Model(spec).toSpec(true);
return spec;
}

@@ -30,0 +54,0 @@

@@ -1,2 +0,2 @@

import {Spec} from './schema/schema';
import {Spec} from './spec';

@@ -3,0 +3,0 @@ // TODO: move to vl.spec.validator?

@@ -8,3 +8,2 @@ "use strict";

var vlCompile = require('./compile/compile');
var vlSchema = require('./schema/schema');
var vlShorthand = require('./shorthand');

@@ -22,3 +21,2 @@ var vlSpec = require('./spec');

exports.fieldDef = vlFieldDef;
exports.schema = vlSchema;
exports.shorthand = vlShorthand;

@@ -25,0 +23,0 @@ exports.spec = vlSpec;

@@ -7,3 +7,2 @@ import * as vlBin from './bin';

import * as vlCompile from './compile/compile';
import * as vlSchema from './schema/schema';
import * as vlShorthand from './shorthand';

@@ -22,3 +21,2 @@ import * as vlSpec from './spec';

export const fieldDef = vlFieldDef;
export const schema = vlSchema;
export const shorthand = vlShorthand;

@@ -25,0 +23,0 @@ export const spec = vlSpec;

@@ -35,5 +35,7 @@ {

"src/aggregate.ts",
"src/axis.ts",
"src/bin.ts",
"src/channel.ts",
"src/compile/axis.ts",
"src/compile/common.ts",
"src/compile/compile.ts",

@@ -45,9 +47,9 @@ "src/compile/config.ts",

"src/compile/legend.ts",
"src/compile/mark-area.ts",
"src/compile/mark-bar.ts",
"src/compile/mark-line.ts",
"src/compile/mark-point.ts",
"src/compile/mark-text.ts",
"src/compile/mark-tick.ts",
"src/compile/mark.ts",
"src/compile/mark/area.ts",
"src/compile/mark/bar.ts",
"src/compile/mark/line.ts",
"src/compile/mark/mark.ts",
"src/compile/mark/point.ts",
"src/compile/mark/text.ts",
"src/compile/mark/tick.ts",
"src/compile/Model.ts",

@@ -57,44 +59,33 @@ "src/compile/scale.ts",

"src/compile/time.ts",
"src/compile/util.ts",
"src/config.ts",
"src/data.ts",
"src/encoding.ts",
"src/enums.ts",
"src/fielddef.ts",
"src/legend.ts",
"src/mark.ts",
"src/schema/axis.schema.ts",
"src/schema/bin.schema.ts",
"src/schema/config.cell.schema.ts",
"src/schema/config.facet.schema.ts",
"src/schema/config.mark.schema.ts",
"src/schema/config.schema.ts",
"src/schema/data.schema.ts",
"src/schema/encoding.schema.ts",
"src/schema/fielddef.schema.ts",
"src/schema/legend.schema.ts",
"src/schema/scale.schema.ts",
"src/schema/schema.ts",
"src/schema/sort.schema.ts",
"src/schema/transform.schema.ts",
"src/schema/vega.schema.ts",
"src/scale.ts",
"src/shorthand.ts",
"src/sort.ts",
"src/spec.ts",
"src/timeunit.ts",
"src/transform.ts",
"src/type.ts",
"src/util.ts",
"src/validate.ts",
"src/vega.schema.ts",
"src/vl.ts",
"test/compile/axis.test.ts",
"test/compile/common.test.ts",
"test/compile/compile.test.ts",
"test/compile/data.test.ts",
"test/compile/legend.test.ts",
"test/compile/mark-area.test.ts",
"test/compile/mark-bar.test.ts",
"test/compile/mark-line.test.ts",
"test/compile/mark-point.test.ts",
"test/compile/mark-text.test.ts",
"test/compile/mark-tick.test.ts",
"test/compile/mark/area.test.ts",
"test/compile/mark/bar.test.ts",
"test/compile/mark/line.test.ts",
"test/compile/mark/point.test.ts",
"test/compile/mark/text.test.ts",
"test/compile/mark/tick.test.ts",
"test/compile/Model.test.ts",
"test/compile/scale.test.ts",
"test/compile/stack.test.ts",
"test/compile/util.test.ts",
"test/fielddef.test.ts",

@@ -101,0 +92,0 @@ "test/schema.test.ts",

@@ -243,4 +243,6 @@ {

"quantile",
"quantize",
"ordinal",
"time"
"time",
"utc"
]

@@ -342,3 +344,3 @@ },

},
"useRawDomain": {
"includeRawDomain": {
"type": "boolean",

@@ -1070,3 +1072,3 @@ "description": "Uses the source data range as scale domain instead of aggregated data for aggregate axis. This option does not work with sum or count aggregate as they might have a substantially larger scale range."

},
"useRawDomain": {
"includeRawDomain": {
"type": "boolean"

@@ -1073,0 +1075,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc