@visactor/vrender-components 0.18.9 → 0.18.10-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 +5 -1
- package/cjs/axis/base.js.map +1 -1
- package/cjs/axis/circle.js +1 -1
- package/cjs/axis/circle.js.map +1 -1
- package/cjs/axis/grid/base.js +5 -1
- package/cjs/axis/grid/base.js.map +1 -1
- package/cjs/axis/index.d.ts +0 -1
- package/cjs/axis/index.js +1 -1
- package/cjs/axis/index.js.map +1 -1
- package/cjs/axis/mixin/circle.js +4 -2
- package/cjs/axis/mixin/circle.js.map +1 -1
- package/cjs/axis/overlap/auto-limit.js +13 -8
- package/cjs/axis/overlap/auto-limit.js.map +1 -1
- package/cjs/axis/util.d.ts +2 -5
- package/cjs/axis/util.js +5 -18
- package/cjs/axis/util.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/legend/color/color.js +5 -7
- package/cjs/legend/color/color.js.map +1 -1
- package/cjs/legend/size/size.js +4 -6
- package/cjs/legend/size/size.js.map +1 -1
- package/cjs/marker/base-line.d.ts +17 -0
- package/cjs/marker/base-line.js +67 -0
- package/cjs/marker/base-line.js.map +1 -0
- package/cjs/marker/base.d.ts +7 -0
- package/cjs/marker/base.js +40 -3
- package/cjs/marker/base.js.map +1 -1
- package/cjs/marker/{area.d.ts → cartesian/area.d.ts} +8 -7
- package/cjs/marker/{area.js → cartesian/area.js} +18 -12
- package/cjs/marker/cartesian/area.js.map +1 -0
- package/cjs/marker/cartesian/line.d.ts +14 -0
- package/cjs/marker/cartesian/line.js +57 -0
- package/cjs/marker/cartesian/line.js.map +1 -0
- package/cjs/marker/config.d.ts +37 -7
- package/cjs/marker/config.js +36 -7
- package/cjs/marker/config.js.map +1 -1
- package/cjs/marker/index.d.ts +4 -2
- package/cjs/marker/index.js +3 -2
- package/cjs/marker/index.js.map +1 -1
- package/cjs/marker/point.d.ts +1 -0
- package/cjs/marker/point.js +22 -6
- package/cjs/marker/point.js.map +1 -1
- package/cjs/marker/polar/arc-line.d.ts +11 -0
- package/cjs/marker/polar/arc-line.js +50 -0
- package/cjs/marker/polar/arc-line.js.map +1 -0
- package/cjs/marker/polar/area.d.ts +44 -0
- package/cjs/marker/polar/area.js +117 -0
- package/cjs/marker/polar/area.js.map +1 -0
- package/cjs/marker/polar/line.d.ts +1 -0
- package/cjs/marker/polar/line.js +3 -0
- package/cjs/marker/polar/line.js.map +1 -0
- package/cjs/marker/register.d.ts +5 -2
- package/cjs/marker/register.js +18 -5
- package/cjs/marker/register.js.map +1 -1
- package/cjs/marker/type.d.ts +111 -15
- package/cjs/marker/type.js +21 -15
- package/cjs/marker/type.js.map +1 -1
- package/cjs/segment/arc-segment.d.ts +13 -0
- package/cjs/segment/arc-segment.js +51 -0
- package/cjs/segment/arc-segment.js.map +1 -0
- package/cjs/segment/index.d.ts +1 -0
- package/cjs/segment/index.js +2 -1
- package/cjs/segment/index.js.map +1 -1
- package/cjs/segment/register.d.ts +2 -1
- package/cjs/segment/register.js +8 -3
- package/cjs/segment/register.js.map +1 -1
- package/cjs/segment/segment.d.ts +9 -7
- package/cjs/segment/segment.js +12 -8
- package/cjs/segment/segment.js.map +1 -1
- package/cjs/segment/type.d.ts +24 -4
- package/cjs/segment/type.js.map +1 -1
- package/cjs/slider/slider.d.ts +0 -2
- package/cjs/slider/slider.js +38 -53
- package/cjs/slider/slider.js.map +1 -1
- package/cjs/slider/type.d.ts +0 -1
- package/cjs/slider/type.js.map +1 -1
- package/cjs/tag/tag.js.map +1 -1
- package/es/axis/base.js +6 -2
- package/es/axis/base.js.map +1 -1
- package/es/axis/circle.js +2 -2
- package/es/axis/circle.js.map +1 -1
- package/es/axis/grid/base.js +6 -2
- package/es/axis/grid/base.js.map +1 -1
- package/es/axis/index.d.ts +0 -1
- package/es/axis/index.js +0 -2
- package/es/axis/index.js.map +1 -1
- package/es/axis/mixin/circle.js +3 -2
- package/es/axis/mixin/circle.js.map +1 -1
- package/es/axis/overlap/auto-limit.js +13 -9
- package/es/axis/overlap/auto-limit.js.map +1 -1
- package/es/axis/util.d.ts +2 -5
- package/es/axis/util.js +1 -15
- package/es/axis/util.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/legend/color/color.js +5 -7
- package/es/legend/color/color.js.map +1 -1
- package/es/legend/size/size.js +4 -6
- package/es/legend/size/size.js.map +1 -1
- package/es/marker/base-line.d.ts +17 -0
- package/es/marker/base-line.js +71 -0
- package/es/marker/base-line.js.map +1 -0
- package/es/marker/base.d.ts +7 -0
- package/es/marker/base.js +45 -2
- package/es/marker/base.js.map +1 -1
- package/es/marker/{area.d.ts → cartesian/area.d.ts} +8 -7
- package/es/marker/{area.js → cartesian/area.js} +23 -15
- package/es/marker/cartesian/area.js.map +1 -0
- package/es/marker/cartesian/line.d.ts +14 -0
- package/es/marker/cartesian/line.js +61 -0
- package/es/marker/cartesian/line.js.map +1 -0
- package/es/marker/config.d.ts +37 -7
- package/es/marker/config.js +38 -7
- package/es/marker/config.js.map +1 -1
- package/es/marker/index.d.ts +4 -2
- package/es/marker/index.js +6 -2
- package/es/marker/index.js.map +1 -1
- package/es/marker/point.d.ts +1 -0
- package/es/marker/point.js +23 -5
- package/es/marker/point.js.map +1 -1
- package/es/marker/polar/arc-line.d.ts +11 -0
- package/es/marker/polar/arc-line.js +54 -0
- package/es/marker/polar/arc-line.js.map +1 -0
- package/es/marker/polar/area.d.ts +44 -0
- package/es/marker/polar/area.js +127 -0
- package/es/marker/polar/area.js.map +1 -0
- package/es/marker/polar/line.d.ts +1 -0
- package/es/marker/polar/line.js +3 -0
- package/es/marker/polar/line.js.map +1 -0
- package/es/marker/register.d.ts +5 -2
- package/es/marker/register.js +16 -4
- package/es/marker/register.js.map +1 -1
- package/es/marker/type.d.ts +111 -15
- package/es/marker/type.js +24 -15
- package/es/marker/type.js.map +1 -1
- package/es/segment/arc-segment.d.ts +13 -0
- package/es/segment/arc-segment.js +49 -0
- package/es/segment/arc-segment.js.map +1 -0
- package/es/segment/index.d.ts +1 -0
- package/es/segment/index.js +2 -0
- package/es/segment/index.js.map +1 -1
- package/es/segment/register.d.ts +2 -1
- package/es/segment/register.js +6 -2
- package/es/segment/register.js.map +1 -1
- package/es/segment/segment.d.ts +9 -7
- package/es/segment/segment.js +11 -8
- package/es/segment/segment.js.map +1 -1
- package/es/segment/type.d.ts +24 -4
- package/es/segment/type.js.map +1 -1
- package/es/slider/slider.d.ts +0 -2
- package/es/slider/slider.js +36 -50
- package/es/slider/slider.js.map +1 -1
- package/es/slider/type.d.ts +0 -1
- package/es/slider/type.js.map +1 -1
- package/es/tag/tag.js.map +1 -1
- package/package.json +3 -3
- package/cjs/marker/area.js.map +0 -1
- package/cjs/marker/line.d.ts +0 -18
- package/cjs/marker/line.js +0 -90
- package/cjs/marker/line.js.map +0 -1
- package/es/marker/area.js.map +0 -1
- package/es/marker/line.d.ts +0 -18
- package/es/marker/line.js +0 -96
- package/es/marker/line.js.map +0 -1
package/es/axis/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/axis/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIvD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAc,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAgB,CAAC,EAAE,EAAE;IAC/C,IAAI,KAAK,GAAG,CAAC,EAAE;QACb,OAAO,KAAK,GAAG,CAAC,EAAE;YAChB,KAAK,IAAI,GAAG,CA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KAAK,GAAmB,EAAE,CAAC;IACjC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAY,EAAE,EAAE;QAChC,IAAK,EAAe,CAAC,IAAI,KAAK,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE;YAC9C,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;SACnB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC","file":"util.js","sourcesContent":["import { getTextBounds } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IGraphic, IGroup, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport type { Dict } from '@visactor/vutils';\nimport { isGreater, isLess, tau, type Point } from '@visactor/vutils';\nimport { traverseGroup } from '../util/common';\n\n// 和 vutils 版本不同\nexport const clampRadian = (angle: number = 0) => {\n if (angle < 0) {\n while (angle < 0) {\n angle += tau;\n }\n } else if (angle > 0) {\n while (angle > tau) {\n angle -= tau;\n }\n }\n return angle;\n};\n\n// 判断数值是否在制定范围内,包含误差\nexport function isInRange(a: number, min: number, max: number) {\n return !isLess(a, min, 0, 1e-6) && !isGreater(a, max, 0, 1e-6);\n}\n\nexport function getLabelPosition(\n tickPosition: Point,\n tickVector: [number, number],\n text: string | number,\n style: Partial<ITextGraphicAttribute>\n) {\n const labelBounds = getTextBounds({\n text,\n ...style\n });\n const width = labelBounds.width();\n const height = labelBounds.height();\n const angle = clampRadian(Math.atan2(tickVector[1], tickVector[0])) - Math.PI;\n\n const PI_3_4 = (Math.PI * 3) / 4;\n const PI_1_4 = Math.PI / 4;\n const PI_1_2 = Math.PI / 2;\n\n // x\n const baseX = tickPosition.x;\n let dx = 0;\n if (isInRange(angle, -PI_3_4, -PI_1_4)) {\n dx = ((angle + PI_3_4) / PI_1_2 - 0.5) * width;\n } else if (isInRange(angle, PI_1_4, PI_3_4)) {\n dx = (0.5 - (angle - PI_1_4) / PI_1_2) * width;\n } else if (Math.cos(angle) >= 0) {\n dx = width * 0.5;\n } else {\n dx = -width * 0.5;\n }\n const x = baseX - dx;\n\n const baseY = tickPosition.y;\n let dy = 0;\n if (isInRange(angle, -PI_3_4, -PI_1_4)) {\n dy = -height * 0.5;\n } else if (isInRange(angle, PI_1_4, PI_3_4)) {\n dy = height * 0.5;\n } else if (Math.cos(angle) >= 0) {\n dy = (0.5 - (PI_1_4 - angle) / PI_1_2) * height;\n } else {\n dy = (0.5 - clampRadian(angle - PI_3_4) / PI_1_2) * height;\n }\n const y = baseY - dy;\n\n return { x, y };\n}\n\nexport function getElMap(g: IGroup) {\n const elMap: Dict<IGraphic> = {};\n traverseGroup(g, (el: IGraphic) => {\n if ((el as IGraphic).type !== 'group' && el.id) {\n elMap[el.id] = el;\n }\n });\n return elMap;\n}\n"]}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAEzC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.18.10-alpha.1\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './util';\n"]}
|
package/es/legend/color/color.js
CHANGED
|
@@ -30,7 +30,7 @@ export class ColorContinuousLegend extends LegendBase {
|
|
|
30
30
|
this._slider && (this._slider.setValue(value), this._updateColor());
|
|
31
31
|
}
|
|
32
32
|
_renderContent() {
|
|
33
|
-
const {colors: colors, slidable: slidable, layout: layout, align: align, min: min, max: max, value: value, railWidth: railWidth, railHeight: railHeight, showHandler: showHandler = !0, handlerSize: handlerSize, handlerStyle: handlerStyle, railStyle: railStyle, trackStyle: trackStyle, startText: startText, endText: endText, handlerText: handlerText, showTooltip: showTooltip, tooltip: tooltip,
|
|
33
|
+
const {colors: colors, slidable: slidable, layout: layout, align: align, min: min, max: max, value: value, railWidth: railWidth, railHeight: railHeight, showHandler: showHandler = !0, handlerSize: handlerSize, handlerStyle: handlerStyle, railStyle: railStyle, trackStyle: trackStyle, startText: startText, endText: endText, handlerText: handlerText, showTooltip: showTooltip, tooltip: tooltip, disableTriggerEvent: disableTriggerEvent} = this.attribute, domain = [], step = (max - min) / (colors.length - 1);
|
|
34
34
|
for (let i = 0; i < colors.length; i++) domain.push(min + step * i);
|
|
35
35
|
this._colorScale = (new LinearScale).domain(domain, !0).range(colors), this._color = this._getTrackColor();
|
|
36
36
|
const slider = new Slider({
|
|
@@ -59,8 +59,7 @@ export class ColorContinuousLegend extends LegendBase {
|
|
|
59
59
|
handlerText: handlerText,
|
|
60
60
|
showTooltip: showTooltip,
|
|
61
61
|
tooltip: tooltip,
|
|
62
|
-
disableTriggerEvent: disableTriggerEvent
|
|
63
|
-
inverse: inverse
|
|
62
|
+
disableTriggerEvent: disableTriggerEvent
|
|
64
63
|
});
|
|
65
64
|
this._innerView.add(slider), this._slider = slider, slider.translateTo(0 - slider.AABBBounds.x1, (this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", DEFAULT_TITLE_SPACE) : 0) - slider.AABBBounds.y1),
|
|
66
65
|
this._updateColor();
|
|
@@ -70,7 +69,7 @@ export class ColorContinuousLegend extends LegendBase {
|
|
|
70
69
|
this._slider.addEventListener("sliderTooltip", this._onSliderToolipChange));
|
|
71
70
|
}
|
|
72
71
|
_getTrackColor() {
|
|
73
|
-
const {colors: colors, layout: layout
|
|
72
|
+
const {colors: colors, layout: layout} = this.attribute;
|
|
74
73
|
if (isEmpty(colors)) return;
|
|
75
74
|
const count = colors.length;
|
|
76
75
|
if (1 === count) return colors[0];
|
|
@@ -82,7 +81,8 @@ export class ColorContinuousLegend extends LegendBase {
|
|
|
82
81
|
color: colors[i]
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
|
-
const isHorizontal = "horizontal" === layout
|
|
84
|
+
const isHorizontal = "horizontal" === layout;
|
|
85
|
+
return {
|
|
86
86
|
gradient: "linear",
|
|
87
87
|
stops: stops,
|
|
88
88
|
x0: 0,
|
|
@@ -90,8 +90,6 @@ export class ColorContinuousLegend extends LegendBase {
|
|
|
90
90
|
x1: isHorizontal ? 1 : 0,
|
|
91
91
|
y1: isHorizontal ? 0 : 1
|
|
92
92
|
};
|
|
93
|
-
return inverse && (isHorizontal ? (res.x0 = 1, res.x1 = 0) : (res.y0 = 1, res.y1 = 0)),
|
|
94
|
-
res;
|
|
95
93
|
}
|
|
96
94
|
_updateColor() {
|
|
97
95
|
const {layout: layout = "horizontal", colors: colors, railWidth: railWidth, railHeight: railHeight} = this.attribute, {startHandler: startHandler, endHandler: endHandler, track: track} = this._slider, {startValue: startValue, endValue: endValue, startPos: startPos, endPos: endPos} = this._slider.currentValue, startHandlerColor = this._colorScale.scale(startValue), endHandlerColor = this._colorScale.scale(endValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/legend/color/color.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AAEjE,kCAAkC,EAAE,CAAC;AACrC,MAAM,OAAO,qBAAsB,SAAQ,UAAiC;IAqC1E,YAAY,UAAiC,EAAE,OAA0B;QACvE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,qBAAqB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QArC5G,SAAI,GAAG,aAAa,CAAC;QAsLb,0BAAqB,GAAG,CAAC,CAAiB,EAAE,EAAE;YACpD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;YAE/C,IAAI,YAAY,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBACtD,MAAM,KAAK,GAAG,IAAI,CAA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M,EAAE,YAAY;IACpB,KAAK,EAAE;QAEL,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,mBAAmB;QAC1B,SAAS,EAAE;YACT,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,qBAAqB;SAC5B;KACF;IACD,WAAW,EAAE,EAAE;IACf,YAAY,EAAE;QACZ,SAAS,EAAE,CAAC;QACZ,MAAM,EAAE,MAAM;QACd,WAAW,EAAE;YACX,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,MAAM;SACf;KACF;IACD,OAAO,EAAE;QACP,UAAU,EAAE;YACV,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,MAAM;SACf;KACF;CACF,CAAC","file":"color.js","sourcesContent":["/**\n * @description 连续颜色图例\n * TODO:\n * showHandlers 测试\n */\nimport { merge, isEmpty, get, isNil } from '@visactor/vutils';\nimport type { FederatedPointerEvent, FederatedEvent, IColor, ILinearGradient, INode } from '@visactor/vrender-core';\nimport type { ILinearScale } from '@visactor/vscale';\nimport { LinearScale } from '@visactor/vscale';\nimport { LegendBase } from '../base';\nimport { Slider } from '../../slider';\nimport { DEFAULT_TITLE_SPACE } from '../constant';\nimport type { ColorLegendAttributes } from './type';\nimport type { ComponentOptions } from '../../interface';\nimport { loadColorContinuousLegendComponent } from '../register';\n\nloadColorContinuousLegendComponent();\nexport class ColorContinuousLegend extends LegendBase<ColorLegendAttributes> {\n name = 'colorLegend';\n\n static defaultAttributes = {\n layout: 'horizontal',\n title: {\n // orient: 'top',\n align: 'start',\n space: DEFAULT_TITLE_SPACE,\n textStyle: {\n fontSize: 12,\n fontWeight: 'bold',\n fill: 'rgba(46, 47, 50, 1)'\n }\n },\n handlerSize: 10,\n handlerStyle: {\n lineWidth: 4,\n stroke: '#fff',\n outerBorder: {\n distance: 2,\n lineWidth: 1,\n stroke: '#ccc'\n }\n },\n tooltip: {\n shapeStyle: {\n lineWidth: 4,\n stroke: '#fff'\n }\n }\n };\n\n private _slider!: Slider;\n private _colorScale!: ILinearScale;\n private _color: IColor | undefined;\n\n constructor(attributes: ColorLegendAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, ColorContinuousLegend.defaultAttributes, attributes));\n }\n\n /**\n * 更新数据选中范围\n * @param value 选中数据范围\n * @returns\n */\n setSelected(value: number[]) {\n if (!this._slider) {\n return;\n }\n this._slider.setValue(value);\n this._updateColor();\n }\n\n protected _renderContent(): void {\n const {\n colors,\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler = true,\n handlerSize,\n handlerStyle,\n railStyle,\n trackStyle,\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n inverse,\n disableTriggerEvent\n } = this.attribute as ColorLegendAttributes;\n\n // 创建 colorScale\n const domain = [];\n const step = (max - min) / (colors.length - 1);\n for (let i = 0; i < colors.length; i++) {\n domain.push(min + step * i);\n }\n\n this._colorScale = new LinearScale().domain(domain, true).range(colors);\n this._color = this._getTrackColor();\n\n const slider = new Slider({\n x: 0,\n y: 0,\n range: {\n draggableTrack: true\n },\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler,\n handlerSize,\n handlerStyle,\n railStyle,\n trackStyle: {\n fill: this._color,\n ...trackStyle\n },\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n disableTriggerEvent,\n inverse\n });\n this._innerView.add(slider as unknown as INode);\n this._slider = slider;\n // 做下位置调整,对齐\n slider.translateTo(\n 0 - slider.AABBBounds.x1,\n (this._title ? this._title.AABBBounds.height() + get(this.attribute, 'title.space', DEFAULT_TITLE_SPACE) : 0) -\n slider.AABBBounds.y1\n );\n this._updateColor();\n }\n\n protected _bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n if (this._slider) {\n this._slider.addEventListener('change', this._onSliderChange as EventListenerOrEventListenerObject);\n this._slider.addEventListener('sliderTooltip', this._onSliderToolipChange as EventListenerOrEventListenerObject);\n }\n }\n\n private _getTrackColor(): IColor | undefined {\n const { colors, layout, inverse } = this.attribute as ColorLegendAttributes;\n\n if (isEmpty(colors)) {\n return undefined;\n }\n const count = colors.length;\n if (count === 1) {\n return colors[0];\n }\n const stops = [];\n\n for (let i = 0; i < count; i++) {\n const percent = i / (count - 1);\n stops.push({\n offset: percent,\n color: colors[i]\n });\n }\n const isHorizontal = layout === 'horizontal';\n\n const res: IColor = {\n gradient: 'linear',\n stops,\n x0: 0,\n y0: 0,\n x1: isHorizontal ? 1 : 0,\n y1: isHorizontal ? 0 : 1\n };\n\n if (inverse) {\n if (isHorizontal) {\n res.x0 = 1;\n res.x1 = 0;\n } else {\n res.y0 = 1;\n res.y1 = 0;\n }\n }\n\n return res;\n }\n\n private _onSliderToolipChange = (e: FederatedEvent) => {\n const tooltipShape = this._slider.tooltipShape;\n\n if (tooltipShape && e.detail && !isNil(e.detail.value)) {\n const color = this._colorScale.scale(e.detail.value);\n\n tooltipShape.setAttribute('fill', color);\n }\n\n this.dispatchEvent(e);\n };\n\n private _onSliderChange = (e: FederatedEvent) => {\n // 更新 handler 以及 track 的渐变色\n this._updateColor();\n this.dispatchEvent(e);\n };\n\n private _updateColor() {\n const { layout = 'horizontal', colors, railWidth, railHeight } = this.attribute as ColorLegendAttributes;\n const { startHandler, endHandler, track } = this._slider;\n const { startValue, endValue, startPos, endPos } = this._slider.currentValue;\n\n // 计算颜色\n const startHandlerColor = this._colorScale.scale(startValue);\n const endHandlerColor = this._colorScale.scale(endValue);\n startHandler?.setAttribute('fill', startHandlerColor);\n endHandler?.setAttribute('fill', endHandlerColor);\n\n const isHorizontal = layout === 'horizontal';\n const railLen = isHorizontal ? railWidth : railHeight;\n const trackLength = Math.abs((startPos as number) - (endPos as number));\n\n // 计算渐变色\n if (trackLength !== railLen && colors && colors.length > 1) {\n const stops = (this._color as ILinearGradient).stops;\n const start = Math.min(startPos as number, endPos as number);\n const end = Math.max(startPos as number, endPos as number);\n const startRatio = start / railLen;\n const endRatio = end / railLen;\n const range = endRatio - startRatio;\n const betweenStops = stops.filter(stop => stop.offset > startRatio && stop.offset < endRatio);\n\n const minValue = Math.min(startValue, endValue);\n const maxValue = Math.max(startValue, endValue);\n const startColor = this._colorScale.scale(minValue);\n const endColor = this._colorScale.scale(maxValue);\n const newStops = [{ offset: 0, color: startColor }];\n betweenStops.forEach(stop => {\n newStops.push({\n offset: (stop.offset - startRatio) / range,\n color: stop.color\n });\n });\n newStops.push({\n offset: 1,\n color: endColor\n });\n track.setAttribute('fill', {\n ...(this._color as ILinearGradient),\n stops: newStops\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/legend/color/color.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AAEjE,kCAAkC,EAAE,CAAC;AACrC,MAAM,OAAO,qBAAsB,SAAQ,UAAiC;IAqC1E,YAAY,UAAiC,EAAE,OAA0B;QACvE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,qBAAqB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QArC5G,SAAI,GAAG,aAAa,CAAC;QAsKb,0BAAqB,GAAG,CAAC,CAAiB,EAAE,EAAE;YACpD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;YAE/C,IAAI,YA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B;KACF;IACD,WAAW,EAAE,EAAE;IACf,YAAY,EAAE;QACZ,SAAS,EAAE,CAAC;QACZ,MAAM,EAAE,MAAM;QACd,WAAW,EAAE;YACX,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,MAAM;SACf;KACF;IACD,OAAO,EAAE;QACP,UAAU,EAAE;YACV,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,MAAM;SACf;KACF;CACF,CAAC","file":"color.js","sourcesContent":["/**\n * @description 连续颜色图例\n * TODO:\n * showHandlers 测试\n */\nimport { merge, isEmpty, get, isNil } from '@visactor/vutils';\nimport type { FederatedPointerEvent, FederatedEvent, IColor, ILinearGradient, INode } from '@visactor/vrender-core';\nimport type { ILinearScale } from '@visactor/vscale';\nimport { LinearScale } from '@visactor/vscale';\nimport { LegendBase } from '../base';\nimport { Slider } from '../../slider';\nimport { DEFAULT_TITLE_SPACE } from '../constant';\nimport type { ColorLegendAttributes } from './type';\nimport type { ComponentOptions } from '../../interface';\nimport { loadColorContinuousLegendComponent } from '../register';\n\nloadColorContinuousLegendComponent();\nexport class ColorContinuousLegend extends LegendBase<ColorLegendAttributes> {\n name = 'colorLegend';\n\n static defaultAttributes = {\n layout: 'horizontal',\n title: {\n // orient: 'top',\n align: 'start',\n space: DEFAULT_TITLE_SPACE,\n textStyle: {\n fontSize: 12,\n fontWeight: 'bold',\n fill: 'rgba(46, 47, 50, 1)'\n }\n },\n handlerSize: 10,\n handlerStyle: {\n lineWidth: 4,\n stroke: '#fff',\n outerBorder: {\n distance: 2,\n lineWidth: 1,\n stroke: '#ccc'\n }\n },\n tooltip: {\n shapeStyle: {\n lineWidth: 4,\n stroke: '#fff'\n }\n }\n };\n\n private _slider!: Slider;\n private _colorScale!: ILinearScale;\n private _color: IColor | undefined;\n\n constructor(attributes: ColorLegendAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, ColorContinuousLegend.defaultAttributes, attributes));\n }\n\n /**\n * 更新数据选中范围\n * @param value 选中数据范围\n * @returns\n */\n setSelected(value: number[]) {\n if (!this._slider) {\n return;\n }\n this._slider.setValue(value);\n this._updateColor();\n }\n\n protected _renderContent(): void {\n const {\n colors,\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler = true,\n handlerSize,\n handlerStyle,\n railStyle,\n trackStyle,\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n disableTriggerEvent\n } = this.attribute as ColorLegendAttributes;\n\n // 创建 colorScale\n const domain = [];\n const step = (max - min) / (colors.length - 1);\n for (let i = 0; i < colors.length; i++) {\n domain.push(min + step * i);\n }\n this._colorScale = new LinearScale().domain(domain, true).range(colors);\n this._color = this._getTrackColor();\n\n const slider = new Slider({\n x: 0,\n y: 0,\n range: {\n draggableTrack: true\n },\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler,\n handlerSize,\n handlerStyle,\n railStyle,\n trackStyle: {\n fill: this._color,\n ...trackStyle\n },\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n disableTriggerEvent\n });\n this._innerView.add(slider as unknown as INode);\n this._slider = slider;\n // 做下位置调整,对齐\n slider.translateTo(\n 0 - slider.AABBBounds.x1,\n (this._title ? this._title.AABBBounds.height() + get(this.attribute, 'title.space', DEFAULT_TITLE_SPACE) : 0) -\n slider.AABBBounds.y1\n );\n this._updateColor();\n }\n\n protected _bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n if (this._slider) {\n this._slider.addEventListener('change', this._onSliderChange as EventListenerOrEventListenerObject);\n this._slider.addEventListener('sliderTooltip', this._onSliderToolipChange as EventListenerOrEventListenerObject);\n }\n }\n\n private _getTrackColor(): IColor | undefined {\n const { colors, layout } = this.attribute as ColorLegendAttributes;\n\n if (isEmpty(colors)) {\n return undefined;\n }\n const count = colors.length;\n if (count === 1) {\n return colors[0];\n }\n const stops = [];\n\n for (let i = 0; i < count; i++) {\n const percent = i / (count - 1);\n stops.push({\n offset: percent,\n color: colors[i]\n });\n }\n const isHorizontal = layout === 'horizontal';\n return {\n gradient: 'linear',\n stops,\n x0: 0,\n y0: 0,\n x1: isHorizontal ? 1 : 0,\n y1: isHorizontal ? 0 : 1\n };\n }\n\n private _onSliderToolipChange = (e: FederatedEvent) => {\n const tooltipShape = this._slider.tooltipShape;\n\n if (tooltipShape && e.detail && !isNil(e.detail.value)) {\n const color = this._colorScale.scale(e.detail.value);\n\n tooltipShape.setAttribute('fill', color);\n }\n\n this.dispatchEvent(e);\n };\n\n private _onSliderChange = (e: FederatedEvent) => {\n // 更新 handler 以及 track 的渐变色\n this._updateColor();\n this.dispatchEvent(e);\n };\n\n private _updateColor() {\n const { layout = 'horizontal', colors, railWidth, railHeight } = this.attribute as ColorLegendAttributes;\n const { startHandler, endHandler, track } = this._slider;\n const { startValue, endValue, startPos, endPos } = this._slider.currentValue;\n\n // 计算颜色\n const startHandlerColor = this._colorScale.scale(startValue);\n const endHandlerColor = this._colorScale.scale(endValue);\n startHandler?.setAttribute('fill', startHandlerColor);\n endHandler?.setAttribute('fill', endHandlerColor);\n\n const isHorizontal = layout === 'horizontal';\n const railLen = isHorizontal ? railWidth : railHeight;\n const trackLength = Math.abs((startPos as number) - (endPos as number));\n\n // 计算渐变色\n if (trackLength !== railLen && colors && colors.length > 1) {\n const stops = (this._color as ILinearGradient).stops;\n const start = Math.min(startPos as number, endPos as number);\n const end = Math.max(startPos as number, endPos as number);\n const startRatio = start / railLen;\n const endRatio = end / railLen;\n const range = endRatio - startRatio;\n const betweenStops = stops.filter(stop => stop.offset > startRatio && stop.offset < endRatio);\n\n const minValue = Math.min(startValue, endValue);\n const maxValue = Math.max(startValue, endValue);\n const startColor = this._colorScale.scale(minValue);\n const endColor = this._colorScale.scale(maxValue);\n const newStops = [{ offset: 0, color: startColor }];\n betweenStops.forEach(stop => {\n newStops.push({\n offset: (stop.offset - startRatio) / range,\n color: stop.color\n });\n });\n newStops.push({\n offset: 1,\n color: endColor\n });\n track.setAttribute('fill', {\n ...(this._color as ILinearGradient),\n stops: newStops\n });\n }\n }\n}\n"]}
|
package/es/legend/size/size.js
CHANGED
|
@@ -27,7 +27,7 @@ export class SizeContinuousLegend extends LegendBase {
|
|
|
27
27
|
this._slider && this._slider.setValue(value);
|
|
28
28
|
}
|
|
29
29
|
_renderContent() {
|
|
30
|
-
const {slidable: slidable, layout: layout, align: align, min: min, max: max, value: value, railWidth: railWidth, railHeight: railHeight, showHandler: showHandler = !0, handlerSize: handlerSize, handlerStyle: handlerStyle, railStyle: railStyle, trackStyle: trackStyle, startText: startText, endText: endText, handlerText: handlerText, showTooltip: showTooltip, tooltip: tooltip, sizeBackground: sizeBackground, disableTriggerEvent: disableTriggerEvent
|
|
30
|
+
const {slidable: slidable, layout: layout, align: align, min: min, max: max, value: value, railWidth: railWidth, railHeight: railHeight, showHandler: showHandler = !0, handlerSize: handlerSize, handlerStyle: handlerStyle, railStyle: railStyle, trackStyle: trackStyle, startText: startText, endText: endText, handlerText: handlerText, showTooltip: showTooltip, tooltip: tooltip, sizeBackground: sizeBackground, disableTriggerEvent: disableTriggerEvent} = this.attribute, mainContainer = graphicCreator.group({
|
|
31
31
|
x: 0,
|
|
32
32
|
y: 0
|
|
33
33
|
});
|
|
@@ -59,14 +59,12 @@ export class SizeContinuousLegend extends LegendBase {
|
|
|
59
59
|
handlerText: handlerText,
|
|
60
60
|
showTooltip: showTooltip,
|
|
61
61
|
tooltip: tooltip,
|
|
62
|
-
disableTriggerEvent: disableTriggerEvent
|
|
63
|
-
inverse: inverse
|
|
62
|
+
disableTriggerEvent: disableTriggerEvent
|
|
64
63
|
});
|
|
65
64
|
mainContainer.add(slider);
|
|
66
65
|
let path, start = 0;
|
|
67
|
-
"horizontal" === layout ? "top" === align ? (path = `M0,0L${railWidth},0L${
|
|
68
|
-
start = railHeight) : (path = `M0,12L${railWidth},12L${
|
|
69
|
-
slider.setAttribute("y", 12)) : "left" === align ? path = `M${railWidth},0L${railWidth + 12},${inverse ? 0 : railHeight}L${railWidth},${railHeight}Z` : (path = `M0,${inverse ? 0 : railHeight}L12,${railHeight}L12,0Z`,
|
|
66
|
+
"horizontal" === layout ? "top" === align ? (path = `M0,0L${railWidth},0L${railWidth},12Z`,
|
|
67
|
+
start = railHeight) : (path = `M0,12L${railWidth},12L${railWidth},0Z`, slider.setAttribute("y", 12)) : "left" === align ? path = `M${railWidth},0L${railWidth},0L${railWidth + 12},${railHeight}L${railWidth},${railHeight}Z` : (path = `M0,${railHeight}L12,${railHeight}L12,0Z`,
|
|
70
68
|
slider.setAttribute("x", 12));
|
|
71
69
|
const background = graphicCreator.path(Object.assign(Object.assign({
|
|
72
70
|
x: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/legend/size/size.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAEhE,iCAAiC,EAAE,CAAC;AACpC,MAAM,OAAO,oBAAqB,SAAQ,UAAgC;IA2BxE,YAAY,UAAgC,EAAE,OAA0B;QACtE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,oBAAoB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QA3B3G,SAAI,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/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C;YACpG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,qBAA2D,CAAC,CAAC;SAClH;IACH,CAAC;;AAnJM,sCAAiB,GAAG;IACzB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE;QACL,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,mBAAmB;QAC1B,SAAS,EAAE;YACT,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,qBAAqB;SAC5B;KACF;IACD,WAAW,EAAE,EAAE;IACf,YAAY,EAAE;QACZ,SAAS,EAAE,CAAC;QACZ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,MAAM;KACb;IACD,cAAc,EAAE;QACd,IAAI,EAAE,oBAAoB;KAC3B;CACF,CAAC","file":"size.js","sourcesContent":["/**\n * @description 连续尺寸图例\n */\nimport type { FederatedEvent, INode } from '@visactor/vrender-core';\nimport { graphicCreator } from '@visactor/vrender-core';\nimport { merge, get } from '@visactor/vutils';\nimport { LegendBase } from '../base';\nimport { Slider } from '../../slider';\nimport { DEFAULT_TITLE_SPACE } from '../constant';\nimport type { ComponentOptions } from '../../interface';\nimport type { SizeLegendAttributes } from './type';\nimport { getSizeHandlerPath } from '../util';\nimport { loadSizeContinuousLegendComponent } from '../register';\n\nloadSizeContinuousLegendComponent();\nexport class SizeContinuousLegend extends LegendBase<SizeLegendAttributes> {\n name = 'sizeLegend';\n\n static defaultAttributes = {\n layout: 'horizontal',\n title: {\n align: 'start',\n space: DEFAULT_TITLE_SPACE,\n textStyle: {\n fontSize: 12,\n fontWeight: 'bold',\n fill: 'rgba(46, 47, 50, 1)'\n }\n },\n handlerSize: 10,\n handlerStyle: {\n lineWidth: 1,\n stroke: '#ccc',\n fill: '#fff'\n },\n sizeBackground: {\n fill: 'rgba(20,20,20,0.1)'\n }\n };\n\n private _slider!: Slider;\n\n constructor(attributes: SizeLegendAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, SizeContinuousLegend.defaultAttributes, attributes));\n }\n\n setSelected(value: number[]) {\n if (!this._slider) {\n return;\n }\n this._slider.setValue(value);\n }\n\n protected _renderContent(): void {\n const {\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler = true,\n handlerSize,\n handlerStyle,\n railStyle,\n trackStyle,\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n sizeBackground,\n disableTriggerEvent\n } = this.attribute as SizeLegendAttributes;\n const isHorizontal = layout === 'horizontal';\n\n const mainContainer = graphicCreator.group({\n x: 0,\n y: 0\n });\n this._innerView.add(mainContainer);\n\n const slider = new Slider({\n x: 0,\n y: 0,\n zIndex: 1,\n range: {\n draggableTrack: true\n },\n slidable,\n layout,\n align,\n min,\n max,\n value,\n railWidth,\n railHeight,\n showHandler,\n handlerSize,\n handlerStyle: {\n symbolType: getSizeHandlerPath(align),\n ...handlerStyle\n },\n railStyle,\n trackStyle,\n startText,\n endText,\n handlerText,\n showTooltip,\n tooltip,\n disableTriggerEvent\n });\n mainContainer.add(slider as unknown as INode);\n\n // 绘制 size 背景\n let start = 0;\n let path;\n const backgroundHeight = 12; // 目前暂不开放配置\n if (layout === 'horizontal') {\n if (align === 'top') {\n path = `M0,0L${railWidth},0L${railWidth},${backgroundHeight}Z`;\n start = railHeight;\n } else {\n path = `M0,${backgroundHeight}L${railWidth},${backgroundHeight}L${railWidth},0Z`;\n slider.setAttribute('y', backgroundHeight);\n }\n } else {\n if (align === 'left') {\n path = `M${railWidth},0L${railWidth},0L${\n railWidth + backgroundHeight\n },${railHeight}L${railWidth},${railHeight}Z`;\n } else {\n path = `M0,${railHeight}L${backgroundHeight},${railHeight}L${backgroundHeight},0Z`;\n slider.setAttribute('x', backgroundHeight);\n }\n }\n const background = graphicCreator.path({\n x: 0,\n y: start,\n path,\n ...sizeBackground,\n zIndex: 0\n });\n mainContainer.add(background);\n\n // 做下位置调整\n const titleSpace = this._title\n ? this._title.AABBBounds.height() + get(this.attribute, 'title.space', DEFAULT_TITLE_SPACE)\n : 0;\n\n mainContainer.translate(0 - mainContainer.AABBBounds.x1, titleSpace - mainContainer.AABBBounds.y1);\n\n this._slider = slider;\n }\n\n protected _bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n if (this._slider) {\n this._slider.addEventListener('change', this._onSliderChange as EventListenerOrEventListenerObject);\n this._slider.addEventListener('sliderTooltip', this._onSliderToolipChange as EventListenerOrEventListenerObject);\n }\n }\n\n private _onSliderChange = (e: FederatedEvent) => {\n this.dispatchEvent(e);\n };\n\n private _onSliderToolipChange = (e: FederatedEvent) => {\n this.dispatchEvent(e);\n };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IGroup } from '@visactor/vrender-core';
|
|
2
|
+
import type { ArcSegment, Segment } from '../segment';
|
|
3
|
+
import { Tag } from '../tag';
|
|
4
|
+
import type { CommonMarkLineAttrs } from './type';
|
|
5
|
+
import { Marker } from './base';
|
|
6
|
+
export declare abstract class BaseMarkLine extends Marker<CommonMarkLineAttrs> {
|
|
7
|
+
name: string;
|
|
8
|
+
static defaultAttributes: Partial<CommonMarkLineAttrs>;
|
|
9
|
+
protected _line: Segment | ArcSegment;
|
|
10
|
+
protected abstract createSegment(): any;
|
|
11
|
+
protected abstract setLineAttributes(): any;
|
|
12
|
+
getLine(): Segment | ArcSegment;
|
|
13
|
+
getLabel(): Tag;
|
|
14
|
+
protected setLabelPos(): void;
|
|
15
|
+
protected initMarker(container: IGroup): void;
|
|
16
|
+
protected updateMarker(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { merge } from "@visactor/vutils";
|
|
2
|
+
|
|
3
|
+
import { Tag } from "../tag";
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_COMMON_MARK_LINE_THEME, DEFAULT_COMMON_MARK_LINE_TEXT_STYLE_MAP } from "./config";
|
|
6
|
+
|
|
7
|
+
import { limitShapeInBounds } from "../util/limit-shape";
|
|
8
|
+
|
|
9
|
+
import { DEFAULT_STATES } from "../constant";
|
|
10
|
+
|
|
11
|
+
import { Marker } from "./base";
|
|
12
|
+
|
|
13
|
+
export class BaseMarkLine extends Marker {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments), this.name = "baseMarkLine";
|
|
16
|
+
}
|
|
17
|
+
getLine() {
|
|
18
|
+
return this._line;
|
|
19
|
+
}
|
|
20
|
+
getLabel() {
|
|
21
|
+
return this._label;
|
|
22
|
+
}
|
|
23
|
+
setLabelPos() {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const {label: label = {}, limitRect: limitRect} = this.attribute, {position: position = "end", refX: refX = 0, refY: refY = 0, confine: confine} = label, points = this._line.getMainSegmentPoints(), labelAngle = null !== (_a = this._line.getEndAngle()) && void 0 !== _a ? _a : 0, labelOffsetX = refX * Math.cos(labelAngle) + refY * Math.cos(labelAngle - Math.PI / 2), labelOffsetY = refX * Math.sin(labelAngle) + refY * Math.sin(labelAngle - Math.PI / 2);
|
|
26
|
+
let labelPoint;
|
|
27
|
+
if (labelPoint = position.includes("start") || position.includes("Start") ? {
|
|
28
|
+
x: points[0].x + labelOffsetX,
|
|
29
|
+
y: points[0].y + labelOffsetY
|
|
30
|
+
} : position.includes("middle") || position.includes("Middle") ? {
|
|
31
|
+
x: (points[0].x + points[points.length - 1].x) / 2 + labelOffsetX,
|
|
32
|
+
y: (points[0].y + points[points.length - 1].y) / 2 + labelOffsetY
|
|
33
|
+
} : {
|
|
34
|
+
x: points[points.length - 1].x + labelOffsetX,
|
|
35
|
+
y: points[points.length - 1].y + labelOffsetY
|
|
36
|
+
}, this._label.setAttributes(Object.assign(Object.assign({}, labelPoint), {
|
|
37
|
+
angle: label.autoRotate ? labelAngle + (null !== (_b = label.refAngle) && void 0 !== _b ? _b : 0) : 0,
|
|
38
|
+
textStyle: Object.assign(Object.assign({}, DEFAULT_COMMON_MARK_LINE_TEXT_STYLE_MAP[position]), label.textStyle)
|
|
39
|
+
})), limitRect && confine) {
|
|
40
|
+
const {x: x, y: y, width: width, height: height} = limitRect;
|
|
41
|
+
limitShapeInBounds(this._label, {
|
|
42
|
+
x1: x,
|
|
43
|
+
y1: y,
|
|
44
|
+
x2: x + width,
|
|
45
|
+
y2: y + height
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
initMarker(container) {
|
|
50
|
+
const {label: label, state: state} = this.attribute, line = this.createSegment();
|
|
51
|
+
line.name = "cartesian-mark-line-line", this._line = line, container.add(line);
|
|
52
|
+
const markLabel = new Tag(Object.assign(Object.assign({}, label), {
|
|
53
|
+
state: {
|
|
54
|
+
panel: merge({}, DEFAULT_STATES, null == state ? void 0 : state.labelBackground),
|
|
55
|
+
text: merge({}, DEFAULT_STATES, null == state ? void 0 : state.label)
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
markLabel.name = "cartesian-mark-line-label", this._label = markLabel, container.add(markLabel),
|
|
59
|
+
this.setLabelPos();
|
|
60
|
+
}
|
|
61
|
+
updateMarker() {
|
|
62
|
+
const {label: label} = this.attribute;
|
|
63
|
+
this.setLineAttributes(), this._label && this._label.setAttributes(Object.assign({
|
|
64
|
+
dx: 0,
|
|
65
|
+
dy: 0
|
|
66
|
+
}, label)), this.setLabelPos();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
BaseMarkLine.defaultAttributes = DEFAULT_COMMON_MARK_LINE_THEME;
|
|
71
|
+
//# sourceMappingURL=base-line.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/marker/base-line.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIzC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,8BAA8B,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAC;AAEnG,OAAO,EAAE,kBAAkB,EAAE,MAAM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,GAAiC,8BAA8B,CAAC","file":"base-line.js","sourcesContent":["import type { IGroup, INode } from '@visactor/vrender-core';\nimport { merge } from '@visactor/vutils';\nimport type { ArcSegment, Segment } from '../segment';\nimport type { TagAttributes } from '../tag';\n// eslint-disable-next-line no-duplicate-imports\nimport { Tag } from '../tag';\nimport { DEFAULT_COMMON_MARK_LINE_THEME, DEFAULT_COMMON_MARK_LINE_TEXT_STYLE_MAP } from './config';\nimport type { CommonMarkLineAttrs } from './type';\nimport { limitShapeInBounds } from '../util/limit-shape';\nimport { DEFAULT_STATES } from '../constant';\nimport { Marker } from './base';\n\nexport abstract class BaseMarkLine extends Marker<CommonMarkLineAttrs> {\n name = 'baseMarkLine';\n static defaultAttributes: Partial<CommonMarkLineAttrs> = DEFAULT_COMMON_MARK_LINE_THEME;\n\n protected _line!: Segment | ArcSegment;\n\n protected abstract createSegment(): any;\n protected abstract setLineAttributes(): any;\n\n getLine() {\n return this._line;\n }\n getLabel() {\n return this._label;\n }\n\n protected setLabelPos() {\n const { label = {}, limitRect } = this.attribute;\n const { position = 'end', refX = 0, refY = 0, confine } = label;\n const points = this._line.getMainSegmentPoints();\n const labelAngle = this._line.getEndAngle() ?? 0;\n const labelOffsetX = refX * Math.cos(labelAngle) + refY * Math.cos(labelAngle - Math.PI / 2);\n const labelOffsetY = refX * Math.sin(labelAngle) + refY * Math.sin(labelAngle - Math.PI / 2);\n let labelPoint;\n if (position.includes('start') || position.includes('Start')) {\n labelPoint = {\n x: points[0].x + labelOffsetX,\n y: points[0].y + labelOffsetY\n };\n } else if (position.includes('middle') || position.includes('Middle')) {\n labelPoint = {\n x: (points[0].x + points[points.length - 1].x) / 2 + labelOffsetX,\n y: (points[0].y + points[points.length - 1].y) / 2 + labelOffsetY\n };\n } else {\n labelPoint = {\n x: points[points.length - 1].x + labelOffsetX,\n y: points[points.length - 1].y + labelOffsetY\n };\n }\n this._label.setAttributes({\n ...labelPoint,\n angle: label.autoRotate ? labelAngle + (label.refAngle ?? 0) : 0,\n textStyle: {\n ...DEFAULT_COMMON_MARK_LINE_TEXT_STYLE_MAP[position],\n ...label.textStyle\n }\n });\n if (limitRect && confine) {\n const { x, y, width, height } = limitRect;\n limitShapeInBounds(this._label, {\n x1: x,\n y1: y,\n x2: x + width,\n y2: y + height\n });\n }\n }\n\n protected initMarker(container: IGroup) {\n const { label, state } = this.attribute as CommonMarkLineAttrs;\n const line = this.createSegment();\n line.name = 'cartesian-mark-line-line';\n this._line = line;\n container.add(line as unknown as INode);\n\n const markLabel = new Tag({\n ...(label as TagAttributes),\n state: {\n panel: merge({}, DEFAULT_STATES, state?.labelBackground),\n text: merge({}, DEFAULT_STATES, state?.label)\n }\n });\n markLabel.name = 'cartesian-mark-line-label';\n this._label = markLabel;\n container.add(markLabel as unknown as INode);\n this.setLabelPos();\n }\n\n protected updateMarker() {\n const { label } = this.attribute as CommonMarkLineAttrs;\n\n this.setLineAttributes();\n\n if (this._label) {\n this._label.setAttributes({\n dx: 0,\n dy: 0, // 需要进行复位\n ...(label as TagAttributes)\n });\n }\n\n this.setLabelPos();\n }\n}\n"]}
|
package/es/marker/base.d.ts
CHANGED
|
@@ -7,12 +7,19 @@ export declare abstract class Marker<T extends MarkerAttrs> extends AbstractComp
|
|
|
7
7
|
private _containerClip;
|
|
8
8
|
private _container;
|
|
9
9
|
protected _label: Tag;
|
|
10
|
+
private _lastHover;
|
|
11
|
+
private _lastSelect;
|
|
10
12
|
protected abstract setLabelPos(): any;
|
|
11
13
|
protected abstract initMarker(container: IGroup): any;
|
|
12
14
|
protected abstract updateMarker(): any;
|
|
13
15
|
protected abstract isValidPoints(): any;
|
|
14
16
|
setAttribute(key: string, value: any, forceUpdateTag?: boolean | undefined): void;
|
|
17
|
+
private _bindEvent;
|
|
18
|
+
private _onHover;
|
|
19
|
+
private _onUnHover;
|
|
20
|
+
private _onClick;
|
|
15
21
|
private _initContainer;
|
|
16
22
|
private _updateContainer;
|
|
17
23
|
protected render(): void;
|
|
24
|
+
release(): void;
|
|
18
25
|
}
|
package/es/marker/base.js
CHANGED
|
@@ -2,13 +2,49 @@ import { graphicCreator } from "@visactor/vrender-core";
|
|
|
2
2
|
|
|
3
3
|
import { AbstractComponent } from "../core/base";
|
|
4
4
|
|
|
5
|
+
import { StateValue } from "../constant";
|
|
6
|
+
|
|
7
|
+
import { traverseGroup } from "../util";
|
|
8
|
+
|
|
9
|
+
import { isEmpty } from "@visactor/vutils";
|
|
10
|
+
|
|
5
11
|
export class Marker extends AbstractComponent {
|
|
6
12
|
constructor() {
|
|
7
|
-
super(...arguments), this.name = "marker"
|
|
13
|
+
super(...arguments), this.name = "marker", this._onHover = e => {
|
|
14
|
+
const target = e.target;
|
|
15
|
+
target !== this._lastHover && target.name && !isEmpty(target.states) && (target.addState(StateValue.hover, !0),
|
|
16
|
+
traverseGroup(this._container, (node => {
|
|
17
|
+
node !== target && node.name && !isEmpty(node.states) && node.addState(StateValue.hoverReverse, !0);
|
|
18
|
+
})), this._lastHover = target);
|
|
19
|
+
}, this._onUnHover = e => {
|
|
20
|
+
this._lastHover && (traverseGroup(this._container, (node => {
|
|
21
|
+
node.name && !isEmpty(node.states) && (node.removeState(StateValue.hoverReverse),
|
|
22
|
+
node.removeState(StateValue.hover));
|
|
23
|
+
})), this._lastHover = null);
|
|
24
|
+
}, this._onClick = e => {
|
|
25
|
+
const target = e.target;
|
|
26
|
+
if (this._lastSelect === target && target.hasState(StateValue.selected)) return this._lastSelect = null,
|
|
27
|
+
void traverseGroup(this._container, (node => {
|
|
28
|
+
node.name && !isEmpty(node.states) && (node.removeState(StateValue.selectedReverse),
|
|
29
|
+
node.removeState(StateValue.selected));
|
|
30
|
+
}));
|
|
31
|
+
target.name && !isEmpty(target.states) && (target.addState(StateValue.selected, !0),
|
|
32
|
+
traverseGroup(this._container, (node => {
|
|
33
|
+
node !== target && node.name && !isEmpty(node.states) && node.addState(StateValue.selectedReverse, !0);
|
|
34
|
+
})), this._lastSelect = target);
|
|
35
|
+
};
|
|
8
36
|
}
|
|
9
37
|
setAttribute(key, value, forceUpdateTag) {
|
|
10
38
|
super.setAttribute(key, value, forceUpdateTag), "visible" === key && this.render();
|
|
11
39
|
}
|
|
40
|
+
_bindEvent() {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
if (!this.attribute.interactive) return;
|
|
43
|
+
const {hover: hover, select: select} = this.attribute;
|
|
44
|
+
hover && (null === (_a = this._container) || void 0 === _a || _a.addEventListener("pointermove", this._onHover),
|
|
45
|
+
null === (_b = this._container) || void 0 === _b || _b.addEventListener("pointerout", this._onUnHover)),
|
|
46
|
+
select && (null === (_c = this._container) || void 0 === _c || _c.addEventListener("pointerdown", this._onClick));
|
|
47
|
+
}
|
|
12
48
|
_initContainer() {
|
|
13
49
|
var _a, _b;
|
|
14
50
|
const {limitRect: limitRect = {}, clipInRange: clipInRange} = this.attribute;
|
|
@@ -46,7 +82,14 @@ export class Marker extends AbstractComponent {
|
|
|
46
82
|
!1 === this.attribute.interactive && this.setAttribute("childrenPickable", !1),
|
|
47
83
|
markerVisible && this.isValidPoints() ? this._container ? (this._updateContainer(),
|
|
48
84
|
this.updateMarker()) : (this._initContainer(), this.initMarker(this._container)) : (this._container = null,
|
|
49
|
-
this.removeAllChild(!0));
|
|
85
|
+
this.removeAllChild(!0)), this._bindEvent();
|
|
86
|
+
}
|
|
87
|
+
release() {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
super.release(), null === (_a = this._container) || void 0 === _a || _a.removeEventListener("pointermove", this._onHover),
|
|
90
|
+
null === (_b = this._container) || void 0 === _b || _b.removeEventListener("pointerout", this._onUnHover),
|
|
91
|
+
null === (_c = this._container) || void 0 === _c || _c.removeEventListener("pointerdown", this._onClick),
|
|
92
|
+
this._container = null;
|
|
50
93
|
}
|
|
51
94
|
}
|
|
52
95
|
//# sourceMappingURL=base.js.map
|
package/es/marker/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/marker/base.ts"],"names":[],"mappings":"AAC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AAG,IAAI,CAAC;YACvB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC3B;IACH,CAAC;CACF","file":"base.js","sourcesContent":["import type { IGroup } from '@visactor/vrender-core';\nimport { graphicCreator } from '@visactor/vrender-core';\nimport { AbstractComponent } from '../core/base';\nimport type { Tag } from '../tag';\nimport type { MarkerAttrs } from './type';\n\nexport abstract class Marker<T extends MarkerAttrs> extends AbstractComponent<Required<T>> {\n name = 'marker';\n private _containerClip!: IGroup;\n private _container!: IGroup;\n\n protected _label!: Tag;\n\n protected abstract setLabelPos(): any;\n protected abstract initMarker(container: IGroup): any;\n protected abstract updateMarker(): any;\n protected abstract isValidPoints(): any;\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean | undefined): void {\n super.setAttribute(key, value, forceUpdateTag);\n if (key === 'visible') {\n this.render();\n }\n }\n\n private _initContainer() {\n const { limitRect = {} as T['limitRect'], clipInRange } = this.attribute;\n let group;\n if (clipInRange) {\n // 如果用户配置了剪切\n const groupClip = graphicCreator.group({\n ...limitRect,\n clip: true,\n pickable: false\n });\n group = graphicCreator.group({\n x: -(limitRect.x ?? 0),\n y: -(limitRect.y ?? 0),\n pickable: false\n });\n groupClip.add(group);\n this._containerClip = groupClip;\n this.add(groupClip);\n } else {\n group = graphicCreator.group({\n x: 0,\n y: 0,\n pickable: false\n });\n this.add(group);\n }\n group.name = 'marker-container';\n this._container = group;\n }\n\n private _updateContainer() {\n const { limitRect = {} as T['limitRect'], clipInRange } = this.attribute;\n if (this._containerClip) {\n this._containerClip.setAttributes({\n ...limitRect\n });\n }\n\n this._container.setAttributes({\n x: clipInRange ? -(limitRect.x ?? 0) : 0,\n y: clipInRange ? -(limitRect.y ?? 0) : 0\n });\n }\n\n protected render() {\n // 因为标注本身不规则,所以默认将组件的 group 设置为不可拾取\n this.setAttribute('pickable', false);\n\n const markerVisible = this.attribute.visible ?? true;\n if (this.attribute.interactive === false) {\n this.setAttribute('childrenPickable', false);\n }\n\n if (markerVisible && this.isValidPoints()) {\n if (!this._container) {\n this._initContainer();\n this.initMarker(this._container);\n } else {\n this._updateContainer();\n this.updateMarker();\n }\n } else {\n this._container = null;\n this.removeAllChild(true);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/marker/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,OAAgB,MAA8B,SAAQ,iBAA8B;IAA1F;;QACE,SAAI,GAAG,QAAQ,CAAC;QAoCR,aAAQ,GAAG,CAAC,CAAwB,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,MAA6B,CAAC;YAC/C,IAAI,MAAM,KAAK,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBACxE,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBACxC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,IAAc,EAAE,EAAE;oBAChD,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;wBACzD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;qBAC9C;gBACH,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;aAC1B;QACH,CAAC,CAAC;QAEM,eAAU,GAAG,CAAC,CAAwB,EAAE,EAAE;YAChD,IAAI,IAAI,CAAC,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C,UAAU,EAAE,KAAK,CAAC,CAAC;QAErC,MAAM,aAAa,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,OAAO,mCAAI,IAAI,CAAC;QACrD,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,KAAK,KAAK,EAAE;YACxC,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;SAC9C;QAED,IAAI,aAAa,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACzC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;gBACpB,IAAI,CAAC,cAAc,EAAE,CAAC;gBACtB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAClC;iBAAM;gBACL,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACxB,IAAI,CAAC,YAAY,EAAE,CAAC;aACrB;SACF;aAAM;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC3B;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,OAAO;;QACL,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,MAAA,IAAI,CAAC,UAAU,0CAAE,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,QAA8C,CAAC,CAAC;QACzG,MAAA,IAAI,CAAC,UAAU,0CAAE,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,UAAgD,CAAC,CAAC;QAC1G,MAAA,IAAI,CAAC,UAAU,0CAAE,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,QAA8C,CAAC,CAAC;QACzG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;CACF","file":"base.js","sourcesContent":["import type { FederatedPointerEvent, IGraphic, IGroup } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { graphicCreator } from '@visactor/vrender-core';\nimport { AbstractComponent } from '../core/base';\nimport type { Tag } from '../tag';\nimport type { MarkerAttrs } from './type';\nimport { StateValue } from '../constant';\nimport { traverseGroup } from '../util';\nimport { isEmpty } from '@visactor/vutils';\n\nexport abstract class Marker<T extends MarkerAttrs> extends AbstractComponent<Required<T>> {\n name = 'marker';\n private _containerClip!: IGroup;\n private _container!: IGroup;\n\n protected _label!: Tag;\n private _lastHover: IGraphic;\n private _lastSelect: IGraphic;\n\n protected abstract setLabelPos(): any;\n protected abstract initMarker(container: IGroup): any;\n protected abstract updateMarker(): any;\n protected abstract isValidPoints(): any;\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean | undefined): void {\n super.setAttribute(key, value, forceUpdateTag);\n if (key === 'visible') {\n this.render();\n }\n }\n\n private _bindEvent() {\n if (!this.attribute.interactive) {\n return;\n }\n const { hover, select } = this.attribute;\n\n if (hover) {\n this._container?.addEventListener('pointermove', this._onHover as EventListenerOrEventListenerObject);\n this._container?.addEventListener('pointerout', this._onUnHover as EventListenerOrEventListenerObject);\n }\n\n if (select) {\n this._container?.addEventListener('pointerdown', this._onClick as EventListenerOrEventListenerObject);\n }\n }\n\n private _onHover = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (target !== this._lastHover && target.name && !isEmpty(target.states)) {\n target.addState(StateValue.hover, true);\n traverseGroup(this._container, (node: IGraphic) => {\n if (node !== target && node.name && !isEmpty(node.states)) {\n node.addState(StateValue.hoverReverse, true);\n }\n });\n this._lastHover = target;\n }\n };\n\n private _onUnHover = (e: FederatedPointerEvent) => {\n if (this._lastHover) {\n traverseGroup(this._container, (node: IGraphic) => {\n if (node.name && !isEmpty(node.states)) {\n node.removeState(StateValue.hoverReverse);\n node.removeState(StateValue.hover);\n }\n });\n this._lastHover = null;\n }\n };\n\n private _onClick = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (this._lastSelect === target && target.hasState(StateValue.selected)) {\n // 取消选中\n this._lastSelect = null;\n traverseGroup(this._container, (node: IGraphic) => {\n if (node.name && !isEmpty(node.states)) {\n node.removeState(StateValue.selectedReverse);\n node.removeState(StateValue.selected);\n }\n });\n return;\n }\n\n if (target.name && !isEmpty(target.states)) {\n target.addState(StateValue.selected, true);\n traverseGroup(this._container, (node: IGraphic) => {\n if (node !== target && node.name && !isEmpty(node.states)) {\n node.addState(StateValue.selectedReverse, true);\n }\n });\n this._lastSelect = target;\n }\n };\n\n private _initContainer() {\n const { limitRect = {} as T['limitRect'], clipInRange } = this.attribute;\n let group;\n if (clipInRange) {\n // 如果用户配置了剪切\n const groupClip = graphicCreator.group({\n ...limitRect,\n clip: true,\n pickable: false\n });\n group = graphicCreator.group({\n x: -(limitRect.x ?? 0),\n y: -(limitRect.y ?? 0),\n pickable: false\n });\n groupClip.add(group);\n this._containerClip = groupClip;\n this.add(groupClip);\n } else {\n group = graphicCreator.group({\n x: 0,\n y: 0,\n pickable: false\n });\n this.add(group);\n }\n group.name = 'marker-container';\n this._container = group;\n }\n\n private _updateContainer() {\n const { limitRect = {} as T['limitRect'], clipInRange } = this.attribute;\n if (this._containerClip) {\n this._containerClip.setAttributes({\n ...limitRect\n });\n }\n\n this._container.setAttributes({\n x: clipInRange ? -(limitRect.x ?? 0) : 0,\n y: clipInRange ? -(limitRect.y ?? 0) : 0\n });\n }\n\n protected render() {\n // 因为标注本身不规则,所以默认将组件的 group 设置为不可拾取\n this.setAttribute('pickable', false);\n\n const markerVisible = this.attribute.visible ?? true;\n if (this.attribute.interactive === false) {\n this.setAttribute('childrenPickable', false);\n }\n\n if (markerVisible && this.isValidPoints()) {\n if (!this._container) {\n this._initContainer();\n this.initMarker(this._container);\n } else {\n this._updateContainer();\n this.updateMarker();\n }\n } else {\n this._container = null;\n this.removeAllChild(true);\n }\n\n this._bindEvent();\n }\n\n release(): void {\n super.release();\n this._container?.removeEventListener('pointermove', this._onHover as EventListenerOrEventListenerObject);\n this._container?.removeEventListener('pointerout', this._onUnHover as EventListenerOrEventListenerObject);\n this._container?.removeEventListener('pointerdown', this._onClick as EventListenerOrEventListenerObject);\n this._container = null;\n }\n}\n"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { IGroup, IPolygon } from '@visactor/vrender-core';
|
|
2
|
-
import { Tag } from '
|
|
3
|
-
import { Marker } from '
|
|
4
|
-
import type {
|
|
5
|
-
import type { ComponentOptions } from '
|
|
6
|
-
export declare class
|
|
2
|
+
import { Tag } from '../../tag';
|
|
3
|
+
import { Marker } from '../base';
|
|
4
|
+
import type { CartesianMarkAreaAttrs } from '../type';
|
|
5
|
+
import type { ComponentOptions } from '../../interface';
|
|
6
|
+
export declare class CartesianMarkArea extends Marker<CartesianMarkAreaAttrs> {
|
|
7
7
|
name: string;
|
|
8
8
|
static defaultAttributes: {
|
|
9
|
+
interactive: boolean;
|
|
9
10
|
label: {
|
|
10
|
-
position: import("
|
|
11
|
+
position: import("../type").ICartesianMarkAreaLabelPosition;
|
|
11
12
|
textStyle: {
|
|
12
13
|
fill: string;
|
|
13
14
|
stroke: string;
|
|
@@ -32,7 +33,7 @@ export declare class MarkArea extends Marker<MarkAreaAttrs> {
|
|
|
32
33
|
private _area;
|
|
33
34
|
getArea(): IPolygon;
|
|
34
35
|
getLabel(): Tag;
|
|
35
|
-
constructor(attributes:
|
|
36
|
+
constructor(attributes: CartesianMarkAreaAttrs, options?: ComponentOptions);
|
|
36
37
|
private _getPositionByDirection;
|
|
37
38
|
protected setLabelPos(): void;
|
|
38
39
|
protected initMarker(container: IGroup): void;
|
|
@@ -2,19 +2,21 @@ import { graphicCreator } from "@visactor/vrender-core";
|
|
|
2
2
|
|
|
3
3
|
import { isValidNumber, merge } from "@visactor/vutils";
|
|
4
4
|
|
|
5
|
-
import { Tag } from "
|
|
5
|
+
import { Tag } from "../../tag";
|
|
6
6
|
|
|
7
|
-
import { Marker } from "
|
|
7
|
+
import { Marker } from "../base";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { DEFAULT_CARTESIAN_MARK_AREA_TEXT_STYLE_MAP, DEFAULT_CARTESIAN_MARK_AREA_THEME } from "../config";
|
|
10
10
|
|
|
11
|
-
import { limitShapeInBounds } from "
|
|
11
|
+
import { limitShapeInBounds } from "../../util/limit-shape";
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { loadCartesianMarkAreaComponent } from "../register";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import { DEFAULT_STATES } from "../../constant";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
loadCartesianMarkAreaComponent();
|
|
18
|
+
|
|
19
|
+
export class CartesianMarkArea extends Marker {
|
|
18
20
|
getArea() {
|
|
19
21
|
return this._area;
|
|
20
22
|
}
|
|
@@ -22,8 +24,8 @@ export class MarkArea extends Marker {
|
|
|
22
24
|
return this._label;
|
|
23
25
|
}
|
|
24
26
|
constructor(attributes, options) {
|
|
25
|
-
super((null == options ? void 0 : options.skipDefault) ? attributes : merge({},
|
|
26
|
-
this.name = "
|
|
27
|
+
super((null == options ? void 0 : options.skipDefault) ? attributes : merge({}, CartesianMarkArea.defaultAttributes, attributes)),
|
|
28
|
+
this.name = "cartesianMarkArea";
|
|
27
29
|
}
|
|
28
30
|
_getPositionByDirection(area, direction) {
|
|
29
31
|
const {x1: x1, x2: x2, y1: y1, y2: y2} = this._area.AABBBounds;
|
|
@@ -49,7 +51,7 @@ export class MarkArea extends Marker {
|
|
|
49
51
|
if (this._label && this._area) {
|
|
50
52
|
const {label: label = {}} = this.attribute, labelPosition = null !== (_a = label.position) && void 0 !== _a ? _a : "middle", labelPoint = this._getPositionByDirection(this._area, labelPosition);
|
|
51
53
|
if (this._label.setAttributes(Object.assign(Object.assign({}, labelPoint), {
|
|
52
|
-
textStyle: Object.assign(Object.assign({},
|
|
54
|
+
textStyle: Object.assign(Object.assign({}, DEFAULT_CARTESIAN_MARK_AREA_TEXT_STYLE_MAP[labelPosition]), label.textStyle)
|
|
53
55
|
})), this.attribute.limitRect && label.confine) {
|
|
54
56
|
const {x: x, y: y, width: width, height: height} = this.attribute.limitRect;
|
|
55
57
|
limitShapeInBounds(this._label, {
|
|
@@ -62,12 +64,18 @@ export class MarkArea extends Marker {
|
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
initMarker(container) {
|
|
65
|
-
const {points: points, label: label, areaStyle: areaStyle} = this.attribute, area = graphicCreator.polygon(Object.assign({
|
|
67
|
+
const {points: points, label: label, areaStyle: areaStyle, state: state} = this.attribute, area = graphicCreator.polygon(Object.assign({
|
|
66
68
|
points: points
|
|
67
69
|
}, areaStyle));
|
|
68
|
-
area.
|
|
69
|
-
|
|
70
|
-
markLabel
|
|
70
|
+
area.states = merge({}, DEFAULT_STATES, null == state ? void 0 : state.area), area.name = "mark-polygon-polygon",
|
|
71
|
+
this._area = area, container.add(area);
|
|
72
|
+
const markLabel = new Tag(Object.assign(Object.assign({}, label), {
|
|
73
|
+
state: {
|
|
74
|
+
panel: merge({}, DEFAULT_STATES, null == state ? void 0 : state.labelBackground),
|
|
75
|
+
text: merge({}, DEFAULT_STATES, null == state ? void 0 : state.label)
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
markLabel.name = "mark-polygon-label", this._label = markLabel, container.add(markLabel),
|
|
71
79
|
this.setLabelPos();
|
|
72
80
|
}
|
|
73
81
|
updateMarker() {
|
|
@@ -89,5 +97,5 @@ export class MarkArea extends Marker {
|
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
CartesianMarkArea.defaultAttributes = DEFAULT_CARTESIAN_MARK_AREA_THEME;
|
|
93
101
|
//# sourceMappingURL=area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/marker/cartesian/area.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO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E,SAAS,EAAE,GAAG,IAAI,CAAC,SAAmC,CAAC;QAC9E,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,aAAa,iBACtB,MAAM,EAAE,MAAM,IACX,SAAS,EACZ,CAAC;SACJ;QACD,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,aAAa,iBACvB,EAAE,EAAE,CAAC,EACL,EAAE,EAAE,CAAC,IACD,KAAuB,EAC3B,CAAC;SACJ;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAES,aAAa;QACrB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,SAAmC,CAAC;QAC5D,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,OAAO,KAAK,CAAC;SACd;QACD,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAY,EAAE,EAAE;YAC9B,IAAI,CAAC,aAAa,CAAE,KAAe,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAE,KAAe,CAAC,CAAC,CAAC,EAAE;gBAC5E,SAAS,GAAG,KAAK,CAAC;gBAClB,OAAO;aACR;QACH,CAAC,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;;AAhIM,mCAAiB,GAAG,iCAAiC,CAAC","file":"area.js","sourcesContent":["import type { IGroup, INode, IPolygon } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { graphicCreator } from '@visactor/vrender-core';\nimport { isValidNumber, merge } from '@visactor/vutils';\nimport type { TagAttributes } from '../../tag';\n// eslint-disable-next-line no-duplicate-imports\nimport { Tag } from '../../tag';\nimport { Marker } from '../base';\nimport { DEFAULT_CARTESIAN_MARK_AREA_TEXT_STYLE_MAP, DEFAULT_CARTESIAN_MARK_AREA_THEME } from '../config';\nimport type { CartesianMarkAreaAttrs } from '../type';\nimport { limitShapeInBounds } from '../../util/limit-shape';\nimport type { ComponentOptions } from '../../interface';\nimport { loadCartesianMarkAreaComponent } from '../register';\nimport type { Point } from '../../core/type';\nimport { DEFAULT_STATES } from '../../constant';\n\nloadCartesianMarkAreaComponent();\nexport class CartesianMarkArea extends Marker<CartesianMarkAreaAttrs> {\n name = 'cartesianMarkArea';\n static defaultAttributes = DEFAULT_CARTESIAN_MARK_AREA_THEME;\n private _area!: IPolygon;\n getArea() {\n return this._area;\n }\n\n getLabel() {\n return this._label;\n }\n\n constructor(attributes: CartesianMarkAreaAttrs, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, CartesianMarkArea.defaultAttributes, attributes));\n }\n\n private _getPositionByDirection(area: IPolygon, direction: string) {\n const { x1, x2, y1, y2 } = this._area.AABBBounds;\n\n if (direction.includes('left') || direction.includes('Left')) {\n return {\n x: x1,\n y: (y1 + y2) / 2\n };\n }\n if (direction.includes('right') || direction.includes('Right')) {\n return {\n x: x2,\n y: (y1 + y2) / 2\n };\n }\n if (direction.includes('top') || direction.includes('Top')) {\n return {\n x: (x1 + x2) / 2,\n y: y1\n };\n }\n if (direction.includes('bottom') || direction.includes('Bottom')) {\n return {\n x: (x1 + x2) / 2,\n y: y2\n };\n }\n\n return {\n x: (x1 + x2) / 2,\n y: (y1 + y2) / 2\n };\n }\n\n protected setLabelPos() {\n if (this._label && this._area) {\n const { label = {} } = this.attribute as CartesianMarkAreaAttrs;\n const labelPosition = label.position ?? 'middle';\n const labelPoint = this._getPositionByDirection(this._area, labelPosition);\n this._label.setAttributes({\n ...labelPoint,\n textStyle: {\n ...DEFAULT_CARTESIAN_MARK_AREA_TEXT_STYLE_MAP[labelPosition],\n ...label.textStyle\n }\n });\n\n if (this.attribute.limitRect && label.confine) {\n const { x, y, width, height } = this.attribute.limitRect;\n limitShapeInBounds(this._label, {\n x1: x,\n y1: y,\n x2: x + width,\n y2: y + height\n });\n }\n }\n }\n\n protected initMarker(container: IGroup) {\n const { points, label, areaStyle, state } = this.attribute as CartesianMarkAreaAttrs;\n const area = graphicCreator.polygon({\n points: points,\n ...areaStyle\n });\n area.states = merge({}, DEFAULT_STATES, state?.area);\n area.name = 'mark-polygon-polygon';\n this._area = area;\n container.add(area);\n\n const markLabel = new Tag({\n ...(label as TagAttributes),\n state: {\n panel: merge({}, DEFAULT_STATES, state?.labelBackground),\n text: merge({}, DEFAULT_STATES, state?.label)\n }\n });\n markLabel.name = 'mark-polygon-label';\n this._label = markLabel;\n container.add(markLabel as unknown as INode);\n this.setLabelPos();\n }\n\n protected updateMarker() {\n const { points, label, areaStyle } = this.attribute as CartesianMarkAreaAttrs;\n if (this._area) {\n this._area.setAttributes({\n points: points,\n ...areaStyle\n });\n }\n if (this._area) {\n this._label.setAttributes({\n dx: 0,\n dy: 0, // 需要进行复位\n ...(label as TagAttributes)\n });\n }\n this.setLabelPos();\n }\n\n protected isValidPoints() {\n const { points } = this.attribute as CartesianMarkAreaAttrs;\n if (!points || points.length < 3) {\n return false;\n }\n let validFlag = true;\n points.forEach((point: Point) => {\n if (!isValidNumber((point as Point).x) || !isValidNumber((point as Point).y)) {\n validFlag = false;\n return;\n }\n });\n return validFlag;\n }\n}\n"]}
|