Skip to content

Commit 02ac2f7

Browse files
authored
Merge pull request #2986 from finos/fix-2970
Fix line chart alt Y axis on zoom
2 parents a7a9d1f + 0f9064a commit 02ac2f7

File tree

10 files changed

+78
-130
lines changed

10 files changed

+78
-130
lines changed

packages/perspective-viewer-d3fc/build.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ function add(builder, path) {
8484
async function compile_css() {
8585
fs.mkdirSync("dist/css", { recursive: true });
8686
const builder = new BuildCss("");
87-
add(builder, "./series_colors.less");
88-
add(builder, "./gradient_colors.less");
8987
add(builder, "./chart.less");
9088
fs.writeFileSync(
9189
"dist/css/perspective-viewer-d3fc.css",

packages/perspective-viewer-d3fc/src/less/chart.less

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

13-
@import "./gradient_colors.less";
14-
@import "./series_colors.less";
15-
1613
@mixin icon {
1714
background-repeat: no-repeat;
1815
background-color: var(--icon--color);
@@ -34,6 +31,17 @@
3431
padding: 12px;
3532
overflow: hidden;
3633

34+
&.yline {
35+
.y-series:not(:first-child) .gridline-x {
36+
display: none;
37+
}
38+
}
39+
40+
text {
41+
// `font-family` does not apply to `<text>` nodes via inheritance.
42+
font-family: var(--interface-monospace--font-family);
43+
}
44+
3745
&.heatmap,
3846
&.treemap {
3947
d3fc-group.cartesian-chart {
@@ -298,11 +306,13 @@
298306
}
299307

300308
& .y-axis text,
309+
& .y2-axis text,
301310
& .x-axis text {
302311
fill: var(--d3fc-axis-ticks--color, rgb(80, 80, 80));
303312
font-size: 11px;
304313
}
305314
& .y-axis path,
315+
& .y2-axis path,
306316
& .x-axis path {
307317
stroke: var(--d3fc-axis--lines, rgb(180, 210, 225));
308318
}
@@ -350,10 +360,16 @@
350360
&.ybar .y-axis path,
351361
&.yline .y-axis path,
352362
&.xyline .y-axis path,
363+
&.ybar .y2-axis path,
364+
&.yline .y2-axis path,
365+
&.xyline .y2-axis path,
353366
&.xyline .x-axis path,
354367
&.yarea .y-axis path,
355368
&.yscatter .y-axis path,
356369
&.xyscatter .y-axis path,
370+
&.yarea .y2-axis path,
371+
&.yscatter .y2-axis path,
372+
&.xyscatter .y2-axis path,
357373
&.xyscatter .x-axis path,
358374
&.xbar .x-axis path {
359375
visibility: hidden;

packages/perspective-viewer-d3fc/src/less/gradient_colors.less

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/perspective-viewer-d3fc/src/less/series_colors.less

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/perspective-viewer-d3fc/src/ts/axis/chartFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const chartFactory = (xAxis, yAxis, cartesian, canvas) => {
155155

156156
// Render the axis
157157
y2AxisDataJoin(container, ["right"])
158-
.attr("class", (d) => `y-axis ${d}-axis`)
158+
.attr("class", (d) => `y2-axis ${d}-axis`)
159159
.on("measure", function (event, d) {
160160
const { width, height } = event.detail;
161161
if (d === "left") {

packages/perspective-viewer-d3fc/src/ts/axis/ordinalAxis.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,31 @@ export const component = (settings: Settings): Component => {
214214
if (orient === "horizontal") {
215215
// x-axis may rotate labels and expand the available height
216216
if (group && group.length * 16 > width - 100) {
217+
// Vertical
217218
return {
218-
size: maxLength * 5 + 10,
219+
size: maxLength * 6.62 + 10,
219220
rotation: 90,
220221
};
221222
} else if (
222223
group &&
223224
group.length * (maxLength * 6 + 10) > width - 100
224225
) {
226+
// Angle
225227
return {
226-
size: maxLength * 3 + 20,
228+
size: maxLength * 4 + 20,
227229
rotation: 45,
228230
};
229231
}
232+
233+
// Horizontal
230234
return {
231235
size: 25,
232236
rotation: 0,
233237
};
234238
} else {
235239
// y-axis size always based on label size
236240
return {
237-
size: maxLength * 5 + 10,
241+
size: maxLength * 6.62 + 10,
238242
rotation: 0,
239243
};
240244
}

packages/perspective-viewer-d3fc/src/ts/charts/line.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ function lineChart(container, settings: Settings) {
6161
const yAxis1: AxisFactoryContent = yAxisFactory(splitter.data());
6262

6363
// No grid lines if splitting y-axis
64-
const plotSeries = splitter.haveSplit()
65-
? series
66-
: withGridLines(series, settings).orient("vertical");
64+
const plotSeries = withGridLines(series, settings).orient("vertical");
65+
6766
const chart = chartSvgFactory(xAxis, yAxis1)
6867
.axisSplitter(splitter)
6968
.plotArea(plotSeries);

packages/perspective-viewer-d3fc/src/ts/series/colorStyles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export const initialiseStyles = (
2727
};
2828

2929
const computed = computedStyle(container);
30-
styles["series"] = computed(`--d3fc-local-series`);
30+
styles["series"] = computed(`--d3fc-series`);
3131
for (let i = 1; ; i++) {
3232
const key = `series-${i}`;
33-
const color = computed(`--d3fc-local-${key}`);
33+
const color = computed(`--d3fc-${key}`);
3434
if (!color) {
3535
break;
3636
}
@@ -44,7 +44,7 @@ export const initialiseStyles = (
4444

4545
const gradients = ["full", "positive", "negative"];
4646
gradients.forEach((g) => {
47-
const gradient = computed(`--d3fc-local-${g}--gradient`);
47+
const gradient = computed(`--d3fc-${g}--gradient`);
4848
styles.gradient[g] = parseGradient(gradient, styles.opacity);
4949
});
5050

packages/perspective-viewer-d3fc/test/js/line.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,50 @@ test.describe("Line regressions", () => {
7979
"line-charts-denser-than-one-second-regression.txt",
8080
]);
8181
});
82+
83+
test("Zoom on a chart with split Y axis renders the right axis", async ({
84+
page,
85+
}) => {
86+
await page.goto("/tools/perspective-test/src/html/basic-test.html");
87+
await page.evaluate(async () => {
88+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
89+
await new Promise((x) => setTimeout(x, 10));
90+
}
91+
});
92+
93+
await page.evaluate(async () => {
94+
await document.querySelector("perspective-viewer")!.restore({
95+
plugin: "Y Line",
96+
plugin_config: {
97+
splitMainValues: ["Profit"],
98+
},
99+
settings: true,
100+
theme: "Pro Light",
101+
group_by: ["Order Date"],
102+
columns: ["Sales", "Profit"],
103+
});
104+
});
105+
106+
await page.mouse.move(500, 500);
107+
await page.mouse.wheel(0, -100);
108+
109+
const contents = await page.$(
110+
"perspective-viewer-d3fc-yline .y2-axis.right-axis"
111+
);
112+
113+
test.expect(await contents?.innerText()).toEqual(`−1,800
114+
−1,600
115+
−1,400
116+
−1,200
117+
−1,000
118+
−800
119+
−600
120+
−400
121+
−200
122+
0
123+
200
124+
400`);
125+
126+
await page.pause();
127+
});
82128
});
-151 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)