Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Three-Dimensional Metric Matrix
deck.gl · Business scenario

Three-Dimensional Metric Matrix

900 octagonal columns rise with metric values and color encodes a period-over-period change from -8% to +8%; a slider compresses or stretches overall height between 0.2× and 2×.

Open standalone → Chinese notes All business examples
/demos/deckgl-nongis-finance-matrix.htmlLIVE
single HTML file · CDN dependencies onlyinterface labels are in Chinese

Business context

Three-dimensional metric matrices appear mostly in business reviews and BI dashboards. The users are finance business partners, regional leads and analysts comparing metric levels and period-over-period direction at once. Data comes from data warehouse wide tables; the 30×30 grid maps product category against region, and 900 metrics per screen is a common size. Real deployments slice further by quarter or channel and keep the cell count in the thousands for legibility.

Wide tables export dimensions and measures, so the grid must be laid out regularly, measures normalized to a fixed range and the change rate computed as a separate column so height and color do not share a field; missing values get an explicit neutral color rather than being left blank. Cesium has no semantics for a column matrix and three.js needs manual instancing and lighting; ColumnLayer submits 900 columns at once, and height scaling only changes elevationScale.

Height is compressed or stretched by elevationScale, so trends read fine but absolute values require undoing the multiplier. Color encodes change rate, not quality: positive and negative each have their own ramp and the middle sits at neutral gray. Height and color come from independent channels, so a tall but falling column means large scale in contraction; reading only one dimension leads to the wrong conclusion.

How it works

The grid spreads from the origin, with column i and row j at [(i-14.5)×12, (j-14.5)×12, 0] and a scene span of 348 units; metric values come from 46 + 38·sin(0.32i)·cos(0.26j) plus ±7 noise, clamped to 2–100, and getElevation returns v×0.4 (0–40 scene units), with elevationScale only for global scaling: moving the slider from 0.2 to 2 grows the tallest column from 8 to 80 units. Color is an independent second channel: the change rate spans -8% to +8%, interpolating toward [86,214,168] on the positive side, [240,104,72] on the negative side and neutral gray [96,108,124] near zero, so 'tall but falling' and 'short but rising' remain distinguishable.

Each column uses diskResolution 8 with triangle-strip geometry: 8 side quads of 2 triangles each plus 8 cap triangles, 16 triangles, 48 indices and 28 vertices in total, about 25,000 vertices for 900 columns; at 16 the count doubles to 32 triangles and at 32 to 64, so vertices grow linearly with diskResolution and 900 columns hit vertex processing first on mobile. Radius 5.04 is 42% of the 12-unit pitch, giving a diameter of 10.08 and a gap of 1.92 units, or 16%, between columns; a smaller gap makes neighbors merge into a solid surface in top view. Height scaling goes through elevationScale instead of recomputing getElevation, so deck.gl changes one uniform and rebuilds neither geometry nor color attributes for the 900 columns.

SettingEffect
diskResolution: 828 vertices and 16 triangles per column, about 25,000 vertices for 900
radius: 5.0442% of the 12-unit pitch, leaving a 1.92-unit, 16% gap
getElevation: v×0.4Compresses the 0–100 metric into 0–40 scene units
elevationScale: 0.2–2Global height multiplier; changes a uniform without rebuilding geometry

Note. diskResolution 8 is enough for a column matrix, since facets are invisible at distance; a column diameter at 84% of the pitch leaves a 16% gap, and anything larger merges neighbors.

Source

demos/deckgl-nongis-finance-matrix.html
<!--
  示例:三维指标矩阵
  要点:30×30 的 ColumnLayer 阵列,diskResolution 8 控制每根柱的侧面段数,柱高与环比变化率分成两个视觉通道
  依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>三维指标矩阵</title>
<style>
  html,body{height:100%;margin:0;background:#0d1117}
  body{display:flex;flex-direction:column;overflow:hidden;
       font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
  .bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
       display:flex;gap:14px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
  .bar b{color:#58a6ff;font-weight:600}
  .bar label{display:flex;align-items:center;gap:5px;cursor:pointer}
  .bar input[type=checkbox]{accent-color:#4f9ef8}
  .bar input[type=range]{width:150px;accent-color:#4f9ef8}
  .bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:4px;cursor:pointer;
       border:1px solid #2f3947;background:#1d242e;color:#c9d3e0}
  .bar button:hover{background:#26303d}
  .bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
  .bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
  #cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
  <span>30 × 30 = 900 根 · 格距 12 · radius 5.04</span>
  <span class="sep"></span>
  <button id="pal" class="on">按变化率着色</button>
  <label>高度 <b id="sc">1.0</b>× <input id="es" type="range" min="0.2" max="2" step="0.05" value="1"></label>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
  'use strict';

  if (typeof deck === 'undefined') {
    document.body.innerHTML =
      '<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
    return;
  }

  function rng(seed) {
    var a = seed >>> 0;
    return function () {
      a = (a + 0x6D2B79F5) >>> 0;
      var t = Math.imul(a ^ (a >>> 15), 1 | a);
      t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
      return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
    };
  }

  var N = 30, GAP = 12;
  var RAD = 0.42 * GAP;   // 柱半径按格距的 42%,即 5.04 场景单位
  var rand = rng(4217);
  var cols = [];
  var i, j;

  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      var v = 46 + 38 * Math.sin(i * 0.32) * Math.cos(j * 0.26) + (rand() - 0.5) * 14;
      v = v < 2 ? 2 : (v > 100 ? 100 : v);
      var chg = 6.4 * Math.sin(i * 0.19 + j * 0.23) + (rand() - 0.5) * 3.4;
      chg = chg < -8 ? -8 : (chg > 8 ? 8 : chg);
      cols.push({
        pos: [(i - 14.5) * GAP, (j - 14.5) * GAP, 0],
        v: v,
        c: chg
      });
    }
  }

  var MONO = [88, 146, 220, 240];
  var mode = 'chg';
  var scale = 1;

  // -8% → 红,0 → 灰,+8% → 绿
  function chgColor(t) {
    var base = [96, 108, 124];
    var to = t >= 0 ? [86, 214, 168] : [240, 104, 72];
    var k = t >= 0 ? t : -t;
    return [
      Math.round(base[0] + (to[0] - base[0]) * k),
      Math.round(base[1] + (to[1] - base[1]) * k),
      Math.round(base[2] + (to[2] - base[2]) * k),
      240
    ];
  }

  function buildLayers() {
    return [
      new deck.ColumnLayer({
        id: 'metric-columns',
        data: cols,
        coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
        diskResolution: 8,
        radius: RAD,
        getPosition: function (d) { return d.pos; },
        getElevation: function (d) { return d.v * 0.4; },
        elevationScale: scale,
        getFillColor: function (d) {
          if (mode === 'mono') return MONO;
          return chgColor(d.c / 8);
        },
        stroked: true,
        getLineColor: [14, 20, 28, 170],
        getLineWidth: 1,
        lineWidthUnits: 'pixels',
        pickable: false
      })
    ];
  }

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    views: new deck.OrbitView({ target: [0, 0, 0], fovy: 28 }),
    initialViewState: { target: [0, 0, 0], rotationX: 34, rotationOrbit: -30, zoom: 0.7 },
    controller: true,
    layers: buildLayers()
  });

  var palEl = document.getElementById('pal');
  palEl.addEventListener('click', function () {
    mode = mode === 'chg' ? 'mono' : 'chg';
    palEl.className = mode === 'chg' ? 'on' : '';
    palEl.textContent = mode === 'chg' ? '按变化率着色' : '单色';
    deckgl.setProps({ layers: buildLayers() });
  });

  var esEl = document.getElementById('es');
  esEl.addEventListener('input', function () {
    scale = +esEl.value;
    document.getElementById('sc').textContent = scale.toFixed(1);
    deckgl.setProps({ layers: buildLayers() });
  });

  window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: this page is in English; the demo keeps Chinese interface labels and code comments. The Chinese page carries the full notes and the same runnable file.

More business examples

deck.gl · APIColumnLayer deck.gl · APIOrbitView deck.gl · APICOORDINATE_SYSTEM