Skip to content

Commit

Permalink
Merge branch 'master' into 2021_03_17-expose_datum_to_tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Mar 23, 2021
2 parents 6872fe1 + f08f4c9 commit d114d1d
Show file tree
Hide file tree
Showing 26 changed files with 1,725 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .playground/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';

import { Example } from '../stories/icicle/03_cpu_profile_flame';
import { Example } from '../stories/wordcloud/1_wordcloud';

export class Playground extends React.Component {
render() {
Expand Down
51 changes: 51 additions & 0 deletions api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ export const ChartTypes: Readonly<{
Partition: "partition";
XYAxis: "xy_axis";
Heatmap: "heatmap";
Wordcloud: "wordcloud";
}>;

// @public (undocumented)
Expand Down Expand Up @@ -2367,6 +2368,56 @@ export interface Visible {
visible: boolean;
}

// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts
//
// @alpha (undocumented)
export const Wordcloud: React_2.FunctionComponent<SpecRequiredProps_9 & SpecOptionalProps_9>;

// @alpha (undocumented)
export interface WordcloudSpec extends Spec {
// (undocumented)
angleCount: number;
// (undocumented)
chartType: typeof ChartTypes.Wordcloud;
// (undocumented)
config: RecursivePartial<PartitionConfig>;
// Warning: (ae-forgotten-export) The symbol "WordModel" needs to be exported by the entry point index.d.ts
//
// (undocumented)
data: WordModel[];
// (undocumented)
endAngle: number;
// (undocumented)
exponent: number;
// (undocumented)
fontFamily: string;
// (undocumented)
fontStyle: string;
// (undocumented)
fontWeight: number;
// (undocumented)
maxFontSize: number;
// (undocumented)
minFontSize: number;
// Warning: (ae-forgotten-export) The symbol "OutOfRoomCallback" needs to be exported by the entry point index.d.ts
//
// (undocumented)
outOfRoomCallback: OutOfRoomCallback;
// (undocumented)
padding: number;
// (undocumented)
specType: typeof SpecTypes.Series;
// (undocumented)
spiral: string;
// (undocumented)
startAngle: number;
// Warning: (ae-forgotten-export) The symbol "WeightFun" needs to be exported by the entry point index.d.ts
//
// (undocumented)
weightFun: WeightFun;
}

// Warning: (ae-missing-release-tag) "XScaleType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"chroma-js": "^2.1.0",
"classnames": "^2.2.6",
"d3-array": "^1.2.4",
"d3-cloud": "^1.2.5",
"d3-collection": "^1.0.7",
"d3-color": "^1.4.0",
"d3-interpolate": "^1.4.0",
Expand Down
1 change: 1 addition & 0 deletions src/chart_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const ChartTypes = Object.freeze({
Partition: 'partition' as const,
XYAxis: 'xy_axis' as const,
Heatmap: 'heatmap' as const,
Wordcloud: 'wordcloud' as const,
});
export type ChartTypes = $Values<typeof ChartTypes>;
52 changes: 52 additions & 0 deletions src/chart_types/wordcloud/layout/config/config.ts
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);
37 changes: 37 additions & 0 deletions src/chart_types/wordcloud/layout/types/config_types.ts
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 src/chart_types/wordcloud/layout/types/viewmodel_types.ts
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: () => [],
});
Loading

0 comments on commit d114d1d

Please sign in to comment.