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

1613 set 20 80 line texts position by percentagex value #1626

Merged
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 api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "14.15.0",
"version": "14.16.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "14.15.0",
"version": "14.16.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numbro from 'numbro';
import { IParetoChartConf } from '../type';
import { TLineDataItem } from './types';
import { formatPercentage } from './utils';
Expand Down Expand Up @@ -29,6 +30,16 @@ function getMarkLineLabel(conf: IParetoChartConf, percentage: IPercentage, count
return new Function(...names, `return \`${label_template}\`;`)(...vals);
}

function getAlignByX(indexPoistion: number) {
const v = Number(numbro(indexPoistion).format({ output: 'number', mantissa: 2 }));
if (v < 0.33) {
return 'left';
}
if (v > 0.66) {
return 'right';
}
return 'center';
}
export function getMarkLineAndArea(conf: IParetoChartConf, lineData: TLineDataItem[]) {
if (lineData.length === 0) {
return {};
Expand All @@ -40,8 +51,9 @@ export function getMarkLineAndArea(conf: IParetoChartConf, lineData: TLineDataIt
}

const match = lineData[i];
const indexPosition = (i + 1) / lineData.length;
const percentage = {
x: formatPercentage((i + 1) / lineData.length),
x: formatPercentage(indexPosition),
y: formatPercentage(match[1]),
};
const count = {
Expand Down Expand Up @@ -71,6 +83,8 @@ export function getMarkLineAndArea(conf: IParetoChartConf, lineData: TLineDataIt
},
label: {
formatter: getMarkLineLabel(conf, percentage, count),
position: 'end',
align: getAlignByX(indexPosition),
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "14.15.0",
"version": "14.16.0",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "14.15.0",
"version": "14.16.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "14.15.0",
"version": "14.16.0",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down