分級ユーティリティ(classify)デモ

📊 使用データ & 機能

  • 世界各国の人口(POP_EST)によるコロプレス図
  • classify() による4種類の分級手法の比較(jenks / equalInterval / quantile / stdDev)
  • 計算した境界値を d3.scaleThreshold にそのまま適用
  • LegendLayer(labelFormat 使用)との連携

計算された境界値(thresholds)

地図表示

実装サンプル

classify() の使用例

// 各国の人口データから分級境界を計算する
const geojson = await d3.json('./geojson/world.geojson');
const values = geojson.features.map(f => f.properties.POP_EST);

// 自然分類(Jenks)で5階級に分級
// method: 'jenks' | 'equalInterval' | 'quantile' | 'stdDev'
const result = Thematika.classify(values, 5, 'jenks');
// result.thresholds → scaleThreshold の domain 用の境界値(4個)
// result.breaks     → 最小値・最大値を含む全境界値(6個)

// D3のscaleThresholdにそのまま渡す
const colorScale = d3.scaleThreshold()
    .domain(result.thresholds)
    .range(d3.schemeYlOrRd[5]);

// コロプレスレイヤー
const choroplethLayer = new Thematika.GeojsonLayer({
    data: geojson,
    attr: {
        fill: d => colorScale(d.properties.POP_EST),
        stroke: '#fff',
        'stroke-width': 0.5
    }
});
map.addLayer('choropleth', choroplethLayer);

// 凡例(labelFormatで数値を整形)
const legend = new Thematika.LegendLayer({
    scale: colorScale,
    position: { top: 20, left: 20 },
    title: '人口',
    labelFormat: d3.format('.2s')
});
map.addLayer('legend', legend);