Skip to content

Commit

Permalink
Merge pull request #1247 from vega/kw/layer
Browse files Browse the repository at this point in the history
Fixing sizing, config order
  • Loading branch information
domoritz committed Mar 17, 2016
2 parents 22add05 + cb56846 commit 2d40fd5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/compile/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function buildModel(spec: Spec, parent: Model, parentGivenName: string):
return null;
}

// TODO: figure if we really need opacity in both
export const STROKE_CONFIG = ['stroke', 'strokeWidth',
'strokeDash', 'strokeDashOffset', 'strokeOpacity', 'opacity'];

Expand Down
16 changes: 15 additions & 1 deletion src/compile/mark/line.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {UnitModel} from '../unit';
import {X, Y} from '../../channel';
import {X, Y, SIZE} from '../../channel';
import {applyColorAndOpacity, applyMarkConfig} from '../common';


Expand Down Expand Up @@ -34,8 +34,22 @@ export namespace line {

applyColorAndOpacity(p, model);
applyMarkConfig(p, model, ['interpolate', 'tension']);

// size as a channel is not supported in Vega yet.
const size = sizeValue(model);
if (size) {
p.strokeWidth = { value: size };
}
return p;
}

function sizeValue(model: UnitModel) {
const fieldDef = model.fieldDef(SIZE);
if (fieldDef && fieldDef.value !== undefined) {
return fieldDef.value;
}
return model.config().mark.lineSize;
}

export function labels(model: UnitModel) {
// TODO(#240): fill this method
Expand Down
2 changes: 1 addition & 1 deletion src/compile/mark/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export namespace rule {
return fieldDef.value;
}

return model.config().mark.size;
return model.config().mark.ruleSize;
}

export function labels(model: UnitModel) {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export function rangeMixins(scale: Scale, model: Model, channel: Channel): any {
} else if (unitModel.mark() === TEXT_MARK) {
return {range: scaleConfig.fontSizeRange };
} else if (unitModel.mark() === RULE) {
return {range: scaleConfig.lineSizeRange };
return {range: scaleConfig.ruleSizeRange };
}
// else -- point, square, circle
if (scaleConfig.pointSizeRange !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class UnitModel extends Model {
}

private _initConfig(specConfig: Config, parent: Model, mark: Mark, encoding: Encoding) {
let config = mergeDeep(duplicate(defaultConfig), specConfig, parent ? parent.config() : {});
let config = mergeDeep(duplicate(defaultConfig), parent ? parent.config() : {}, specConfig);
config.mark = initMarkConfig(mark, encoding, config);
return config;
}
Expand Down
14 changes: 14 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ export interface MarkConfig {
*/
tension?: number;

// ---------- Line ---------
/**
* Size of line mark.
*/
lineSize?: number;

// ---------- Rule ---------
/**
* Size of rule mark.
*/
ruleSize?: number;

// ---------- Bar ----------
/**
* The size of the bars. If unspecified, the default size is `bandSize-1`,
Expand Down Expand Up @@ -285,6 +297,8 @@ export const defaultMarkConfig: MarkConfig = {
strokeWidth: 2,
size: 30,
barThinSize: 2,
// lineSize is undefined by default, and refer to value from strokeWidth
ruleSize: 1,
tickThickness: 1,

fontSize: 10,
Expand Down
6 changes: 3 additions & 3 deletions src/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export interface ScaleConfig {
/** Default range for font size scale */
fontSizeRange?: number[];

/** Default range for line stroke widths */
lineSizeRange?: number[];
/** Default range for rule stroke widths */
ruleSizeRange?: number[];

/** Default range for bar size scale */
pointSizeRange?: number[];
Expand All @@ -80,7 +80,7 @@ export const defaultScaleConfig: ScaleConfig = {
sequentialColorRange: ['#AFC6A3', '#09622A'], // tableau greens
shapeRange: 'shapes',
fontSizeRange: [8, 40],
lineSizeRange: [1, 10]
ruleSizeRange: [1, 5]
};

export interface FacetScaleConfig {
Expand Down

0 comments on commit 2d40fd5

Please sign in to comment.