@@ -15,6 +15,8 @@ import {
1515import { CLASS_NAMES } from '../constant' ;
1616import type { RequiredArcAxisStyleProps , RequiredAxisStyleProps , RequiredLinearAxisStyleProps } from '../types' ;
1717import { getLineAngle , getLineTangentVector } from './utils' ;
18+ import { applyClassName , getAxisClassName } from '../utils/classname' ;
19+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map' ;
1820
1921type LineDatum = {
2022 line : [ Vector2 , Vector2 ] ;
@@ -97,18 +99,21 @@ function renderArc(
9799 style : RequiredArcAxisStyleProps ,
98100 animate : StandardAnimationOption
99101) {
100- const { startAngle, endAngle, center, radius } = attr ;
102+ const { startAngle, endAngle, center, radius, classNamePrefix } = attr ;
101103
102104 return container
103105 . selectAll ( CLASS_NAMES . line . class )
104106 . data ( [ { d : getArcPath ( startAngle , endAngle , ...center , radius ) } ] , ( d , i ) => i )
105107 . join (
106- ( enter ) =>
107- enter
108+ ( enter ) => {
109+ const line = enter
108110 . append ( 'path' )
109111 . attr ( 'className' , CLASS_NAMES . line . name )
110112 . styles ( attr )
111- . styles ( { d : ( d : any ) => d . d } ) ,
113+ . styles ( { d : ( d : any ) => d . d } ) ;
114+ applyClassName ( line , CLASS_NAMES . line , CLASSNAME_SUFFIX_MAP . line , classNamePrefix ) ;
115+ return line ;
116+ } ,
112117 ( update ) =>
113118 update
114119 . transition ( function ( ) {
@@ -158,22 +163,51 @@ function renderLinear(
158163 style : RequiredLinearAxisStyleProps ,
159164 animate : StandardAnimationOption
160165) {
161- const { showTrunc, startPos, endPos, truncRange, lineExtension } = attr ;
166+ const { showTrunc, startPos, endPos, truncRange, lineExtension, classNamePrefix } = attr ;
162167 const [ [ x1 , y1 ] , [ x2 , y2 ] ] = [ startPos , endPos ] ;
163168 const [ ox1 , oy1 , ox2 , oy2 ] = lineExtension ? extendLine ( startPos , endPos , lineExtension ) : new Array ( 4 ) . fill ( 0 ) ;
164169 const renderLine = ( data : LineDatum [ ] ) => {
165170 return container
166171 . selectAll ( CLASS_NAMES . line . class )
167172 . data ( data , ( d , i ) => i )
168173 . join (
169- ( enter ) =>
170- enter
174+ ( enter ) => {
175+ const lines = enter
171176 . append ( 'line' )
172- . attr ( 'className' , ( d : LineDatum ) => `${ CLASS_NAMES . line . name } ${ d . className } ` )
173177 . styles ( style )
174178 . transition ( function ( d : LineDatum ) {
175179 return transition ( this , getLinePath ( d . line ) , false ) ;
176- } ) ,
180+ } ) ;
181+ // Set className with appropriate logic for line elements
182+ lines . attr ( 'className' , ( d : LineDatum ) => {
183+ if ( ! classNamePrefix ) {
184+ return `${ CLASS_NAMES . line . name } ${ d . className } ` ;
185+ }
186+ const baseLineClassName = getAxisClassName (
187+ CLASS_NAMES . line . name ,
188+ CLASSNAME_SUFFIX_MAP . line ,
189+ classNamePrefix
190+ ) ;
191+ if ( d . className === CLASS_NAMES . lineFirst . name ) {
192+ const specificClassName = getAxisClassName (
193+ CLASS_NAMES . lineFirst . name ,
194+ CLASSNAME_SUFFIX_MAP . lineFirst ,
195+ classNamePrefix
196+ ) ;
197+ return `${ baseLineClassName } ${ specificClassName } ` ;
198+ }
199+ if ( d . className === CLASS_NAMES . lineSecond . name ) {
200+ const specificClassName = getAxisClassName (
201+ CLASS_NAMES . lineSecond . name ,
202+ CLASSNAME_SUFFIX_MAP . lineSecond ,
203+ classNamePrefix
204+ ) ;
205+ return `${ baseLineClassName } ${ specificClassName } ` ;
206+ }
207+ return baseLineClassName ;
208+ } ) ;
209+ return lines ;
210+ } ,
177211 ( update ) =>
178212 update . styles ( style ) . transition ( function ( { line } : LineDatum ) {
179213 return transition ( this , getLinePath ( line ) , animate . update ) ;
@@ -228,9 +262,13 @@ function renderAxisArrow(
228262 const { showArrow, showTrunc, lineArrow, lineArrowOffset, lineArrowSize } = attr ;
229263
230264 let shapeToAddArrow : Selection ;
231- if ( type === 'arc' ) shapeToAddArrow = container . select ( CLASS_NAMES . line . class ) ;
232- else if ( showTrunc ) shapeToAddArrow = container . select ( CLASS_NAMES . lineSecond . class ) ;
233- else shapeToAddArrow = container . select ( CLASS_NAMES . line . class ) ;
265+ if ( type === 'arc' ) {
266+ shapeToAddArrow = container . select ( CLASS_NAMES . line . class ) ;
267+ } else if ( showTrunc ) {
268+ shapeToAddArrow = container . select ( CLASS_NAMES . lineSecond . class ) ;
269+ } else {
270+ shapeToAddArrow = container . select ( CLASS_NAMES . line . class ) ;
271+ }
234272 if ( ! showArrow || ! lineArrow || ( attr . type === 'arc' && isCircle ( attr . startAngle , attr . endAngle ) ) ) {
235273 const node = shapeToAddArrow . node < Line > ( ) ;
236274 if ( node ) node . style . markerEnd = undefined ;
0 commit comments