Skip to content

Commit

Permalink
Merge pull request #1510 from tradingview/disable-bold-time-scale-labels
Browse files Browse the repository at this point in the history
add option to disable bold labels in time scale
  • Loading branch information
SlicedSilver committed Feb 5, 2024
2 parents 2c5c2c7 + b010143 commit 6daf134
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ module.exports = [
{
name: 'CJS',
path: 'dist/lightweight-charts.production.cjs',
limit: '47.96 KB',
limit: '47.98 KB',
},
{
name: 'ESM',
path: 'dist/lightweight-charts.production.mjs',
limit: '47.89 KB',
limit: '47.91 KB',
},
{
name: 'Standalone-ESM',
path: 'dist/lightweight-charts.standalone.production.mjs',
limit: '49.61 KB',
limit: '49.63 KB',
},
{
name: 'Standalone',
path: 'dist/lightweight-charts.standalone.production.js',
limit: '49.66 KB',
limit: '49.68 KB',
},
];
1 change: 1 addition & 0 deletions src/api/options/time-scale-options-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const timeScaleOptionsDefaults: HorzScaleOptions = {
ticksVisible: false,
uniformDistribution: false,
minimumHeight: 0,
allowBoldLabels: true,
};
4 changes: 3 additions & 1 deletion src/gui/time-axis-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ export class TimeAxisWidget<HorzScaleItem> implements MouseEventHandlers, IDestr
ctx.fillText(tickMark.label, coordinate, yText);
}
}
ctx.font = this._baseBoldFont();
if (this._chart.options().timeScale.allowBoldLabels) {
ctx.font = this._baseBoldFont();
}
for (const tickMark of tickMarks) {
if (tickMark.weight >= maxWeight) {
const coordinate = tickMark.needAlignCoordinate ? this._alignTickMarkLabelCoordinate(ctx, tickMark.coord, tickMark.label) : tickMark.coord;
Expand Down
7 changes: 7 additions & 0 deletions src/model/time-scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ export interface HorzScaleOptions {
* @defaultValue 0
*/
minimumHeight: number;

/**
* Allow major time scale labels to be rendered in a bolder font weight.
*
* @defaultValue true
*/
allowBoldLabels: boolean;
}

export interface ITimeScale {
Expand Down
22 changes: 22 additions & 0 deletions tests/e2e/graphics/test-cases/time-scale/disable-bold-labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function generateData() {
const res = [];
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0));
for (let i = 0; i < 500; ++i) {
res.push({
time: time.getTime() / 1000,
value: i,
});

time.setUTCDate(time.getUTCDate() + 1);
}
return res;
}

function runTestCase(container) {
const chart = window.chart = LightweightCharts.createChart(container);
chart.timeScale().applyOptions({ allowBoldLabels: false });

const mainSeries = chart.addLineSeries();

mainSeries.setData(generateData());
}

0 comments on commit 6daf134

Please sign in to comment.