Skip to content

Commit

Permalink
Merge branch 'master' into nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
netil committed Nov 8, 2023
2 parents 7f7c1b9 + d2923f2 commit 3f0689d
Show file tree
Hide file tree
Showing 4 changed files with 425 additions and 398 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"@types/d3-selection": "^3.0.8",
"@types/d3-transition": "^3.0.6",
"@types/d3-selection": "^3.0.9",
"@types/d3-transition": "^3.0.7",
"d3-axis": "^3.0.0",
"d3-brush": "^3.0.0",
"d3-drag": "^3.0.0",
Expand Down Expand Up @@ -117,17 +117,17 @@
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^11.1.5",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.0.0",
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^11.0.0",
"@semantic-release/release-notes-generator": "^12.0.0",
"@semantic-release/npm": "^11.0.1",
"@semantic-release/release-notes-generator": "^12.1.0",
"@types/chai": "^4.3.9",
"@types/d3": "^7.4.2",
"@types/mocha": "^10.0.3",
"@types/sinon": "^10.0.20",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@types/sinon": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"babel-helper-modules": "^6.0.0",
"babel-loader": "^9.1.3",
"babel-plugin-add-module-exports": "^1.0.4",
Expand All @@ -154,7 +154,7 @@
"d3-polygon": "^3.0.1",
"docdash": "^2.0.2",
"dtslint": "^4.2.1",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"eslint-config-naver": "^2.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
Expand All @@ -181,12 +181,12 @@
"mocha": "^10.2.0",
"node-sass": "^9.0.0",
"regenerator-runtime": "^0.14.0",
"rollup": "^4.1.5",
"rollup": "^4.3.0",
"rollup-plugin-delete": "^2.0.0",
"sass-loader": "^13.3.2",
"semantic-release": "^22.0.6",
"semantic-release": "^22.0.7",
"simulant": "^0.2.2",
"sinon": "^17.0.0",
"sinon": "^17.0.1",
"string-replace-loader": "^3.1.0",
"style-loader": "^3.3.3",
"taffydb": "^2.7.3",
Expand Down
15 changes: 13 additions & 2 deletions src/ChartInternal/internals/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
*/
import {isArray, isValue, isFunction, isObjectType} from "../../module/util";
import {isArray, isValue, isFunction, isObjectType, isObject} from "../../module/util";
import type {AxisType} from "../../../types/types";

/**
Expand Down Expand Up @@ -65,7 +65,18 @@ export default {
dataLabelFormat(targetId: string): Function {
const $$ = this;
const dataLabels = $$.config.data_labels;
const defaultFormat = v => (isArray(v) ? v.join("~") : (isValue(v) ? +v : ""));
const defaultFormat = v => {
const delimiter = "~";
let res = v;

if (isArray(v)) {
res = v.join(delimiter);
} else if (isObject(v)) {
res = Object.values(v).join(delimiter);
}

return res;
};
let format = defaultFormat;

// find format according to axis id
Expand Down
44 changes: 36 additions & 8 deletions test/internals/text-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {select as d3Select} from "d3-selection";
import {format as d3Format} from "d3-format";
import util from "../assets/util";
import {$AXIS, $SHAPE, $TEXT} from "../../src/config/classes";
import {isArray, isNumber} from "../../src/module/util";
import {isArray, isNumber, isObject} from "../../src/module/util";

describe("TEXT", () => {
let chart;
Expand Down Expand Up @@ -436,11 +436,17 @@ describe("TEXT", () => {
[155, 130, 115],
[160, 135, 120],
],
["data2", [230, 340], 200, [-100, -50]]
["data2", [230, 340], 200, [-100, -50]],
["data3",
{high: 155, low: 145, mid: 150},
{high: 200, mid: 190, low: 150},
{high: 230, mid: 215, low: 200}
]
],
types: {
data1: "area-line-range",
data2: "bar"
data2: "bar",
data3: "area-line-range"
},
labels: {
colors: "black"
Expand All @@ -449,9 +455,15 @@ describe("TEXT", () => {
};
});

it("should locate data labels in correct position", () => {
it("should data labels rendered correctly", () => {
chart.$.text.texts.each(function(d) {
const text = isArray(d.value) ? d.value.join("~") : String(d.value);
let text = String(d.value);

if (isArray(d.value)) {
text = d.value.join("~");
} else if (isObject(d.value)) {
text = Object.values(d.value).join("~");
}

expect(this.textContent).to.be.equal(text);
});
Expand All @@ -461,16 +473,32 @@ describe("TEXT", () => {
args.data.labels.centered = true;

args.data.labels.format = function(value, id, index) {
return Array.isArray(value) ? value.join("-") : value;
let v = value;
const delimiter = "/";

if (Array.isArray(value)) {
v = value.join(delimiter);
} else if (typeof value === "object") {
v = Object.values(v).join(delimiter);
}

return v;
};
});

it("should locate data labels in correct position", () => {
it("should locate data labels in correct position and formatted correctly", () => {
const {$: {bar, text}} = chart;
const barText: number[] = [];
const delimiter = "/";

text.texts.each(function(d) {
const text = isArray(d.value) ? d.value.join("-") : String(d.value);
let text = String(d.value);

if (isArray(d.value)) {
text = d.value.join(delimiter);
} else if (isObject(d.value)) {
text = Object.values(d.value).join(delimiter);
}

expect(this.textContent).to.be.equal(text);

Expand Down
Loading

0 comments on commit 3f0689d

Please sign in to comment.