diff --git a/apps/color-buddy/public/examples/pie-chart.json b/apps/color-buddy/public/examples/pie-chart.json new file mode 100644 index 00000000..fc8e67c7 --- /dev/null +++ b/apps/color-buddy/public/examples/pie-chart.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://vega.github.io/schema/vega-lite/v5.json", + "description": "A simple pie chart with labels.", + "data": { + "values": [ + { "category": "a", "value": 4 }, + { "category": "b", "value": 6 }, + { "category": "c", "value": 10 }, + { "category": "d", "value": 3 }, + { "category": "e", "value": 7 }, + { "category": "f", "value": 8 } + ] + }, + "encoding": { + "theta": { "field": "value", "type": "quantitative", "stack": true }, + "color": { "field": "category", "type": "nominal", "legend": null } + }, + "layer": [ + { + "mark": { "type": "arc", "outerRadius": 80 } + }, + { + "mark": { "type": "text", "radius": 90 }, + "encoding": { + "text": { "field": "category", "type": "nominal" } + } + } + ] +} diff --git a/apps/color-buddy/src/stores/example-store.ts b/apps/color-buddy/src/stores/example-store.ts index de2d606a..c72cfa1b 100644 --- a/apps/color-buddy/src/stores/example-store.ts +++ b/apps/color-buddy/src/stores/example-store.ts @@ -29,6 +29,11 @@ export const DEMOS = [ title: "Bar Chart", filename: "./examples/grouped-bar-chart.json", }, + { + type: "vega", + title: "Pie Chart", + filename: "./examples/pie-chart.json", + }, { type: "vega", title: "Heatmap", filename: "./examples/heatmap.json" }, { type: "vega", title: "Map", filename: "./examples/illinois-map.json" }, { diff --git a/packages/palette/src/Color.ts b/packages/palette/src/Color.ts index 4b7c8944..6e530a77 100644 --- a/packages/palette/src/Color.ts +++ b/packages/palette/src/Color.ts @@ -139,6 +139,11 @@ export class Color { return this.toColorIO().luminance; } deltaE(color: Color, algorithm: DistAlgorithm = "2000"): number { + const allowedAlgorithms = new Set(["76", "CMC", "2000", "ITP", "Jz", "OK"]); + if (!allowedAlgorithms.has(algorithm)) { + return 0; + } + const left = this.toColorIO().to("srgb"); const right = color.toColorIO().to("srgb"); return left.deltaE(right, algorithm);