Skip to content

Commit

Permalink
build(prettier): support optional chain with TS 3.7
Browse files Browse the repository at this point in the history
fix #46
  • Loading branch information
xiaoiver committed Nov 12, 2019
1 parent 89424b8 commit 00493b8
Show file tree
Hide file tree
Showing 21 changed files with 8,217 additions and 727 deletions.
6 changes: 2 additions & 4 deletions package.json
Expand Up @@ -50,6 +50,7 @@
"enzyme-adapter-react-16": "^1.5.0",
"enzyme-to-json": "^3.0.0-beta6",
"gatsby": "^2.17.7",
"geotiff": "^1.0.0-beta.6",
"gh-pages": "^2.1.1",
"gl": "^4.4.0",
"html-webpack-plugin": "^3.2.0",
Expand All @@ -62,7 +63,7 @@
"npm-run-all": "^4.1.5",
"postcss": "^7.0.18",
"postcss-plugin": "^1.0.0",
"prettier": "^1.18.2",
"prettier": "^1.19.1",
"raw-loader": "^1.0.0",
"react": "^16.8.6",
"react-docgen-typescript-loader": "^3.1.0",
Expand Down Expand Up @@ -129,8 +130,5 @@
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"dependencies": {
"geotiff": "^1.0.0-beta.6"
}
}
3 changes: 2 additions & 1 deletion packages/component/src/control/layer.ts
Expand Up @@ -220,7 +220,8 @@ export default class Layers extends Control {

const obj = this.layerService.getLayer(e.target.layerId);

const type = obj.overlay
// @ts-ignore
const type = obj?.overlay
? e.type === 'add'
? 'overlayadd'
: 'overlayremove'
Expand Down
10 changes: 1 addition & 9 deletions packages/core/src/services/layer/LayerService.ts
Expand Up @@ -17,10 +17,6 @@ export default class LayerService implements ILayerService {

public add(layer: ILayer) {
this.layers.push(layer);
this.initPlugin(layer);
layer.init();
// 添加完成需要触发重绘
// this.renderLayers();
}

public initLayers() {
Expand Down Expand Up @@ -75,11 +71,7 @@ export default class LayerService implements ILayerService {
this.layers.forEach((layer) => layer.destroy());
this.layers = [];
}
private initPlugin(layer: ILayer) {
for (const plugin of layer.plugins) {
plugin.apply(layer);
}
}

private clear() {
this.renderService.clear({
color: [0, 0, 0, 0],
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/services/layer/StyleAttributeService.ts
Expand Up @@ -4,7 +4,7 @@ import { gl } from '../renderer/gl';
import { IAttribute } from '../renderer/IAttribute';
import { IElements } from '../renderer/IElements';
import { IRendererService } from '../renderer/IRendererService';
import { IParseDataItem } from '../source/ISourceService'
import { IParseDataItem } from '../source/ISourceService';
import { ILayer } from './ILayerService';
import {
IEncodeFeature,
Expand Down Expand Up @@ -216,10 +216,11 @@ export default class StyleAttributeService implements IStyleAttributeService {
) {
descriptors.forEach((descriptor, attributeIdx) => {
if (descriptor && descriptor.update) {
const normal = normalsForCurrentFeature?.slice(
vertexIdx * 3,
vertexIdx * 3 + 3,
)|| [];
const normal =
normalsForCurrentFeature?.slice(
vertexIdx * 3,
vertexIdx * 3 + 3,
) || [];
(descriptor.buffer.data as number[]).push(
...descriptor.update(
feature,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/services/map/IMapService.ts
Expand Up @@ -20,9 +20,9 @@ export interface IMapService {
getMarkerContainer(): HTMLElement;
// MapEvent // 定义事件类型

on(type: string, hander: (...args: any[]) => void): void;
off(type: string, hander: (...args: any[]) => void): void;
once(type: string, hander: (...args: any[]) => void): void;
on(type: string, handler: (...args: any[]) => void): void;
off(type: string, handler: (...args: any[]) => void): void;
once(type: string, handler: (...args: any[]) => void): void;
// get dom
getContainer(): HTMLElement | null;
getSize(): [number, number];
Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/services/renderer/passes/PixelPickingPass.ts
Expand Up @@ -24,7 +24,8 @@ function decodePickingColor(color: Uint8Array): number {
* @see https://github.com/antvis/L7/blob/next/dev-docs/PixelPickingEngine.md
*/
@injectable()
export default class PixelPickingPass<InitializationOptions = {}> implements IPass<InitializationOptions> {
export default class PixelPickingPass<InitializationOptions = {}>
implements IPass<InitializationOptions> {
@lazyInject(TYPES.IRendererService)
protected readonly rendererService: IRendererService;

Expand Down Expand Up @@ -132,7 +133,12 @@ export default class PixelPickingPass<InitializationOptions = {}> implements IPa

const xInDevicePixel = x * window.devicePixelRatio;
const yInDevicePixel = y * window.devicePixelRatio;
if (xInDevicePixel > width || xInDevicePixel < 0 || yInDevicePixel > height || yInDevicePixel < 0) {
if (
xInDevicePixel > width ||
xInDevicePixel < 0 ||
yInDevicePixel > height ||
yInDevicePixel < 0
) {
return;
}

Expand Down Expand Up @@ -214,7 +220,9 @@ export default class PixelPickingPass<InitializationOptions = {}> implements IPa
const { clear, useFramebuffer } = this.rendererService;

// 先输出到 PostProcessor
const readFBO = this.layer.multiPassRenderer.getPostProcessor().getReadFBO();
const readFBO = this.layer.multiPassRenderer
.getPostProcessor()
.getReadFBO();
this.layer.hooks.beforeRender.call();
useFramebuffer(readFBO, () => {
clear({
Expand Down
22 changes: 12 additions & 10 deletions packages/core/src/services/scene/SceneService.ts
Expand Up @@ -59,7 +59,8 @@ export default class Scene extends EventEmitter implements ISceneService {
/**
* 是否首次渲染
*/
private inited: boolean;
private inited: boolean = false;
private initPromise: Promise<void>;

/**
* canvas 容器
Expand Down Expand Up @@ -87,6 +88,8 @@ export default class Scene extends EventEmitter implements ISceneService {
public init(globalConfig: IGlobalConfig) {
this.initClear();
this.configService.setAndCheckConfig(globalConfig);
// 初始化 ShaderModule
this.shaderModule.registerBuiltinModules();

// 初始化资源管理 图片
this.iconService.init();
Expand Down Expand Up @@ -134,34 +137,33 @@ export default class Scene extends EventEmitter implements ISceneService {
this.logger.error('容器 id 不存在');
}

// 初始化 ShaderModule
this.shaderModule.registerBuiltinModules();

// 初始化 container 上的交互
this.interactionService.init();

this.logger.info('renderer loaded');
});

// TODO:init worker, fontAtlas...

// 执行异步并行初始化任务
this.initPromise = this.hooks.init.promise(this.configService.getConfig());
}

public addLayer(layer: ILayer) {
this.logger.info(`add layer ${layer.name}`);

this.layerService.add(layer);
}

public async render() {
// 首次初始化,或者地图的容器被强制销毁的需要重新初始化
if (!this.inited) {
// 首次渲染需要等待底图、相机初始化
await this.hooks.init.promise(this.configService.getConfig());
// 初始化marker 容器
// 还未初始化完成需要等待
await this.initPromise;
// 初始化 marker 容器 TODO: 可以放到 map 初始化方法中?
this.map.addMarkerContainer();
this.inited = true;
this.layerService.initLayers();

this.layerService.renderLayers();
this.inited = true;
this.emit('loaded');
}

Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/utils/vertex-compression.ts
Expand Up @@ -85,7 +85,12 @@ export function packCircleVertex(
packUint8ToFloat(strokeColor[2], strokeColor[3]),
];

[[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(([extrudeX, extrudeY]) => {
[
[-1, -1],
[1, -1],
[1, 1],
[-1, 1],
].forEach(([extrudeX, extrudeY]) => {
// vec4(
// color,
// color,
Expand Down
15 changes: 5 additions & 10 deletions packages/layers/src/core/BaseLayer.ts
Expand Up @@ -52,9 +52,7 @@ let layerIdCounter = 0;
/**
* Layer 基类默认样式属性
*/
const defaultLayerInitializationOptions: Partial<
ILayerInitializationOptions
> = {
const defaultLayerInitializationOptions: Partial<ILayerInitializationOptions> = {
minZoom: 0,
maxZoom: 20,
visible: true,
Expand Down Expand Up @@ -142,12 +140,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
>;
private scaleOptions: IScaleOptions = {};

private enodeOptions: {
[type: string]: {
field: string;
};
};

@lazyInject(TYPES.IInteractionService)
private readonly interactionService: IInteractionService;

Expand Down Expand Up @@ -343,7 +335,10 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
public fitBounds(): void {
const source = this.getSource();
const extent = source.extent;
this.map.fitBounds([[extent[0], extent[1]], [extent[2], extent[3]]]);
this.map.fitBounds([
[extent[0], extent[1]],
[extent[2], extent[3]],
]);
}

public destroy() {
Expand Down
6 changes: 3 additions & 3 deletions packages/layers/src/core/triangulation.ts
Expand Up @@ -83,9 +83,9 @@ export function PolygonExtrudeTriangulation(feature: IEncodeFeature) {
export function HeatmapGridTriangulation(feature: IEncodeFeature) {
const { shape } = feature;

const { positions, index } = getHeatmapGeometry(shape as
| ShapeType2D
| ShapeType3D);
const { positions, index } = getHeatmapGeometry(
shape as ShapeType2D | ShapeType3D,
);
return {
vertices: positions, // [ x, y, z ] 多边形顶点
indices: index,
Expand Down
5 changes: 4 additions & 1 deletion packages/layers/src/plugins/DataMappingPlugin.ts
Expand Up @@ -89,7 +89,10 @@ export default class DataMappingPlugin implements ILayerPlugin {
const params: unknown[] = [];

scalers.forEach(({ field }) => {
if (record.hasOwnProperty(field) || attribute.scale?.type ==='variable') {
if (
record.hasOwnProperty(field) ||
attribute.scale?.type === 'variable'
) {
params.push(record[field]);
}
});
Expand Down
44 changes: 21 additions & 23 deletions packages/layers/src/plugins/FeatureScalePlugin.ts
Expand Up @@ -43,12 +43,12 @@ export default class FeatureScalePlugin implements ILayerPlugin {
@inject(TYPES.ILogService)
private readonly logger: ILogService;

// key = field_attribute name
// key = field_attribute name
private scaleCache: {
[field: string]: IStyleScale;
} = {};

private scaleOptions: IScaleOptions = {}
private scaleOptions: IScaleOptions = {};

public apply(layer: ILayer) {
layer.hooks.init.tap('FeatureScalePlugin', () => {
Expand Down Expand Up @@ -83,11 +83,12 @@ export default class FeatureScalePlugin implements ILayerPlugin {
if (attribute.scale) {
// 创建Scale
const attributeScale = attribute.scale;
attributeScale.names= this.parseFields(attribute!.scale!.field || []);
const scales: IStyleScale[] = attributeScale.names
.map((field:string) => {
return this.getOrCreateScale(field, attribute, dataArray);
})
attributeScale.names = this.parseFields(attribute!.scale!.field || []);
const scales: IStyleScale[] = attributeScale.names.map(
(field: string) => {
return this.getOrCreateScale(field, attribute, dataArray);
},
);

// 为scales 设置值区间
if (scales.some((scale) => scale.type === StyleScaleType.VARIABLE)) {
Expand All @@ -106,24 +107,23 @@ export default class FeatureScalePlugin implements ILayerPlugin {
});
}

attributeScale.scalers = scales.map((scale: IStyleScale)=> {
attributeScale.scalers = scales.map((scale: IStyleScale) => {
return {
field: scale.field,
func: scale.scale,
}
};
});

attribute.needRescale = false;
}

});
}
private getOrCreateScale(
field: string,
attribute: IStyleAttribute,
dataArray: IParseDataItem[],
) {
const scalekey = [field,attribute.name].join('_')
const scalekey = [field, attribute.name].join('_');
if (this.scaleCache[scalekey]) {
return this.scaleCache[scalekey];
}
Expand All @@ -134,11 +134,11 @@ export default class FeatureScalePlugin implements ILayerPlugin {
styleScale.type === StyleScaleType.VARIABLE &&
attribute.scale?.values &&
attribute.scale?.values.length > 0
) { // 只有变量初始化range
) {
// 只有变量初始化range
styleScale.scale.range(attribute.scale?.values);
}


return this.scaleCache[scalekey];
}

Expand All @@ -161,13 +161,12 @@ export default class FeatureScalePlugin implements ILayerPlugin {
// 首先查找全局默认配置例如 color
const scaleOption: IScale | undefined = this.scaleOptions[field];
const styleScale: IStyleScale = {
field,
scale: undefined,
type: StyleScaleType.VARIABLE,
option: scaleOption,
};
field,
scale: undefined,
type: StyleScaleType.VARIABLE,
option: scaleOption,
};
if (!data || !data.length) {

if (scaleOption && scaleOption.type) {
styleScale.scale = this.createDefaultScale(scaleOption);
} else {
Expand All @@ -176,7 +175,7 @@ export default class FeatureScalePlugin implements ILayerPlugin {
}
return styleScale;
}
const firstValue = (data!.find((d) => !isNil(d[field])))?.[field]
const firstValue = data!.find((d) => !isNil(d[field]))?.[field];
// 常量 Scale
if (isNumber(field) || (isNil(firstValue) && !scaleOption)) {
styleScale.scale = d3.scaleOrdinal([field]);
Expand All @@ -190,7 +189,6 @@ export default class FeatureScalePlugin implements ILayerPlugin {
Object.assign(cfg, scaleOption);
styleScale.scale = this.createDefaultScale(cfg);
styleScale.option = cfg;

}
return styleScale;
}
Expand All @@ -217,8 +215,8 @@ export default class FeatureScalePlugin implements ILayerPlugin {
cfg.domain = extent(values);
} else if (type === ScaleTypes.CAT) {
cfg.domain = uniq(values);
} else if(type === ScaleTypes.QUANTILE) {
cfg.domain = values
} else if (type === ScaleTypes.QUANTILE) {
cfg.domain = values;
}
return cfg;
}
Expand Down

0 comments on commit 00493b8

Please sign in to comment.