You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2017/10/10 06:17:53 UTC

[incubator-superset] branch master updated: add annotation option and a linear color map for heatmap viz. (#3634)

This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ad4167  add annotation option and a linear color map for heatmap viz. (#3634)
5ad4167 is described below

commit 5ad4167512e81468c09ce856f4054bb16e3af5b0
Author: Yu Xiao <xi...@gmail.com>
AuthorDate: Tue Oct 10 15:17:51 2017 +0900

    add annotation option and a linear color map for heatmap viz. (#3634)
    
    * add annotation option and a linear color map for heatmap viz.
    
    * error fixes.
    
    * fixes for requested changes
---
 .../assets/javascripts/explore/stores/controls.jsx     |  9 +++++++++
 superset/assets/javascripts/explore/stores/visTypes.js |  1 +
 superset/assets/javascripts/modules/colors.js          |  7 +++++++
 superset/assets/visualizations/heatmap.js              | 18 ++++++++++++++++++
 4 files changed, 35 insertions(+)

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx
index 8d470f0..d2851ee 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -202,6 +202,7 @@ export const controls = {
       ['blue_white_yellow', 'blue/white/yellow'],
       ['white_black', 'white/black'],
       ['black_white', 'black/white'],
+      ['dark_blue', 'light/dark blue'],
     ],
     default: 'blue_white_yellow',
     clearable: false,
@@ -1086,6 +1087,14 @@ export const controls = {
     description: t('Whether to display the legend (toggles)'),
   },
 
+  show_values: {
+    type: 'CheckboxControl',
+    label: t('Show Values'),
+    renderTrigger: true,
+    default: false,
+    description: t('Whether to display the numerical values within the cells'),
+  },
+
   x_axis_showminmax: {
     type: 'CheckboxControl',
     label: t('X bounds'),
diff --git a/superset/assets/javascripts/explore/stores/visTypes.js b/superset/assets/javascripts/explore/stores/visTypes.js
index 4cdabf8..0459b38 100644
--- a/superset/assets/javascripts/explore/stores/visTypes.js
+++ b/superset/assets/javascripts/explore/stores/visTypes.js
@@ -976,6 +976,7 @@ export const visTypes = {
           ['left_margin', 'bottom_margin'],
           ['y_axis_bounds', 'y_axis_format'],
           ['show_legend', 'show_perc'],
+          ['show_values'],
           ['sort_x_axis', 'sort_y_axis'],
         ],
       },
diff --git a/superset/assets/javascripts/modules/colors.js b/superset/assets/javascripts/modules/colors.js
index 8e3e521..803b683 100644
--- a/superset/assets/javascripts/modules/colors.js
+++ b/superset/assets/javascripts/modules/colors.js
@@ -94,6 +94,13 @@ export const spectrums = {
     'black',
     'white',
   ],
+  dark_blue: [
+    '#EBF5F8',
+    '#6BB1CC',
+    '#357E9B',
+    '#1B4150',
+    '#092935',
+  ],
 };
 
 export const getColorFromScheme = (function () {
diff --git a/superset/assets/visualizations/heatmap.js b/superset/assets/visualizations/heatmap.js
index 002af8a..d86253d 100644
--- a/superset/assets/visualizations/heatmap.js
+++ b/superset/assets/visualizations/heatmap.js
@@ -130,6 +130,24 @@ function heatmapVis(slice, payload) {
     .attr('height', height)
     .style('position', 'relative');
 
+  if (fd.show_values) {
+    const cells = svg.selectAll('rect')
+      .data(data)
+      .enter()
+      .append('g')
+      .attr('transform', `translate(${margin.left}, ${margin.top})`);
+
+    cells.append('text')
+      .attr('transform', d => `translate(${xRbScale(d.x)}, ${yRbScale(d.y)})`)
+      .attr('y', yRbScale.rangeBand() / 2)
+      .attr('x', xRbScale.rangeBand() / 2)
+      .attr('text-anchor', 'middle')
+      .attr('dy', '.35em')
+      .text(d => valueFormatter(d.v))
+      .attr('font-size', Math.min(yRbScale.rangeBand(), xRbScale.rangeBand()) / 3 + 'px')
+      .attr('fill', d => d.v >= payload.data.extents[1] / 2 ? 'white' : 'black');
+  }
+
   if (fd.show_legend) {
     const legendScaler = colorScalerFactory(
       fd.linear_color_scheme, null, null, payload.data.extents);

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <co...@superset.apache.org>'].