-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 2021_03_17-expose_datum_to_tooltip
- Loading branch information
Showing
26 changed files
with
1,725 additions
and
1 deletion.
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
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
Binary file added
BIN
+180 KB
...-all-stories-wordcloud-alpha-simple-wordcloud-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,52 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ConfigItem, configMap } from '../../../../common/config_objects'; | ||
import { Config } from '../types/config_types'; | ||
|
||
/** @internal */ | ||
export const configMetadata: Record<string, ConfigItem> = { | ||
// shape geometry | ||
width: { dflt: 300, min: 0, max: 1024, type: 'number', reconfigurable: false }, | ||
height: { dflt: 150, min: 0, max: 1024, type: 'number', reconfigurable: false }, | ||
margin: { | ||
type: 'group', | ||
values: { | ||
left: { dflt: 0, min: -0.25, max: 0.25, type: 'number' }, | ||
right: { dflt: 0, min: -0.25, max: 0.25, type: 'number' }, | ||
top: { dflt: 0, min: -0.25, max: 0.25, type: 'number' }, | ||
bottom: { dflt: 0, min: -0.25, max: 0.25, type: 'number' }, | ||
}, | ||
}, | ||
|
||
// general text config | ||
fontFamily: { | ||
dflt: 'Impact', | ||
type: 'string', | ||
}, | ||
|
||
// fill text config | ||
minFontSize: { dflt: 10, min: 10, max: 50, type: 'number', reconfigurable: true }, | ||
maxFontSize: { dflt: 70, min: 15, max: 150, type: 'number', reconfigurable: true }, | ||
|
||
backgroundColor: { dflt: '#ffffff', type: 'color' }, | ||
sectorLineWidth: { dflt: 1, min: 0, max: 4, type: 'number' }, | ||
}; | ||
|
||
export const config: Config = configMap<Config>((item: ConfigItem) => item.dflt, configMetadata); |
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,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Pixels, SizeRatio } from '../../../../common/geometry'; | ||
import { FontFamily } from '../../../../common/text_utils'; | ||
|
||
// todo switch to `io-ts` style, generic way of combining static and runtime type info | ||
/** potential internal */ | ||
export interface Config { | ||
// shape geometry | ||
width: number; | ||
height: number; | ||
margin: { left: SizeRatio; right: SizeRatio; top: SizeRatio; bottom: SizeRatio }; | ||
|
||
// general text config | ||
fontFamily: FontFamily; | ||
|
||
// fill text config | ||
minFontSize: Pixels; | ||
maxFontSize: Pixels; | ||
} |
162 changes: 162 additions & 0 deletions
162
src/chart_types/wordcloud/layout/types/viewmodel_types.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,162 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { $Values as Values } from 'utility-types'; | ||
|
||
import { Pixels, PointObject } from '../../../../common/geometry'; | ||
import { Color } from '../../../../utils/common'; | ||
import { Logger } from '../../../../utils/logger'; | ||
import { config } from '../config/config'; | ||
import { Config } from './config_types'; | ||
|
||
/** @public */ | ||
export interface WordModel { | ||
text: string; | ||
weight: number; | ||
color: Color; | ||
} | ||
|
||
export const WeightFun = Object.freeze({ | ||
log: 'log' as const, | ||
linear: 'linear' as const, | ||
exponential: 'exponential' as const, | ||
squareRoot: 'squareRoot' as const, | ||
}); | ||
|
||
/** @public */ | ||
export type WeightFun = Values<typeof WeightFun>; | ||
|
||
/** @internal */ | ||
export interface Word { | ||
color: string; | ||
font: string; | ||
fontFamily: string; | ||
fontWeight: number; | ||
hasText: boolean; | ||
height: number; | ||
padding: number; | ||
rotate: number; | ||
size: number; | ||
style: string; | ||
text: string; | ||
weight: number; | ||
x: number; | ||
x0: number; | ||
x1: number; | ||
xoff: number; | ||
y: number; | ||
y0: number; | ||
y1: number; | ||
yoff: number; | ||
} | ||
|
||
/** @internal */ | ||
export interface Configs { | ||
count: number; | ||
endAngle: number; | ||
exponent: number; | ||
fontFamily: string; | ||
fontStyle: string; | ||
fontWeight: number; | ||
height: number; | ||
maxFontSize: number; | ||
minFontSize: number; | ||
padding: number; | ||
spiral: string; | ||
startAngle: number; | ||
weightFun: WeightFun; | ||
width: number; | ||
} | ||
|
||
export type OutOfRoomCallback = (wordCount: number, renderedWordCount: number, renderedWords: string[]) => void; | ||
|
||
/** @internal */ | ||
export interface WordcloudViewModel { | ||
startAngle: number; | ||
endAngle: number; | ||
angleCount: number; | ||
padding: number; | ||
fontWeight: number; | ||
fontFamily: string; | ||
fontStyle: string; | ||
minFontSize: number; | ||
maxFontSize: number; | ||
spiral: string; | ||
exponent: number; | ||
data: WordModel[]; | ||
weightFun: WeightFun; | ||
outOfRoomCallback: OutOfRoomCallback; | ||
// specType: string; | ||
} | ||
|
||
/** @internal */ | ||
export interface Datum { | ||
text: string; | ||
weight: number; | ||
color: string; | ||
} | ||
|
||
/** @internal */ | ||
export type PickFunction = (x: Pixels, y: Pixels) => Array<WordcloudViewModel>; | ||
|
||
/** @internal */ | ||
export type ShapeViewModel = { | ||
config: Config; | ||
wordcloudViewModel: WordcloudViewModel; | ||
chartCenter: PointObject; | ||
pickQuads: PickFunction; | ||
}; | ||
|
||
const commonDefaults: WordcloudViewModel = { | ||
startAngle: -20, | ||
endAngle: 20, | ||
angleCount: 5, | ||
padding: 2, | ||
fontWeight: 300, | ||
fontFamily: 'Impact', | ||
fontStyle: 'italic', | ||
minFontSize: 10, | ||
maxFontSize: 50, | ||
spiral: 'archimedean', | ||
exponent: 3, | ||
data: [], | ||
weightFun: 'exponential', | ||
outOfRoomCallback: (wordCount, renderedWordCount) => { | ||
Logger.warn(`Not all words have been placed: ${renderedWordCount} words rendered out of ${wordCount}`); | ||
}, | ||
}; | ||
|
||
/** @internal */ | ||
export const defaultWordcloudSpec = { | ||
...commonDefaults, | ||
}; | ||
|
||
/** @internal */ | ||
export const nullWordcloudViewModel: WordcloudViewModel = { | ||
...commonDefaults, | ||
data: [], | ||
}; | ||
|
||
/** @internal */ | ||
export const nullShapeViewModel = (specifiedConfig?: Config, chartCenter?: PointObject): ShapeViewModel => ({ | ||
config: specifiedConfig || config, | ||
wordcloudViewModel: nullWordcloudViewModel, | ||
chartCenter: chartCenter || { x: 0, y: 0 }, | ||
pickQuads: () => [], | ||
}); |
Oops, something went wrong.