Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Implement tagcloud renderer (#77910) #78580

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 171 additions & 0 deletions src/plugins/vis_type_tagcloud/public/__snapshots__/to_ast.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions src/plugins/vis_type_tagcloud/public/_tag_cloud.scss

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/vis_type_tagcloud/public/components/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Label extends Component {
render() {
return (
<div
className="tgcVisLabel"
className="tgcChart__label"
style={{ display: this.state.shouldShowLabel ? 'block' : 'none' }}
>
{this.state.label}
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/vis_type_tagcloud/public/components/tag_cloud.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Prefix all styles with "tgc" to avoid conflicts.
// Examples
// tgcChart
// tgcChart__legend
// tgcChart__legend--small
// tgcChart__legend-isLoading

.tgcChart__container, .tgcChart__wrapper {
flex: 1 1 0;
display: flex;
}

.tgcChart {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}

.tgcChart__label {
width: 100%;
text-align: center;
font-weight: $euiFontWeightBold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 React, { useEffect, useMemo, useRef } from 'react';
import { EuiResizeObserver } from '@elastic/eui';
import { throttle } from 'lodash';

import { TagCloudVisDependencies } from '../plugin';
import { TagCloudVisRenderValue } from '../tag_cloud_fn';
// @ts-ignore
import { TagCloudVisualization } from './tag_cloud_visualization';

import './tag_cloud.scss';

type TagCloudChartProps = TagCloudVisDependencies &
TagCloudVisRenderValue & {
fireEvent: (event: any) => void;
renderComplete: () => void;
};

export const TagCloudChart = ({
colors,
visData,
visParams,
fireEvent,
renderComplete,
}: TagCloudChartProps) => {
const chartDiv = useRef<HTMLDivElement>(null);
const visController = useRef<any>(null);

useEffect(() => {
visController.current = new TagCloudVisualization(chartDiv.current, colors, fireEvent);
return () => {
visController.current.destroy();
visController.current = null;
};
}, [colors, fireEvent]);

useEffect(() => {
if (visController.current) {
visController.current.render(visData, visParams).then(renderComplete);
}
}, [visData, visParams, renderComplete]);

const updateChartSize = useMemo(
() =>
throttle(() => {
if (visController.current) {
visController.current.render().then(renderComplete);
}
}, 300),
[renderComplete]
);

return (
<EuiResizeObserver onResize={updateChartSize}>
{(resizeRef) => (
<div className="tgcChart__wrapper" ref={resizeRef}>
<div className="tgcChart__container" ref={chartDiv} />
</div>
)}
</EuiResizeObserver>
);
};

// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { TagCloudChart as default };
Loading