Skip to content

Commit

Permalink
Minor pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
artemipanchuk committed Dec 27, 2023
1 parent 48f7827 commit 3a1d8b1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export {CHARTKIT_SCROLLABLE_NODE_CLASSNAME} from './common';

export * from './widget-data';
20 changes: 20 additions & 0 deletions src/constants/widget-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export enum DashStyle {
Dash = 'Dash',
DashDot = 'DashDot',
Dot = 'Dot',
LongDash = 'LongDash',
LongDashDot = 'LongDashDot',
LongDashDotDot = 'LongDashDotDot',
ShortDash = 'ShortDash',
ShortDashDot = 'ShortDashDot',
ShortDashDotDot = 'ShortDashDotDot',
ShortDot = 'ShortDot',
Solid = 'Solid',
}

export enum LineCap {
Butt = 'butt',
Round = 'round',
Square = 'square',
None = 'none',
}
3 changes: 2 additions & 1 deletion src/plugins/d3/examples/line/Shapes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import {ChartKitWidgetData, LineSeriesData, LineSeries, DashStyle} from '../../../../types';
import {ChartKitWidgetData, LineSeriesData, LineSeries} from '../../../../types';
import {ChartKit} from '../../../../components/ChartKit';
import nintendoGames from '../../examples/nintendoGames';
import {DashStyle} from '../../../../constants';

const SHAPES = {
[DashStyle.Solid]: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {ScaleOrdinal} from 'd3';
import get from 'lodash/get';
import merge from 'lodash/merge';

import {DashStyle, LineCap} from '../../../../../constants';

import {
ChartKitWidgetSeries,
ChartKitWidgetSeriesOptions,
DashStyle,
LineCap,
LineSeries,
RectLegendSymbolOptions,
} from '../../../../../types';
Expand Down Expand Up @@ -121,7 +121,7 @@ export function prepareLineSeries(args: PrepareLineSeriesArgs) {
},
marker: prepareMarker(series, seriesOptions),
dashStyle,
linecap: prepareLinecap(dashStyle, series, seriesOptions),
linecap: prepareLinecap(dashStyle as DashStyle, series, seriesOptions),
};

return prepared;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/d3/renderer/hooks/useShapes/line/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {PreparedLineSeries} from '../../useSeries/types';
import {DashStyle, LineCap, LineSeriesData} from '../../../../../../types';
import {LineSeriesData} from '../../../../../../types';
import {LabelData} from '../../../types';
import {DashStyle, LineCap} from '../../../../../../constants';

export type PointData = {
x: number;
Expand Down
12 changes: 7 additions & 5 deletions src/plugins/d3/renderer/hooks/useShapes/scatter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ export function ScatterSeriesShape(props: ScatterSeriesShapeProps) {
const inactiveOptions = get(seriesOptions, 'scatter.states.inactive');

const selection = svgElement
.selectAll(`circle`)
.selectAll('point')
.data(preparedData, shapeKey)
.join(
(enter) => enter.append('circle').attr('class', b('point')),
(enter) => enter.append('rect').attr('class', b('point')),
(update) => update,
(exit) => exit.remove(),
)
.attr('fill', (d) => d.data.color || d.series.color || '')
.attr('r', (d) => d.data.radius || DEFAULT_SCATTER_POINT_RADIUS)
.attr('cx', (d) => d.cx)
.attr('cy', (d) => d.cy);
// .attr('r', (d) => d.data.radius || DEFAULT_SCATTER_POINT_RADIUS)
.attr('x', (d) => d.cx)
.attr('y', (d) => d.cy)
.attr('width', () => DEFAULT_SCATTER_POINT_RADIUS)
.attr('height', () => DEFAULT_SCATTER_POINT_RADIUS);

svgElement
.on('mousemove', (e) => {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/d3/renderer/hooks/useShapes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type {BaseType, ScaleBand, ScaleLinear, ScaleTime} from 'd3';
import {select} from 'd3';
import get from 'lodash/get';

import type {BasicInactiveState, DashStyle} from '../../../../../types';
import type {BasicInactiveState} from '../../../../../types';
import {getDataCategoryValue} from '../../utils';
import type {ChartScale} from '../useAxisScales';
import type {PreparedAxis} from '../useChartOptions/types';

import type {PreparedLineData} from './line/types';
import type {PreparedScatterData} from './scatter';
import {DashStyle} from '../../../../../constants';

export function getXValue(args: {
point: {x?: number | string};
xAxis: PreparedAxis;
Expand Down
2 changes: 1 addition & 1 deletion src/types/widget-data/line.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';
import type {PointMarkerOptions} from './marker';
import type {DashStyle, LineCap} from './series';
import {DashStyle, LineCap} from '../../constants';

export type LineSeriesData<T = any> = BaseSeriesData<T> & {
/**
Expand Down
30 changes: 5 additions & 25 deletions src/types/widget-data/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {BarYSeries, BarYSeriesData} from './bar-y';
import type {PointMarkerOptions, PointMarkerHalo} from './marker';
import type {AreaSeries, AreaSeriesData} from './area';

import {DashStyle, LineCap} from '../../constants';

export type ChartKitWidgetSeries<T = any> =
| ScatterSeries<T>
| PieSeries<T>
Expand All @@ -27,27 +29,6 @@ export type DataLabelRendererData<T = any> = {
data: ChartKitWidgetSeriesData<T>;
};

export enum DashStyle {
Dash = 'Dash',
DashDot = 'DashDot',
Dot = 'Dot',
LongDash = 'LongDash',
LongDashDot = 'LongDashDot',
LongDashDotDot = 'LongDashDotDot',
ShortDash = 'ShortDash',
ShortDashDot = 'ShortDashDot',
ShortDashDotDot = 'ShortDashDotDot',
ShortDot = 'ShortDot',
Solid = 'Solid',
}

export enum LineCap {
Butt = 'butt',
Round = 'round',
Square = 'square',
None = 'none',
}

type BasicHoverState = {
/**
* Enable separate styles for the hovered series.
Expand Down Expand Up @@ -199,14 +180,13 @@ export type ChartKitWidgetSeriesOptions = {
*
* @default 'Solid'
* */
dashStyle?: DashStyle;
dashStyle?: `${DashStyle}`;

/** Options for line cap style
*
* @default 'round' when dashStyle is 'solid'
* @default 'none' when dashStyle is not 'solid'
* @default 'round' when dashStyle is not 'solid', 'none' when dashStyle is not 'solid'
* */
linecap?: LineCap;
linecap?: `${LineCap}`;
};
area?: {
/** Pixel width of the graph line.
Expand Down

0 comments on commit 3a1d8b1

Please sign in to comment.