Skip to content

Commit

Permalink
format + fix xAxisLabel margin
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed Dec 20, 2023
1 parent a95fbf7 commit 5e391a5
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
24 changes: 12 additions & 12 deletions src/apps/weblib/canvas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Canvas:
circle: { x: number, y: number, radius: number }
line: { x1: number, y1: number, x2: number, y2: number }
text: { x: number, y: number, sizex: number, sizey: number, text: C.CString }
setBrushGradient:
{
x1: number,
y1: number,
x2: number,
y2: number,
stopCount: number/size_t,
stops: C.CColorGradientPtr
}
transform: { a: number, b: number, c: number, d: number, e: number, f: number }
save: {}
restore: {}
setBrushGradient:
{
x1: number,
y1: number,
x2: number,
y2: number,
stopCount: number/size_t,
stops: C.CColorGradientPtr
}
transform: { a: number, b: number, c: number, d: number, e: number, f: number }
save: {}
restore: {}
20 changes: 10 additions & 10 deletions src/apps/weblib/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ mergeInto(LibraryManager.library, {
openUrl: function (url) {
window.open(UTF8ToString(url), '_blank')
},
textBoundary: function (font, text, sizeX, sizeY) {
const dc = Module.measureCanvas
dc.font = UTF8ToString(font)
let metrics = dc.measureText(UTF8ToString(text))
const width = metrics.width
metrics = dc.measureText('Op')
const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent
setValue(sizeX, width, 'double')
setValue(sizeY, height, 'double')
}
textBoundary: function (font, text, sizeX, sizeY) {
const dc = Module.measureCanvas
dc.font = UTF8ToString(font)
let metrics = dc.measureText(UTF8ToString(text))
const width = metrics.width
metrics = dc.measureText('Op')
const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent
setValue(sizeX, width, 'double')
setValue(sizeY, height, 'double')
}
})
2 changes: 1 addition & 1 deletion src/apps/weblib/ts-api/cvizzu.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ModuleOptions {
export interface CVizzu {
// decorations
canvases: { [key: CPointer]: Canvas }
measureCanvas: CanvasRenderingContext2D
measureCanvas: CanvasRenderingContext2D

// members
HEAPU8: Uint8Array
Expand Down
6 changes: 3 additions & 3 deletions src/apps/weblib/ts-api/module/ccanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CCanvas extends CObject {
return new CColorGradient(this, stops, stopCount)
}

getString(text: CString): string {
return this._wasm.UTF8ToString(text)
}
getString(text: CString): string {
return this._wasm.UTF8ToString(text)
}
}
10 changes: 5 additions & 5 deletions src/apps/weblib/ts-api/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export class Module extends CEnv {
constructor(wasm: CVizzu) {
super(wasm, new ObjectRegistry(wasm._object_free))
const context2D = (<HTMLCanvasElement>document.createElement('canvas')).getContext('2d')
if (!context2D) throw new Error('Failed to get 2D context')
this._wasm.measureCanvas = context2D
this._wasm.canvases = {}
this.setLogging(false)
}
if (!context2D) throw new Error('Failed to get 2D context')
this._wasm.measureCanvas = context2D
this._wasm.canvases = {}
this.setLogging(false)
}

registerRenderer(cCanvas: CCanvas, canvas: Canvas): void {
this._wasm.canvases[cCanvas.getId()] = canvas
Expand Down
14 changes: 7 additions & 7 deletions src/apps/weblib/ts-api/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ export class Render implements Plugin, Canvas {
}

text(x: number, y: number, sizex: number, sizey: number, text: CString): void {
const dc = this._canvas.context
dc.textAlign = 'left'
dc.textBaseline = 'top'
x = x + (sizex < 0 ? -sizex : 0)
y = y + (sizey < 0 ? -sizey : 0)
dc.fillText(this._ccanvas.getString(text), x, y)
}
const dc = this._canvas.context
dc.textAlign = 'left'
dc.textBaseline = 'top'
x = x + (sizex < 0 ? -sizex : 0)
y = y + (sizey < 0 ? -sizey : 0)
dc.fillText(this._ccanvas.getString(text), x, y)
}

setBrushGradient(
x1: number,
Expand Down
4 changes: 2 additions & 2 deletions src/chart/main/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ Chart Chart::def()
Padding
{
.paddingTop = Gfx::Length::Emphemeral(8 / 12.0),
.paddingRight = Gfx::Length::Emphemeral(8 / 12.0),
.paddingRight = Gfx::Length::Emphemeral(3 / 12.0),
.paddingBottom = Gfx::Length::Emphemeral(8 / 12.0),
.paddingLeft = Gfx::Length::Emphemeral(8 / 12.0)
.paddingLeft = Gfx::Length::Emphemeral(3 / 12.0)
},
Font
{
Expand Down
9 changes: 3 additions & 6 deletions src/chart/main/stylesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ void Sheet::setAxisLabels()
else if (const auto &xAxis =
options->getChannels().at(Gen::ChannelId::x);
!xAxis.isEmpty() && xAxis.isDimension()
&& options->angle == 0) {
&& options->angle == 0)
def.angle.reset();
// def.paddingLeft = Gfx::Length::Emphemeral(2 / 12.0);
// def.paddingRight = Gfx::Length::Emphemeral(2 / 12.0);
}
}

void Sheet::setAxisTitle()
Expand Down Expand Up @@ -210,8 +207,8 @@ void Sheet::setAfterStyles(Gen::Plot &plot, const Geom::Size &size)

auto textBoundary =
Gfx::ICanvas::textBoundary(font, pair.second.label);
auto textXMargin = 0.; // xLabel.toMargin(textBoundary,
// font.size).getSpace().x;
auto textXMargin =
xLabel.toMargin(textBoundary, font.size).getSpace().x;
auto xHalfSize =
(textBoundary.x + textXMargin) / plotX / 2.0;

Expand Down

0 comments on commit 5e391a5

Please sign in to comment.