@antv/g2 5.0.10 → 5.0.12
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/CHANGELOG.md +178 -0
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +1 -0
- package/esm/api/chart.js +5 -1
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/geoPath.d.ts +1 -0
- package/esm/api/composition/geoPath.js +1 -0
- package/esm/api/composition/geoPath.js.map +1 -1
- package/esm/api/mark/index.d.ts +5 -1
- package/esm/api/mark/index.js +3 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +13 -1
- package/esm/api/mark/mark.js +18 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/node.d.ts +1 -0
- package/esm/api/node.js +5 -1
- package/esm/api/node.js.map +1 -1
- package/esm/api/utils.d.ts +1 -1
- package/esm/api/utils.js +11 -6
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +2 -1
- package/esm/component/axis.js.map +1 -1
- package/esm/component/scrollbar.js +8 -5
- package/esm/component/scrollbar.js.map +1 -1
- package/esm/composition/facetRect.js +13 -17
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/utils/venn/circleintersection.d.ts +33 -0
- package/esm/data/utils/venn/circleintersection.js +192 -0
- package/esm/data/utils/venn/circleintersection.js.map +1 -0
- package/esm/data/utils/venn/diagram.d.ts +2 -0
- package/esm/data/utils/venn/diagram.js +44 -0
- package/esm/data/utils/venn/diagram.js.map +1 -0
- package/esm/data/utils/venn/index.d.ts +5 -0
- package/esm/data/utils/venn/index.js +6 -0
- package/esm/data/utils/venn/index.js.map +1 -0
- package/esm/data/utils/venn/layout.d.ts +27 -0
- package/esm/data/utils/venn/layout.js +607 -0
- package/esm/data/utils/venn/layout.js.map +1 -0
- package/esm/data/venn.d.ts +7 -0
- package/esm/data/venn.js +34 -0
- package/esm/data/venn.js.map +1 -0
- package/esm/geo/geoPath.js +2 -1
- package/esm/geo/geoPath.js.map +1 -1
- package/esm/interaction/brushAxisHighlight.d.ts +5 -3
- package/esm/interaction/brushAxisHighlight.js +126 -12
- package/esm/interaction/brushAxisHighlight.js.map +1 -1
- package/esm/interaction/brushHighlight.js +6 -5
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/elementHighlight.d.ts +2 -2
- package/esm/interaction/elementHighlight.js +40 -6
- package/esm/interaction/elementHighlight.js.map +1 -1
- package/esm/interaction/elementHighlightByColor.d.ts +1 -1
- package/esm/interaction/elementHighlightByX.d.ts +1 -1
- package/esm/interaction/elementSelect.d.ts +2 -2
- package/esm/interaction/elementSelect.js +42 -13
- package/esm/interaction/elementSelect.js.map +1 -1
- package/esm/interaction/elementSelectByColor.d.ts +1 -1
- package/esm/interaction/elementSelectByX.d.ts +1 -1
- package/esm/interaction/event.js +5 -2
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/legendFilter.js +42 -13
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/legendHighlight.d.ts +1 -1
- package/esm/interaction/legendHighlight.js +53 -15
- package/esm/interaction/legendHighlight.js.map +1 -1
- package/esm/interaction/scrollbarFilter.d.ts +2 -0
- package/esm/interaction/scrollbarFilter.js +25 -0
- package/esm/interaction/scrollbarFilter.js.map +1 -0
- package/esm/interaction/sliderFilter.d.ts +1 -1
- package/esm/interaction/sliderFilter.js +75 -19
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +2 -2
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/utils.d.ts +1 -0
- package/esm/interaction/utils.js +3 -0
- package/esm/interaction/utils.js.map +1 -1
- package/esm/mark/area.js +7 -3
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/heatmap.d.ts +7 -0
- package/esm/mark/heatmap.js +36 -0
- package/esm/mark/heatmap.js.map +1 -0
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/text.js +0 -2
- package/esm/mark/text.js.map +1 -1
- package/esm/mark/utils.d.ts +1 -0
- package/esm/mark/utils.js +1 -1
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/plot.js +13 -10
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.d.ts +2 -2
- package/esm/runtime/render.js +7 -3
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/scale.js +41 -12
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +12 -9
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +2 -2
- package/esm/runtime/types/options.d.ts +6 -0
- package/esm/shape/heatmap/heatmap.d.ts +4 -0
- package/esm/shape/heatmap/heatmap.js +70 -0
- package/esm/shape/heatmap/heatmap.js.map +1 -0
- package/esm/shape/heatmap/renderer/gradient.d.ts +5 -0
- package/esm/shape/heatmap/renderer/gradient.js +13 -0
- package/esm/shape/heatmap/renderer/gradient.js.map +1 -0
- package/esm/shape/heatmap/renderer/index.d.ts +6 -0
- package/esm/shape/heatmap/renderer/index.js +122 -0
- package/esm/shape/heatmap/renderer/index.js.map +1 -0
- package/esm/shape/heatmap/renderer/types.d.ts +36 -0
- package/esm/shape/heatmap/renderer/types.js +2 -0
- package/esm/shape/heatmap/renderer/types.js.map +1 -0
- package/esm/shape/image/image.js +8 -3
- package/esm/shape/image/image.js.map +1 -1
- package/esm/shape/index.d.ts +4 -0
- package/esm/shape/index.js +2 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.d.ts +8 -0
- package/esm/shape/interval/color.js +19 -8
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/interval/rect.d.ts +10 -1
- package/esm/shape/interval/rect.js.map +1 -1
- package/esm/shape/line/trail.d.ts +3 -0
- package/esm/shape/line/trail.js +74 -0
- package/esm/shape/line/trail.js.map +1 -0
- package/esm/shape/path/color.js +5 -3
- package/esm/shape/path/color.js.map +1 -1
- package/esm/spec/component.d.ts +1 -1
- package/esm/spec/composition.d.ts +9 -6
- package/esm/spec/dataTransform.d.ts +24 -2
- package/esm/spec/mark.d.ts +2 -1
- package/esm/stdlib/index.js +6 -6
- package/esm/stdlib/index.js.map +1 -1
- package/esm/utils/lru.d.ts +4 -0
- package/esm/utils/lru.js +18 -0
- package/esm/utils/lru.js.map +1 -0
- package/esm/utils/number.d.ts +4 -0
- package/esm/utils/number.js +7 -0
- package/esm/utils/number.js.map +1 -0
- package/esm/utils/scale.d.ts +2 -1
- package/esm/utils/scale.js +30 -11
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/vector.d.ts +1 -0
- package/esm/utils/vector.js +3 -0
- package/esm/utils/vector.js.map +1 -1
- package/lib/api/chart.d.ts +1 -0
- package/lib/api/chart.js +5 -1
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +1 -0
- package/lib/api/composition/geoPath.js +1 -0
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/mark/index.d.ts +5 -1
- package/lib/api/mark/index.js +2 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +13 -1
- package/lib/api/mark/mark.js +19 -1
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/node.d.ts +1 -0
- package/lib/api/node.js +5 -1
- package/lib/api/node.js.map +1 -1
- package/lib/api/utils.d.ts +1 -1
- package/lib/api/utils.js +11 -6
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +2 -1
- package/lib/component/axis.js.map +1 -1
- package/lib/component/scrollbar.js +8 -5
- package/lib/component/scrollbar.js.map +1 -1
- package/lib/composition/facetRect.js +12 -16
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/utils/venn/circleintersection.d.ts +33 -0
- package/lib/data/utils/venn/circleintersection.js +202 -0
- package/lib/data/utils/venn/circleintersection.js.map +1 -0
- package/lib/data/utils/venn/diagram.d.ts +2 -0
- package/lib/data/utils/venn/diagram.js +48 -0
- package/lib/data/utils/venn/diagram.js.map +1 -0
- package/lib/data/utils/venn/index.d.ts +5 -0
- package/lib/data/utils/venn/index.js +12 -0
- package/lib/data/utils/venn/index.js.map +1 -0
- package/lib/data/utils/venn/layout.d.ts +27 -0
- package/lib/data/utils/venn/layout.js +620 -0
- package/lib/data/utils/venn/layout.js.map +1 -0
- package/lib/data/venn.d.ts +7 -0
- package/lib/data/venn.js +38 -0
- package/lib/data/venn.js.map +1 -0
- package/lib/geo/geoPath.js +2 -1
- package/lib/geo/geoPath.js.map +1 -1
- package/lib/interaction/brushAxisHighlight.d.ts +5 -3
- package/lib/interaction/brushAxisHighlight.js +126 -12
- package/lib/interaction/brushAxisHighlight.js.map +1 -1
- package/lib/interaction/brushHighlight.js +6 -5
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/elementHighlight.d.ts +2 -2
- package/lib/interaction/elementHighlight.js +39 -5
- package/lib/interaction/elementHighlight.js.map +1 -1
- package/lib/interaction/elementHighlightByColor.d.ts +1 -1
- package/lib/interaction/elementHighlightByX.d.ts +1 -1
- package/lib/interaction/elementSelect.d.ts +2 -2
- package/lib/interaction/elementSelect.js +41 -12
- package/lib/interaction/elementSelect.js.map +1 -1
- package/lib/interaction/elementSelectByColor.d.ts +1 -1
- package/lib/interaction/elementSelectByX.d.ts +1 -1
- package/lib/interaction/event.js +5 -2
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/legendFilter.js +42 -13
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/legendHighlight.d.ts +1 -1
- package/lib/interaction/legendHighlight.js +53 -15
- package/lib/interaction/legendHighlight.js.map +1 -1
- package/lib/interaction/scrollbarFilter.d.ts +2 -0
- package/lib/interaction/scrollbarFilter.js +29 -0
- package/lib/interaction/scrollbarFilter.js.map +1 -0
- package/lib/interaction/sliderFilter.d.ts +1 -1
- package/lib/interaction/sliderFilter.js +73 -17
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +1 -1
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/utils.d.ts +1 -0
- package/lib/interaction/utils.js +5 -1
- package/lib/interaction/utils.js.map +1 -1
- package/lib/mark/area.js +7 -3
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/heatmap.d.ts +7 -0
- package/lib/mark/heatmap.js +40 -0
- package/lib/mark/heatmap.js.map +1 -0
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/text.js +0 -2
- package/lib/mark/text.js.map +1 -1
- package/lib/mark/utils.d.ts +1 -0
- package/lib/mark/utils.js +2 -1
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/plot.js +13 -10
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.d.ts +2 -2
- package/lib/runtime/render.js +7 -3
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/scale.js +40 -11
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +12 -9
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +2 -2
- package/lib/runtime/types/options.d.ts +6 -0
- package/lib/shape/heatmap/heatmap.d.ts +4 -0
- package/lib/shape/heatmap/heatmap.js +74 -0
- package/lib/shape/heatmap/heatmap.js.map +1 -0
- package/lib/shape/heatmap/renderer/gradient.d.ts +5 -0
- package/lib/shape/heatmap/renderer/gradient.js +17 -0
- package/lib/shape/heatmap/renderer/gradient.js.map +1 -0
- package/lib/shape/heatmap/renderer/index.d.ts +6 -0
- package/lib/shape/heatmap/renderer/index.js +126 -0
- package/lib/shape/heatmap/renderer/index.js.map +1 -0
- package/lib/shape/heatmap/renderer/types.d.ts +36 -0
- package/lib/shape/heatmap/renderer/types.js +3 -0
- package/lib/shape/heatmap/renderer/types.js.map +1 -0
- package/lib/shape/image/image.js +8 -3
- package/lib/shape/image/image.js.map +1 -1
- package/lib/shape/index.d.ts +4 -0
- package/lib/shape/index.js +6 -2
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.d.ts +8 -0
- package/lib/shape/interval/color.js +19 -8
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/interval/rect.d.ts +10 -1
- package/lib/shape/interval/rect.js.map +1 -1
- package/lib/shape/line/trail.d.ts +3 -0
- package/lib/shape/line/trail.js +78 -0
- package/lib/shape/line/trail.js.map +1 -0
- package/lib/shape/path/color.js +5 -3
- package/lib/shape/path/color.js.map +1 -1
- package/lib/spec/component.d.ts +1 -1
- package/lib/spec/composition.d.ts +9 -6
- package/lib/spec/dataTransform.d.ts +24 -2
- package/lib/spec/mark.d.ts +2 -1
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -1
- package/lib/utils/lru.d.ts +4 -0
- package/lib/utils/lru.js +25 -0
- package/lib/utils/lru.js.map +1 -0
- package/lib/utils/number.d.ts +4 -0
- package/lib/utils/number.js +11 -0
- package/lib/utils/number.js.map +1 -0
- package/lib/utils/scale.d.ts +2 -1
- package/lib/utils/scale.js +32 -12
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/vector.d.ts +1 -0
- package/lib/utils/vector.js +5 -1
- package/lib/utils/vector.js.map +1 -1
- package/package.json +5 -1
- package/src/api/chart.ts +4 -1
- package/src/api/composition/geoPath.ts +2 -0
- package/src/api/mark/index.ts +6 -0
- package/src/api/mark/mark.ts +24 -0
- package/src/api/node.ts +6 -1
- package/src/api/utils.ts +18 -6
- package/src/component/axis.ts +1 -0
- package/src/component/scrollbar.ts +11 -8
- package/src/composition/facetRect.ts +14 -17
- package/src/data/index.ts +2 -0
- package/src/data/utils/venn/circleintersection.ts +235 -0
- package/src/data/utils/venn/diagram.ts +47 -0
- package/src/data/utils/venn/index.ts +5 -0
- package/src/data/utils/venn/layout.ts +769 -0
- package/src/data/venn.ts +58 -0
- package/src/geo/geoPath.ts +3 -1
- package/src/interaction/brushAxisHighlight.ts +130 -11
- package/src/interaction/brushHighlight.ts +6 -4
- package/src/interaction/elementHighlight.ts +39 -3
- package/src/interaction/elementSelect.ts +48 -10
- package/src/interaction/event.ts +7 -2
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +46 -13
- package/src/interaction/legendHighlight.ts +55 -14
- package/src/interaction/scrollbarFilter.ts +32 -0
- package/src/interaction/sliderFilter.ts +108 -28
- package/src/interaction/tooltip.ts +2 -5
- package/src/interaction/utils.ts +6 -0
- package/src/mark/area.ts +6 -3
- package/src/mark/heatmap.ts +48 -0
- package/src/mark/index.ts +2 -0
- package/src/mark/line.ts +1 -1
- package/src/mark/text.ts +0 -1
- package/src/mark/utils.ts +1 -1
- package/src/runtime/plot.ts +31 -13
- package/src/runtime/render.ts +9 -7
- package/src/runtime/scale.ts +58 -14
- package/src/runtime/transform.ts +18 -9
- package/src/runtime/types/component.ts +2 -1
- package/src/runtime/types/options.ts +6 -0
- package/src/shape/heatmap/heatmap.ts +85 -0
- package/src/shape/heatmap/renderer/gradient.ts +16 -0
- package/src/shape/heatmap/renderer/index.ts +193 -0
- package/src/shape/heatmap/renderer/types.ts +38 -0
- package/src/shape/image/image.ts +9 -3
- package/src/shape/index.ts +6 -0
- package/src/shape/interval/color.ts +29 -5
- package/src/shape/interval/rect.ts +10 -1
- package/src/shape/line/trail.ts +80 -0
- package/src/shape/path/color.ts +10 -6
- package/src/spec/component.ts +2 -1
- package/src/spec/composition.ts +24 -8
- package/src/spec/dataTransform.ts +25 -0
- package/src/spec/mark.ts +2 -0
- package/src/stdlib/index.ts +10 -0
- package/src/utils/lru.ts +25 -0
- package/src/utils/number.ts +6 -0
- package/src/utils/scale.ts +29 -10
- package/src/utils/vector.ts +4 -0
package/src/runtime/scale.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createInterpolateValue } from '@antv/scale';
|
|
1
|
+
import { Linear, createInterpolateValue } from '@antv/scale';
|
|
2
2
|
import { extent } from 'd3-array';
|
|
3
3
|
import * as d3ScaleChromatic from 'd3-scale-chromatic';
|
|
4
|
-
import { upperFirst } from '@antv/util';
|
|
4
|
+
import { max, upperFirst } from '@antv/util';
|
|
5
5
|
import { firstOf, lastOf, unique } from '../utils/array';
|
|
6
6
|
import { defined, identity, isStrictObject } from '../utils/helper';
|
|
7
7
|
import { Primitive, G2Theme, G2MarkState, ChannelGroups } from './types/common';
|
|
@@ -26,12 +26,22 @@ export function inferScale(name, values, options, coordinates, theme, library) {
|
|
|
26
26
|
const { guide = {} } = options;
|
|
27
27
|
const type = inferScaleType(name, values, options);
|
|
28
28
|
if (typeof type !== 'string') return options;
|
|
29
|
-
const
|
|
29
|
+
const expectedDomain = inferScaleDomain(type, name, values, options);
|
|
30
|
+
const actualDomain = maybeRatio(type, expectedDomain, options);
|
|
30
31
|
return {
|
|
31
32
|
...options,
|
|
32
33
|
...inferScaleOptions(type, name, values, options, coordinates),
|
|
33
|
-
domain,
|
|
34
|
-
range: inferScaleRange(
|
|
34
|
+
domain: actualDomain,
|
|
35
|
+
range: inferScaleRange(
|
|
36
|
+
type,
|
|
37
|
+
name,
|
|
38
|
+
values,
|
|
39
|
+
options,
|
|
40
|
+
actualDomain,
|
|
41
|
+
theme,
|
|
42
|
+
library,
|
|
43
|
+
),
|
|
44
|
+
expectedDomain,
|
|
35
45
|
guide,
|
|
36
46
|
name,
|
|
37
47
|
type,
|
|
@@ -144,6 +154,35 @@ function syncFacetsScaleByChannel(
|
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
function maybeRatio(
|
|
158
|
+
type: string,
|
|
159
|
+
domain: Primitive[],
|
|
160
|
+
options: G2ScaleOptions,
|
|
161
|
+
) {
|
|
162
|
+
const { ratio } = options;
|
|
163
|
+
if (ratio === undefined || ratio === null) return domain;
|
|
164
|
+
if (isQuantitativeScale({ type })) {
|
|
165
|
+
return clampQuantitativeScale(domain as number[], ratio, type);
|
|
166
|
+
}
|
|
167
|
+
if (isDiscreteScale({ type })) return clampDiscreteScale(domain, ratio);
|
|
168
|
+
return domain;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function clampQuantitativeScale(domain: number[], ratio: number, type: string) {
|
|
172
|
+
const D = domain.map(Number);
|
|
173
|
+
const scale = new Linear({
|
|
174
|
+
domain: D,
|
|
175
|
+
range: [D[0], D[0] + (D[D.length - 1] - D[0]) * ratio],
|
|
176
|
+
});
|
|
177
|
+
if (type === 'time') return domain.map((d) => new Date(scale.map(d)));
|
|
178
|
+
return domain.map((d) => scale.map(d));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function clampDiscreteScale(domain: Primitive[], ratio: number) {
|
|
182
|
+
const index = Math.round(domain.length * ratio);
|
|
183
|
+
return domain.slice(0, index);
|
|
184
|
+
}
|
|
185
|
+
|
|
147
186
|
function isQuantitativeScale(scale: G2ScaleOptions) {
|
|
148
187
|
const { type } = scale;
|
|
149
188
|
if (typeof type !== 'string') return false;
|
|
@@ -190,7 +229,6 @@ function inferScaleDomain(
|
|
|
190
229
|
): Primitive[] {
|
|
191
230
|
const { domain } = options;
|
|
192
231
|
if (domain !== undefined) return domain;
|
|
193
|
-
const { domainMax, domainMin } = options;
|
|
194
232
|
switch (type) {
|
|
195
233
|
case 'linear':
|
|
196
234
|
case 'time':
|
|
@@ -198,20 +236,16 @@ function inferScaleDomain(
|
|
|
198
236
|
case 'pow':
|
|
199
237
|
case 'sqrt':
|
|
200
238
|
case 'quantize':
|
|
201
|
-
case 'threshold':
|
|
202
|
-
|
|
203
|
-
return [domainMin ?? d0, domainMax ?? d1];
|
|
204
|
-
}
|
|
239
|
+
case 'threshold':
|
|
240
|
+
return maybeMinMax(inferDomainQ(values, options), options);
|
|
205
241
|
case 'band':
|
|
206
242
|
case 'ordinal':
|
|
207
243
|
case 'point':
|
|
208
244
|
return inferDomainC(values);
|
|
209
245
|
case 'quantile':
|
|
210
246
|
return inferDomainO(values);
|
|
211
|
-
case 'sequential':
|
|
212
|
-
|
|
213
|
-
return [domainMin ?? d0, domainMax ?? d1];
|
|
214
|
-
}
|
|
247
|
+
case 'sequential':
|
|
248
|
+
return maybeMinMax(inferDomainS(values), options);
|
|
215
249
|
default:
|
|
216
250
|
return [];
|
|
217
251
|
}
|
|
@@ -403,6 +437,16 @@ function asQuantitativeType(name: string, range: Primitive[]) {
|
|
|
403
437
|
return range ? 'linear' : 'sequential';
|
|
404
438
|
}
|
|
405
439
|
|
|
440
|
+
function maybeMinMax(
|
|
441
|
+
domain: Primitive[],
|
|
442
|
+
options: G2ScaleOptions,
|
|
443
|
+
): Primitive[] {
|
|
444
|
+
if (domain.length === 0) return domain;
|
|
445
|
+
const { domainMin, domainMax } = options;
|
|
446
|
+
const [d0, d1] = domain;
|
|
447
|
+
return [domainMin ?? d0, domainMax ?? d1];
|
|
448
|
+
}
|
|
449
|
+
|
|
406
450
|
function inferDomainQ(values: Primitive[][], options: G2ScaleOptions) {
|
|
407
451
|
const { zero = false } = options;
|
|
408
452
|
let min = Infinity;
|
package/src/runtime/transform.ts
CHANGED
|
@@ -255,20 +255,29 @@ export function addGuideToScale(
|
|
|
255
255
|
deepMix(mark, {
|
|
256
256
|
scale: {
|
|
257
257
|
...Object.fromEntries(
|
|
258
|
-
axisChannels.map((channel) =>
|
|
259
|
-
channel
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
258
|
+
axisChannels.map((channel) => {
|
|
259
|
+
const scrollbarOptions = normalize(scrollbar, channel);
|
|
260
|
+
return [
|
|
261
|
+
channel,
|
|
262
|
+
{
|
|
263
|
+
guide: normalize(axis, channel),
|
|
264
|
+
slider: normalize(slider, channel),
|
|
265
|
+
scrollbar: scrollbarOptions,
|
|
266
|
+
...(scrollbarOptions && {
|
|
267
|
+
ratio:
|
|
268
|
+
scrollbarOptions.ratio === undefined
|
|
269
|
+
? 0.5
|
|
270
|
+
: scrollbarOptions.ratio,
|
|
271
|
+
}),
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
}),
|
|
266
275
|
),
|
|
267
276
|
color: { guide: normalize(legend, 'color') },
|
|
268
277
|
size: { guide: normalize(legend, 'size') },
|
|
269
278
|
shape: { guide: normalize(legend, 'shape') },
|
|
270
279
|
// fixme: opacity is conflict with DisplayObject.opacity
|
|
271
|
-
// to be
|
|
280
|
+
// to be confirm.
|
|
272
281
|
opacity: { guide: normalize(legend, 'opacity') },
|
|
273
282
|
},
|
|
274
283
|
});
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { DataComponent } from './data';
|
|
15
15
|
import { Encode, EncodeComponent } from './encode';
|
|
16
16
|
import { Mark, MarkComponent } from './mark';
|
|
17
|
-
import { G2ViewTree, G2Library, G2Mark } from './options';
|
|
17
|
+
import { G2ViewTree, G2Library, G2Mark, G2Context } from './options';
|
|
18
18
|
import { Transform, TransformComponent } from './transform';
|
|
19
19
|
|
|
20
20
|
export type G2ComponentNamespaces =
|
|
@@ -145,6 +145,7 @@ export type Shape = (
|
|
|
145
145
|
coordinate: Coordinate,
|
|
146
146
|
theme: G2Theme,
|
|
147
147
|
point2d?: Vector2[][],
|
|
148
|
+
context?: G2Context,
|
|
148
149
|
) => DisplayObject;
|
|
149
150
|
export type ShapeProps = {
|
|
150
151
|
defaultMarker?: string;
|
|
@@ -57,6 +57,11 @@ export type G2Context = {
|
|
|
57
57
|
group?: DisplayObject;
|
|
58
58
|
animations?: GAnimation[];
|
|
59
59
|
views?: G2ViewDescriptor[];
|
|
60
|
+
/**
|
|
61
|
+
* Tell G2 how to create a canvas-like element, some marks will use it later such as wordcloud & heatmap.
|
|
62
|
+
* Use `document.createElement('canvas')` instead if not provided.
|
|
63
|
+
*/
|
|
64
|
+
createCanvas?: () => HTMLCanvasElement;
|
|
60
65
|
};
|
|
61
66
|
|
|
62
67
|
export type G2View = {
|
|
@@ -126,6 +131,7 @@ export type G2Mark = {
|
|
|
126
131
|
labels?: Record<string, any>[];
|
|
127
132
|
interaction?: Record<string, any>;
|
|
128
133
|
coordinate?: Record<string, any>;
|
|
134
|
+
viewStyle?: Record<string, any>;
|
|
129
135
|
};
|
|
130
136
|
|
|
131
137
|
export type G2MarkChildrenCallback = (
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { max as d3max, min as d3min } from 'd3-array';
|
|
2
|
+
import { Image as GImage } from '@antv/g';
|
|
3
|
+
import { applyStyle, getShapeTheme } from '../utils';
|
|
4
|
+
import { select } from '../../utils/selection';
|
|
5
|
+
import { ShapeComponent as SC } from '../../runtime';
|
|
6
|
+
import { HeatmapRenderer } from './renderer';
|
|
7
|
+
import type { HeatmapRendererOptions } from './renderer/types';
|
|
8
|
+
|
|
9
|
+
export type HeatmapOptions = HeatmapRendererOptions;
|
|
10
|
+
|
|
11
|
+
function deleteKey(obj: any, fn: (v, k) => boolean) {
|
|
12
|
+
const r = { ...obj };
|
|
13
|
+
return Object.keys(obj).reduce((r, k) => {
|
|
14
|
+
const v = obj[k];
|
|
15
|
+
if (!fn(v, k)) r[k] = v;
|
|
16
|
+
return r;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Heatmap: SC<HeatmapOptions> = (options) => {
|
|
21
|
+
const {
|
|
22
|
+
gradient,
|
|
23
|
+
opacity,
|
|
24
|
+
maxOpacity,
|
|
25
|
+
minOpacity,
|
|
26
|
+
blur,
|
|
27
|
+
useGradientOpacity,
|
|
28
|
+
...style
|
|
29
|
+
} = options;
|
|
30
|
+
return (points: number[][], value, coordinate, theme, _, context) => {
|
|
31
|
+
const { mark, shape, defaultShape, transform } = value;
|
|
32
|
+
const { ...shapeTheme } = getShapeTheme(theme, mark, shape, defaultShape);
|
|
33
|
+
const { createCanvas } = context;
|
|
34
|
+
|
|
35
|
+
const [width, height] = coordinate.getSize();
|
|
36
|
+
const data = points.map((p: number[]) => ({
|
|
37
|
+
x: p[0],
|
|
38
|
+
y: p[1],
|
|
39
|
+
value: p[2],
|
|
40
|
+
radius: p[3],
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const min = d3min(points, (p) => p[2]);
|
|
44
|
+
const max = d3max(points, (p) => p[2]);
|
|
45
|
+
|
|
46
|
+
const options = {
|
|
47
|
+
gradient,
|
|
48
|
+
opacity,
|
|
49
|
+
minOpacity,
|
|
50
|
+
maxOpacity,
|
|
51
|
+
blur,
|
|
52
|
+
useGradientOpacity,
|
|
53
|
+
};
|
|
54
|
+
const ctx =
|
|
55
|
+
width && height
|
|
56
|
+
? HeatmapRenderer(
|
|
57
|
+
width,
|
|
58
|
+
height,
|
|
59
|
+
min,
|
|
60
|
+
max,
|
|
61
|
+
data,
|
|
62
|
+
deleteKey(options, (v) => v === undefined),
|
|
63
|
+
createCanvas,
|
|
64
|
+
)
|
|
65
|
+
: { canvas: null };
|
|
66
|
+
|
|
67
|
+
return select(new GImage())
|
|
68
|
+
.call(applyStyle, shapeTheme)
|
|
69
|
+
.style('x', 0)
|
|
70
|
+
.style('y', 0)
|
|
71
|
+
.style('width', width)
|
|
72
|
+
.style('height', height)
|
|
73
|
+
.style('src', ctx.canvas)
|
|
74
|
+
.style('transform', transform)
|
|
75
|
+
.call(applyStyle, style)
|
|
76
|
+
.node();
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
Heatmap.props = {
|
|
81
|
+
defaultMarker: 'point',
|
|
82
|
+
defaultEnterAnimation: 'fadeIn',
|
|
83
|
+
defaultUpdateAnimation: 'morphing',
|
|
84
|
+
defaultExitAnimation: 'fadeOut',
|
|
85
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HeatmapGradient } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse heatmap gradient.
|
|
5
|
+
*/
|
|
6
|
+
export function parseGradient(
|
|
7
|
+
gradient: HeatmapGradient,
|
|
8
|
+
): Array<[number, string]> {
|
|
9
|
+
if (typeof gradient === 'string') {
|
|
10
|
+
return gradient.split(' ').map((stop) => {
|
|
11
|
+
const [r, c] = stop.split(':');
|
|
12
|
+
return [+r, c];
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return gradient;
|
|
16
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { lru } from '../../../utils/lru';
|
|
2
|
+
import { parseGradient } from './gradient';
|
|
3
|
+
import {
|
|
4
|
+
HeatmapGradient,
|
|
5
|
+
HeatmapRendererData,
|
|
6
|
+
HeatmapRendererOptions,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
function newCanvas(
|
|
10
|
+
createCanvas: () => HTMLCanvasElement,
|
|
11
|
+
width: number,
|
|
12
|
+
height: number,
|
|
13
|
+
) {
|
|
14
|
+
const c = createCanvas ? createCanvas() : document.createElement('canvas');
|
|
15
|
+
c.width = width;
|
|
16
|
+
c.height = height;
|
|
17
|
+
return c;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get a point with template.
|
|
22
|
+
* @param radius
|
|
23
|
+
* @param blurFactor
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
const getPointTemplate = lru(
|
|
27
|
+
(
|
|
28
|
+
radius: number,
|
|
29
|
+
blurFactor: number,
|
|
30
|
+
createCanvas?: () => HTMLCanvasElement,
|
|
31
|
+
) => {
|
|
32
|
+
const tplCanvas = newCanvas(createCanvas, radius * 2, radius * 2);
|
|
33
|
+
const tplCtx = tplCanvas.getContext('2d');
|
|
34
|
+
const x = radius;
|
|
35
|
+
const y = radius;
|
|
36
|
+
|
|
37
|
+
if (blurFactor === 1) {
|
|
38
|
+
tplCtx.beginPath();
|
|
39
|
+
tplCtx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
|
40
|
+
tplCtx.fillStyle = 'rgba(0,0,0,1)';
|
|
41
|
+
tplCtx.fill();
|
|
42
|
+
} else {
|
|
43
|
+
const gradient = tplCtx.createRadialGradient(
|
|
44
|
+
x,
|
|
45
|
+
y,
|
|
46
|
+
radius * blurFactor,
|
|
47
|
+
x,
|
|
48
|
+
y,
|
|
49
|
+
radius,
|
|
50
|
+
);
|
|
51
|
+
gradient.addColorStop(0, 'rgba(0,0,0,1)');
|
|
52
|
+
gradient.addColorStop(1, 'rgba(0,0,0,0)');
|
|
53
|
+
tplCtx.fillStyle = gradient;
|
|
54
|
+
tplCtx.fillRect(0, 0, 2 * radius, 2 * radius);
|
|
55
|
+
}
|
|
56
|
+
return tplCanvas;
|
|
57
|
+
},
|
|
58
|
+
(radius) => `${radius}`,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get a color palette with len = 256 base on gradient.
|
|
63
|
+
* @param gradientConfig
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
function getColorPalette(gradientConfig: HeatmapGradient, createCanvas) {
|
|
67
|
+
const paletteCanvas = newCanvas(createCanvas, 256, 1);
|
|
68
|
+
const paletteCtx = paletteCanvas.getContext('2d');
|
|
69
|
+
|
|
70
|
+
const gradient = paletteCtx.createLinearGradient(0, 0, 256, 1);
|
|
71
|
+
parseGradient(gradientConfig).forEach(([r, c]) => {
|
|
72
|
+
gradient.addColorStop(r, c);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
paletteCtx.fillStyle = gradient;
|
|
76
|
+
paletteCtx.fillRect(0, 0, 256, 1);
|
|
77
|
+
|
|
78
|
+
return paletteCtx.getImageData(0, 0, 256, 1).data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Draw all circle with alpha.
|
|
83
|
+
*/
|
|
84
|
+
function drawAlpha(
|
|
85
|
+
shadowCtx,
|
|
86
|
+
min: number,
|
|
87
|
+
max: number,
|
|
88
|
+
data: HeatmapRendererData[],
|
|
89
|
+
options: HeatmapRendererOptions,
|
|
90
|
+
createCanvas?: () => HTMLCanvasElement,
|
|
91
|
+
) {
|
|
92
|
+
const { blur } = options;
|
|
93
|
+
let len = data.length;
|
|
94
|
+
while (len--) {
|
|
95
|
+
const { x, y, value: v, radius } = data[len];
|
|
96
|
+
// Ff value is bigger than max, use max as value.
|
|
97
|
+
const value = Math.min(v, max);
|
|
98
|
+
const rectX = x - radius;
|
|
99
|
+
const rectY = y - radius;
|
|
100
|
+
|
|
101
|
+
const tpl = getPointTemplate(radius, 1 - blur, createCanvas);
|
|
102
|
+
// Value from minimum / value range, => [0, 1].
|
|
103
|
+
const templateAlpha = (value - min) / (max - min);
|
|
104
|
+
// Small values are not visible because globalAlpha < .001 cannot be read from imageData.
|
|
105
|
+
shadowCtx.globalAlpha = Math.max(templateAlpha, 0.001);
|
|
106
|
+
shadowCtx.drawImage(tpl, rectX, rectY);
|
|
107
|
+
}
|
|
108
|
+
return shadowCtx;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function colorize(
|
|
112
|
+
shadowCtx,
|
|
113
|
+
maxWidth: number,
|
|
114
|
+
maxHeight: number,
|
|
115
|
+
palette,
|
|
116
|
+
options: HeatmapRendererOptions,
|
|
117
|
+
) {
|
|
118
|
+
const { minOpacity, opacity, maxOpacity, useGradientOpacity } = options;
|
|
119
|
+
const x = 0;
|
|
120
|
+
const y = 0;
|
|
121
|
+
const width = maxWidth;
|
|
122
|
+
const height = maxHeight;
|
|
123
|
+
|
|
124
|
+
const img = shadowCtx.getImageData(x, y, width, height);
|
|
125
|
+
const imgData = img.data;
|
|
126
|
+
const len = imgData.length;
|
|
127
|
+
|
|
128
|
+
for (let i = 3; i < len; i += 4) {
|
|
129
|
+
const alpha = imgData[i];
|
|
130
|
+
const offset = alpha * 4;
|
|
131
|
+
|
|
132
|
+
if (!offset) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Should be in [min, max], min >= 0.
|
|
137
|
+
const finalAlpha =
|
|
138
|
+
opacity || Math.max(0, Math.min(maxOpacity, Math.max(minOpacity, alpha)));
|
|
139
|
+
// Update rgba.
|
|
140
|
+
imgData[i - 3] = palette[offset];
|
|
141
|
+
imgData[i - 2] = palette[offset + 1];
|
|
142
|
+
imgData[i - 1] = palette[offset + 2];
|
|
143
|
+
imgData[i] = useGradientOpacity ? palette[offset + 3] : finalAlpha;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return img;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Render a heatmap with canvas.
|
|
151
|
+
* See [heatmap.js](https://github.com/pa7/heatmap.js/blob/master/src/renderer/canvas2d.js).
|
|
152
|
+
*/
|
|
153
|
+
export function HeatmapRenderer(
|
|
154
|
+
width: number,
|
|
155
|
+
height: number,
|
|
156
|
+
min: number,
|
|
157
|
+
max: number,
|
|
158
|
+
data: HeatmapRendererData[],
|
|
159
|
+
options: HeatmapRendererOptions,
|
|
160
|
+
createCanvas: () => HTMLCanvasElement,
|
|
161
|
+
) {
|
|
162
|
+
const opts: HeatmapRendererOptions = {
|
|
163
|
+
blur: 0.85,
|
|
164
|
+
minOpacity: 0,
|
|
165
|
+
opacity: 0.6,
|
|
166
|
+
maxOpacity: 1,
|
|
167
|
+
gradient: [
|
|
168
|
+
[0.25, 'rgb(0,0,255)'],
|
|
169
|
+
[0.55, 'rgb(0,255,0)'],
|
|
170
|
+
[0.85, 'yellow'],
|
|
171
|
+
[1.0, 'rgb(255,0,0)'],
|
|
172
|
+
],
|
|
173
|
+
...options,
|
|
174
|
+
};
|
|
175
|
+
opts.minOpacity *= 255;
|
|
176
|
+
opts.opacity *= 255;
|
|
177
|
+
opts.maxOpacity *= 255;
|
|
178
|
+
|
|
179
|
+
const shadowCanvas = newCanvas(createCanvas, width, height);
|
|
180
|
+
const shadowCtx = shadowCanvas.getContext('2d');
|
|
181
|
+
|
|
182
|
+
const palette = getColorPalette(opts.gradient, createCanvas);
|
|
183
|
+
|
|
184
|
+
shadowCtx.clearRect(0, 0, width, height);
|
|
185
|
+
drawAlpha(shadowCtx, min, max, data, opts, createCanvas);
|
|
186
|
+
const img = colorize(shadowCtx, width, height, palette, opts);
|
|
187
|
+
|
|
188
|
+
const canvas = newCanvas(createCanvas, width, height);
|
|
189
|
+
const ctx = canvas.getContext('2d');
|
|
190
|
+
ctx.putImageData(img, 0, 0);
|
|
191
|
+
|
|
192
|
+
return ctx;
|
|
193
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type HeatmapGradientArray = Array<[number, string]>;
|
|
2
|
+
export type HeatmapGradient = string | HeatmapGradientArray;
|
|
3
|
+
|
|
4
|
+
export type HeatmapRendererOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* An gradient string that represents the gradient (syntax: number string [0,1] : color string).
|
|
7
|
+
*/
|
|
8
|
+
gradient?: HeatmapGradient;
|
|
9
|
+
/**
|
|
10
|
+
* A global opacity for the whole heatmap, default = 0.6.
|
|
11
|
+
* This overrides maxOpacity and minOpacity if set!
|
|
12
|
+
*/
|
|
13
|
+
opacity?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The maximal opacity the highest value in the heatmap will have. (will be overridden if opacity set).
|
|
16
|
+
*/
|
|
17
|
+
maxOpacity?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The minimum opacity the lowest value in the heatmap will have (will be overridden if opacity set).
|
|
20
|
+
*/
|
|
21
|
+
minOpacity?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The blur factor that will be applied to all datapoints, default = 0.85.
|
|
24
|
+
* The higher the blur factor is, the smoother the gradients will be.
|
|
25
|
+
*/
|
|
26
|
+
blur?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Use gradient opacity.
|
|
29
|
+
*/
|
|
30
|
+
useGradientOpacity?: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type HeatmapRendererData = {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
value: number;
|
|
37
|
+
radius: number;
|
|
38
|
+
};
|
package/src/shape/image/image.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Image as GImage } from '@antv/g';
|
|
|
2
2
|
import { ShapeComponent as SC } from '../../runtime';
|
|
3
3
|
import { applyStyle, getShapeTheme } from '../utils';
|
|
4
4
|
import { select } from '../../utils/selection';
|
|
5
|
+
import { p } from '../../mark/utils';
|
|
5
6
|
|
|
6
7
|
export type ImageOptions = Record<string, any>;
|
|
7
8
|
|
|
@@ -16,9 +17,14 @@ export const Image: SC<ImageOptions> = (options) => {
|
|
|
16
17
|
defaultShape,
|
|
17
18
|
);
|
|
18
19
|
const { color = defaultColor, src = '', size = 32, transform = '' } = value;
|
|
19
|
-
|
|
20
|
+
let { width = size, height = size } = style;
|
|
20
21
|
const [[x0, y0]] = points;
|
|
21
22
|
|
|
23
|
+
// Support percentage width, height.
|
|
24
|
+
const [w, h] = coordinate.getSize();
|
|
25
|
+
width = typeof width === 'string' ? p(width) * w : width;
|
|
26
|
+
height = typeof height === 'string' ? p(height) * h : height;
|
|
27
|
+
|
|
22
28
|
const x = x0 - Number(width) / 2;
|
|
23
29
|
const y = y0 - Number(height) / 2;
|
|
24
30
|
|
|
@@ -26,12 +32,12 @@ export const Image: SC<ImageOptions> = (options) => {
|
|
|
26
32
|
.call(applyStyle, shapeTheme)
|
|
27
33
|
.style('x', x)
|
|
28
34
|
.style('y', y)
|
|
29
|
-
.style('width', size)
|
|
30
|
-
.style('height', size)
|
|
31
35
|
.style('img', src)
|
|
32
36
|
.style('stroke', color)
|
|
33
37
|
.style('transform', transform)
|
|
34
38
|
.call(applyStyle, style)
|
|
39
|
+
.style('width', width)
|
|
40
|
+
.style('height', height)
|
|
35
41
|
.node();
|
|
36
42
|
};
|
|
37
43
|
};
|
package/src/shape/index.ts
CHANGED
|
@@ -2,11 +2,14 @@ export { Rect } from './interval/rect';
|
|
|
2
2
|
export { Hollow as HollowRect } from './interval/hollow';
|
|
3
3
|
export { Funnel } from './interval/funnel';
|
|
4
4
|
export { Pyramid } from './interval/pyramid';
|
|
5
|
+
|
|
5
6
|
export { Line } from './line/line';
|
|
6
7
|
export { Smooth } from './line/smooth';
|
|
7
8
|
export { HV } from './line/hv';
|
|
8
9
|
export { VH } from './line/vh';
|
|
9
10
|
export { HVH } from './line/hvh';
|
|
11
|
+
export { Trail } from './line/trail';
|
|
12
|
+
|
|
10
13
|
export { Bowtie } from './point/bowtie';
|
|
11
14
|
export { Cross } from './point/cross';
|
|
12
15
|
export { Diamond } from './point/diamond';
|
|
@@ -49,6 +52,7 @@ export { Label } from './label/label';
|
|
|
49
52
|
export { Path } from './path/path';
|
|
50
53
|
export { Hollow as HollowPath } from './path/hollow';
|
|
51
54
|
export { Density } from './density/density';
|
|
55
|
+
export { Heatmap } from './heatmap/heatmap';
|
|
52
56
|
export { Shape } from './shape/shape';
|
|
53
57
|
|
|
54
58
|
export type { RectOptions } from './interval/rect';
|
|
@@ -60,6 +64,7 @@ export type { SmoothOptions } from './line/smooth';
|
|
|
60
64
|
export type { HVOptions } from './line/hv';
|
|
61
65
|
export type { VHOptions } from './line/vh';
|
|
62
66
|
export type { HVHOptions } from './line/hvh';
|
|
67
|
+
export type { TrailOptions } from './line/trail';
|
|
63
68
|
|
|
64
69
|
export type { BowtieOptions } from './point/bowtie';
|
|
65
70
|
export type { CrossOptions } from './point/cross';
|
|
@@ -96,6 +101,7 @@ export type { ImageOptions } from './image/image';
|
|
|
96
101
|
export type { PolygonOptions } from './polygon/polygon';
|
|
97
102
|
export type { BoxOptions } from './box/box';
|
|
98
103
|
export type { ViolinOptions } from './box/violin';
|
|
104
|
+
export type { HeatmapOptions } from './heatmap/heatmap';
|
|
99
105
|
|
|
100
106
|
export type { LineOptions as LineXYOptions } from './lineXY/line';
|
|
101
107
|
export type { ConnectorOptions } from './connector/connector';
|
|
@@ -3,7 +3,8 @@ import { arc } from 'd3-shape';
|
|
|
3
3
|
import { Vector2, ShapeComponent as SC } from '../../runtime';
|
|
4
4
|
import { isPolar, isHelix, isTranspose } from '../../utils/coordinate';
|
|
5
5
|
import { select } from '../../utils/selection';
|
|
6
|
-
import { sub } from '
|
|
6
|
+
import { sub } from '../../utils/vector';
|
|
7
|
+
import { clamp } from '../../utils/number';
|
|
7
8
|
import {
|
|
8
9
|
applyStyle,
|
|
9
10
|
getArcObject,
|
|
@@ -14,6 +15,14 @@ import {
|
|
|
14
15
|
|
|
15
16
|
export type ColorOptions = {
|
|
16
17
|
colorAttribute: 'fill' | 'stroke';
|
|
18
|
+
/**
|
|
19
|
+
* Minimum width of each interval.
|
|
20
|
+
*/
|
|
21
|
+
minWidth?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum width of each interval.
|
|
24
|
+
*/
|
|
25
|
+
maxWidth?: number;
|
|
17
26
|
[key: string]: any;
|
|
18
27
|
};
|
|
19
28
|
|
|
@@ -35,6 +44,8 @@ export function rect(
|
|
|
35
44
|
radiusBottomRight = radius,
|
|
36
45
|
radiusTopLeft = radius,
|
|
37
46
|
radiusTopRight = radius,
|
|
47
|
+
minWidth = -Infinity,
|
|
48
|
+
maxWidth = Infinity,
|
|
38
49
|
...rest
|
|
39
50
|
} = style;
|
|
40
51
|
if (!isPolar(coordinate) && !isHelix(coordinate)) {
|
|
@@ -53,11 +64,20 @@ export function rect(
|
|
|
53
64
|
const finalWidth = absWidth - (insetLeft + insetRight);
|
|
54
65
|
const finalHeight = absHeight - (insetTop + insetBottom);
|
|
55
66
|
|
|
67
|
+
const clampWidth = tpShape
|
|
68
|
+
? finalWidth
|
|
69
|
+
: clamp(finalWidth, minWidth, maxWidth);
|
|
70
|
+
const clampHeight = tpShape
|
|
71
|
+
? clamp(finalHeight, minWidth, maxWidth)
|
|
72
|
+
: finalHeight;
|
|
73
|
+
const clampX = finalX - (clampWidth - finalWidth) / 2;
|
|
74
|
+
const clampY = finalY - (clampHeight - finalHeight) / 2;
|
|
75
|
+
|
|
56
76
|
return select(new Rect({}))
|
|
57
|
-
.style('x',
|
|
58
|
-
.style('y',
|
|
59
|
-
.style('width',
|
|
60
|
-
.style('height',
|
|
77
|
+
.style('x', clampX)
|
|
78
|
+
.style('y', clampY)
|
|
79
|
+
.style('width', clampWidth)
|
|
80
|
+
.style('height', clampHeight)
|
|
61
81
|
.style('radius', [
|
|
62
82
|
radiusTopLeft,
|
|
63
83
|
radiusTopRight,
|
|
@@ -128,6 +148,8 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
128
148
|
insetRight = inset,
|
|
129
149
|
insetBottom = inset,
|
|
130
150
|
insetTop = inset,
|
|
151
|
+
minWidth,
|
|
152
|
+
maxWidth,
|
|
131
153
|
...rest
|
|
132
154
|
} = style;
|
|
133
155
|
const { color = defaultColor, opacity } = value;
|
|
@@ -160,6 +182,8 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
160
182
|
insetRight,
|
|
161
183
|
insetBottom,
|
|
162
184
|
insetTop,
|
|
185
|
+
minWidth,
|
|
186
|
+
maxWidth,
|
|
163
187
|
};
|
|
164
188
|
|
|
165
189
|
return (
|