Skip to content

Commit

Permalink
Fixes diff view color issue (#383)
Browse files Browse the repository at this point in the history
* fixes diff colors issue

* lints js files

* trying to make linter happy
  • Loading branch information
petethepig authored Sep 9, 2021
1 parent 230699f commit 897de97
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 79 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
transformIgnorePatterns: []
transformIgnorePatterns: [],
};
9 changes: 5 additions & 4 deletions scripts/webpack/webpack.panel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { merge } = require("webpack-merge");

const prod = require("./webpack.prod.js");
const path = require("path");
const prod = require("./webpack.prod.js");

module.exports = merge(prod, {
entry: {
flamegraphComponent: "./webapp/javascript/components/FlameGraph/FlameGraphComponent/index.jsx",
flamegraphComponent:
"./webapp/javascript/components/FlameGraph/FlameGraphComponent/index.jsx",
},

output: {
Expand All @@ -15,7 +16,7 @@ module.exports = merge(prod, {
clean: true,

library: "pyroscope",
libraryTarget: 'umd',
umdNamedDefine: true
libraryTarget: "umd",
umdNamedDefine: true,
},
});
17 changes: 17 additions & 0 deletions webapp/__tests__/color.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {colorBasedOnDiff} from '../javascript/components/FlameGraph/FlameGraphComponent/color';

describe.each([
[ -300, 100, 'rgba(0, 200, 0, 0.8)' ],
[ -200, 100, 'rgba(0, 200, 0, 0.8)' ],
[ -100, 100, 'rgba(0, 200, 0, 0.8)' ],
[ -50, 100, 'rgba(59, 200, 59, 0.8)' ],
[ 0, 100, 'rgba(200, 200, 200, 0.8)' ],
[ 50, 100, 'rgba(200, 59, 59, 0.8)' ],
[ 100, 100, 'rgba(200, 0, 0, 0.8)' ],
[ 200, 100, 'rgba(200, 0, 0, 0.8)' ],
[ 300, 100, 'rgba(200, 0, 0, 0.8)' ],
])('.colorBasedOnDiff(%i, %i)', (a, b, expected) => {
it(`returns ${expected}`, () => {
expect(colorBasedOnDiff(a,b,0.8).toString()).toBe(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function colorBasedOnPackageName(name, a) {
// if left == 0 || Math.abs(diff) > left, we use the color of 100%
export function colorBasedOnDiff(diff, left, a) {
const v =
!left || Math.abs(diff) > left ? 1 : 200 * Math.sqrt(Math.abs(diff / left));
!left || Math.abs(diff) > left
? 200
: 200 * Math.sqrt(Math.abs(diff / left));
if (diff >= 0) return Color.rgb(200, 200 - v, 200 - v).alpha(a);
return Color.rgb(200 - v, 200, 200 - v).alpha(a);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ class FlameGraph extends React.Component {
tooltipEl.children[1].children[1].style.color = tooltipDiffColor;

// makes it so that tooltip is always visible even if mouse is close to the right edge
const tooltipX = Math.min(e.clientX + 12, window.innerWidth - tooltipEl.clientWidth - 20);
const tooltipX = Math.min(
e.clientX + 12,
window.innerWidth - tooltipEl.clientWidth - 20
);
tooltipEl.style.left = `${tooltipX}px`;
tooltipEl.style.top = `${e.clientY + 20}px`;
};
Expand Down
4 changes: 3 additions & 1 deletion webapp/javascript/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ function Footer() {
rel="noreferrer"
target="_blank"
>
<FontAwesomeIcon icon={faDownload} />&nbsp;<span>Newer Version Available ({latestVersion})</span>
<FontAwesomeIcon icon={faDownload} />
&nbsp;
<span>{`Newer Version Available (${latestVersion})`}</span>
</a>
</span>
)}
Expand Down
2 changes: 1 addition & 1 deletion webapp/javascript/components/ProfilerHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { faColumns } from "@fortawesome/free-solid-svg-icons/faColumns";
import { faIcicles } from "@fortawesome/free-solid-svg-icons/faIcicles";
import { faListUl } from "@fortawesome/free-solid-svg-icons/faListUl";
import { faTable } from "@fortawesome/free-solid-svg-icons/faTable";
import { FitModes } from "../util/fitMode"
import { FitModes } from "../util/fitMode";

export default function ProfilerHeader({
view,
Expand Down
2 changes: 1 addition & 1 deletion webapp/javascript/components/ProfilerTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react";
import clsx from "clsx";
import { getFormatter, getPackageNameFromStackTrace } from "../util/format";
import { colorBasedOnPackageName, defaultColor, diffColorGreen, diffColorRed } from "../util/color";
import { colorBasedOnPackageName, defaultColor, diffColorGreen, diffColorRed } from "./FlameGraph/FlameGraphComponent/color";
import { parseFlamebearerFormat } from "../util/flamebearer";
import { fitIntoTableCell } from "../util/fitMode";

Expand Down
6 changes: 5 additions & 1 deletion webapp/javascript/components/PyroscopeApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import TimelineChartWrapper from "./TimelineChartWrapper";
import Header from "./Header";
import Footer from "./Footer";
import { buildRenderURL } from "../util/updateRequests";
import { fetchNames, fetchTimeline, abortTimelineRequest } from "../redux/actions";
import {
fetchNames,
fetchTimeline,
abortTimelineRequest,
} from "../redux/actions";

function PyroscopeApp(props) {
const { actions, renderURL } = props;
Expand Down
18 changes: 9 additions & 9 deletions webapp/javascript/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ function Sidebar(props) {
<FontAwesomeIcon icon={faKeyboard} />
</button>
</SidebarItem>
{
window.isAuthRequired ? (
<SidebarItem tooltipText="Sign Out">
<button type="button" onClick={() => signOut()}>
<FontAwesomeIcon icon={faSignOutAlt} />
</button>
</SidebarItem>
) : []
}
{window.isAuthRequired ? (
<SidebarItem tooltipText="Sign Out">
<button type="button" onClick={() => signOut()}>
<FontAwesomeIcon icon={faSignOutAlt} />
</button>
</SidebarItem>
) : (
[]
)}
<Modal
isOpen={state.shortcutsModalOpen}
style={modalStyle}
Expand Down
18 changes: 13 additions & 5 deletions webapp/javascript/components/TagsBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { connect } from "react-redux";
import "react-dom";
import { Menu, SubMenu, MenuItem, MenuButton } from "@szhsin/react-menu";

import { fetchTags, fetchTagValues, setQuery, abortFetchTags, abortFetchTagValues } from "../redux/actions";
import {
fetchTags,
fetchTagValues,
setQuery,
abortFetchTags,
abortFetchTagValues,
} from "../redux/actions";
import "../util/prism";

function TagsBar({ query, actions, tags, tagValuesLoading }) {
Expand Down Expand Up @@ -42,10 +48,12 @@ function TagsBar({ query, actions, tags, tagValuesLoading }) {
const loadTagValues = (tag) => {
actions.fetchTagValues(query, tag);
};
useEffect(() => {
// since fetchTagValues may be running
return actions.abortFetchTagValues;
}, [])
useEffect(
() =>
// since fetchTagValues may be running
actions.abortFetchTagValues,
[]
);

const onTagsValueChange = (tagKey, tagValue) => {
let newQuery;
Expand Down
54 changes: 0 additions & 54 deletions webapp/javascript/util/color.js

This file was deleted.

0 comments on commit 897de97

Please sign in to comment.