Skip to content

Commit 67476b1

Browse files
author
netil
committed
Merge branch 'master' into next
2 parents e35c49c + 0060786 commit 67476b1

File tree

12 files changed

+541
-224
lines changed

12 files changed

+541
-224
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"@eslint/js": "^9.12.0",
108108
"@rollup/plugin-node-resolve": "^15.3.0",
109109
"@rollup/plugin-replace": "^6.0.1",
110-
"@rollup/plugin-typescript": "^12.1.0",
110+
"@rollup/plugin-typescript": "^12.1.1",
111111
"@semantic-release/changelog": "^6.0.3",
112112
"@semantic-release/commit-analyzer": "^13.0.0",
113113
"@semantic-release/exec": "^6.0.3",
@@ -118,9 +118,9 @@
118118
"@testing-library/react": "^16.0.1",
119119
"@types/d3": "^7.4.3",
120120
"@types/sinon": "^17.0.3",
121-
"@vitest/browser": "^2.1.2",
122-
"@vitest/coverage-istanbul": "^2.1.2",
123-
"@vitest/ui": "^2.1.2",
121+
"@vitest/browser": "^2.1.3",
122+
"@vitest/coverage-istanbul": "^2.1.3",
123+
"@vitest/ui": "^2.1.3",
124124
"better-docs": "^2.7.3",
125125
"clean-webpack-plugin": "^4.0.0",
126126
"cloc": "2.2.0-cloc",
@@ -137,26 +137,26 @@
137137
"esbuild-loader": "^4.2.2",
138138
"eslint": "^9.12.0",
139139
"eslint-plugin-import": "^2.31.0",
140-
"eslint-plugin-jsdoc": "^50.3.1",
140+
"eslint-plugin-jsdoc": "^50.4.1",
141141
"husky": "^9.1.6",
142142
"jsdoc": "^4.0.3",
143143
"lint-staged": "^15.2.10",
144144
"mini-css-extract-plugin": "^2.9.1",
145-
"playwright": "^1.47.2",
145+
"playwright": "^1.48.0",
146146
"regenerator-runtime": "^0.14.1",
147147
"rollup": "^4.24.0",
148148
"rollup-plugin-delete": "^2.1.0",
149-
"sass": "^1.79.4",
149+
"sass": "^1.79.5",
150150
"sass-loader": "^16.0.2",
151151
"semantic-release": "^24.1.2",
152152
"simulant": "^0.2.2",
153153
"sinon": "^19.0.2",
154154
"string-replace-loader": "^3.1.0",
155155
"style-loader": "^4.0.0",
156-
"tslib": "^2.7.0",
157-
"typescript": "^5.6.2",
158-
"typescript-eslint": "^8.8.1",
159-
"vitest": "^2.1.2",
156+
"tslib": "^2.8.0",
157+
"typescript": "^5.6.3",
158+
"typescript-eslint": "^8.9.0",
159+
"vitest": "^2.1.3",
160160
"webpack": "^5.95.0",
161161
"webpack-bundle-analyzer": "^4.10.2",
162162
"webpack-clean": "^1.2.5",

src/ChartInternal/Axis/AxisRendererHelper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ export default class AxisRendererHelper {
7777
value => `translate(0,${value})`;
7878

7979
return (selection, scale) => {
80-
selection.attr("transform", d => (
81-
isValue(d) ? fn(Math.ceil(scale(d))) : null
82-
));
80+
selection.attr("transform", d => {
81+
const x = scale(d);
82+
83+
return isValue(d) ? fn(Math.ceil(x)) : null;
84+
});
8385
};
8486
}
8587

src/ChartInternal/interactions/eventrect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ export default {
671671
clickHandlerForMultipleXS(ctx): void {
672672
const $$ = ctx;
673673
const {config, state} = $$;
674+
const pointSensitivity = config.point_sensitivity;
674675
const targetsToShow = $$.filterTargetsToShow($$.data.targets);
675676

676677
if ($$.hasArcType(targetsToShow)) {
@@ -679,9 +680,9 @@ export default {
679680

680681
const mouse = getPointer(state.event, this);
681682
const closest = $$.findClosestFromTargets(targetsToShow, mouse);
682-
const sensitivity = config.point_sensitivity === "radius" ?
683-
closest.r :
684-
config.point_sensitivity;
683+
const sensitivity = pointSensitivity === "radius" ? closest?.r : (
684+
isFunction(pointSensitivity) ? closest && pointSensitivity(closest) : pointSensitivity
685+
);
685686

686687
if (!closest) {
687688
return;

src/ChartInternal/interactions/zoom.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export default {
2323
$$.scale.zoom = null;
2424

2525
$$.generateZoom();
26-
$$.initZoomBehaviour();
26+
27+
$$.config.zoom_type === "drag" &&
28+
$$.initZoomBehaviour();
2729
},
2830

2931
/**
@@ -72,6 +74,7 @@ export default {
7274
const ratio = diffDomain($$.scale.x.orgDomain()) / diffDomain($$.getZoomDomain());
7375
const extent = this.orgScaleExtent();
7476

77+
// https://d3js.org/d3-zoom#zoom_scaleExtent
7578
this.scaleExtent([extent[0] * ratio, extent[1] * ratio]);
7679

7780
return this;
@@ -96,6 +99,11 @@ export default {
9699
isRotated ? "rescaleY" : "rescaleX"
97100
](org.xScale || scale.x);
98101

102+
// prevent drag zoom to be out of range
103+
if (newScale.domain().some(v => /(Invalid Date|NaN)/.test(v.toString()))) {
104+
return;
105+
}
106+
99107
const domain = $$.trimXDomain(newScale.domain());
100108
const rescale = config.zoom_rescale;
101109

@@ -381,7 +389,7 @@ export default {
381389
.attr("height", isRotated ? 0 : state.height);
382390
}
383391

384-
start = getPointer(event, <SVGElement>this)[prop.index];
392+
start = getPointer(event, this as SVGAElement)[prop.index];
385393
end = start;
386394

387395
zoomRect
@@ -391,7 +399,7 @@ export default {
391399
$$.onZoomStart(event);
392400
})
393401
.on("drag", function(event) {
394-
end = getPointer(event, <SVGElement>this)[prop.index];
402+
end = getPointer(event, this as SVGAElement)[prop.index];
395403

396404
zoomRect
397405
.attr(prop.axis, Math.min(start, end))

src/ChartInternal/internals/legend.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,10 @@ export default {
462462
.on(interaction.dblclick ? "dblclick" : "click",
463463
interaction || isFunction(config.legend_item_onclick) ?
464464
function(event, id) {
465-
if (!callFn(config.legend_item_onclick, api, id)) {
465+
if (
466+
!callFn(config.legend_item_onclick, api, id,
467+
!state.hiddenTargetIds.includes(id))
468+
) {
466469
const {altKey, target, type} = event;
467470

468471
if (type === "dblclick" || altKey) {
@@ -493,7 +496,10 @@ export default {
493496
!isTouch && item
494497
.on("mouseout", interaction || isFunction(config.legend_item_onout) ?
495498
function(event, id) {
496-
if (!callFn(config.legend_item_onout, api, id)) {
499+
if (
500+
!callFn(config.legend_item_onout, api, id,
501+
!state.hiddenTargetIds.includes(id))
502+
) {
497503
d3Select(this).classed($FOCUS.legendItemFocused, false);
498504

499505
if (hasGauge) {
@@ -506,7 +512,10 @@ export default {
506512
null)
507513
.on("mouseover", interaction || isFunction(config.legend_item_onover) ?
508514
function(event, id) {
509-
if (!callFn(config.legend_item_onover, api, id)) {
515+
if (
516+
!callFn(config.legend_item_onover, api, id,
517+
!state.hiddenTargetIds.includes(id))
518+
) {
510519
d3Select(this).classed($FOCUS.legendItemFocused, true);
511520

512521
if (hasGauge) {

src/config/Options/common/legend.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ export default {
118118
* }
119119
*
120120
* // when set below callback, will disable corresponding default interactions
121-
* onclick: function(id) { ... },
122-
* onover: function(id) { ... },
123-
* onout: function(id) { ... },
121+
* onclick: function(id, visible) {
122+
* // toggle based on the data visibility
123+
* this[visible ? "hide" : "show"](id);
124+
* },
125+
* onover: function(id, visible) { ... },
126+
* onout: function(id, visible) { ... },
124127
*
125128
* // set tile's size
126129
* tile: {

test/api/zoom-spec.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,81 @@ describe("API zoom", function() {
632632
expect($$.scale.zoom).to.be.null;
633633
});
634634
});
635+
636+
describe("zoom extent", () => {
637+
beforeAll(() => {
638+
chart = util.generate({
639+
data: {
640+
json: [
641+
{"date":"2023-09-30 00:00:00","ek_house":0},
642+
{"date":"2023-10-14 00:00:00","ek_house":0},
643+
{"date":"2023-10-21 00:00:00","ek_house":0},
644+
{"date":"2023-10-28 00:00:00","ek_house":0},
645+
{"date":"2023-11-04 00:00:00","ek_house":0},
646+
],
647+
keys: {
648+
x: "date",
649+
value: ["ek_house"],
650+
},
651+
},
652+
axis: {
653+
x: {
654+
type: "timeseries",
655+
tick: {
656+
format: "%Y-%m-%d"
657+
},
658+
},
659+
y: {
660+
show: false
661+
}
662+
},
663+
zoom: {
664+
enabled: true
665+
}
666+
});
667+
});
668+
669+
it("shouldn't throw error for timeseries x axis, when is given out of range.", () => new Promise(done => {
670+
chart.zoom([1697701666380, 1697702008724]);
671+
672+
setTimeout(() => {
673+
chart.$.circles.each(function() {
674+
expect(this.getAttribute("cx") !== "NaN").to.be.true;
675+
});
676+
677+
done(1);
678+
}, 300);
679+
}));
680+
681+
it("shouldn't throw error for indexed x axis, when is given out of range.", () => new Promise(done => {
682+
chart = util.generate({
683+
data: {
684+
columns: [
685+
["data2", 130, 100, 140, 200, 150, 50, 120, 100, 80, 90]
686+
],
687+
},
688+
zoom: {
689+
enabled: true
690+
},
691+
axis: {
692+
y: {
693+
show: false
694+
}
695+
}
696+
});
697+
698+
chart.zoom([
699+
4.908784864317814,
700+
4.908812566017803
701+
]);
702+
703+
setTimeout(() => {
704+
chart.$.circles.each(function() {
705+
expect(this.getAttribute("cx") !== "NaN").to.be.true;
706+
});
707+
708+
done(1);
709+
}, 300);
710+
}));
711+
});
635712
});

test/internals/bb-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ describe("Interface & initialization", () => {
536536
}));
537537

538538
it("check lazy rendering on callbacks", () => new Promise(done => {
539-
const el = <HTMLDivElement>document.body.querySelector("#chart");
539+
const el = document.body.querySelector("#chart") as HTMLDivElement;
540540

541541
// hide to lazy render
542542
el.style.display = "none";

test/internals/legend-spec.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ describe("LEGEND", () => {
815815
});
816816

817817
it("set options: legend.item.onclick", () => {
818-
args.legend.item.onclick = () => {};
818+
args.legend.item.onclick = sinon.spy(() => {});
819819
});
820820

821821
it("should only 'click' event lister bound", () => {
@@ -826,14 +826,24 @@ describe("LEGEND", () => {
826826

827827
expect(item.on("mouseover mouseout")).to.be.undefined;
828828
expect(item.on("click")).to.not.be.undefined;
829-
830829
expect(item.style("cursor")).to.be.equal("pointer");
830+
831+
id === "data1" && chart.hide(id);
832+
833+
fireEvent(item.node(), "click", {
834+
clientX: 2,
835+
clientY: 2
836+
}, chart);
831837
});
838+
839+
// given visible state argguments?
840+
expect(args.legend.item.onclick.args)
841+
.to.be.deep.equal(chart.data().map(({id}) => [id, id === "data1" ? false : true]));
832842
});
833843

834844
it("set options: legend.item.onover", () => {
835845
delete args.legend.item.onclick;
836-
args.legend.item.onover = () => {};
846+
args.legend.item.onover = sinon.spy(() => {});
837847
});
838848

839849
it("should only 'mouseover' event lister bound", () => {
@@ -844,14 +854,24 @@ describe("LEGEND", () => {
844854

845855
expect(item.on("click mouseout")).to.be.undefined;
846856
expect(item.on("mouseover")).to.not.be.undefined;
847-
848857
expect(item.style("cursor")).to.be.equal("pointer");
858+
859+
id === "data2" && chart.hide(id);
860+
861+
fireEvent(item.node(), "mouseover", {
862+
clientX: 2,
863+
clientY: 2
864+
}, chart);
849865
});
866+
867+
// given visible state argguments?
868+
expect(args.legend.item.onover.args)
869+
.to.be.deep.equal(chart.data().map(({id}) => [id, id === "data2" ? false : true]));
850870
});
851871

852872
it("set options: legend.item.onout", () => {
853873
delete args.legend.item.onover;
854-
args.legend.item.onout = () => {};
874+
args.legend.item.onout = sinon.spy(() => {});
855875
});
856876

857877
it("should only 'mouseout' event lister bound", () => {
@@ -862,9 +882,19 @@ describe("LEGEND", () => {
862882

863883
expect(item.on("click mouseover")).to.be.undefined;
864884
expect(item.on("mouseout")).to.not.be.undefined;
865-
866885
expect(item.style("cursor")).to.be.equal("pointer");
886+
887+
id === "data1" && chart.hide(id);
888+
889+
fireEvent(item.node(), "mouseout", {
890+
clientX: 2,
891+
clientY: 2
892+
}, chart);
867893
});
894+
895+
// given visible state argguments?
896+
expect(args.legend.item.onout.args)
897+
.to.be.deep.equal(chart.data().map(({id}) => [id, id === "data1" ? false : true]));
868898
});
869899

870900
it("set options: legend.item.interaction.dblclik=true", () => {

0 commit comments

Comments
 (0)