@visactor/vrender-components 1.0.47-alpha.0 → 1.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/axis/base.js +9 -9
- package/cjs/axis/base.js.map +1 -1
- package/cjs/axis/circle.js +3 -3
- package/cjs/axis/circle.js.map +1 -1
- package/cjs/axis/grid/base.js +5 -5
- package/cjs/axis/grid/base.js.map +1 -1
- package/cjs/axis/line.js +6 -6
- package/cjs/axis/line.js.map +1 -1
- package/cjs/brush/brush.js +2 -2
- package/cjs/brush/brush.js.map +1 -1
- package/cjs/brush/config.js +2 -1
- package/cjs/checkbox/index.js +1 -2
- package/cjs/core/base.js +2 -2
- package/cjs/core/base.js.map +1 -1
- package/cjs/crosshair/sector.js +1 -2
- package/cjs/data-zoom/config.js +2 -1
- package/cjs/data-zoom/renderer.js.map +1 -1
- package/cjs/empty-tip/empty-tip.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/arc.js +1 -1
- package/cjs/label/base.js +2 -2
- package/cjs/label/base.js.map +1 -1
- package/cjs/label-item/index.js +1 -1
- package/cjs/legend/base.js +2 -2
- package/cjs/legend/base.js.map +1 -1
- package/cjs/legend/discrete/discrete.js +10 -10
- package/cjs/legend/discrete/discrete.js.map +1 -1
- package/cjs/legend/size/size.js +3 -3
- package/cjs/legend/size/size.js.map +1 -1
- package/cjs/marker/arc-area.js +2 -2
- package/cjs/marker/arc-area.js.map +1 -1
- package/cjs/marker/area.js +2 -2
- package/cjs/marker/area.js.map +1 -1
- package/cjs/marker/base.js +4 -4
- package/cjs/marker/base.js.map +1 -1
- package/cjs/marker/point.d.ts +1 -1
- package/cjs/marker/point.js +6 -6
- package/cjs/marker/point.js.map +1 -1
- package/cjs/pager/pager.js +5 -5
- package/cjs/pager/pager.js.map +1 -1
- package/cjs/poptip/contribution.js +3 -10
- package/cjs/poptip/contribution.js.map +1 -1
- package/cjs/poptip/index.d.ts +1 -1
- package/cjs/poptip/index.js +2 -11
- package/cjs/poptip/index.js.map +1 -1
- package/cjs/poptip/module.d.ts +2 -2
- package/cjs/poptip/module.js +17 -10
- package/cjs/poptip/module.js.map +1 -1
- package/cjs/poptip/poptip-plugin.js +5 -12
- package/cjs/poptip/poptip-plugin.js.map +1 -1
- package/cjs/poptip/register.js.map +1 -1
- package/cjs/scrollbar/module.d.ts +2 -2
- package/cjs/scrollbar/module.js +13 -6
- package/cjs/scrollbar/module.js.map +1 -1
- package/cjs/scrollbar/scrollbar-plugin.js +5 -12
- package/cjs/scrollbar/scrollbar-plugin.js.map +1 -1
- package/cjs/segment/arc-segment.js +2 -2
- package/cjs/segment/arc-segment.js.map +1 -1
- package/cjs/segment/segment.js +5 -5
- package/cjs/segment/segment.js.map +1 -1
- package/cjs/slider/slider.d.ts +0 -1
- package/cjs/slider/slider.js +25 -20
- package/cjs/slider/slider.js.map +1 -1
- package/cjs/util/graphic-creator.d.ts +14 -0
- package/cjs/util/graphic-creator.js +22 -0
- package/cjs/util/graphic-creator.js.map +1 -0
- package/cjs/util/text.js +3 -3
- package/cjs/util/text.js.map +1 -1
- package/dist/index.es.js +11618 -11248
- package/es/axis/base.js +3 -1
- package/es/axis/base.js.map +1 -1
- package/es/axis/circle.js +1 -1
- package/es/axis/circle.js.map +1 -1
- package/es/axis/grid/base.js +1 -1
- package/es/axis/grid/base.js.map +1 -1
- package/es/axis/line.js +1 -1
- package/es/axis/line.js.map +1 -1
- package/es/brush/brush.js +1 -1
- package/es/brush/brush.js.map +1 -1
- package/es/brush/config.js +2 -1
- package/es/checkbox/index.js +1 -2
- package/es/core/base.js +2 -2
- package/es/core/base.js.map +1 -1
- package/es/crosshair/sector.js +1 -2
- package/es/data-zoom/config.js +2 -1
- package/es/data-zoom/renderer.js.map +1 -1
- package/es/empty-tip/empty-tip.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/arc.js +1 -1
- package/es/label/base.js +3 -1
- package/es/label/base.js.map +1 -1
- package/es/label-item/index.js +1 -1
- package/es/legend/base.js +1 -1
- package/es/legend/base.js.map +1 -1
- package/es/legend/discrete/discrete.js +1 -1
- package/es/legend/discrete/discrete.js.map +1 -1
- package/es/legend/size/size.js +1 -1
- package/es/legend/size/size.js.map +1 -1
- package/es/marker/arc-area.js +1 -1
- package/es/marker/arc-area.js.map +1 -1
- package/es/marker/area.js +1 -1
- package/es/marker/area.js.map +1 -1
- package/es/marker/base.js +1 -1
- package/es/marker/base.js.map +1 -1
- package/es/marker/point.d.ts +1 -1
- package/es/marker/point.js +1 -1
- package/es/marker/point.js.map +1 -1
- package/es/pager/pager.js +1 -1
- package/es/pager/pager.js.map +1 -1
- package/es/poptip/contribution.js +2 -14
- package/es/poptip/contribution.js.map +1 -1
- package/es/poptip/index.d.ts +1 -1
- package/es/poptip/index.js +1 -1
- package/es/poptip/index.js.map +1 -1
- package/es/poptip/module.d.ts +2 -2
- package/es/poptip/module.js +14 -8
- package/es/poptip/module.js.map +1 -1
- package/es/poptip/poptip-plugin.js +5 -19
- package/es/poptip/poptip-plugin.js.map +1 -1
- package/es/poptip/register.js.map +1 -1
- package/es/scrollbar/module.d.ts +2 -2
- package/es/scrollbar/module.js +11 -5
- package/es/scrollbar/module.js.map +1 -1
- package/es/scrollbar/scrollbar-plugin.js +5 -13
- package/es/scrollbar/scrollbar-plugin.js.map +1 -1
- package/es/segment/arc-segment.js +1 -1
- package/es/segment/arc-segment.js.map +1 -1
- package/es/segment/segment.js +1 -1
- package/es/segment/segment.js.map +1 -1
- package/es/slider/slider.d.ts +0 -1
- package/es/slider/slider.js +15 -8
- package/es/slider/slider.js.map +1 -1
- package/es/util/graphic-creator.d.ts +14 -0
- package/es/util/graphic-creator.js +18 -0
- package/es/util/graphic-creator.js.map +1 -0
- package/es/util/text.js +3 -1
- package/es/util/text.js.map +1 -1
- package/package.json +11 -10
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.graphicCreator = void 0;
|
|
6
|
+
|
|
7
|
+
const vrender_core_1 = require("@visactor/vrender-core"), createGraphic = vrender_core_1.createGraphic;
|
|
8
|
+
|
|
9
|
+
exports.graphicCreator = {
|
|
10
|
+
arc: attributes => createGraphic("arc", attributes),
|
|
11
|
+
circle: attributes => createGraphic("circle", attributes),
|
|
12
|
+
group: attributes => createGraphic("group", attributes),
|
|
13
|
+
image: attributes => createGraphic("image", attributes),
|
|
14
|
+
line: attributes => createGraphic("line", attributes),
|
|
15
|
+
path: attributes => createGraphic("path", attributes),
|
|
16
|
+
polygon: attributes => createGraphic("polygon", attributes),
|
|
17
|
+
rect: attributes => createGraphic("rect", attributes),
|
|
18
|
+
richtext: attributes => createGraphic("richtext", attributes),
|
|
19
|
+
symbol: attributes => createGraphic("symbol", attributes),
|
|
20
|
+
text: attributes => createGraphic("text", attributes)
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=graphic-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/util/graphic-creator.ts"],"names":[],"mappings":";;;AAwBA,yDAA4E;AAE5E,MAAM,aAAa,GAAG,4BAA+F,CAAC;AAEzG,QAAA,cAAc,GAAG;IAC5B,GAAG,EAAE,CAAC,UAAgC,EAAQ,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC;IACjF,MAAM,EAAE,CAAC,UAAmC,EAAW,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC7F,KAAK,EAAE,CAAC,UAAkC,EAAU,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC;IACzF,KAAK,EAAE,CAAC,UAAkC,EAAU,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC;IACzF,IAAI,EAAE,CAAC,UAAiC,EAAS,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC;IACrF,IAAI,EAAE,CAAC,UAAiC,EAAS,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC;IACrF,OAAO,EAAE,CAAC,UAAoC,EAAY,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC;IACjG,IAAI,EAAE,CAAC,UAAiC,EAAS,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC;IACrF,QAAQ,EAAE,CAAC,UAAqC,EAAa,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,UAAU,CAAC;IACrG,MAAM,EAAE,CAAC,UAAmC,EAAW,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC7F,IAAI,EAAE,CAAC,UAAiC,EAAS,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC;CACtF,CAAC","file":"graphic-creator.js","sourcesContent":["import type {\n IArc,\n IArcGraphicAttribute,\n ICircle,\n ICircleGraphicAttribute,\n IGroup,\n IGroupGraphicAttribute,\n IImage,\n IImageGraphicAttribute,\n ILine,\n ILineGraphicAttribute,\n IPath,\n IPathGraphicAttribute,\n IPolygon,\n IPolygonGraphicAttribute,\n IRect,\n IRectGraphicAttribute,\n IRichText,\n IRichTextGraphicAttribute,\n ISymbol,\n ISymbolGraphicAttribute,\n IText,\n ITextGraphicAttribute\n} from '@visactor/vrender-core';\nimport { createGraphic as createCoreGraphic } from '@visactor/vrender-core';\n\nconst createGraphic = createCoreGraphic as <TGraphic, TAttributes>(type: string, attributes: TAttributes) => TGraphic;\n\nexport const graphicCreator = {\n arc: (attributes: IArcGraphicAttribute): IArc => createGraphic('arc', attributes),\n circle: (attributes: ICircleGraphicAttribute): ICircle => createGraphic('circle', attributes),\n group: (attributes: IGroupGraphicAttribute): IGroup => createGraphic('group', attributes),\n image: (attributes: IImageGraphicAttribute): IImage => createGraphic('image', attributes),\n line: (attributes: ILineGraphicAttribute): ILine => createGraphic('line', attributes),\n path: (attributes: IPathGraphicAttribute): IPath => createGraphic('path', attributes),\n polygon: (attributes: IPolygonGraphicAttribute): IPolygon => createGraphic('polygon', attributes),\n rect: (attributes: IRectGraphicAttribute): IRect => createGraphic('rect', attributes),\n richtext: (attributes: IRichTextGraphicAttribute): IRichText => createGraphic('richtext', attributes),\n symbol: (attributes: ISymbolGraphicAttribute): ISymbol => createGraphic('symbol', attributes),\n text: (attributes: ITextGraphicAttribute): IText => createGraphic('text', attributes)\n};\n"]}
|
package/cjs/util/text.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.alignTextInLine = exports.createTextGraphicByType = exports.reactAttributeTransform = exports.htmlAttributeTransform = exports.richTextAttributeTransform = exports.getTextType = exports.isRichText = exports.measureTextSize = exports.initTextMeasure = void 0;
|
|
6
6
|
|
|
7
|
-
const vrender_core_1 = require("@visactor/vrender-core"), vutils_1 = require("@visactor/vutils"), constant_1 = require("../constant"), initTextMeasure = (textSpec, option, useNaiveCanvas, defaultFontParams) => new vutils_1.TextMeasure(Object.assign({
|
|
7
|
+
const vrender_core_1 = require("@visactor/vrender-core"), graphic_creator_1 = require("./graphic-creator"), vutils_1 = require("@visactor/vutils"), constant_1 = require("../constant"), initTextMeasure = (textSpec, option, useNaiveCanvas, defaultFontParams) => new vutils_1.TextMeasure(Object.assign({
|
|
8
8
|
defaultFontParams: Object.assign({
|
|
9
9
|
fontFamily: constant_1.DEFAULT_TEXT_FONT_FAMILY,
|
|
10
10
|
fontSize: constant_1.DEFAULT_TEXT_FONT_SIZE
|
|
@@ -66,8 +66,8 @@ function reactAttributeTransform(attributes) {
|
|
|
66
66
|
|
|
67
67
|
function createTextGraphicByType(textAttributes, typeKey = "type") {
|
|
68
68
|
const textType = getTextType(textAttributes, typeKey);
|
|
69
|
-
return "rich" === textType ?
|
|
70
|
-
|
|
69
|
+
return "rich" === textType ? graphic_creator_1.graphicCreator.richtext(richTextAttributeTransform(textAttributes)) : ("html" === textType ? textAttributes = htmlAttributeTransform(textAttributes) : "react" === textType && (textAttributes = reactAttributeTransform(textAttributes)),
|
|
70
|
+
graphic_creator_1.graphicCreator.text(textAttributes));
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
function alignTextInLine(layoutAlign, graphic, textAlign, pos, textWidth) {
|
package/cjs/util/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/util/text.ts"],"names":[],"mappings":";;;AAQA,
|
|
1
|
+
{"version":3,"sources":["../src/util/text.ts"],"names":[],"mappings":";;;AAQA,yDAAuD;AACvD,uDAAmD;AAGnD,6CAAkE;AAClE,0CAA+E;AAGxE,MAAM,eAAe,GAAG,CAC7B,QAAyC,EACzC,MAAoC,EACpC,cAAwB,EACxB,iBAAkD,EACd,EAAE;IACtC,OAAO,IAAI,oBAAW,iBAElB,iBAAiB,kBACf,UAAU,EAAE,mCAAwB,EACpC,QAAQ,EAAE,iCAAsB,IAC7B,iBAAiB,GAEtB,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,4BAAa,EACzD,cAAc,EAAE,cAAc,GAAG,oBAAW,CAAC,iBAAiB,GAAG,oBAAW,CAAC,iBAAiB,CAAC,WAAW,EAAE,IACzG,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,GAEnB,QAAQ,CACT,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,eAAe,mBAmB1B;AAGF,SAAgB,eAAe,CAC7B,IAA2C,EAC3C,QAAwC,EACxC,mBAAmD,EAAE;IAErD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;KAChC;IACD,MAAM,MAAM,GAAG,IAAA,4BAAa,EAAC;QAC3B,IAAI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text.js","sourcesContent":["import type {\n IRichText,\n IRichTextAttribute,\n IText,\n ITextGraphicAttribute,\n TextAlignType\n} from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { getTextBounds } from '@visactor/vrender-core';\nimport { graphicCreator } from './graphic-creator';\nimport type { ITextMeasureOption } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { TextMeasure, isObject, isValid } from '@visactor/vutils';\nimport { DEFAULT_TEXT_FONT_FAMILY, DEFAULT_TEXT_FONT_SIZE } from '../constant';\nimport type { HTMLTextContent, ReactTextContent, TextContent } from '../core/type';\n\nexport const initTextMeasure = (\n textSpec?: Partial<ITextGraphicAttribute>,\n option?: Partial<ITextMeasureOption>,\n useNaiveCanvas?: boolean,\n defaultFontParams?: Partial<ITextGraphicAttribute>\n): TextMeasure<ITextGraphicAttribute> => {\n return new TextMeasure<ITextGraphicAttribute>(\n {\n defaultFontParams: {\n fontFamily: DEFAULT_TEXT_FONT_FAMILY,\n fontSize: DEFAULT_TEXT_FONT_SIZE,\n ...defaultFontParams\n },\n getTextBounds: useNaiveCanvas ? undefined : getTextBounds,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n textSpec\n );\n};\n\n// FIXME: 和上一个方法统一,使用 TextMeasure 类\nexport function measureTextSize(\n text: string | number | string[] | number[],\n textSpec: Partial<ITextGraphicAttribute>,\n defaultTextTheme: Partial<ITextGraphicAttribute> = {}\n) {\n if (!text) {\n return { width: 0, height: 0 };\n }\n const bounds = getTextBounds({\n text,\n fontFamily: textSpec.fontFamily || defaultTextTheme.fontFamily || DEFAULT_TEXT_FONT_FAMILY,\n fontSize: textSpec.fontSize || defaultTextTheme.fontSize || 12,\n fontWeight: textSpec.fontWeight || defaultTextTheme.fontWeight,\n textAlign: textSpec.textAlign || 'center',\n textBaseline: textSpec.textBaseline,\n ellipsis: !!textSpec.ellipsis,\n maxLineWidth: textSpec.maxLineWidth || Infinity,\n lineHeight: textSpec.fontSize || defaultTextTheme.fontSize || 12\n });\n\n return { width: bounds.width(), height: bounds.height() };\n}\n\nexport function isRichText(attributes: TextContent, typeKey = 'type') {\n return getTextType(attributes, typeKey) === 'rich';\n}\n\nexport function getTextType(attributes: TextContent, typeKey = 'type') {\n if (isObject(attributes.text) && 'type' in attributes.text) {\n return attributes.text.type ?? 'text';\n }\n\n if (typeKey in attributes) {\n return attributes[typeKey] ?? 'text';\n }\n\n return 'text';\n}\n\nexport function richTextAttributeTransform(attributes: ITextGraphicAttribute & IRichTextAttribute & TextContent) {\n if (isValid(attributes.maxLineWidth)) {\n attributes.maxWidth = attributes.maxLineWidth;\n delete attributes.maxLineWidth;\n }\n\n attributes.width = attributes.width ?? 0;\n attributes.height = attributes.height ?? 0;\n attributes.textConfig = (attributes.text as unknown as any).text || attributes.text;\n return attributes;\n}\n\nexport function htmlAttributeTransform(attributes: ITextGraphicAttribute) {\n const { text, _originText } = attributes as unknown as HTMLTextContent;\n const { text: html } = text;\n\n attributes.html = html;\n attributes.text = _originText;\n attributes.renderable = false; // 文字图元配置了 html,则不绘制原始文字\n return attributes;\n}\n\nexport function reactAttributeTransform(attributes: ITextGraphicAttribute) {\n const { text, _originText } = attributes as unknown as ReactTextContent;\n const { text: react } = text;\n\n attributes.react = react;\n attributes.text = _originText;\n attributes.renderable = false; // 文字图元配置了 react,则不绘制原始文字\n\n return attributes;\n}\n\nexport function createTextGraphicByType(textAttributes: ITextGraphicAttribute, typeKey = 'type') {\n const textType = getTextType(textAttributes, typeKey);\n if (textType === 'rich') {\n return graphicCreator.richtext(richTextAttributeTransform(textAttributes as IRichTextAttribute));\n }\n\n if (textType === 'html') {\n textAttributes = htmlAttributeTransform(textAttributes);\n } else if (textType === 'react') {\n textAttributes = reactAttributeTransform(textAttributes);\n }\n\n return graphicCreator.text(textAttributes as ITextGraphicAttribute);\n}\n\nexport function alignTextInLine(\n layoutAlign: 'left' | 'right',\n graphic: IText | IRichText,\n textAlign: TextAlignType,\n pos: number,\n textWidth: number\n) {\n if (layoutAlign === 'right') {\n if (textAlign === 'center') {\n graphic.setAttribute('x', pos - textWidth / 2);\n } else if (textAlign === 'right' || textAlign === 'end') {\n // 右对齐\n graphic.setAttribute('x', pos);\n } else {\n // 默认左对齐\n graphic.setAttribute('x', pos - textWidth);\n }\n } else {\n if (textAlign === 'center') {\n graphic.setAttribute('x', pos + textWidth / 2);\n } else if (textAlign === 'right' || textAlign === 'end') {\n // 右对齐\n graphic.setAttribute('x', pos + textWidth);\n } else {\n // 默认左对齐\n graphic.setAttribute('x', pos);\n }\n }\n}\n"]}
|