forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Migrate Explorer Charts to React. (elastic#22622) (elastic#22632)
This migrates the Anomaly Explorer charts to React. The PR aims to change as little of the actual logic to create and render the charts.
- Loading branch information
Showing
26 changed files
with
806 additions
and
621 deletions.
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
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/ml/public/components/chart_tooltip/chart_tooltip_service.js
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,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
|
||
import $ from 'jquery'; | ||
|
||
const doc = document.documentElement; | ||
const FADE_TIMEOUT_MS = 200; | ||
|
||
export const mlChartTooltipService = { | ||
element: null, | ||
fadeTimeout: null, | ||
}; | ||
|
||
mlChartTooltipService.show = function (contents, target, offset = { x: 0, y: 0 }) { | ||
if (this.element === null) { | ||
return; | ||
} | ||
|
||
// if a previous fade out was happening, stop it | ||
if (this.fadeTimeout !== null) { | ||
clearTimeout(this.fadeTimeout); | ||
} | ||
|
||
// populate the tooltip contents | ||
this.element.html(contents); | ||
|
||
// side bar width | ||
const navOffset = $('.global-nav').width(); | ||
const contentWidth = $('body').width() - navOffset - 10; | ||
const tooltipWidth = this.element.width(); | ||
const scrollTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); | ||
|
||
const pos = target.getBoundingClientRect(); | ||
const x = (pos.left + (offset.x) + 4) - navOffset; | ||
const y = pos.top + (offset.y) + scrollTop; | ||
|
||
if (x + tooltipWidth > contentWidth) { | ||
// the tooltip is hanging off the side of the page, | ||
// so move it to the other side of the target | ||
this.element.css({ | ||
left: x - (tooltipWidth + offset.x + 22), | ||
top: (y - 28) | ||
}); | ||
} else { | ||
this.element.css({ | ||
left: x, | ||
top: (y - 28) | ||
}); | ||
} | ||
|
||
this.element.css({ | ||
opacity: '0.9', | ||
display: 'block' | ||
}); | ||
}; | ||
|
||
mlChartTooltipService.hide = function () { | ||
if (this.element === null) { | ||
return; | ||
} | ||
|
||
this.element.css({ | ||
opacity: '0', | ||
}); | ||
|
||
// after the fade out transition has finished, set the display to | ||
// none so it doesn't block any mouse events underneath it. | ||
this.fadeTimeout = setTimeout(() => { | ||
this.element.css('display', 'none'); | ||
this.fadeTimeout = null; | ||
}, FADE_TIMEOUT_MS); | ||
}; |
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
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/ml/public/components/loading_indicator/loading_indicator.js
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
|
||
import './styles/main.less'; | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
export function LoadingIndicator({ height }) { | ||
height = height ? +height : 100; | ||
return ( | ||
<div className="ml-loading-indicator" style={{ height: `${height}px` }}> | ||
<div className="loading-spinner"><i className="fa fa-spinner fa-spin" /></div> | ||
</div> | ||
); | ||
} | ||
LoadingIndicator.propTypes = { | ||
height: PropTypes.number | ||
}; |
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
Oops, something went wrong.