This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/superset-ui-preset-chart-xy/src/encodeable/types/Axis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
interface Axis { | ||
title: string; | ||
tickCount: number; | ||
format: string; | ||
} | ||
|
||
export type XAxis = Axis & { | ||
orient: 'top' | 'bottom'; | ||
labelAngle: number; | ||
labelOverlap: string; | ||
}; | ||
|
||
export interface WithXAxis { | ||
axis?: XAxis; | ||
} | ||
|
||
export type YAxis = Axis & { | ||
orient: 'left' | 'right'; | ||
}; | ||
|
||
export interface WithYAxis { | ||
axis?: YAxis; | ||
} | ||
|
||
export interface WithAxis { | ||
axis?: XAxis | YAxis; | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/superset-ui-preset-chart-xy/src/encodeable/types/Channel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export interface ChannelOptions { | ||
namespace?: string; | ||
legend?: boolean; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/superset-ui-preset-chart-xy/src/encodeable/types/Data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type PlainObject<Key extends string = string, Value extends any = any> = { | ||
[key in Key]: Value | ||
}; | ||
|
||
export type Dataset<T extends string = string> = { | ||
keys: T[]; | ||
values: Partial<PlainObject<T>>[]; | ||
}; | ||
|
||
export function verifyDataset<T extends string>(input: Dataset<T>): Dataset<T> { | ||
return input; | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/superset-ui-preset-chart-xy/src/encodeable/types/FieldDef.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// eslint-disable no-unused-vars | ||
import { ValueDef, Value } from 'vega-lite/build/src/fielddef'; | ||
import { Type } from 'vega-lite/build/src/type'; | ||
import { TimeFormatter } from '@superset-ui/time-format'; | ||
import { NumberFormatter } from '@superset-ui/number-format'; | ||
import { WithScale } from './Scale'; | ||
import { WithXAxis, WithYAxis, WithAxis } from './Axis'; | ||
import { WithLegend } from './Legend'; | ||
|
||
export type Formatter = NumberFormatter | TimeFormatter | ((d: any) => string); | ||
|
||
// ValueDef is { value: xxx } | ||
|
||
// FieldDef is { field: 'fieldName', type: ... } | ||
|
||
export interface FieldDef { | ||
field: string; | ||
format?: string; | ||
} | ||
|
||
export interface TypedFieldDef extends FieldDef { | ||
type: Type; | ||
} | ||
|
||
export type TextFieldDef = FieldDef; | ||
|
||
// PropFieldDef is { field: 'fieldName', scale: xxx } | ||
|
||
type ScaleFieldDef<V extends Value = Value> = TypedFieldDef & WithScale<V>; | ||
|
||
export type MarkPropFieldDef<V extends Value = Value> = ScaleFieldDef<V> & WithLegend; | ||
|
||
// PositionFieldDef is { field: 'fieldName', scale: xxx, axis: xxx } | ||
|
||
type PositionFieldDefBase<V extends Value = Value> = ScaleFieldDef<V>; | ||
|
||
export type XFieldDef<V extends Value = Value> = PositionFieldDefBase<V> & WithXAxis; | ||
|
||
export type YFieldDef<V extends Value = Value> = PositionFieldDefBase<V> & WithYAxis; | ||
|
||
export type PositionFieldDef<V extends Value = Value> = ScaleFieldDef<V> & WithAxis; | ||
|
||
export type MarkPropChannelDef<V extends Value = Value> = MarkPropFieldDef<V> | ValueDef<V>; | ||
|
||
export type TextChannelDef = TextFieldDef | ValueDef<string>; | ||
|
||
export type ChannelDef<V extends Value = Value> = | ||
| XFieldDef<V> | ||
| YFieldDef<V> | ||
| MarkPropFieldDef<V> | ||
| TextFieldDef | ||
| ValueDef<V>; | ||
|
||
export function isValueDef<V extends Value>(channelDef: ChannelDef<V>): channelDef is ValueDef<V> { | ||
return channelDef && 'value' in channelDef && !!channelDef.value; | ||
} | ||
|
||
export function isFieldDef<V extends Value>(channelDef: ChannelDef<V>): channelDef is FieldDef { | ||
return channelDef && 'field' in channelDef && !!channelDef.field; | ||
} | ||
|
||
export function isTypedFieldDef<V extends Value>( | ||
channelDef: ChannelDef<V>, | ||
): channelDef is TypedFieldDef { | ||
return isFieldDef(channelDef) && 'type' in channelDef && !!channelDef.type; | ||
} | ||
|
||
export function isScaleFieldDef<V extends Value>( | ||
channelDef: ChannelDef<V>, | ||
): channelDef is ScaleFieldDef { | ||
return channelDef && ('scale' in channelDef || 'sort' in channelDef); | ||
} | ||
|
||
export function isMarkPropFieldDef<V extends Value>( | ||
channelDef: ChannelDef<V>, | ||
): channelDef is MarkPropFieldDef { | ||
return channelDef && 'legend' in channelDef; | ||
} | ||
|
||
export function isPositionFieldDef<V extends Value>( | ||
channelDef: ChannelDef<V>, | ||
): channelDef is PositionFieldDef<V> { | ||
return channelDef && ('axis' in channelDef || 'stack' in channelDef || 'impute' in channelDef); | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/superset-ui-preset-chart-xy/src/encodeable/types/Legend.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Legend = boolean | null; | ||
|
||
export interface WithLegend { | ||
legend?: Legend; | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/superset-ui-preset-chart-xy/src/encodeable/types/Scale.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ScaleType } from 'vega-lite/build/src/scale'; | ||
import { Value } from 'vega-lite/build/src/fielddef'; | ||
|
||
export { ScaleType, Value }; | ||
|
||
export interface Scale<V extends Value = Value> { | ||
type?: ScaleType; | ||
domain?: any[]; | ||
range?: V[]; | ||
scheme?: string; | ||
} | ||
|
||
export interface WithScale<V extends Value = Value> { | ||
scale?: Scale<V>; | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/superset-ui-preset-chart-xy/src/encodeable/types/Spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface BaseOptions { | ||
namespace?: string; | ||
} | ||
|
||
export interface PartialSpec<Encoding, Options extends BaseOptions = BaseOptions> { | ||
encoding: Partial<Encoding>; | ||
options?: Options; | ||
} | ||
|
||
export interface FullSpec<Encoding, Options extends BaseOptions = BaseOptions> { | ||
encoding: Encoding; | ||
options?: Options; | ||
} |