|
1 | 1 | import * as Plot from "@observablehq/plot"; |
2 | | -import type {LegendScales} from "@observablehq/plot"; |
3 | | -import {select} from "d3"; |
4 | 2 | import {test} from "test/plot"; |
5 | 3 |
|
6 | | -function opacityLegends(options: LegendScales) { |
7 | | - const doc = (typeof document !== "undefined" ? document : undefined) || Plot.legend(options).ownerDocument; |
8 | | - const div = doc.createElement("div"); |
9 | | - div.style.cssText = "display: flex; gap: 20px;"; |
10 | | - for (const [bg, color] of [ |
11 | | - ["white", "black"], |
12 | | - ["black", "white"] |
13 | | - ]) { |
14 | | - const box = doc.createElement("div"); |
15 | | - box.style.cssText = `background-color: ${bg}; color: ${color}; color-scheme: ${ |
16 | | - color === "white" ? "dark" : "light" |
17 | | - }; padding: 20px;`; |
18 | | - const svg = Plot.legend(options); |
19 | | - select(svg).attr("style", `--plot-background: ${bg}`); |
20 | | - box.appendChild(svg); |
21 | | - div.appendChild(box); |
22 | | - } |
23 | | - return div; |
24 | | -} |
25 | | - |
26 | 4 | test(function opacityLegend() { |
27 | | - return opacityLegends({opacity: {domain: [0, 10], label: "Quantitative"}}); |
| 5 | + return Plot.legend({opacity: {domain: [0, 10], label: "Quantitative"}}); |
28 | 6 | }); |
29 | 7 |
|
30 | 8 | test(function opacityLegendRange() { |
31 | | - return opacityLegends({opacity: {domain: [0, 1], range: [0.5, 1], label: "Range"}}); |
| 9 | + return Plot.legend({opacity: {domain: [0, 1], range: [0.5, 1], label: "Range"}}); |
32 | 10 | }); |
33 | 11 |
|
34 | 12 | test(function opacityLegendLinear() { |
35 | | - return opacityLegends({opacity: {type: "linear", domain: [0, 10], label: "Linear"}}); |
| 13 | + return Plot.legend({opacity: {type: "linear", domain: [0, 10], label: "Linear"}}); |
36 | 14 | }); |
37 | 15 |
|
38 | 16 | test(function opacityLegendColor() { |
39 | | - return opacityLegends({opacity: {type: "linear", domain: [0, 10], label: "Linear"}, color: "steelblue"}); |
| 17 | + return Plot.legend({opacity: {type: "linear", domain: [0, 10], label: "Linear"}, color: "steelblue"}); |
40 | 18 | }); |
41 | 19 |
|
42 | 20 | test(function opacityLegendLog() { |
43 | | - return opacityLegends({opacity: {type: "log", domain: [1, 10], label: "Log"}}); |
| 21 | + return Plot.legend({opacity: {type: "log", domain: [1, 10], label: "Log"}}); |
44 | 22 | }); |
45 | 23 |
|
46 | 24 | test(function opacityLegendSqrt() { |
47 | | - return opacityLegends({opacity: {type: "sqrt", domain: [0, 1], label: "Sqrt"}}); |
| 25 | + return Plot.legend({opacity: {type: "sqrt", domain: [0, 1], label: "Sqrt"}}); |
48 | 26 | }); |
49 | 27 |
|
50 | 28 | test(function opacityLegendCSS4() { |
51 | | - return opacityLegends({opacity: {type: "linear", domain: [0, 1], label: "p3"}, color: "color(display-p3 0 1 0)"}); |
| 29 | + return Plot.legend({opacity: {type: "linear", domain: [0, 1], label: "p3"}, color: "color(display-p3 0 1 0)"}); |
52 | 30 | }); |
0 commit comments