-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[ML] Migrate Explorer Charts to React. #22622
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80dcaff
[ML] Initial explorer charts react migration.
walterra e5f15d7
[ML] Moved mocha tests to jest/enzyme/jsdom. Trying to fix a race con…
walterra 636ec6b
[ML] Rename explorerChartsContainerData to explorerChartsContainerSer…
walterra cf537e2
[ML] Remove some temporary code.
walterra d7beaf9
[ML] Successfully mocks getBBox so the original code doesn't have to …
walterra 7b39fcc
[ML] Changes inclunding review feedback.
walterra f2763dc
[ML] Use relative paths for imports.
walterra 208f892
[ML] Move getDefaultData() inside factory. Add constants for default …
walterra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,12 @@ import d3 from 'd3'; | |
|
||
import { numTicks } from 'plugins/ml/util/chart_utils'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use relative paths? |
||
import { ordinalSuffix } from 'ui/utils/ordinal_suffix'; | ||
import { mlChartTooltipService } from '../../components/chart_tooltip/chart_tooltip_service'; | ||
|
||
import { uiModules } from 'ui/modules'; | ||
const module = uiModules.get('apps/ml'); | ||
|
||
module.directive('mlMetricDistributionChart', function (mlChartTooltipService) { | ||
module.directive('mlMetricDistributionChart', function () { | ||
|
||
function link(scope, element, attrs) { | ||
const svgWidth = attrs.width ? +attrs.width : 400; | ||
|
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 }) { | ||
walterra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth making all these imports relative paths?