File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import {create, path} from "d3";
22import { inferFontVariant } from "../axes.js" ;
33import { maybeAutoTickFormat } from "../axis.js" ;
44import { isNoneish , maybeColorChannel , maybeNumberChannel } from "../options.js" ;
5+ import { isOrdinalScale } from "../scales.js" ;
56import { applyInlineStyles , impliedString , maybeClassName } from "../style.js" ;
67
78function maybeScale ( scale , key ) {
@@ -12,6 +13,7 @@ function maybeScale(scale, key) {
1213}
1314
1415export function legendSwatches ( color , options ) {
16+ if ( ! isOrdinalScale ( color ) ) throw new Error ( `swatches legend requires ordinal color scale (not ${ color . type } )` ) ;
1517 return legendItems (
1618 color ,
1719 options ,
Original file line number Diff line number Diff line change 11import * as Plot from "@observablehq/plot" ;
22import * as assert from "assert" ;
33
4- it ( "Plot.legend({color: {type:'identity'}}) returns undefined" , ( ) => {
5- const l = Plot . legend ( { color : { type : "identity" } } ) ;
6- assert . strictEqual ( l , undefined ) ;
4+ it ( `Plot.legend({color: {type: "identity"}}) returns undefined` , ( ) => {
5+ assert . strictEqual ( Plot . legend ( { color : { type : "identity" } } ) , undefined ) ;
6+ } ) ;
7+
8+ it ( `Plot.legend({legend: "swatches", color: {type: "<not-ordinal>"}}) throws an error` , ( ) => {
9+ assert . throws ( ( ) => Plot . legend ( { legend : "swatches" , color : { type : "linear" } } ) , / s w a t c h e s l e g e n d r e q u i r e s o r d i n a l c o l o r s c a l e \( n o t l i n e a r \) / ) ;
10+ assert . throws ( ( ) => Plot . legend ( { legend : "swatches" , color : { type : "diverging" } } ) , / s w a t c h e s l e g e n d r e q u i r e s o r d i n a l c o l o r s c a l e \( n o t d i v e r g i n g \) / ) ;
711} ) ;
812
913it ( "Plot.legend({}) throws an error" , ( ) => {
You can’t perform that action at this time.
0 commit comments