@chart-parts/vsvg
Advanced tools
Comparing version 0.0.21 to 0.1.1
@@ -1,5 +0,1 @@ | ||
/*! | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project. | ||
*/ | ||
export {}; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,12 +5,13 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable no-submodule-imports no-implicit-dependencies | ||
const Mark_1 = require("@chart-parts/scenegraph/lib/elements/Mark"); | ||
const ArcItem_1 = require("@chart-parts/scenegraph/lib/elements/items/ArcItem"); | ||
const __1 = require("../"); | ||
/* eslint-disable @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
import { Mark } from '@chart-parts/scenegraph/dist/cjs/elements/Mark'; | ||
// @ts-ignore | ||
import { ArcItem } from '@chart-parts/scenegraph/dist/cjs/elements/items/ArcItem'; | ||
import { renderMark } from '../'; | ||
describe('The Arc Renderer', () => { | ||
it('can render an arc', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = ArcItem_1.ArcItem.ITEM_TYPE; | ||
const arc = new ArcItem_1.ArcItem(); | ||
const mark = new Mark(); | ||
mark.marktype = ArcItem.ITEM_TYPE; | ||
const arc = new ArcItem(); | ||
arc.startAngle = 0; | ||
@@ -26,5 +26,5 @@ arc.endAngle = 1; | ||
mark.items.push(arc); | ||
const result = __1.renderMark(mark, { nextId: () => 'id' }); | ||
const result = renderMark(mark, { nextId: () => 'id' }); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -1,5 +0,1 @@ | ||
/*! | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project. | ||
*/ | ||
export {}; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,12 +5,13 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable no-submodule-imports no-implicit-dependencies | ||
const Mark_1 = require("@chart-parts/scenegraph/lib/elements/Mark"); | ||
const RectItem_1 = require("@chart-parts/scenegraph/lib/elements/items/RectItem"); | ||
const __1 = require("../"); | ||
/* eslint-disable @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
import { Mark } from '@chart-parts/scenegraph/dist/cjs/elements/Mark'; | ||
// @ts-ignore | ||
import { RectItem } from '@chart-parts/scenegraph/dist/cjs/elements/items/RectItem'; | ||
import { renderMark } from '../'; | ||
describe('The Rect Renderer', () => { | ||
it('can render a rectangle', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = RectItem_1.RectItem.ITEM_TYPE; | ||
const rect = new RectItem_1.RectItem(); | ||
const mark = new Mark(); | ||
mark.marktype = RectItem.ITEM_TYPE; | ||
const rect = new RectItem(); | ||
rect.x = 0; | ||
@@ -24,5 +24,5 @@ rect.y = 0; | ||
mark.items.push(rect); | ||
const result = __1.renderMark(mark, { nextId: () => '' }); | ||
const result = renderMark(mark, { nextId: () => '' }); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -1,5 +0,1 @@ | ||
/*! | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project. | ||
*/ | ||
export {}; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,13 +5,14 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable no-submodule-imports no-implicit-dependencies | ||
const Mark_1 = require("@chart-parts/scenegraph/lib/elements/Mark"); | ||
const RuleItem_1 = require("@chart-parts/scenegraph/lib/elements/items/RuleItem"); | ||
const __1 = require("../"); | ||
/* eslint-disable @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
import { Mark } from '@chart-parts/scenegraph/dist/cjs/elements/Mark'; | ||
// @ts-ignore | ||
import { RuleItem } from '@chart-parts/scenegraph/dist/cjs/elements/items/RuleItem'; | ||
import { renderMark } from '../'; | ||
const ctx = { nextId: () => 'id' }; | ||
describe('The Rule Renderer', () => { | ||
it('can render a rule with an x, y, and x2 value', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = RuleItem_1.RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem_1.RuleItem(); | ||
const mark = new Mark(); | ||
mark.marktype = RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem(); | ||
rule.x = 0; | ||
@@ -22,9 +22,9 @@ rule.y = 0; | ||
mark.items.push(rule); | ||
const rendered = __1.renderMark(mark, ctx); | ||
const rendered = renderMark(mark, ctx); | ||
expect(rendered).toMatchSnapshot(); | ||
}); | ||
it('can render a rule with an x, y, and y value', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = RuleItem_1.RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem_1.RuleItem(); | ||
const mark = new Mark(); | ||
mark.marktype = RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem(); | ||
rule.x = 0; | ||
@@ -34,9 +34,9 @@ rule.y = 0; | ||
mark.items.push(rule); | ||
const rendered = __1.renderMark(mark, ctx); | ||
const rendered = renderMark(mark, ctx); | ||
expect(rendered).toMatchSnapshot(); | ||
}); | ||
it('can render a rule with an x, y, and a smaller x2 value', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = RuleItem_1.RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem_1.RuleItem(); | ||
const mark = new Mark(); | ||
mark.marktype = RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem(); | ||
rule.x = 100; | ||
@@ -46,9 +46,9 @@ rule.y = 100; | ||
mark.items.push(rule); | ||
const rendered = __1.renderMark(mark, ctx); | ||
const rendered = renderMark(mark, ctx); | ||
expect(rendered).toMatchSnapshot(); | ||
}); | ||
it('can render a rule with an x, y, and a smaller y value', () => { | ||
const mark = new Mark_1.Mark(); | ||
mark.marktype = RuleItem_1.RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem_1.RuleItem(); | ||
const mark = new Mark(); | ||
mark.marktype = RuleItem.ITEM_TYPE; | ||
const rule = new RuleItem(); | ||
rule.x = 100; | ||
@@ -58,5 +58,5 @@ rule.y = 100; | ||
mark.items.push(rule); | ||
const rendered = __1.renderMark(mark, ctx); | ||
const rendered = renderMark(mark, ctx); | ||
expect(rendered).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,18 +5,20 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const path_1 = require("../path"); | ||
const interfaces_2 = require("./interfaces"); | ||
class ArcRenderer { | ||
import { MarkType } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { arc } from '../path'; | ||
import { translate } from './interfaces'; | ||
export class ArcRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, ArcRenderer.TARGET_MARK_TYPE); | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Arc, mark.role, mark.items.map(item => { | ||
assertTypeIs(mark, ArcRenderer.TARGET_MARK_TYPE); | ||
const nodes = emitMarkGroup(MarkType.Arc, mark.role, mark.items.map(item => { | ||
const { x, y } = item; | ||
const result = { | ||
type: 'path', | ||
attrs: Object.assign({}, util_1.commonProps(item), { d: path_1.arc(item) }), | ||
attrs: { | ||
...commonProps(item), | ||
d: arc(item), | ||
}, | ||
ariaTitle: item.ariaTitle, | ||
ariaDescription: item.ariaDescription, | ||
transforms: [interfaces_2.translate(x || 0, y || 0)], | ||
transforms: [translate(x || 0, y || 0)], | ||
channels: item.channels, | ||
@@ -31,3 +32,2 @@ metadata: item.metadata, | ||
} | ||
ArcRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Arc; | ||
exports.ArcRenderer = ArcRenderer; | ||
ArcRenderer.TARGET_MARK_TYPE = MarkType.Arc; |
@@ -10,4 +10,4 @@ /*! | ||
render(mark: SGMark<SGAreaItem>): { | ||
nodes: import("@chart-parts/interfaces/lib/vdom/svg").VSvgNode[]; | ||
nodes: import("@chart-parts/interfaces").VSvgNode[]; | ||
}; | ||
} |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,9 +5,8 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const path_1 = require("../path"); | ||
class AreaRenderer { | ||
import { MarkType, getItemSpace, } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { area } from '../path'; | ||
export class AreaRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, AreaRenderer.TARGET_MARK_TYPE); | ||
assertTypeIs(mark, AreaRenderer.TARGET_MARK_TYPE); | ||
if (mark.items.map.length === 0) { | ||
@@ -18,3 +16,3 @@ return { nodes: [] }; | ||
const areaItems = mark.items.map(a => { | ||
const space = interfaces_1.getItemSpace(a); | ||
const space = getItemSpace(a); | ||
const ai = a; | ||
@@ -28,3 +26,6 @@ ai.width = space.shape.width; | ||
type: 'path', | ||
attrs: Object.assign({ d: path_1.area(areaItems) }, util_1.commonProps(firstItem)), | ||
attrs: { | ||
d: area(areaItems), | ||
...commonProps(firstItem), | ||
}, | ||
ariaTitle: firstItem.ariaTitle, | ||
@@ -35,7 +36,6 @@ ariaDescription: firstItem.ariaDescription, | ||
}; | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Area, mark.role, [areaItem]); | ||
const nodes = emitMarkGroup(MarkType.Area, mark.role, [areaItem]); | ||
return { nodes }; | ||
} | ||
} | ||
AreaRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Area; | ||
exports.AreaRenderer = AreaRenderer; | ||
AreaRenderer.TARGET_MARK_TYPE = MarkType.Area; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,9 +5,7 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable no-submodule-imports | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const index_1 = require("./index"); | ||
const path_1 = require("../path"); | ||
const interfaces_2 = require("./interfaces"); | ||
import { MarkType, getItemSpace, } from '@chart-parts/interfaces'; | ||
import { commonProps, assertTypeIs } from './util'; | ||
import { renderMark } from './index'; | ||
import { rectangle } from '../path'; | ||
import { translate, } from './interfaces'; | ||
function flatMap(items, lambda) { | ||
@@ -23,3 +20,3 @@ const mappedItems = items.map(lambda); | ||
function renderGroupRectangle(item, space) { | ||
const groupRectCommonProps = util_1.commonProps(item); | ||
const groupRectCommonProps = commonProps(item); | ||
const originX = space.origin.x || 0; | ||
@@ -31,5 +28,5 @@ const originY = space.origin.y || 0; | ||
const groupRectShape = { | ||
d: path_1.rectangle(item, originX, originY).toString(), | ||
d: rectangle(item, originX, originY).toString(), | ||
}; | ||
const attrs = Object.assign({}, groupRectCommonProps, groupRectShape); | ||
const attrs = { ...groupRectCommonProps, ...groupRectShape }; | ||
const { metadata, channels } = item; | ||
@@ -55,3 +52,3 @@ const groupRect = { | ||
groupItems.forEach(m => { | ||
const renderedChild = index_1.renderMark(m, context); | ||
const renderedChild = renderMark(m, context); | ||
if (renderedChild.defs) { | ||
@@ -68,3 +65,3 @@ defs = [...defs, ...renderedChild.defs]; | ||
type: 'g', | ||
transforms: [interfaces_2.translate(space.origin.x, space.origin.y)], | ||
transforms: [translate(space.origin.x, space.origin.y)], | ||
children, | ||
@@ -93,8 +90,8 @@ metadata, | ||
} | ||
class GroupRenderer { | ||
export class GroupRenderer { | ||
render(mark, context) { | ||
util_1.assertTypeIs(mark, GroupRenderer.TARGET_MARK_TYPE); | ||
assertTypeIs(mark, GroupRenderer.TARGET_MARK_TYPE); | ||
const defs = []; | ||
const nodes = flatMap(mark.items, (item) => { | ||
const space = interfaces_1.getItemSpace(item); | ||
const space = getItemSpace(item); | ||
// Render the Group's Rectangle | ||
@@ -118,3 +115,2 @@ const groupRect = renderGroupRectangle(item, space); | ||
} | ||
GroupRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Group; | ||
exports.GroupRenderer = GroupRenderer; | ||
GroupRenderer.TARGET_MARK_TYPE = MarkType.Group; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,26 +5,22 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const registry_1 = require("./registry"); | ||
const ArcRenderer_1 = require("./ArcRenderer"); | ||
const AreaRenderer_1 = require("./AreaRenderer"); | ||
const GroupRenderer_1 = require("./GroupRenderer"); | ||
const LineRenderer_1 = require("./LineRenderer"); | ||
const PathRenderer_1 = require("./PathRenderer"); | ||
const RectRenderer_1 = require("./RectRenderer"); | ||
const RuleRenderer_1 = require("./RuleRenderer"); | ||
const SymbolRenderer_1 = require("./SymbolRenderer"); | ||
const TextRenderer_1 = require("./TextRenderer"); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Arc, new ArcRenderer_1.ArcRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Area, new AreaRenderer_1.AreaRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Group, new GroupRenderer_1.GroupRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Line, new LineRenderer_1.LineRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Path, new PathRenderer_1.PathRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Rect, new RectRenderer_1.RectRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Rule, new RuleRenderer_1.RuleRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Symbol, new SymbolRenderer_1.SymbolRenderer()); | ||
registry_1.registerRenderer(interfaces_1.MarkType.Text, new TextRenderer_1.TextRenderer()); | ||
__export(require("./registry")); | ||
import { MarkType } from '@chart-parts/interfaces'; | ||
import { registerRenderer } from './registry'; | ||
import { ArcRenderer } from './ArcRenderer'; | ||
import { AreaRenderer } from './AreaRenderer'; | ||
import { GroupRenderer } from './GroupRenderer'; | ||
import { LineRenderer } from './LineRenderer'; | ||
import { PathRenderer } from './PathRenderer'; | ||
import { RectRenderer } from './RectRenderer'; | ||
import { RuleRenderer } from './RuleRenderer'; | ||
import { SymbolRenderer } from './SymbolRenderer'; | ||
import { TextRenderer } from './TextRenderer'; | ||
registerRenderer(MarkType.Arc, new ArcRenderer()); | ||
registerRenderer(MarkType.Area, new AreaRenderer()); | ||
registerRenderer(MarkType.Group, new GroupRenderer()); | ||
registerRenderer(MarkType.Line, new LineRenderer()); | ||
registerRenderer(MarkType.Path, new PathRenderer()); | ||
registerRenderer(MarkType.Rect, new RectRenderer()); | ||
registerRenderer(MarkType.Rule, new RuleRenderer()); | ||
registerRenderer(MarkType.Symbol, new SymbolRenderer()); | ||
registerRenderer(MarkType.Text, new TextRenderer()); | ||
export * from './registry'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,11 +5,8 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
function translate(x, y) { | ||
return { type: interfaces_1.VSvgTransformType.translate, value: [x, y] }; | ||
import { VSvgTransformType, } from '@chart-parts/interfaces'; | ||
export function translate(x, y) { | ||
return { type: VSvgTransformType.translate, value: [x, y] }; | ||
} | ||
exports.translate = translate; | ||
function rotate(angle) { | ||
return { type: interfaces_1.VSvgTransformType.rotate, value: angle }; | ||
export function rotate(angle) { | ||
return { type: VSvgTransformType.rotate, value: angle }; | ||
} | ||
exports.rotate = rotate; |
@@ -10,4 +10,4 @@ /*! | ||
render(mark: SGMark<SGLineItem>): { | ||
nodes: import("@chart-parts/interfaces/lib/vdom/svg").VSvgNode[]; | ||
nodes: import("@chart-parts/interfaces").VSvgNode[]; | ||
}; | ||
} |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,9 +5,8 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const path_1 = require("../path"); | ||
class LineRenderer { | ||
import { MarkType } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { line } from '../path'; | ||
export class LineRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, LineRenderer.TARGET_MARK_TYPE); | ||
assertTypeIs(mark, LineRenderer.TARGET_MARK_TYPE); | ||
if (mark.items.map.length === 0) { | ||
@@ -20,3 +18,6 @@ return { nodes: [] }; | ||
type: 'path', | ||
attrs: Object.assign({ d: path_1.line(mark.items) }, util_1.commonProps(firstItem)), | ||
attrs: { | ||
d: line(mark.items), | ||
...commonProps(firstItem), | ||
}, | ||
metadata: firstItem.metadata, | ||
@@ -27,7 +28,6 @@ channels: firstItem.channels, | ||
}; | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Line, mark.role, [lineItem]); | ||
const nodes = emitMarkGroup(MarkType.Line, mark.role, [lineItem]); | ||
return { nodes }; | ||
} | ||
} | ||
LineRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Line; | ||
exports.LineRenderer = LineRenderer; | ||
LineRenderer.TARGET_MARK_TYPE = MarkType.Line; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,15 +5,14 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const interfaces_2 = require("./interfaces"); | ||
class PathRenderer { | ||
import { MarkType } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { translate } from './interfaces'; | ||
export class PathRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, PathRenderer.TARGET_MARK_TYPE); | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Path, mark.role, mark.items.map(item => { | ||
assertTypeIs(mark, PathRenderer.TARGET_MARK_TYPE); | ||
const nodes = emitMarkGroup(MarkType.Path, mark.role, mark.items.map(item => { | ||
const { x, y } = item; | ||
const result = { | ||
type: 'path', | ||
attrs: Object.assign({}, util_1.commonProps(item), { d: item.path }), | ||
transforms: [interfaces_2.translate(x || 0, y || 0)], | ||
attrs: { ...commonProps(item), d: item.path }, | ||
transforms: [translate(x || 0, y || 0)], | ||
metadata: item.metadata, | ||
@@ -30,3 +28,2 @@ channels: item.channels, | ||
} | ||
PathRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Path; | ||
exports.PathRenderer = PathRenderer; | ||
PathRenderer.TARGET_MARK_TYPE = MarkType.Path; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,17 +5,16 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const path_1 = require("../path"); | ||
class RectRenderer { | ||
import { MarkType, getItemSpace, } from '@chart-parts/interfaces'; | ||
import { commonProps, assertTypeIs, emitMarkGroup } from './util'; | ||
import { rectangle } from '../path'; | ||
export class RectRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, RectRenderer.TARGET_MARK_TYPE); | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Rect, mark.role, mark.items.map(item => { | ||
assertTypeIs(mark, RectRenderer.TARGET_MARK_TYPE); | ||
const nodes = emitMarkGroup(MarkType.Rect, mark.role, mark.items.map(item => { | ||
const { metadata, channels } = item; | ||
const space = interfaces_1.getItemSpace(item); | ||
const attrs = util_1.commonProps(item); | ||
const space = getItemSpace(item); | ||
const attrs = commonProps(item); | ||
const rectItem = item; | ||
rectItem.width = space.shape.width; | ||
rectItem.height = space.shape.height; | ||
attrs.d = path_1.rectangle(rectItem, space.origin.x, space.origin.y).toString(); | ||
attrs.d = rectangle(rectItem, space.origin.x, space.origin.y).toString(); | ||
const result = { | ||
@@ -35,3 +33,2 @@ type: 'path', | ||
} | ||
RectRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Rect; | ||
exports.RectRenderer = RectRenderer; | ||
RectRenderer.TARGET_MARK_TYPE = MarkType.Rect; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,9 +5,7 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const itemRendererRegistry = new Map(); | ||
function registerRenderer(markType, markRenderer) { | ||
export function registerRenderer(markType, markRenderer) { | ||
itemRendererRegistry.set(markType, markRenderer); | ||
} | ||
exports.registerRenderer = registerRenderer; | ||
function renderMark(mark, context) { | ||
export function renderMark(mark, context) { | ||
if (!mark.marktype) { | ||
@@ -20,2 +17,1 @@ throw new Error(`Unhandled mark type "${mark.marktype}"`); | ||
} | ||
exports.renderMark = renderMark; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,14 +5,13 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const interfaces_2 = require("./interfaces"); | ||
class RuleRenderer { | ||
import { MarkType } from '@chart-parts/interfaces'; | ||
import { assertTypeIs, emitMarkGroup, commonProps } from './util'; | ||
import { translate } from './interfaces'; | ||
export class RuleRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, RuleRenderer.TARGET_MARK_TYPE); | ||
assertTypeIs(mark, RuleRenderer.TARGET_MARK_TYPE); | ||
// Render each item embedded in this mark | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Rule, mark.role, mark.items.map(item => { | ||
const nodes = emitMarkGroup(MarkType.Rule, mark.role, mark.items.map(item => { | ||
const x = item.x || 0; | ||
const y = item.y || 0; | ||
const attrs = util_1.commonProps(item); | ||
const attrs = commonProps(item); | ||
if (item.x2 !== undefined) { | ||
@@ -28,3 +26,3 @@ attrs.x2 = item.x2 - x; | ||
attrs, | ||
transforms: [interfaces_2.translate(x, y)], | ||
transforms: [translate(x, y)], | ||
channels: item.channels, | ||
@@ -40,3 +38,2 @@ metadata: item.metadata, | ||
} | ||
RuleRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Rule; | ||
exports.RuleRenderer = RuleRenderer; | ||
RuleRenderer.TARGET_MARK_TYPE = MarkType.Rule; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,16 +5,18 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const path_1 = require("../path"); | ||
const interfaces_2 = require("./interfaces"); | ||
class SymbolRenderer { | ||
import { MarkType, } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { symbol } from '../path'; | ||
import { translate } from './interfaces'; | ||
export class SymbolRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, SymbolRenderer.TARGET_MARK_TYPE); | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Symbol, mark.role, mark.items.map(item => { | ||
assertTypeIs(mark, SymbolRenderer.TARGET_MARK_TYPE); | ||
const nodes = emitMarkGroup(MarkType.Symbol, mark.role, mark.items.map(item => { | ||
const { x = 0, y = 0 } = item; | ||
const result = { | ||
type: 'path', | ||
attrs: Object.assign({}, util_1.commonProps(item), { d: path_1.symbol(item) }), | ||
transforms: [interfaces_2.translate(x, y)], | ||
attrs: { | ||
...commonProps(item), | ||
d: symbol(item), | ||
}, | ||
transforms: [translate(x, y)], | ||
metadata: item.metadata, | ||
@@ -31,3 +32,2 @@ channels: item.channels, | ||
} | ||
SymbolRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Symbol; | ||
exports.SymbolRenderer = SymbolRenderer; | ||
SymbolRenderer.TARGET_MARK_TYPE = MarkType.Symbol; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,10 +5,13 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const util_1 = require("./util"); | ||
const interfaces_2 = require("./interfaces"); | ||
import { MarkType, VerticalTextAlignment, } from '@chart-parts/interfaces'; | ||
import { emitMarkGroup, commonProps, assertTypeIs } from './util'; | ||
import { rotate, translate } from './interfaces'; | ||
const alignments = { left: 'start', center: 'middle', right: 'end' }; | ||
const DEFAULT_FONT_SIZE = 11; | ||
const DEFAULT_FONT_FAMILY = 'sans-serif'; | ||
function calculateTextOrigin({ x, y, baseline, fontSize, radius = 0, theta = 0, }) { | ||
function calculateTextOrigin({ x, y, | ||
// TODO: use these? | ||
// baseline, | ||
// fontSize, | ||
radius = 0, theta = 0, }) { | ||
x = x || 0; | ||
@@ -26,7 +28,7 @@ y = y || 0; | ||
switch (alignment) { | ||
case interfaces_1.VerticalTextAlignment.Top: | ||
case VerticalTextAlignment.Top: | ||
return 'hanging'; | ||
case interfaces_1.VerticalTextAlignment.Middle: | ||
case VerticalTextAlignment.Middle: | ||
return 'central'; | ||
case interfaces_1.VerticalTextAlignment.Bottom: | ||
case VerticalTextAlignment.Bottom: | ||
return 'baseline'; | ||
@@ -41,17 +43,20 @@ default: | ||
if (item.angle !== undefined) { | ||
transforms.push(interfaces_2.translate(origin[0], origin[1]), interfaces_2.rotate(item.angle)); | ||
transforms.push(translate(origin[0], origin[1]), rotate(item.angle)); | ||
if (item.dx !== undefined || item.dy !== undefined) { | ||
transforms.push(interfaces_2.translate(item.dx || 0, item.dy || 0)); | ||
transforms.push(translate(item.dx || 0, item.dy || 0)); | ||
} | ||
} | ||
else { | ||
transforms.push(interfaces_2.translate(origin[0] + (item.dx || 0) || 0, origin[1] + (item.dy || 0) || 0)); | ||
transforms.push(translate(origin[0] + (item.dx || 0) || 0, origin[1] + (item.dy || 0) || 0)); | ||
} | ||
return transforms; | ||
} | ||
class TextRenderer { | ||
export class TextRenderer { | ||
render(mark) { | ||
util_1.assertTypeIs(mark, TextRenderer.TARGET_MARK_TYPE); | ||
const nodes = util_1.emitMarkGroup(interfaces_1.MarkType.Text, mark.role, mark.items.map(item => { | ||
const attrs = Object.assign({}, util_1.commonProps(item), { alignmentBaseline: calculateBaseline(item.baseline) }); | ||
assertTypeIs(mark, TextRenderer.TARGET_MARK_TYPE); | ||
const nodes = emitMarkGroup(MarkType.Text, mark.role, mark.items.map(item => { | ||
const attrs = { | ||
...commonProps(item), | ||
alignmentBaseline: calculateBaseline(item.baseline), | ||
}; | ||
if (item.align) { | ||
@@ -83,3 +88,2 @@ attrs.textAnchor = alignments[item.align]; | ||
} | ||
TextRenderer.TARGET_MARK_TYPE = interfaces_1.MarkType.Text; | ||
exports.TextRenderer = TextRenderer; | ||
TextRenderer.TARGET_MARK_TYPE = MarkType.Text; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,3 +5,2 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -13,3 +11,3 @@ * Perform an invariant assertion that a mark is of a given type | ||
*/ | ||
function assertTypeIs(mark, itemType) { | ||
export function assertTypeIs(mark, itemType) { | ||
if (mark.marktype !== itemType) { | ||
@@ -22,3 +20,2 @@ throw new Error(` | ||
} | ||
exports.assertTypeIs = assertTypeIs; | ||
function roleClass(role) { | ||
@@ -32,3 +29,3 @@ return `role-${role || 'mark'}`; | ||
*/ | ||
function emitMarkGroup(marktype, role, children) { | ||
export function emitMarkGroup(marktype, role, children) { | ||
const markGroup = { | ||
@@ -43,3 +40,2 @@ type: 'g', | ||
} | ||
exports.emitMarkGroup = emitMarkGroup; | ||
/** | ||
@@ -50,3 +46,3 @@ * Copies shared vsvg props from the given mark into the vsvg node | ||
*/ | ||
function commonProps(item) { | ||
export function commonProps(item) { | ||
const result = {}; | ||
@@ -83,2 +79,1 @@ if (item.fill !== undefined) { | ||
} | ||
exports.commonProps = commonProps; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,6 +5,2 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./VirtualSvgConverter")); | ||
export * from './VirtualSvgConverter'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,16 +5,15 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const d3_shape_1 = require("d3-shape"); | ||
import { curveBasis, curveBasisClosed, curveBasisOpen, curveBundle, curveCardinal, curveCardinalClosed, curveCardinalOpen, curveCatmullRom, curveCatmullRomClosed, curveCatmullRomOpen, curveLinear, curveLinearClosed, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore, } from 'd3-shape'; | ||
const lookup = { | ||
basis: { | ||
curve: d3_shape_1.curveBasis, | ||
curve: curveBasis, | ||
}, | ||
'basis-closed': { | ||
curve: d3_shape_1.curveBasisClosed, | ||
curve: curveBasisClosed, | ||
}, | ||
'basis-open': { | ||
curve: d3_shape_1.curveBasisOpen, | ||
curve: curveBasisOpen, | ||
}, | ||
bundle: { | ||
curve: d3_shape_1.curveBundle, | ||
curve: curveBundle, | ||
tension: 'beta', | ||
@@ -25,3 +23,3 @@ value: 0.85, | ||
cardinal: { | ||
curve: d3_shape_1.curveCardinal, | ||
curve: curveCardinal, | ||
tension: 'tension', | ||
@@ -31,3 +29,3 @@ value: 0, | ||
'cardinal-open': { | ||
curve: d3_shape_1.curveCardinalOpen, | ||
curve: curveCardinalOpen, | ||
tension: 'tension', | ||
@@ -37,3 +35,3 @@ value: 0, | ||
'cardinal-closed': { | ||
curve: d3_shape_1.curveCardinalClosed, | ||
curve: curveCardinalClosed, | ||
tension: 'tension', | ||
@@ -43,3 +41,3 @@ value: 0, | ||
'catmull-rom': { | ||
curve: d3_shape_1.curveCatmullRom, | ||
curve: curveCatmullRom, | ||
tension: 'alpha', | ||
@@ -49,3 +47,3 @@ value: 0.5, | ||
'catmull-rom-closed': { | ||
curve: d3_shape_1.curveCatmullRomClosed, | ||
curve: curveCatmullRomClosed, | ||
tension: 'alpha', | ||
@@ -55,3 +53,3 @@ value: 0.5, | ||
'catmull-rom-open': { | ||
curve: d3_shape_1.curveCatmullRomOpen, | ||
curve: curveCatmullRomOpen, | ||
tension: 'alpha', | ||
@@ -61,26 +59,26 @@ value: 0.5, | ||
linear: { | ||
curve: d3_shape_1.curveLinear, | ||
curve: curveLinear, | ||
}, | ||
'linear-closed': { | ||
curve: d3_shape_1.curveLinearClosed, | ||
curve: curveLinearClosed, | ||
}, | ||
monotone: { | ||
horizontal: d3_shape_1.curveMonotoneY, | ||
vertical: d3_shape_1.curveMonotoneX, | ||
horizontal: curveMonotoneY, | ||
vertical: curveMonotoneX, | ||
}, | ||
natural: { | ||
curve: d3_shape_1.curveNatural, | ||
curve: curveNatural, | ||
}, | ||
step: { | ||
curve: d3_shape_1.curveStep, | ||
curve: curveStep, | ||
}, | ||
'step-after': { | ||
curve: d3_shape_1.curveStepAfter, | ||
curve: curveStepAfter, | ||
}, | ||
'step-before': { | ||
curve: d3_shape_1.curveStepBefore, | ||
curve: curveStepBefore, | ||
}, | ||
}; | ||
function curves(type, orientation, tension) { | ||
const entry = lookup.hasOwnProperty(type) && lookup[type]; | ||
export default function curves(type, orientation, tension) { | ||
const entry = Object.prototype.hasOwnProperty.call(lookup, type) && lookup[type]; | ||
// let curve: CurveFactory | CurveBundleFactory | ||
@@ -100,2 +98,1 @@ if (entry) { | ||
} | ||
exports.default = curves; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,40 +5,34 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const shapes_1 = require("@chart-parts/shapes"); | ||
const curves_1 = require("./curves"); | ||
function arc(item, context) { | ||
return shapes_1.arcShape.context(context)(item); | ||
import { Interpolation, Orientation, } from '@chart-parts/interfaces'; | ||
import { rectShape, arcShape, areavShape, areahShape, lineShape, symbolWithArea, symbolWithWidth, } from '@chart-parts/shapes'; | ||
import curves from './curves'; | ||
export function arc(item, context) { | ||
return arcShape.context(context)(item); | ||
} | ||
exports.arc = arc; | ||
function area(items, context) { | ||
export function area(items, context) { | ||
const first = items[0]; | ||
const interp = first.interpolate || interfaces_1.Interpolation.Linear; | ||
const isHorizontal = first.orient === interfaces_1.Orientation.Horizontal; | ||
const variant = isHorizontal ? shapes_1.areahShape : shapes_1.areavShape; | ||
const interp = first.interpolate || Interpolation.Linear; | ||
const isHorizontal = first.orient === Orientation.Horizontal; | ||
const variant = isHorizontal ? areahShape : areavShape; | ||
return variant | ||
.curve(curves_1.default(interp, first.orient, first.tension)) | ||
.curve(curves(interp, first.orient, first.tension)) | ||
.context(context)(items); | ||
} | ||
exports.area = area; | ||
function line(items, context) { | ||
export function line(items, context) { | ||
const item = items[0]; | ||
const interp = item.interpolate || 'linear'; | ||
return shapes_1.lineShape | ||
.curve(curves_1.default(interp, undefined, item.tension)) | ||
return lineShape | ||
.curve(curves(interp, undefined, item.tension)) | ||
.context(context)(items); | ||
} | ||
exports.line = line; | ||
function rectangle(item, xOffset, yOffset, context) { | ||
return shapes_1.rectShape.build(item, xOffset, yOffset, context); | ||
export function rectangle(item, xOffset, yOffset, context) { | ||
return rectShape.build(item, xOffset, yOffset, context); | ||
} | ||
exports.rectangle = rectangle; | ||
function symbol(item, context) { | ||
export function symbol(item, context) { | ||
if (item.width != null) { | ||
return shapes_1.symbolWithWidth.context(context)(item); | ||
return symbolWithWidth.context(context)(item); | ||
} | ||
else { | ||
return shapes_1.symbolWithArea.context(context)(item); | ||
return symbolWithArea.context(context)(item); | ||
} | ||
} | ||
exports.symbol = symbol; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,6 +5,5 @@ * Copyright (c) Microsoft. All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@chart-parts/interfaces"); | ||
const element_renderers_1 = require("./element_renderers"); | ||
const interfaces_2 = require("./element_renderers/interfaces"); | ||
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, } from '@chart-parts/interfaces'; | ||
import { renderMark } from './element_renderers'; | ||
import { translate } from './element_renderers/interfaces'; | ||
const DEFAULT_BG_COLOR = 'transparent'; | ||
@@ -18,5 +16,5 @@ const DEFAULT_ORIGIN = [0, 0]; | ||
*/ | ||
class VirtualSvgConverter { | ||
export class VirtualSvgConverter { | ||
render(mark, options) { | ||
const { width = interfaces_1.DEFAULT_WIDTH, height = interfaces_1.DEFAULT_HEIGHT, backgroundColor = DEFAULT_BG_COLOR, origin = DEFAULT_ORIGIN, ariaTitle, ariaDescription, } = options; | ||
const { width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, backgroundColor = DEFAULT_BG_COLOR, origin = DEFAULT_ORIGIN, ariaTitle, ariaDescription, } = options; | ||
const [x = 0, y = 0] = origin; | ||
@@ -29,3 +27,3 @@ // Create the rendering Context | ||
// Get the rendering of the root mark | ||
const root = element_renderers_1.renderMark(mark, context); | ||
const root = renderMark(mark, context); | ||
const children = [ | ||
@@ -38,3 +36,3 @@ { | ||
type: 'g', | ||
transforms: [interfaces_2.translate(x, y)], | ||
transforms: [translate(x, y)], | ||
children: root.nodes, | ||
@@ -68,2 +66,1 @@ }, | ||
} | ||
exports.VirtualSvgConverter = VirtualSvgConverter; |
{ | ||
"name": "@chart-parts/vsvg", | ||
"description": "Implementation of the visual prerendering phase, which translates scenegraphs to an intermediate, svg-based, form", | ||
"version": "0.0.21", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"version": "0.1.1", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "lib/index.d.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"start": "tsc -w --preserveWatchOutput", | ||
"build": "tsc -b", | ||
"lint": "tslint 'src/**/*.ts' 'src/**/*.tsx'" | ||
"clean": "../../../scripts/clean_package.sh", | ||
"build": "../../../scripts/build_package.sh", | ||
"start": "../../../scripts/watch_package.sh" | ||
}, | ||
"devDependencies": { | ||
"@chart-parts/scenegraph": "^0.0.21", | ||
"rimraf": "^2.6.2", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.1.3" | ||
"@chart-parts/scenegraph": "^0.1.1" | ||
}, | ||
"dependencies": { | ||
"@chart-parts/interfaces": "^0.0.21", | ||
"@chart-parts/shapes": "^0.0.21", | ||
"@types/d3-path": "^1.0.7", | ||
"@types/d3-shape": "^1.2.4", | ||
"d3-path": "^1.0.7", | ||
"d3-shape": "^1.2.2", | ||
"lodash": "^4.17.10", | ||
"rxjs": "^6.3.3", | ||
"@chart-parts/interfaces": "^0.1.1", | ||
"@chart-parts/shapes": "^0.1.1", | ||
"@types/d3-path": "^1.0.8", | ||
"@types/d3-shape": "^1.2.7", | ||
"d3-path": "^1.0.8", | ||
"d3-shape": "^1.3.5", | ||
"lodash": "^4.17.15", | ||
"shallowequal": "^1.1.0" | ||
@@ -35,3 +30,3 @@ }, | ||
}, | ||
"gitHead": "d2a342f510340335cb0a8ab5e33e4d4e25ed771d" | ||
"gitHead": "745ce2d7118a3b17d0c6ce32555582fdc22d88ff" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
168514
8
1
84
3240
1
+ Added@chart-parts/interfaces@0.1.3(transitive)
+ Added@chart-parts/shapes@0.1.3(transitive)
- Removedrxjs@^6.3.3
- Removed@chart-parts/interfaces@0.0.21(transitive)
- Removed@chart-parts/shapes@0.0.21(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedtslib@1.14.1(transitive)
Updated@chart-parts/shapes@^0.1.1
Updated@types/d3-path@^1.0.8
Updated@types/d3-shape@^1.2.7
Updatedd3-path@^1.0.8
Updatedd3-shape@^1.3.5
Updatedlodash@^4.17.15