@@ -264,6 +264,74 @@ defmodule VegaLite.DataTest do
264
264
assert vl == Data . heatmap ( @ data , x: "height" , y: "weight" , color: "height" , text: "height" )
265
265
end
266
266
267
+ test "with text_color" do
268
+ vl =
269
+ Vl . new ( )
270
+ |> Vl . data_from_values ( @ data , only: [ "height" , "weight" ] )
271
+ |> Vl . layers ( [
272
+ Vl . new ( )
273
+ |> Vl . mark ( :rect )
274
+ |> Vl . encode_field ( :x , "height" , type: :nominal )
275
+ |> Vl . encode_field ( :y , "weight" , type: :nominal )
276
+ |> Vl . encode_field ( :color , "height" , type: :quantitative ) ,
277
+ Vl . new ( )
278
+ |> Vl . mark ( :text )
279
+ |> Vl . encode_field ( :x , "height" , type: :nominal )
280
+ |> Vl . encode_field ( :y , "weight" , type: :nominal )
281
+ |> Vl . encode_field ( :text , "height" , type: :quantitative )
282
+ |> Vl . encode_field ( :color , "height" , type: :quantitative )
283
+ ] )
284
+
285
+ assert vl ==
286
+ Data . heatmap ( @ data ,
287
+ x: "height" ,
288
+ y: "weight" ,
289
+ color: "height" ,
290
+ text: "height" ,
291
+ text_color: "height"
292
+ )
293
+ end
294
+
295
+ test "with text_color with condition" do
296
+ vl =
297
+ Vl . new ( )
298
+ |> Vl . data_from_values ( @ data , only: [ "height" , "weight" ] )
299
+ |> Vl . layers ( [
300
+ Vl . new ( )
301
+ |> Vl . mark ( :rect )
302
+ |> Vl . encode_field ( :x , "height" , type: :nominal )
303
+ |> Vl . encode_field ( :y , "weight" , type: :nominal )
304
+ |> Vl . encode_field ( :color , "height" , type: :quantitative ) ,
305
+ Vl . new ( )
306
+ |> Vl . mark ( :text )
307
+ |> Vl . encode_field ( :x , "height" , type: :nominal )
308
+ |> Vl . encode_field ( :y , "weight" , type: :nominal )
309
+ |> Vl . encode_field ( :text , "height" , type: :quantitative )
310
+ |> Vl . encode_field ( :color , "height" ,
311
+ type: :quantitative ,
312
+ condition: [
313
+ [ test: "datum['height'] < 0" , value: :white ] ,
314
+ [ test: "datum['height'] >= 0" , value: :black ]
315
+ ]
316
+ )
317
+ ] )
318
+
319
+ assert vl ==
320
+ Data . heatmap ( @ data ,
321
+ x: "height" ,
322
+ y: "weight" ,
323
+ color: "height" ,
324
+ text: "height" ,
325
+ text_color: [
326
+ field: "height" ,
327
+ condition: [
328
+ [ test: "datum['height'] < 0" , value: :white ] ,
329
+ [ test: "datum['height'] >= 0" , value: :black ]
330
+ ]
331
+ ]
332
+ )
333
+ end
334
+
267
335
test "with title and extra fields" do
268
336
vl =
269
337
Vl . new ( title: "Heatmap" )
@@ -450,6 +518,74 @@ defmodule VegaLite.DataTest do
450
518
)
451
519
end
452
520
521
+ test "with text_color" do
522
+ vl =
523
+ Vl . new ( )
524
+ |> Vl . data_from_values ( @ data , only: [ "height" , "weight" ] )
525
+ |> Vl . layers ( [
526
+ Vl . new ( )
527
+ |> Vl . mark ( :rect )
528
+ |> Vl . encode_field ( :x , "height" , type: :quantitative , bin: true )
529
+ |> Vl . encode_field ( :y , "weight" , type: :quantitative , bin: true )
530
+ |> Vl . encode_field ( :color , "height" , type: :quantitative , aggregate: :count ) ,
531
+ Vl . new ( )
532
+ |> Vl . mark ( :text )
533
+ |> Vl . encode_field ( :x , "height" , type: :quantitative , bin: true )
534
+ |> Vl . encode_field ( :y , "weight" , type: :quantitative , bin: true )
535
+ |> Vl . encode_field ( :text , "height" , type: :quantitative , aggregate: :count )
536
+ |> Vl . encode_field ( :color , "height" , type: :quantitative )
537
+ ] )
538
+
539
+ assert vl ==
540
+ Data . density_heatmap ( @ data ,
541
+ x: "height" ,
542
+ y: "weight" ,
543
+ color: "height" ,
544
+ text: "height" ,
545
+ text_color: "height"
546
+ )
547
+ end
548
+
549
+ test "with text_color with condition" do
550
+ vl =
551
+ Vl . new ( )
552
+ |> Vl . data_from_values ( @ data , only: [ "height" , "weight" ] )
553
+ |> Vl . layers ( [
554
+ Vl . new ( )
555
+ |> Vl . mark ( :rect )
556
+ |> Vl . encode_field ( :x , "height" , type: :quantitative , bin: true )
557
+ |> Vl . encode_field ( :y , "weight" , type: :quantitative , bin: true )
558
+ |> Vl . encode_field ( :color , "height" , type: :quantitative , aggregate: :count ) ,
559
+ Vl . new ( )
560
+ |> Vl . mark ( :text )
561
+ |> Vl . encode_field ( :x , "height" , type: :quantitative , bin: true )
562
+ |> Vl . encode_field ( :y , "weight" , type: :quantitative , bin: true )
563
+ |> Vl . encode_field ( :text , "height" , type: :quantitative , aggregate: :count )
564
+ |> Vl . encode_field ( :color , "height" ,
565
+ type: :quantitative ,
566
+ condition: [
567
+ [ test: "datum['height'] < 0" , value: :white ] ,
568
+ [ test: "datum['height'] >= 0" , value: :black ]
569
+ ]
570
+ )
571
+ ] )
572
+
573
+ assert vl ==
574
+ Data . density_heatmap ( @ data ,
575
+ x: "height" ,
576
+ y: "weight" ,
577
+ color: "height" ,
578
+ text: "height" ,
579
+ text_color: [
580
+ field: "height" ,
581
+ condition: [
582
+ [ test: "datum['height'] < 0" , value: :white ] ,
583
+ [ test: "datum['height'] >= 0" , value: :black ]
584
+ ]
585
+ ]
586
+ )
587
+ end
588
+
453
589
test "with specified aggregate for text" do
454
590
vl =
455
591
Vl . new ( )
0 commit comments