I'm creating a line (path) which changes color when it is clicked. In order to change color I'm adding a class
. This action will also act as switching the class from one path (line) to another.
Below is my working code.
public drawLines() {
this._containerSvg.append( 'line:defs' ).append( 'line:marker' )
.attr( 'id', 'triangle' )
.attr( 'refX', 6 )
.attr( 'refY', 6 )
.attr( 'markerWidth', 30 )
.attr( 'markerHeight', 30 )
.attr( 'markerUnits', 'userSpaceOnUse' )
.attr( 'orient', 'auto' )
.append( 'path' )
.attr( 'd', 'M 0 0 12 6 0 12 3 6' )
.style( 'fill', 'black' );
this._containerSvg.selectAll( 'line' )
.data( this._connectLines, ( line : Line ) => {
return line.id
} )
.enter()
.append( 'line' )
.attr( 'id', ( line : Line ) => line.id )
.attr( 'x1', ( line : Line ) => line.x1 )
.attr( 'y1', ( line : Line ) => line.y1 )
.attr( 'x2', ( line : Line ) => line.x2 )
.attr( 'y2', ( line : Line ) => line.y2 )
.style( 'stroke', 'black' )
.style( 'stroke-width', '4px' )
.style( 'cursor', 'pointer' )
.attr( 'marker-end', 'url(#triangle)' )
.on( 'click', ( line ) => {
this._selectedLine = line;
this.updateLines();
} );
}
updateLines() {
this._containerSvg.selectAll( 'line' )
.data( this._connectLines, ( line : Line ) => {
return line.id;
} )
.attr( 'x1', ( line : Line ) => line.x1 )
.attr( 'y1', ( line : Line ) => line.y1 )
.attr( 'x2', ( line : Line ) => line.x2 )
.attr( 'y2', ( line : Line ) => line.y2 )
.attr( 'class', ( line : Line ) => this._selectedLine === line ? 'selected' : '' )
}
CSS File.
svg line.selected {
stroke: green !important;
}
Whenever the line is selected it is changing it to green but not the arrow. How can I change the color of arrow as well when the line is selected?
Thanks in advance.