Skip to content

Commit

Permalink
add pie chart example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Sep 24, 2024
1 parent 726f627 commit a3e8b16
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions apps/color-buddy/public/examples/pie-chart.json
Original file line number Diff line number Diff line change
@@ -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" }
}
}
]
}
5 changes: 5 additions & 0 deletions apps/color-buddy/src/stores/example-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
{
Expand Down
5 changes: 5 additions & 0 deletions packages/palette/src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3e8b16

Please sign in to comment.