Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VirusPC committed Nov 11, 2021
1 parent 669c5de commit c3b3ec0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ declare const x: number;
declare const y: number;

const computor: Computor = excentricLabeling();
computor.labelWidth(20)
.labelHeight(5)
computor.defaultLabelWidth(20)
.defaultLabelHeight(5)
.radius(10)

const result= computor(rawData, x, y)
```

### Input

`RawInfo[]`, the position of points. User can specify the width and/or height for the point. Otherwise, the algorithm will use the width and height from settings: `computor.labelWidth(20)`, `computor.labelHeight(10)`.
`RawInfo[]`, the position of points. User can specify the width and/or height for the point. Otherwise, the algorithm will use the width and height from settings: `computor.defaultLabelWidth(20)`, `computor.defaultLabelHeight(10)`.

```ts
type RawInfo = {
Expand Down Expand Up @@ -100,9 +100,9 @@ interface Computer {
// if isInfosFiltered equals true, then computer will filter out the elements outside the lens
(rawInfos: RawInfo[], cx: number, cy: number, isInfosFiltered: boolean): LayoutInfo[];
elementsNumInLens: (() => number);
labelWidth: (() => number)
defaultLabelWidth: (() => number)
& ((size: number) => Computer);
labelHeight: (() => number)
defaultLabelHeight: (() => number)
& ((size: number) => Computer);
radius: (() => number)
& ((radius: number) => Computer);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "excentric-labeling",
"version": "3.0.0",
"version": "3.0.1",
"description": "An layout algorithm about the exentric labeling interaction technique",
"type": "commonjs",
"main": "dist/index.js",
Expand Down
46 changes: 23 additions & 23 deletions src/excentric-labeling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type LayoutInfo = {
interface Computer {
(rawInfos: RawInfo[], cx: number, cy: number, isInfosFiltered: boolean): LayoutInfo[];
elementsNumInLens: (() => number);
labelWidth: (() => number)
defaultLabelWidth: (() => number)
& ((size: number) => Computer);
labelHeight: (() => number)
defaultLabelHeight: (() => number)
& ((size: number) => Computer);
radius: (() => number)
& ((radius: number) => Computer);
Expand Down Expand Up @@ -65,16 +65,16 @@ export default function excentricLabeling(): Computer {
let _spaceBetweenLabels = 3;
let _leftSpace = 20;
let _rightSpace = 20;
let _labelWidth = 20;
let _labelHeight = 10;
let _defaultLabelWidth = 20;
let _defaultLabelHeight = 10;
let _elementsNumInLens = 0;

const computeExcentricLabelingLayout: Computer = (rawInfos: RawInfo[], cx: number, cy: number, isInfosFiltered:boolean = false) => {
let filteredRawInfos = rawInfos;
if(!isInfosFiltered) filteredRawInfos = filterElementsInLens(filteredRawInfos, cx, cy, _radius);
_elementsNumInLens = filteredRawInfos.length;
filteredRawInfos = filterElementsWithMaxNumber(filteredRawInfos, _maxLabelsNum);
const layoutInfos = initLayoutInfos(filteredRawInfos, _labelWidth, _labelHeight);
const layoutInfos = initLayoutInfos(filteredRawInfos, _defaultLabelWidth, _defaultLabelHeight);
computeStartPoints(layoutInfos);
if (!_verticallyCoherent) computePointsOnLens(layoutInfos, cx, cy, _radius);
dividedIntoLeftOrRight(layoutInfos, cx, cy);
Expand All @@ -88,19 +88,19 @@ export default function excentricLabeling(): Computer {
return _elementsNumInLens;
}

function labelWidth(): number;
function labelWidth(labelWidth: number): Computer;
function labelWidth(labelWidth?: number) {
if (labelWidth === undefined) return _labelWidth;
_labelWidth = labelWidth;
function defaultLabelWidth(): number;
function defaultLabelWidth(defaultLabelWidth: number): Computer;
function defaultLabelWidth(defaultLabelWidth?: number) {
if (defaultLabelWidth === undefined) return _defaultLabelWidth;
_defaultLabelWidth = defaultLabelWidth;
return computeExcentricLabelingLayout;
};

function labelHeight(): number;
function labelHeight(labelHeight: number): Computer;
function labelHeight(labelHeight?: number) {
if (labelHeight === undefined) return _labelHeight;
_labelHeight = labelHeight;
function defaultLabelHeight(): number;
function defaultLabelHeight(defaultLabelHeight: number): Computer;
function defaultLabelHeight(defaultLabelHeight?: number) {
if (defaultLabelHeight === undefined) return _defaultLabelHeight;
_defaultLabelHeight = defaultLabelHeight;
return computeExcentricLabelingLayout;
};

Expand Down Expand Up @@ -177,8 +177,8 @@ export default function excentricLabeling(): Computer {
computeExcentricLabelingLayout.elementsNumInLens = elementsNumInLens;
computeExcentricLabelingLayout.radius = radius;
computeExcentricLabelingLayout.maxLabelsNum = maxLabelsNum;
computeExcentricLabelingLayout.labelWidth = labelWidth;
computeExcentricLabelingLayout.labelHeight = labelHeight;
computeExcentricLabelingLayout.defaultLabelWidth = defaultLabelWidth;
computeExcentricLabelingLayout.defaultLabelHeight = defaultLabelHeight;
computeExcentricLabelingLayout.verticallyCoherent = verticallyCoherent;
computeExcentricLabelingLayout.horizontallyCoherent = horizontallyCoherent;
computeExcentricLabelingLayout.spaceBetweenLabels = spaceBetweenLabels;
Expand All @@ -200,12 +200,12 @@ function filterElementsWithMaxNumber(rawInfos: RawInfo[], maxLabelsNum: number)
return rawInfos.slice(0, maxLabelsNum);
}

function initLayoutInfos(rawInfos: RawInfo[], _labelWidth: number, _labelHeight: number): LayoutInfo[] {
return rawInfos.map((rawInfo) => initLayoutInfo(rawInfo, _labelWidth, _labelHeight));
function initLayoutInfos(rawInfos: RawInfo[], _defaultLabelWidth: number, _defaultLabelHeight: number): LayoutInfo[] {
return rawInfos.map((rawInfo) => initLayoutInfo(rawInfo, _defaultLabelWidth, _defaultLabelHeight));
}

function initLayoutInfo(rawInfo: RawInfo, _labelWidth: number, _labelHeight: number): LayoutInfo {
const { x, y, labelWidth, labelHeight } = rawInfo
function initLayoutInfo(rawInfo: RawInfo, _defaultLabelWidth: number, _defaultLabelHeight: number): LayoutInfo {
const { x, y, defaultLabelWidth, defaultLabelHeight } = rawInfo
return {
x, y,
//name: labelName,
Expand All @@ -214,8 +214,8 @@ function initLayoutInfo(rawInfo: RawInfo, _labelWidth: number, _labelHeight: num
labelBBox: {
x: 0,
y: 0,
width: labelWidth ?? _labelWidth,
height: labelHeight ?? _labelHeight,
width: defaultLabelWidth ?? _defaultLabelWidth,
height: defaultLabelHeight ?? _defaultLabelHeight,
},
rawInfo: rawInfo
}
Expand Down

0 comments on commit c3b3ec0

Please sign in to comment.