-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(template): add plot template (#1497)
- Loading branch information
Showing
5 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
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,51 @@ | ||
import { interaction, animation, theme, scale } from '../../adaptor/common'; | ||
import { Params } from '../../core/adaptor'; | ||
import { flow } from '../../utils'; | ||
import { TemplateOptions } from './types'; | ||
|
||
/** | ||
* geometry 处理 | ||
* @param params | ||
*/ | ||
function geometry(params: Params<TemplateOptions>): Params<TemplateOptions> { | ||
const { chart, options } = params; | ||
const { data, xField, yField } = options; | ||
|
||
chart.data(data); | ||
|
||
chart.interval().position(`${xField}*${yField}`); | ||
|
||
return params; | ||
} | ||
|
||
/** | ||
* meta 配置 | ||
* @param params | ||
*/ | ||
export function meta(params: Params<TemplateOptions>): Params<TemplateOptions> { | ||
const { options } = params; | ||
const { xAxis, yAxis, xField, yField } = options; | ||
|
||
return flow( | ||
scale({ | ||
[xField]: xAxis, | ||
[yField]: yAxis, | ||
}) | ||
)(params); | ||
} | ||
/** | ||
* 折线图适配器 | ||
* @param chart | ||
* @param options | ||
*/ | ||
export function adaptor(params: Params<TemplateOptions>) { | ||
// flow 的方式处理所有的配置到 G2 API | ||
return flow( | ||
geometry, | ||
meta, | ||
interaction, | ||
animation, | ||
theme | ||
// ... 其他的 adaptor flow | ||
)(params); | ||
} |
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,21 @@ | ||
import { Plot } from '../../core/plot'; | ||
import { TemplateOptions } from './types'; | ||
import { adaptor } from './adaptor'; | ||
import { Adaptor } from '../../core/adaptor'; | ||
|
||
export { TemplateOptions }; | ||
|
||
/** | ||
* 这个是一个图表开发的 模板代码! | ||
*/ | ||
export class Template extends Plot<TemplateOptions> { | ||
/** 图表类型 */ | ||
public type: string = 'template'; | ||
|
||
/** | ||
* 获取适配器 | ||
*/ | ||
protected getSchemaAdaptor(): Adaptor<TemplateOptions> { | ||
return adaptor; | ||
} | ||
} |
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,9 @@ | ||
import { Options } from '../../types'; | ||
|
||
/** 配置类型定义 */ | ||
export interface TemplateOptions extends Options { | ||
/** x 轴字段 */ | ||
readonly xField?: string; | ||
/** y 轴字段 */ | ||
readonly yField?: string; | ||
} |
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
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