Skip to content

chore: resolve d3-array type locked issue #6607

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/plots/static/barley-line-trail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export async function barleyLineTrail(): Promise<G2Spec> {
const keyDelta = rollup(
data,
([a, b]) => {
if (b.year < a.year) [a, b] = [b, a];
return b.yield - a.yield;
if ((b as any).year < (a as any).year) [a, b] = [b, a];
return (b as any).yield - (a as any).yield;
},
key,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function incomeStatementByRegionIntervalCustom() {
const groupData = (data) => {
const groups = group(data, (d: any) => d.x);
return Array.from(groups.entries()).reduce((r, [k, v]) => {
const y = v[v.length - 1].end;
const y = (v[v.length - 1] as any).end;
return r.concat({
x: k,
y,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@antv/g-plugin-dragndrop": "^2.0.22",
"@antv/scale": "^0.4.16",
"@antv/util": "^3.3.10",
"@antv/vendor": "1.0.6",
"@antv/vendor": "^1.0.8",
"flru": "^1.0.2",
"fmin": "0.0.2",
"pdfast": "^0.2.0"
Expand Down Expand Up @@ -165,4 +165,4 @@
"bugs": {
"url": "https://github.com/antvis/g2/issues"
}
}
}
10 changes: 5 additions & 5 deletions src/data/utils/arc/arc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { group, sum } from '@antv/vendor/d3-array';
import { error } from '../../../utils/helper';
import { ArcData, ArcOptions } from './types';
import { ArcData, ArcOptions, ArcEdge, ArcNode } from './types';
import * as SortMethods from './sort';

const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -53,7 +53,7 @@ export function Arc(options?: ArcOptions) {
/**
* Calculate id, value, frequency for node, and source,target for edge.
*/
function preprocess(nodes, edges) {
function preprocess(nodes: ArcNode[], edges: ArcEdge[]) {
edges.forEach((edge) => {
edge.source = source(edge);
edge.target = target(edge);
Expand Down Expand Up @@ -83,15 +83,15 @@ export function Arc(options?: ArcOptions) {
return { nodes, edges };
}

function sortNodes(nodes, edges) {
function sortNodes(nodes: ArcNode[], edges: ArcEdge[]) {
const method = typeof sortBy === 'function' ? sortBy : SortMethods[sortBy];

if (method) {
nodes.sort(method);
}
}

function layoutNodes(nodes, edges) {
function layoutNodes(nodes: ArcNode[], edges: ArcEdge[]) {
const size = nodes.length;
if (!size) {
throw error("Invalid nodes: it's empty!");
Expand Down Expand Up @@ -145,7 +145,7 @@ export function Arc(options?: ArcOptions) {
/**
* Get edge layout information from nodes, and save into edge object.
*/
function layoutEdges(nodes, edges) {
function layoutEdges(nodes: ArcNode[], edges: ArcEdge[]) {
const nodesMap = new Map(nodes.map((d) => [d.id, d]));

if (!weight) {
Expand Down
30 changes: 28 additions & 2 deletions src/data/utils/arc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,34 @@ export type ArcOptions = {
/** Thickness of node, default: 0.05 */
thickness?: number;
};
export interface ArcEdge {
source: string;
target: string;
sourceWeight: number;
targetWeight: number;
x: number[] | number;
y: number[] | number;
value: number;
weight?: number;
width?: number;
height?: number;
frequency?: number;
[key: string]: any;
}

export interface ArcNode {
id: string;
x: number[] | number;
y: number[] | number;
value: number;
frequency: number;
weight?: number;
width?: number;
height?: number;
[key: string]: any;
}

export type ArcData = {
nodes: any[];
edges: any[];
nodes: ArcNode[];
edges: ArcEdge[];
};
6 changes: 4 additions & 2 deletions src/interaction/legendHighlight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { group } from '@antv/vendor/d3-array';
import { InternMap, group } from '@antv/vendor/d3-array';
import { subObject } from '../utils/helper';
import {
mergeState,
Expand Down Expand Up @@ -66,7 +66,9 @@ export function LegendHighlight() {
const highlightItem = (event, item) => {
// Update UI.
const value = datumOf(item);
const elementSet = new Set(elementGroup.get(value));
const elementSet = new Set(
(elementGroup as InternMap<unknown, any[]>).get(value),
);
for (const e of elements) {
if (elementSet.has(e)) setState(e, 'active');
else setState(e, 'inactive');
Expand Down
17 changes: 15 additions & 2 deletions src/runtime/layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Coordinate } from '@antv/coord';
import { ascending, group, max, min, sum } from '@antv/vendor/d3-array';
import {
NestedInternMap,
ascending,
group,
max,
min,
sum,
} from '@antv/vendor/d3-array';
import { deepMix } from '@antv/util';
import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
import { capitalizeFirst, defined } from '../utils/helper';
Expand Down Expand Up @@ -389,10 +396,16 @@ export function placeComponents(
layout: Layout,
): void {
// Group components by plane & position.
const positionComponents = group<G2GuideComponentOptions, string>(

const positionComponents: NestedInternMap<
G2GuideComponentOptions,
G2GuideComponentOptions[],
[string]
> = group<G2GuideComponentOptions, [string]>(
components,
(d) => `${d.plane || 'xy'}-${d.position}`,
);

const {
paddingLeft,
paddingRight,
Expand Down
4 changes: 2 additions & 2 deletions src/transform/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Bin: TC<BinOptions> = (options = {}) => {
const channelIndexKey = {};

// Group indexes and update channelIndexKey.
const groupBy = (I, mark) => {
const groupBy = (I, mark): number[][] => {
const { encode } = mark;
const binValues = binChannels.map((channel) => {
const [V] = columnOf(encode, channel);
Expand Down Expand Up @@ -80,7 +80,7 @@ export const Bin: TC<BinOptions> = (options = {}) => {

// Group by indexes by channel keys.
const key = (i: number) => groupKeys.map((key) => key(i)).join('-');
return Array.from(group(DI, key).values());
return Array.from(group(DI, key).values()) as number[][];
};

return GroupN({
Expand Down
Loading