-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
regressions.ts
3769 lines (3092 loc) · 121 KB
/
regressions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sinon from "sinon"
import {expect, expect_condition, expect_not_null} from "../unit/assertions"
import {display, fig, row, column, grid, DelayedInternalProvider} from "./_util"
import {PlotActions, actions, xy, tap, press, mouse_enter, mouse_down, mouse_click} from "../interactive"
import type {ArrowHead, Image, Line, BasicTickFormatter} from "@bokehjs/models"
import {
Arrow, NormalHead, OpenHead,
BoxAnnotation, LabelSet, ColorBar, Slope, Span, Whisker,
Range1d, DataRange1d, FactorRange,
ColumnDataSource, CDSView, BooleanFilter, IndexFilter, Selection,
LinearAxis, CategoricalAxis,
GlyphRenderer, GraphRenderer, GridBox,
Circle, Quad, MultiLine, Scatter, Text,
StaticLayoutProvider,
LinearColorMapper,
Plot,
TeX,
Toolbar, ToolProxy, PanTool, PolySelectTool, LassoSelectTool, HoverTool, ZoomInTool, ZoomOutTool, RangeTool, WheelPanTool,
TileRenderer, WMTSTileSource,
ImageURLTexture,
Row, Column,
Pane,
Tabs, TabPanel,
FixedTicker,
Jitter,
ParkMillerLCG,
GridPlot,
Tooltip,
Node, Indexed,
} from "@bokehjs/models"
import {
InlineStyleSheet,
} from "@bokehjs/models/dom"
import {
Button, Toggle, Select, MultiSelect, MultiChoice, RadioGroup, RadioButtonGroup,
Div, TextInput, DatePicker, AutocompleteInput,
} from "@bokehjs/models/widgets"
import {DataTable, TableColumn, DateFormatter} from "@bokehjs/models/widgets/tables"
import type {Factor} from "@bokehjs/models/ranges/factor_range"
import type {Color, Arrayable} from "@bokehjs/core/types"
import type {LineDash, Location, OutputBackend} from "@bokehjs/core/enums"
import {Anchor, MarkerType} from "@bokehjs/core/enums"
import {subsets, tail} from "@bokehjs/core/util/iterator"
import {isArray, isPlainObject} from "@bokehjs/core/util/types"
import {range, linspace} from "@bokehjs/core/util/array"
import {ndarray} from "@bokehjs/core/util/ndarray"
import {Random} from "@bokehjs/core/util/random"
import {Matrix} from "@bokehjs/core/util/matrix"
import {paint, delay} from "@bokehjs/core/util/defer"
import {encode_rgba} from "@bokehjs/core/util/color"
import {Figure, figure, show} from "@bokehjs/api/plotting"
import {Spectral3, Spectral11, turbo, plasma} from "@bokehjs/api/palettes"
import type {Keys} from "@bokehjs/core/dom"
import {div} from "@bokehjs/core/dom"
import type {LRTB} from "@bokehjs/core/util/bbox"
import {sprintf} from "@bokehjs/core/util/templating"
import {assert} from "@bokehjs/core/util/assert"
import {MathTextView} from "@bokehjs/models/text/math_text"
import {FigureView} from "@bokehjs/models/plots/figure"
import {gridplot} from "@bokehjs/api/gridplot"
import {f} from "@bokehjs/api/expr"
import {np} from "@bokehjs/api/linalg"
import {open_picker} from "./widgets"
function svg_data_url(svg: string): string {
return `data:image/svg+xml;utf-8,${svg}`
}
function scalar_image(N: number = 100) {
const x = linspace(0, 10, N)
const y = linspace(0, 10, N)
const d = new Float64Array(N*N)
const {sin, cos} = Math
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
d[i*N + j] = sin(x[i])*cos(y[j])
}
}
return ndarray(d, {dtype: "float64", shape: [N, N]})
}
function rgba_image() {
const N = 20
const d = new Uint32Array(N*N) // TODO: doesn't allow Uint8Array[N, N, 4]
const dv = new DataView(d.buffer)
const {trunc} = Math
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
const r = trunc(i/N*255)
const g = 158
const b = trunc(j/N*255)
const a = 255
dv.setUint32(4*(i*N + j), encode_rgba([r, g, b, a]))
}
}
return ndarray(d, {dtype: "uint32", shape: [N, N]})
}
function svg_image() {
return svg_data_url(`\
<svg version="1.1" viewBox="0 0 2 2" xmlns="http://www.w3.org/2000/svg">
<circle cx="1" cy="1" r="1" fill="blue" />
</svg>
`)
}
describe("Bug", () => {
describe("in issue #9879", () => {
it("disallows to change FactorRange to a lower dimension with a different number of factors", async () => {
const p = fig([200, 200], {
x_range: new FactorRange({factors: [["a", "b"], ["b", "c"]]}),
y_range: new DataRange1d(),
})
const source = new ColumnDataSource({data: {x: [["a", "b"], ["b", "c"]], y: [1, 2]}})
p.vbar({x: {field: "x"}, top: {field: "y"}, width: 0.1, source})
const {view} = await display(p)
source.data = {x: ["a"], y: [1]}
;(p.x_range as FactorRange).factors = ["a"]
await view.ready
})
})
describe("in issue #9522", () => {
it("disallows arrow to be positioned correctly in stacked layouts", async () => {
const horz = (end?: ArrowHead) => new Arrow({x_start: 1, x_end: 5, y_start: 0, y_end: 0, end})
const vert = (end?: ArrowHead) => new Arrow({x_start: 2, x_end: 2, y_start: 1, y_end: -2, end})
const p1 = fig([200, 200], {x_range: [0, 6], y_range: [-3, 2]})
p1.add_layout(horz(new NormalHead({fill_color: "blue"})))
p1.add_layout(vert())
const p2 = fig([200, 200], {x_range: [0, 6], y_range: [-3, 2]})
p2.add_layout(horz())
p2.add_layout(vert(new NormalHead({fill_color: "green"})))
await display(row([p1, p2]))
})
})
describe("in issue #9703", () => {
it.allowing(8)("disallows ImageURL glyph to set anchor and angle at the same time", async () => {
const p = fig([300, 300], {x_range: [-1, 10], y_range: [-1, 10]})
const img = svg_data_url(`\
<svg version="1.1" viewBox="0 0 2 2" xmlns="http://www.w3.org/2000/svg">
<path d="M 0,0 2,0 1,2 Z" fill="green" />
</svg>
`)
let y = 0
const w = 1, h = 1
for (const anchor of [...Anchor].slice(0, 9)) {
p.image_url({url: [img], x: 0, y, w, h, anchor, angle: 0})
p.image_url({url: [img], x: 1, y, w, h, anchor, angle: Math.PI/6})
p.image_url({url: [img], x: 2, y, w, h, anchor, angle: Math.PI/4})
p.image_url({url: [img], x: 3, y, w, h, anchor, angle: Math.PI/3})
p.image_url({url: [img], x: 4, y, w, h, anchor, angle: Math.PI/2})
p.image_url({url: [img], x: 5, y, w, h, anchor, angle: Math.PI/1})
y += 1
}
await display(p)
})
})
describe("in issue #9724", () => {
it("makes automatic padding in data ranges inconsistent", async () => {
const x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
const padding = {
range_padding: 1,
range_padding_units: "absolute" as const,
}
const p0 = (() => {
const x_range = new DataRange1d()
const y_range = new DataRange1d(padding)
const p = fig([150, 150], {x_range, y_range})
p.line({x, y: 10, line_width: 2, color: "red"})
return p
})()
const p1 = (() => {
const x_range = new DataRange1d()
const y_range = new DataRange1d(padding)
const p = fig([150, 150], {x_range, y_range})
p.line({x, y: 10, line_width: 2, color: "red"})
p.line({x, y: 15, line_width: 2, color: "blue"})
return p
})()
const p2 = (() => {
const x_range = new DataRange1d()
const y_range = new DataRange1d({start: 0, ...padding})
const p = fig([150, 150], {x_range, y_range})
p.line({x, y: 10, line_width: 2, color: "red"})
return p
})()
const p3 = (() => {
const x_range = new DataRange1d()
const y_range = new DataRange1d({start: 0, ...padding})
const p = fig([150, 150], {x_range, y_range})
p.line({x, y: 10, line_width: 2, color: "red"})
p.line({x, y: 15, line_width: 2, color: "blue"})
return p
})()
await display(row([p0, p1, p2, p3]))
})
})
describe("in issue #9877", () => {
function plot(fill: Color | null, line: Color | null) {
const p = fig([200, 200], {x_range: [0, 3], y_range: [0, 3]})
p.circle({x: [1, 1, 2, 2], y: [1, 2, 1, 2], radius: 0.5, line_color: null, fill_color: "red"})
const box = new BoxAnnotation({
bottom: 1, top: 2, left: 1, right: 2,
fill_color: fill, fill_alpha: 0.5,
line_color: line, line_alpha: 1.0, line_width: 4,
})
p.add_layout(box)
return p
}
it("disallows BoxAnnotation to respect fill_color == null", async () => {
const p0 = plot("blue", "green")
const p1 = plot(null, "green")
await display(row([p0, p1]))
})
it("disallows BoxAnnotation to respect line_color == null", async () => {
const p0 = plot("blue", "green")
const p1 = plot("blue", null)
await display(row([p0, p1]))
})
})
describe("in issue #9230", () => {
function plot(output_backend: OutputBackend, selected?: Selection) {
const p = fig([200, 200], {tools: "box_select", output_backend})
const x = [0, 1, 2, 3]
const y = [0, 1, 2, 3]
const c = ["black", "red", "green", "blue"]
const source = new ColumnDataSource({data: {x, y, c}, selected})
const view = new CDSView({filter: new BooleanFilter({booleans: [false, true, true, true]})})
p.scatter({field: "x"}, {field: "y"}, {source, view, color: {field: "c"}, size: 20})
return p
}
it("makes GlyphRenderer use incorrect subset indices", async () => {
const p0 = plot("canvas")
const p1 = plot("webgl")
await display(row([p0, p1]))
})
it("makes GlyphRenderer use incorrect subset indices after selection", async () => {
const items = []
for (const indices of subsets([1, 2, 3])) {
const selection = new Selection({indices})
const p0 = plot("canvas", selection)
const p1 = plot("webgl", selection)
items.push(column([p0, p1]))
}
await display(row(items))
})
})
describe("in issue #10856", () => {
it("makes GlyphRenderer ignore changes to secondary glyphs", async () => {
const p = fig([200, 200])
const x = [0, 1, 2, 3, 4]
const y = [0, 1, 2, 3, 4]
const c = ["red", "orange", "green", "blue", "purple"]
const selected = new Selection({indices: [1, 3, 4]})
const source = new ColumnDataSource({data: {x, y, c}, selected})
const r = p.scatter({field: "x"}, {field: "y"}, {
source,
color: {field: "c"},
selection_line_color: "white",
size: 20,
})
const {view} = await display(p)
const glyph = r.selection_glyph
assert(glyph instanceof Scatter)
glyph.line_color = "black"
glyph.hatch_color = "black"
glyph.hatch_pattern = "/"
await view.ready
})
})
describe("in issue #10042", () => {
it("disallows to set subgroup_label_orientation = 0", async () => {
const random = new Random(1)
const factors: Factor[] = [
["A", "01", "AA"], ["A", "01", "AB"], ["A", "01", "AC"], ["A", "01", "AD"], ["A", "01", "AE"],
["B", "02", "AA"], ["B", "02", "AB"], ["B", "02", "AC"], ["B", "02", "AD"], ["B", "02", "AE"],
]
const y_range = new FactorRange({factors})
const p = fig([200, 300], {y_range})
p.hbar({
y: factors,
left: 0,
right: random.floats(factors.length),
height: 0.8,
})
for (const axis of p.yaxis) {
if (axis instanceof CategoricalAxis) {
axis.subgroup_label_orientation = 0
}
}
await display(p)
})
})
describe("in issue #10575", () => {
const factors: Factor[] = [
["A", "01", "AA"], ["A", "01", "AB"], ["A", "01", "AC"], ["A", "01", "AD"], ["A", "01", "AE"],
["B", "02", "AA"], ["B", "02", "AB"], ["B", "02", "AC"], ["B", "02", "AD"], ["B", "02", "AE"],
]
it("disallows rendering Whisker annotation with a categorical x-range", async () => {
const random = new Random(1)
const x = factors
const y = random.floats(factors.length)
const upper = y.map((yi) => yi + random.float())
const lower = y.map((yi) => yi - random.float())
const source = new ColumnDataSource({data: {x, y, lower, upper}})
const whisker = new Whisker({source, dimension: "height", base: {field: "x"}})
const x_range = new FactorRange({factors})
const p = fig([400, 200], {x_range})
p.scatter({source})
p.add_layout(whisker)
await display(p)
})
it("disallows rendering Whisker annotation with a categorical y-range", async () => {
const random = new Random(1)
const x = random.floats(factors.length)
const y = factors
const upper = x.map((xi) => xi + random.float())
const lower = x.map((xi) => xi - random.float())
const source = new ColumnDataSource({data: {x, y, lower, upper}})
const whisker = new Whisker({source, dimension: "width", base: {field: "y"}})
const y_range = new FactorRange({factors})
const p = fig([200, 400], {y_range})
p.scatter({source})
p.add_layout(whisker)
await display(p)
})
})
describe("in issue #10219", () => {
it("disallows correct placement of Rect glyph with partial categorical ranges", async () => {
const source = new ColumnDataSource({data: {
x: ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
y: ["A", "B", "C", "A", "B", "C", "A", "B", "C"],
}})
const p = fig([300, 300], {x_range: ["B", "C"], y_range: ["C", "B"]})
p.rect({x: {field: "x"}, y: {field: "y"}, width: 0.9, height: 0.9, source})
p.circle({x: {field: "x"}, y: {field: "y"}, radius: 0.2, color: "red", source})
await display(p)
})
})
describe("in issue #10246", () => {
function make_layout(output_backend: OutputBackend) {
const x = range(0, 11)
const y0 = x
const y1 = x.map((xi) => 10 - xi)
const y2 = x.map((xi) => Math.abs(xi - 5))
const s0 = fig([200, 200], {output_backend})
s0.scatter(x, y0, {size: 12, alpha: 0.8, color: "#53777a"})
const s1 = fig([200, 200], {output_backend})
s1.scatter(x, y1, {marker: "triangle", size: 12, alpha: 0.8, color: "#c02942"})
const s2 = fig([200, 200], {output_backend, visible: false})
s2.scatter(x, y2, {marker: "square", size: 12, alpha: 0.8, color: "#d95b43"})
return row([s0, s1, s2])
}
it("makes a plot with visible == false throw an exception", async () => {
const l0 = make_layout("canvas")
const l1 = make_layout("webgl")
await display(column([l0, l1]))
})
})
describe("in issue #10195", () => {
it("makes extra axes render with invalid data ranges", async () => {
function make_plot(axis_location: Location) {
const p = fig([200, 200])
p.extra_y_ranges = {yrangename: new Range1d({start: 0, end: 1})}
p.add_layout(new LinearAxis({y_range_name: "yrangename"}), axis_location)
return p
}
const p0 = make_plot("above")
const p1 = make_plot("below")
const p2 = make_plot("left")
const p3 = make_plot("right")
await display(row([p0, p1, p2, p3]))
})
})
describe("in issue #10305", () => {
it("disallows to render lines with NaNs using SVG backend", async () => {
function make_plot(output_backend: OutputBackend) {
const p = fig([200, 200], {output_backend, title: output_backend})
const y = [NaN, 0, 1, 4, NaN, NaN, NaN, 3, 4, NaN, NaN, 5, 6, 9, 10]
p.line({x: range(y.length), y, line_width: 5, line_dash: "dashed"})
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
const p2 = make_plot("webgl")
await display(row([p0, p1, p2]))
})
it("disallows to render multi-lines with NaNs using SVG backend", async () => {
function make_plot(output_backend: OutputBackend) {
const p = fig([200, 200], {output_backend, title: output_backend})
const y = [NaN, 0, 1, 4, NaN, NaN, NaN, 3, 4, NaN, NaN, 5, 6, 9, 10]
p.multi_line({xs: [range(y.length)], ys: [y], line_width: 5, line_dash: "dashed"})
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
const p2 = make_plot("webgl")
await display(row([p0, p1, p2]))
})
})
describe("in issue #10725", () => {
it("renders image glyphs in wrong orientation using SVG backend", async () => {
function make_plot(output_backend: OutputBackend) {
const image = scalar_image(500)
const color_mapper = new LinearColorMapper({palette: Spectral11})
const p = fig([200, 200], {output_backend})
p.image({image: {value: image}, x: 0, y: 0, dw: 10, dh: 10, color_mapper})
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
await display(row([p0, p1]))
})
})
describe("in issue #10362", () => {
it("disallows updating layout when changing axis label", async () => {
const p = fig([200, 100])
p.circle({x: [0, 1, 2], y: [0, 1, 2], radius: 0.25})
const {view} = await display(p)
p.xaxis.axis_label = "X-Axis Label"
await view.ready
})
})
describe("in issue #10369", () => {
it("disallows ImageURL glyph to compute correct bounds with different anchors", async () => {
const img = svg_image()
const plots = []
for (const anchor of [...Anchor].slice(0, 9)) {
const x_range = new DataRange1d()
const y_range = new DataRange1d()
const p = fig([200, 200], {x_range, y_range, title: anchor, match_aspect: true})
p.image_url({url: [img], x: 0, y: 0, w: 1, h: 1, anchor})
plots.push(p)
}
const r = grid(Matrix.from(plots, 3))
await display(r)
})
})
describe("in issue #8446", () => {
it("disallows correct rendering circle scatter plots with SVG backend", async () => {
function make_plot(output_backend: OutputBackend) {
const p = fig([200, 200], {output_backend, title: output_backend})
p.scatter([-1, -2, -3, -4, -5], [6, 7, 2, 4, 5], {size: 20, color: "navy", alpha: 0.5, marker: "circle"})
p.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], {size: 20, color: "red", alpha: 0.5})
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
await display(row([p0, p1]))
})
})
describe("in issue #6775", () => {
it("disallows correct rendering of legends with SVG backend", async () => {
function make_plot(output_backend: OutputBackend) {
const p = fig([200, 200], {output_backend, title: output_backend})
p.scatter({x: 1, y: 1, size: 30, marker: "diamond", legend_label: "diamond", color: "red"})
p.scatter({x: 2, y: 1, size: 30, marker: "square", legend_label: "square"})
p.legend.location = "top_center"
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
await display(row([p0, p1]))
})
})
describe("in issue #589", () => {
it("disallows updating legend when glyphs change", async () => {
const x = [1, 2, 3, 4, 5, 10]
const y = [5, 6, 2, 3, 4, 10]
const p = fig([300, 300])
const r = p.line(x, y, {legend_label: "foo"})
const {view} = await display(p)
p.scatter(x, y, {legend_label: "foo"})
r.glyph.line_dash = "dotted"
r.glyph.line_color = "black"
p.line([1, 4, 8], [2, 12, 6], {line_color: "red", legend_label: "bar"})
p.legend.background_fill_color = "blue"
p.legend.background_fill_alpha = 0.2
await view.ready
})
})
describe("in issue #10454", () => {
it("disallows using categorical coordinates with LabelSet annotation", async () => {
const p = fig([300, 300], {x_range: ["X1", "X2", "X3"], y_range: ["Y1", "Y2", "Y3"]})
p.rect({x: ["X1", "X2", "X3"], y: ["Y1", "Y2", "Y3"], width: 1, height: 1, fill_alpha: 0.3})
const labels0 = new LabelSet({x: {value: "X1"}, y: {value: "Y3"}, text: {value: "L0"}, text_color: "red"})
p.add_layout(labels0)
const labels1 = new LabelSet({x: {value: "X3"}, y: {value: "Y1"}, text: {value: "L1"}, text_color: "green"})
p.add_layout(labels1)
const source = new ColumnDataSource({data: {
x: ["X1", "X2", "X3"],
y: ["Y1", "Y2", "Y3"],
text: ["L20", "L21", "L22"],
}})
const labels2 = new LabelSet({x: {field: "x"}, y: {field: "y"}, text: {field: "text"}, source, text_color: "blue"})
p.add_layout(labels2)
await display(p)
})
it("disallows using categorical coordinates with Arrow annotation", async () => {
const p = fig([300, 300], {x_range: ["X1", "X2", "X3"], y_range: ["Y1", "Y2", "Y3"]})
p.rect({x: ["X1", "X2", "X3"], y: ["Y1", "Y2", "Y3"], width: 1, height: 1, fill_alpha: 0.3})
const arrow0 = new Arrow({
x_start: {value: "X1"}, y_start: {value: "Y1"},
x_end: {value: "X3"}, y_end: {value: "Y3"},
line_color: "red",
})
p.add_layout(arrow0)
const arrow1 = new Arrow({
x_start: {value: "X3"}, y_start: {value: "Y1"},
x_end: {value: "X1"}, y_end: {value: "Y3"},
line_color: "green",
})
p.add_layout(arrow1)
const source = new ColumnDataSource({data: {
x_start: ["X2", "X2", "X2", "X2"],
y_start: ["Y2", "Y2", "Y2", "Y2"],
x_end: ["X3", "X2", "X1", "X2"],
y_end: ["Y2", "Y3", "Y2", "Y1"],
}})
const labels2 = new Arrow({
x_start: {field: "x_start"},
y_start: {field: "y_start"},
x_end: {field: "x_end"},
y_end: {field: "y_end"},
source,
line_color: "blue",
})
p.add_layout(labels2)
await display(p)
})
})
describe("in issue #10136", () => {
it("prevents correct rendering of overlapping arrows", async () => {
const p = fig([200, 100], {x_range: [0, 3], y_range: [0, 2]})
const source = new ColumnDataSource({data: {
x_end: [1, 2, 3],
}})
const head = new OpenHead({size: 30, line_width: 3})
const arrow = new Arrow({
end: head,
x_start: {value: 0},
y_start: {value: 1},
x_end: {field: "x_end"},
y_end: {value: 1},
line_width: 3,
source,
})
p.add_layout(arrow)
await display(p)
})
})
describe("in issue #10457", () => {
it("prevents rendering circle glyph with reversed ranges and radius in data units", async () => {
function plot(x_range: [number, number], y_range: [number, number]) {
const title = `[${x_range}] × [${y_range}]`
const p = fig([150, 150], {x_range, y_range, title})
p.circle({
x: [0, 50, 100], y: [0, 50, 100], radius: {value: 20},
fill_color: ["red", "green", "blue"],
line_color: "black",
alpha: 0.5,
})
return p
}
const p1 = plot([0, 100], [0, 100])
const p2 = plot([100, 0], [0, 100])
const p3 = plot([0, 100], [100, 0])
const p4 = plot([100, 0], [100, 0])
const layout = row([p1, p2, p3, p4])
await display(layout)
})
it("prevents rendering marker glyphs with reversed ranges", async () => {
function plot(marker: MarkerType, x_range: [number, number], y_range: [number, number]) {
const p = fig([100, 50], {x_range, y_range, x_axis_type: null, y_axis_type: null})
p.scatter({
x: [0, 50, 100],
y: [0, 50, 100],
size: {value: 30},
marker,
fill_color: ["red", "green", "blue"],
line_color: "black",
alpha: 0.5,
})
return p
}
function plots(marker: MarkerType) {
const p1 = plot(marker, [0, 100], [0, 100])
const p2 = plot(marker, [100, 0], [0, 100])
const p3 = plot(marker, [0, 100], [100, 0])
const p4 = plot(marker, [100, 0], [100, 0])
return [p1, p2, p3, p4]
}
const layout = column([...MarkerType].map((marker) => row(plots(marker))))
await display(layout)
})
})
describe("in issue #10472", () => {
it("prevents GraphRenderer to participate in auto-ranging", async () => {
const p = fig([200, 200], {
x_range: new DataRange1d({range_padding: 0.2}),
y_range: new DataRange1d({range_padding: 0.2}),
})
const layout_provider = new StaticLayoutProvider({
graph_layout: new Map([
[4, [2, 1]],
[5, [2, 2]],
[6, [3, 1]],
[7, [3, 2]],
]),
})
const node_renderer = new GlyphRenderer({
glyph: new Scatter({size: 10, fill_color: "red"}),
data_source: new ColumnDataSource({data: {index: [4, 5, 6, 7]}}),
})
const edge_renderer = new GlyphRenderer({
glyph: new MultiLine({line_width: 2, line_color: "gray"}),
data_source: new ColumnDataSource({data: {start: [4, 4, 5, 6], end: [5, 6, 6, 7]}}),
})
const graph = new GraphRenderer({layout_provider, node_renderer, edge_renderer})
p.add_renderers(graph)
await display(p)
})
})
describe("in issue #9764", () => {
it("prevents display of MultiChoice placeholder", async () => {
const widget = new MultiChoice({placeholder: "Choose ...", options: ["1", "2", "3"], width: 200})
await display(widget, [250, 100])
})
})
describe("in issue #10452", () => {
it("prevents changing MultiChoice.disabled property", async () => {
const widget = new MultiChoice({value: ["2", "3"], options: ["1", "2", "3"], width: 200})
const {view} = await display(widget, [250, 100])
widget.disabled = true
await view.ready
})
})
describe("in issue #10507", () => {
it.allowing(22)("prevents changing MultiSelect.disabled property", async () => {
const widget = new MultiSelect({value: ["2", "3"], options: ["1", "2", "3"], width: 200})
const {view} = await display(widget, [250, 100])
widget.disabled = true
await view.ready
})
})
describe("in issue #10695", () => {
it.allowing(16)("prevents showing MultiChoice's dropdown menu", async () => {
const random = new Random(1)
const N = 10
const columns = ["Apple", "Pear", "Banana"]
const source = new ColumnDataSource({data: {
Apple: random.floats(N),
Pear: random.floats(N),
Banana: random.floats(N),
}})
const choices = new MultiChoice({options: columns})
const button = new Button({label: "A button"})
const table = new DataTable({
width: 300,
height: 100,
source,
columns: columns.map((field) => new TableColumn({title: field, field})),
})
const layout = column([choices, button, table])
const {view} = await display(layout, [350, 250])
const choices_view = view.owner.get_one(choices)
choices_view.choice_el.showDropdown()
await paint()
})
})
describe("in issue #11365", () => {
it.allowing(16)("prevents showing MultiChoice's dropdown menu over subsequent roots", async () => {
const columns = ["Apple", "Pear", "Banana"]
const choices = new MultiChoice({options: columns})
const button = new Button({label: "A button"})
const layout = column([choices, button])
const {view, el} = await display(layout, [350, 200])
// XXX: note that this plot is not going to show up in the baseline (blf) nor will
// be considered a part of the test by any means by the testing framework (e.g. no
// cleanup will be made). This needs proper support for multi-root display, which
// will be increasing more useful in future testing.
const plot = fig([300, 100])
plot.scatter([1, 2, 3], [1, 2, 3])
await show(plot, el)
const choices_view = view.owner.get_one(choices)
choices_view.choice_el.showDropdown()
await paint()
})
})
describe("in issue #12115", () => {
it.allowing(16)("prevents showing MultiChoice's dropdown items correctly", async () => {
const columns = ["Apple", "Pear", "Banana"]
const choices = new MultiChoice({options: columns, width: 75, width_policy: "fixed"})
const {view} = await display(choices, [100, 200])
view.choice_el.showDropdown()
await paint()
})
})
describe("in issue #10749", () => {
it("prevents DataTable from correctly ordering rows and formatting string dates", async () => {
const indices = range(0, 22)
const source = new ColumnDataSource({
data: {
dates: indices.map((i) => `2014-03-${i + 1}`),
downloads: indices.map((i) => i % 10),
},
})
const columns = [
new TableColumn({field: "dates", title: "Date", formatter: new DateFormatter()}),
new TableColumn({field: "downloads", title: "Downloads"}),
]
const table = new DataTable({source, columns, selectable: "checkbox", width: 300, height: 400})
const {view} = await display(table, [350, 450])
source.selected.indices = indices
await view.ready
expect(view.get_selected_rows()).to.be.equal(indices)
})
})
describe("in issue #10488", () => {
it("disallows correct placement of Rect glyph with datetime values", async () => {
const t0 = 1600755745624.793
const source = new ColumnDataSource({data: {
x: linspace(t0, t0 + 2*3600*1000, 50),
}})
const p = fig([800, 300])
p.rect({x: {field: "x"}, y: 0, width: 100000, height: 1, line_color: "red", fill_alpha: 0.5, line_alpha: 0.5, source})
await display(p)
})
})
describe("in issue #10498", () => {
it("prevents GridBox from rebuilding when rows or cols properties are modified", async () => {
const p1 = fig([300, 300])
const p2 = fig([300, 300])
p1.scatter({x: [0, 1], y: [0, 1], color: "red"})
p2.scatter({x: [1, 0], y: [0, 1], color: "green"})
const box = new GridBox({
children: [[p1, 0, 0], [p2, 0, 1]],
cols: ["300px", "300px"],
sizing_mode: "fixed",
})
const {view} = await display(box, [600, 300])
box.cols = ["100px", "500px"]
await view.ready
})
})
describe("in issue #10541", () => {
it("prevents Slope with gradient=0", async () => {
const p = fig([200, 200], {x_range: [-5, 5], y_range: [-5, 5]})
for (const gradient of [1, -1, 0, 2, -0.5]) {
const s = new Slope({gradient, y_intercept: -1})
p.add_layout(s)
}
await display(p)
})
})
describe("in issue #10589", () => {
it("prevents correctly filtering out indices when using MultiLine glyph", async () => {
const source = new ColumnDataSource({data: {
xs: [[0, 0], [1, 1], [2, 2]],
ys: [[0, 1], [0, 1], [0, 1]],
}})
const filter = new IndexFilter({indices: [0, 2]})
const view = new CDSView({filter})
function make_plot(output_backend: OutputBackend) {
const p = fig([200, 200], {output_backend, title: output_backend})
p.multi_line({field: "xs"}, {field: "ys"}, {view, source, line_width: 8, line_cap: "round"})
return p
}
const p0 = make_plot("canvas")
const p1 = make_plot("svg")
const p2 = make_plot("webgl")
await display(row([p0, p1, p2]))
})
})
describe("in issue #11006", () => {
it("prevents scaling of superscripts when using non-px font size units", async () => {
const p = fig([300, 50], {
x_range: new Range1d({start: 10**-2, end: 10**11}),
y_range: new Range1d({start: 0, end: 1}),
x_axis_type: "log",
y_axis_type: null,
min_border_top: 0,
min_border_bottom: 0,
min_border_left: 20,
min_border_right: 20,
})
p.xaxis.major_label_text_font_size = "14pt"
await display(p)
})
})
describe("in issue #10809", () => {
it("prevents repaint of resized layoutable renderers", async () => {
const p = fig([100, 100])
const {view} = await display(p)
p.circle({x: 0, y: 0, radius: 1})
await view.ready
})
})
describe("in issue #11045", () => {
it("prevents correct paint of glyphs using hatch patters in SVG backend after pan", async () => {
const p = fig([200, 200], {x_range: [-1, 1], y_range: [-1, 1], output_backend: "svg"})
p.circle({x: 0, y: 0, radius: 1, fill_color: "orange", alpha: 0.6, hatch_pattern: "@"})
const {view} = await display(p)
const {start: x_start, end: x_end} = p.x_range
const {start: y_start, end: y_end} = p.y_range
const pan = 0.5
const xrs = new Map([[p.x_range, {start: x_start + pan, end: x_end + pan}]])
const yrs = new Map([[p.y_range, {start: y_start + pan, end: y_end + pan}]])
view.update_range({xrs, yrs}, {panning: true})
// TODO: p.pan(0.5, 0.5)
await view.ready
})
})
describe("in issue #10851", () => {
function box(width: number, height: number): HTMLElement {
return div({style: {width: `${width}px`, height: `${height}px`, backgroundColor: "red"}})
}
function layout() {
const p0 = fig([200, 200], {sizing_mode: "scale_width", background_fill_alpha: 0.5, border_fill_alpha: 0.5})
const p1 = fig([200, 200], {sizing_mode: "scale_width", background_fill_alpha: 0.5, border_fill_alpha: 0.5})
p0.scatter([0, 1, 2], [3, 4, 5])
p1.scatter([1, 2, 3], [4, 5, 6])
return row([p0, p1], {sizing_mode: "scale_width", styles: {background_color: "orange"}})
}
it("results in incorrect layout when viewport is smaller than optimal size", async () => {
await display(layout(), [500, 300], box(350, 175))
})
it("results in incorrect layout when viewport is larger than optimal size", async () => {
await display(layout(), [500, 300], box(450, 225))
})
})
describe("in issue #11154", () => {
it("does not allow the plotting API to consider hatch visuals", async () => {
const p = fig([200, 200])
const r = p.rect({
x: [0, 1, 2], y: 3, width: 0.7, height: 0.7, angle: [0.0, 0.3, 0.6],
hatch_pattern: "x", fill_color: "orange",
})
r.data_source.selected.indices = [1]
await display(p)
})
})