-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tagcloud renderer (#77910)
* Implement toExpressionAst for tagcloud * Implement tagcloud vis renderer * Use resize observer * Use common no data message * Update build_pipeline.test * Update tag cloud tests * Revert "Use common no data message" This reverts commit fddf019. * Update interpreter functional tests * Add tests for toExpressionAst fn * Use throttled chart update * Update renderer Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
966f00a
commit 53d4938
Showing
30 changed files
with
674 additions
and
317 deletions.
There are no files selected for viewing
31 changes: 14 additions & 17 deletions
31
src/plugins/vis_type_tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
171 changes: 171 additions & 0 deletions
171
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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
26 changes: 26 additions & 0 deletions
26
src/plugins/vis_type_tagcloud/public/components/tag_cloud.scss
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,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; | ||
} |
84 changes: 84 additions & 0 deletions
84
src/plugins/vis_type_tagcloud/public/components/tag_cloud_chart.tsx
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,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 }; |
Oops, something went wrong.