@@ -184,25 +184,35 @@ var animint = function (to_select, json_file) {
184184 // geom. This is a hack and should be removed when we implement
185185 // the selected.color, selected.size, etc aesthetics.
186186 //
187- // 2022.08.01 update: get rid of the hack of "rect stroke" to
188- // implement a general function for alpha_off, color_off.
187+ // 2022.08.01 update: get rid of the hack of "rect stroke" to
188+ // implement a general function for alpha_off, color_off.
189189 // In order to have multiple styles functioning together
190- // so here use array to store the styles.
190+ // so here use array to store the styles.
191191 // Default using alpha/opacity style, execpt rect/tile geom
192192 // rect/tile geom default using stroke style
193+ const checkProperty = ( prop ) =>
194+ g_info . params . hasOwnProperty ( prop ) || g_info . aes . hasOwnProperty ( prop ) ;
195+
193196 let select_styles = [ ] ;
194- let has_colour_off = g_info . params . hasOwnProperty ( "colour_off" ) || g_info . aes . hasOwnProperty ( "colour_off" ) ;
195- let has_alpha_off = g_info . params . hasOwnProperty ( "alpha_off" ) || g_info . aes . hasOwnProperty ( "alpha_off" ) ;
196- if ( has_colour_off || g_info . geom == "rect" ) {
197- select_styles . push ( "stroke" ) ;
198- }
199- if ( has_alpha_off ) {
200- select_styles . push ( "opacity" ) ;
201- }
202- if ( ! has_colour_off && ! has_alpha_off && ! select_styles . length ) {
203- select_styles = [ "opacity" ] ;
197+ const has_colour_off = checkProperty ( 'colour_off' ) ;
198+ const has_alpha_off = checkProperty ( 'alpha_off' ) ;
199+ const has_fill_off = checkProperty ( 'fill_off' ) ;
200+
201+ if ( has_colour_off || g_info . geom === 'rect' ) {
202+ select_styles . push ( 'stroke' ) ;
203+ }
204+ if ( has_alpha_off ) {
205+ select_styles . push ( 'opacity' ) ;
204206 }
207+ if ( has_fill_off ) {
208+ select_styles . push ( 'fill' ) ;
209+ }
210+ if ( ! select_styles . length ) {
211+ select_styles = [ 'opacity' ] ;
212+ }
213+
205214 g_info . select_style = select_styles ;
215+
206216 // Determine if data will be an object or an array.
207217 if ( g_info . geom in data_object_geoms ) {
208218 g_info . data_is_object = true ;
@@ -228,8 +238,8 @@ var animint = function (to_select, json_file) {
228238 g_info . common_tsv = common_tsv ;
229239 var common_path = getTSVpath ( common_tsv ) ;
230240 d3 . tsv ( common_path , function ( error , response ) {
231- var converted = convert_R_types ( response , g_info . types ) ;
232- g_info . data [ common_tsv ] = nest_by_group . map ( converted ) ;
241+ var converted = convert_R_types ( response , g_info . types ) ;
242+ g_info . data [ common_tsv ] = nest_by_group . map ( converted ) ;
233243 } ) ;
234244 } else {
235245 g_info . common_tsv = null ;
@@ -1184,6 +1194,16 @@ var animint = function (to_select, json_file) {
11841194 fill = g_info . params . colour ;
11851195 }
11861196
1197+ const get_fill_off = function ( d ) {
1198+ let off_fill ;
1199+ if ( aes . hasOwnProperty ( "fill_off" ) && d . hasOwnProperty ( "fill_off" ) ) {
1200+ off_fill = d [ "fill_off" ] ;
1201+ } else if ( g_info . params . hasOwnProperty ( "fill_off" ) ) {
1202+ off_fill = g_info . params . fill_off ;
1203+ }
1204+ return off_fill ;
1205+ } ;
1206+
11871207 // For aes(hjust) the compiler should make an "anchor" column.
11881208 var text_anchor = "middle" ;
11891209 if ( g_info . params . hasOwnProperty ( "anchor" ) ) {
@@ -1219,6 +1239,9 @@ var animint = function (to_select, json_file) {
12191239 if ( ! g_info . select_style . includes ( "opacity" ) ) {
12201240 e . style ( "opacity" , get_alpha ) ;
12211241 }
1242+ if ( ! g_info . select_style . includes ( "fill" ) ) {
1243+ e . style ( "fill" , get_fill ) ;
1244+ }
12221245 } ;
12231246 if ( g_info . data_is_object ) {
12241247
@@ -1487,7 +1510,6 @@ var animint = function (to_select, json_file) {
14871510 eActions = function ( e ) {
14881511 e . attr ( "x" , toXY ( "x" , "x" ) )
14891512 . attr ( "y" , toXY ( "y" , "y" ) )
1490- . style ( "fill" , get_colour )
14911513 . attr ( "font-size" , get_size )
14921514 . style ( "text-anchor" , get_text_anchor )
14931515 . attr ( "transform" , get_angle )
@@ -1503,7 +1525,6 @@ var animint = function (to_select, json_file) {
15031525 e . attr ( "cx" , toXY ( "x" , "x" ) )
15041526 . attr ( "cy" , toXY ( "y" , "y" ) )
15051527 . attr ( "r" , get_size )
1506- . style ( "fill" , get_fill )
15071528 . style ( "stroke-width" , get_stroke_width ) ;
15081529 select_style_fun ( g_info , e ) ;
15091530 } ;
@@ -1518,7 +1539,6 @@ var animint = function (to_select, json_file) {
15181539 } )
15191540 . attr ( "y" , scales . y . range ( ) [ 1 ] )
15201541 . attr ( "height" , scales . y . range ( ) [ 0 ] - scales . y . range ( ) [ 1 ] )
1521- . style ( "fill" , get_fill )
15221542 . style ( "stroke-dasharray" , get_dasharray )
15231543 . style ( "stroke-width" , get_size ) ;
15241544 select_style_fun ( g_info , e ) ;
@@ -1534,7 +1554,6 @@ var animint = function (to_select, json_file) {
15341554 } )
15351555 . attr ( "x" , scales . x . range ( ) [ 0 ] )
15361556 . attr ( "width" , scales . x . range ( ) [ 1 ] - scales . x . range ( ) [ 0 ] )
1537- . style ( "fill" , get_fill )
15381557 . style ( "stroke-dasharray" , get_dasharray )
15391558 . style ( "stroke-width" , get_size ) ;
15401559 select_style_fun ( g_info , e ) ;
@@ -1560,7 +1579,6 @@ var animint = function (to_select, json_file) {
15601579 } )
15611580 . style ( "stroke-dasharray" , get_dasharray )
15621581 . style ( "stroke-width" , get_size )
1563- . style ( "fill" , get_fill ) ;
15641582 select_style_fun ( g_info , e ) ;
15651583 } ;
15661584 eAppend = "rect" ;
@@ -1626,7 +1644,6 @@ var animint = function (to_select, json_file) {
16261644 } )
16271645 . style ( "stroke-dasharray" , get_dasharray )
16281646 . style ( "stroke-width" , get_size )
1629- . style ( "fill" , get_fill ) ;
16301647 select_style_fun ( g_info , e ) ;
16311648 e . append ( "line" )
16321649 . attr ( "x1" , function ( d ) {
@@ -1659,11 +1676,13 @@ var animint = function (to_select, json_file) {
16591676 var selected_funs = function ( style_name , select_fun ) {
16601677 style_on_funs = {
16611678 "opacity" : get_alpha ,
1662- "stroke" : get_colour
1679+ "stroke" : get_colour ,
1680+ "fill" : get_fill
16631681 } ;
16641682 style_off_funs = {
16651683 "opacity" : get_alpha_off ,
1666- "stroke" : get_colour_off
1684+ "stroke" : get_colour_off ,
1685+ "fill" : get_fill_off
16671686 } ;
16681687 if ( select_fun == "mouseout" ) {
16691688 return function ( d ) {
@@ -1752,8 +1771,13 @@ var animint = function (to_select, json_file) {
17521771 } ) ;
17531772 }
17541773 } else { //has neither clickSelects nor clickSelects.variable.
1755- elements . style ( "opacity" , get_alpha )
1756- if ( g_info . geom != "text" ) {
1774+ elements . style ( "opacity" , get_alpha ) ;
1775+ // geom_segment/linerange/hline/vline no `stroke` with no clickSelects
1776+ const excludedGeoms = [ "segment" , "linerange" , "hline" , "vline" ] ;
1777+ if ( ! excludedGeoms . includes ( g_info . geom ) ) {
1778+ elements . style ( "fill" , get_fill ) ;
1779+ }
1780+ if ( g_info . geom != "text" ) { // geom_text no `stroke` with no clickSelects
17571781 elements . style ( "stroke" , get_colour ) ;
17581782 }
17591783 }
0 commit comments