Skip to content

Commit

Permalink
feat: scale property of color enc
Browse files Browse the repository at this point in the history
  • Loading branch information
soundquiet committed Sep 1, 2021
1 parent b64886e commit f18179e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/pie_color.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"basis": {
"type": "chart"
},
"data": {
"type": "json-array",
"values": [
{"category": 1, "value": 4},
{"category": 2, "value": 6},
{"category": 3, "value": 10},
{"category": 4, "value": 3},
{"category": 5, "value": 7},
{"category": 6, "value": 8}
]
},
"layer": [
{
"mark": "arc",
"encoding": {
"theta": {"field": "value", "type": "quantitative"},
"color": {"field": "category", "type": "nominal", "scale": { "range": ["#5c0011", "#874d00", "#ffec3d", "#7cb305", "#08979c", "#003a8c"]}}
}
}
]
}
4 changes: 4 additions & 0 deletions src/adaptor/g2plot/toConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export function toG2PlotConfg(spec: ChartAntVSpec) {
} else {
configs.config.colorField = layer.encoding[key]?.field;
}
if (layer.encoding[key]?.scale && layer.encoding[key]?.scale.range) {
// define color
configs.config.color = layer.encoding[key]?.scale.range;
}
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/schema/encoding/color.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { EType } from './type';
import { Aggregate } from './aggregate';
import { Scale } from './scale';

export interface Color {
field: string;
type: EType;
aggregate?: Aggregate;
scale?: Scale;
}
13 changes: 13 additions & 0 deletions src/schema/encoding/scale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// TODO: detailed type denifition. currently to support color hex string
export type Scale = {
// range after data mapping
// such as ['apple', 'banana'] --map to--> ['red', 'yellow'](range)
range: (string | number)[];
rangeMin: string | number;
rangeMax: string | number;
// data domain used to data mapping
// such as [0, 100] --domain:[10, 90]--> [10, 90](filter data less than 10)
domain: number[];
domainMin: number;
domaminMax: number;
};

0 comments on commit f18179e

Please sign in to comment.