Skip to content
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

fix(axis): fix undefined error reading generatedTicks #2788

Merged
merged 1 commit into from
Jul 19, 2022
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
2 changes: 1 addition & 1 deletion src/ChartInternal/Axis/AxisRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default class AxisRenderer {
* @private
*/
getGeneratedTicks(count: number): (Date|number)[] {
const len = this.generatedTicks.length - 1;
const len = this.generatedTicks?.length - 1;
let res = this.generatedTicks;

if (len > count) {
Expand Down
1 change: 0 additions & 1 deletion src/ChartInternal/internals/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export default {
const {axis, config, scale, state, $el: {grid, main}} = $$;
const isRotated = config.axis_rotated;
const pos = d => Math.ceil(scale.y(d));

const gridValues =
axis.y.getGeneratedTicks(config.grid_y_ticks) || $$.scale.y.ticks(config.grid_y_ticks);

Expand Down
62 changes: 58 additions & 4 deletions test/internals/grid-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* eslint-disable */
import {expect} from "chai";
import {select as d3Select} from "d3-selection";
import { utils } from "mocha";
import {$AXIS, $COMMON, $EVENT, $FOCUS, $GRID} from "../../src/config/classes";
import util from "../assets/util";

Expand Down Expand Up @@ -155,7 +156,7 @@ describe("GRID", function() {

it("should show grids depending on y axis ticks", () => {
const ygrids = chart.$.main.select(`.${$GRID.ygrids}`);
const expectedYs = [];
const expectedYs: number[] = [];

ygrids.selectAll(`.${$GRID.ygrid}`).each(function(d, i) {
expectedYs[i] = +d3Select(this).attr("y1");
Expand All @@ -181,9 +182,9 @@ describe("GRID", function() {
args = {
data: {
columns: [
["data1", 100, 50, 150, 200, 100, 350, 58, 210, 80, 126],
["data2", 305, 350, 55, 25, 335, 29, 258, 310, 180, 226],
["data3", 223, 121, 259, 247, 53, 159, 95, 111, 307, 337]
["data1", 100, 50, 150, 200, 100, 350, 58, 210, 80, 126],
["data2", 305, 350, 55, 25, 335, 29, 258, 310, 180, 226],
["data3", 223, 121, 259, 247, 53, 159, 95, 111, 307, 337]
],
type: "line",
labels: true
Expand All @@ -208,6 +209,59 @@ describe("GRID", function() {

expect(gridLen).to.be.equal(tickLen);
});

it("shouldn't be throw error", () => {
try {
util.generate({
"data": {
"json": [
{ "data_periodo": "2018-05-01", "int_exists": 0 },
{ "data_periodo": "2018-06-01", "int_exists": 0 }
],
"keys": {
"x": "data_periodo",
"value": [
"int_exists"
]
},
"type": "line"
},
"axis": {
"y": {
"tick": {
"format": null,
"count": 1
},
"show": false,
"max": 1,
"min": 0.1
},
},
"grid": {
"y": {
"show": true,
"lines": [
{
"value": 0,
"position": "start",
"text": "assenza"
},
{
"value": 1,
"position": "start",
"text": "presenza"
}
]
}
}
});
} catch (e) {
// it shouldn't be thrown
expect(false).to.be.true;
}

expect(true).to.be.ok;
});
});

describe("front option", () => {
Expand Down