Skip to content

Commit

Permalink
fix(core angular react): fix tooltip styling
Browse files Browse the repository at this point in the history
affects: @carbon/charts-angular, @carbon/charts, @carbon/charts-react

fix tooltip styling
  • Loading branch information
theiliad committed Aug 22, 2018
1 parent a0d2f90 commit 80b36f5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ node_modules
.vscode/
.idea/
*.log
packages/react/build
packages/core/demo/bundle/
packages/react/build/
storybook-dist
Binary file added packages/angular/demo/assets/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/angular/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"storybook": "start-storybook -p 9005 -c .storybook"
"storybook": "start-storybook -p 9005 -c .storybook -s ./assets"
},
"private": true,
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
<link rel="shortcut icon" href="favicon.ico" />

<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:400,500,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:400,500,600,700" rel="stylesheet">

<link href="https://unpkg.com/carbon-components/css/carbon-components.min.css" rel="stylesheet">
</head>
Expand Down
9 changes: 8 additions & 1 deletion packages/core/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ const changeDemoData = (chartType: any, oldData: any, delay?: number) => {
const firstTry = Math.max(0.5 * currentVal, currentVal * Math.random() * (Math.random() * 5));
const result = currentVal > 0 ? Math.min(2 * currentVal, firstTry) : Math.max(2 * currentVal, firstTry);

return Math.floor(result);
if (Math.random() > 0.5
|| chartType.indexOf("stacked") !== -1
|| chartType.indexOf("pie") !== -1
|| chartType.indexOf("donut") !== -1) {
return Math.floor(result);
} else {
return Math.floor(result) * -1;
}
};

switch (chartType) {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/base-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ export class BaseChart {
// Draw tooltip
const tooltip = d3.select(this.holder).append("div")
.attr("class", "tooltip chart-tooltip")
.style("border-color", this.colorScale[d.datasetLabel](d.label))
// .style("border-color", this.colorScale[d.datasetLabel](d.label))
.style("top", d3.mouse(this.holder as SVGSVGElement)[1] - Configuration.tooltip.magicTop2 + "px");

// TODOCARBON - Remove
Expand All @@ -805,7 +805,6 @@ export class BaseChart {
`;
} else {
tooltipHTML += `
${d.label}<br/>
<b>${d.datasetLabel}:</b> ${formattedValue}<br/>
`;
}
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/pie-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class PieChart extends BaseChart {
const tooltip = d3.select(this.holder).append("div")
.attr("class", "tooltip chart-tooltip")
.style("top", d3.mouse(this.holder as SVGSVGElement)[1] - Configuration.tooltip.magicTop2 + "px")
.style("border-color", this.colorScale[this.displayData.datasets[0].label](d.data.label)); // TODO - Support multiple datasets
// .style("border-color", this.colorScale[this.displayData.datasets[0].label](d.data.label)); // TODO - Support multiple datasets

// TODOCARBON - Remove
// Tools.addCloseBtn(tooltip, "xs")
Expand All @@ -279,15 +279,16 @@ export class PieChart extends BaseChart {
<p>${d.data.label}</p>
`;

if (d.data.label === Configuration.pie.label.other) {
const { items } = d.data;
// TODOCARBON - Switch to popover onclick
// if (d.data.label === Configuration.pie.label.other) {
// const { items } = d.data;

items.map(item => {
tooltipHTML += `
<p>${item.label}: ${item.value.toLocaleString()}</p>
`;
});
}
// items.map(item => {
// tooltipHTML += `
// <b>${item.label}:</b> ${item.value.toLocaleString()}<br />
// `;
// });
// }

tooltip.append("div").attr("class", "text-box").html(tooltipHTML);
if (d3.mouse(this.holder as SVGSVGElement)[0] + (tooltip.node() as Element).clientWidth > this.holder.clientWidth) {
Expand Down
18 changes: 12 additions & 6 deletions packages/core/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,14 @@ div.chart-overlay {
}

.tooltip {
background-color: #484848;
color: #fff;
box-shadow: 0 0 10px 0 rgba(0,0,0,0.16);
background-color: #fff;
border: 1px solid #DFE3E6;
padding: .25rem .5rem;
display: block;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, .1);
@include fonts();
font-size: 12px;
font-weight: 300;
position: absolute;
padding: 10px;
border-radius: 3px;
Expand All @@ -272,13 +274,17 @@ div.chart-overlay {
z-index: 1059;

p {
margin-bottom: 5px;
font-size: 12px;

&.bignum {
margin-top: 15px;
font-size: 27px;
font-size: 19px;
font-weight: 600;
}
}

b {
font-weight: 600;
}
}

#carbon-charts-patterns svg {
Expand Down
Binary file added packages/react/assets/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack -w",
"build": "webpack",
"storybook": "start-storybook -p 9006 -c .storybook"
"storybook": "start-storybook -p 9006 -c .storybook -s ./assets"
},
"repository": {
"type": "git",
Expand Down
Binary file removed src/assets/demo-stacked-bar.jpg
Binary file not shown.

0 comments on commit 80b36f5

Please sign in to comment.