Skip to content

Commit

Permalink
feat(treemap): add borderRadius
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 15, 2020
1 parent e6c0f31 commit fe0d94a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/chart/treemap/TreemapSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ interface TreemapSeriesLabelOption extends LabelOption {
}

interface TreemapSeriesItemStyleOption extends ItemStyleOption {
borderRadius?: number | number[]

colorAlpha?: number
colorSaturation?: number

Expand Down Expand Up @@ -253,7 +255,7 @@ class TreemapSeriesModel extends SeriesModel<TreemapSeriesOption> {
position: 'inside', // Can be [5, '5%'] or position stirng like 'insideTopLeft', ...
// formatter: null,
color: '#fff',
ellipsis: true
overflow: 'truncate'
// align
// verticalAlign
},
Expand All @@ -263,7 +265,7 @@ class TreemapSeriesModel extends SeriesModel<TreemapSeriesOption> {
height: 20,
// formatter: null,
// color: '#fff',
ellipsis: true,
overflow: 'truncate',
// align: null,
verticalAlign: 'middle'
},
Expand Down
7 changes: 4 additions & 3 deletions src/chart/treemap/TreemapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ function renderNode(
const itemStyleEmphasisModel = nodeModel.getModel(['emphasis', 'itemStyle']);
const itemStyleBlurModel = nodeModel.getModel(['blur', 'itemStyle']);
const itemStyleSelectModel = nodeModel.getModel(['select', 'itemStyle']);
const borderRadius = itemStyleNormalModel.get('borderRadius') || 0;

// End of closure ariables available in "Procedures in renderNode".
// -----------------------------------------------------------------
Expand Down Expand Up @@ -843,7 +844,7 @@ function renderNode(
ecData.dataIndex = thisNode.dataIndex;
ecData.seriesIndex = seriesModel.seriesIndex;

bg.setShape({x: 0, y: 0, width: thisWidth, height: thisHeight});
bg.setShape({x: 0, y: 0, width: thisWidth, height: thisHeight, r: borderRadius});

if (thisInvisible) {
// If invisible, do not set visual, otherwise the element will
Expand Down Expand Up @@ -901,7 +902,8 @@ function renderNode(
x: borderWidth,
y: borderWidth,
width: contentWidth,
height: contentHeight
height: contentHeight,
r: borderRadius
});

if (thisInvisible) {
Expand Down Expand Up @@ -981,7 +983,6 @@ function renderNode(

const textEl = rectEl.getTextContent();
const textStyle = textEl.style;
textStyle.overflow = 'truncate';
textStyle.truncateMinChar = 2;
textStyle.width = width;

Expand Down
51 changes: 46 additions & 5 deletions test/treemap-obama.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- <link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet"> -->
<link href="https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@300&family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet">
</head>
<body>
<style>
Expand Down Expand Up @@ -234,14 +236,31 @@
colorMappingBy: 'id',
itemStyle: {
borderWidth: 3,
gapWidth: 3
gapWidth: 3,
borderRadius: 5,
shadowBlur: 20,
shadowColor: 'rgba(20, 20, 40, 1)',
}
},
{
colorAlpha: mode === 2
? [0.5, 1] : null,
? [0.3, 0.5] : null,
itemStyle: {
gapWidth: 1
borderWidth: 2,
gapWidth: 1,
borderRadius: 5,
shadowBlur: 5,
shadowColor: 'rgba(20, 20, 40, 0.5)'
}
},
{
upperLabel: {
show: false
},
itemStyle: {
borderWidth: 0,
gapWidth: 0,
borderRadius: 1
}
}
];
Expand Down Expand Up @@ -297,6 +316,7 @@
});

chart.setOption({
// backgroundColor: '#000',

legend: {
data: [SERIES_NAME]
Expand All @@ -315,10 +335,31 @@
label: {
show: true,
formatter: "{b}",
ellipsis: true
fontSize: 10,
fontWeight: 100,
fontFamily: 'Barlow Condensed',
overflow: 'break'
},
labelLayout: function (params) {
if (params.rect.width < 5 || params.rect.height < 5) {
return {
fontSize: 0
};
}
return {
fontSize: Math.min(Math.sqrt(params.rect.width * params.rect.height) / 10, 20)
};
},
itemStyle: {
borderColor: 'black'
borderColor: 'rgba(100, 100, 200, 0.2)',
borderWidth: 0
},
upperLabel: {
show: true,
height: 15,
fontSize: 10,
fontFamily: 'Barlow Condensed',
color: null
},
levels: getLevelOption(0),
data: buildData('2012 Amount', window.obama_budget_2012)
Expand Down

0 comments on commit fe0d94a

Please sign in to comment.