Skip to content

Commit

Permalink
[#933] [3.0] Chart - Axis Label show 옵션 추가 (#934)
Browse files Browse the repository at this point in the history
Co-authored-by: jinhee park <jinhee@ex-em.com>
  • Loading branch information
jhee564 and jhee564 authored Nov 12, 2021
1 parent 8c0d9f5 commit 9bc000c
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 149 deletions.
1 change: 1 addition & 0 deletions docs/views/barChart/api/barChart.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const chartData = {
##### labelStyle
| 이름 | 타입 | 디폴트 | 설명 | 종류(예시) |
|-----|------|-------|-----|-----|
| show | Boolean | true | label 표시 여부 | true / false |
| fontSize | Number | 12 | 글자 크기 | |
| color | Hex, RGB, RGBA Code(String) | '#25262E' | 글자 색상 | |
| fontFamily | String | 'Roboto' | 폰트 | |
Expand Down
1 change: 1 addition & 0 deletions docs/views/lineChart/api/lineChart.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const chartData =
##### labelStyle
| 이름 | 타입 | 디폴트 | 설명 | 종류(예시) |
|-----|------|-------|-----|-----|
| show | Boolean | true | label 표시 여부 | true / false |
| fontSize | Number | 12 | 글자 크기 | |
| color | Hex, RGB, RGBA Code(String) | '#25262E' | 글자 색상 | |
| fontFamily | String | 'Roboto' | 폰트 | |
Expand Down
1 change: 1 addition & 0 deletions docs/views/scatterChart/api/scatterChart.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const chartData =
##### labelStyle
| 이름 | 타입 | 디폴트 | 설명 | 종류(예시) |
|-----|------|-------|-----|-----|
| show | Boolean | true | label 표시 여부 | true / false |
| fontSize | Number | 12 | 글자 크기 | |
| color | Hex, RGB, RGBA Code(String) | '#25262E' | 글자 색상 | |
| fontFamily | String | 'Roboto' | 폰트 | |
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": "evui",
"version": "3.1.39",
"version": "3.1.40",
"description": "A EXEM Library project",
"author": "exem <dev_client@ex-em.com>",
"license": "MIT",
Expand Down
50 changes: 27 additions & 23 deletions src/components/chart/chart.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,38 +441,42 @@ class EvChart {
let lh = 0;

axesX.forEach((axis, index) => {
lw = range.x[index].size.width + labelBuffer.width;
lh = range.x[index].size.height + labelBuffer.height;
if (axis.labelStyle?.show) {
lw = range.x[index].size.width + labelBuffer.width;
lh = range.x[index].size.height + labelBuffer.height;

if (axis.position === 'bottom') {
if (lh > labelOffset.bottom) {
labelOffset.bottom = lh;
}
} else if (axis.position === 'top') {
if (lh > labelOffset.top) {
labelOffset.top = lh;
if (axis.position === 'bottom') {
if (lh > labelOffset.bottom) {
labelOffset.bottom = lh;
}
} else if (axis.position === 'top') {
if (lh > labelOffset.top) {
labelOffset.top = lh;
}
}
}

labelOffset.left = (lw / 2) > labelOffset.left ? (lw / 2) : labelOffset.left;
labelOffset.right = (lw / 2) > labelOffset.right ? (lw / 2) : labelOffset.right;
labelOffset.left = (lw / 2) > labelOffset.left ? (lw / 2) : labelOffset.left;
labelOffset.right = (lw / 2) > labelOffset.right ? (lw / 2) : labelOffset.right;
}
});

axesY.forEach((axis, index) => {
lw = Math.max(range.y[index].size.width + labelBuffer.width, 42 + labelBuffer.width);
if (axis.labelStyle?.show) {
lw = Math.max(range.y[index].size.width + labelBuffer.width, 42 + labelBuffer.width);

if (axis.position === 'left') {
if (lw > labelOffset.left) {
labelOffset.left = lw;
}
} else if (axis.position === 'right') {
if (lw > labelOffset.right) {
labelOffset.right = lw;
if (axis.position === 'left') {
if (lw > labelOffset.left) {
labelOffset.left = lw;
}
} else if (axis.position === 'right') {
if (lw > labelOffset.right) {
labelOffset.right = lw;
}
}
}

labelOffset.top = (lh / 2) > labelOffset.top ? (lh / 2) : labelOffset.top;
labelOffset.bottom = (lh / 2) > labelOffset.bottom ? (lh / 2) : labelOffset.bottom;
labelOffset.top = (lh / 2) > labelOffset.top ? (lh / 2) : labelOffset.top;
labelOffset.bottom = (lh / 2) > labelOffset.bottom ? (lh / 2) : labelOffset.bottom;
}
});

return labelOffset;
Expand Down
1 change: 1 addition & 0 deletions src/components/chart/helpers/helpers.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const AXIS_OPTION = {
interval: null,
decimalPoint: null,
labelStyle: {
show: true,
fontSize: 12,
color: '#25262E',
fontFamily: 'Roboto',
Expand Down
108 changes: 55 additions & 53 deletions src/components/chart/scale/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,69 +220,71 @@ class Scale {
return;
}

const labelGap = (endPoint - startPoint) / steps;
const ticks = [];
let labelCenter = null;
let linePosition = null;
if (this.labelStyle?.show) {
const labelGap = (endPoint - startPoint) / steps;
const ticks = [];
let labelCenter = null;
let linePosition = null;

ctx.strokeStyle = this.gridLineColor;
ctx.lineWidth = 1;
aliasPixel = Util.aliasPixel(ctx.lineWidth);

ctx.strokeStyle = this.gridLineColor;
ctx.lineWidth = 1;
aliasPixel = Util.aliasPixel(ctx.lineWidth);
let labelText;
for (let ix = 0; ix <= steps; ix++) {
ctx.beginPath();
ticks[ix] = axisMin + (ix * stepValue);

let labelText;
for (let ix = 0; ix <= steps; ix++) {
ctx.beginPath();
ticks[ix] = axisMin + (ix * stepValue);
labelCenter = Math.round(startPoint + (labelGap * ix));
linePosition = labelCenter + aliasPixel;
labelText = this.getLabelFormat(Math.min(axisMax, ticks[ix]));

labelCenter = Math.round(startPoint + (labelGap * ix));
linePosition = labelCenter + aliasPixel;
labelText = this.getLabelFormat(Math.min(axisMax, ticks[ix]));
let labelPoint;

let labelPoint;
if (this.type === 'x') {
labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
ctx.fillText(labelText, labelCenter, labelPoint);
if (options?.selectItem?.showLabelTip && hitInfo?.label && !this.options?.horizontal) {
const selectedLabel = this.getLabelFormat(
Math.min(axisMax, hitInfo.label + (0 * stepValue)),
);
if (selectedLabel === labelText) {
const height = Math.round(ctx.measureText(this.labelStyle?.fontSize).width);
Util.showLabelTip({
ctx: this.ctx,
width: Math.round(ctx.measureText(selectedLabel).width) + 10,
height,
x: labelCenter,
y: labelPoint + (height - 2),
borderRadius: 2,
arrowSize: 3,
text: labelText,
backgroundColor: options?.selectItem?.labelTipStyle?.backgroundColor,
textColor: options?.selectItem?.labelTipStyle?.textColor,
});
}
}
if (ix !== 0 && this.showGrid) {
ctx.moveTo(linePosition, offsetPoint);
ctx.lineTo(linePosition, offsetCounterPoint);
}
} else {
labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
ctx.fillText(labelText, labelPoint, labelCenter);

if (this.type === 'x') {
labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
ctx.fillText(labelText, labelCenter, labelPoint);
if (options?.selectItem?.showLabelTip && hitInfo?.label && !this.options?.horizontal) {
const selectedLabel = this.getLabelFormat(
Math.min(axisMax, hitInfo.label + (0 * stepValue)),
);
if (selectedLabel === labelText) {
const height = Math.round(ctx.measureText(this.labelStyle?.fontSize).width);
Util.showLabelTip({
ctx: this.ctx,
width: Math.round(ctx.measureText(selectedLabel).width) + 10,
height,
x: labelCenter,
y: labelPoint + (height - 2),
borderRadius: 2,
arrowSize: 3,
text: labelText,
backgroundColor: options?.selectItem?.labelTipStyle?.backgroundColor,
textColor: options?.selectItem?.labelTipStyle?.textColor,
});
if (ix === steps) {
linePosition += 1;
}
}
if (ix !== 0 && this.showGrid) {
ctx.moveTo(linePosition, offsetPoint);
ctx.lineTo(linePosition, offsetCounterPoint);
}
} else {
labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
ctx.fillText(labelText, labelPoint, labelCenter);

if (ix === steps) {
linePosition += 1;
if (ix !== 0 && this.showGrid) {
ctx.moveTo(offsetPoint, linePosition);
ctx.lineTo(offsetCounterPoint, linePosition);
}
}

if (ix !== 0 && this.showGrid) {
ctx.moveTo(offsetPoint, linePosition);
ctx.lineTo(offsetCounterPoint, linePosition);
}
ctx.stroke();
ctx.closePath();
}

ctx.stroke();
ctx.closePath();
}

// Draw plot lines and plot bands
Expand Down
Loading

0 comments on commit 9bc000c

Please sign in to comment.