Skip to content

Commit

Permalink
docs(interval): log scale with zero value
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jun 25, 2023
1 parent 567717b commit 1a2ce9f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
28 changes: 28 additions & 0 deletions site/examples/general/interval/demo/column-log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* A recreation of this demo: https://observablehq.com/@d3/bar-chart
*/
import { Chart } from '@antv/g2';

const EPSILON = 1e-6;

const chart = new Chart({
container: 'container',
theme: 'classic',
padding: 'auto',
autoFit: true,
});

chart
.interval()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
})
.encode('x', 'letter')
.encode('y', 'frequency')
.encode('y1', EPSILON) // Log scale cant' map zero, set a value close to zero.
.scale('y', { type: 'log' })
.axis('y', { labelFormatter: (d) => (d === EPSILON ? 0 : d) });

chart.render();
8 changes: 8 additions & 0 deletions site/examples/general/interval/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*fu-BSYg7U_kAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "column-log.ts",
"title": {
"zh": "对数柱形图",
"en": "Log Column Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*cRE5TqJGnVUAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "bar.ts",
"title": {
Expand Down
1 change: 1 addition & 0 deletions src/spec/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export type BaseMark<T extends MarkTypes, C extends string = ChannelTypes> = {
scale?: Partial<Record<C, Scale>>;
coordinate?: Coordinate;
style?: Record<string, any>;
viewStyle?: Record<string, any>;
state?: Partial<
Record<
'active' | 'selected' | 'inactive' | 'unselected',
Expand Down
2 changes: 1 addition & 1 deletion src/transform/maybeGradient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepMix } from '@antv/util';
import { TransformComponent as TC } from '../runtime';
import { column, columnOf, constant, visualColumn } from './utils/helper';
import { constant, visualColumn } from './utils/helper';

export type MaybeGradientOptions = Record<string, never>;

Expand Down

0 comments on commit 1a2ce9f

Please sign in to comment.