vanilladocs
vanillapunch.com
API / ui/uichart

ui/uichart

라인 차트.

Line chart.

UILineChartextends Component

짝Counterpart: vanilla-engine UILineChart

라인 차트.

  • 값 배열을 노드 영역에 폴리라인으로 그린다. pushValue 로 매 프레임 / 매 초 새 값을 밀어 넣으면 오래된 값이 밀려나는 실시간 그래프가 된다.
  • 사용:
const lineChart = chartNode.addComponent(UILineChart);
lineChart.setMaxSampleCount(60);
매 초: lineChart.pushValue(newValue);

Line chart.

  • Draws a value array as a polyline in the node area. Pushing new values with pushValue every frame / every second makes it a real-time graph where old values are pushed out.
  • Usage:
const lineChart = chartNode.addComponent(UILineChart);
lineChart.setMaxSampleCount(60);
every second: lineChart.pushValue(newValue);
예제Example값을 밀어 넣어 꺾은선 그리기Drawing a line chart by pushing values
import { Engine, EngineConfiguration, UIScene, UILineChart, WorldNode, Color, Pivot, Vector2 } from "./build/vanilla.js";

class LineChartScene extends UIScene {
	create() {
		super.create();
		const chartNode = new WorldNode();
		chartNode.setPivot(Pivot.topLeft.clone());
		chartNode.setAnchor(Pivot.topLeft.clone());
		chartNode.setContentSize(Vector2.create(480, 160));
		chartNode.setLocalPosition(Vector2.create(80, 100));
		const lineChart = chartNode.addComponent(UILineChart);
		lineChart.setMaxSampleCount(60);
		lineChart.setValueRange(0, 100);
		lineChart.setLineColor(new Color(0.3, 0.8, 1, 1));
		lineChart.setLineWidth(2);
		for (let sampleIndex = 0; sampleIndex < 80; ++sampleIndex) {
			lineChart.pushValue(50 + Math.sin(sampleIndex * 0.3) * 30);
		}
		const valueList = lineChart.getValueList();
		console.log(valueList.length);
		const root = this.getRoot();
		root.addChild(chartNode);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new LineChartScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor()#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine UILineChart.new

메서드methodpushValue(value)#0.3.0 부터since 0.3.0소스source

값 하나 추가. (표본 수를 넘기면 앞에서 밀려난다)

Adds one value. (when the sample count is exceeded, values are pushed out from the front)

valuenumber
새 표본 값. (맨 뒤에 붙는다)New sample value. (appended at the end)

짝Counterpart: vanilla-engine UILineChart.push_value

메서드methoddraw(graphic)#0.3.0 부터since 0.3.0소스source

출력.

Draw.

graphicGraphic
그릴 그래픽. (노드 로컬 좌표, 내용 영역 왼쪽 위가 원점)Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
메서드methodcalculateDrawnRect(rect)#0.4.0 부터since 0.4.0소스source

그리는 사각형을 rect 에 적기. (오버라이드: 격자는 내용 영역 안, 선은 값이 정한 범위 밖으로 나간 만큼 위아래로 넘친다)

  • 가로는 표본이 내용 폭 안에 퍼지므로 내용 폭. 세로는 내용 높이와 가장 큰 값, 가장 작은 값이 놓이는 높이를 합친다.
  • 선 두께만큼(이음새를 메우는 반두께 연장까지) 사방으로 넓혀 본다.

Writes the drawn rectangle to rect. (Override: the grid stays inside the content area, the line spills up or down as far as values leave the set range)

  • Horizontally the content width, since samples spread within it. Vertically the union of the content height and the heights of the largest and smallest values.
  • Grown on all sides by the line width (including the half-width extension that fills joints).
rectRect
그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)

반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.

예제Example범위를 넘는 값이 그리는 곳 보기Seeing where out-of-range values draw
import { WorldNode, UILineChart, Rect, Vector2 } from "./build/vanilla.js";

const node = new WorldNode();
node.setContentSize(Vector2.create(160, 60));
const chart = node.addComponent(UILineChart);
chart.setValueRange(0, 1);
chart.setValueList([0.5, 2, 0.2]);
const drawnRect = Rect.zero();
chart.calculateDrawnRect(drawnRect);
console.log(drawnRect.position.y < 0);
메서드methodcalculatePoints(width, height)#0.4.0 부터since 0.4.0소스source

폴리라인 점 계산. (그리기와 같은 자리, 표본이 둘보다 적으면 빈 목록)

Computes the polyline points. (same positions as drawing, an empty list if fewer than two samples)

widthnumber
그래프 너비. (픽셀, 표본 수 상한을 채웠을 때 마지막 점이 이 자리)Graph width. (pixels, where the last point lands when the sample count limit is reached)
heightnumber
그래프 높이. (픽셀, 위아래 2 픽셀은 비운다)Graph height. (pixels, 2 pixels are left empty at the top and bottom)

반환ReturnsVector2[] 표본마다 점 하나. (왼쪽 위가 원점, 값이 클수록 위)One point per sample. (origin at the top left, larger values are higher)

짝Counterpart: vanilla-engine UILineChart.calculate_points

메서드methodsetMaxSampleCount(maxSampleCount)#0.3.0 부터since 0.3.0소스source

표본 수 상한 설정. (2 보다 작으면 2, 이미 든 표본이 새 상한보다 많으면 오래된 것부터 버린다)

Sets the maximum sample count. (Below 2 becomes 2, if more samples are held than the new limit the oldest are dropped)

maxSampleCountnumber
표본 수 상한.Sample count limit.

짝Counterpart: vanilla-engine UILineChart.set_max_sample_count

예제Example상한을 줄이면 오래된 표본부터 버리기Lowering the limit drops the oldest samples
import { UILineChart } from "./build/vanilla.js";

const lineChart = new UILineChart();
lineChart.setValueList([1, 2, 3, 4, 5]);
lineChart.setMaxSampleCount(3);
const valueList = lineChart.getValueList();
console.log(valueList.join(", "));
메서드methodgetMaxSampleCount()#0.3.0 부터since 0.3.0소스source

표본 수 상한 반환.

Returns the sample count limit.

반환Returnsnumber 표본 수 상한. (2 이상)Sample count limit. (2 or more)

짝Counterpart: vanilla-engine UILineChart.get_max_sample_count

메서드methodsetValueRange(minValue, maxValue)#0.3.0 부터since 0.3.0소스source

세로 값 범위 설정. (null 인 끝은 표본의 최소, 최대로 자동으로 맞춘다)

Sets the vertical value range. (an end that is null automatically fits the samples' minimum or maximum)

minValuenumber | null
아래 끝 값. (null 이면 자동)Bottom end value. (automatic if null)
maxValuenumber | null
위 끝 값. (null 이면 자동)Top end value. (automatic if null)

짝Counterpart: vanilla-engine UILineChart.set_value_range

예제Example고정 범위와 자동 범위의 점 자리 비교Comparing point positions with a fixed range and an automatic range
import { UILineChart } from "./build/vanilla.js";

const lineChart = new UILineChart();
lineChart.setMaxSampleCount(3);
lineChart.setValueList([20, 40, 60]);
lineChart.setValueRange(0, 100);
const fixedPoints = lineChart.calculatePoints(200, 104);
console.log(fixedPoints[2].y);
lineChart.setValueRange(null, null);
const autoPoints = lineChart.calculatePoints(200, 104);
console.log(autoPoints[2].y);
메서드methodsetValueList(valueList)#0.3.0 부터since 0.3.0소스source

표본 목록 설정. (표본 수 상한보다 길면 뒤쪽만 남긴다)

Sets the sample list. (keeps only the tail if longer than the sample count limit)

valueListnumber[]
표본 값 목록. (복사해 쥔다)Sample value list. (copied and kept)

짝Counterpart: vanilla-engine UILineChart.set_value_list

메서드methodgetValueList()#0.3.0 부터since 0.3.0소스source

표본 목록 반환.

Returns the sample list.

반환Returnsnumber[] 표본 값 목록의 복사본. (오래된 것부터)Copy of the sample value list. (oldest first)

짝Counterpart: vanilla-engine UILineChart.get_value_list

메서드methodsetLineColor(lineColor)#0.3.0 부터since 0.3.0소스source

선 색 설정.

Sets the line color.

lineColorColor | string
선 색. (복제해 쥔다)Line color. (cloned and kept)

짝Counterpart: vanilla-engine UILineChart.set_line_color

메서드methodsetGridColor(gridColor)#0.3.0 부터since 0.3.0소스source

격자 색 설정. (가로 격자선 3 개)

Sets the grid color. (3 horizontal grid lines)

gridColorColor | string
격자 색. (복제해 쥔다)Grid color. (cloned and kept)

짝Counterpart: vanilla-engine UILineChart.set_grid_color

메서드methodsetLineWidth(lineWidth)#0.3.0 부터since 0.3.0소스source

선 굵기 설정.

Sets the line thickness.

lineWidthnumber
선 굵기. (픽셀)Line width. (pixels)

짝Counterpart: vanilla-engine UILineChart.set_line_width

UIBarChartextends Component

짝Counterpart: vanilla-engine UIBarChart

바 차트.

  • 값 배열을 세로 막대로 그린다. 값이 바뀌면 다음 프레임에 그대로 반영된다.

Bar chart.

  • Draws a value array as vertical bars. Value changes are reflected as is on the next frame.
예제Example막대 하나를 강조한 막대 그래프Bar chart with one bar highlighted
import { Engine, EngineConfiguration, UIScene, UIBarChart, WorldNode, Color, Pivot, Vector2 } from "./build/vanilla.js";

class BarChartScene extends UIScene {
	create() {
		super.create();
		const chartNode = new WorldNode();
		chartNode.setPivot(Pivot.topLeft.clone());
		chartNode.setAnchor(Pivot.topLeft.clone());
		chartNode.setContentSize(Vector2.create(420, 160));
		chartNode.setLocalPosition(Vector2.create(110, 100));
		const barChart = chartNode.addComponent(UIBarChart);
		barChart.setValueList([12, 30, 22, 48, 36, 54, 41]);
		barChart.setMaxValue(60);
		barChart.setBarGap(8);
		barChart.setBarColor(new Color(0.42, 0.48, 1, 0.6));
		barChart.setHighlightColor(new Color(0.22, 0.84, 1, 1));
		barChart.setHighlightIndex(5);
		const root = this.getRoot();
		root.addChild(chartNode);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new BarChartScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor()#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine UIBarChart.new

메서드methoddraw(graphic)#0.3.0 부터since 0.3.0소스source

출력.

Draw.

graphicGraphic
그릴 그래픽. (노드 로컬 좌표, 내용 영역 왼쪽 위가 원점)Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
메서드methodcalculateDrawnRect(rect)#0.4.0 부터since 0.4.0소스source

그리는 사각형을 rect 에 적기. (오버라이드: 막대는 내용 영역 안, 막대 사이가 너무 넓어 막대 폭이 음수가 되면 그만큼 옆으로 넘친다)

  • 세로는 막대가 가장 낮아도 한 단위 높이로 그리므로 내용 높이가 한 단위보다 작으면 위로 넘친다. 한 단위씩 넓혀 본다.

Writes the drawn rectangle to rect. (Override: bars stay inside the content area; if the gaps are so wide that the bar width turns negative, it spills sideways by that much)

  • Vertically, the lowest bar is still drawn one unit tall, so it spills upward when the content height is under one unit. Grown by one unit.
rectRect
그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)

반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.

예제Example막대 그래프가 그리는 곳 보기Seeing where a bar chart draws
import { WorldNode, UIBarChart, Rect, Vector2 } from "./build/vanilla.js";

const node = new WorldNode();
node.setContentSize(Vector2.create(120, 40));
const chart = node.addComponent(UIBarChart);
chart.setValueList([3, 5, 2]);
const drawnRect = Rect.zero();
chart.calculateDrawnRect(drawnRect);
console.log(drawnRect.size.x, drawnRect.size.y);
메서드methodcalculateBarRects(width, height)#0.4.0 부터since 0.4.0소스source

막대 사각형 목록 계산. (그리기와 같은 자리)

Computes the bar rectangle list. (same positions as drawing)

widthnumber
그래프 너비. (픽셀, 막대 사이 간격을 뺀 나머지를 막대 수로 나눈다)Graph width. (pixels, the remainder after the gaps between bars is divided by the bar count)
heightnumber
그래프 높이. (픽셀, 최대 값이 이 높이)Graph height. (pixels, the maximum value reaches this height)

반환ReturnsRect[] 막대마다 사각형 하나. (바닥에 붙고, 값이 0 이하여도 높이 1 픽셀)One rectangle per bar. (sits on the bottom, 1 pixel tall even if the value is 0 or less)

짝Counterpart: vanilla-engine UIBarChart.calculate_bar_rects

메서드methodsetValueList(valueList)#0.3.0 부터since 0.3.0소스source

막대 값 목록 설정.

Sets the bar value list.

valueListnumber[]
막대 값 목록. (복사해 쥔다)Bar value list. (copied and kept)

짝Counterpart: vanilla-engine UIBarChart.set_value_list

메서드methodgetValueList()#0.3.0 부터since 0.3.0소스source

막대 값 목록 반환.

Returns the bar value list.

반환Returnsnumber[] 막대 값 목록의 복사본.Copy of the bar value list.

짝Counterpart: vanilla-engine UIBarChart.get_value_list

메서드methodsetMaxValue(maxValue)#0.3.0 부터since 0.3.0소스source

최대 값 설정. (막대가 높이를 다 채우는 값, 넘는 값은 잘린다)

Sets the maximum value. (the value at which a bar fills the full height, larger values are clipped)

maxValuenumber | null
최대 값. (null 이면 값 목록의 최대)Maximum value. (the largest value in the list if null)

짝Counterpart: vanilla-engine UIBarChart.set_max_value

메서드methodsetBarColor(barColor)#0.3.0 부터since 0.3.0소스source

막대 색 설정.

Sets the bar color.

barColorColor | string
막대 색. (복제해 쥔다)Bar color. (cloned and kept)

짝Counterpart: vanilla-engine UIBarChart.set_bar_color

메서드methodsetHighlightColor(highlightColor)#0.3.0 부터since 0.3.0소스source

강조 막대 색 설정.

Sets the highlighted bar color.

highlightColorColor | string
강조 막대 색. (복제해 쥔다)Highlighted bar color. (cloned and kept)

짝Counterpart: vanilla-engine UIBarChart.set_highlight_color

메서드methodsetHighlightIndex(highlightIndex)#0.3.0 부터since 0.3.0소스source

강조할 막대 순서 설정.

Sets the index of the bar to highlight.

highlightIndexnumber
-1 이면 강조 없음.-1 means no highlight.

짝Counterpart: vanilla-engine UIBarChart.set_highlight_index

메서드methodsetBarGap(barGap)#0.3.0 부터since 0.3.0소스source

막대 사이 간격 설정.

Sets the gap between bars.

barGapnumber
막대 사이 간격. (픽셀)Gap between bars. (pixels)

짝Counterpart: vanilla-engine UIBarChart.set_bar_gap