Skip to content

Commit

Permalink
test: resolve boxSeriesData types
Browse files Browse the repository at this point in the history
  • Loading branch information
jungeun-cho authored and jung-han committed Feb 25, 2021
1 parent d9a9df3 commit 28d5da9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
10 changes: 8 additions & 2 deletions apps/chart/src/charts/barChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ import * as labelBrush from '@src/brushes/label';
import * as dataLabelBrush from '@src/brushes/dataLabel';
import * as exportMenuBrush from '@src/brushes/exportMenu';

import { BoxSeriesDataType, BarChartOptions, BoxSeriesInput, BoxSeriesData } from '@t/options';
import {
BoxSeriesDataType,
BarChartOptions,
BoxSeriesInput,
BoxSeriesData,
BoxSeriesType,
} from '@t/options';

export interface BarChartProps {
el: HTMLElement;
Expand Down Expand Up @@ -119,7 +125,7 @@ export default class BarChart extends Chart<BarChartOptions> {
el,
options,
series: {
bar: data.series,
bar: data.series as BoxSeriesType<BoxSeriesDataType>[],
},
categories: data.categories,
modules: [stackSeriesData, dataRange, scale, axes, plot],
Expand Down
10 changes: 8 additions & 2 deletions apps/chart/src/charts/columnChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import * as labelBrush from '@src/brushes/label';
import * as exportMenuBrush from '@src/brushes/exportMenu';
import * as dataLabelBrush from '@src/brushes/dataLabel';

import { ColumnChartOptions, BoxSeriesData, BoxSeriesDataType, BoxSeriesInput } from '@t/options';
import {
ColumnChartOptions,
BoxSeriesData,
BoxSeriesDataType,
BoxSeriesInput,
BoxSeriesType,
} from '@t/options';

export interface ColumnChartProps {
el: HTMLElement;
Expand Down Expand Up @@ -119,7 +125,7 @@ export default class ColumnChart extends Chart<ColumnChartOptions> {
el,
options,
series: {
column: data.series,
column: data.series as BoxSeriesType<BoxSeriesDataType>[],
},
categories: data.categories,
modules: [stackSeriesData, dataRange, scale, axes, plot],
Expand Down
26 changes: 14 additions & 12 deletions apps/chart/src/component/boxSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function isLeftBottomSide(seriesIndex: number) {
return !!(seriesIndex % 2);
}

function calculateBarLength(value: BoxSeriesDataType, min: number, max: number) {
function calculateBarLength(value: Exclude<BoxSeriesDataType, null>, min: number, max: number) {
if (isRangeValue(value)) {
let [start, end] = value;

Expand Down Expand Up @@ -540,23 +540,25 @@ export default class BoxSeries extends Component {

seriesData.forEach(({ data, name, color }) => {
data.forEach((value, dataIndex) => {
const barLength = this.makeBarLength(value, renderOptions);

if (isNumber(barLength)) {
tooltipData.push({
label: name,
color,
value: this.getTooltipValue(value),
category: categories.length ? categories[dataIndex] : '',
});
if (!isNull(value)) {
const barLength = this.makeBarLength(value, renderOptions);

if (isNumber(barLength)) {
tooltipData.push({
label: name,
color,
value: this.getTooltipValue(value),
category: categories.length ? categories[dataIndex] : '',
});
}
}
});
});

return tooltipData;
}

private getTooltipValue(value: BoxSeriesDataType): string | number {
private getTooltipValue(value: Exclude<BoxSeriesDataType, null>): string | number {
return isRangeValue(value) ? `${value[0]} ~ ${value[1]}` : value;
}

Expand Down Expand Up @@ -628,7 +630,7 @@ export default class BoxSeries extends Component {

getStartPosition(
barLength: number,
value: BoxSeriesDataType,
value: Exclude<BoxSeriesDataType, null>,
renderOptions: RenderOptions,
isLBSideWithDiverging: boolean
): number {
Expand Down
6 changes: 3 additions & 3 deletions apps/chart/stories/column.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export const positiveAndNegativeWithMinMax = () => {
};

export const range = () => {
const { el } = createChart(temperatureRangeData);
const { el } = createChart(temperatureRangeData as BoxSeriesData);

return el;
};

export const rangeWithMinMax = () => {
const { el } = createChart(temperatureRangeData, {
const { el } = createChart(temperatureRangeData as BoxSeriesData, {
yAxis: {
scale: {
min: -4,
Expand All @@ -163,7 +163,7 @@ export const rangeWithMinMax = () => {
};

export const rangeWithDataLabels = () => {
const { el } = createChart(temperatureRangeData, {
const { el } = createChart(temperatureRangeData as BoxSeriesData, {
series: { dataLabels: { visible: true } },
});

Expand Down

0 comments on commit 28d5da9

Please sign in to comment.