Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div class="chart-container">
    <canvas id="chart"></canvas>
</div>

              
            
!

CSS

              
                body {  
  background: #1D1F20;
  padding: .2rem;
}

canvas {
  border: .02rem dotted red;
}

.chart-container {
  position: relative;
  margin: auto;
  height: 80vh;
  width: 80vw;
}

              
            
!

JS

              
                
/**
 * Calculate after-tax insurance fee per month as at 2018 in Japan
 * @see https://codepen.io/ymkjp/pen/bPygPa
 * @param {Number} mInsuranceFee Monthly insurance fee
 * @param {Number} yTaxableIncome Annual taxable income
 */
const calcAfterTaxInsuranceFeePerMonth = (mInsuranceFee, yTaxableIncome) => {
  const yiFee = 12 * mInsuranceFee
  const itExemption = calcIncomeTaxExemption(yiFee)
  const rtExemption = calcResidentialTaxExemption(yiFee)
  const itRate = getIncomeTaxRate(yTaxableIncome - itExemption)
  const rtRate = getResidentialTaxRate(yTaxableIncome - rtExemption)
  return (yiFee - (itExemption * itRate) - (rtExemption * rtRate)) / 12
}

/**
 * Return tax rate
 * @see https://www.nta.go.jp/taxes/shiraberu/taxanswer/shotoku/2260.htm
 * @param yTaxableIncome
 * @returns {number}
 */
const getIncomeTaxRate = (yTaxableIncome) => {
  if (yTaxableIncome < 1950000) {
    return 0.05
  } else if (yTaxableIncome < 3300000) {
    return 0.10
  } else if (yTaxableIncome < 6950000) {
    return 0.20
  } else if (yTaxableIncome < 9000000) {
    return 0.23
  } else if (yTaxableIncome < 18000000) {
    return 0.33
  } else if (yTaxableIncome < 40000000) {
    return 0.40
  } else {
    return 0.45
  }
}

/**
 * Return tax rate
 * @see https://ja.wikipedia.org/wiki/%E5%B8%82%E7%94%BA%E6%9D%91%E6%B0%91%E7%A8%8E
 * @param yTaxableIncome
 * @returns {number}
 */
const getResidentialTaxRate = (yTaxableIncome) => {
  return 0.1
}

/**
 * Return exemption amount
 * @see https://www.jili.or.jp/knows_learns/basic/tax/premium.html
 * @param yiFee
 * @returns {number}
 */
const calcIncomeTaxExemption = (yiFee) => {
  if (yiFee <= 20000) {
    return yiFee
  } else if (yiFee <= 40000) {
    return 0.5 * yiFee + 10000
  } else if (yiFee <= 80000) {
    return 0.25 * yiFee + 20000
  } else {
    return 40000
  }
}

/**
 * Return exemption amount
 * @see https://www.jili.or.jp/knows_learns/basic/tax/premium.html
 * @param yiFee
 * @returns {number}
 */
const calcResidentialTaxExemption = (yiFee) => {
  if (yiFee <= 12000) {
    return yiFee
  } else if (yiFee <= 32000) {
    return 0.5 * yiFee + 6000
  } else if (yiFee <= 56000) {
    return 0.25 * yiFee + 14000
  } else {
    return 28000
  }
}

numeral.register('locale', 'jp', {
  delimiters: {
    thousands: ',',
    decimal: '.'
  },
  currency: {
    symbol: '¥'
  }
})

const createData = () => {
  const monthlyInsuranceFeeTable = Array.from({ length: 7 }, (_, i) => {
    return (i + 1) * 1000
  })

  const annualTaxableIncomeTable = Array.from({ length: 202 }, (_, i) => {
    return i * 100 * 1000
  })

  const colors = palette('tol-dv', monthlyInsuranceFeeTable.length).map((hex) => {
    return '#' + hex
  })
  const datasets = monthlyInsuranceFeeTable.map((x1, i) => {
    return {
      label: `${numeral(x1).format('$0,0')} per month`,
      borderWidth: 2,
      showLine: true,
      backgroundColor: colors[i] + '11',
      borderColor: colors[i],
      data: annualTaxableIncomeTable.map(x2 => {
        return calcAfterTaxInsuranceFeePerMonth(x1, x2)
      })
    }
  })
  return {
    labels: annualTaxableIncomeTable.map(v => numeral(v).format('$0,0')),
    datasets: datasets
  }
}

const options = {
  title: {
    display: true,
    text: 'Tax Exemption - insurance fee vs annual income (JPY)'
  },
  scales: {
    yAxes: [{
      ticks: {
        callback: (v) => {
          return numeral(v).format('$0,0')
        }
      }
    }]
  }
}

if (typeof require === 'undefined' || require.main === module) {
  numeral.locale('jp')
  Chart.Line('chart', {
    options: options,
    data: createData()
  })
}

              
            
!
999px

Console