Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support href and cursor properties for marks #3229

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/docs/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ In addition to the constant `value`, [value definitions](#value-def) of `text` a
{:#href}
## Hyperlink Channel

By setting the `href` channel, a mark becomes a hyperlink. The specified URL is loaded upon a muse click. The `cursor` mark property can be set to `pointer` to serve as affordance for hyperlinks.
By setting the `href` channel, a mark becomes a hyperlink. The specified URL is loaded upon a muse click. The [`cursor` mark property](mark.html#hyperlink) can be set to `pointer` to serve as affordance for hyperlinks.

{% include table.html props="href" source="Encoding" %}

Expand Down
5 changes: 3 additions & 2 deletions site/docs/mark/mark.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ The rest of this section describe groups of properties supported by the `mark` c

{% include table.html props="strokeWidth,strokeDash,strokeDashOffset" source="MarkConfig" %}

### Link Properties
{:#hyperlink}
### Hyperlink Properties

Marks can act as hyperlinks when the `href` property is defined. A `cursor` property can also be provided to serve as affordance for the links.
Marks can act as hyperlinks when the `href` property or [channel](encoding.html#href) is defined. A `cursor` property can also be provided to serve as affordance for the links.

{% include table.html props="href,cursor" source="MarkConfig" %}

Expand Down
3 changes: 2 additions & 1 deletion src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export type PositionScaleChannel = typeof POSITION_SCALE_CHANNELS[0];
// NON_POSITION_SCALE_CHANNEL = SCALE_CHANNELS without X, Y
const {
// x2 and y2 share the same scale as x and y
// text, tooltip, and href have format instead of scale
// text and tooltip have format instead of scale,
// href has neother format, nor scale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neither

text: _t, tooltip: _tt, href: _hr,
// detail and order have no scale
detail: _dd, order: _oo,
Expand Down
2 changes: 1 addition & 1 deletion src/vega.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export interface VgSignal {
push?: string;
}

export type VgEncodeChannel = 'x'|'x2'|'xc'|'width'|'y'|'y2'|'yc'|'height'|'opacity'|'fill'|'fillOpacity'|'stroke'|'strokeWidth'|'strokeOpacity'|'strokeDash'|'strokeDashOffset'|'cursor'|'clip'|'size'|'shape'|'path'|'innerRadius'|'outerRadius'|'startAngle'|'endAngle'|'interpolate'|'tension'|'orient'|'url'|'align'|'baseline'|'text'|'dir'|'ellipsis'|'limit'|'dx'|'dy'|'radius'|'theta'|'angle'|'font'|'fontSize'|'fontWeight'|'fontStyle'|'href'|'cursor';
export type VgEncodeChannel = 'x'|'x2'|'xc'|'width'|'y'|'y2'|'yc'|'height'|'opacity'|'fill'|'fillOpacity'|'stroke'|'strokeWidth'|'strokeOpacity'|'strokeDash'|'strokeDashOffset'|'cursor'|'clip'|'size'|'shape'|'path'|'innerRadius'|'outerRadius'|'startAngle'|'endAngle'|'interpolate'|'tension'|'orient'|'url'|'align'|'baseline'|'text'|'dir'|'ellipsis'|'limit'|'dx'|'dy'|'radius'|'theta'|'angle'|'font'|'fontSize'|'fontWeight'|'fontStyle'|'tooltip'|'href'|'cursor';
export type VgEncodeEntry = {
[k in VgEncodeChannel]?: VgValueRef | (VgValueRef & {test?: string})[];
};
Expand Down
30 changes: 0 additions & 30 deletions test/compile/mark/mark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,6 @@ describe('Mark', function() {
assert.equal(markGroup[0].from.data, 'main');
});
});

describe('Bar with tooltip', () => {
it('should pass tooltip value to encoding', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "field": "Cost__Other", "aggregate": "sum"},
"y": {"bin": true, "type": "quantitative", "field": "Cost__Total_$"},
"tooltip": {"value": "foo"}
}
});
const markGroup = parseMarkGroup(model);
assert.equal(markGroup[0].encode.update.tooltip.value, 'foo');
});
});

describe('Bar with href', () => {
it('should pass href value to encoding', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "field": "Cost__Other", "aggregate": "sum"},
"y": {"bin": true, "type": "quantitative", "field": "Cost__Total_$"},
"href": {"value": "https://idl.cs.washington.edu/"}
}
});
const markGroup = parseMarkGroup(model);
assert.equal(markGroup[0].encode.update.href.value, 'https://idl.cs.washington.edu/');
});
});
});

describe('getPathSort', () => {
Expand Down
28 changes: 28 additions & 0 deletions test/compile/mark/point.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,34 @@ describe('Mark: Point', function() {
});

});

describe('with tooltip', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
"mark": "point",
"encoding": {
"tooltip": {"value": "foo"}
}
});
const props = point.encodeEntry(model);

it('should pass tooltip value to encoding', () => {
assert.deepEqual(props.tooltip, {value: "foo"});
});
});

describe('with href', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
"mark": "point",
"encoding": {
"href": {"value": "https://idl.cs.washington.edu/"}
}
});
const props = point.encodeEntry(model);

it('should pass href value to encoding', () => {
assert.deepEqual(props.href, {value: 'https://idl.cs.washington.edu/'});
});
});
});

describe('Mark: Square', function() {
Expand Down