Skip to content

Commit

Permalink
feat: migrate-dumi-theme-antv (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangying1027 committed Nov 18, 2022
1 parent 516854f commit 7a758ed
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 671 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
"silent": false
},
"resolutions": {
"monaco-editor": "0.20.0",
"monaco-editor-webpack-plugin": "1.9.1",
"react-monaco-editor": "0.34.0",
"signal-exit": "3.0.3"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { isFunction, each, upperFirst, mix, groupToMap, isObject, flatten } from '@antv/util';
import Selection, { SelectionState } from './selection';
import { Adjust, getAdjust } from '../../deps/f2-adjust/src';
import { Adjust, Dodge, Jitter, Stack, Symmetric } from '../../deps/f2-adjust/src';
import { toTimeStamp } from '../../util/index';
import { GeomType, GeometryProps, GeometryAdjust } from './interface';
import AttrController from '../../controller/attr';
import { Scale } from '../../deps/f2-scale/src';
import { AnimationProps, isEqual } from '@antv/f-engine';

const AdjustMap = {
'Stack': Stack,
'Dodge': Dodge,
'Jitter': Jitter,
'Symmetric': Symmetric
}
// 保留原始数据的字段
const FIELD_ORIGIN = 'origin';

Expand Down Expand Up @@ -243,7 +249,7 @@ class Geometry<
}
: adjust;
const adjustType = upperFirst(adjustCfg.type);
const AdjustConstructor = getAdjust(adjustType);
const AdjustConstructor = AdjustMap[adjustType];
if (!AdjustConstructor) {
throw new Error('not support such adjust : ' + adjust);
}
Expand Down
1 change: 1 addition & 0 deletions packages/f2/src/components/guide/views/Lottie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default (props: LottieGuideProps, context) => {
const posY = y + (offsetYNum || 0) - width / 2;

return (
// @ts-ignore
<Lottie
data={lottieJson}
options={option}
Expand Down
33 changes: 0 additions & 33 deletions packages/f2/src/deps/f2-adjust/src/factory.ts

This file was deleted.

10 changes: 1 addition & 9 deletions packages/f2/src/deps/f2-adjust/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { getAdjust, registerAdjust } from './factory';

import Adjust from './adjusts/adjust';

import Dodge from './adjusts/dodge';
import Jitter from './adjusts/jitter';
import Stack from './adjusts/stack';
import Symmetric from './adjusts/symmetric';

// 注册内置的 adjust
registerAdjust('Dodge', Dodge);
registerAdjust('Jitter', Jitter);
registerAdjust('Stack', Stack);
registerAdjust('Symmetric', Symmetric);

// 最终暴露给外部的方法
export { getAdjust, registerAdjust, Adjust };
export { Adjust, Dodge, Jitter, Stack, Symmetric };

export * from './interface';
208 changes: 208 additions & 0 deletions packages/site/.dumi/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
require('../site/global.less');

if (window) {
window.f2 = require('../src/f2').default;
window.f2React = require('../src/f2-react').default;
window.React = require('react');
window.ReactDOM = require('react-dom');
// window.f2 = require('./src/index-all.js');
// window.DataSet = require('@antv/data-set');
window.lodash = require('lodash');
// window.$ = require('jquery');

/* eslint-disable */
window.initPlayground = () => {
/**
* 模拟移动端 touch 事件
*/
var eventTarget;

// polyfills
if (!document.createTouch) {
document.createTouch = function(view, target, identifier, pageX, pageY, screenX, screenY) {
// auto set
return new Touch(
target,
identifier,
{
pageX: pageX,
pageY: pageY,
screenX: screenX,
screenY: screenY,
clientX: pageX - window.pageXOffset,
clientY: pageY - window.pageYOffset,
},
0,
0
);
};
}

if (!document.createTouchList) {
document.createTouchList = function() {
var touchList = TouchList();
for (var i = 0; i < arguments.length; i++) {
touchList[i] = arguments[i];
}
touchList.length = arguments.length;
return touchList;
};
}

/**
* create an touch point
* @constructor
* @param target
* @param identifier
* @param pos
* @param deltaX
* @param deltaY
* @returns {Object} touchPoint
*/

var Touch = function Touch(target, identifier, pos, deltaX, deltaY) {
deltaX = deltaX || 0;
deltaY = deltaY || 0;

this.identifier = identifier;
this.target = target;
this.clientX = pos.clientX + deltaX;
this.clientY = pos.clientY + deltaY;
this.screenX = pos.screenX + deltaX;
this.screenY = pos.screenY + deltaY;
this.pageX = pos.pageX + deltaX;
this.pageY = pos.pageY + deltaY;
};

/**
* create empty touchlist with the methods
* @constructor
* @returns touchList
*/
function TouchList() {
var touchList = [];

touchList['item'] = function(index) {
return this[index] || null;
};

// specified by Mozilla
touchList['identifiedTouch'] = function(id) {
return this[id + 1] || null;
};

return touchList;
}

/**
* Simple trick to fake touch event support
* this is enough for most libraries like Modernizr and Hammer
*/
function fakeTouchSupport() {
var objs = [window, document.documentElement];
var props = ['ontouchstart', 'ontouchmove', 'ontouchcancel', 'ontouchend'];

for (var o = 0; o < objs.length; o++) {
for (var p = 0; p < props.length; p++) {
if (objs[o] && objs[o][props[p]] === undefined) {
objs[o][props[p]] = null;
}
}
}
}

/**
* only trigger touches when the left mousebutton has been pressed
* @param touchType
* @returns {Function}
*/
function onMouse(touchType) {
return function(ev) {
// prevent mouse events

if (ev.which !== 1) {
return;
}

// The EventTarget on which the touch point started when it was first placed on the surface,
// even if the touch point has since moved outside the interactive area of that element.
// also, when the target doesnt exist anymore, we update it
if (
ev.type === 'mousedown' ||
!eventTarget ||
(eventTarget && !eventTarget.dispatchEvent)
) {
eventTarget = ev.target;
}

triggerTouch(touchType, ev);

// reset
if (ev.type === 'mouseup') {
eventTarget = null;
}
};
}

/**
* trigger a touch event
* @param eventName
* @param mouseEv
*/
function triggerTouch(eventName, mouseEv) {
var touchEvent = document.createEvent('Event');
touchEvent.initEvent(eventName, true, true);

touchEvent.altKey = mouseEv.altKey;
touchEvent.ctrlKey = mouseEv.ctrlKey;
touchEvent.metaKey = mouseEv.metaKey;
touchEvent.shiftKey = mouseEv.shiftKey;

touchEvent.touches = getActiveTouches(mouseEv);
touchEvent.targetTouches = getActiveTouches(mouseEv);
touchEvent.changedTouches = createTouchList(mouseEv);

eventTarget.dispatchEvent(touchEvent);
}

/**
* create a touchList based on the mouse event
* @param mouseEv
* @returns {TouchList}
*/
function createTouchList(mouseEv) {
var touchList = TouchList();
touchList.push(new Touch(eventTarget, 1, mouseEv, 0, 0));
return touchList;
}

/**
* receive all active touches
* @param mouseEv
* @returns {TouchList}
*/
function getActiveTouches(mouseEv) {
// empty list
if (mouseEv.type === 'mouseup') {
return TouchList();
}
return createTouchList(mouseEv);
}

/**
* TouchEmulator initializer
*/
function TouchEmulator() {
fakeTouchSupport();

window.addEventListener('mousedown', onMouse('touchstart'), true);
window.addEventListener('mousemove', onMouse('touchmove'), true);
window.addEventListener('mouseup', onMouse('touchend'), true);
}

// start distance when entering the multitouch mode
TouchEmulator['multiTouchOffset'] = 75;

new TouchEmulator();
};
}
Loading

0 comments on commit 7a758ed

Please sign in to comment.